home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1558 / options.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.5 KB  |  72 lines

  1.  
  2. /*
  3.  * Copyright (C) 1990 by Jay Konigsberg. mail: jak@sactoh0
  4.  *
  5.  * Permission to use, copy, modify, and distribute this  software  and  its
  6.  * documentation is hereby  granted,  provided  that  the  above  copyright
  7.  * notice appear in all copies  and that  both  the  copyright  notice  and
  8.  * this permission notice appear in supporting documentation. This software
  9.  * is provided "as is" without express or implied  warranty.  However,  the
  10.  * author retains all Copyright priviliges and rights  to  renumeration  if
  11.  * this software is sold.
  12.  */
  13.  
  14. /*
  15.  * get options for simped. -p postnews, -a append mode.
  16.  */
  17.  
  18. #include    "simped.h"
  19.  
  20. char *options (argc, argv, postnews, append, editfile)
  21. int    argc;
  22. char    **argv,
  23.     *postnews,    /* flag to add a '--' line to file */
  24.     *append,    /* always come up in append mode */
  25.     *editfile;
  26. {
  27. /* system calls and library functions */
  28. int    getopt(),
  29.     fprintf(),
  30.     exit();
  31.  
  32. /* variables */
  33. /* extern char *optarg; UNUSED */
  34. extern int optind;
  35.  
  36. int    option,            /* getopt variable */
  37.     error=FALSE;        /* error checking the options */
  38.  
  39. while ((option = getopt(argc, argv, "pa")) != -1)
  40.     {
  41.     switch (option)
  42.     {
  43.     case 'p':
  44.         *postnews=TRUE;
  45.         break;
  46.     case 'a':
  47.         *append=TRUE;
  48.         break;
  49.     case '?':
  50.         error=TRUE;
  51.         break;
  52.     }
  53.     }
  54. if ( argc > optind+1 )
  55.     {
  56.     fprintf(stderr, "Max one filename on command line.\n");
  57.     error=TRUE;
  58.     }
  59. else
  60.     {
  61.     editfile=argv[optind];
  62.     }
  63.  
  64. if (error)
  65.     {
  66.     fprintf(stderr,
  67.     "usage: simped [-p] [-a] filename\n");
  68.     exit(2);
  69.     }
  70. return(editfile);
  71. }
  72.