From 99c5df51cf8be92d33b1bdf8079ecf9d37c2488a Mon Sep 17 00:00:00 2001 From: etheisen Date: Wed, 14 Feb 1996 07:06:41 +0000 Subject: [PATCH] Command line arguments were not being handled correctly. Modified for proper funtionality and for compliance with manpage. --- games/backgammon/common_source/save.c | 2 +- games/backgammon/common_source/subs.c | 156 +++++++++++++++----------- 2 files changed, 90 insertions(+), 68 deletions(-) diff --git a/games/backgammon/common_source/save.c b/games/backgammon/common_source/save.c index aa86cecfa1b..fbc381c2682 100644 --- a/games/backgammon/common_source/save.c +++ b/games/backgammon/common_source/save.c @@ -52,7 +52,7 @@ static char exist2[] = "' already exists.\nAre you sure you want to use this file?"; static char cantuse[] = "\nCan't use "; static char saved[] = "This game has been saved on the file '"; -static char type[] = "'.\nType \"backgammon "; +static char type[] = "'.\nType \"backgammon -s "; static char rec[] = "\" to recover your game.\n\n"; static char cantrec[] = "Can't recover file: "; diff --git a/games/backgammon/common_source/subs.c b/games/backgammon/common_source/subs.c index ab38c956d0a..901071586bf 100644 --- a/games/backgammon/common_source/subs.c +++ b/games/backgammon/common_source/subs.c @@ -52,15 +52,15 @@ static char plwhite[] = "Player is white, computer is red."; static char nocomp[] = "(No computer play.)"; char *descr[] = { - "Usage: backgammon [-] [n r w b pr pw pb t3a]\n", - "\t-\tgets this list\n\tn\tdon't ask for rules or instructions", - "\tr\tplayer is red (implies n)\n\tw\tplayer is white (implies n)", - "\tb\ttwo players, red and white (implies n)", - "\tpr\tprint the board before red's turn", - "\tpw\tprint the board before white's turn", - "\tpb\tprint the board before both player's turn", - "\tterm\tterminal is a term", - "\tsfile\trecover saved game from file", + "Usage: backgammon [-] [-nrwb] [-pr] [-pw] [-pb] [-t ] [-s ]\n", + "\t-\tgets this list\n\t-n\tdon't ask for rules or instructions", + "\t-r\tplayer is red (implies n)\n\t-w\tplayer is white (implies n)", + "\t-b\ttwo players, red and white (implies n)", + "\t-pr\tprint the board before red's turn", + "\t-pw\tprint the board before white's turn", + "\t-pb\tprint the board before both player's turn", + "\t-t term\tterminal is type term", + "\t-s file\trecover previously saved game from file", 0 }; @@ -309,81 +309,103 @@ register char ***arg; { register char **s; + register int i, j; /* process arguments here. dashes are ignored, nbrw are ignored - if the game is being recovered */ + if the game is being recovered */ s = *arg; - while ((s[0] != NULL) && (s[0][0] == '-')) { - switch (s[0][1]) { - /* don't ask if rules or instructions needed */ - case 'n': - if (rflag) + /* + * Loop through 1 cmdline arg block. + * Must start with a '-'. + */ + for (i = 0; (s[0][0] == '-') && (s[0][i] != NULL); i++) { + switch (s[0][i]) { + + /* don't ask if rules or instructions needed */ + case 'n': + if (rflag) + break; + aflag = 0; + args[acnt++] = 'n'; break; - aflag = 0; - args[acnt++] = 'n'; - break; - /* player is both read and white */ - case 'b': - if (rflag) + /* player is both read and white */ + case 'b': + if (rflag) + break; + pnum = 0; + aflag = 0; + args[acnt++] = 'b'; break; - pnum = 0; - aflag = 0; - args[acnt++] = 'b'; - break; - /* player is red */ - case 'r': - if (rflag) + /* player is red */ + case 'r': + if (rflag) + break; + pnum = -1; + aflag = 0; + args[acnt++] = 'r'; break; - pnum = -1; - aflag = 0; - args[acnt++] = 'r'; - break; - /* player is white */ - case 'w': - if (rflag) + /* player is white */ + case 'w': + if (rflag) + break; + pnum = 1; + aflag = 0; + args[acnt++] = 'w'; break; - pnum = 1; - aflag = 0; - args[acnt++] = 'w'; - break; - /* print board after move according to following character */ - case 'p': - if (s[0][2] != 'r' && s[0][2] != 'w' && s[0][2] != 'b') + /* print board after move according to + following character */ + case 'p': + if (s[0][i-1] == '-' && s[0][2] == 'r' && + s[0][2] == 'w' && s[0][2] == 'b') { + args[acnt++] = 'p'; + args[acnt++] = s[0][2]; + if (s[0][2] == 'r') + bflag = 1; + if (s[0][2] == 'w') + bflag = -1; + if (s[0][2] == 'b') + bflag = 0; + } + i++; /* Blindly skip next char */ + break; + + /* use spec'd term from /etc/termcap */ + case 't': + if (s[0][1-i] != '-') + break; + if (s[0][2] == '\0') { /* get terminal caps */ + s++; + tflag = getcaps (*s); + } + else + tflag = getcaps (&s[0][2]); break; - args[acnt++] = 'p'; - args[acnt++] = s[0][2]; - if (s[0][2] == 'r') - bflag = 1; - if (s[0][2] == 'w') - bflag = -1; - if (s[0][2] == 'b') - bflag = 0; - break; - case 't': - if (s[0][2] == '\0') { /* get terminal caps */ + /* restore saved game */ + case 's': + if (s[0][i-1] != '-') + break; s++; - tflag = getcaps (*s); - } else - tflag = getcaps (&s[0][2]); - break; + /* recover file */ + recover (s[0]); + break; - case 's': - s++; - /* recover file */ - recover (s[0]); - break; - } - s++; - } - if (s[0] != 0) - recover(s[0]); + /* print cmdline options */ + case '-': + if (strlen(&(s[0][0])) == 1) { + for (j = 0; descr[j] != NULL; j++) + printf("%s\n", descr[j]); + exit(0); + } + break; + } /* end switch */ + } /* end for */ } init () { -- 2.20.1