home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / Classes / RCString / matcher.m < prev    next >
Encoding:
Text File  |  1993-01-19  |  1.9 KB  |  96 lines

  1. //
  2. // testing of regular expression matching category.
  3. // Both GNU and BSD types, depending on compile-time
  4. // flag (GNU_REGEXP or BSD_REGEXP).
  5. #import <stdio.h>
  6. #import <stdlib.h>
  7. #import <signal.h>
  8. #import <fcntl.h>
  9. #import <string.h>
  10. #import <sys/time.h>
  11. #import <RCString.h>
  12.  
  13.  
  14. int
  15. main(int c, char **v)
  16. {
  17.     RCString *oString;
  18.     char buf[512];
  19.     char *bpMatch;
  20.     RCString *oMatch;
  21.     void usage();
  22.  
  23. #ifdef NeXT
  24.     int signalHandler();
  25.  
  26.     // install a few signal handlers
  27.     signal(SIGSEGV, signalHandler);
  28.     signal(SIGBUS,  signalHandler);
  29.     signal(SIGILL,  signalHandler);
  30.  
  31.     // turn on fairly high level of malloc error checking
  32.     malloc_debug(16);
  33. #endif NeXT
  34.  
  35.     if (c < 4) {
  36.         usage(*v);
  37.         exit(1);
  38.     }
  39.  
  40.     // pause to allow use of MallocDebug 
  41.     if (c > 4)
  42.         gets(buf);
  43.  
  44.     oString = [RCString newFromString:*(v + 1)];
  45.     if (oString) {
  46.         printf("\"%s\" %s regular expression \"%s\"\n",
  47.             [oString data],
  48.             [oString matches:*(v + 2)]?"MATCHES" : "DOESN'T MATCH",
  49.             *(v + 2));
  50.  
  51.         if ((bpMatch = [oString subStringMatching:*(v + 2)]))
  52.         {
  53.             printf("string that matches: \"%s\"\n", bpMatch);
  54.             free(bpMatch);
  55.         } else {
  56.             fprintf(stderr, "NULL string from match\n");
  57.         }
  58.  
  59.         if ((oMatch = [oString objectMatching:*(v + 2)]))
  60.         {
  61.             printf("string from object that matches: \"%s\"\n",
  62.                 [oMatch data]);
  63.             [oMatch free];
  64.         } else {
  65.             fprintf(stderr, "NULL object from match\n");
  66.         }
  67.  
  68.         printf("string from object (with replacement): \"%s\"\n",
  69.             [[oString replaceSubStringMatching:*(v + 2) with:*(v + 3)] data]);
  70.     
  71.         free(oString);
  72.     }
  73.  
  74.     // pause to allow use of MallocDebug 
  75.     if (c > 4)
  76.         gets(buf);
  77.  
  78.     return(0);
  79. }
  80.  
  81. void
  82. usage(char *command)
  83. {
  84.     fprintf(stderr, "%s: check regular expression stuff\n", command);
  85.     fprintf(stderr, "usage: %s string regexp replacment_string\n", command);
  86. }
  87.  
  88. #ifdef NeXT
  89. int
  90. signalHandler(int something)
  91. {
  92.     printf("signalHandler(%d) (0x%x)\n", something, (unsigned int)something);
  93.     exit(0);
  94. }
  95. #endif
  96.