Re: user/5222

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

Re: user/5222

Ruslan Ermilov
The following reply was made to PR user/5222; it has been noted by GNATS.

From: Ruslan Ermilov <[hidden email]>
To: [hidden email]
Cc:  
Subject: Re: user/5222
Date: Mon, 4 Sep 2006 23:29:16 +0400

 An alternative approach would be to adopt the technique used
 in Ian Taylor's UUCP package.
 
 %%%
 Index: cu.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/tip/tip/cu.c,v
 retrieving revision 1.6
 diff -u -p -r1.6 cu.c
 --- cu.c 31 Aug 2006 14:14:29 -0000 1.6
 +++ cu.c 4 Sep 2006 19:18:01 -0000
 @@ -60,7 +60,26 @@ cumain(int argc, char *argv[])
  CU = DV = NOSTR;
  BR = DEFBR;
  parity = 0; /* none */
 - while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) {
 +
 + /*
 + * We want to accept -# as a speed.  It's easiest to look through
 + * the arguments, replace -# with -s#, and let getopt() handle it.
 + */
 + for (i = 1; i < argc; i++) {
 + if (argv[i][0] == '-' &&
 +    argv[i][1] >= '0' && argv[i][1] <= '9') {
 + asprintf(&cp, "-s%s", argv[i] + 1);
 + if (cp == NULL) {
 + fprintf(stderr,
 +    "%s: cannot convert -# to -s#\n",
 +    __progname);
 + exit(3);
 + }
 + argv[i] = cp;
 + }
 + }
 +
 + while ((ch = getopt(argc, argv, "a:l:s:htoe")) != -1) {
  switch (ch) {
  case 'a':
  CU = optarg;
 @@ -105,13 +124,6 @@ cumain(int argc, char *argv[])
  else
  parity = -1; /* even */
  break;
 - case '0': case '1': case '2': case '3': case '4':
 - case '5': case '6': case '7': case '8': case '9':
 - if (CU)
 - CU[strlen(CU)-1] = ch;
 - if (DV)
 - DV[strlen(DV)-1] = ch;
 - break;
  default:
  cuusage();
  break;
 %%%
 
 
 Cheers,
 --
 Ruslan Ermilov
 [hidden email]
 FreeBSD committer