home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2989 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-06  |  2.2 KB  |  103 lines

  1.  
  2. /*+
  3.  * File: main.c
  4.  *
  5.  * Description:
  6.  *    List a directory, display it for selection and execute an action on
  7.  *    the selected file.
  8.  *
  9.  * This module is the proprietary property of Cottege Computing
  10.  * copyright 1989, all rights reserved.
  11.  *
  12.  * Audit Trail:
  13.  *    SCCS = @(#) main.c 1.2 11/20/89 16:45:33
  14.  *    Dan Flak - 11/18/89
  15.  *
  16. -*/
  17.  
  18. /* #includes                            */
  19. #include <stdio.h>
  20.  
  21. /* #defines                             */
  22. #define SAY printf
  23. #define WIDTH 14
  24. #define MAXFILES 255
  25.  
  26. /* external variables                   */
  27.  
  28. /* referenced external functions        */
  29. int  listdir();                            /* Prepares a list of files        */
  30. char *select();                            /* shows the list of files for slec-
  31.                                          * tion                               */
  32.  
  33. /* referenced internal functions        */
  34.  
  35. /* global variables                     */
  36. char xarray[MAXFILES][WIDTH + 1];        /* Array of filenames               */
  37. char *aptr[MAXFILES];                    /* Array of pointers to filenames  */
  38.  
  39. int  narray;                            /* Number of elements in array     */
  40.  
  41. /* static variables                     */
  42.  
  43. /*<
  44.  * Function: main (argc, argv)
  45.  *
  46.  * Description:
  47.  *   Call listdir to fill the array with filenames. Call select to display
  48.  *   them. Exec a command on the selected file.
  49.  *
  50.  * Data Type: int
  51.  *
  52.  * Arguments:
  53.  *    argv[1] = directory name
  54.  *    argv[2] = sort key (0 = alphabetical, 1 = by date)
  55.  *    argv[3] = showdot (0 = don't show .*, 1 = show .*)
  56.  *    argv[4] = command to execute
  57.  *      .          .
  58.  *      .          .
  59.  *      .          .
  60.  *    argv[n] = options to the command to execute.
  61.  *
  62.  * Returns:
  63.  *
  64.  * Side Effects:
  65.  *
  66.  * Calls:
  67.  *
  68.  * PDL:
  69.  *
  70. >*/
  71.  
  72. int
  73. main (argc, argv)
  74. int  argc;
  75. char *argv[];
  76. {
  77. int i;
  78. char *ptr;
  79. char cmdstr[128];
  80.  
  81. for (i = 0; i < MAXFILES; i++)            /* initalize the pointers to the   */
  82.     {                                    /* the array                       */
  83.     aptr[i] = xarray[i];
  84.     }
  85.  
  86. narray = listdir (argv[1], aptr, atoi (argv[2]), atoi (argv[3]));
  87.                                         /* get directory contents           */
  88.  
  89. ptr = select (aptr, narray, WIDTH);     /* select a file                   */
  90.  
  91. if (*ptr != NULL)                        /* display it                       */
  92.     {
  93.     chdir (argv[1]);
  94.     strcpy (cmdstr, argv[4]);
  95.     for (i = 5; i < argc; i++)
  96.         {
  97.         sprintf (cmdstr, "%s %s", cmdstr, argv[i]);
  98.         }
  99.     sprintf (cmdstr,"%s %s", cmdstr, ptr);
  100.     system (cmdstr);
  101.     }
  102. }
  103.