Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getopt for parsing program arguments #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions sl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright 1993,1998,2014
* Toyoda Masashi
* (mtoyoda@acm.org)
* Last Modified: 2014/06/03
* Last Modified: 2015/10/07
*========================================
*/
/* sl version 5.02 : Fix compiler warnings. */
Expand Down Expand Up @@ -46,7 +46,7 @@ void add_man(int y, int x);
int add_C51(int x);
int add_D51(int x);
int add_sl(int x);
void option(char *str);
void option(int argc, char * const argv[]);
int my_mvaddstr(int y, int x, char *str);

int ACCIDENT = 0;
Expand All @@ -63,12 +63,13 @@ int my_mvaddstr(int y, int x, char *str)
return OK;
}

void option(char *str)
void option(int argc, char * const argv[])
{
int c;
extern int ACCIDENT, FLY, LONG;

while (*str != '\0') {
switch (*str++) {
while ((c = getopt(argc, argv, "aFlc")) != -1) {
switch (c) {
case 'a': ACCIDENT = 1; break;
case 'F': FLY = 1; break;
case 'l': LOGO = 1; break;
Expand All @@ -82,11 +83,8 @@ int main(int argc, char *argv[])
{
int x, i;

for (i = 1; i < argc; ++i) {
if (*argv[i] == '-') {
option(argv[i] + 1);
}
}
option(argc, argv);

initscr();
signal(SIGINT, SIG_IGN);
noecho();
Expand Down