{"id":16636795,"url":"https://github.com/takamin/win-c","last_synced_at":"2025-10-30T07:30:27.842Z","repository":{"id":29888634,"uuid":"33434079","full_name":"takamin/win-c","owner":"takamin","description":"getopt / getopt_long for Windows Visual C/C++ (MIT LICENSE)","archived":false,"fork":false,"pushed_at":"2016-11-21T04:54:13.000Z","size":18,"stargazers_count":28,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T07:11:47.937Z","etag":null,"topics":["argv-parser","cplusplu","getopt"],"latest_commit_sha":null,"homepage":"http://takamints.hatenablog.jp/entry/2015/04/27/231454","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/takamin.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}},"created_at":"2015-04-05T07:41:04.000Z","updated_at":"2024-11-19T09:07:13.000Z","dependencies_parsed_at":"2022-08-23T04:50:29.445Z","dependency_job_id":null,"html_url":"https://github.com/takamin/win-c","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takamin%2Fwin-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takamin%2Fwin-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takamin%2Fwin-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takamin%2Fwin-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takamin","download_url":"https://codeload.github.com/takamin/win-c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238941561,"owners_count":19556006,"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":["argv-parser","cplusplu","getopt"],"created_at":"2024-10-12T06:22:52.283Z","updated_at":"2025-10-30T07:30:22.575Z","avatar_url":"https://github.com/takamin.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"win-c\n============\n\nC/C++から使えるWindowsのコンソールアプリケーション用のライブラリです。\n\n__関数__\n\n* `getopt() / getopt_long()` - コマンドラインオプション解析\n\n## `getopt() / getopt_long()` - コマンドラインオプション解析\n\n関数の仕様は、[POSIXのgetopt](http://linuxjm.sourceforge.jp/html/LDP_man-pages/man3/getopt.3.html)を参照してください。\n\n* 長いオプションの`optional_argument` と `getopt_long_only()`は、対応していません。\n\n### 使用例\n\n以下は、C++での使い方サンプルです。\n\n```\n#include \u003ciostream\u003e\n#include \"getopt.h\"\nusing namespace std;\nint main(int argc, char* argv[]) {\n    //オプションの定義。a, b, c, dで、bとcは引数を取る\n    //  -a\n    //  -b \u003copt_b_arg\u003e\n    //  -c \u003copt_c_arg\u003e\n    //  -d\n    char const * optstring = \"ab:c:d\";\n    int opt_a = 0;\n    char* opt_b = 0;\n    char* opt_c = 0;\n    int opt_d = 0;\n\n    //オプションの解析\n    int opt = 0;\n    while((opt = getopt(argc, argv, optstring)) != -1) {\n        switch(opt) {\n        case 'a':\n            opt_a = 1;\n            break;\n        case 'b':\n            opt_b = optarg;\n            break;\n        case 'c':\n            opt_c = optarg;\n            break;\n        case 'd':\n            opt_d = 1;\n            break;\n        default:\n            cerr \u003c\u003c \"unknown option.\" \u003c\u003c endl;\n            exit(-1);\n            break;\n        }\n    }\n\n    //オプション以外のパラメータ\n    char* noptarg = argv[optind++];\n}\n```\n\n### 使い方\n\nmain関数のargc,argvとオプション定義の文字列を渡して、(-1)が返されるまで繰り返し呼び出して、オプション解析を行います。\n\n#### オプションの定義\n\nオプションは、オプションの文字列を並べた文字列で定義。\n\n引数を取るオプションは、オプション文字の次にコロンを記述。\n\n#### 戻り値\n\n(-1)はオプション解析が終了したことを表します。\n\nオプションが見つかるとその文字を返します。\n\nオプションでない文字が指定されているときは、'?'が返されます。\n\n#### オプションの引数\n\n引数を取るオプションが見つかった場合、`optarg`がその引数を指し示しています。\n\n#### オプション以外のコマンドラインパラメータ\n\nオプション解析が終了すると、グローバル変数 `optind` が、オプションでない最初のコマンドラインパラメータを指しています。\n`optind \u003c argc` なら、`argv[optind]`が、オプションではない最初のコマンドラインパラメータです。\n`optind \u003e= argc` なら、オプションでないパラメータはありません。\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakamin%2Fwin-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakamin%2Fwin-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakamin%2Fwin-c/lists"}