{"id":16985369,"url":"https://github.com/prajwalch/readtrmin","last_synced_at":"2025-03-22T01:25:25.060Z","repository":{"id":49043060,"uuid":"379594984","full_name":"prajwalch/readtrmin","owner":"prajwalch","description":"safe and simple terminal input reader for c language","archived":false,"fork":false,"pushed_at":"2021-12-06T09:26:17.000Z","size":113,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T19:33:53.449Z","etag":null,"topics":["c","c-library","input-handler","library"],"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/prajwalch.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}},"created_at":"2021-06-23T12:26:12.000Z","updated_at":"2022-01-12T13:17:27.000Z","dependencies_parsed_at":"2022-09-08T23:51:01.175Z","dependency_job_id":null,"html_url":"https://github.com/prajwalch/readtrmin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prajwalch%2Freadtrmin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prajwalch%2Freadtrmin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prajwalch%2Freadtrmin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prajwalch%2Freadtrmin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prajwalch","download_url":"https://codeload.github.com/prajwalch/readtrmin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244891602,"owners_count":20527289,"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","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","c-library","input-handler","library"],"created_at":"2024-10-14T02:43:18.884Z","updated_at":"2025-03-22T01:25:25.030Z","avatar_url":"https://github.com/prajwalch.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ReadTrmIn\n**aim of safe and simple terminal input reader**\n\n## Requirements\n* make\n* clang (v9.0.0 or above) or gcc\n\n## Key Features\n* String reading options to allow or disallow certain things like:\n   - whitespace\n   - number\n   - special characters (#, $, _ and so on)\n   - uppercase and lowercase\n* Option to specify numbers of input to read for string and int.\n* Buffer overflow handling for string\n\n\n## How To Build And Install\n\nAfter cloned the repository, run the below command to build:\n\n```bash\nmake\n```\n\nTo build for debugging run:\n```bash\nmake DEBUG=1\n```\n\n## How to link on your project\n Don't forget to build and install the library first. Once you are done that make a new project and create new 3 source file by the name of `char_example.c`, `string_example.c` and `int_example.c`. Now you can copy and paste the code into each file respectively or manually type.\n\n```c\n// char_example.c\n\n#include \u003cstdio.h\u003e\n#include \u003creadtrmin/readtrmin.h\u003e\n\nint main(int argc, char **argv)\n{\n   char single_char = 0;\n   readtrmin_char(\u0026single_char);\n   // print it\n   printf(\"%c\\n\", single_char):\n}\n```\n\n```c\n// string_example.c\n\n#include \u003cstdio.h\u003e\n#include \u003creadtrmin/readtrmin.h\u003e\n\nint main(int argc, char **argv)\n{\n   char your_buffer[5] = {0};\n   \n   /* \n     * readtrmin_string takes 4 arguments\n     * char *buffer\n     * size_t buffer_size\n     * size_t max_input_length\n     * StringOptions *option (it is defined on the header file)\n   */\n   \n   readtrmin_string(your_buffer, 5, 4, \u0026default_stringoption);\n   // print it\n   printf(\"%s\\n\", your_buffer);\n}\n```\nFor more details on StringOptions see the [API](#api) section below.\n\n```c\n// int_example.c\n\n#include \u003cstdio.h\u003e\n#include \u003creadtrmin/readtrmin.h\u003e\n\u003e\nint main(int argc, char **argv)\n{\n   long your_int = 0;\n   \n   // second argument is max_input_length you want to read.\n   // Note that for now more than 9 are not allowed\n   readtrmin_int(\u0026your_int, 1);\n   // print it\n   printf(\"%lu\\n\", your_int):\n}\n```\nNow compile one of the examples by linking it with the library as shown below:\n```bash\n$ clang -lreadtrmin program_name.c\n$ ./a.out\n```\n## API\nReadtrmin provided only 3 API functions for now as shown in the above example.\n\n```c\nbool readtermin_char(char *pointer_arg);\n```\nIt is straight forward you pass the address of the char type variable and it will take the input and stored it there. It only allows the alphabet letter (aA to zZ).\n\nReturn true if the read is successful otherwise false.\n\n```c\nbool readtrmin_string(char *buffer_arg, size_t buffer_size, size_t max_input_len, StringOptions *string_option);\n```\nThis function is a bit like the above function but with more features that allow you to give the maximum length of input/string to read as well as what are the things to allowed like ***space, number, special characters, and so on.***  on the string while reading it by passing the options to the function. The type `StringOptions` is defined on the header file `readtrmin.h` as below.\n\n```c\ntypedef struct StringOptions {\n  bool allow_space;\n  bool allow_number;\n  bool allow_symbol;\n  bool allow_uppercase;\n  bool allow_lowercase;\n} StringOptions;\n```\nIf you didn't want to make your custom options you can use default options which are defined on the header file `stringoptions_coll.h` file as below. This header file can also be include separately by yourself, but by default it is included on the `readtrmin.h` header file. So no need to worry about it.\n\n```c\nconst StringOptions default_string_option = {\n  .allow_space = false,\n  .allow_numer = false,\n  .allow_symbol = false,\n  .allow_uppercase = true,\n  .allow_lowercase = true\n};\n```\nFor using it you can directly pass the address. See the above string example (string_example.c) shown on the section [How to link on your project](#how-to-link-on-your-project)\n\nNow to create your own option declare it with type `StringOptions` and give value (true or false) to members as shown on below:\n```c\nStringOptions your_option;\nyour_option.allow_space = true;\nyour_option.allow_number = true;\n// And so on\n\n// you can also do like this\nStringOptions your_options = {\n  .allow_space = true,\n  .allow_number = true,\n  // and so on\n}\n```\n\nHere is the complete example of using  custom option:\n```c\n#include \u003cstdio.h\u003e\n#include \u003creadtrmin/readtrmin.h\u003e\n\nint main(int argc, char **argc)\n{\n  StringOptions my_option = {\n    .allow_space = false,\n    .allow_number = true,\n    .allow_symbol = true,\n    .allow_uppercase = true,\n    .allow_lowercase = true\n  };\n  \n  char username[9] = { 0 };\n  readtrmin_string(username, 9, 8, \u0026my_option);\n  printf(\"username: %s\\n\", username);\n}\n```\n\nAnd last we have int reader\n```c\nbool readtrmin_int(long *pointer_arg, size_t max_input_len);\n```\nIt is also the same as reading char but it only parses number input. you can provide how many numbers you want to take from the input by passing on argument max_input_len. \n\n***Note that for now it's not allowed to take more than 9 numbers***\n## License\n\nMIT\n\n---\n\n\u003e GitHub [@PrajwalCH](https://github.com/PrajwalCH) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e Twitter [@prjwlCH](https://twitter.com/prjwlCH)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprajwalch%2Freadtrmin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprajwalch%2Freadtrmin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprajwalch%2Freadtrmin/lists"}