-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2020 Rinwasyu | ||
* | ||
* This file is part of kot. | ||
* | ||
* Kot is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Kot is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "kot.h" | ||
#include "option.h" | ||
|
||
void option_help() { | ||
printf("Usage: %s [--help] [--version]\n", PROGNAME); | ||
exit(0); | ||
} | ||
|
||
void option_version() { | ||
printf("%s %s\n", PROGNAME, VERSION); | ||
printf("Copyright %s %s\n", AUTHOR_YEAR, AUTHOR); | ||
printf("%s\n", WEBSITE); | ||
printf("This program is licensed under %s\n", LICENSE); | ||
exit(0); | ||
} | ||
|
||
void option_readOptions(struct Option *option, int argc, char **argv) { | ||
int unknown_options = 0; | ||
for (int i = 1; i < argc; i++) { | ||
if (argv[i][0] == '-') { | ||
int j = 1; | ||
for (; argv[i][j] == '-'; j++); | ||
|
||
if (strcmp(&argv[i][j], "help") == 0) { | ||
option->help(); | ||
} else if (strcmp(&argv[i][j], "version") == 0) { | ||
option->version(); | ||
} else { | ||
printf("Unknown option: %s\n", argv[i]); | ||
unknown_options++; | ||
} | ||
} | ||
} | ||
if (unknown_options > 0) { | ||
option->help(); | ||
} | ||
} | ||
|
||
struct Option option = { | ||
option_readOptions, | ||
option_help, | ||
option_version | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2020 Rinwasyu | ||
* | ||
* This file is part of kot. | ||
* | ||
* Kot is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Kot is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef KOT_OPTION_H | ||
|
||
#define KOT_OPTION_H | ||
|
||
struct Option { | ||
void (*readOptions)(struct Option *option, int argc, char **argv); | ||
void (*help)(void); | ||
void (*version)(void); | ||
}; | ||
|
||
void option_help(void); | ||
void option_version(void); | ||
void option_readOptions(struct Option *option, int argc, char **argv); | ||
|
||
struct Option option; | ||
|
||
#endif |