home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
gnuish
/
sed106.arc
/
patches
< prev
next >
Wrap
Text File
|
1990-09-22
|
13KB
|
523 lines
*** e:\tmp/RCSt1006323 Sat Sep 22 18:15:06 1990
--- sed.c Sat Sep 22 18:11:00 1990
***************
*** 1,4 ****
-
/* GNU SED, a batch stream editor.
Copyright (C) 1989, Free Software Foundation, Inc.
--- 1,3 ----
***************
*** 16,23 ****
--- 15,37 ----
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
+ This port is also distributed under the terms of the
+ GNU General Public License as published by the
+ Free Software Foundation.
+
+ Please note that this file is not identical to the
+ original GNU release, you should have received this
+ code as patch to the official release. */
+
+ #ifdef MSDOS
+ static char RCS_Id[] =
+ "$Header: e:/gnu/sed/RCS/sed.c 1.6.1.2 90/09/22 17:14:48 tho Exp $";
+ #endif
+
#include <stdio.h>
#include <ctype.h>
+
#include <regex.h>
/* Compile with 'gcc [-g] [-DHAS_UTILS] [-O] -o sed sed.c [-lutils]' */
***************
*** 25,31 ****
--- 39,63 ----
/* Add '-I. regex.c' if regex is not in the system include dir/library */
/* This is a good idea */
+
+ #ifdef MSDOS
+
+ static char Program_Id[] = "sed";
+ static char RCS_Revision[] = "$Revision: 1.6.1.2 $";
+
+ #define VERSION \
+ "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
+ (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
+
+ #define COPYING \
+ "This is free software, distributed under the terms of the\n" \
+ "GNU General Public License. For details, see the file COPYING.\n"
+
+ #else /* not MSDOS */
+
char *version_string = "GNU sed version 1.06 (or so)";
+
+ #endif /* not MSDOS */
/*
1.00 Began (thinking about) distributing this file
1.01 Added s/re/rep/[digits]
***************
*** 43,49 ****
*/
#ifdef USG
! #define bcopy(s, d, n) ((void)memcpy((d),(s), (n)))
#endif
/* Struct vector is used to describe a chunk of a sed program. There is one
--- 75,81 ----
*/
#ifdef USG
! #define bcopy( s, d, n) ((void)memmove((d), (s), (n)))
#endif
/* Struct vector is used to describe a chunk of a sed program. There is one
***************
*** 175,190 ****
/* This for all you losing compilers out there that can't handle void * */
! #ifdef __GNU__
#define VOID void
#else
#define VOID char
#endif
! extern int optind;
! extern char *optarg;
! extern int getopt();
extern char *memchr();
extern VOID *memmove();
--- 207,268 ----
/* This for all you losing compilers out there that can't handle void * */
! #if defined( __GNU__ ) || defined( MSDOS )
#define VOID void
#else
#define VOID char
#endif
! #include "getopt.h"
!
! #ifdef MSDOS
!
! #include <stdlib.h>
! #include <string.h>
!
! #include <gnulib.h>
!
! #ifndef STDIO_BUFSIZE
! #define STDIO_BUFSIZE 0x4000
! #endif
!
! extern void main (int argc, char **argv);
!
! static char *get_buffer (VOID *);
! static char *__fp_name (FILE *);
! static FILE *ck_fopen (char *, char *);
! static FILE *compile_filename (int);
! static int compile_address (struct addr *);
! static int inchar (void);
! static int match_address (struct addr *);
! static int read_pattern_space (void);
! static int size_buffer (VOID *);
! static struct sed_label *setup_jump(struct sed_label *, struct sed_cmd *,
! struct vector *);
! static struct vector *compile_program (struct vector *);
! static VOID *ck_malloc (int);
! static VOID *ck_realloc (VOID *, int);
! static VOID *init_buffer (void);
! static void add1_buffer (VOID *, int);
! static void add_buffer (VOID *, VOID *, int);
! static void append_pattern_space (void);
! static void bad_prog (char *);
! static void ck_fclose (FILE *);
! static void ck_fwrite (char *, int, int, FILE *);
! static void compile_file (char *);
! static void compile_string (char *);
! static void compile_regex (int);
! static void execute_program (struct vector *);
! static void flush_buffer (VOID *);
! static void line_append (struct line *, struct line *);
! static void line_copy (struct line *, struct line *);
! static void panic (char *,...);
! static void read_file (char *);
! static void savchar (int);
! static void str_append (struct line *, char *, int);
+ #else /* not MSDOS */
+
extern char *memchr();
extern VOID *memmove();
***************
*** 209,214 ****
--- 287,294 ----
void execute_program();
void compile_regex ();
+ #endif /* not MSDOS */
+
#ifndef HAS_UTILS
char *myname;
#else
***************
*** 297,309 ****
static char NO_ADDR[] = "Command doesn't take any addresses";
static char LINE_JUNK[] ="Extra characters after command";
static char BAD_EOF[] = "Unexpected End-of-file";
static char USAGE[] = "Usage: %s [-n] [-e script...] [-f sfile...] [file...]\n";
static char NO_REGEX[] = "No previous regular expression";
/* Yes, the main program, which parses arguments, and does the right thing with them,
It also inits the temporary storage, etc. */
! main(argc,argv)
! char **argv;
{
int opt;
int compiled = 0;
--- 377,396 ----
static char NO_ADDR[] = "Command doesn't take any addresses";
static char LINE_JUNK[] ="Extra characters after command";
static char BAD_EOF[] = "Unexpected End-of-file";
+ #ifdef MSDOS
+ static char USAGE[] =
+ "Usage: %s [-CV] [-n] [-e script...] [-f sfile...] [file...]\n";
+ #else
static char USAGE[] = "Usage: %s [-n] [-e script...] [-f sfile...] [file...]\n";
+ #endif
static char NO_REGEX[] = "No previous regular expression";
/* Yes, the main program, which parses arguments, and does the right thing with them,
It also inits the temporary storage, etc. */
! void
! main (argc, argv)
! int argc;
! char **argv;
{
int opt;
int compiled = 0;
***************
*** 310,316 ****
--- 397,408 ----
struct sed_label *go,*lbl;
myname=argv[0];
+
+ #ifdef MSDOS
+ while((opt=getopt(argc,argv,"ne:f:CV"))!=EOF) {
+ #else
while((opt=getopt(argc,argv,"ne:f:"))!=EOF) {
+ #endif
switch(opt) {
case 'n':
if(no_default_output)
***************
*** 325,332 ****
--- 417,442 ----
compile_file(optarg);
compiled++;
break;
+ #ifdef MSDOS
+ case 'C':
+ fprintf (stderr, COPYING);
+ exit (0);
+ break;
+ case 'V':
+ fprintf (stderr, VERSION);
+ exit (0);
+ break;
+ default:
+ fprintf (stderr, USAGE, myname);
+ exit (4);
+ break;
+ #endif /* MSDOS */
}
}
+ #ifdef MSDOS
+ if (setvbuf (stdout, NULL, _IOFBF, STDIO_BUFSIZE) != 0)
+ panic ("can't adjust buffering for /dev/stdout");
+ #endif
if(!compiled) {
if(argc<=optind)
panic("No program to run\n");
***************
*** 373,378 ****
--- 483,489 ----
/* 'str' is a string (from the command line) that contains a sed command.
Compile the command, and add it to the end of 'the_program' */
+ void
compile_string(str)
char *str;
{
***************
*** 385,390 ****
--- 496,502 ----
/* 'str' is the name of a file containing sed commands. Read them in
and add them to the end of 'the_program' */
+ void
compile_file(str)
char *str;
{
***************
*** 685,690 ****
--- 797,803 ----
}
/* Complain about a programming error and exit. */
+ void
bad_prog(why)
char *why;
{
***************
*** 748,754 ****
--- 861,871 ----
{
int ch;
int num;
+ #ifdef MSDOS
+ char *b;
+ #else
char *b,*init_buffer();
+ #endif
ch=inchar();
***************
*** 783,788 ****
--- 900,906 ----
void
compile_regex (slash)
+ int slash;
{
VOID *b;
int ch;
***************
*** 839,846 ****
--- 957,973 ----
if(size_buffer(b)) {
last_regex=(struct re_pattern_buffer *)ck_malloc(sizeof(struct re_pattern_buffer));
last_regex->allocated=size_buffer(b);
+ #ifdef MSDOS
+ last_regex->buffer
+ = ck_malloc ((size_t) last_regex->allocated);
+ #else
last_regex->buffer=ck_malloc(last_regex->allocated);
+ #endif
+ #ifdef __LOOSE_WITHOUT_FASTMAP__ /* who would want to ??? */
last_regex->fastmap=0;
+ #else
+ last_regex->fastmap = ck_malloc (1 << BYTEWIDTH);
+ #endif
last_regex->translate=0;
re_compile_pattern(get_buffer(b),size_buffer(b),last_regex);
} else if(!last_regex)
***************
*** 881,886 ****
--- 1008,1014 ----
opened if it isn't already open. */
FILE *
compile_filename(readit)
+ int readit;
{
char *file_name;
int n;
***************
*** 935,943 ****
--- 1063,1073 ----
else {
input_file=fopen(name,"r");
if(input_file==0) {
+ #ifndef MSDOS
extern int errno;
extern char *sys_errlist[];
extern int sys_nerr;
+ #endif
char *ptr;
***************
*** 948,953 ****
--- 1078,1088 ----
return;
}
}
+ #ifdef MSDOS
+ if (setvbuf (input_file, NULL, _IOFBF, STDIO_BUFSIZE) != 0)
+ panic ("can't adjust buffering for %s",
+ (*name=='-' && name[1]=='\0') ? "/dev/stdin" : name);
+ #endif
while(read_pattern_space()) {
execute_program(the_program);
if(!no_default_output)
***************
*** 1162,1168 ****
--- 1297,1309 ----
char *tmp;
tmp=memchr(line.text,'\n',line.length);
+ #ifdef __BUG__
+ /* this can't be true! obviously copied from 'D'
+ (where it is correct). [tho] */
ck_fwrite(line.text,1,line.length-(tmp-line.text),stdout);
+ #else /* FIXED */
+ ck_fwrite(line.text,1,tmp-line.text,stdout);
+ #endif /* FIXED */
}
break;
***************
*** 1259,1265 ****
--- 1400,1413 ----
if(!count)
break;
replaced=1;
+ #ifdef __BUG__
+ /* This is wrong (at least with the new regex library)
+ after the last (failed!) re_search() the registers
+ will be set to -1! [tho] */
str_append(&tmp,line.text+regs.end[0],line.length-regs.end[0]);
+ #else /* FIXED */
+ str_append(&tmp,line.text+start,line.length-start);
+ #endif /* FIXED */
t.text=line.text;
t.length=line.length;
t.alloc=line.alloc;
***************
*** 1503,1510 ****
--- 1651,1664 ----
#include "stdarg.h"
/* Print an error message and exit */
+ #ifdef MSDOS
+ void
+ panic (char *str, ...)
+ #else /* not MSDOS */
+ void
panic(str)
char *str;
+ #endif /* not MSDOS */
{
va_list iggy;
***************
*** 1520,1526 ****
exit(4);
}
! #else
#include "varargs.h"
panic(str,va_alist)
--- 1674,1680 ----
exit(4);
}
! #else /* not __STDC__ */
#include "varargs.h"
panic(str,va_alist)
***************
*** 1541,1547 ****
exit(4);
}
! #endif
/* Store information about files opened with ck_fopen
so that error messages from ck_fread, etc can print the
--- 1695,1701 ----
exit(4);
}
! #endif /* not __STDC__ */
/* Store information about files opened with ck_fopen
so that error messages from ck_fread, etc can print the
***************
*** 1599,1604 ****
--- 1753,1762 ----
__id_s[n].name=(char *)ck_malloc(strlen(name)+1);
strcpy(__id_s[n].name,name);
}
+ #ifdef MSDOS
+ if (setvbuf (ret, NULL, _IOFBF, STDIO_BUFSIZE) != 0)
+ panic ("can't adjust buffering for %s", name);
+ #endif
return ret;
}
***************
*** 1628,1634 ****
--- 1786,1794 ----
int size;
{
VOID *ret;
+ #ifndef MSDOS
VOID *malloc();
+ #endif
ret=malloc(size);
if(ret==(VOID *)0)
***************
*** 1643,1649 ****
--- 1803,1811 ----
int size;
{
VOID *ret;
+ #ifndef MSDOS
VOID *realloc();
+ #endif
ret=realloc(ptr,size);
if(ret==(VOID *)0)
***************
*** 1651,1656 ****
--- 1813,1820 ----
return ret;
}
+ #ifndef MSDOS
+
/* Return a malloc()'d copy of a string */
char *
strdup(str)
***************
*** 1682,1688 ****
--- 1846,1857 ----
scan = (char *)s;
uc = (ucharwanted&0xFF);
for (n = size; n > 0; n--)
+ #ifdef __BUG__
+ /* Nope, '==' has higher precedence than '&' ... [tho] */
if ((*scan)&0xFF == uc)
+ #else /* FIXED */
+ if ( ((*scan)&0xFF) == uc)
+ #endif /* FIXED */
return((VOID *)scan);
else
scan++;
***************
*** 1721,1726 ****
--- 1890,1897 ----
return(dst);
}
+
+ #endif /* not MSDOS */
/* Implement a variable sized buffer of 'stuff'. We don't know what it is,
nor do we care, as long as it doesn't mind being aligned by malloc. */