home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / c / cpp.lha / member.c < prev    next >
C/C++ Source or Header  |  1991-04-15  |  1KB  |  67 lines

  1. /*
  2.  
  3.  
  4.  Copyright (C) 1990 Texas Instruments Incorporated.
  5.  
  6.  Permission is granted to any individual or institution to use, copy, modify,
  7.  and distribute this software, provided that this complete copyright and
  8.  permission notice is maintained, intact, in all copies and supporting
  9.  documentation.
  10.  
  11.  Texas Instruments Incorporated provides this software "as is" without
  12.  express or implied warranty.
  13.  
  14.  
  15.  *
  16.  * Edit history
  17.  * Created: LGO 30-Mar-89 -- Initial design and implementation.
  18.  *
  19.  * ISSAME defmacro
  20.  *
  21.  * #pragma defmacro ISSAME "member" delimiter=) expanding
  22.  *
  23.  * CPP defmacro for doing symbolic comparisions
  24.  * The input looks like ISSAME(arg1, arg2, ..., argn)
  25.  * The output is "1" when arg1 is the same as one of the other args, else "0".
  26.  *
  27.  */
  28.  
  29. #include "defmacio.h"
  30.  
  31. #define BSIZE 512
  32.  
  33. member(argc, argv)
  34.    int argc;
  35.    char** argv;
  36. {
  37.   char c;
  38.   char macname[BSIZE];
  39.   char* arg1;
  40.   char* arg2;
  41.  
  42.   if(copytoken(macname) == NULL)      /* Skip macro name */
  43.     return(1);
  44.  
  45.   c = skip_blanks();
  46.   if(c != '(') {
  47.     fprintf(stderr, "%s: Can't find argument list\n", macname);
  48.     return 1;
  49.   }
  50.  
  51.   arg1 = scan_token(",)");
  52.   getchar();
  53.   do {
  54.     arg2 = scan_token(",)");
  55.     if(strcmp(arg1, arg2) == 0) {
  56.       putchar('1');
  57.       goto exit;
  58.     }
  59.     free(arg2);
  60.   } while (getchar() != ')');
  61.   putchar('0');
  62.  exit:
  63.   free(arg1);
  64.   free(arg2);
  65.   return 0;
  66. }
  67.