{"id":31880716,"url":"https://github.com/patamigo0/lib-customparserinc","last_synced_at":"2025-10-13T01:25:02.189Z","repository":{"id":312584587,"uuid":"1047204256","full_name":"PatAmigo0/Lib-CustomParserInC","owner":"PatAmigo0","description":"A simple tool to help you with some routine parsing tasks","archived":false,"fork":false,"pushed_at":"2025-09-07T17:35:07.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-07T19:24:07.770Z","etag":null,"topics":["c","file-parser"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PatAmigo0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-08-29T23:22:32.000Z","updated_at":"2025-09-07T17:35:11.000Z","dependencies_parsed_at":"2025-08-31T18:34:17.677Z","dependency_job_id":"2d79a75a-14a3-447b-a324-f00fea4c5091","html_url":"https://github.com/PatAmigo0/Lib-CustomParserInC","commit_stats":null,"previous_names":["patamigo0/file_parser_in_c_lib"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PatAmigo0/Lib-CustomParserInC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomParserInC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomParserInC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomParserInC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomParserInC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PatAmigo0","download_url":"https://codeload.github.com/PatAmigo0/Lib-CustomParserInC/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomParserInC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279013890,"owners_count":26085325,"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-10-12T02:00:06.719Z","response_time":53,"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","file-parser"],"created_at":"2025-10-13T01:25:00.764Z","updated_at":"2025-10-13T01:25:02.182Z","avatar_url":"https://github.com/PatAmigo0.png","language":"C","readme":"# File Parser Library\n\nThis lightweight library provides a simple, efficient way to parse, manipulate, and save CSV (and other delimited) files in C. It features automatic type detection, sorting capabilities, and flexible data handling.\n\n## Version\n```0.2 BETA```\n\n## Features\n\n- **Automatic type detection**: Strings, integers, floats, and NULL values\n- **Flexible parsing**: Customizable delimiters and parsing options\n- **Sorting capabilities**: Sort by column index or name, ascending or descending\n- **Memory efficient**: Smart memory management with automatic cleanup\n- **Comprehensive logging**: Configurable logging levels for debugging\n- **Header support**: Automatic header detection and handling\n- **Cross-platform**: Works on any platform with a C99 compiler\n\n## Installation\n\n1. Add `fileparser.h` and `fileparser.c` to your project\n2. Include the header in your code:\n```c\n#include \"fileparser.h\"\n```\n\n## Requirements\n\n- C99 compatible compiler\n- Standard C libraries (stdio.h, stdlib.h, string.h)\n\n## Usage\n\n### Basic Setup\n\n```c\n#include \"fileparser.h\"\n\nint main()\n{\n    // create a parser with default settings\n    PARSER parser = create_parser();\n    \n    // parse a CSV file\n    if (parse_file(\u0026parser, \"data.csv\"))\n    {\n        printf(\"Failed to parse file\\n\");\n        return 1;\n    }\n    \n    // print all data\n    print_all_data(\u0026parser);\n    \n    // sort by the second column (index 1)\n    PARSER_SORT_SETTINGS sort_settings = create_parser_sort_settings();\n    sort_settings.tag = COLUMN_INDEX;\n    sort_settings.value.column_index = 1;\n    sort_settings.direction = ASCENDING;\n    \n    if (sort_data(\u0026parser, sort_settings))\n    {\n        printf(\"Failed to sort data\\n\");\n    }\n    \n    // save the sorted data\n    save_data(\u0026parser, \"sorted_data.csv\");\n    \n    // always clean up\n    free_parser(\u0026parser);\n    \n    return 0;\n}\n```\n\n### Advanced Usage with Custom Settings\n\n```c\n#include \"fileparser.h\"\n\nint main()\n{\n    // create custom parser settings\n    PARSER_SETTINGS settings = create_parser_settings();\n    settings.splitter = ',';        // use comma as delimiter\n    settings.ignore_first_line = 0; // don't ignore first line\n    settings.first_line_as_header = 1; // treat first line as header\n    \n    // change default settings\n    change_default_settings(settings);\n    \n    // create parser with custom settings\n    PARSER parser = create_parser();\n    \n    // parse file\n    if (parse_file(\u0026parser, \"data.csv\"))\n    {\n        PARSER_LOG_CRITICAL(\"Failed to parse file\");\n        return 1;\n    }\n    \n    // sort by column name\n    PARSER_SORT_SETTINGS sort_settings = create_parser_sort_settings();\n    sort_settings.tag = COLUMN_NAME;\n    sort_settings.value.column_name = \"Age\"; // column name to sort by\n    sort_settings.direction = DESCENDING;\n    sort_settings.case_sensitive = 0; // case insensitive comparison\n    \n    if (sort_data(\u0026parser, sort_settings))\n    {\n        PARSER_LOG_CRITICAL(\"Failed to sort data\");\n    }\n    else\n    {\n        // save sorted data with pipe delimiter\n        parser.settings.splitter = '|';\n        save_data(\u0026parser, \"sorted_data.txt\");\n    }\n    \n    // always clean up\n    free_parser(\u0026parser);\n    \n    return 0;\n}\n```\n\n## Core Functions Reference\n\n### Parser Creation \u0026 Management\n1. **`PARSER create_parser()`**  \n   Creates and returns a new parser object with default settings.\n\n2. **`int parse_file(PARSER* parser, const char* filename)`**  \n   Parses a file and stores the data in the parser object. (You can do your custom logic with it)\n\n3. **`void free_parser(PARSER* parser)`**  \n   Frees all resources associated with the parser.\n\n### Data Manipulation\n4. **`int sort_data(PARSER* parser, PARSER_SORT_SETTINGS settings)`**  \n   Sorts the parsed data by the specified column.\n\n5. **`int save_data(PARSER* parser, const char* filename)`**  \n   Saves the parsed data to a file.\n\n### Data Display\n6. **`int print_all_data(PARSER* parser)`**  \n   Prints all parsed data to the console.\n\n7. **`int print_data(PARSER* parser, size_t how_much_to_print)`**  \n   Prints a specified amount of parsed data to the console.\n\n### Settings Management\n8. **`PARSER_SETTINGS create_parser_settings()`**  \n   Creates a new settings object with default values.\n\n9. **`void change_default_settings(PARSER_SETTINGS settings)`**  \n   Changes the default parser settings.\n\n10. **`PARSER_SORT_SETTINGS create_parser_sort_settings()`**  \n    Creates a new sort settings object with default values.\n\n11. **`void change_default_sort_settings(PARSER_SORT_SETTINGS settings)`**  \n    Changes the default sort settings.\n\n## Configuration\n\n### Logging Levels\nThe library provides configurable logging levels:\n\n```c\n#define LOGLEVEL_CRITICAL 0  // only critical errors\n#define LOGLEVEL_WARNING  1  // warnings and errors\n#define LOGLEVEL_INFO     2  // informational messages (default)\n#define LOGLEVEL_DEBUG    3  // debug information\n#define LOGLEVEL_NONE     4  // no logging\n```\n\nTo change the logging level, modify the `LOG_LEVEL` definition in `fileparser.h`:\n\n```c\n#define LOG_LEVEL LOGLEVEL_WARNING // change to the desired level\n```\n\n### Parser Settings\nCustomize parsing behavior with `PARSER_SETTINGS`:\n\n- `splitter`: Character used to separate values (default: ';')\n- `ignore_first_line`: Whether to ignore the first line (default: 0)\n- `ignore_errors`: Whether to continue parsing on errors (default: 1)\n- `first_line_as_header`: Whether to treat the first line as header (default: 1)\n\n### Sort Settings\nCustomize sorting behavior with `PARSER_SORT_SETTINGS`:\n\n- `tag`: Specify whether to sort by `COLUMN_NAME` or `COLUMN_INDEX`\n- `value`: The column name or index to sort by\n- `direction`: `ASCENDING` or `DESCENDING` order\n- `case_sensitive`: Whether string comparisons should be case sensitive (default: 1)\n\n## Building\n\nCompile with your project:\n```bash\ngcc \u003cyour_app.c\u003e fileparser.c -o your_app\n```\n\n## Data Types\n\nThe library automatically detects and handles these data types:\n\n- **STRING_TYPE**: Text values (quoted or unquoted)\n- **INTEGER_TYPE**: Whole numbers\n- **FLOAT_TYPE**: Decimal numbers\n- **NULL_TYPE**: Empty values or explicit NULL strings\n\n**NOTE:** More to be added in the future.\n\n## IMPORTANT NOTES\n\n1. **Memory Management**  \n   - Always use `free_parser()` to properly free parser resources\n\n2. **File Format**  \n   - Supports any delimiter (CHAR) (configurable via `splitter` setting)\n   - Handles multi quoted values (like \"\"\"hello\"\"\")\n   - Automatically trims whitespace and newlines\n   - Recognizes \"NULL\" (case-insensitive) as a null value\n\n3. **Performance**  \n   - Efficient parsing with minimal memory overhead\n   - Sorting uses quicksort algorithm for performance\n\n4. **Error Handling**  \n   - Comprehensive error logging at multiple levels\n   - All functions return error codes for programmatic handling\n\n5. **Header Handling**  \n   - Headers are automatically converted to strings if needed\n   - Missing headers are given automatic names (\\_\\_parser_column\\_\\%d\\_\\_) where \\%d stands for column index\n\n## Contributing\n\nContributions are welcome! Please submit pull requests or open issues on GitHub.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatamigo0%2Flib-customparserinc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatamigo0%2Flib-customparserinc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatamigo0%2Flib-customparserinc/lists"}