home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ed.zip / regexp.pat < prev    next >
Text File  |  1989-12-05  |  3KB  |  151 lines

  1. *** regexp.org
  2. --- regexp.h
  3. **************
  4. *** 15,20
  5.       char program[1];    /* Unwarranted chumminess with compiler. */
  6.   } regexp;
  7.   
  8.   extern regexp *regcomp();
  9.   extern int regexec();
  10.   extern void regsub();
  11. --- 15,26 -----
  12.       char program[1];    /* Unwarranted chumminess with compiler. */
  13.   } regexp;
  14.   
  15. + #ifdef __STDC__
  16. + extern regexp *regcomp( char * );
  17. + extern int regexec( regexp*, char* );
  18. + extern char *regsub( regexp*, char*, char* );
  19. + extern void regerror( char* );
  20. + #else
  21.   extern regexp *regcomp();
  22.   extern int regexec();
  23.   extern char *regsub();
  24. **************
  25. *** 17,21
  26.   
  27.   extern regexp *regcomp();
  28.   extern int regexec();
  29. ! extern void regsub();
  30.   extern void regerror();
  31. --- 23,28 -----
  32.   #else
  33.   extern regexp *regcomp();
  34.   extern int regexec();
  35. ! extern char *regsub();
  36.   extern void regerror();
  37.   #endif
  38. **************
  39. *** 19,21
  40.   extern int regexec();
  41.   extern void regsub();
  42.   extern void regerror();
  43. --- 25,28 -----
  44.   extern int regexec();
  45.   extern char *regsub();
  46.   extern void regerror();
  47. + #endif
  48. *** regsub.org
  49. --- regsub.c
  50. **************
  51. *** 18,23
  52.    *
  53.    *    3. Altered versions must be plainly marked as such, and must not
  54.    *        be misrepresented as being the original software.
  55.    */
  56.   #include <stdio.h>
  57.   #include <regexp.h>
  58. --- 18,27 -----
  59.    *
  60.    *    3. Altered versions must be plainly marked as such, and must not
  61.    *        be misrepresented as being the original software.
  62. +  *
  63. +  * This version modified by Ian Phillipps to return pointer to terminating
  64. +  * NUL on substitution string. [ Temp mail address ex-igp@camcon.co.uk ]
  65. +  *
  66.    */
  67.   #include <stdio.h>
  68.   #include <regexp.h>
  69. **************
  70. *** 32,38
  71.   /*
  72.    - regsub - perform substitutions after a regexp match
  73.    */
  74. ! void
  75.   regsub(prog, source, dest)
  76.   regexp *prog;
  77.   char *source;
  78. --- 36,42 -----
  79.   /*
  80.    - regsub - perform substitutions after a regexp match
  81.    */
  82. ! char *
  83.   regsub(prog, source, dest)
  84.   regexp *prog;
  85.   char *source;
  86. **************
  87. *** 47,53
  88.   
  89.       if (prog == NULL || source == NULL || dest == NULL) {
  90.           regerror("NULL parm to regsub");
  91. !         return;
  92.       }
  93.       if (UCHARAT(prog->program) != MAGIC) {
  94.           regerror("damaged regexp fed to regsub");
  95. --- 51,57 -----
  96.   
  97.       if (prog == NULL || source == NULL || dest == NULL) {
  98.           regerror("NULL parm to regsub");
  99. !         return NULL;
  100.       }
  101.       if (UCHARAT(prog->program) != MAGIC) {
  102.           regerror("damaged regexp fed to regsub");
  103. **************
  104. *** 51,57
  105.       }
  106.       if (UCHARAT(prog->program) != MAGIC) {
  107.           regerror("damaged regexp fed to regsub");
  108. !         return;
  109.       }
  110.   
  111.       src = source;
  112. --- 55,61 -----
  113.       }
  114.       if (UCHARAT(prog->program) != MAGIC) {
  115.           regerror("damaged regexp fed to regsub");
  116. !         return NULL;
  117.       }
  118.   
  119.       src = source;
  120. **************
  121. *** 74,80
  122.               dst += len;
  123.               if (len != 0 && *(dst-1) == '\0') {    /* strncpy hit NUL. */
  124.                   regerror("damaged match string");
  125. !                 return;
  126.               }
  127.           }
  128.       }
  129. --- 78,84 -----
  130.               dst += len;
  131.               if (len != 0 && *(dst-1) == '\0') {    /* strncpy hit NUL. */
  132.                   regerror("damaged match string");
  133. !                 return NULL;
  134.               }
  135.           }
  136.       }
  137. **************
  138. *** 78,82
  139.               }
  140.           }
  141.       }
  142. !     *dst++ = '\0';
  143.   }
  144. --- 82,87 -----
  145.               }
  146.           }
  147.       }
  148. !     *dst = '\0';
  149. !     return dst;
  150.   }
  151.