home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / intercal.zip / src / arrgghh.c < prev    next >
C/C++ Source or Header  |  1996-06-09  |  3KB  |  102 lines

  1. /* 
  2.  *    SYNOPSIS:    parseargs(argc,argv)
  3.  *    FILE :        parseargs.c
  4.  *    AUTHOR :    Steve Swales
  5.  *    DATE:        October 7, 1990
  6.  *    PURPOSE:     Parse arguments for INTERCAL programs.
  7.  *
  8. LICENSE TERMS
  9.     Copyright (C) 1996 Eric S. Raymond 
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include "abcess.h"
  29. #include "lose.h"
  30.  
  31. int traditional = 0;
  32. int wimp_mode = 0;
  33.  
  34. void
  35. parseargs(int argc, char **argv)
  36. {
  37.     register int i, j;
  38.     static int helpflag = -1;
  39.     static char *flags[] = {
  40.     "help",
  41.     "wimpmode",
  42.     "traditional"
  43.       };
  44.     static int *bools[] = {
  45.     &helpflag,
  46.     &wimp_mode,
  47.     &traditional
  48.       };
  49.     static int nflags = (int)(sizeof(flags)/sizeof(flags[0]));
  50.  
  51.     for(i = 1;i < argc;i++) {
  52.     if(argv[i][0] != '+' && argv[i][0] != '-') {
  53.         break;
  54.     }
  55.     for(j = 0; j < nflags;j++) {
  56.         if(0 == strcmp(argv[i]+1,flags[j])) {
  57.         *(bools[j]) = (argv[i][0] == '+');
  58.         break;
  59.         }
  60.     }
  61.     if(j == nflags) {
  62.         fprintf(stderr,"%s: can't grok %s\n",argv[0],argv[i]);
  63.         helpflag = 1;
  64.     }
  65.     }
  66.     if(helpflag != -1) {
  67.     if(!helpflag) {
  68.         fprintf(stderr,
  69.             "Once you start messing with INTERCAL... \n");
  70.         fprintf(stderr,"\t\tthere is no help for you!\n\n");
  71.         sleep(3);
  72.     }
  73.     fprintf(stderr,"Current flags (and current state) are:\n");
  74.     for(i = 0;i < nflags;i++) {
  75.         fprintf(stderr,"\t[+/-]%-20.20s\t(%s)\n",flags[i],
  76.             (*(bools[i]) == 1)?"ON":((*(bools[i]) == 0)?"OFF":"???"));
  77.     }
  78.     fprintf(stderr,"All flags must be preceded by either + or -, which\n");
  79.     fprintf(stderr," usually will mean turn on or turn off something,\n");
  80.     fprintf(stderr," but not always, and not all of them currently\n");
  81.     fprintf(stderr," do anything, but you can switch them on or off\n");
  82.     fprintf(stderr," if you like anyway. Isn't this helpful?\n\n");
  83.     fflush(stderr);
  84.     sleep(3);
  85.     lose(E778, 0, (char *)NULL);
  86.     }
  87.     if(wimp_mode) {
  88.     fprintf(stderr,"How sad... you have selected to run an INTERCAL\n");
  89.     fprintf(stderr,"program in WIMP MODE.\n\n");
  90.     fprintf(stderr,"This means that:\n");
  91.     fprintf(stderr," A) Rather than the nifty input like:\n");
  92.     fprintf(stderr,"\tONE NINER SEVEN TWO OH SIX THREE,\n");
  93.     fprintf(stderr,"    and even niftier output like:\n");
  94.     fprintf(stderr,"\t______\n");
  95.     fprintf(stderr,"\tMCMLXXMMLXIII,\n");
  96.     fprintf(stderr,"    you will have to settle for plain old number\n");
  97.     fprintf(stderr,"    representations like 1972063; and,\n");
  98.     fprintf(stderr," B) You are a WIMP!\n\n");
  99.     fflush(stderr);
  100.     }
  101. }
  102.