ksh: make ksh_getopt() return -1, not EOF

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ksh: make ksh_getopt() return -1, not EOF

Alexey Dobriyan-2
Just like getopt(3).

Index: bin/ksh/c_ksh.c
===================================================================
RCS file: /cvs/src/bin/ksh/c_ksh.c,v
retrieving revision 1.28
diff -u -p -r1.28 c_ksh.c
--- bin/ksh/c_ksh.c 2005/12/11 20:31:21 1.28
+++ bin/ksh/c_ksh.c 2006/03/09 20:31:29
@@ -24,7 +24,7 @@ c_cd(char **wp)
  int phys_path;
  char *cdpath;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "LP")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, "LP")) != -1)
  switch (optc) {
  case 'L':
  physical = 0;
@@ -159,7 +159,7 @@ c_pwd(char **wp)
  int physical = Flag(FPHYSICAL);
  char *p;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "LP")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, "LP")) != -1)
  switch (optc) {
  case 'L':
  physical = 0;
@@ -241,7 +241,7 @@ c_print(char **wp)
  } else {
  int optc;
  const char *options = "Rnprsu,";
- while ((optc = ksh_getopt(wp, &builtin_opt, options)) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, options)) != -1)
  switch (optc) {
  case 'R': /* fake BSD echo command */
  flags |= PO_PMINUSMINUS;
@@ -398,7 +398,7 @@ c_whence(char **wp)
  int fcflags;
  const char *options = iam_whence ? "pv" : "pvV";
 
- while ((optc = ksh_getopt(wp, &builtin_opt, options)) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, options)) != -1)
  switch (optc) {
  case 'p':
  pflag = 1;
@@ -557,7 +557,7 @@ c_typeset(char **wp)
  * Here, the number must follow the RLZi option, but is optional
  * (see the # kludge in ksh_getopt()).
  */
- while ((optc = ksh_getopt(wp, &builtin_opt, options)) != EOF) {
+ while ((optc = ksh_getopt(wp, &builtin_opt, options)) != -1) {
  flag = 0;
  switch (optc) {
  case 'L':
@@ -825,7 +825,7 @@ c_alias(char **wp)
  int optc;
 
  builtin_opt.flags |= GF_PLUSOPT;
- while ((optc = ksh_getopt(wp, &builtin_opt, "dprtUx")) != EOF) {
+ while ((optc = ksh_getopt(wp, &builtin_opt, "dprtUx")) != -1) {
  prefix = builtin_opt.info & GI_PLUS ? '+' : '-';
  switch (optc) {
  case 'd':
@@ -959,7 +959,7 @@ c_unalias(char **wp)
  int rv = 0, all = 0;
  int optc;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "adt")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, "adt")) != -1)
  switch (optc) {
  case 'a':
  all = 1;
@@ -1029,7 +1029,7 @@ c_jobs(char **wp)
  int nflag = 0;
  int rv = 0;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "lpnz")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, "lpnz")) != -1)
  switch (optc) {
  case 'l':
  flag = 1;
@@ -1129,7 +1129,7 @@ c_kill(char **wp)
  } else {
  int optc;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "ls:")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, "ls:")) != -1)
  switch (optc) {
  case 'l':
  lflag = 1;
@@ -1333,7 +1333,7 @@ c_bind(char **wp)
  int optc, rv = 0, macro = 0, list = 0;
  char *cp;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "lm")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, "lm")) != -1)
  switch (optc) {
  case 'l':
  list = 1;
Index: bin/ksh/c_sh.c
===================================================================
RCS file: /cvs/src/bin/ksh/c_sh.c,v
retrieving revision 1.31
diff -u -p -r1.31 c_sh.c
--- bin/ksh/c_sh.c 2005/10/08 18:07:31 1.31
+++ bin/ksh/c_sh.c 2006/03/09 20:31:29
@@ -58,7 +58,7 @@ c_umask(char **wp)
  mode_t old_umask;
  int optc;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "S")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, "S")) != -1)
  switch (optc) {
  case 'S':
  symbolic = 1;
@@ -252,7 +252,7 @@ c_read(char **wp)
  struct tbl *vp;
  char *xp = NULL;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "prsu,")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, "prsu,")) != -1)
  switch (optc) {
  case 'p':
  if ((fd = coproc_getfd(R_OK, &emsg)) < 0) {
@@ -646,7 +646,7 @@ c_unset(char **wp)
  int optc, unset_var = 1;
  int ret = 0;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "fv")) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, "fv")) != -1)
  switch (optc) {
  case 'f':
  unset_var = 0;
@@ -787,7 +787,7 @@ timex_hook(struct op *t, char **volatile
 
  ksh_getopt_reset(&opt, 0);
  opt.optind = 0; /* start at the start */
- while ((optc = ksh_getopt(wp, &opt, ":p")) != EOF)
+ while ((optc = ksh_getopt(wp, &opt, ":p")) != -1)
  switch (optc) {
  case 'p':
  t->str[0] |= TF_POSIX;
@@ -843,7 +843,7 @@ c_mknod(char **wp)
  void *set = NULL;
  mode_t mode = 0, oldmode = 0;
 
- while ((optc = ksh_getopt(wp, &builtin_opt, "m:")) != EOF) {
+ while ((optc = ksh_getopt(wp, &builtin_opt, "m:")) != -1) {
  switch (optc) {
  case 'm':
  set = setmode(builtin_opt.optarg);
Index: bin/ksh/c_ulimit.c
===================================================================
RCS file: /cvs/src/bin/ksh/c_ulimit.c,v
retrieving revision 1.14
diff -u -p -r1.14 c_ulimit.c
--- bin/ksh/c_ulimit.c 2005/03/30 17:16:37 1.14
+++ bin/ksh/c_ulimit.c 2006/03/09 20:31:30
@@ -69,7 +69,7 @@ c_ulimit(char **wp)
  *p = '\0';
  }
  what = 'f';
- while ((optc = ksh_getopt(wp, &builtin_opt, options)) != EOF)
+ while ((optc = ksh_getopt(wp, &builtin_opt, options)) != -1)
  switch (optc) {
  case 'H':
  how = HARD;
Index: bin/ksh/history.c
===================================================================
RCS file: /cvs/src/bin/ksh/history.c,v
retrieving revision 1.32
diff -u -p -r1.32 history.c
--- bin/ksh/history.c 2005/12/11 18:53:51 1.32
+++ bin/ksh/history.c 2006/03/09 20:31:46
@@ -65,7 +65,7 @@ c_fc(char **wp)
  }
 
  while ((optc = ksh_getopt(wp, &builtin_opt,
-    "e:glnrs0,1,2,3,4,5,6,7,8,9,")) != EOF)
+    "e:glnrs0,1,2,3,4,5,6,7,8,9,")) != -1)
  switch (optc) {
  case 'e':
  p = builtin_opt.optarg;
Index: bin/ksh/misc.c
===================================================================
RCS file: /cvs/src/bin/ksh/misc.c,v
retrieving revision 1.29
diff -u -p -r1.29 misc.c
--- bin/ksh/misc.c 2006/03/06 10:44:10 1.29
+++ bin/ksh/misc.c 2006/03/09 20:31:50
@@ -359,7 +359,7 @@ parse_args(char **argv,
  } else
  opts = set_opts;
  ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT);
- while ((optc = ksh_getopt(argv, &go, opts)) != EOF) {
+ while ((optc = ksh_getopt(argv, &go, opts)) != -1) {
  set = (go.info & GI_PLUS) ? 0 : 1;
  switch (optc) {
  case 'A':
@@ -913,14 +913,14 @@ ksh_getopt(char **argv, Getopt *go, cons
  go->optind++;
  go->p = 0;
  go->info |= GI_MINUSMINUS;
- return EOF;
+ return -1;
  }
  if (arg == (char *) 0 ||
     ((flag != '-' ) && /* neither a - nor a + (if + allowed) */
     (!(go->flags & GF_PLUSOPT) || flag != '+')) ||
     (c = arg[1]) == '\0') {
  go->p = 0;
- return EOF;
+ return -1;
  }
  go->optind++;
  go->info &= ~(GI_MINUS|GI_PLUS);