home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / programs / amiga / midi / midi_playground / sourcecode / cli.c < prev    next >
C/C++ Source or Header  |  1993-01-23  |  2KB  |  91 lines

  1. /**************************************************************************
  2. * cli.c:    The command-line interface for MP.
  3. *        Part of MP, the MIDI Playground.
  4. *
  5. * Author:    Daniel Barrett
  6. * Version:    See the file "version.h".
  7. * Copyright:    None!  This program is in the Public Domain.
  8. *        Please share it with others.
  9. ***************************************************************************/
  10.  
  11.     
  12. #include "mp.h"
  13.  
  14.  
  15. /* The main program from the CLI.  Check the command-line arguments, set
  16.  * up the input and output files, and call MIDIPlayground(). */
  17.     
  18. BOOL CommandLineProgram(int argc, char *argv[])
  19. {
  20.     FILE *in, *out;
  21.     char *infile, *outfile;
  22.     FLAGS theFlags[NUM_FLAGS];
  23.     
  24.     InitStuff(theFlags, &in, &out, &infile, &outfile);
  25.  
  26.     if ((argc == 1)   ||   (argc == 2 && !strcmp(argv[1], "?")))
  27.         Help(argv[0]);
  28.     else if (!HandleOptions(argc, argv, theFlags, &infile, &outfile))
  29.     {
  30.         fprintf(stderr, "There is an error in your options/flags.\n");
  31.         BegForUsage(argv[0]);
  32.     }
  33.     else if (!SetupFiles(infile, outfile, &in, &out))
  34.         ;
  35.     else if (optind < argc)
  36.     {
  37.         fprintf(stderr, "You gave me too many arguments.\n");
  38.         BegForUsage(argv[0]);
  39.     }
  40.     else
  41.         (void)MIDIPlayground(theFlags, in, out);
  42.  
  43.     CloseFiles(in, out, infile, outfile);
  44. }
  45.  
  46.     
  47. /************************************************************************
  48. * Handling command-line options.
  49. ************************************************************************/
  50.  
  51. BOOL HandleOptions(int argc, char *argv[], FLAGS theFlags[], char **infile,
  52.            char **outfile)
  53. {
  54.     int c;
  55.     BOOL success = TRUE;
  56.     static char options[] = GETOPT_OPTIONS;
  57.     
  58.     while ((c = getopt(argc, argv, options)) != EOF)
  59.     {
  60.         switch (c)
  61.         {
  62.           case OPT_INPUT:
  63.              success &= !theFlags[FLAG_ITYPE];
  64.              success &= CheckIOType(*optarg, FLAG_ITYPE, theFlags);
  65.              break;
  66.           case OPT_OUTPUT:
  67.              success &= !theFlags[FLAG_OTYPE];
  68.              success &= CheckIOType(*optarg, FLAG_OTYPE, theFlags);
  69.              break;
  70.           case OPT_INFILE:
  71.              success &= (optarg[0] != '\0');
  72.              success &= MakeFilename(infile, optarg);
  73.              break;
  74.           case OPT_OUTFILE:
  75.              success &= (optarg[0] != '\0');
  76.              success &= MakeFilename(outfile, optarg);
  77.              break;
  78.           case OPT_SYSEX:
  79.              success &= !theFlags[FLAG_SYSEX];
  80.              theFlags[FLAG_SYSEX]++;
  81.              break;
  82.           default:
  83.              success = FALSE;
  84.              break;
  85.         }
  86.     }
  87.     return(success && CheckFlags(theFlags));
  88. }
  89.  
  90.     
  91.