home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume19 / parseargs / patch05c < prev    next >
Encoding:
Text File  |  1991-05-17  |  55.4 KB  |  1,551 lines

  1. Newsgroups: comp.sources.misc
  2. From: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
  3. Subject:  v19i084:  parseargs - functions to parse command line argument, Patch05c/5
  4. Message-ID: <1991May17.181700.22341@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 4747f9bf175800bfb90cd1fcd9a794e4
  6. Date: Fri, 17 May 1991 18:17:00 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
  10. Posting-number: Volume 19, Issue 84
  11. Archive-name: parseargs/patch05c
  12. Patch-To: parseargs: Volume 17, Issue 45-57
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file PATCH05 continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 3; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping PATCH05'
  32. else
  33. echo 'x - continuing file PATCH05'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'PATCH05' &&
  35. -    { "argv", "set %s=", "'",   "';\n",  "'\\%c'",   "'" },
  36. -    /* KSH : Positional parms in -- ; Assignment Syntax: name="value"; */
  37. -    { "--", "%s=",       "'",   "';\n",  "'\\%c'",   "'" },
  38. -    /* SH : Positional parms in -- ; Assignment Syntax: name="value"; */
  39. -    { "--", "%s=",       "'",   "';\n",  "'\\%c'",   "'" },
  40. -    /* RC : Positional parms in -- ; Assignment Syntax: name="value"; */
  41. -    { "*", "%s=",       "'",   "';\n",  "''",   "'" },
  42. -    /* AWK : Positional parms in ARGV; Assignment Syntax: name\nvalue\n\n; */
  43. -    { "ARGV", "%s\n",    "",   "\n\n",  "'\034'",   "\n" },
  44. X  
  45. -    /* PERL : Positional parms in ARGV; Assignment Syntax: $name=value\n; */
  46. -    { "ARGV", "$%s = ",  "'",   "';\n",  "\\'",   "'" }
  47. - };
  48. X  /*************************************************************************/
  49. X  
  50. X     /* define all current arg-vector types */
  51. --- 189,309 ----
  52. X  **    the Bourne shell ("sh") will be assumed.
  53. X  **
  54. X  **    If the user wishes to use a value other than "TRUE" for a boolean
  55. ! **    flag that is true, this may be done using the -T string option.  The
  56. ! **    same may also be done for a boolean flag that is false using the -F
  57. ! **    string option.
  58. X  **
  59. X  **    Parseargs will only set the values of variables that correspond to
  60. ! **    arguments that were given on the command line. If a particular
  61. ! **    argument was not supplied on the command line, then no assignment is
  62. ! **    made for the corresponding shell variable and it will have the same
  63. ! **    value that it had before parseargs was invoked. The only exception to
  64. ! **    this is that if the -u option is specified, then the positional
  65. ! **    parameters are unset before any shell variable assignments (which may
  66. ! **    reset the positional parameters) are made.
  67. X  ***^^*********************************************************************/
  68. X  
  69. !    /* type used to index into the shell-info array */
  70. ! typedef unsigned  shellidx_t;
  71. !    /* possible shell names and corresponding types */
  72. ! typedef enum {
  73. !    SH,
  74. !    BASH,
  75. !    CSH,   /* tcsh & itcsh are equivalent to csh for our purposes */
  76. !    KSH,
  77. !    RC,
  78. !    ZSH,
  79. !    ASH,   /* not yet supported */
  80. !    CLAM,  /* not yet supported */
  81. !    AWK,
  82. !    PERL
  83. ! } shell_t;
  84. X  
  85. X     /* structure for shell-specific info */
  86. X  typedef struct {
  87. !    shell_t  type;    /* type of shell */
  88. !    char  *name;      /* name of the shell */
  89. !    char  *unset;     /* syntax used to unset positional parameters */
  90. !    char  *sclset;    /* syntax used to set scalars (%s is the scalar name) */
  91. !    char  *sclpfx;    /* prefix used for scalars */
  92. !    char  *sclsfx;    /* suffix used for scalars */
  93. !    char  *aryset;    /* syntax used to set arrays (%s is the array name) */
  94. !    char  *arypfx;    /* prefix used for arrays */
  95. !    char  *arysep;    /* separator used for arrays */
  96. !    char  *arysfx;    /* suffix used for arrays */
  97. X     char  *escape;    /* format to escape chars (%c is the char to escape) */
  98. X     char  *metachars; /* special characters that need to be escaped */
  99. X  } shell_info;
  100. X  
  101. !    /* array of shell info records for supported shells */
  102. X  static CONST shell_info  Shell[] = {
  103. +    {
  104. +       SH,  "sh",
  105. +       "shift $#;\n",  
  106. +       "%s=",  "'",  "';\n",
  107. +       "%s=",  "'",  "'%s'",  "';\n",
  108. +       "'\\%c'",  "'"
  109. +    },
  110. +    {
  111. +       BASH,  "bash",
  112. +       "shift $#;\n",  
  113. +       "%s=",  "'",  "';\n",
  114. +       "%s=",  "'",  "'%s'",  "';\n",
  115. +       "'\\%c'",  "'"
  116. +    },
  117. +    {
  118. +       KSH,  "ksh",
  119. +       "set --;\n",  
  120. +       "%s=",  "'",  "';\n",
  121. +       "set %cA %s ",  "'",  "'%s'",  "';\n",
  122. +       "'\\%c'",  "'"
  123. +    },
  124. +    {
  125. +       CSH,  "csh",
  126. +       "set argv=();\n",  
  127. +       "set %s=",  "'",  "';\n",
  128. +       "set %s=",  "( '",  "'%s'",  "' );\n",
  129. +       "'\\%c'",  "'"
  130. +    },
  131. +    {
  132. +       ZSH,  "zsh",
  133. +       "argv=();\n",  
  134. +       "%s=",  "'",  "';\n",
  135. +       "%s=",  "( '",  "'%s'",  "' );\n",
  136. +       "'\\%c'",  "'"
  137. +    },
  138. +    {
  139. +       RC,  "rc",
  140. +       "*=();\n",  
  141. +       "%s=",  "'",  "';\n",
  142. +       "%s=",  "( '",  "'%s'",  "' );\n",
  143. +       "''",  "'"
  144. +    },
  145. +    {
  146. +       PERL,  "perl",
  147. +       "@ARGV = ();\n",  
  148. +       "$%s = ",  "'",  "';\n",
  149. +       "@%s = ",  "( '",  "', '",  "' );\n",
  150. +       "\\%c",  "'"
  151. +    },
  152. +    {
  153. +       AWK,  "awk",
  154. +       "ARGV\n\n",  
  155. +       "%s\n",  "",  "\n\n",
  156. +       "%s\n",  "",  "%s",  "\n\n",
  157. +       "''",  "'"
  158. +    }
  159. + };
  160. X  
  161. ! static size_t NumShells = ( sizeof(Shell) / sizeof(shell_info) );
  162. X  
  163. X  
  164. X  /*************************************************************************/
  165. X  
  166. X     /* define all current arg-vector types */
  167. ***************
  168. *** 319,325 ****
  169. X  static  ARGDESC   *UsrArgd = ARGDESCNULL;       /* users arg-table */
  170. X  static  cmdarg_t  *UsrVals = CMDARGNULL;        /* variable names & values */
  171. X  static  int        UsrArgc = 0;                 /* # of arg-table entries */
  172. ! static  shell_t    UsrSh;                       /* shell indicator */
  173. X  static  BOOL       UseStdin = TRUE;             /* read argd from stdin */
  174. X  
  175. X  static  char   *ShellName  = CHARNULL;  /* name of user's shell */
  176. --- 374,380 ----
  177. X  static  ARGDESC   *UsrArgd = ARGDESCNULL;       /* users arg-table */
  178. X  static  cmdarg_t  *UsrVals = CMDARGNULL;        /* variable names & values */
  179. X  static  int        UsrArgc = 0;                 /* # of arg-table entries */
  180. ! static  shellidx_t  UsrSh;                      /* shell indicator */
  181. X  static  BOOL       UseStdin = TRUE;             /* read argd from stdin */
  182. X  
  183. X  static  char   *ShellName  = CHARNULL;  /* name of user's shell */
  184. ***************
  185. *** 928,938 ****
  186. X  #endif
  187. X  {
  188. X     int  isatty  ARGS((int));
  189. !    int  fread   ARGS((ARBPTR, size_t, size_t, FILE *));
  190. X     FILE *fp;
  191. X     char *buf;
  192. !    register int  nchars = 0;   /* # bytes read */
  193. !    register int  bufsiz = 0;   /* actual buffer-size needed */
  194. X  
  195. X     /* open file if necessary */
  196. X     if ( UseStdin )  {
  197. --- 983,997 ----
  198. X  #endif
  199. X  {
  200. X     int  isatty  ARGS((int));
  201. ! #ifdef __ANSI_C__
  202. !    size_t  fread( ARBPTR, size_t, size_t, FILE * );
  203. ! #else
  204. !    int  fread();
  205. ! #endif
  206. X     FILE *fp;
  207. X     char *buf;
  208. !    register size_t  nchars = 0;   /* # bytes read */
  209. !    register size_t  bufsiz = 0;   /* actual buffer-size needed */
  210. X  
  211. X     /* open file if necessary */
  212. X     if ( UseStdin )  {
  213. ***************
  214. *** 967,977 ****
  215. X     */
  216. X     do {
  217. X           /* read fildes into the buffer */
  218. !       nchars = fread( &(buf[bufsiz]), sizeof(char), BUFFER_SIZE, fp );
  219. !       if ( nchars < 0 )   {
  220. X           eprintf( "\
  221. X  %s: Fatal Error:\n\
  222. ! \tBad status from read() while reading argument descriptor table\n",
  223. X                    Cmd_Name );
  224. X           free(buf);
  225. X           cleanup();
  226. --- 1026,1036 ----
  227. X     */
  228. X     do {
  229. X           /* read fildes into the buffer */
  230. !       nchars = (size_t) fread( &(buf[bufsiz]), sizeof(char), BUFFER_SIZE, fp );
  231. !       if ( ferror(fp) )   {
  232. X           eprintf( "\
  233. X  %s: Fatal Error:\n\
  234. ! \tBad return from fread() while reading argument descriptor table\n",
  235. X                    Cmd_Name );
  236. X           free(buf);
  237. X           cleanup();
  238. ***************
  239. *** 997,1008 ****
  240. X  
  241. X  
  242. X  /***************************************************************************
  243. ! ** ^FUNCTION: get_shell_type - return shell corresponding to given string
  244. X  **
  245. X  ** ^SYNOPSIS:
  246. X  */
  247. X  #ifndef __ANSI_C__
  248. !    static shell_t get_shell_type( sh_str )
  249. X  /*
  250. X  ** ^PARAMETERS:
  251. X  */
  252. --- 1056,1067 ----
  253. X  
  254. X  
  255. X  /***************************************************************************
  256. ! ** ^FUNCTION: get_shell_index - return shell corresponding to given string
  257. X  **
  258. X  ** ^SYNOPSIS:
  259. X  */
  260. X  #ifndef __ANSI_C__
  261. !    static shell_t get_shell_index( sh_str )
  262. X  /*
  263. X  ** ^PARAMETERS:
  264. X  */
  265. ***************
  266. *** 1012,1018 ****
  267. X  #endif  /* !__ANSI_C__ */
  268. X  
  269. X  /* ^DESCRIPTION:
  270. ! **    Get_shell_type will retrun the shell-type for the named shell. If
  271. X  **    No corresponding shell is known, then an error message is printed
  272. X  **    and execution is terminated.
  273. X  **
  274. --- 1071,1077 ----
  275. X  #endif  /* !__ANSI_C__ */
  276. X  
  277. X  /* ^DESCRIPTION:
  278. ! **    Get_shell_index will return the shell-type for the named shell. If
  279. X  **    No corresponding shell is known, then an error message is printed
  280. X  **    and execution is terminated.
  281. X  **
  282. ***************
  283. *** 1029,1063 ****
  284. X  **    Trivial.
  285. X  ***^^**********************************************************************/
  286. X  #ifdef __ANSI_C__
  287. !    static shell_t get_shell_type ( const char *sh_str )
  288. X  #endif
  289. X  {
  290. !     if      ( strEQ( sh_str, BOURNE_SHELL ) )
  291. !        return   SH;
  292. !     else if ( strEQ( sh_str, TC_SHELL ) )
  293. !        return   TCSH;
  294. !     else if ( strEQ( sh_str, C_SHELL ) )
  295. !        return   CSH;
  296. !     else if ( strEQ( sh_str, KORN_SHELL ) )
  297. !        return   KSH;
  298. !     else if ( strEQ( sh_str, BOURNE_AGAIN_SHELL ) )
  299. !        return   BASH;
  300. !     else if ( strEQ( sh_str, RC_SHELL ) )
  301. !        return   RC;
  302. !     else if ( strEQ( sh_str, AWK_LANG ) )
  303. !        return   AWK;
  304. !     else if ( strEQ( sh_str, PERL_LANG ) )
  305. !        return   PERL;
  306. !     else {
  307. !        eprintf( "%s: Fatal Error: unknown shell '%s'\n",
  308. !                 Cmd_Name, sh_str );
  309. !        eprintf( "\tKnown shells are: %s, %s, %s, %s, %s, %s, %s, and %s\n",
  310. !                 AWK_LANG, BOURNE_AGAIN_SHELL, C_SHELL, KORN_SHELL, RC_SHELL,
  311. !                 PERL_LANG, BOURNE_SHELL, TC_SHELL );
  312. !        cleanup();
  313. !        exit( e_SYNTAX );
  314. !     }
  315. X  }
  316. X  
  317. X  
  318. --- 1088,1120 ----
  319. X  **    Trivial.
  320. X  ***^^**********************************************************************/
  321. X  #ifdef __ANSI_C__
  322. !    static shellidx_t get_shell_index ( const char *sh_str )
  323. X  #endif
  324. X  {
  325. !    int  i;
  326. !    register char *sh = sh_str;
  327. !       /* special case to recognize tcsh & itcsh */
  328. !    if ( strEQ( sh, "tcsh" ) )  ++sh;
  329. !    if ( strEQ( sh, "itcsh" ) )  sh += 2;
  330. !    for ( i = 0 ; i < NumShells ; i++ ) {
  331. !       if ( strEQ( sh, Shell[i].name ) )   return  (shellidx_t) i;
  332. !    }
  333. !    usrerr( "Unknown shell \"%s\"", sh_str );
  334. !    eprintf( "\tKnown shells are listed below:\n" );
  335. !    for ( i = 0 ; i < NumShells ; i++ ) {
  336. !       if ( strEQ( "csh", Shell[i].name ) ) {
  337. !          eprintf( "\t\tcsh/tcsh/itcsh\n" );
  338. !       }
  339. !       else {
  340. !          eprintf( "\t\t%s\n", Shell[i].name );
  341. !       }
  342. !    }
  343. !    cleanup();
  344. !    exit( e_SYNTAX );
  345. X  }
  346. X  
  347. X  
  348. ***************
  349. *** 1316,1324 ****
  350. X     static void put_char_arg( FILE *fp, int ch )
  351. X  #endif
  352. X  {
  353. !       /* newline needs to be escaped specially for CSH, TCSH, and PERL */
  354. X     if ( ch == '\n' ) {
  355. !       if ( UsrSh == CSH   || UsrSh == TCSH ) {
  356. X           fprintf( fp, "\\\n" );
  357. X           return;
  358. X        }
  359. --- 1373,1381 ----
  360. X     static void put_char_arg( FILE *fp, int ch )
  361. X  #endif
  362. X  {
  363. !       /* newline needs to be escaped specially for CSH */
  364. X     if ( ch == '\n' ) {
  365. !       if ( Shell[ UsrSh ].type == CSH ) {
  366. X           fprintf( fp, "\\\n" );
  367. X           return;
  368. X        }
  369. ***************
  370. *** 1516,1525 ****
  371. X  #endif  /* !__ANSI_C__ */
  372. X  
  373. X  /* ^DESCRIPTION:
  374. ! **    Parseargs treats ARGLIST and ARGVEC arguments in a special way. The
  375. ! **    method used for setting up an argument list depends largely upon the
  376. ! **    syntax of shell that was specified on the command line via the -s option
  377. ! **    (although an ARGLIST argument is treated the same as an ARGVEC argument).
  378. X  **
  379. X  ** ^Resetting_the_Positional_Parameters_to_an_Argument_List:
  380. X  **    For the Bourne, Bourne-Again, and Korn shells, if the variable name
  381. --- 1573,1586 ----
  382. X  #endif  /* !__ANSI_C__ */
  383. X  
  384. X  /* ^DESCRIPTION:
  385. ! **    Parseargs treats ARGLIST arguments in a special way. The method used
  386. ! **    for setting up an argument list depends largely upon the syntax of
  387. ! **    shell that was specified on the command line via the -s option
  388. ! **    (although ARGLIST arguments are treated exactly the same as ARGVEC
  389. ! **    arguments).  With the exception perl which always uses a comma to
  390. ! **    separate array elements, all shells will use the string specified
  391. ! **    with the -S option as the field separator between elements of an
  392. ! **    array (the default field separator is a space character).
  393. X  **
  394. X  ** ^Resetting_the_Positional_Parameters_to_an_Argument_List:
  395. X  **    For the Bourne, Bourne-Again, and Korn shells, if the variable name
  396. ***************
  397. *** 1532,1544 ****
  398. X  **    parameters will be unset if the associated list of command line
  399. X  **    arguments is not encountered).
  400. X  **
  401. ! **    Similarly for the C and TC shells, if the variable name corresponding
  402. ! **    to the ARGLIST argument is "argv", then the positional parameters
  403. ! **    of the calling program will be re-assigned to the contents of the
  404. ! **    argument list.
  405. X  **
  406. X  **    For the Plan 9 shell (rc), if the variable name corresponding to the
  407. ! **    ARGLIST argument is "*", then the positional parameters of the calling
  408. X  **    program will be re-assigned to the contents of the argument list.
  409. X  **
  410. X  **    For awk and perl, if the variable name corresponding to the ARGLIST
  411. --- 1593,1605 ----
  412. X  **    parameters will be unset if the associated list of command line
  413. X  **    arguments is not encountered).
  414. X  **
  415. ! **    Similarly for the C & Z shells (zsh, csh, tcsh, itcsh), if the
  416. ! **    variable name corresponding to the ARGLIST argument is "argv", then
  417. ! **    the positional parameters of the calling program will be re-assigned
  418. ! **    to the contents of the argument list.
  419. X  **
  420. X  **    For the Plan 9 shell (rc), if the variable name corresponding to the
  421. ! **    ARGLIST argument is "*", then the positional parameters of then calling
  422. X  **    program will be re-assigned to the contents of the argument list.
  423. X  **
  424. X  **    For awk and perl, if the variable name corresponding to the ARGLIST
  425. ***************
  426. *** 1553,1562 ****
  427. X  **         name='arg1 arg2  ...'
  428. X  **
  429. X  **    After invoking parseargs, if you wish to go through all the words in
  430. ! **    the variable name and one of the words in name contains an IFS charac-
  431. ! **    ter (such as a space or a tab), then that particular word will be
  432. ! **    treated by the Bourne shell as two distinct words.
  433. ! **
  434. X  **    Also for the Bourne shell, If the associated variable name is NOT
  435. X  **    "--" and the -A option WAS specified, then that variable is treated
  436. X  **    as the root name of an array that is set using the following syntax:
  437. --- 1614,1622 ----
  438. X  **         name='arg1 arg2  ...'
  439. X  **
  440. X  **    After invoking parseargs, if you wish to go through all the words in
  441. ! **    the variable name and one of the words in name contains an IFS
  442. ! **    character (such as a space or a tab), then that particular word will
  443. ! **    be treated by the Bourne shell as two distinct words.
  444. X  **    Also for the Bourne shell, If the associated variable name is NOT
  445. X  **    "--" and the -A option WAS specified, then that variable is treated
  446. X  **    as the root name of an array that is set using the following syntax:
  447. ***************
  448. *** 1584,1590 ****
  449. X  **    "--" and the -A option WAS specified, then that variable is assigned
  450. X  **    using the +A option of the set command (which preserves any array
  451. X  **    elements that were not overwritten by the set command).
  452. - **
  453. X  **    It should be noted that there is a bug in versions of the Korn shell
  454. X  **    earlier than 11/16/88a, in which the following:
  455. X  **
  456. --- 1644,1649 ----
  457. ***************
  458. *** 1598,1613 ****
  459. X  **
  460. X  **         set  -A  save_parms  "$@"
  461. X  **
  462. ! ** ^C_and_TC_Shell_Argument_Lists:
  463. ! **    For the C and TC shells, ARGLIST variables are treated as word-lists
  464. ! **    and are assigned using the following syntax:
  465. X  **
  466. X  **         set  name = ( 'arg1'  'arg2'  ... )
  467. X  **
  468. X  **    The first item will be in $name[1], the second item will be in
  469. X  **    $name[2], etc ..., and all items may be given by $name.  Notice that
  470. ! **    Korn shell arrays start at index zero whereas C and TC shell word-
  471. ! **    lists start at index one.
  472. X  **
  473. X  ** ^Bourne-Again_Shell_Argument_Lists:
  474. X  **    At present, the Free Software Foundation's Bourne-Again shell is
  475. --- 1657,1672 ----
  476. X  **
  477. X  **         set  -A  save_parms  "$@"
  478. X  **
  479. ! ** ^C_Shell_Argument_Lists:
  480. ! **    For the C shells (csh, tcsh, itcsh), ARGLIST variables are treated as
  481. ! **    word-lists and are assigned using the following syntax:
  482. X  **
  483. X  **         set  name = ( 'arg1'  'arg2'  ... )
  484. X  **
  485. X  **    The first item will be in $name[1], the second item will be in
  486. X  **    $name[2], etc ..., and all items may be given by $name.  Notice that
  487. ! **    Korn shell arrays start at index zero whereas C shell word-lists start
  488. ! **    at index one.
  489. X  **
  490. X  ** ^Bourne-Again_Shell_Argument_Lists:
  491. X  **    At present, the Free Software Foundation's Bourne-Again shell is
  492. ***************
  493. *** 1615,1631 ****
  494. X  **    bash supports arrays.
  495. X  **
  496. X  ** ^Plan_9_Shell_Argument_Lists:
  497. ! **    For the Plan 9 shell, if the associated variable name is not "*" then
  498. ! **    it is considered to be a word-list and set using the following syntax:
  499. X  **
  500. X  **         name=( 'arg1'  'arg2'  ... )
  501. X  **
  502. X  ** ^Awk_Argument_Lists:
  503. ! **    For awk, if the -A option is not given, then the output for thes
  504. X  **    variable-list will be a line with the variable name, followed by a
  505. X  **    line with each of the values (each value will be separated with the
  506. X  **    field separator specified using the -S option - which defaults to a
  507. ! **    space character):
  508. X  **
  509. X  **         name
  510. X  **         arg1  arg2  ...
  511. --- 1674,1702 ----
  512. X  **    bash supports arrays.
  513. X  **
  514. X  ** ^Plan_9_Shell_Argument_Lists:
  515. ! **    For the Plan 9 shell, if the associated variable name is not "*"
  516. ! **    then it is considered to be a word-list and set using the following
  517. ! **    syntax:
  518. X  **
  519. X  **         name=( 'arg1'  'arg2'  ... )
  520. X  **
  521. + ** ^Z_Shell_Argument_Lists:
  522. + **    For the Z shell, ARGLIST variables are treated as word-lists and are
  523. + **    assigned using the following syntax:
  524. + **
  525. + **         name = ( 'arg1'  'arg2'  ... )
  526. + **
  527. + **    The first item will be in $name[1], the second item will be in
  528. + **    $name[2], etc ..., and all items may be given by $name.  Notice that
  529. + **    Korn shell arrays start at index zero whereas Z and C shell word-lists
  530. + **    start at index one.
  531. + **
  532. X  ** ^Awk_Argument_Lists:
  533. ! **    For awk, if the -A option is not given, then the output for the
  534. X  **    variable-list will be a line with the variable name, followed by a
  535. X  **    line with each of the values (each value will be separated with the
  536. X  **    field separator specified using the -S option - which defaults to a
  537. ! **    space).
  538. X  **
  539. X  **         name
  540. X  **         arg1  arg2  ...
  541. ***************
  542. *** 1650,1662 ****
  543. X  **         @name=( 'arg1' , 'arg2' ,  ... );
  544. X  **
  545. X  ** ^A_Final_Note_on_Argument_Lists:
  546. ! **    The word-lists used by the C shell, the arrays used by the Korn shell,
  547. ! **    The Plan 9 shell, awk, & perl, and the positional parameters used by
  548. ! **    all shells (if overwritten by parseargs) will preserve any IFS
  549. ! **    characters in their contents.  That us to say that if an item in one
  550. ! **    of the aforementioned multi-word lists contains any IFS characters,
  551. ! **    it will not be split up into multiple items but will remain a single
  552. ! **    item which contains IFS characters.
  553. X  **
  554. X  ** ^REQUIREMENTS:
  555. X  **    <val> should correspond to the vlue of the argument indicated by <ad>
  556. --- 1721,1733 ----
  557. X  **         @name=( 'arg1' , 'arg2' ,  ... );
  558. X  **
  559. X  ** ^A_Final_Note_on_Argument_Lists:
  560. ! **    The word-lists used by the C and Z shells, the arrays used by the Korn
  561. ! **    shell, the Plan 9 shell, awk, perl, and the positional parameters used
  562. ! **    by all shells (if overwritten by parseargs) will preserve any IFS
  563. ! **    characters in their contents.  That is to say that if an item in one
  564. ! **    of the aforementioned multi-word lists contains any IFS characters, it
  565. ! **    will not be split up into multiple items but will remain a single item
  566. ! **    which contains IFS characters.
  567. X  **
  568. X  ** ^REQUIREMENTS:
  569. X  **    <val> should correspond to the vlue of the argument indicated by <ad>
  570. ***************
  571. *** 1676,1757 ****
  572. X     static void print_argvector( const ARGDESC *ad, const cmdarg_t *val )
  573. X  #endif
  574. X  {
  575. !    BOOL   is_array = TRUE;
  576. X     int    i;
  577. X     char   *varname;
  578. X  
  579. !    switch( UsrSh ) {
  580. !       case KSH :
  581. !          if ( strEQ( val->name, Shell[ UsrSh ].varname ) ) {
  582. !             fputs( "set -- ", stdout );
  583. !          }
  584. !          else {
  585. !             printf( "set %cA %s ", ((ModArr) ? '+' : '-'), val->name );
  586. !          }
  587. !          break;
  588. !       case TCSH : case CSH : case RC: case PERL :
  589. !          if ( UsrSh == PERL )
  590. !             printf( "@%s = ", val->name );
  591. !          else if ( UsrSh == RC )
  592. !             printf( "%s=", val->name );
  593. !          else /* UsrSh == CSH/TCSH */
  594. !             printf( "set %s=", val->name );
  595. !          fputc( '(', stdout );
  596. !          break;
  597. !       case BASH: case SH : case AWK:
  598. !          if ( UsrSh == AWK )  is_array = FALSE;
  599. !          if ( strEQ( val->name, Shell[ UsrSh ].varname ) ) {
  600. !             fputs( ((UsrSh == AWK) ? "ARGV\n" : "set -- "), stdout );
  601. !          }
  602. !          else {
  603. !             if ( ModArr )   { /* use fake array syntax */
  604. !                i = strlen( val->name );
  605. !                varname = (char *)ckalloc( (i + 4) * sizeof(char) );
  606. !                for ( i = 0 ; i < val->value.Vector.count ; i++ ) {
  607. !                   sprintf( varname, "%s%d", val->name, i+1 );
  608. !                   printf( Shell[ UsrSh ].setcmd, varname );
  609. !                   printf( Shell[ UsrSh ].prefix );
  610. !                   put_arg( stdout, ad, val, i );
  611. !                   printf( "%s", Shell[ UsrSh ].suffix );
  612. !                }
  613. !                sprintf( varname, "%s_count", val->name );
  614. !                printf( Shell[ UsrSh ].setcmd, varname );
  615. !                printf( Shell[ UsrSh ].prefix );
  616. !                printf( "%d", val->value.Vector.count );
  617. !                printf( "%s", Shell[ UsrSh ].suffix );
  618. !                free( varname );
  619. !                if ( val->value.Vector.array ) {
  620. !                   free( val->value.Vector.array );
  621. !                   val->value.Vector.array = NULL;
  622. !                }
  623. !                return;
  624. !             }/*if ModArr*/
  625. !             else {
  626. !                is_array = FALSE;
  627. !                printf( Shell[ UsrSh ].setcmd, val->name );
  628. !                printf( Shell[ UsrSh ].prefix );
  629. !             }
  630. !          }/*else !positional-parms*/
  631. !          break;
  632. !    }/*switch*/
  633. X     for ( i = 0 ; i < val->value.Vector.count ; i++ ) {
  634. -       if ( is_array )  printf( Shell[ UsrSh ].prefix );
  635. X        put_arg( stdout, ad, val, i );
  636. !       if ( is_array )  printf( Shell[ UsrSh ].prefix );
  637. !       if ( i != (val->value.Vector.count - 1) ) {
  638. !          fputs( ((UsrSh == PERL) ? ", " : FieldSep), stdout );
  639. X        }
  640. -    }/* end-for */
  641. -    if ( UsrSh == CSH  ||  UsrSh == TCSH  || UsrSh == RC  ||  UsrSh == PERL ) {
  642. -      fputc( ')', stdout );
  643. X     }
  644. !    fputs( ((! is_array) ? Shell[ UsrSh ].suffix : ";\n"), stdout );
  645. X  }
  646. X  
  647. X  
  648. --- 1747,1798 ----
  649. X     static void print_argvector( const ARGDESC *ad, const cmdarg_t *val )
  650. X  #endif
  651. X  {
  652. !    register  shell_t  cli = Shell[ UsrSh ].type;
  653. !    BOOL   set_printed = FALSE;
  654. X     int    i;
  655. X     char   *varname;
  656. X  
  657. !       /* need to check for '--' for sh, ksh, and bash */
  658. !    if ( strEQ("--", val->name) && (cli == SH || cli == BASH || cli == KSH) ) {
  659. !       printf( "set -- " );
  660. !       set_printed = TRUE;
  661. !    }
  662. !       /* if faking arrays for sh, bash, or awk -- do it now! */
  663. !    else if ( ModArr  &&  (cli == SH || cli == BASH || cli == AWK) ) {
  664. !       i = strlen( val->name );
  665. !       varname = (char *)ckalloc( (i + 4) * sizeof(char) );
  666. !       for ( i = 0 ; i < val->value.Vector.count ; i++ ) {
  667. !          sprintf( varname, "%s%d", val->name, i+1 );
  668. !          printf( Shell[ UsrSh ].sclset, varname );
  669. !          printf( Shell[ UsrSh ].sclpfx );
  670. !          put_arg( stdout, ad, val, i );
  671. !          printf( "%s", Shell[ UsrSh ].sclsfx );
  672. !       }
  673. !       sprintf( varname, "%s_count", val->name );
  674. !       printf( Shell[ UsrSh ].sclset, varname );
  675. !       printf( Shell[ UsrSh ].sclpfx );
  676. !       printf( "%d", val->value.Vector.count );
  677. !       printf( "%s", Shell[ UsrSh ].sclsfx );
  678. !       return;
  679. !    }
  680. !       /* print the array already */
  681. !    if ( !set_printed )  {
  682. !       if ( cli == KSH ) {
  683. !          printf( Shell[ UsrSh ].aryset, ((ModArr) ? '+' : '-'), val->name );
  684. !       }
  685. !       else {
  686. !          printf( Shell[ UsrSh ].aryset, val->name );
  687. !       }
  688. !    }
  689. !    printf( Shell[ UsrSh ].arypfx );
  690. X     for ( i = 0 ; i < val->value.Vector.count ; i++ ) {
  691. X        put_arg( stdout, ad, val, i );
  692. !       if ( (i + 1)  !=  val->value.Vector.count ) {
  693. !          printf( Shell[ UsrSh ].arysep, FieldSep );
  694. X        }
  695. X     }
  696. !    printf( Shell[ UsrSh ].arysfx );
  697. X  }
  698. X  
  699. X  
  700. ***************
  701. *** 1838,1846 ****
  702. X           ***^^*************************************************************/
  703. X           if ( ARG_isVALOPTIONAL(ad) ) {
  704. X              sprintf(buf, "%s_flag", vals[i].name);
  705. !             printf( Shell[ UsrSh ].setcmd, buf);
  706. !             printf( Shell[ UsrSh ].prefix );
  707. !             printf( "%s%s", StrTrue, Shell[ UsrSh ].suffix );
  708. X  
  709. X              if ( !ARG_isVALGIVEN(ad) )  continue;
  710. X           }/*if OPTARG*/
  711. --- 1879,1887 ----
  712. X           ***^^*************************************************************/
  713. X           if ( ARG_isVALOPTIONAL(ad) ) {
  714. X              sprintf(buf, "%s_flag", vals[i].name);
  715. !             printf( Shell[ UsrSh ].sclset, buf);
  716. !             printf( Shell[ UsrSh ].sclpfx );
  717. !             printf( "%s%s", StrTrue, Shell[ UsrSh ].sclsfx );
  718. X  
  719. X              if ( !ARG_isVALGIVEN(ad) )  continue;
  720. X           }/*if OPTARG*/
  721. ***************
  722. *** 1852,1865 ****
  723. X           }
  724. X  
  725. X              /* print shell-specific variable prefix and name */
  726. !          printf( Shell[ UsrSh ].setcmd, vals[i].name );
  727. !          printf( Shell[ UsrSh ].prefix );
  728. X  
  729. X              /* print shell-variable value */
  730. X           put_arg( stdout, ad, (vals + i), 0 );
  731. X  
  732. X              /* print the shell-specific suffix */
  733. !          printf( "%s", Shell[ UsrSh ].suffix );
  734. X        }/*if ARGGIVEN*/
  735. X     }/* end-for */
  736. X  }
  737. --- 1893,1906 ----
  738. X           }
  739. X  
  740. X              /* print shell-specific variable prefix and name */
  741. !          printf( Shell[ UsrSh ].sclset, vals[i].name );
  742. !          printf( Shell[ UsrSh ].sclpfx );
  743. X  
  744. X              /* print shell-variable value */
  745. X           put_arg( stdout, ad, (vals + i), 0 );
  746. X  
  747. X              /* print the shell-specific suffix */
  748. !          printf( "%s", Shell[ UsrSh ].sclsfx );
  749. X        }/*if ARGGIVEN*/
  750. X     }/* end-for */
  751. X  }
  752. ***************
  753. *** 1898,1931 ****
  754. X     static void unset_positional_parameters( void )
  755. X  #endif
  756. X  {
  757. !    switch( UsrSh ) {
  758. !       case TCSH: case CSH:
  759. !          printf( "set argv=();\n" );
  760. !          break;
  761. !       case PERL:
  762. !          printf( "@ARGV = ();\n" );
  763. !          break;
  764. !       case KSH:
  765. !          printf( "set --;\n" );
  766. !          break;
  767. !       case BASH: case SH:
  768. !          printf( "shift $#;\n" );
  769. !          break;
  770. !       case RC:
  771. !          printf( "*=();\n" );
  772. !          break;
  773. !       case AWK:
  774. !          printf( "%s%s", Shell[ UsrSh ].varname, Shell[ UsrSh ].suffix );
  775. !          break;
  776. !       default:
  777. !          break;
  778. !    }/*switch*/
  779. X  }
  780. X  
  781. X  
  782. --- 1939,1945 ----
  783. X     static void unset_positional_parameters( void )
  784. X  #endif
  785. X  {
  786. !    printf( Shell[ UsrSh ].unset );
  787. X  }
  788. X  
  789. X  
  790. ***************
  791. *** 2020,2029 ****
  792. X        /* see if we need to "default" the shell name */
  793. X     if ( !PrUsage   &&   !PrManual ) {
  794. X        if ( !ShellName ) {
  795. !          UsrSh = SH;   /* default to Bourne Shell */
  796. X        }
  797. X        else {
  798. !          UsrSh = get_shell_type( basename( ShellName ) );
  799. X        }
  800. X     }
  801. X  
  802. --- 2034,2043 ----
  803. X        /* see if we need to "default" the shell name */
  804. X     if ( !PrUsage   &&   !PrManual ) {
  805. X        if ( !ShellName ) {
  806. !          UsrSh = get_shell_index( "sh" );  /* default to Bourne Shell */
  807. X        }
  808. X        else {
  809. !          UsrSh = get_shell_index( basename( ShellName ) );
  810. X        }
  811. X     }
  812. X  
  813. diff -cNr ../patchlevel4/parseargs.h ./parseargs.h
  814. *** ../patchlevel4/parseargs.h    Thu May  2 11:06:11 1991
  815. --- ./parseargs.h    Thu May  2 14:36:15 1991
  816. ***************
  817. *** 605,610 ****
  818. --- 605,613 ----
  819. X  **       is useful when more than one call to the parseargs library is needed
  820. X  **       to parse all the command-line arguments (which could occur if the
  821. X  **       command-line argument came from a file or from two argv-vectors).
  822. + **       When this flag is set, then each call to parseargs will check for
  823. + **       missing required arguments (and will prompt the user for them if
  824. + **       desired).
  825. X  **
  826. X  **       Keeping this flag on until the final set of arguments is parsed will
  827. X  **       cause parseargs to not check for missing arguments until the last set
  828. diff -cNr ../patchlevel4/parseargs.pl ./parseargs.pl
  829. *** ../patchlevel4/parseargs.pl    Thu May  2 11:06:11 1991
  830. --- ./parseargs.pl    Thu May  2 14:36:18 1991
  831. ***************
  832. *** 54,65 ****
  833. X  
  834. X  sub parseargs {
  835. X     local($argd, @argv) = ( pop(@_), $0, @_ );
  836. !    local($unset, $end, $sh, $env) = ( '-u', '--', '-s', '-e' );
  837. X     local($parse_output, $_);
  838. X  
  839. X     $_ = $main'ENV{'PARSECNTL'};
  840. X     if ( /[^!~\^]\s*[KkLl]/ ) {  ## KeyWords only!
  841. !       ($unset, $end, $sh, $env) = ( '+unset', '++', '+shell', '+env' );
  842. X     }
  843. X  
  844. X     if ( ! $main'PARSEOPTS )  { $main'PARSEOPTS = "$unset"; }
  845. --- 54,65 ----
  846. X  
  847. X  sub parseargs {
  848. X     local($argd, @argv) = ( pop(@_), $0, @_ );
  849. !    local($unset, $sh, $env, $end) = ( '-u', '-s', '-e', '--' );
  850. X     local($parse_output, $_);
  851. X  
  852. X     $_ = $main'ENV{'PARSECNTL'};
  853. X     if ( /[^!~\^]\s*[KkLl]/ ) {  ## KeyWords only!
  854. !       ($unset, $sh, $env, $end) = ( '+unset', '+shell', '+env', '++' );
  855. X     }
  856. X  
  857. X     if ( ! $main'PARSEOPTS )  { $main'PARSEOPTS = "$unset"; }
  858. diff -cNr ../patchlevel4/parseargs1.txt ./parseargs1.txt
  859. *** ../patchlevel4/parseargs1.txt    Thu May  2 11:06:45 1991
  860. --- ./parseargs1.txt    Wed Dec 31 18:00:00 1969
  861. ***************
  862. *** 1,1056 ****
  863. - PARSEARGS(1)                         PARSEARGS(1)
  864. - NAME
  865. -      parseargs - parse command line arguments in shell scripts
  866. - SYNOPSIS
  867. -      parseargs     [-#UMCAlouip1]    [-S separator] [-T string]
  868. -          [-F string] [-a arg-spec] [-e name] [-f file]
  869. -          [-s shell] -- name [arguments ...]
  870. - OPTIONS
  871. -      -#           just    print the version and patchlevel, do not
  872. -            parse the command line
  873. -      -U           just    print program usage, do    not parse the
  874. -            command line
  875. -      -M           just    print (n|t)roff    -man manual page
  876. -            template, do    not parse the command line
  877. -      -S    separator  field-separator-string used to delimit array
  878. -            elements  (default=
  879. -      -T    string       string to use for true boolean arguments
  880. -            (default=``TRUE'')
  881. -      -F    string       string to use for false boolean arguments
  882. -            (default=``'')
  883. -      -C           Ignore the difference between upper and lower
  884. -            case    when parsing single character options.
  885. -      -A           modify array    behavior for the specified shell.
  886. -      -a    arg-spec   argument specification string
  887. -      -e    name       read    the arg-spec string from the environment
  888. -            variable named name
  889. -      -f    file       read    the arg-spec from file    (default=stdin)
  890. -      -l           Long-options    only. Disable the parsing of
  891. -            (single-character) options.
  892. -      -o           Options only. Disable the parsing of    long-
  893. -            options (keywords).
  894. -      -s    shell       use shell command syntax  (default=``sh'')
  895. -      -u           unset positional parameters before assigning
  896. -            variables
  897. -      -p           prompt the user for missing required    arguments
  898. - Page 1
  899. - PARSEARGS(1)                         PARSEARGS(1)
  900. -      -i           ignore bad command-line syntax and continue
  901. -            processing (instead of aborting)
  902. -      -1           Force any and all non-positional parameters to
  903. -            be specified    before any positional parameters
  904. -            on the command-line.
  905. - ARGUMENTS
  906. -      --           Indicates that any remaining    options    are
  907. -            intended for    the calling program.
  908. -      name       name    of calling program
  909. -      arguments       arguments to    calling    program
  910. - DESCRIPTION
  911. -      Given a command name, a vector of string-valued arguments
  912. -      such as that passed to a shell script, and    a specification
  913. -      string describing the possible arguments, parseargs matches
  914. -      actual arguments to possible arguments, converts values to
  915. -      the desired type, and diagnoses problems such as missing
  916. -      arguments,    extra arguments, and argument values that are
  917. -      syntactically incorrect.  Other behavior such as prompting
  918. -      the user for missing arguments and    ignoring bad command-line
  919. -      syntax may    be specified on    the command-line through the use
  920. -      of    various    options, or through the    use of the ``PARSECNTL''
  921. -      environment variable.
  922. -      Given the command name and    the argument specification
  923. -      string, parseargs -U prints a reasonably friendly version of
  924. -      the usage of the calling program on standard diagnostic
  925. -      output. The ``verbosity'' of the usage message may    be
  926. -      controlled    through    the use    of the ``USAGECNTL'' environment
  927. -      variable.
  928. -      Given the command name and    the argument specification
  929. -      string, parseargs -M prints a template of the command-syntax
  930. -      on    standard output    that is    suitable for input to nroff or
  931. -      troff using the -man macro    package.
  932. -      Given no other arguments parseargs    -# prints on standard
  933. -      output, the current version and patchlevel    of the running
  934. -      version of    parseargs.
  935. -      The argument specification    string contains    one entry for
  936. -      each possible flag.  Entries in the argument specification
  937. -      string are    separated by commas.  Each entry has five comma-
  938. -      separated fields:    a name,    some flags, a type, a variable-
  939. -      name, and a prompt.  Each of these    fields are described
  940. -      below:
  941. - Page 2
  942. - PARSEARGS(1)                         PARSEARGS(1)
  943. -      name      The single character name of the    associated flag.
  944. -            For example, to indicate    that the program is
  945. -            expecting a ``-x'' flag,    this field would contain
  946. -            'x'.  Positional    arguments (those without a ``-x''
  947. -            prefix) are indicated by    passing    a ``space''
  948. -            character.
  949. -      flags     Flags modifying the semantics of    this entry.
  950. -            These should have one of    ARGREQ to indicate a
  951. -            required    argument or ARGOPT to indicate an
  952. -            optional    argument (ARGOPT is the    default    unless
  953. -            ARGREQ is specified).  ARGPOS may be ``ored'' in
  954. -            to indicate a positional    argument that may also be
  955. -            keyword matched.     ARGVALOPT may be ``ored'' in to
  956. -            indicate    that an    argument to the    option may be
  957. -            optionally supplied on the command-line,    but is
  958. -            not required.  ARGVALREQ    may be ``ored''    in to
  959. -            indicate    that an    argument to the    option is
  960. -            required    (this is the default behavior for options
  961. -            that take arguments).  ARGLIST may be ``ored'' in
  962. -            (using the `|' character) to indicate that an
  963. -            argument    is actually a list of one or more
  964. -            arguments from the command line.     ARGHIDDEN may be
  965. -            ``ored''    in to indicate a flag that should not be
  966. -            printed in usage    messages - for example,    flags
  967. -            intended    for internal debugging purposes.
  968. -      type      The type    of the argument.  Existing types include
  969. -            argUsage    (print usage message and exit),    argBool
  970. -            and argSBool (set Boolean flags), argUBool (unset
  971. -            Boolean flags), argStr (string-valued arguments),
  972. -            argChar (char-valued arguments),    argInt (native
  973. -            integer arguments), argShort (short integer
  974. -            arguments), argLong (long integer arguments),
  975. -            argFloat    (short floating    point arguments),
  976. -            argDouble (long floating    point arguments), and
  977. -            argDummy    (only used as part of usage message, not
  978. -            matched on command-line).
  979. -      variable  The name    of the shell variable that should receive
  980. -            the converted value.
  981. -      prompt    The string used when prompting interactively for
  982. -            argument    values,    and printed in usage messages.
  983. -            This string may be followed by a    textual
  984. -            description that    is enclosed in parentheses,
  985. -            square brackets,    curly braces, or angle brackets.
  986. -      The argument specification    string must be terminated by the
  987. -      single string:  ``ENDOFARGS''.
  988. - Page 3
  989. - PARSEARGS(1)                         PARSEARGS(1)
  990. -      Note that the comma character (',') is used to separate all
  991. -      fields within an entry, and to separate the entries
  992. -      themselves.  For this reason, no field in any entry may
  993. -      contain a comma unless it appears inside of double    or single
  994. -      quotes.
  995. -      Parseargs will parse all command-line arguments for the
  996. -      calling script and    match them against the argument
  997. -      specification string provided. The    argument specification
  998. -      string is read from standard input    by default but may not
  999. -      come from a terminal. The argument    specification string may
  1000. -      be    supplied as a single string argument by    using the -a
  1001. -      ``string''    flag.  Long argument specification strings
  1002. -      however, may limit    the number of arguments    to the script if
  1003. -      there is a    limit to the number of arguments and/or
  1004. -      characters    that may appear    on the command line.  For this
  1005. -      reason, the argument specification    string may be stored: in
  1006. -      an    environment variable using the -e name option; in a file
  1007. -      and read using the    -f file    option;    or read    from standard
  1008. -      input.  When using    the -e option, the user    must remember to
  1009. -      use the name of an    environment variable (not a mere shell
  1010. -      variable)!     The default behavior is to read the argument
  1011. -      specification from    standard input.
  1012. - SHELLS
  1013. -      After the command line has    been parsed, parseargs will print
  1014. -      on    standard output, a script to set the shell variables
  1015. -      which correspond to arguments that    were present on    the
  1016. -      command-line.  This script    may be evaluated by redirecting
  1017. -      it    to a file and then executing the file, or by directly
  1018. -      evaluating    the output from    parseargs (under most UNIX
  1019. -      shells, this could    be done    using eval).  If any arguments on
  1020. -      the command line contained    any special characters that
  1021. -      needed to be escaped from the shell, these    characters will
  1022. -      remain intact (not    be evaluated by    the shell) in the
  1023. -      corresponding shell variable.
  1024. -      The -s shell option may be    used to    tell parseargs which
  1025. -      shell syntax to use. At present, parseargs    only recognizes
  1026. -      ``sh'', ``csh'', ``ksh'', ``tcsh'', ``bash'', ``rc'',
  1027. -      ``awk'', and ``perl'' as valid command interpreters. Awk
  1028. -      output is slightly    different from that of the other shells
  1029. -      in    that the actual    variable settings are not printed but
  1030. -      each line of an associative array is printed (the first
  1031. -      field is the array    index, the second is the value for that
  1032. -      index).  If no shell is specified,    then the Bourne    shell
  1033. -      (``sh'') will be assumed.
  1034. -      If    the user wishes    to use a value other than ``TRUE'' for a
  1035. -      boolean flag that is true,    this may be done using the -T
  1036. -      string option.  The same may also be done for a boolean flag
  1037. -      that is false using the -F    string option.
  1038. - Page 4
  1039. - PARSEARGS(1)                         PARSEARGS(1)
  1040. -      Parseargs will only set the values    of variables that
  1041. -      correspond    to arguments that were given on    the command line.
  1042. -      If    a particular argument was not supplied on the command
  1043. -      line, then    no assignment is made for the corresponding shell
  1044. -      variable and it will have the same    value that it had before
  1045. -      parseargs was invoked. The    only exception to this is that if
  1046. -      the -u option is specified, then the positional parameters
  1047. -      are unset before any shell    variable assignments (which may
  1048. -      reset the positional parameters) are made.
  1049. -      The double-dash (``--'') which precedes the name and
  1050. -      arguments of the calling program is needed    in order for
  1051. -      parseargs to be able to distinguish options to itself from
  1052. -      options for the calling program.
  1053. -      The default behavior of parseargs is to allow both    single-
  1054. -      character options and long-options    (keywords) on the
  1055. -      command-line. The user may    specify    that only options (long-
  1056. -      options) are to be    permitted by specifying    the -o (-l)
  1057. -      option on the command-line.
  1058. - SPECIFYING PARSE-BEHAVIOR
  1059. -      The -C, -p, -i, and -1 switches may be used to modify the
  1060. -      command-line parsing behavior of the invoking script.
  1061. -      Specifying    -C will    cause case-differences in single-
  1062. -      character options to be ignored. Specifying -p will cause
  1063. -      the user to be interactively prompted for any missing
  1064. -      required arguments. Specifying -i will cause syntactically
  1065. -      incorrect arguments to be ignored (instead    of having a usage
  1066. -      message printed and execution terminated).    Specifying -1
  1067. -      will force    all non-positional parameters to precede any
  1068. -      positional    parameters on the command-line (hence anything on
  1069. -      the command-line after a positional parameter that    resembles
  1070. -      a keyword parameter will nevertheles be interpreted as a
  1071. -      positional    parameter).
  1072. - OPTIONS    WITH OPTIONAL ARGUMENTS
  1073. -      Options that may take an optional argument    need special
  1074. -      consideration.  The shell programmer needs    to know    whether
  1075. -      or    not the    option was given, and (if given) if it was
  1076. -      accompanied by an argument. In order to accommodate this
  1077. -      need, parseargs will set an additional shell variable for
  1078. -      each argument that    is given the ARGVALOPT flag if it is
  1079. -      supplied on the command line regardless of    whether    or not it
  1080. -      was accompanied by    its optional argument.    If the user has
  1081. -      defined an    option which may optionally take an argument and
  1082. -      the option    appears    on the command line with or without its
  1083. -      associated    argument, then the shell variable <name>_flag
  1084. -      will be assigned the value    ``TRUE'' (or the value supplied
  1085. -      with the -T option    to parseargs) where <name> is the name of
  1086. -      the shell variable    associated with    the option in the
  1087. -      argument description string.
  1088. - Page 5
  1089. - PARSEARGS(1)                         PARSEARGS(1)
  1090. - ARGUMENT LISTS
  1091. -      Parseargs treats ARGLIST arguments    in a special way. The
  1092. -      method used for setting up    an argument list depends largely
  1093. -      upon the syntax of    shell that was specified on the    command
  1094. -      line via the -s option (although ARGLIST arguments    are
  1095. -      treated exactly the same as ARGVEC    arguments).
  1096. -      Resetting the Positional Parameters to an Argument    List
  1097. -      For the Bourne, Bourne-Again, and Korn shells, if the
  1098. -      variable name corresponding to the    ARGLIST    argument is
  1099. -      ``--'', then the positional parameters of the calling
  1100. -      program will be re-assigned to the    contents of the    argument
  1101. -      list ($1 will be the first    item, $2 the second item, and so
  1102. -      on). In this particular case, the calling program may wish
  1103. -      to    use the    -u option to reset the positional parameters to
  1104. -      NULL before making    any shell-variable assignments (this way,
  1105. -      the positional parameters will be unset if    the associated
  1106. -      list of command line arguments is not encountered).
  1107. -      Similarly for the C and TC    shells,    if the variable    name
  1108. -      corresponding to the ARGLIST argument is ``argv'',    then the
  1109. -      positional    parameters of the calling program will be re-
  1110. -      assigned to the contents of the argument list.
  1111. -      For the Plan 9 shell (rc),    if the variable    name
  1112. -      corresponding to the ARGLIST argument is ``*'', then the
  1113. -      positional    parameters of the calling program will be re-
  1114. -      assigned to the contents of the argument list.
  1115. -      For awk and perl, if the variable name corresponding to the
  1116. -      ARGLIST argument is ``ARGV'', then    the positional parameters
  1117. -      of    the calling program will be re-assigned    to the contents
  1118. -      of    the argument list.
  1119. -      Bourne Shell Argument Lists
  1120. -      For the Bourne shell, if the associated variable name is NOT
  1121. -      ``--'' and    the -A option was NOT specified, then that
  1122. -      variable is treated as a regular shell variable and is
  1123. -      assigned using the    following syntax:
  1124. -       name='arg1 arg2  ...'
  1125. -      After invoking parseargs, if you wish to go through all the
  1126. -      words in the variable name    and one    of the words in    name
  1127. -      contains an IFS character (such as    a space    or a tab), then
  1128. -      that particular word will be treated by the Bourne    shell as
  1129. -      two distinct words.
  1130. -      Also for the Bourne shell,    If the associated variable name
  1131. -      is    NOT ``--'' and the -A option WAS specified, then that
  1132. -      variable is treated as the    root name of an    array that is set
  1133. -      using the following syntax:
  1134. -       name1='arg1'
  1135. -       name2='arg2'
  1136. - Page 6
  1137. - PARSEARGS(1)                         PARSEARGS(1)
  1138. -           ...
  1139. -      and the variable ``name_count'' will be set to contain the
  1140. -      number of items in    the array.  The    user may then step
  1141. -      through all the items in the array    using the following
  1142. -      syntax:
  1143. -       i=1
  1144. -       while    [ $i -le $name_count ] ; do
  1145. -         eval echo "item #$i    is: " \$name$i
  1146. -         i=`expr $i + 1`
  1147. -       done
  1148. -      Korn Shell    Argument Lists
  1149. -      For the Korn shell, if the    associated variable name is NOT
  1150. -      ``--'', then that variable    is treated as an array and is
  1151. -      assigned using the    -A option of the set command. The first
  1152. -      item will be in ${name[0]}, the second item will be in
  1153. -      ${name[1]}, etc ..., and all items    may be given by
  1154. -      ${name[*]}    or ${name[@]}.    If the associated variable name
  1155. -      is    NOT ``--'' and the -A option WAS specified, then that
  1156. -      variable is assigned using    the +A option of the set command
  1157. -      (which preserves any array    elements that were not
  1158. -      overwritten by the    set command).
  1159. -      It    should be noted    that there is a    bug in versions    of the
  1160. -      Korn shell    earlier    than 11/16/88a,    in which the following:
  1161. -       set  -A  name     'arg1'     'arg2'     ...
  1162. -      causes the    positional parameters to be overwritten    as an
  1163. -      unintentional side-effect.    If your    version    of the Korn shell
  1164. -      is    earlier    than this and you wish to keep the contents of
  1165. -      your positional parameters    after invoking parseargs than you
  1166. -      must save them yourself before you    call parseargs.    This may
  1167. -      be    accomplished by    the following:
  1168. -       set  -A  save_parms  "$@"
  1169. -      C and TC Shell Argument Lists
  1170. -      For the C and TC shells, ARGLIST variables    are treated as
  1171. -      word-lists    and are    assigned using the following syntax:
  1172. -       set  name = (    'arg1'    'arg2'    ... )
  1173. -      The first item will be in $name[1], the second item will be
  1174. -      in    $name[2], etc ..., and all items may be    given by $name.
  1175. -      Notice that Korn shell arrays start at index zero whereas C
  1176. -      and TC shell word-lists start at index one.
  1177. -      Bourne-Again Shell    Argument Lists
  1178. -      At    present, the Free Software Foundation's    Bourne-Again
  1179. -      shell is treated exactly the same as the Bourne Shell. This
  1180. -      will change when bash supports arrays.
  1181. -      Plan 9 Shell Argument Lists
  1182. -      For the Plan 9 shell, if the associated variable name is not
  1183. -      ``*'' then    it is considered to be a word-list and set using
  1184. - Page 7
  1185. - PARSEARGS(1)                         PARSEARGS(1)
  1186. -      the following syntax:
  1187. -       name=( 'arg1'     'arg2'     ... )
  1188. -      Awk Argument Lists
  1189. -      For awk, if the -A    option is not given, then the output for
  1190. -      thes variable-list    will be    a line with the    variable name,
  1191. -      followed by a line    with each of the values    (each value will
  1192. -      be    separated with the field separator specified using the -S
  1193. -      option - which defaults to    a space).
  1194. -       name
  1195. -       arg1    arg2  ...
  1196. -      If    the -A option is given,    then the associated variable is
  1197. -      considered    the root name of an array. The ouput for the
  1198. -      array will    consist    of two lines for each item in the list
  1199. -      (as in the    following example):
  1200. -       name1
  1201. -       arg1
  1202. -       name2
  1203. -       arg2
  1204. -      and the variable ``name_count'' will have an output line
  1205. -      showing the number    of items in the    array.
  1206. -      Perl Argument Lists
  1207. -      For perl, each argument list is considered    an array and is
  1208. -      set using the following syntax:
  1209. -       @name=( 'arg1' , 'arg2' ,  ... );
  1210. -      A Final Note on Argument Lists
  1211. -      The word-lists used by the    C shell, the arrays used by the
  1212. -      Korn shell, the Plan 9 shell, awk,    perl, and the positional
  1213. -      parameters    used by    all shells (if overwritten by parseargs)
  1214. -      will preserve any IFS characters in their contents.  That is
  1215. -      to    say that if an item in one of the aforementioned multi-
  1216. -      word lists    contains any IFS characters, it    will not be split
  1217. -      up    into multiple items but    will remain a single item which
  1218. -      contains IFS characters.
  1219. - SUPPLYING DEFAULT ARGUMENTS
  1220. -      Programs that use parseargs may be    given default arguments
  1221. -      under UNIX    and PCs    through    the use    of environment variables
  1222. -      (symbols are used for VMS systems). If a  C-program or
  1223. -      shell-script uses parseargs to implement a    command    named
  1224. -      ``cmd'' then the environment variable ``CMD_ARGS''    will be
  1225. -      parsed for    any "default" arguments    before the command-line
  1226. -      is    parsed.     The command-line will over-ride any options that
  1227. -      are specified in this environment variable    (except    that
  1228. -      ARGLISTs and ARGVECs set in ``CMD_ARGS'' will be appended
  1229. -      from the command-line if they are selected).
  1230. - Page 8
  1231. - PARSEARGS(1)                         PARSEARGS(1)
  1232. -      It    is important to    note that the contents of the
  1233. -      ``CMD_ARGS'' environment variable are NOT expanded    by the
  1234. -      shell and hence any special characters (such as quotes or
  1235. -      back-slashes) will    NOT be escaped or removed by parseargs.
  1236. -      Furthermore, it will not be possible to try and use a tab,
  1237. -      space, or newline character in the    environment variable as
  1238. -      anything other than an argument separator.
  1239. -      Lastly, parts of an option    specification in ``CMD_ARGS'' may
  1240. -      NOT be continued on the command-line. As an example, if -f
  1241. -      requires an argument and CMD_ARGS="-f", then the command-
  1242. -      line "cmd    bah" will NOT assign "bah" as the argument to -f
  1243. -      but will instead complain about a missing argument    for -f.
  1244. -      Similarly,    if -l takes a list of arguments    and CMD_ARGS="-l
  1245. -      item1 item2", then    the command-line "cmd  bah", will NOT
  1246. -      assign "bah" to the end of    the list containing "item1" and
  1247. -      "item2" but will instead treat "bah" as the first positional
  1248. -      parameter on the command-line.
  1249. - PARSING    BEHAVIOR
  1250. -      The programmer may    control    parsing    behavior through the use
  1251. -      of    parsecntl(3).  The user    may set    his (or    her) own desired
  1252. -      parsing behavior through the use of the ``PARSECNTL''
  1253. -      environment variable.  By indicating any number of    flags
  1254. -      (possibly negated)    the user will directly modify the
  1255. -      behavior of the parseargs library.    Flags may be combined by
  1256. -      placing a `+' or `|' character in between flags. A    switch is
  1257. -      negated by    immediately preceding it with a    `!' or `-'
  1258. -      character.     The possible ``flags''    are given by the
  1259. -      following table. Flags are    case-insensitive.
  1260. -      Prompt
  1261. -       Prompt the user for any missing arguments that are
  1262. -       required on the command-line.    No special escaping or
  1263. -       quoting is performed on the user input. Required
  1264. -       arguments that expect    a list of values will be
  1265. -       repeatedly prompted for (one item per    line) until a
  1266. -       blank    line (followed by a carriage return) is    entered.
  1267. -      Ignore
  1268. -       Ignore any unrecognized or improperly    specified
  1269. -       command-line arguments and continue execution    of the
  1270. -       program. Normally, if    a required argument is unmatched
  1271. -       (or an argument is improperly    specified), a usage
  1272. -       message is printed program execution is terminated.
  1273. -      OptsOnly
  1274. -       Under    UNIX, setting this flag    will disable the parsing
  1275. -       of long-option syntax. This will cause all arguments
  1276. -       starting with    `+' to always be treated as a positional
  1277. -       parameter (instead of    a long-option).
  1278. - Page 9
  1279. - PARSEARGS(1)                         PARSEARGS(1)
  1280. -      KwdsOnly
  1281. -       Under    UNIX, setting this flag    disables the parsing of
  1282. -       single-character options.  This will cause all
  1283. -       arguments starting with `-' to always    be treated as a
  1284. -       positional parameter (instead    of an option).
  1285. -      LoptsOnly
  1286. -       Same as KwdsOnly.
  1287. -      Flags1st
  1288. -       Setting this flag causes the parseargs library to force
  1289. -       any and all non-positional arguments to be specified
  1290. -       before any positional    ones.  As an example, under UNIX,
  1291. -       if this flag is SET then parseargs will consider the
  1292. -       command line "cmd -x arg" to consist of one option and
  1293. -       one positional argument; however the command line "cmd
  1294. -       arg -x" would    be considered to consist of two
  1295. -       positional arguments (the -x option will be unmatched).
  1296. -       If this flag is UNSET, then both of the previous
  1297. -       examples are considered to consist of    one option and
  1298. -       one positional argument.
  1299. -      CaseIgnore
  1300. -       Setting this flag will cause character-case to be
  1301. -       ignored when attempting to match single-character
  1302. -       argument names (i.e. causes "-i" and "-I" to be
  1303. -       considered equivalent).
  1304. -      If    the environment    variable ``PARSECNTL'' is empty    or
  1305. -      undefined,    then the parsing behavior set by the programmer
  1306. -      is    used.  If the programmer has not explicitly used
  1307. -      parsecntl(3) to modify the    parsing    behavior, then the
  1308. -      default behavior will be ``Flags1st'' for Unix systems,
  1309. -      ``!Prompt + !Ignore'' for AmigaDOS    systems, ``CaseIgnore''
  1310. -      for MS-DOS    and OS/2 systems, and ``Prompt'' for VMS systems.
  1311. - USAGE MESSAGES
  1312. -      Through the use of    an environment variable    (or a VMS
  1313. -      symbol), the user may control the syntax and the verbosity
  1314. -      of    the command-usage messages that    are printed by parseargs.
  1315. -      The desired level of verbosity may    be set by defining the
  1316. -      environment variable ``USAGECNTL" to be a combination of
  1317. -      strings (case insensitive). The value of each string
  1318. -      controls one of three different ``modes'' of behavior in the
  1319. -      displaying    of usage messages:  The    first ``mode'' is
  1320. SHAR_EOF
  1321. true || echo 'restore of PATCH05 failed'
  1322. fi
  1323. echo 'End of  part 3'
  1324. echo 'File PATCH05 is continued in part 4'
  1325. echo 4 > _shar_seq_.tmp
  1326. exit 0
  1327. exit 0 # Just in case...
  1328. -- 
  1329. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1330. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1331. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1332. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1333.