home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_06 / 9n06086b < prev    next >
Text File  |  1990-03-01  |  3KB  |  116 lines

  1. /**************************************************************************
  2.  
  3.     ffc.c
  4.  
  5.     Format File in Columns.
  6.  
  7.  
  8.     Invocation:
  9.  
  10.         % ffc [-c num] [-d] [-h num] [-l num]
  11.               [-o output_file] [-p]  [input_file(s)]
  12.  
  13.     where
  14.  
  15.         "-c <num>"
  16.             specifies the number of columns (default = 2).
  17.         "-d"
  18.             turns debug output on.
  19.         "-h <num>"
  20.             specifies the number of blank lines at the top of each
  21.             page (default = 0).
  22.         "-l <num>"
  23.             specifies the number of lines per page (default = 66).
  24.         "-o <output_file>"
  25.             specifies the name of the output file (default =
  26.             standard output).
  27.         "-p"
  28.             invokes page numbering on output.
  29.         <input_file(s)>
  30.             are the files to be read and formatted in columns on
  31.             output (default = standard input).
  32.  
  33.  
  34.     Compilation:
  35.  
  36.         The program should be compiled and linked with the
  37.         GETOPT function:
  38.  
  39.             % cc ffc.c getopt.c -o ffc
  40.  
  41. **************************************************************************/
  42.  
  43.  
  44. #include  <stdio.h>                     /* Standard I/O definitions. */
  45. #include  "getopt.h"                    /* GETOPT(3) definitions. */
  46.  
  47.                                         /* List of input file names. */
  48. #define  MAX_FILES  1024
  49. static  char  *file_table[MAX_FILES] ;
  50. static  int  num_input_files = 0 ;
  51.  
  52.                                         /* Page dimensions, etc. */
  53. static  int  debug = 0 ;                /* 0 = no, -1 = yes. */
  54. static  int  num_columns = 2 ;
  55. static  int  num_header_lines = 0 ;
  56. static  int  page_length = 66 ;
  57. static  int  page_numbering = 0 ;       /* 0 = no, -1 = yes. */
  58.  
  59.  
  60.  
  61. main (argc, argv)
  62.  
  63.     int  argc ;
  64.     char  *argv[] ;
  65.  
  66. {  /* Local variables. */
  67.  
  68.     char  *output_file = NULL ;
  69.     int  errflg, option ;
  70.  
  71.  
  72.  
  73. /* Scan the command line arguments. */
  74.  
  75.     errflg = 0 ;
  76.  
  77.     while (((option = getopt (argc, argv, "c:dh:l:o:p")) != NONOPT) ||
  78.            (optarg != NULL)) {
  79.  
  80.         printf ("Option = '%c'    Argument = \"%s\"\n", option, optarg) ;
  81.  
  82.         switch (option) {
  83.         case 'c':  num_columns = atoi (optarg) ;  break ;
  84.         case 'd':  debug = -1 ;  break ;
  85.         case 'h':  num_header_lines = atoi (optarg) ;  break ;
  86.         case 'l':  page_length = atoi (optarg) ;  break ;
  87.         case 'o':  output_file = optarg ;  break ;
  88.         case 'p':  page_numbering = -1 ;  break ;
  89.         case '?':  errflg++ ;  break ;
  90.         case NONOPT:
  91.             if (num_input_files < MAX_FILES) {
  92.                 file_table[num_input_files++] = optarg ;
  93.             }
  94.             break ;
  95.         default :  break ;
  96.         }
  97.  
  98.     }
  99.  
  100.  
  101. /* If an invalid option was detected, print out a command usage message. */
  102.  
  103.     if (errflg) {
  104.         fprintf (stderr, "Usage:  ffc  [-c num] [-d] [-h num]\n") ;
  105.         fprintf (stderr, "             [-l num] [-o output_file]\n") ;
  106.         fprintf (stderr, "             [-p]  [input_file(s)]\n") ;
  107.         exit (-1) ;
  108.     }
  109.  
  110.  
  111. /* Print out the files in multiple columns. */
  112.  
  113.     /* ... the remainder of the program ... */
  114.  
  115. }
  116.