Skip to content

Commit

Permalink
Add header for funcs in main
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Dec 28, 2024
1 parent d590c8f commit d46e7b6
Showing 1 changed file with 100 additions and 59 deletions.
159 changes: 100 additions & 59 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/**
*
* @function lint
* @function lint_do
* @brief Linting the given content and parameters
* @params {bool} isCode - Whether the content is code or file
* @params {const char*} path - Path of the file
Expand All @@ -34,7 +34,7 @@
* @returns {void}
*
*/
void lint(bool isCode, const char *path, char *content, char *build_file) {
void lint_do(bool isCode, const char *path, char *content, char *build_file) {
DEBUG_ME;
lexer_t *lexer = lexer_create(path, content);

Expand Down Expand Up @@ -165,12 +165,12 @@ void help(char *app) {
}

/**
*
*
* @function update
* @brief Update and download new version
* @params {void}
* @returns {void}
*
*
*/
void update()
{
Expand Down Expand Up @@ -205,86 +205,127 @@ void update()

/**
*
* @function doargs
* @brief Handle command line arguments
* @function lint
* @brief Lint a file or code based on arguments
* @params {int} argc - Number of arguments
* @params {char**} argv - Array of arguments
* @returns {void}
*
*/
void doargs(int argc, char **argv) {
DEBUG_ME;
if (argc < 2) {
help(argv[0]);
void lint(int argc, char **argv) {
const char *path = argv[1];
if (argc <= 2) {
error(1, "Usage: %s lint <file>\n", argv[0]);
}

const char *path = argv[1];
// printf("path: %s\n", path);
// printf("Argc: %d\n", argc);
if (strcmp(argv[2], "code") == 0) {
if (argc <= 3) {
error(1, "Usage: %s lint code <content>\n", argv[0]);
}

if (strcmp(path, "version") == 0) {
printf("Salam %s\n", SALAM_VERSION);
exit(1);
} else if (strcmp(path, "help") == 0) {
help(argv[0]);
} else if (strcmp(path, "update") == 0) {
update();
} else if (strcmp(path, "lint") == 0) {
if (argc <= 2) {
error(1, "Usage: %s lint <file>\n", argv[0]);
char *content = argv[3];

lint_do(true, "stdin", content, NULL);
} else {
if (!file_exists(argv[2])) {
error(1, "File does not exist: %s\n", argv[2]);
}

if (strcmp(argv[2], "code") == 0) {
if (argc <= 3) {
error(1, "Usage: %s lint code <content>\n", argv[0]);
}
if (argc <= 3) {
error(1, "Usage: %s lint <file> <output>\n", argv[0]);
}

char *content = argv[3];
char *content = file_reads_binary(path, NULL);

lint(true, "stdin", content, NULL);
} else {
if (!file_exists(argv[2])) {
error(1, "File does not exist: %s\n", argv[2]);
}
char *output_file = argv[3];

if (argc <= 3) {
error(1, "Usage: %s lint <file> <output>\n", argv[0]);
}
lint_do(false, path, content, output_file);

char *content = file_reads_binary(path, NULL);
memory_destroy(content);
}
}

char *output_file = argv[3];
/**
*
* @function code
* @brief Execute code content
* @params {int} argc - Number of arguments
* @params {char**} argv - Array of arguments
* @returns {void}
*
*/
void code(int argc, char **argv)
{
if (argc <= 2) {
error(1, "Usage: %s code <content>\n", argv[0]);
}

lint(false, path, content, output_file);
char *content = argv[2];

memory_destroy(content);
}
} else if (strcmp(path, "code") == 0) {
if (argc <= 2) {
error(1, "Usage: %s code <content>\n", argv[0]);
}
char *output_dir = argv[3];

run(true, "stdin", content, output_dir);
}

char *content = argv[2];
/**
*
* @function execute
* @brief Execute a file
* @params {int} argc - Number of arguments
* @params {char**} argv - Array of arguments
* @returns {void}
*
*/
void execute(int argc, char** argv)
{
const char *path = argv[1];
if (!file_exists(path)) {
error(1, "File does not exist: %s\n", path);
}

char *output_dir = argv[3];
char *content = file_reads_binary(path, NULL);

run(true, "stdin", content, output_dir);
} else {
if (!file_exists(path)) {
error(1, "File does not exist: %s\n", path);
}
char *output_dir = NULL;

char *content = file_reads_binary(path, NULL);
if (argc >= 3) {
output_dir = argv[2];
}

char *output_dir = NULL;
run(false, path, content, output_dir);

if (argc >= 3) {
output_dir = argv[2];
}
memory_destroy(content);
}

/**
*
* @function doargs
* @brief Handle command line arguments
* @params {int} argc - Number of arguments
* @params {char**} argv - Array of arguments
* @returns {void}
*
*/
void doargs(int argc, char **argv) {
DEBUG_ME;
if (argc < 2) {
help(argv[0]);
}

run(false, path, content, output_dir);
const char *path = argv[1];

memory_destroy(content);
if (strcmp(path, "version") == 0) {
printf("Salam %s\n", SALAM_VERSION);
exit(1);
} else if (strcmp(path, "help") == 0) {
help(argv[0]);
} else if (strcmp(path, "update") == 0) {
update(argc, argv);
} else if (strcmp(path, "lint") == 0) {
lint(argc, argv);
} else if (strcmp(path, "code") == 0) {
code(argc, argv);
} else {
execute(argc, argv);
}
}

Expand Down

0 comments on commit d46e7b6

Please sign in to comment.