home *** CD-ROM | disk | FTP | other *** search
/ Mega CD-ROM 1 / megacd_rom_1.zip / megacd_rom_1 / GNUISH / SED106.ZIP / PATCHES < prev    next >
Text File  |  1990-09-22  |  13KB  |  523 lines

  1. *** e:\tmp/RCSt1006323    Sat Sep 22 18:15:06 1990
  2. --- sed.c    Sat Sep 22 18:11:00 1990
  3. ***************
  4. *** 1,4 ****
  5.   /*  GNU SED, a batch stream editor.
  6.       Copyright (C) 1989, Free Software Foundation, Inc.
  7.   
  8. --- 1,3 ----
  9. ***************
  10. *** 16,23 ****
  11. --- 15,37 ----
  12.       along with this program; if not, write to the Free Software
  13.       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  14.   
  15. + /*  MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  16. +     This port is also distributed under the terms of the
  17. +     GNU General Public License as published by the
  18. +     Free Software Foundation.
  19. +     Please note that this file is not identical to the
  20. +     original GNU release, you should have received this
  21. +     code as patch to the official release.  */
  22. + #ifdef MSDOS
  23. + static char RCS_Id[] =
  24. +   "$Header: e:/gnu/sed/RCS/sed.c 1.6.1.2 90/09/22 17:14:48 tho Exp $";
  25. + #endif
  26.   #include <stdio.h>
  27.   #include <ctype.h>
  28.   #include <regex.h>
  29.   
  30.   /* Compile with 'gcc [-g] [-DHAS_UTILS] [-O] -o sed sed.c [-lutils]' */
  31. ***************
  32. *** 25,31 ****
  33. --- 39,63 ----
  34.   /* Add '-I. regex.c' if regex is not in the system include dir/library */
  35.   
  36.   /* This is a good idea */
  37. + #ifdef MSDOS
  38. + static char Program_Id[] = "sed";
  39. + static char RCS_Revision[] = "$Revision: 1.6.1.2 $";
  40. + #define VERSION \
  41. +   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  42. +   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  43. + #define COPYING \
  44. +   "This is free software, distributed under the terms of the\n" \
  45. +   "GNU General Public License.  For details, see the file COPYING.\n"
  46. + #else /* not MSDOS */
  47.   char *version_string = "GNU sed version 1.06 (or so)";
  48. + #endif /* not MSDOS */
  49.   /*
  50.       1.00    Began (thinking about) distributing this file
  51.       1.01    Added s/re/rep/[digits]
  52. ***************
  53. *** 43,49 ****
  54.    */
  55.   
  56.   #ifdef USG
  57. ! #define bcopy(s, d, n) ((void)memcpy((d),(s), (n)))
  58.   #endif
  59.   
  60.   /* Struct vector is used to describe a chunk of a sed program.  There is one
  61. --- 75,81 ----
  62.    */
  63.   
  64.   #ifdef USG
  65. ! #define bcopy( s, d, n) ((void)memmove((d), (s), (n)))
  66.   #endif
  67.   
  68.   /* Struct vector is used to describe a chunk of a sed program.  There is one
  69. ***************
  70. *** 175,190 ****
  71.   
  72.   
  73.   /* This for all you losing compilers out there that can't handle void * */
  74. ! #ifdef __GNU__
  75.   #define VOID void
  76.   #else
  77.   #define VOID char
  78.   #endif
  79.   
  80. ! extern int optind;
  81. ! extern char *optarg;
  82. ! extern int getopt();
  83.   
  84.   extern char *memchr();
  85.   extern VOID *memmove();
  86.   
  87. --- 207,268 ----
  88.   
  89.   
  90.   /* This for all you losing compilers out there that can't handle void * */
  91. ! #if defined( __GNU__ ) || defined( MSDOS )
  92.   #define VOID void
  93.   #else
  94.   #define VOID char
  95.   #endif
  96.   
  97. ! #include "getopt.h"
  98. ! #ifdef MSDOS
  99. ! #include <stdlib.h>
  100. ! #include <string.h>
  101. ! #include <gnulib.h>
  102. ! #ifndef STDIO_BUFSIZE
  103. ! #define STDIO_BUFSIZE    0x4000
  104. ! #endif
  105. ! extern  void main (int argc, char **argv);
  106. ! static  char *get_buffer (VOID *);
  107. ! static  char *__fp_name (FILE *);
  108. ! static  FILE *ck_fopen (char *, char *);
  109. ! static  FILE *compile_filename (int);
  110. ! static  int compile_address (struct addr *);
  111. ! static  int inchar (void);
  112. ! static  int match_address (struct addr *);
  113. ! static  int read_pattern_space (void);
  114. ! static  int size_buffer (VOID *);
  115. ! static  struct sed_label *setup_jump(struct sed_label *, struct sed_cmd *,
  116. !                      struct vector *);
  117. ! static  struct vector *compile_program (struct vector *);
  118. ! static  VOID *ck_malloc (int);
  119. ! static  VOID *ck_realloc (VOID *, int);
  120. ! static  VOID *init_buffer (void);
  121. ! static  void add1_buffer (VOID *, int);
  122. ! static  void add_buffer (VOID *, VOID *, int);
  123. ! static  void append_pattern_space (void);
  124. ! static  void bad_prog (char *);
  125. ! static  void ck_fclose (FILE *);
  126. ! static  void ck_fwrite (char *, int, int, FILE *);
  127. ! static  void compile_file (char *);
  128. ! static  void compile_string (char *);
  129. ! static  void compile_regex (int);
  130. ! static  void execute_program (struct vector *);
  131. ! static  void flush_buffer (VOID *);
  132. ! static  void line_append (struct line *, struct line *);
  133. ! static  void line_copy (struct line *, struct line *);
  134. ! static  void panic (char *,...);
  135. ! static  void read_file (char *);
  136. ! static  void savchar (int);
  137. ! static  void str_append (struct line *, char *, int);
  138.   
  139. + #else /* not MSDOS */
  140.   extern char *memchr();
  141.   extern VOID *memmove();
  142.   
  143. ***************
  144. *** 209,214 ****
  145. --- 287,294 ----
  146.   void execute_program();
  147.   void compile_regex ();
  148.   
  149. + #endif /* not MSDOS */
  150.   #ifndef HAS_UTILS
  151.   char *myname;
  152.   #else
  153. ***************
  154. *** 297,309 ****
  155.   static char NO_ADDR[] = "Command doesn't take any addresses";
  156.   static char LINE_JUNK[] ="Extra characters after command";
  157.   static char BAD_EOF[] =  "Unexpected End-of-file";
  158.   static char USAGE[] =   "Usage: %s [-n] [-e script...] [-f sfile...] [file...]\n";
  159.   static char NO_REGEX[] = "No previous regular expression";
  160.   
  161.   /* Yes, the main program, which parses arguments, and does the right thing with them,
  162.      It also inits the temporary storage, etc. */
  163. ! main(argc,argv)
  164. ! char **argv;
  165.   {
  166.       int opt;
  167.       int compiled = 0;
  168. --- 377,396 ----
  169.   static char NO_ADDR[] = "Command doesn't take any addresses";
  170.   static char LINE_JUNK[] ="Extra characters after command";
  171.   static char BAD_EOF[] =  "Unexpected End-of-file";
  172. + #ifdef MSDOS
  173. + static char USAGE[] =
  174. +   "Usage: %s [-CV] [-n] [-e script...] [-f sfile...] [file...]\n";
  175. + #else
  176.   static char USAGE[] =   "Usage: %s [-n] [-e script...] [-f sfile...] [file...]\n";
  177. + #endif
  178.   static char NO_REGEX[] = "No previous regular expression";
  179.   
  180.   /* Yes, the main program, which parses arguments, and does the right thing with them,
  181.      It also inits the temporary storage, etc. */
  182. ! void
  183. ! main (argc, argv)
  184. !   int argc;
  185. !   char **argv;
  186.   {
  187.       int opt;
  188.       int compiled = 0;
  189. ***************
  190. *** 310,316 ****
  191. --- 397,408 ----
  192.       struct sed_label *go,*lbl;
  193.   
  194.       myname=argv[0];
  195. + #ifdef MSDOS
  196. +     while((opt=getopt(argc,argv,"ne:f:CV"))!=EOF) {
  197. + #else
  198.       while((opt=getopt(argc,argv,"ne:f:"))!=EOF) {
  199. + #endif
  200.           switch(opt) {
  201.           case 'n':
  202.               if(no_default_output)
  203. ***************
  204. *** 325,332 ****
  205. --- 417,442 ----
  206.               compile_file(optarg);
  207.               compiled++;
  208.               break;
  209. + #ifdef MSDOS
  210. +         case 'C':
  211. +             fprintf (stderr, COPYING);
  212. +             exit (0);
  213. +             break;
  214. +         case 'V':
  215. +             fprintf (stderr, VERSION);
  216. +             exit (0);
  217. +             break;
  218. +         default:
  219. +             fprintf (stderr, USAGE, myname);
  220. +             exit (4);
  221. +             break;
  222. + #endif /* MSDOS */
  223.           }
  224.       }
  225. + #ifdef MSDOS
  226. +     if (setvbuf (stdout, NULL, _IOFBF, STDIO_BUFSIZE) != 0)
  227. +       panic ("can't adjust buffering for /dev/stdout");
  228. + #endif
  229.       if(!compiled) {
  230.           if(argc<=optind)
  231.               panic("No program to run\n");
  232. ***************
  233. *** 373,378 ****
  234. --- 483,489 ----
  235.   
  236.   /* 'str' is a string (from the command line) that contains a sed command.
  237.      Compile the command, and add it to the end of 'the_program' */
  238. + void
  239.   compile_string(str)
  240.   char *str;
  241.   {
  242. ***************
  243. *** 385,390 ****
  244. --- 496,502 ----
  245.   
  246.   /* 'str' is the name of a file containing sed commands.  Read them in
  247.      and add them to the end of 'the_program' */
  248. + void
  249.   compile_file(str)
  250.   char *str;
  251.   {
  252. ***************
  253. *** 685,690 ****
  254. --- 797,803 ----
  255.   }
  256.   
  257.   /* Complain about a programming error and exit. */
  258. + void
  259.   bad_prog(why)
  260.   char *why;
  261.   {
  262. ***************
  263. *** 748,754 ****
  264. --- 861,871 ----
  265.   {
  266.       int    ch;
  267.       int    num;
  268. + #ifdef MSDOS
  269. +     char    *b;
  270. + #else
  271.       char    *b,*init_buffer();
  272. + #endif
  273.   
  274.       ch=inchar();
  275.   
  276. ***************
  277. *** 783,788 ****
  278. --- 900,906 ----
  279.   
  280.   void
  281.   compile_regex (slash)
  282. +   int slash;
  283.   {
  284.       VOID *b;
  285.       int ch;
  286. ***************
  287. *** 839,846 ****
  288. --- 957,973 ----
  289.       if(size_buffer(b)) {
  290.           last_regex=(struct re_pattern_buffer *)ck_malloc(sizeof(struct re_pattern_buffer));
  291.           last_regex->allocated=size_buffer(b);
  292. + #ifdef MSDOS
  293. +         last_regex->buffer
  294. +           = ck_malloc ((size_t) last_regex->allocated);
  295. + #else
  296.           last_regex->buffer=ck_malloc(last_regex->allocated);
  297. + #endif
  298. + #ifdef __LOOSE_WITHOUT_FASTMAP__    /* who would want to ??? */
  299.           last_regex->fastmap=0;
  300. + #else
  301. +         last_regex->fastmap = ck_malloc (1 << BYTEWIDTH);
  302. + #endif
  303.           last_regex->translate=0;
  304.           re_compile_pattern(get_buffer(b),size_buffer(b),last_regex);
  305.       } else if(!last_regex)
  306. ***************
  307. *** 881,886 ****
  308. --- 1008,1014 ----
  309.      opened if it isn't already open. */
  310.   FILE *
  311.   compile_filename(readit)
  312. +   int readit;
  313.   {
  314.       char *file_name;
  315.       int n;
  316. ***************
  317. *** 935,943 ****
  318. --- 1063,1073 ----
  319.       else {
  320.           input_file=fopen(name,"r");
  321.           if(input_file==0) {
  322. + #ifndef MSDOS
  323.               extern int errno;
  324.               extern char *sys_errlist[];
  325.               extern int sys_nerr;
  326. + #endif
  327.   
  328.               char *ptr;
  329.   
  330. ***************
  331. *** 948,953 ****
  332. --- 1078,1088 ----
  333.               return;
  334.           }
  335.       }
  336. + #ifdef MSDOS
  337. +     if (setvbuf (input_file, NULL, _IOFBF, STDIO_BUFSIZE) != 0)
  338. +       panic ("can't adjust buffering for %s",
  339. +          (*name=='-' && name[1]=='\0') ? "/dev/stdin" : name);
  340. + #endif
  341.       while(read_pattern_space()) {
  342.           execute_program(the_program);
  343.           if(!no_default_output)
  344. ***************
  345. *** 1162,1168 ****
  346. --- 1297,1309 ----
  347.                   char *tmp;
  348.   
  349.                   tmp=memchr(line.text,'\n',line.length);
  350. + #ifdef __BUG__
  351. +                 /* this can't be true! obviously copied from 'D'
  352. +                    (where it is correct). [tho] */
  353.                   ck_fwrite(line.text,1,line.length-(tmp-line.text),stdout);
  354. + #else /* FIXED */
  355. +                 ck_fwrite(line.text,1,tmp-line.text,stdout);
  356. + #endif /* FIXED */
  357.               }
  358.               break;
  359.   
  360. ***************
  361. *** 1259,1265 ****
  362. --- 1400,1413 ----
  363.               if(!count)
  364.                   break;
  365.               replaced=1;
  366. + #ifdef __BUG__
  367. +             /* This is wrong (at least with the new regex library)
  368. +                after the last (failed!) re_search() the registers
  369. +                will be set to -1!  [tho] */
  370.               str_append(&tmp,line.text+regs.end[0],line.length-regs.end[0]);
  371. + #else /* FIXED */
  372. +             str_append(&tmp,line.text+start,line.length-start);
  373. + #endif /* FIXED */
  374.               t.text=line.text;
  375.               t.length=line.length;
  376.               t.alloc=line.alloc;
  377. ***************
  378. *** 1503,1510 ****
  379. --- 1651,1664 ----
  380.   #include "stdarg.h"
  381.   
  382.   /* Print an error message and exit */
  383. + #ifdef MSDOS
  384. + void
  385. + panic (char *str, ...)
  386. + #else /* not MSDOS */
  387. + void
  388.   panic(str)
  389.   char *str;
  390. + #endif /* not MSDOS */
  391.   {
  392.       va_list iggy;
  393.   
  394. ***************
  395. *** 1520,1526 ****
  396.       exit(4);
  397.   }
  398.   
  399. ! #else
  400.   #include "varargs.h"
  401.   
  402.   panic(str,va_alist)
  403. --- 1674,1680 ----
  404.       exit(4);
  405.   }
  406.   
  407. ! #else /* not __STDC__ */
  408.   #include "varargs.h"
  409.   
  410.   panic(str,va_alist)
  411. ***************
  412. *** 1541,1547 ****
  413.       exit(4);
  414.   }
  415.   
  416. ! #endif
  417.   
  418.   /* Store information about files opened with ck_fopen
  419.      so that error messages from ck_fread, etc can print the
  420. --- 1695,1701 ----
  421.       exit(4);
  422.   }
  423.   
  424. ! #endif /* not __STDC__ */
  425.   
  426.   /* Store information about files opened with ck_fopen
  427.      so that error messages from ck_fread, etc can print the
  428. ***************
  429. *** 1599,1604 ****
  430. --- 1753,1762 ----
  431.           __id_s[n].name=(char *)ck_malloc(strlen(name)+1);
  432.           strcpy(__id_s[n].name,name);
  433.       }
  434. + #ifdef MSDOS
  435. +     if (setvbuf (ret, NULL, _IOFBF, STDIO_BUFSIZE) != 0)
  436. +       panic ("can't adjust buffering for %s", name);
  437. + #endif
  438.       return ret;
  439.   }
  440.   
  441. ***************
  442. *** 1628,1634 ****
  443. --- 1786,1794 ----
  444.   int size;
  445.   {
  446.       VOID *ret;
  447. + #ifndef MSDOS
  448.       VOID *malloc();
  449. + #endif
  450.   
  451.       ret=malloc(size);
  452.       if(ret==(VOID *)0)
  453. ***************
  454. *** 1643,1649 ****
  455. --- 1803,1811 ----
  456.   int size;
  457.   {
  458.       VOID *ret;
  459. + #ifndef MSDOS
  460.       VOID *realloc();
  461. + #endif
  462.   
  463.       ret=realloc(ptr,size);
  464.       if(ret==(VOID *)0)
  465. ***************
  466. *** 1651,1656 ****
  467. --- 1813,1820 ----
  468.       return ret;
  469.   }
  470.   
  471. + #ifndef MSDOS
  472.   /* Return a malloc()'d copy of a string */
  473.   char *
  474.   strdup(str)
  475. ***************
  476. *** 1682,1688 ****
  477. --- 1846,1857 ----
  478.       scan = (char *)s;
  479.       uc = (ucharwanted&0xFF);
  480.       for (n = size; n > 0; n--)
  481. + #ifdef __BUG__
  482. +         /* Nope, '==' has higher precedence than '&' ... [tho]  */
  483.           if ((*scan)&0xFF == uc)
  484. + #else /* FIXED */
  485. +         if ( ((*scan)&0xFF) == uc)
  486. + #endif /* FIXED */
  487.               return((VOID *)scan);
  488.           else
  489.               scan++;
  490. ***************
  491. *** 1721,1726 ****
  492. --- 1890,1897 ----
  493.   
  494.       return(dst);
  495.   }
  496. + #endif /* not MSDOS */
  497.   
  498.   /* Implement a variable sized buffer of 'stuff'.  We don't know what it is,
  499.      nor do we care, as long as it doesn't mind being aligned by malloc. */
  500.