{"id":27154989,"url":"https://github.com/maximilianfeldthusen/simpleparser","last_synced_at":"2025-09-05T07:44:30.501Z","repository":{"id":280942153,"uuid":"943686579","full_name":"maximilianfeldthusen/simpleParser","owner":"maximilianfeldthusen","description":"This C code implements a simple command-line interface (CLI) that allows users to input commands and receive responses based on those commands.","archived":false,"fork":false,"pushed_at":"2025-04-24T16:47:11.000Z","size":12,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"TFD","last_synced_at":"2025-04-24T17:46:58.553Z","etag":null,"topics":["c","parser"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maximilianfeldthusen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-06T05:24:56.000Z","updated_at":"2025-04-24T16:47:14.000Z","dependencies_parsed_at":"2025-03-06T06:38:03.291Z","dependency_job_id":"9341a84a-d25c-4bee-a507-602a757b9416","html_url":"https://github.com/maximilianfeldthusen/simpleParser","commit_stats":null,"previous_names":["maximilianfeldthusen/simpleparser"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maximilianfeldthusen/simpleParser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FsimpleParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FsimpleParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FsimpleParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FsimpleParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maximilianfeldthusen","download_url":"https://codeload.github.com/maximilianfeldthusen/simpleParser/tar.gz/refs/heads/TFD","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FsimpleParser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273728157,"owners_count":25157136,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","parser"],"created_at":"2025-04-08T18:56:43.353Z","updated_at":"2025-09-05T07:44:25.467Z","avatar_url":"https://github.com/maximilianfeldthusen.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Documentation\n\n### simpleParser\n\nThis C code implements a simple command-line interface (CLI) that allows users to input commands and receive responses based on those commands. Here's a breakdown of the code:\n\n### Header Files\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstring.h\u003e\n```\n- **`\u003cstdio.h\u003e`**: This header file is included for standard input and output functions (like `printf` and `fgets`).\n- **`\u003cstdlib.h\u003e`**: This is included for utility functions like `atoi`, which converts strings to integers.\n- **`\u003cstring.h\u003e`**: This header is included for string manipulation functions like `strtok`, `strncmp`, and `strcmp`.\n\n### Constants\n\n```c\n#define MAX_INPUT_SIZE 1024\n#define MAX_ARG_SIZE 100\n#define DELIM \" \\t\\r\n\"\n```\n- **`MAX_INPUT_SIZE`**: The maximum size for the input buffer.\n- **`MAX_ARG_SIZE`**: The maximum number of arguments that can be parsed.\n- **`DELIM`**: A string containing delimiters (space, tab, carriage return, newline) used for tokenizing the input.\n\n### Function Prototypes\n\n```c\nvoid parseInput(char *input);\nvoid executeCommand(char **args);\n```\nThese are declarations for two functions that will be defined later in the code.\n\n### Main Function\n\n```c\nint main() {\n    char input[MAX_INPUT_SIZE];\n\n    printf(\"Welcome to the simple backend parser!\\n\");\n    printf(\"Type 'exit' to quit.\\n\");\n\n    while (1) {\n        printf(\"\u003e \");\n        if (fgets(input, sizeof(input), stdin) == NULL) {\n            break;  // Error or EOF\n        }\n\n        // Check for exit command\n        if (strncmp(input, \"exit\", 4) == 0) {\n            break;\n        }\n\n        // Parse and execute the input command\n        parseInput(input);\n    }\n\n    return 0;\n}\n```\n\n- The program starts by welcoming the user and instructing them how to exit.\n- An infinite loop is initiated that waits for user input.\n- **`fgets`** is used to read a line of input from the user. If there is an error or EOF, it breaks the loop.\n- The program checks if the user typed \"exit\" to terminate the program.\n- If not, it calls the `parseInput` function to handle the input.\n\n### `parseInput` Function\n\n```c\nvoid parseInput(char *input) {\n    char *args[MAX_ARG_SIZE];\n    int argCount = 0;\n\n    // Tokenizing the input string based on the delimiters\n    char *token = strtok(input, DELIM);\n    while (token != NULL \u0026\u0026 argCount \u003c MAX_ARG_SIZE - 1) {\n        args[argCount++] = token;\n        token = strtok(NULL, DELIM);\n    }\n    args[argCount] = NULL;  // Null-terminate the array of arguments\n\n    // Execute the command\n    executeCommand(args);\n}\n```\n\n- This function takes the input string and tokenizes it into individual arguments based on the specified delimiters.\n- It uses `strtok` to split the string into tokens. Each token (argument) is stored in the `args` array until the maximum number of arguments is reached.\n- The last entry in the `args` array is set to `NULL` to indicate the end of the arguments.\n- After parsing, it calls `executeCommand` to process the command.\n\n### `executeCommand` Function\n\n```c\nvoid executeCommand(char **args) {\n    if (args[0] == NULL) {\n        return;  // No command entered\n    }\n\n    // Example command handling\n    if (strcmp(args[0], \"hello\") == 0) {\n        printf(\"Hello, World!\\n\");\n    } else if (strcmp(args[0], \"add\") == 0 \u0026\u0026 args[1] != NULL \u0026\u0026 args[2] != NULL) {\n        int num1 = atoi(args[1]);\n        int num2 = atoi(args[2]);\n        printf(\"Result: %d\n\", num1 + num2);\n    } else if (strcmp(args[0], \"sub\") == 0 \u0026\u0026 args[1] != NULL \u0026\u0026 args[2] != NULL) {\n        int num1 = atoi(args[1]);\n        int num2 = atoi(args[2]);\n        printf(\"Result: %d\n\", num1 - num2);\n    } else {\n        printf(\"Unknown command: %s\n\", args[0]);\n    }\n}\n```\n\n- This function checks if any command was entered. If `args[0]` is `NULL`, it simply returns.\n- It compares the first argument (`args[0]`) with known commands:\n  - **`hello`**: Prints \"Hello, World!\".\n  - **`add`**: If two additional arguments are provided, it converts them to integers using `atoi`, adds them, and prints the result.\n  - **`sub`**: Similar to `add`, but it subtracts the second number from the first.\n- If the command doesn't match any known ones, it prints an \"Unknown command\" message.\n\n### Summary\nThis code implements a simple command-line interface that can parse and execute basic commands like \"hello\", \"add\", and \"sub\". It demonstrates basic string processing, command execution, and user interaction in C. \n\n\n![C](https://img.shields.io/badge/c-%2300599C.svg?style=for-the-badge\u0026logo=c\u0026logoColor=white)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianfeldthusen%2Fsimpleparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximilianfeldthusen%2Fsimpleparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianfeldthusen%2Fsimpleparser/lists"}