Branch: Tag:

1997-08-31

1997-08-31 16:46:15 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added optional extra argument "throw_errors" to all functions able to call exit().

Rev: lib/modules/Getopt.pmod:1.4

12:    array|string shortform,    array|string|void longform,    array|string|void envvars, -  mixed|void def) +  mixed|void def, +  int|void throw_errors)   {    mixed value;    int i,hasarg;
46:    {    if(i == sizeof(argv)-1)    { +  if (throw_errors) { +  throw(({ "No argument to option "+tmp+".\n", +  backtrace() })); +  } else {    werror("No argument to option "+tmp+".\n");    exit(1);    } -  +  }    value=argv[i+1];    argv[i+1]=0;    }
74:    {    if(i == sizeof(argv)-1)    { +  if (throw_errors) { +  throw(({ "No argument to option -"+argv[i][j..j]+".\n", +  backtrace() })); +  } else {    werror("No argument to option -"+argv[i][j..j]+".\n");    exit(1);    } -  +  }       value=argv[i+1];    argv[i+1] = 0;
120:   #define ENV 3   #define DEF 4    - mixed *find_all_options(string *argv, mixed *options, void|int posix_me_harder) + mixed *find_all_options(string *argv, mixed *options, +  void|int posix_me_harder, void|int throw_errors)   {    mapping quick=([]);    foreach(options, mixed opt)
162:    {    if(e==sizeof(argv)-1)    { +  if (throw_errors) { +  throw(({ "No argument to option "+opt+".\n", +  backtrace() })); +  } else {    werror("No argument to option "+opt+".\n");    exit(1);    } -  +  }    arg=argv[e+1];    argv[e+1]=0;    }
187:    {    if(e==sizeof(argv)-1)    { +  if (throw_errors) { +  throw(({ "No argument to option "+opt+".\n", +  backtrace() })); +  } else {    werror("No argument to option "+opt+".\n");    exit(1);    } -  +  }    arg=argv[e+1];    argv[e+1]=0;    }else{
240:   }       - string *get_args(string *argv, void|int posix_me_harder) + string *get_args(string *argv, void|int posix_me_harder, void|int throw_errors)   {    int i;    for(i=1;i<sizeof(argv);i++)
254:    argv[i]=0;    break;    }else{ +  if (throw_errors) { +  throw(({ "Unknown option "+argv[i]+".\n", +  backtrace() })); +  } else {    werror("Unknown option "+argv[i]+".\n");    exit(1);    } -  +  }    }else{ -  if(strlen(argv[i]) == 2) +  if(strlen(argv[i]) == 2) { +  if (throw_errors) { +  throw(({ "Unknown option "+argv[i]+".\n", +  backtrace() })); +  } else {    werror("Unknown option "+argv[i]+".\n"); -  else +  } +  } else { +  if (throw_errors) { +  throw(({ "Unknown options "+argv[i]+".\n", +  backtrace() })); +  } else {    werror("Unknown options "+argv[i]+".\n"); -  +  } +  }    exit(1);    }    }else{