44 Commits

Author SHA1 Message Date
Serge
ba2871aa34 Update commands bc, egrep, expr, iostat, mail, ps, su, vmstat, wall, write. 2022-07-10 22:14:32 -07:00
Serge
edde805980 Update tail, tar, tee, time, touch, tr, tsort, tty, uniq, w, wc, whereis, who. 2022-07-10 20:07:46 -07:00
Serge
db74d0da32 Update pwd, rev, rm, rmail, rmdir, size, sleep, sort, split, sum, sync. 2022-07-10 19:03:28 -07:00
Serge
1253330adc Update kill, last, ln, mesg, mkdir, mv, nice, od, pagesize, pr, printenv. 2022-07-10 18:33:12 -07:00
Serge
26e2d7dd5e Update du, echo, ed, fgrep, file, grep, head, hostid, join. 2022-07-10 17:35:59 -07:00
Serge
9c3b2e0d9a Update basename, cal, cat, cb, chgrp, chmod, cmp, col, comm, cp, dd. 2022-07-10 16:33:56 -07:00
Serge
51da6c0e6e Update pstat, reboot, shutdown, update, vipw, virus. 2022-07-10 15:00:28 -07:00
Serge
dbe1779a29 Update mkfs, mknod, mkpasswd, mount. 2022-07-10 14:19:42 -07:00
Serge
c6f46414ed Update getty. 2022-06-19 20:44:39 -07:00
Serge
552f5ed4c2 Update chroot and fsck. 2022-06-18 22:53:38 -07:00
Serge
2d61fa76c3 Update yacc. 2022-06-18 22:44:41 -07:00
Serge
72d7321b45 Reindent yacc sources. 2022-06-18 22:00:26 -07:00
Serge
82817c9308 Update uucp. 2022-06-18 21:50:44 -07:00
Serge
c849b8f1f8 Update date2 and tip. 2022-06-18 15:10:26 -07:00
Serge
1febcc5f9f Update cron and gtest. 2022-06-18 14:51:24 -07:00
Serge
7b1d52abff Update src/cmd/Makefile. 2022-06-12 22:49:06 -07:00
Serge
2f2d84e6a0 Update stty, sysctl, test, uname, xargs, zmodem. 2022-06-12 21:53:58 -07:00
Serge
6794c38ff4 Update smlrc. 2022-06-12 20:02:11 -07:00
Serge
840cd1db8b Update smallc. 2022-06-12 19:46:53 -07:00
Serge
f6602a8a6d Update cmd/sh. 2022-05-28 00:39:33 -07:00
Serge
97dfd3ae89 Update sed. 2022-05-27 21:54:16 -07:00
Serge
e728e7f25d Update cmd/re and scm. 2022-05-27 21:12:40 -07:00
Serge
146bae8a98 Update cmd/picoc. 2022-05-27 20:39:20 -07:00
Serge
724973121b Update cmd/more. 2022-05-27 19:24:20 -07:00
Serge
cc59786ed6 Update man, md5 and med. 2022-05-27 18:32:55 -07:00
Serge
4c51256273 Update cmd/login. 2022-05-27 18:11:42 -07:00
Serge
27ddb2eef0 Update lex and ls. 2022-05-27 17:47:38 -07:00
Serge
c213981071 Update glcdtest, hostname, id. 2022-05-27 17:22:07 -07:00
Serge
75302a4eec Implement sqrtf() as a wrapper around sqrt(), for simplicity. 2022-05-27 17:14:04 -07:00
Serge
2252835438 Update cmd/find. 2022-05-27 16:08:38 -07:00
Serge
9e2d5993f6 Update diff and emg. 2022-05-27 02:26:28 -07:00
Serge
a47779d9d6 Update cmd/dc. 2022-05-27 01:23:51 -07:00
Serge
bd9f0208d2 Fix chpass. 2022-05-27 00:46:24 -07:00
Serge
4fdec2101b Move libclang into libc.
Catch all warnings.
2022-05-27 00:20:07 -07:00
Serge
9c50b5a97d Update kernel makefiles. 2022-05-26 00:55:10 -07:00
Serge
37d1b00b7c Update awk. 2022-05-26 00:50:08 -07:00
Serge
716151b46f Update awk and libm. 2022-05-26 00:23:40 -07:00
Serge
8458c9e3c4 Fix linking of user programs.
Start fixing awk.
2022-05-25 23:05:45 -07:00
Serge
4e2c809150 Fix linker script.
Skip empty GNU_STACK section in elf2aout utility.
2022-05-25 22:33:30 -07:00
Serge
ef83392732 Add library libclang: low level support routines from
llvm-project/compiler-rt/lib/builtins collection.
2022-05-25 21:36:20 -07:00
Serge
9d5c61e023 adb: declare all global variables as extern, and define them in main.c. 2022-05-25 20:21:33 -07:00
Serge
d5002ad0ac Use LD for linking mips binaries, not CC.
Fix a few incompatibilities in C sources.
2022-05-25 19:23:39 -07:00
Serge
00c4bf1ea1 Modify makefile in lib/startup to pass options to external assembler. 2022-05-25 18:17:29 -07:00
Serge
9f617eb6fe Modify build scripts for clang.
Disable -mips16 flag for now.
Fix a few issues and incompatibilities detected by compiler.
2022-05-25 17:38:22 -07:00
537 changed files with 16556 additions and 12732 deletions

1
.gitignore vendored
View File

@@ -26,3 +26,4 @@
*.img
Makefile.user
TODO

View File

@@ -34,8 +34,9 @@ CONFIG = $(TOPSRC)/tools/configsys/config
all:
$(MAKE) -C tools
$(MAKE) -C src
$(MAKE) -C lib
$(MAKE) -C src install
$(MAKE) -C install
$(MAKE) kernel
$(MAKE) fs

View File

@@ -23,9 +23,13 @@ LDFLAGS =
LIBS =
# Add system include path
ifeq (,$(wildcard /usr/include/i386-linux-gnu))
CFLAGS += -I/usr/include
ifeq (/usr/include/x86_64-linux-gnu,$(wildcard /usr/include/x86_64-linux-gnu))
CFLAGS += -I/usr/include/x86_64-linux-gnu
else
ifeq (/usr/include/i386-linux-gnu,$(wildcard /usr/include/i386-linux-gnu))
CFLAGS += -I/usr/include/i386-linux-gnu
else
CFLAGS += -I/usr/include
endif
endif
CFLAGS += -I$(TOPSRC)/include

View File

@@ -84,17 +84,17 @@ extern WINDOW *stdscr, *curscr;
int __void__;
#define VOID(x) (__void__ = (int) (x))
#else
#define VOID(x) (x)
#define VOID(x) ((void)(x))
#endif
/*
* psuedo functions for standard screen
*/
#define addch(ch) VOID(waddch(stdscr, ch))
#define getch() VOID(wgetch(stdscr))
#define getch() wgetch(stdscr)
#define addstr(str) VOID(waddstr(stdscr, str))
#define getstr(str) VOID(wgetstr(stdscr, str))
#define move(y, x) VOID(wmove(stdscr, y, x))
#define move(y, x) wmove(stdscr, y, x)
#define clear() VOID(wclear(stdscr))
#define erase() VOID(werase(stdscr))
#define clrtobot() VOID(wclrtobot(stdscr))
@@ -111,7 +111,7 @@ int __void__;
/*
* mv functions
*/
#define mvwaddch(win,y,x,ch) VOID(wmove(win,y,x)==ERR?ERR:waddch(win,ch))
#define mvwaddch(win,y,x,ch) (wmove(win,y,x) == ERR ? ERR : waddch(win,ch))
#define mvwgetch(win,y,x) VOID(wmove(win,y,x)==ERR?ERR:wgetch(win))
#define mvwaddstr(win,y,x,str) VOID(wmove(win,y,x)==ERR?ERR:waddstr(win,str))
#define mvwgetstr(win,y,x,str) VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str))

View File

@@ -13,3 +13,5 @@ struct group *getgrgid(gid_t gid);
void setgrent(void);
void endgrent(void);
int setgroups(size_t size, const gid_t *list);
int getgrouplist(char *uname, gid_t agroup, gid_t *groups, int *grpcnt);
int initgroups(char *uname, int agroup);

2
include/inttypes.h Normal file
View File

@@ -0,0 +1,2 @@
#include <stdint.h>
#include <stddef.h>

7
include/regex.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef _REGEX_H
#define _REGEX_H
char *re_comp(const char *regex);
int re_exec(const char *string);
#endif

37
include/stdbool.h Normal file
View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2000 Jeroen Ruigrok van der Werven <asmodai@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __bool_true_false_are_defined
#define __bool_true_false_are_defined 1
#ifndef __cplusplus
#define false 0
#define true 1
#define bool _Bool
#endif /* !__cplusplus */
#endif /* __bool_true_false_are_defined */

View File

@@ -5,9 +5,26 @@
typedef signed char int8_t;
typedef short int int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#define INT8_C(x) x
#define UINT8_C(x) x##U
#define INT16_C(x) x
#define UINT16_C(x) x##U
#define INT32_C(x) x
#define UINT32_C(x) x##U
#define INT64_C(x) x##LL
#define UINT64_C(x) x##ULL
#define INTMAX_C(x) x##LL
#define UINTMAX_C(x) x##ULL
#endif

View File

@@ -65,17 +65,11 @@ typedef unsigned size_t;
_flsbuf((unsigned char)(x), p)))
#endif /* not lint */
#define getchar() getc(stdin)
#define putchar(x) putc(x,stdout)
#define feof(p) (((p)->_flag&_IOEOF)!=0)
#define ferror(p) (((p)->_flag&_IOERR)!=0)
#define fileno(p) ((p)->_file)
#define clearerr(p) ((p)->_flag &= ~(_IOERR|_IOEOF))
FILE *fopen (const char *, const char *);
FILE *fdopen (int, const char *);
FILE *freopen (const char *, const char *, FILE *);
FILE *popen (const char *, const char *);
int pclose(FILE *stream);
FILE *tmpfile (void);
int fclose (FILE *);
long ftell (FILE *);
@@ -83,6 +77,7 @@ int fflush (FILE *);
int fgetc (FILE *);
int ungetc (int, FILE *);
int fputc (int, FILE *);
int putchar (int);
int fputs (const char *, FILE *);
int puts (const char *);
char *fgets (char *, int, FILE *);
@@ -95,6 +90,7 @@ void setbuffer (FILE *, char *, size_t);
void setlinebuf (FILE *);
int setvbuf (FILE *, char *, int, size_t);
int fseek (FILE *, long, int);
int rename(const char *, const char *);
void rewind (FILE *);
int remove (const char *);
int getw(FILE *stream);
@@ -112,6 +108,13 @@ int fscanf (FILE *, const char *, ...);
int scanf (const char *, ...);
int sscanf (const char *, const char *, ...);
#define getchar() getc(stdin)
#define putchar(x) putc(x,stdout)
#define feof(p) (((p)->_flag&_IOEOF)!=0)
#define ferror(p) (((p)->_flag&_IOERR)!=0)
#define fileno(p) ((p)->_file)
#define clearerr(p) ((p)->_flag &= ~(_IOERR|_IOEOF))
#ifndef _VA_LIST_
# ifdef __GNUC__
# define va_list __builtin_va_list /* For Gnu C */

View File

@@ -37,7 +37,7 @@ typedef unsigned size_t;
int bcmp(const void *, const void *, size_t);
void bcopy(const void *, void *, size_t);
void bzero(void *, unsigned long);
void bzero(void *, unsigned int);
int ffs(int);
char *index(const char *, int);
char *rindex(const char *, int);

View File

@@ -6,6 +6,6 @@ extern int tgetnum(char *);
extern int tgetflag(char *);
extern char *tgetstr(char *, char **);
extern char *tgoto(char *, int, int);
extern int tputs(register char *, int, int (*)());
extern int tputs(register char *, int, int (*)(int));
#endif

View File

@@ -61,10 +61,12 @@ void _exit (int);
int access();
unsigned int alarm();
pid_t fork();
pid_t setsid(void);
gid_t getegid();
uid_t geteuid();
gid_t getgid();
char *getlogin();
int setlogin(const char *name);
pid_t getpgrp();
pid_t getpid();
pid_t getppid();
@@ -91,7 +93,7 @@ char *re_comp();
void *sbrk(int incr);
int sethostid();
void setusershell();
void sync();
void sync(void);
unsigned int ualarm();
void usleep();
int pause(void);
@@ -105,6 +107,7 @@ int unlink (const char *pathname);
int link(const char *oldpath, const char *newpath);
ssize_t readlink(const char *path, char *buf, size_t bufsiz);
int chown(const char *path, uid_t owner, gid_t group);
int fchown(int fd, uid_t owner, gid_t group);
int nice(int inc);
int setuid(uid_t uid);
int setgid(gid_t gid);
@@ -112,6 +115,7 @@ int seteuid (uid_t euid);
int setegid(gid_t egid);
int setreuid(uid_t ruid, uid_t euid);
int setregid(gid_t rgid, gid_t egid);
int setpgrp(void);
int isatty(int fd);
int chdir(const char *path);
int fchdir(int fd);
@@ -142,6 +146,18 @@ int getopt (int argc, char * const argv[], const char *optstring);
extern char *optarg; /* getopt(3) external variables */
extern int opterr, optind, optopt;
int gethostname(char *name, int namelen);
int sethostname(char *name, int namelen);
int chroot(const char *path);
int fsync(int fd);
int getpagesize(void);
int symlink(const char *target, const char *linkpath);
int vhangup(void);
int mknod(const char *, mode_t, dev_t);
int reboot(int howto);
int ttyslot(void);
#ifndef _VA_LIST_
# ifdef __GNUC__
# define va_list __builtin_va_list /* For Gnu C */

View File

@@ -25,3 +25,5 @@ struct utmp {
char ut_host[UT_HOSTSIZE];
long ut_time;
};
void login(struct utmp *ut);

View File

@@ -48,8 +48,8 @@ struct vseg { /* structure of a segment in memory */
/* masks for s_flags */
#define S_DIRTY 01 /* segment has been modified */
long nswaps; /* number of swaps */
long nmapsegs; /* number of mapseg calls */
extern long nswaps; /* number of swaps */
extern long nmapsegs; /* number of mapseg calls */
int vminit(), vmopen();
struct vseg *vmmapseg();

View File

@@ -9,7 +9,7 @@ TOPSRC = $(shell cd ../..; pwd)
include $(TOPSRC)/target.mk
vpath %.c $(TOPSRC)/src/startup-mips
CFLAGS = -Os -B$(TOPSRC)/lib/ -Wa,-x $(DEFS)
CFLAGS = -Os -B$(TOPSRC)/lib/ -fno-integrated-as -Xassembler -x $(DEFS)
OBJS = ../crt0.o

View File

@@ -24,7 +24,7 @@ SUBDIR += chown chroot disktool fsck getty init \
mkfs mknod mkpasswd mount pstat \
reboot shutdown umount update vipw virus
# TODO: ccom lex m4 yacc reloc sre pforth
# TODO: ccom lex m4 reloc sre pforth
# Shell scripts that need only be installed and are never removed.
#
@@ -73,7 +73,8 @@ FRC:
# $(STD) $(SETUID) $(KMEM) $(OPERATOR) $(TTY) strip
%: %.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@.elf $< $(LIBS)
$(CC) $(CFLAGS) -c $<
$(LD) $(LDFLAGS) -o $@.elf $@.o $(LIBS)
$(OBJDUMP) -S $@.elf > $@.dis
$(SIZE) $@.elf
$(ELF2AOUT) $@.elf $@ && /bin/rm $@.elf

View File

@@ -12,7 +12,7 @@ CFLAGS += -DNUM_SYMS_CACHE=50 -Wall -Werror
all: adb
adb: $(OBJS)
${CC} ${LDFLAGS} -o adb.elf $(OBJS) ${LIBS}
${LD} ${LDFLAGS} -o adb.elf $(OBJS) ${LIBS}
${OBJDUMP} -S adb.elf > adb.dis
${SIZE} adb.elf
${ELF2AOUT} adb.elf $@ && rm adb.elf

View File

@@ -152,68 +152,68 @@ typedef struct reglist REGLIST;
#define leng(a) ((long)((unsigned)(a)))
#define shorten(a) ((long)a)
struct sgttyb adbtty, usrtty;
jmp_buf erradb;
sig_t sigint, sigqit;
extern struct sgttyb adbtty, usrtty;
extern jmp_buf erradb;
extern sig_t sigint, sigqit;
MAP txtmap;
MAP datmap;
extern MAP txtmap;
extern MAP datmap;
BKPTR bkpthead; /* breakpoints */
extern BKPTR bkpthead; /* breakpoints */
struct SYMbol *symbol;
extern struct SYMbol *symbol;
extern u_int *uframe;
const char *errflg;
char *lp;
char *myname; /* program name */
char *printptr;
extern const char *errflg;
extern char *lp;
extern char *myname; /* program name */
extern char *printptr;
extern char *Ipath;
extern char *symfil;
extern char *corfil;
char printbuf[MAXLIN];
int wtflag;
int pid;
int executing;
int fcor;
int fsym;
int mkfault;
int dotinc;
int adrflg;
int cntflg;
int lastframe;
int kernel;
int callpc;
int octal;
int localok;
int maxoff;
int maxpos;
int eof;
int infile;
int argcount;
int magic;
int signo;
extern char printbuf[MAXLIN];
extern int wtflag;
extern int pid;
extern int executing;
extern int fcor;
extern int fsym;
extern int mkfault;
extern int dotinc;
extern int adrflg;
extern int cntflg;
extern int lastframe;
extern int kernel;
extern int callpc;
extern int octal;
extern int localok;
extern int maxoff;
extern int maxpos;
extern int eof;
extern int infile;
extern int argcount;
extern int magic;
extern int signo;
extern int lastc;
extern int lastcom;
extern int outfile;
long dot;
long ditto;
long expv;
long adrval;
long cntval;
long localval;
long maxfile;
long txtsiz;
long datsiz;
long datbas;
long stksiz;
long entrypt;
long loopcnt;
extern long dot;
extern long ditto;
extern long expv;
extern long adrval;
extern long cntval;
extern long localval;
extern long maxfile;
extern long txtsiz;
extern long datsiz;
extern long datbas;
extern long stksiz;
extern long entrypt;
extern long loopcnt;
long var[36];
u_int corhdr [USIZE/sizeof(u_int)];
extern long var[36];
extern u_int corhdr [USIZE/sizeof(u_int)];
off_t symoff;
extern off_t symoff;
extern const REGLIST reglist [];

View File

@@ -5,6 +5,55 @@ char *Ipath = "/share/adb";
static int exitflg;
struct sgttyb adbtty, usrtty;
jmp_buf erradb;
sig_t sigint, sigqit;
MAP txtmap;
MAP datmap;
BKPTR bkpthead; /* breakpoints */
struct SYMbol *symbol;
const char *errflg;
char *lp;
char *myname; /* program name */
char printbuf[MAXLIN];
int wtflag;
int pid;
int executing;
int fcor;
int fsym;
int mkfault;
int dotinc;
int adrflg;
int cntflg;
int lastframe;
int kernel;
int callpc;
int octal;
int localok;
int maxoff;
int maxpos;
int eof;
int infile;
int argcount;
int magic;
int signo;
long dot;
long ditto;
long expv;
long adrval;
long cntval;
long localval;
long maxfile;
long txtsiz;
long datsiz;
long datbas;
long stksiz;
long entrypt;
long loopcnt;
long var[36];
u_int corhdr [USIZE/sizeof(u_int)];
off_t symoff;
long
roundn(a, b)
long a, b;

View File

@@ -14,7 +14,7 @@ SRCS = adc-demo.c
all: adc-demo
adc-demo: ${OBJS}
${CC} ${LDFLAGS} -o adc-demo.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o adc-demo.elf ${OBJS} ${LIBS}
${OBJDUMP} -S adc-demo.elf > adc-demo.dis
${SIZE} adc-demo.elf
${ELF2AOUT} adc-demo.elf $@

View File

@@ -13,7 +13,7 @@ AOUTOBJS = aout.o mips-dis.o
all: aout
aout: $(AOUTOBJS)
${CC} ${LDFLAGS} -o aout.elf $(AOUTOBJS) ${LIBS}
${LD} ${LDFLAGS} -o aout.elf $(AOUTOBJS) ${LIBS}
${OBJDUMP} -S aout.elf > aout.dis
${SIZE} aout.elf
${ELF2AOUT} aout.elf $@ && rm aout.elf

View File

@@ -14,7 +14,7 @@ MANSRC = ar.1 ar.5
all: ar $(MAN)
ar: ${OBJS}
${CC} ${LDFLAGS} -o ar.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o ar.elf ${OBJS} ${LIBS}
${OBJDUMP} -S ar.elf > ar.dis
${SIZE} ar.elf
${ELF2AOUT} ar.elf $@ && rm ar.elf

View File

@@ -11,7 +11,7 @@ LDFLAGS +=
all: as
as: as.o
${CC} ${LDFLAGS} -o as.elf as.o ${LIBS}
${LD} ${LDFLAGS} -o as.elf as.o ${LIBS}
${OBJDUMP} -S as.elf > as.dis
${SIZE} as.elf
${ELF2AOUT} as.elf $@ && rm as.elf

View File

@@ -11,7 +11,7 @@ SOURCE = awk.def.h awk.g.y awk.lx.l b.c lib.c main.c parse.c \
proc.c freeze.c run.c tran.c
awk: $(FILES) awk.g.o
${CC} ${LDFLAGS} -o awk.elf $(FILES) awk.g.o ${LIBS}
${LD} ${LDFLAGS} -o awk.elf $(FILES) awk.g.o ${LIBS}
${OBJDUMP} -S awk.elf > awk.dis
${SIZE} awk.elf
${ELF2AOUT} awk.elf $@ && rm awk.elf

View File

@@ -68,7 +68,7 @@ typedef struct {
cell *optr;
} obj;
#define BOTCH 1
#define BOTCH 0
struct nd {
char ntype;
char subtype;
@@ -127,9 +127,23 @@ extern int pairstack[], paircnt;
#define istemp(n) (n.otype == OCELL && n.osub == CTEMP)
#define isfld(n) (!donefld && n.osub==CFLD && n.otype==OCELL && n.optr->nval==EMPTY)
#define isrec(n) (donefld && n.osub==CFLD && n.otype==OCELL && n.optr->nval!=EMPTY)
obj nullproc();
obj relop();
obj nullproc(void);
obj relop(node **a, int n);
#define MAXSYM 50
#define HAT 0177 /* matches ^ in regular expr */
/* watch out for mach dep */
struct fa;
void yyerror(char *s);
void error(int f, char *s, ...);
void syminit(void);
int freeze(char *s);
int thaw(char *s);
void run(void);
void recbld(void);
int isnumber(char *s);
int getrec(void);
int member(char c, char *s);
void fldbld(void);
void freesymtab(cell *ap);
int match(struct fa *pfa, char *p);

View File

@@ -1,4 +1,8 @@
/* awk.g.y 4.1 82/05/07 */
%code requires {
#define YYSTYPE node *
#define YYSTYPE_IS_DECLARED 1
}
%token FIRSTTOKEN /*must be first*/
%token FINAL FATAL
@@ -37,6 +41,22 @@
#ifndef DEBUG
# define PUTS(x)
#endif
int yylex(void);
node *valtonode(cell *a, int b);
node *stat1(int a, node *b);
node *stat2(int a, node *b, node *c);
node *stat3(int a, node *b, node *c, node *d);
node *stat4(int a, node *b, node *c, node *d, node *e);
node *op1(int a, node *b);
node *op2(int a, node *b, node *c);
node *op3(int a, node *b, node *c, node *d);
node *genprint(void);
node *pa2stat(node *a, node *b, node *c);
node *linkum(node *a, node *b);
struct fa *makedfa(node *p);
char *cclenter(char *p);
node *exptostat(node *a);
void startreg(void);
%}
%%
@@ -48,13 +68,13 @@ program:
begin:
XBEGIN '{' stat_list '}' { PUTS("XBEGIN list"); $$ = $3; }
| begin NL
| { PUTS("empty XBEGIN"); $$ = (hack)nullstat; }
| { PUTS("empty XBEGIN"); $$ = nullstat; }
;
end:
XEND '{' stat_list '}' { PUTS("XEND list"); $$ = $3; }
| end NL
| { PUTS("empty END"); $$ = (hack)nullstat; }
| { PUTS("empty END"); $$ = nullstat; }
;
compound_conditional:
@@ -83,7 +103,7 @@ else:
;
field:
FIELD { PUTS("field"); $$ = valtonode($1, CFLD); }
FIELD { PUTS("field"); $$ = valtonode((cell *) $1, CFLD); }
| INDIRECT term { PUTS("ind field"); $$ = op1(INDIRECT, $2); }
;
@@ -92,14 +112,14 @@ if:
;
lex_expr:
expr MATCHOP regular_expr { PUTS("expr~re"); $$ = op2($2, $1, makedfa($3)); }
expr MATCHOP regular_expr { PUTS("expr~re"); $$ = op2((int) $2, $1, (node *) makedfa($3)); }
| '(' lex_expr ')' { PUTS("(lex_expr)"); $$ = $2; }
;
var:
NUMBER {PUTS("number"); $$ = valtonode($1, CCON); }
| STRING { PUTS("string"); $$ = valtonode($1, CCON); }
| VAR { PUTS("var"); $$ = valtonode($1, CVAR); }
NUMBER {PUTS("number"); $$ = valtonode((cell *) $1, CCON); }
| STRING { PUTS("string"); $$ = valtonode((cell *) $1, CCON); }
| VAR { PUTS("var"); $$ = valtonode((cell *) $1, CVAR); }
| VAR '[' expr ']' { PUTS("array[]"); $$ = op2(ARRAY, $1, $3); }
| field
;
@@ -113,7 +133,7 @@ term:
$$ = op2(FNCN, $1, valtonode(lookup("$record", symtab, 0), CFLD));
}
| FNCN '(' expr ')' { PUTS("func(expr)"); $$ = op2(FNCN, $1, $3); }
| SPRINTF print_list { PUTS("sprintf"); $$ = op1($1, $2); }
| SPRINTF print_list { PUTS("sprintf"); $$ = op1((int) $1, $2); }
| SUBSTR '(' expr ',' expr ',' expr ')'
{ PUTS("substr(e,e,e)"); $$ = op3(SUBSTR, $3, $5, $7); }
| SUBSTR '(' expr ',' expr ')'
@@ -141,7 +161,7 @@ term:
expr:
term { PUTS("term"); }
| expr term { PUTS("expr term"); $$ = op2(CAT, $1, $2); }
| var ASGNOP expr { PUTS("var=expr"); $$ = stat2($2, $1, $3); }
| var ASGNOP expr { PUTS("var=expr"); $$ = stat2((int) $2, $1, $3); }
;
optNL:
@@ -160,13 +180,13 @@ pa_stat:
pa_stats:
pa_stats pa_stat st { PUTS("pa_stats pa_stat"); $$ = linkum($1, $2); }
| { PUTS("null pa_stat"); $$ = (hack)nullstat; }
| { PUTS("null pa_stat"); $$ = nullstat; }
| pa_stats pa_stat {PUTS("pa_stats pa_stat"); $$ = linkum($1, $2); }
;
pattern:
regular_expr { PUTS("regex");
$$ = op2(MATCH, valtonode(lookup("$record", symtab, 0), CFLD), makedfa($1));
$$ = op2(MATCH, valtonode(lookup("$record", symtab, 0), CFLD), (node *) makedfa($1));
}
| rel_expr { PUTS("relexpr"); }
| lex_expr { PUTS("lexexpr"); }
@@ -199,9 +219,9 @@ regular_expr:
r:
CHAR { PUTS("regex CHAR"); $$ = op2(CHAR, (node *) 0, $1); }
| DOT { PUTS("regex DOT"); $$ = op2(DOT, (node *) 0, (node *) 0); }
| CCL { PUTS("regex CCL"); $$ = op2(CCL, (node *) 0, cclenter($1)); }
| NCCL { PUTS("regex NCCL"); $$ = op2(NCCL, (node *) 0, cclenter($1)); }
| '^' { PUTS("regex ^"); $$ = op2(CHAR, (node *) 0, HAT); }
| CCL { PUTS("regex CCL"); $$ = op2(CCL, (node *) 0, (node *) cclenter((char*)$1)); }
| NCCL { PUTS("regex NCCL"); $$ = op2(NCCL, (node *) 0, (node *) cclenter((char*)$1)); }
| '^' { PUTS("regex ^"); $$ = op2(CHAR, (node *) 0, (node *) HAT); }
| '$' { PUTS("regex $"); $$ = op2(CHAR, (node *) 0, (node *) 0); }
| r OR r { PUTS("regex OR"); $$ = op2(OR, $1, $3); }
| r r %prec CAT
@@ -214,7 +234,7 @@ r:
rel_expr:
expr RELOP expr
{ PUTS("expr relop expr"); $$ = op2($2, $1, $3); }
{ PUTS("expr relop expr"); $$ = op2((int) $2, $1, $3); }
| '(' rel_expr ')'
{ PUTS("(relexpr)"); $$ = $2; }
;
@@ -226,15 +246,15 @@ st:
simple_stat:
PRINT print_list redir expr
{ PUTS("print>stat"); $$ = stat3($1, $2, $3, $4); }
{ PUTS("print>stat"); $$ = stat3((int) $1, $2, $3, $4); }
| PRINT print_list
{ PUTS("print list"); $$ = stat3($1, $2, nullstat, nullstat); }
{ PUTS("print list"); $$ = stat3((int) $1, $2, nullstat, nullstat); }
| PRINTF print_list redir expr
{ PUTS("printf>stat"); $$ = stat3($1, $2, $3, $4); }
{ PUTS("printf>stat"); $$ = stat3((int) $1, $2, $3, $4); }
| PRINTF print_list
{ PUTS("printf list"); $$ = stat3($1, $2, nullstat, nullstat); }
{ PUTS("printf list"); $$ = stat3((int) $1, $2, nullstat, nullstat); }
| expr { PUTS("expr"); $$ = exptostat($1); }
| { PUTS("null simple statement"); $$ = (hack)nullstat; }
| { PUTS("null simple statement"); $$ = nullstat; }
| error { yyclearin; yyerror("illegal statement"); }
;
@@ -255,7 +275,7 @@ statement:
stat_list:
stat_list statement { PUTS("stat_list stat"); $$ = linkum($1, $2); }
| { PUTS("null stat list"); $$ = (hack)nullstat; }
| { PUTS("null stat list"); $$ = nullstat; }
;
while:

View File

@@ -3,17 +3,18 @@
%Start A str chc sc reg comment
%{
#include "awk.h"
#include "awk.def.h"
#include "awk.h"
#define YY_NO_INPUT /* defeat lex */
extern int yylval;
extern int mustfld;
int lineno = 1;
#define CADD cbuf[clen++]=yytext[0]; if(clen>=CBUFLEN-1) {yyerror("string too long", cbuf); BEGIN A;}
#define CADD cbuf[clen++]=yytext[0]; if(clen>=CBUFLEN-1) {yyerror("string too long"); BEGIN A;}
#define CBUFLEN 150
char cbuf[CBUFLEN];
int clen, cflag;
cell *fieldadr(int n);
%}
A [a-zA-Z_]
@@ -42,36 +43,36 @@ WS [ \t]
<A>PROGEND return(EOF);
<A>"&&" return(AND);
<A>"!" return(NOT);
<A>"!=" { yylval = NE; return(RELOP); }
<A>"~" { yylval = MATCH; return(MATCHOP); }
<A>"!~" { yylval = NOTMATCH; return(MATCHOP); }
<A>"<" { yylval = LT; return(RELOP); }
<A>"<=" { yylval = LE; return(RELOP); }
<A>"==" { yylval = EQ; return(RELOP); }
<A>">=" { yylval = GE; return(RELOP); }
<A>">" { yylval = GT; return(RELOP); }
<A>">>" { yylval = APPEND; return(RELOP); }
<A>"++" { yylval = INCR; return(INCR); }
<A>"--" { yylval = DECR; return(DECR); }
<A>"+=" { yylval = ADDEQ; return(ASGNOP); }
<A>"-=" { yylval = SUBEQ; return(ASGNOP); }
<A>"*=" { yylval = MULTEQ; return(ASGNOP); }
<A>"/=" { yylval = DIVEQ; return(ASGNOP); }
<A>"%=" { yylval = MODEQ; return(ASGNOP); }
<A>"=" { yylval = ASSIGN; return(ASGNOP); }
<A>"!=" { yylval = (node *) NE; return(RELOP); }
<A>"~" { yylval = (node *) MATCH; return(MATCHOP); }
<A>"!~" { yylval = (node *) NOTMATCH; return(MATCHOP); }
<A>"<" { yylval = (node *) LT; return(RELOP); }
<A>"<=" { yylval = (node *) LE; return(RELOP); }
<A>"==" { yylval = (node *) EQ; return(RELOP); }
<A>">=" { yylval = (node *) GE; return(RELOP); }
<A>">" { yylval = (node *) GT; return(RELOP); }
<A>">>" { yylval = (node *) APPEND; return(RELOP); }
<A>"++" { yylval = (node *) INCR; return(INCR); }
<A>"--" { yylval = (node *) DECR; return(DECR); }
<A>"+=" { yylval = (node *) ADDEQ; return(ASGNOP); }
<A>"-=" { yylval = (node *) SUBEQ; return(ASGNOP); }
<A>"*=" { yylval = (node *) MULTEQ; return(ASGNOP); }
<A>"/=" { yylval = (node *) DIVEQ; return(ASGNOP); }
<A>"%=" { yylval = (node *) MODEQ; return(ASGNOP); }
<A>"=" { yylval = (node *) ASSIGN; return(ASGNOP); }
<A>"$"{D}+ { if (atoi(yytext+1)==0) {
yylval = (hack)lookup("$record", symtab, 0);
yylval = (node *) lookup("$record", symtab, 0);
return(STRING);
} else {
yylval = fieldadr(atoi(yytext+1));
yylval = (node *) fieldadr(atoi(yytext+1));
return(FIELD);
}
}
<A>"$"{WS}* { return(INDIRECT); }
<A>NF { mustfld=1; yylval = (hack)setsymtab(yytext, EMPTY, 0.0, NUM, symtab); return(VAR); }
<A>NF { mustfld=1; yylval = (node *) setsymtab(yytext, EMPTY, 0.0, NUM, symtab); return(VAR); }
<A>({D}+("."?){D}*|"."{D}+)((e|E)("+"|-)?{D}+)? {
yylval = (hack)setsymtab(yytext, EMPTY, atof(yytext), CON|NUM, symtab); return(NUMBER); }
yylval = (node *) setsymtab(yytext, EMPTY, atof(yytext), CON|NUM, symtab); return(NUMBER); }
<A>"}"{WS}*\n { BEGIN sc; lineno++; return(';'); }
<A>"}" { BEGIN sc; return(';'); }
<A>;\n { lineno++; return(';'); }
@@ -84,27 +85,27 @@ WS [ \t]
<A>exit return(EXIT);
<A>break return(BREAK);
<A>continue return(CONTINUE);
<A>print { yylval = PRINT; return(PRINT); }
<A>printf { yylval = PRINTF; return(PRINTF); }
<A>sprintf { yylval = SPRINTF; return(SPRINTF); }
<A>split { yylval = SPLIT; return(SPLIT); }
<A>print { yylval = (node *) PRINT; return(PRINT); }
<A>printf { yylval = (node *) PRINTF; return(PRINTF); }
<A>sprintf { yylval = (node *) SPRINTF; return(SPRINTF); }
<A>split { yylval = (node *) SPLIT; return(SPLIT); }
<A>substr return(SUBSTR);
<A>index return(INDEX);
<A>in return(IN);
<A>getline return(GETLINE);
<A>length { yylval = FLENGTH; return(FNCN); }
<A>log { yylval = FLOG; return(FNCN); }
<A>int { yylval = FINT; return(FNCN); }
<A>exp { yylval = FEXP; return(FNCN); }
<A>sqrt { yylval = FSQRT; return(FNCN); }
<A>{A}{B}* { yylval = (hack)setsymtab(yytext, tostring(""), 0.0, STR|NUM, symtab); return(VAR); }
<A>length { yylval = (node *) FLENGTH; return(FNCN); }
<A>log { yylval = (node *) FLOG; return(FNCN); }
<A>int { yylval = (node *) FINT; return(FNCN); }
<A>exp { yylval = (node *) FEXP; return(FNCN); }
<A>sqrt { yylval = (node *) FSQRT; return(FNCN); }
<A>{A}{B}* { yylval = (node *) setsymtab(yytext, tostring(""), 0.0, STR|NUM, symtab); return(VAR); }
<A>\" { BEGIN str; clen=0; }
<A># { BEGIN comment; }
<comment>\n { BEGIN A; lineno++; return(NL); }
<comment>. ;
<A>. { yylval = yytext[0]; return(yytext[0]); }
<A>. { yylval = (node *) (int) yytext[0]; return(yytext[0]); }
<reg>"[" { BEGIN chc; clen=0; cflag=0; }
<reg>"[^" { BEGIN chc; clen=0; cflag=1; }
@@ -118,19 +119,19 @@ WS [ \t]
<reg>")" return(')');
<reg>"^" return('^');
<reg>"$" return('$');
<reg>\\{D}{D}{D} { sscanf(yytext+1, "%o", &yylval); return(CHAR); }
<reg>\\. { if (yytext[1]=='n') yylval = '\n';
else if (yytext[1] == 't') yylval = '\t';
else yylval = yytext[1];
<reg>\\{D}{D}{D} { sscanf(yytext+1, "%o", (int *) &yylval); return(CHAR); }
<reg>\\. { if (yytext[1]=='n') yylval = (node *) '\n';
else if (yytext[1] == 't') yylval = (node *) '\t';
else yylval = (node *) (int) yytext[1];
return(CHAR);
}
<reg>"/" { BEGIN A; unput('/'); }
<reg>\n { yyerror("newline in regular expression"); lineno++; BEGIN A; }
<reg>. { yylval = yytext[0]; return(CHAR); }
<reg>. { yylval = (node *) (int) yytext[0]; return(CHAR); }
<str>\" { char *s; BEGIN A; cbuf[clen]=0; s = tostring(cbuf);
cbuf[clen] = ' '; cbuf[++clen] = 0;
yylval = (hack)setsymtab(cbuf, s, 0.0, CON|STR, symtab); return(STRING); }
yylval = (node *) setsymtab(cbuf, s, 0.0, CON|STR, symtab); return(STRING); }
<str>\n { yyerror("newline in string"); lineno++; BEGIN A; }
<str>"\\\"" { cbuf[clen++]='"'; }
<str,chc>"\\"n { cbuf[clen++]='\n'; }
@@ -139,7 +140,7 @@ WS [ \t]
<str>. { CADD; }
<chc>"\\""]" { cbuf[clen++]=']'; }
<chc>"]" { BEGIN reg; cbuf[clen]=0; yylval = (hack)tostring(cbuf);
<chc>"]" { BEGIN reg; cbuf[clen]=0; yylval = (node *) tostring(cbuf);
if (cflag==0) { return(CCL); }
else { return(NCCL); } }
<chc>\n { yyerror("newline in character class"); lineno++; BEGIN A; }
@@ -147,9 +148,10 @@ WS [ \t]
%%
int
input()
{
register c;
int c;
extern char *lexprog;
if (yyin == NULL)
@@ -163,6 +165,7 @@ input()
return(c);
}
void
startreg()
{
BEGIN reg;

View File

@@ -38,6 +38,12 @@ node *point[MAXLIN];
int setcnt;
int line;
void follow(node *v);
int notin(int **array, int n, int *prev);
void cfoll(node *v);
void overflo(void);
void freetr(node *p);
void penter(node *p);
struct fa *makedfa(p) /* returns dfa for tree pointed to by p */
node *p;
@@ -58,6 +64,7 @@ node *p;
return(fap);
}
void
penter(p) /* set up parent pointers and leaf indices */
node *p;
{
@@ -83,6 +90,7 @@ node *p;
}
}
void
freetr(p) /* free parse tree and follow sets */
node *p;
{
@@ -109,7 +117,7 @@ node *p;
char *cclenter(p)
register char *p;
{
register i, c;
int i, c;
char *op;
op = p;
@@ -137,15 +145,17 @@ register char *p;
return(tostring(chars));
}
void
overflo()
{
error(FATAL, "regular expression too long\n");
}
void
cfoll(v) /* enter follow set of each leaf of vertex v into foll[leaf] */
register node *v;
{
register i;
int i;
int prev;
int *add();
@@ -174,10 +184,11 @@ register node *v;
}
}
int
first(p) /* collects initially active leaves of p into setvec */
register node *p; /* returns 0 or 1 depending on whether p matches empty string */
{
register b;
int b;
switch(type(p)) {
LEAF
@@ -208,6 +219,7 @@ register node *p; /* returns 0 or 1 depending on whether p matches empty string
return(-1);
}
void
follow(v)
node *v; /* collects leaves that can follow v into setvec */
{
@@ -243,8 +255,8 @@ node *v; /* collects leaves that can follow v into setvec */
}
}
member(c, s) /* is c in s? */
register char c, *s;
int
member(char c, char *s) /* is c in s? */
{
while (*s)
if (c == *s++)
@@ -252,10 +264,11 @@ register char c, *s;
return(0);
}
int
notin(array, n, prev) /* is setvec in array[0] thru array[n]? */
int **array;
int *prev; {
register i, j;
int i, j;
int *ptr;
for (i=0; i<=n; i++) {
ptr = array[i];
@@ -272,7 +285,7 @@ int *prev; {
int *add(n) { /* remember setvec */
int *ptr, *p;
register i;
int i;
if ((p = ptr = (int *) malloc((n+1)*sizeof(int))) == NULL)
overflo();
*ptr = n;
@@ -288,8 +301,8 @@ int *add(n) { /* remember setvec */
struct fa *cgotofn()
{
register i, k;
register int *ptr;
int i, k;
int *ptr;
char c;
char *p;
node *cp;
@@ -505,11 +518,12 @@ struct fa *cgotofn()
return(where[0]);
}
int
match(pfa, p)
register struct fa *pfa;
register char *p;
{
register count;
int count;
char c;
if (p == 0) return(0);
if (pfa->cch == 1) { /* fast test for first character, if possible */

View File

@@ -1,12 +1,15 @@
#include "stdio.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int
freeze(s)
char *s;
{
int fd;
unsigned int *len;
size_t len;
len = (unsigned int *)sbrk(0);
len = (size_t) sbrk(0);
if((fd = creat(s, 0666)) < 0) {
perror(s);
return(1);
@@ -17,6 +20,7 @@ freeze(s)
return(0);
}
int
thaw(s)
char *s;
{

View File

@@ -30,6 +30,8 @@ cell fldtab[MAXFLD] = { /*room for fields */
};
int maxfld = 0; /* last used field */
void setclvar(char *s);
void
error(int f, char *s, ...)
{
@@ -46,12 +48,13 @@ error(int f, char *s, ...)
exit(2);
}
int
getrec()
{
register char *rr;
extern int svargc;
extern char **svargv;
register c, sep;
int c, sep;
dprintf("**RS=%o, **FS=%o\n", **RS, **FS, NULL);
donefld = 0;
@@ -108,6 +111,7 @@ getrec()
return(0); /* true end of file */
}
void
setclvar(s) /* set var=value from s */
char *s;
{
@@ -122,6 +126,7 @@ char *s;
dprintf("command line set %s to |%s|\n", s, p, NULL);
}
void
fldbld()
{
register char *r, *fr, sep;
@@ -183,6 +188,7 @@ fldbld()
printf("field %d: |%s|\n", i, fldtab[i].sval);
}
void
recbld()
{
int i;
@@ -193,7 +199,7 @@ recbld()
r = record;
for (i = 1; i <= *NF; i++) {
p = getsval(&fldtab[i]);
while (*r++ = *p++)
while ((*r++ = *p++))
;
*(r-1) = **OFS;
}
@@ -215,6 +221,7 @@ cell *fieldadr(n)
int errorflag = 0;
void
yyerror(s)
char *s;
{
@@ -222,6 +229,7 @@ yyerror(s)
errorflag = 2;
}
void
PUTS(s)
char *s;
{
@@ -230,10 +238,11 @@ PUTS(s)
#define MAXEXPON 38 /* maximum exponenet for fp number */
int
isnumber(s)
register char *s;
{
register d1, d2;
int d1, d2;
int point;
char *es;

View File

@@ -1,6 +1,7 @@
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "awk.def.h"
#include "awk.h"
@@ -13,12 +14,12 @@ int svargc;
char **svargv, **xargv;
extern FILE *yyin; /* lex input file */
char *lexprog; /* points to program argument if it exists */
extern errorflag; /* non-zero if any syntax errors; set by yyerror */
int filefd, symnum, ansfd;
char *filelist;
extern int maxsym, errno;
extern int maxsym;
int
main(argc, argv)
int argc;
char *argv[];
@@ -29,9 +30,9 @@ main(argc, argv)
while (argc > 1) {
argc--;
argv++;
/* this nonsense is because gcos argument handling */
/* folds -F into -f. accordingly, one checks the next
/* character after f to see if it's -f file or -Fx.
/* this nonsense is because gcos argument handling
* folds -F into -f. accordingly, one checks the next
* character after f to see if it's -f file or -Fx.
*/
if (argv[0][0] == '-' && TOLOWER(argv[0][1]) == 'f' && argv[0][2] == '\0') {
yyin = fopen(argv[1], "r");
@@ -92,6 +93,7 @@ main(argc, argv)
exit(errorflag);
}
int
yywrap()
{
return(1);

View File

@@ -119,7 +119,7 @@ node *stat4(a,b,c,d,e) node *b, *c, *d, *e;
node *valtonode(a, b) cell *a;
{
register node *x;
x = node0(a);
x = node0((int) a);
x->ntype = NVALUE;
x->subtype = b;
return(x);

View File

@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "awk.def.h"
#include "awk.h"
struct tok
@@ -29,7 +30,7 @@ struct xx
{ INDIRECT, "indirect", "$("},
{ SUBSTR, "substr", "substr"},
{ INDEX, "sindex", "sindex"},
{ SPRINTF, "asprintf", "sprintf "},
{ SPRINTF, "awksprintf", "sprintf "},
{ ADD, "arith", " + "},
{ MINUS, "arith", " - "},
{ MULT, "arith", " * "},

View File

@@ -31,6 +31,10 @@ static cell nullval = { EMPTY, EMPTY, 0.0, NUM, 0 };
obj true = { OBOOL, BTRUE, 0 };
obj false = { OBOOL, BFALSE, 0 };
void redirprint(char *s, int a, node *b);
void tempfree(obj a);
void
run()
{
register int i;
@@ -40,7 +44,7 @@ run()
/* Wait for children to complete if output to a pipe. */
for (i=0; i<FILENUM; i++)
if (files[i].fp && files[i].type == '|')
pclose(files[i].fp);
fclose(files[i].fp);
}
obj execute(u) node *u;
@@ -152,7 +156,7 @@ obj matchop(a,n) node **a;
if (isstr(x)) s = x.optr->sval;
else s = getsval(x.optr);
tempfree(x);
i = match(a[1], s);
i = match((struct fa*) a[1], s);
if (n==MATCH && i==1 || n==NOTMATCH && i==0)
return(true);
else
@@ -224,6 +228,7 @@ obj relop(a,n) node **a;
}
}
void
tempfree(a) obj a;
{
if (!istemp(a)) return;
@@ -397,7 +402,7 @@ char *format(s,a) char *s; node *a;
return(buf);
}
obj asprintf(a,n) node **a;
obj awksprintf(a,n) node **a;
{
obj x;
node *y;
@@ -592,7 +597,7 @@ obj aprintf(a,n) node **a;
{
obj x;
x = asprintf(a,n);
x = awksprintf(a,n);
if (a[1]==NULL) {
printf("%s", x.optr->sval);
tempfree(x);
@@ -840,7 +845,11 @@ obj print(a,n) node **a;
return(false);
}
obj nullproc() {}
obj nullproc()
{
static const obj zero;
return zero;
}
obj nodetoobj(a) node *a;
{
@@ -853,6 +862,7 @@ obj nodetoobj(a) node *a;
return(x);
}
void
redirprint(s, a, b) char *s; node *b;
{
register int i;

View File

@@ -1,5 +1,6 @@
e y.tab.h
1,$g!/#define /d
1,$g/YYSTYPE/d
1,$s/# *define *//
1,$s/^/{"/
1,$s/ /", /

View File

@@ -19,6 +19,10 @@ cell *recloc; /* location of record */
cell *nrloc; /* NR */
cell *nfloc; /* NF */
void checkval(cell *vp);
int hash(char *s);
void
syminit()
{
setsymtab("0", tostring("0"), 0.0, NUM|STR|CON|FLD, symtab);
@@ -51,6 +55,7 @@ cell **makesymtab()
return(cp);
}
void
freesymtab(ap) /* free symbol table */
cell *ap;
{
@@ -76,7 +81,7 @@ awkfloat f;
unsigned t;
cell **tab;
{
register h;
int h;
register cell *p;
cell *lookup();
@@ -101,13 +106,14 @@ cell **tab;
return(p);
}
int
hash(s) /* form hash value for string s */
register unsigned char *s;
char *s;
{
register int hashval;
for (hashval = 0; *s != '\0'; )
hashval += *s++;
hashval += (unsigned char) *s++;
return(hashval % MAXSYM);
}
@@ -206,6 +212,7 @@ register cell *vp;
return(vp->sval);
}
void
checkval(vp)
register cell *vp;
{

View File

@@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
main(argc, argv)
int main(argc, argv)
char **argv;
{
register char *p1, *p2, *p3;

View File

@@ -11,13 +11,13 @@ LIBS = -lcurses -ltermcap -lm -lc
all: basic renumber
basic: ${OBJS}
${CC} ${LDFLAGS} -o basic.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o basic.elf ${OBJS} ${LIBS}
${OBJDUMP} -S basic.elf > basic.dis
${SIZE} basic.elf
${ELF2AOUT} basic.elf $@ && rm basic.elf
renumber: renumber.o
${CC} ${LDFLAGS} -o renumber.elf $< ${LIBS}
${LD} ${LDFLAGS} -o renumber.elf $< ${LIBS}
${OBJDUMP} -S renumber.elf > renumber.dis
${SIZE} renumber.elf
${ELF2AOUT} renumber.elf $@ && rm renumber.elf

View File

@@ -1,5 +1,8 @@
%{
int *getout();
int *getout(void);
int getch(void);
int cpeek(int c, int yes, int no);
void yyerror(char *s);
%}
%right '='
%left '+' '-'
@@ -39,12 +42,12 @@ int *pre, *post;
%%
start :
| start stat tail
= output( $2 );
= output( (int*) $2 );
| start def dargs ')' '{' dlist slist '}'
={ bundle(6, pre, $7, post, "0", numb[lev], "Q");
conout( $$, $2 );
conout( (int*) $$, (char*) $2 );
rcrs = crs;
output( "" );
output( (int*) "" );
lev = bindx = 0;
}
;
@@ -62,11 +65,11 @@ stat : e
| LETTER '=' e
={ bundle(3, $3, "s", $1 ); }
| LETTER '[' e ']' '=' e
={ bundle(4, $6, $3, ":", geta($1)); }
={ bundle(4, $6, $3, ":", geta((char*) $1)); }
| LETTER EQOP e
={ bundle(6, "l", $1, $3, $2, "s", $1 ); }
| LETTER '[' e ']' EQOP e
={ bundle(8,$3, ";", geta($1), $6, $5, $3, ":", geta($1));}
={ bundle(8,$3, ";", geta((char*) $1), $6, $5, $3, ":", geta((char*) $1));}
| _BREAK
={ bundle(2, numb[lev-bstack[bindx-1]], "Q" ); }
| _RETURN '(' e ')'
@@ -94,17 +97,17 @@ stat : e
| error
={ bundle(1,"c"); }
| _IF CRS BLEV '(' re ')' stat
={ conout( $7, $2 );
={ conout( (int*) $7, (char*) $2 );
bundle(3, $5, $2, " " );
}
| _WHILE CRS '(' re ')' stat BLEV
={ bundle(3, $6, $4, $2 );
conout( $$, $2 );
conout( (int*) $$, (char*) $2 );
bundle(3, $4, $2, " " );
}
| fprefix CRS re ';' e ')' stat BLEV
={ bundle(5, $7, $5, "s.", $3, $2 );
conout( $$, $2 );
conout( (int*) $$, (char*) $2 );
bundle(5, $1, "s.", $3, $2, " " );
}
| '~' LETTER '=' e
@@ -174,7 +177,7 @@ e : e '+' e
| e '^' e
= bundle(3, $1, $3, "^" );
| LETTER '[' e ']'
={ bundle(3,$3, ";", geta($1)); }
={ bundle(3,$3, ";", geta((char*) $1)); }
| LETTER INCR
= bundle(4, "l", $1, "d1+s", $1 );
| INCR LETTER
@@ -184,13 +187,13 @@ e : e '+' e
| LETTER DECR
= bundle(4, "l", $1, "d1-s", $1 );
| LETTER '[' e ']' INCR
= bundle(7,$3,";",geta($1),"d1+",$3,":",geta($1));
= bundle(7,$3,";",geta((char*) $1),"d1+",$3,":",geta((char*) $1));
| INCR LETTER '[' e ']'
= bundle(7,$4,";",geta($2),"1+d",$4,":",geta($2));
= bundle(7,$4,";",geta((char*) $2),"1+d",$4,":",geta((char*) $2));
| LETTER '[' e ']' DECR
= bundle(7,$3,";",geta($1),"d1-",$3,":",geta($1));
= bundle(7,$3,";",geta((char*) $1),"d1-",$3,":",geta((char*) $1));
| DECR LETTER '[' e ']'
= bundle(7,$4,";",geta($2),"1-d",$4,":",geta($2));
= bundle(7,$4,";",geta((char*) $2),"1-d",$4,":",geta((char*) $2));
| SCALE INCR
= bundle(1,"Kd1+k");
| INCR SCALE
@@ -216,9 +219,9 @@ e : e '+' e
| DECR OBASE
= bundle(1,"O1-do");
| LETTER '(' cargs ')'
= bundle(4, $3, "l", getf($1), "x" );
= bundle(4, $3, "l", getf((char*) $1), "x" );
| LETTER '(' ')'
= bundle(3, "l", getf($1), "x" );
= bundle(3, "l", getf((char*) $1), "x" );
| cons
={ bundle(2, " ", $1 ); }
| DOT cons
@@ -236,9 +239,9 @@ e : e '+' e
| LETTER EQOP e %prec '='
={ bundle(6, "l", $1, $3, $2, "ds", $1 ); }
| LETTER '[' e ']' '=' e
= { bundle(5,$6,"d",$3,":",geta($1)); }
= { bundle(5,$6,"d",$3,":",geta((char*) $1)); }
| LETTER '[' e ']' EQOP e
= { bundle(9,$3,";",geta($1),$6,$5,"d",$3,":",geta($1)); }
= { bundle(9,$3,";",geta((char*) $1),$6,$5,"d",$3,":",geta((char*) $1)); }
| LENGTH '(' e ')'
= bundle(2,$3,"Z");
| SCALE '(' e ')'
@@ -277,7 +280,7 @@ cargs : eora
;
eora: e
| LETTER '[' ']'
=bundle(2,"l",geta($1));
=bundle(2,"l",geta((char*) $1));
;
cons : constant
@@ -303,7 +306,7 @@ CRS :
;
def : _DEFINE LETTER '('
={ $$ = (int) getf($2);
={ $$ = (int) getf((char*) $2);
pre = (int*) "";
post = (int*) "";
lev = 1;
@@ -313,19 +316,19 @@ def : _DEFINE LETTER '('
dargs :
| lora
={ pp( $1 ); }
={ pp((char*) $1); }
| dargs ',' lora
={ pp( $3 ); }
={ pp((char*) $3); }
;
dlets : lora
={ tp($1); }
={ tp((char*) $1); }
| dlets ',' lora
={ tp($3); }
={ tp((char*) $3); }
;
lora : LETTER
| LETTER '[' ']'
={ $$ = (int) geta($1); }
={ $$ = (int) geta((char*) $1); }
;
%%
@@ -348,7 +351,9 @@ char *letr[26] = {
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z" } ;
char *dot = { "." };
yylex(){
int yylex()
{
int c, ch;
restart:
c = getch();
@@ -445,7 +450,8 @@ restart:
}
}
cpeek( c, yes, no ){
int cpeek(int c, int yes, int no)
{
if( (peekc=getch()) != c ) return( no );
else {
peekc = -1;
@@ -453,7 +459,8 @@ cpeek( c, yes, no ){
}
}
getch(){
int getch()
{
int ch;
loop:
ch = (peekc < 0) ? getc(in) : peekc;
@@ -472,13 +479,18 @@ loop:
goto loop;
}
yyerror("cannot open input file");
return EOF;
}
# define b_sp_max 3000
int b_space [ b_sp_max ];
int * b_sp_nxt = { b_space };
int bdebug = 0;
bundle(a){
int bundle(int a, ...)
{
int i, *p, *q;
p = &a;
@@ -494,16 +506,18 @@ bundle(a){
return( (int) q );
}
routput(p) int *p; {
void routput(int *p)
{
if( bdebug ) printf("routput(%p)\n", p );
if( p >= &b_space[0] && p < &b_space[b_sp_max]){
/* part of a bundle */
while( *p != 0 ) routput( *p++ );
while( *p != 0 ) routput( (int*) *p++ );
}
else printf( "%s", (char*) p ); /* character string */
}
output( p ) int *p; {
void output(int *p)
{
routput( p );
b_sp_nxt = & b_space[0];
printf( "\n" );
@@ -512,7 +526,8 @@ output( p ) int *p; {
crs = rcrs;
}
conout( p, s ) int *p; char *s; {
void conout(int *p, char *s)
{
printf("[");
routput( p );
printf("]s%s\n", s );
@@ -520,7 +535,8 @@ conout( p, s ) int *p; char *s; {
lev--;
}
yyerror( s ) char *s; {
void yyerror(char *s)
{
if(ifile > sargc)ss="teletype";
printf("c[%s on line %d, %s]pc\n", s ,ln+1,ss);
fflush(stdout);
@@ -531,7 +547,8 @@ yyerror( s ) char *s; {
b_sp_nxt = &b_space[0];
}
pp( s ) char *s; {
void pp(char *s)
{
/* puts the relevant stuff on pre and post for the letter s */
bundle(3, "S", s, pre );
@@ -540,14 +557,17 @@ pp( s ) char *s; {
post = (int*) yyval;
}
tp( s ) char *s; { /* same as pp, but for temps */
/* same as pp, but for temps */
void tp(char *s)
{
bundle(3, "0S", s, pre );
pre = (int*) yyval;
bundle(4, post, "L", s, "s." );
post = (int*) yyval;
}
yyinit(argc,argv) int argc; char *argv[];{
void yyinit(int argc, char *argv[])
{
signal( 2, SIG_IGN ); /* ignore all interrupts */
sargv=argv;
sargc= -- argc;
@@ -560,24 +580,25 @@ yyinit(argc,argv) int argc; char *argv[];{
ln = 0;
ss = sargv[1];
}
int *getout(){
int *getout()
{
printf("q");
fflush(stdout);
exit(0);
}
int *
getf(p) char *p;{
int *getf(char *p)
{
return (int*) &funtab[2 * (*p - 0141)];
}
int *
geta(p) char *p;{
int *geta(char *p)
{
return (int*) &atab[2 * (*p - 0141)];
}
main(argc, argv)
char **argv;
int main(int argc, char **argv)
{
int p[2];

View File

@@ -11,11 +11,15 @@ char *smon[]= {
};
char string[432];
main(argc, argv)
static int number(char *str);
static void cal(int m, int y, char *p, int w);
static void pstr(char *str, int n);
static int jan1(int yr);
int main(argc, argv)
char *argv[];
{
register y, i, j;
int m;
int y, i, j, m;
if(argc < 2) {
printf("usage: cal [month] year\n");
@@ -27,7 +31,6 @@ char *argv[];
/*
* print out just month
*/
m = number(argv[1]);
if(m<1 || m>12)
goto badarg;
@@ -44,7 +47,6 @@ char *argv[];
/*
* print out complete year
*/
xlong:
y = number(argv[1]);
if(y<1 || y>9999)
@@ -72,15 +74,15 @@ badarg:
printf("Bad argument\n");
}
number(str)
int number(str)
char *str;
{
register n, c;
register char *s;
int n, c;
char *s;
n = 0;
s = str;
while(c = *s++) {
while ((c = *s++)) {
if(c<'0' || c>'9')
return(0);
n = n*10 + c-'0';
@@ -88,11 +90,11 @@ char *str;
return(n);
}
pstr(str, n)
void pstr(str, n)
char *str;
{
register i;
register char *s;
int i;
char *s;
s = str;
i = n;
@@ -114,11 +116,11 @@ char mon[] = {
30, 31, 30, 31,
};
cal(m, y, p, w)
void cal(m, y, p, w)
char *p;
{
register d, i;
register char *s;
int d, i;
char *s;
s = p;
d = jan1(y);
@@ -173,16 +175,14 @@ char *p;
* return day of the week
* of jan 1 of given year
*/
jan1(yr)
int jan1(yr)
{
register y, d;
int y, d;
/*
* normal gregorian calendar
* one extra day per four years
*/
y = yr;
d = 4+y+(y+3)/4;
@@ -191,7 +191,6 @@ jan1(yr)
* regular gregorian
* less three days per 400
*/
if (y > 1800) {
d -= (y-1701)/100;
d += (y-1601)/400;
@@ -200,9 +199,8 @@ jan1(yr)
/*
* great calendar changeover instant
*/
if (y > 1752)
d += 3;
return(d%7);
return d % 7;
}

View File

@@ -10,7 +10,7 @@ MANSRC = calendar.1
all: calendar $(MAN)
calendar: ${OBJS}
${CC} ${LDFLAGS} -o calendar.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o calendar.elf ${OBJS} ${LIBS}
${OBJDUMP} -S calendar.elf > calendar.dis
${SIZE} calendar.elf
${ELF2AOUT} calendar.elf $@ && rm calendar.elf

View File

@@ -56,6 +56,7 @@ static char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94";
#include <string.h>
#include <tzfile.h>
#include <unistd.h>
#include <strings.h>
#include "pathnames.h"

View File

@@ -9,20 +9,24 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
/* #define OPTSIZE BUFSIZ /* define this only if not 4.2 BSD or beyond */
// #define OPTSIZE BUFSIZ /* define this only if not 4.2 BSD or beyond */
int bflg, eflg, nflg, sflg, tflg, uflg, vflg;
int spaced, col, lno, inlin, ibsize, obsize;
main(argc, argv)
static void copyopt(FILE *f);
static int fastcat(int fd);
int main(argc, argv)
char **argv;
{
int fflg = 0;
register FILE *fi;
register c;
FILE *fi;
int c;
int dev, ino = -1;
struct stat statb;
int retval = 0;
@@ -121,10 +125,10 @@ char **argv;
exit(retval);
}
copyopt(f)
register FILE *f;
void copyopt(f)
FILE *f;
{
register int c;
int c;
top:
c = getc(f);
@@ -168,11 +172,11 @@ top:
goto top;
}
fastcat(fd)
register int fd;
int fastcat(fd)
int fd;
{
register int buffsize, n, nwritten, offset;
register char *buff;
int buffsize, n, nwritten, offset;
char *buff;
struct stat statbuff;
#ifndef OPTSIZE

View File

@@ -9,26 +9,20 @@ int sifflg[10];
int iflev = 0;
int ifflg = -1;
int level = 0;
int ind[10] = {
0,0,0,0,0,0,0,0,0,0 };
int ind[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int eflg = 0;
int paren = 0;
int pflg[10] = {
0,0,0,0,0,0,0,0,0,0 };
int pflg[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
char lchar;
char pchar;
int aflg = 0;
int ct;
int stabs[20][10];
int qflg = 0;
char *wif[] = {
"if",0};
char *welse[] = {
"else",0};
char *wfor[] = {
"for",0};
char *wds[] = {
"case","default",0};
char *wif[] = { "if", 0 };
char *welse[] = { "else", 0 };
char *wfor[] = { "for", 0 };
char *wds[] = { "case", "default", 0 };
int j = 0;
char string[200];
char cc;
@@ -37,9 +31,16 @@ int peek = -1;
int tabs = 0;
int lastchar;
int c;
int getstr();
putstr()
static void ptabs(void);
static int getch(void);
static int lookup(char *tab[]);
static void gotelse(void);
static int getnl(void);
static void comment(void);
static int getstr(void);
void putstr()
{
if (j > 0) {
if (sflg != 0) {
@@ -47,14 +48,14 @@ putstr()
sflg = 0;
if (aflg == 1) {
aflg = 0;
if(tabs > 0)printf(" ");
if (tabs > 0)
printf(" ");
}
}
string[j] = '\0';
printf("%s", string);
j = 0;
}
else{
} else {
if (sflg != 0) {
sflg = 0;
aflg = 0;
@@ -62,9 +63,9 @@ putstr()
}
}
main(argc, argv)
int main(argc, argv)
int argc;
char argv[];
char *argv[];
{
while ((c = getch()) != EOF) {
switch (c) {
@@ -72,28 +73,30 @@ main(argc, argv)
case '\t':
if (lookup(welse) == 1) {
gotelse();
if(sflg == 0 || j > 0)string[j++] = c;
if (sflg == 0 || j > 0)
string[j++] = c;
putstr();
sflg = 0;
continue;
}
if(sflg == 0 || j > 0)string[j++] = c;
if (sflg == 0 || j > 0)
string[j++] = c;
continue;
case '\n':
if((eflg = lookup(welse)) == 1)gotelse();
if ((eflg = lookup(welse)) == 1)
gotelse();
putstr();
printf("\n");
sflg = 1;
if (eflg == 1) {
pflg[level]++;
tabs++;
}
else
if(pchar == lchar)
} else if (pchar == lchar)
aflg = 1;
continue;
case '{':
if(lookup(welse) == 1)gotelse();
if (lookup(welse) == 1)
gotelse();
siflev[clevel] = iflev;
sifflg[clevel] = ifflg;
iflev = ifflg = 0;
@@ -117,7 +120,8 @@ main(argc, argv)
continue;
case '}':
clevel--;
if((iflev = siflev[clevel]-1) < 0)iflev = 0;
if ((iflev = siflev[clevel] - 1) < 0)
iflev = 0;
ifflg = sifflg[clevel];
if (pflg[level] > 0 && ind[level] == 0) {
tabs -= pflg[level];
@@ -129,13 +133,15 @@ main(argc, argv)
if ((peek = getch()) == ';') {
printf("%c;", c);
peek = -1;
}
else printf("%c",c);
} else
printf("%c", c);
getnl();
putstr();
printf("\n");
sflg = 1;
if(clevel < slevel[level])if(level > 0)level--;
if (clevel < slevel[level])
if (level > 0)
level--;
if (ind[level] != 0) {
tabs -= pflg[level];
pflg[level] = 0;
@@ -172,11 +178,14 @@ main(argc, argv)
putstr();
printf("\n");
sflg = 1;
if(iflev > 0)
if(ifflg == 1){iflev--;
if (iflev > 0) {
if (ifflg == 1) {
iflev--;
ifflg = 0;
} else {
iflev = 0;
}
}
else iflev = 0;
continue;
case '\\':
string[j++] = c;
@@ -195,8 +204,7 @@ main(argc, argv)
if (lookup(wds) == 0) {
sflg = 0;
putstr();
}
else{
} else {
tabs--;
putstr();
tabs++;
@@ -212,7 +220,8 @@ main(argc, argv)
continue;
case '/':
string[j++] = c;
if((peek = getch()) != '*')continue;
if ((peek = getch()) != '*')
continue;
string[j++] = peek;
peek = -1;
comment();
@@ -223,7 +232,8 @@ main(argc, argv)
putstr();
if (getnl() == 1) {
peek = '\n';
if(paren != 0)aflg = 1;
if (paren != 0)
aflg = 1;
else if (tabs > 0) {
pflg[level]++;
tabs++;
@@ -233,7 +243,8 @@ main(argc, argv)
continue;
case '#':
string[j++] = c;
while((cc = getch()) != '\n')string[j++] = cc;
while ((cc = getch()) != '\n')
string[j++] = cc;
string[j++] = cc;
sflg = 0;
putstr();
@@ -243,11 +254,13 @@ main(argc, argv)
string[j++] = c;
paren++;
if (lookup(wfor) == 1) {
while((c = getstr()) != ';');
while ((c = getstr()) != ';')
;
ct = 0;
cont:
while ((c = getstr()) != ')') {
if(c == '(') ct++;
if (c == '(')
ct++;
}
if (ct != 0) {
ct--;
@@ -274,42 +287,49 @@ cont:
continue;
default:
string[j++] = c;
if(c != ',')lchar = c;
if (c != ',')
lchar = c;
}
}
}
ptabs()
void ptabs()
{
int i;
for(i=0; i < tabs; i++)printf("\t");
for (i = 0; i < tabs; i++)
printf("\t");
}
getch()
int getch()
{
if(peek < 0 && lastchar != ' ' && lastchar != '\t')pchar = lastchar;
if (peek < 0 && lastchar != ' ' && lastchar != '\t')
pchar = lastchar;
lastchar = (peek < 0) ? getc(stdin) : peek;
peek = -1;
return (lastchar);
}
lookup(tab)
int lookup(tab)
char *tab[];
{
char r;
int l, kk, k, i;
if(j < 1)return(0);
if (j < 1)
return (0);
kk = 0;
while(string[kk] == ' ')kk++;
while (string[kk] == ' ')
kk++;
for (i = 0; tab[i] != 0; i++) {
l = 0;
for(k=kk;(r = tab[i][l++]) == string[k] && r != '\0';k++);
if(r == '\0' && (string[k] < 'a' || string[k] > 'z' || k >= j))return(1);
for (k = kk; (r = tab[i][l++]) == string[k] && r != '\0'; k++)
;
if (r == '\0' && (string[k] < 'a' || string[k] > 'z' || k >= j))
return (1);
}
return (0);
}
getstr()
int getstr()
{
char ch;
beg:
@@ -318,18 +338,20 @@ beg:
goto beg;
}
if (ch == '\'' || ch == '"') {
while((cc = string[j++] = getch()) != ch)if(cc == '\\')string[j++] = getch();
while ((cc = string[j++] = getch()) != ch)
if (cc == '\\')
string[j++] = getch();
goto beg;
}
if (ch == '\n') {
putstr();
aflg = 1;
goto beg;
}
else return(ch);
} else
return (ch);
}
gotelse()
void gotelse()
{
tabs = stabs[clevel][iflev];
pflg[level] = spflg[clevel][iflev];
@@ -337,7 +359,7 @@ gotelse()
ifflg = 1;
}
getnl()
int getnl()
{
while ((peek = getch()) == '\t' || peek == ' ') {
string[j++] = peek;
@@ -350,8 +372,8 @@ getnl()
string[j++] = '*';
peek = -1;
comment();
}
else string[j++] = '/';
} else
string[j++] = '/';
}
if ((peek = getch()) == '\n') {
peek = -1;
@@ -360,7 +382,7 @@ getnl()
return (0);
}
comment()
void comment()
{
int i = j;

View File

@@ -15,7 +15,7 @@ CFLAGS += -DVERSSTR=\"1.0\" \
all: cc
cc: $(OBJS)
${CC} ${LDFLAGS} -o cc.elf $(OBJS) ${LIBS}
${LD} ${LDFLAGS} -o cc.elf $(OBJS) ${LIBS}
${OBJDUMP} -S cc.elf > cc.dis
${SIZE} cc.elf
${ELF2AOUT} cc.elf $@ && rm cc.elf

View File

@@ -22,7 +22,7 @@ MANSRC = ccom.1
all: ccom $(MAN)
ccom: ${OBJS}
${CC} ${LDFLAGS} -o ccom.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o ccom.elf ${OBJS} ${LIBS}
${OBJDUMP} -S ccom.elf > ccom.dis
${SIZE} ccom.elf
${ELF2AOUT} ccom.elf $@ && rm ccom.elf

View File

@@ -14,7 +14,7 @@ MANSRC = chflags.1
all: chflags chflags.0
chflags: ${OBJS}
${CC} ${LDFLAGS} -o chflags.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o chflags.elf ${OBJS} ${LIBS}
${OBJDUMP} -S chflags.elf > chflags.dis
${SIZE} chflags.elf
${ELF2AOUT} chflags.elf $@ && rm chflags.elf

View File

@@ -16,6 +16,9 @@
#include <sys/stat.h>
#include <grp.h>
#include <pwd.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/dir.h>
struct group *gr;
@@ -27,12 +30,18 @@ int status;
int fflag, rflag;
static char *fchdirmsg = "Can't fchdir() back to starting directory";
main(argc, argv)
static void fatal(int status, char *fmt, ...);
static int isnumber(char *s);
static int Perror(char *s);
static int error(char *fmt, ...);
static int chownr(char *dir, uid_t uid, gid_t gid, int savedir);
int main(argc, argv)
int argc;
char *argv[];
{
register c, i;
register char *cp;
int c, i;
char *cp;
int fcurdir;
argc--, argv++;
@@ -107,25 +116,25 @@ ok:
exit(status);
}
isnumber(s)
int isnumber(s)
char *s;
{
register int c;
int c;
while (c = *s++)
while ((c = *s++))
if (!isdigit(c))
return (0);
return (1);
}
chownr(dir, uid, gid, savedir)
int chownr(dir, uid, gid, savedir)
char *dir;
uid_t uid;
gid_t gid;
int savedir;
{
register DIR *dirp;
register struct direct *dp;
DIR *dirp;
struct direct *dp;
struct stat st;
int ecode;
@@ -173,33 +182,37 @@ chownr(dir, uid, gid, savedir)
return (ecode);
}
error(fmt, a)
char *fmt, *a;
int verror(char *fmt, va_list args)
{
if (!fflag) {
fprintf(stderr, "chgrp: ");
fprintf(stderr, fmt, a);
vfprintf(stderr, fmt, args);
putc('\n', stderr);
}
return (!fflag);
}
/* VARARGS */
fatal(status, fmt, a)
int status;
char *fmt, *a;
int error(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
int status = verror(fmt, args);
va_end(args);
return status;
}
void fatal(int status, char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fflag = 0;
(void) error(fmt, a);
verror(fmt, args);
va_end(args);
exit(status);
}
Perror(s)
char *s;
int Perror(char *s)
{
if (!fflag) {
fprintf(stderr, "chgrp: ");
perror(s);

View File

@@ -12,6 +12,9 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
@@ -24,11 +27,21 @@ int status;
int fflag;
int rflag;
main(argc, argv)
static void fatal(int status, char *fmt, ...);
static int Perror(char *s);
static int error(char *fmt, ...);
static int newmode(unsigned nm);
static int chmodr(char *dir, int mode, int savedir);
static int abss(void);
static int who(void);
static int what(void);
static int where(int om);
int main(argc, argv)
char *argv[];
{
register char *p, *flags;
register int i;
char *p, *flags;
int i;
struct stat st;
int fcurdir;
@@ -89,13 +102,13 @@ done:
exit(status);
}
chmodr(dir, mode, savedir)
int chmodr(dir, mode, savedir)
char *dir;
int mode;
int savedir;
{
register DIR *dirp;
register struct direct *dp;
DIR *dirp;
struct direct *dp;
struct stat st;
int ecode;
@@ -140,32 +153,37 @@ chmodr(dir, mode, savedir)
return (ecode);
}
error(fmt, a)
char *fmt, *a;
int verror(char *fmt, va_list args)
{
if (!fflag) {
fprintf(stderr, "chmod: ");
fprintf(stderr, fmt, a);
vfprintf(stderr, fmt, args);
putc('\n', stderr);
}
return (!fflag);
}
fatal(status, fmt, a)
int status;
char *fmt, *a;
int error(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
int status = verror(fmt, args);
va_end(args);
return status;
}
void fatal(int status, char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fflag = 0;
(void) error(fmt, a);
verror(fmt, args);
va_end(args);
exit(status);
}
Perror(s)
char *s;
int Perror(char *s)
{
if (!fflag) {
fprintf(stderr, "chmod: ");
perror(s);
@@ -173,10 +191,10 @@ Perror(s)
return (!fflag);
}
newmode(nm)
int newmode(nm)
unsigned nm;
{
register o, m, b;
int o, m, b;
int savem;
ms = modestring;
@@ -186,7 +204,7 @@ newmode(nm)
return (m);
do {
m = who();
while (o = what()) {
while ((o = what())) {
b = where(nm);
switch (o) {
case '+':
@@ -207,9 +225,9 @@ newmode(nm)
return (nm);
}
abss()
int abss()
{
register c, i;
int c, i;
i = 0;
while ((c = *ms++) >= '0' && c <= '7')
@@ -229,9 +247,9 @@ abss()
#define SETID 06000 /* set[ug]id */
#define STICKY 01000 /* sticky bit */
who()
int who()
{
register m;
int m;
m = 0;
for (;;) switch (*ms++) {
@@ -255,7 +273,7 @@ who()
}
}
what()
int what()
{
switch (*ms) {
@@ -267,10 +285,10 @@ what()
return (0);
}
where(om)
register om;
int where(om)
int om;
{
register m;
int m;
m = 0;
switch (*ms) {

View File

@@ -1,7 +1,7 @@
TOPSRC = $(shell cd ../../..; pwd)
include $(TOPSRC)/target.mk
CFLAGS = -O
CFLAGS = -O -Werror
SRCS = chown.c
OBJS = chown.o
MAN = chown.0
@@ -10,7 +10,7 @@ MANSRC = chown.8
all: chown $(MAN)
chown: ${OBJS}
${CC} ${LDFLAGS} -o chown.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o chown.elf ${OBJS} ${LIBS}
${OBJDUMP} -S chown.elf > chown.dis
${SIZE} chown.elf
${ELF2AOUT} chown.elf $@ && rm chown.elf

View File

@@ -17,6 +17,8 @@
#include <sys/dir.h>
#include <grp.h>
#include <strings.h>
#include <unistd.h>
#include <fcntl.h>
static char *fchdirmsg = "Can't fchdir() back to starting directory";
struct passwd *pwd;
@@ -27,88 +29,52 @@ int status;
int fflag;
int rflag;
main(argc, argv)
char *argv[];
{
register int c;
register gid_t gid;
register char *cp, *group;
struct group *grp;
int fcurdir;
argc--, argv++;
while (argc > 0 && argv[0][0] == '-') {
for (cp = &argv[0][1]; *cp; cp++) switch (*cp) {
case 'f':
fflag++;
break;
case 'R':
rflag++;
break;
default:
fatal(255, "unknown option: %c", *cp);
}
argv++, argc--;
}
if (argc < 2) {
fprintf(stderr, "usage: chown [-fR] owner[.group] file ...\n");
exit(-1);
}
gid = -1;
group = index(argv[0], '.');
if (group != NULL) {
*group++ = '\0';
if (!isnumber(group)) {
if ((grp = getgrnam(group)) == NULL)
fatal(255, "unknown group: %s",group);
gid = grp -> gr_gid;
(void) endgrent();
} else if (*group != '\0')
gid = atoi(group);
}
if (!isnumber(argv[0])) {
if ((pwd = getpwnam(argv[0])) == NULL)
fatal(255, "unknown user id: %s",argv[0]);
uid = pwd->pw_uid;
} else
uid = atoi(argv[0]);
fcurdir = open(".", O_RDONLY);
if (fcurdir < 0)
fatal(255, "Can't open .");
for (c = 1; c < argc; c++) {
/* do stat for directory arguments */
if (lstat(argv[c], &stbuf) < 0) {
status += Perror(argv[c]);
continue;
}
if (rflag && ((stbuf.st_mode&S_IFMT) == S_IFDIR)) {
status += chownr(argv[c], uid, gid, fcurdir);
continue;
}
if (chown(argv[c], uid, gid)) {
status += Perror(argv[c]);
continue;
}
}
exit(status);
}
int
isnumber(s)
char *s;
{
register c;
int c;
while(c = *s++)
while ((c = *s++))
if (!isdigit(c))
return (0);
return (1);
}
int
Perror(s)
char *s;
{
if (!fflag) {
fprintf(stderr, "chown: ");
perror(s);
}
return (!fflag);
}
int
error(fmt, a)
char *fmt, *a;
{
if (!fflag) {
fprintf(stderr, "chown: ");
fprintf(stderr, fmt, a);
putc('\n', stderr);
}
return (!fflag);
}
void
fatal(status, fmt, a)
int status;
char *fmt, *a;
{
fflag = 0;
(void) error(fmt, a);
exit(status);
}
int
chownr(dir, uid, gid, savedir)
char *dir;
{
@@ -151,40 +117,79 @@ chownr(dir, uid, gid, savedir)
break;
}
if (fchdir(savedir) < 0)
fatal(255, fchdirmsg);
fatal(255, fchdirmsg, "");
closedir(dirp);
return (ecode);
}
error(fmt, a)
char *fmt, *a;
int
main(argc, argv)
char *argv[];
{
register int c;
register gid_t gid;
register char *cp, *group;
struct group *grp;
int fcurdir;
if (!fflag) {
fprintf(stderr, "chown: ");
fprintf(stderr, fmt, a);
putc('\n', stderr);
argc--, argv++;
while (argc > 0 && argv[0][0] == '-') {
for (cp = &argv[0][1]; *cp; cp++) switch (*cp) {
case 'f':
fflag++;
break;
case 'R':
rflag++;
break;
default:
fatal(255, "unknown option: %c", (char*)(int)*cp);
}
return (!fflag);
argv++, argc--;
}
if (argc < 2) {
fprintf(stderr, "usage: chown [-fR] owner[.group] file ...\n");
exit(-1);
}
gid = -1;
group = index(argv[0], '.');
if (group != NULL) {
*group++ = '\0';
if (!isnumber(group)) {
if ((grp = getgrnam(group)) == NULL)
fatal(255, "unknown group: %s", group);
gid = grp -> gr_gid;
(void) endgrent();
} else if (*group != '\0')
gid = atoi(group);
}
if (!isnumber(argv[0])) {
if ((pwd = getpwnam(argv[0])) == NULL)
fatal(255, "unknown user id: %s", argv[0]);
uid = pwd->pw_uid;
} else
uid = atoi(argv[0]);
fatal(status, fmt, a)
int status;
char *fmt, *a;
{
fcurdir = open(".", O_RDONLY);
if (fcurdir < 0)
fatal(255, "Can't open .", "");
fflag = 0;
(void) error(fmt, a);
for (c = 1; c < argc; c++) {
/* do stat for directory arguments */
if (lstat(argv[c], &stbuf) < 0) {
status += Perror(argv[c]);
continue;
}
if (rflag && ((stbuf.st_mode&S_IFMT) == S_IFDIR)) {
status += chownr(argv[c], uid, gid, fcurdir);
continue;
}
if (chown(argv[c], uid, gid)) {
status += Perror(argv[c]);
continue;
}
}
exit(status);
}
Perror(s)
char *s;
{
if (!fflag) {
fprintf(stderr, "chown: ");
perror(s);
}
return (!fflag);
}

View File

@@ -27,7 +27,7 @@ MANSRC = chpass.1
all: chpass chpass.0
chpass: ${OBJS}
${CC} ${LDFLAGS} -o chpass.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o chpass.elf ${OBJS} ${LIBS}
${OBJDUMP} -S chpass.elf > chpass.dis
${SIZE} chpass.elf
${ELF2AOUT} chpass.elf $@ && rm chpass.elf

View File

@@ -20,6 +20,7 @@
#include <sys/signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <pwd.h>
#include <errno.h>
#include <stdio.h>
@@ -29,6 +30,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <paths.h>
#include <fcntl.h>
#include "chpass.h"
char e1[] = ": ";
@@ -57,6 +59,16 @@ struct entry list[] = {
uid_t uid;
void loadpw(char *arg, struct passwd *pw);
void usage(void);
int info(struct passwd *pw);
int copy(struct passwd *pw, FILE *fp);
int makedb(char *file);
int edit(char *file);
int check(FILE *fp, struct passwd *pw);
int prompt(void);
int
main(argc, argv)
int argc;
char **argv;
@@ -70,7 +82,6 @@ main(argc, argv)
int aflag, ch, fd;
char *fend, *passwd, *temp, *tend;
char from[MAXPATHLEN], to[MAXPATHLEN];
char *getusershell();
uid = getuid();
aflag = 0;
@@ -220,6 +231,7 @@ bad: (void)fprintf(stderr, "%s unchanged.\n", _PATH_SHADOW);
exit(0);
}
int
info(pw)
struct passwd *pw;
{
@@ -268,6 +280,7 @@ info(pw)
return(rval);
}
int
check(fp, pw)
FILE *fp;
struct passwd *pw;
@@ -331,6 +344,7 @@ check(fp, pw)
return(1);
}
int
copy(pw, fp)
struct passwd *pw;
FILE *fp;
@@ -371,6 +385,7 @@ copy(pw, fp)
return(1);
}
int
makedb(file)
char *file;
{
@@ -384,14 +399,17 @@ makedb(file)
return(w == -1 || status);
}
int
edit(file)
char *file;
{
int status, pid, w;
char *p, *editor, *getenv();
if (editor = getenv("EDITOR")) {
if (p = rindex(editor, '/'))
editor = getenv("EDITOR");
if (editor) {
p = rindex(editor, '/');
if (p)
++p;
else
p = editor;
@@ -408,6 +426,7 @@ edit(file)
return(w == -1 || status);
}
void
loadpw(arg, pw)
char *arg;
register struct passwd *pw;
@@ -432,6 +451,7 @@ bad: (void)fprintf(stderr, "chpass: bad password list.\n");
}
}
int
prompt()
{
register int c;
@@ -447,6 +467,7 @@ prompt()
/* NOTREACHED */
}
void
usage()
{
(void)fprintf(stderr, "usage: chpass [-a list] [user]\n");

View File

@@ -22,3 +22,5 @@ struct entry {
};
extern uid_t uid;
void print(FILE *fp, struct passwd *pw);

View File

@@ -23,9 +23,12 @@
#include <stdio.h>
#include <ctype.h>
#include <paths.h>
#include <stdlib.h>
#include <unistd.h>
#include "chpass.h"
/* ARGSUSED */
int
p_login(p, pw, ep)
char *p;
struct passwd *pw;
@@ -57,6 +60,7 @@ p_login(p, pw, ep)
}
/* ARGSUSED */
int
p_passwd(p, pw, ep)
char *p;
struct passwd *pw;
@@ -73,6 +77,7 @@ p_passwd(p, pw, ep)
}
/* ARGSUSED */
int
p_uid(p, pw, ep)
register char *p;
struct passwd *pw;
@@ -99,6 +104,7 @@ p_uid(p, pw, ep)
}
/* ARGSUSED */
int
p_gid(p, pw, ep)
register char *p;
struct passwd *pw;
@@ -131,6 +137,7 @@ p_gid(p, pw, ep)
}
/* ARGSUSED */
int
p_gecos(p, pw, ep)
char *p;
struct passwd *pw;
@@ -146,6 +153,7 @@ p_gecos(p, pw, ep)
}
/* ARGSUSED */
int
p_hdir(p, pw, ep)
char *p;
struct passwd *pw;
@@ -163,13 +171,13 @@ p_hdir(p, pw, ep)
}
/* ARGSUSED */
int
p_shell(p, pw, ep)
register char *p;
struct passwd *pw;
struct entry *ep;
{
register char *sh, *t;
char *getusershell();
if (!*p) {
pw->pw_shell = _PATH_BSHELL;

View File

@@ -19,7 +19,10 @@
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <paths.h>
#include "chpass.h"
@@ -46,6 +49,7 @@ ttoa(tval)
return(tbuf);
}
int
atot(p, store)
char *p;
time_t *store;
@@ -109,13 +113,13 @@ bad: return(1);
return(0);
}
void
print(fp, pw)
register FILE *fp;
struct passwd *pw;
{
register char *p;
char *bp;
char *getusershell(), *ttoa();
fprintf(fp, "#Changing user database information for %s.\n",
pw->pw_name);

View File

@@ -25,7 +25,7 @@ MANSRC = chroot.8
all: chroot ${MAN}
chroot: ${OBJS}
${CC} ${LDFLAGS} -o chroot.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o chroot.elf ${OBJS} ${LIBS}
${OBJDUMP} -S chroot.elf > chroot.dis
${SIZE} chroot.elf
${ELF2AOUT} chroot.elf $@ && rm chroot.elf

View File

@@ -18,8 +18,18 @@
#include <stdlib.h>
#include <unistd.h>
#include <paths.h>
#include <string.h>
main(argc, argv)
void fatal(msg)
char *msg;
{
extern int errno;
fprintf(stderr, "chroot: %s: %s\n", msg, strerror(errno));
exit(1);
}
int main(argc, argv)
int argc;
char **argv;
{
@@ -43,12 +53,3 @@ main(argc, argv)
}
/* NOTREACHED */
}
fatal(msg)
char *msg;
{
extern int errno;
fprintf(stderr, "chroot: %s: %s\n", msg, strerror(errno));
exit(1);
}

View File

@@ -9,13 +9,17 @@
* software without specific written prior permission. This software
* is provided ``as is'' without express or implied warranty.
*/
#include <sys/param.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/param.h>
#include <sys/stat.h>
#define DIFF 1 /* found differences */
#define ERR 2 /* error during run */
@@ -34,9 +38,7 @@ static char *file1, *file2; /* file names */
* error --
* print I/O error message and die
*/
static
error(filename)
char *filename;
static void error(char *filename)
{
extern int errno;
int sverrno;
@@ -54,9 +56,7 @@ error(filename)
* endoffile --
* print end-of-file message and exit indicating the files were different
*/
static
endoffile(filename)
char *filename;
static void endoffile(char *filename)
{
/* 32V put this message on stdout, S5 does it on stderr. */
if (!silent)
@@ -68,11 +68,10 @@ endoffile(filename)
* skip --
* skip first part of file
*/
static
skip(dist, fd, fname)
register u_long dist; /* length in bytes, to skip */
register int fd; /* file descriptor */
char *fname; /* file name for error */
static void skip(
u_long dist, /* length in bytes, to skip */
int fd, /* file descriptor */
char *fname) /* file name for error */
{
register int rlen; /* read length */
register int nread;
@@ -88,8 +87,7 @@ skip(dist, fd, fname)
}
}
static
cmp()
static void cmp()
{
register u_char *C1, *C2; /* traveling pointers */
register int cnt, /* counter */
@@ -133,8 +131,8 @@ cmp()
if (*C1 != *C2)
printf("%6ld %3o %3o\n", byte, *C1, *C2);
}
}
else for (C1 = buf1, C2 = buf2;; ++C1, ++C2) {
} else
for (C1 = buf1, C2 = buf2;; ++C1, ++C2) {
++byte;
if (*C1 != *C2) {
printf("%s %s differ: char %ld, line %ld\n", file1, file2, byte, line);
@@ -143,8 +141,7 @@ cmp()
if (*C1 == '\n')
++line;
}
}
else {
} else {
byte += len2;
/*
* here's the real performance problem, we've got to
@@ -171,9 +168,7 @@ cmp()
* otoi --
* octal/decimal string to u_long
*/
static u_long
otoi(C)
register char *C; /* argument string */
static u_long otoi(char *C)
{
register u_long val; /* return value */
register int base; /* number base */
@@ -188,19 +183,14 @@ otoi(C)
* usage --
* print usage and die
*/
static
usage()
static void usage()
{
fputs("usage: cmp [-ls] file1 file2 [skip1] [skip2]\n", stderr);
exit(ERR);
}
main(argc, argv)
int argc;
char **argv;
int main(int argc, char **argv)
{
extern char *optarg;
extern int optind;
int ch;
while ((ch = getopt(argc, argv, "ls")) != EOF)

View File

@@ -18,19 +18,23 @@ int cp, lp;
int ll, llh, mustwr;
int pcp = 0;
char *pgmname;
char *strcpy();
main (argc, argv)
static void incr(void);
static void decr(void);
static void outc(char c);
static void emit(char *s, int lineno);
int main(argc, argv)
int argc; char **argv;
{
int i;
int greek;
register int c;
int c;
pgmname = argv[0];
for (i = 1; i < argc; i++) {
register char *p;
char *p;
if (*argv[i] != '-') {
fprintf(stderr, "%s: bad option %s\n",
pgmname, argv[i]);
@@ -159,8 +163,7 @@ main (argc, argv)
exit(0);
}
outc (c)
register char c;
void outc(char c)
{
if (lp > cp) {
line = lbuff;
@@ -189,7 +192,7 @@ outc (c)
if (bflag || *line == '\0' || *line == ' ')
*line = c;
else {
register char c1, c2, c3;
char c1, c2, c3;
c1 = *++line;
*line++ = '\b';
c2 = *line;
@@ -205,7 +208,7 @@ outc (c)
}
}
store (lno)
void store(lno)
{
lno %= PL;
if (page[lno] != 0)
@@ -218,9 +221,9 @@ store (lno)
strcpy(page[lno],lbuff);
}
fetch(lno)
void fetch(lno)
{
register char *p;
char *p;
lno %= PL;
p = lbuff;
@@ -231,13 +234,14 @@ fetch(lno)
if (page[lno])
strcpy(line, page[lno]);
}
emit (s, lineno)
void emit(s, lineno)
char *s;
int lineno;
{
static int cline = 0;
register int ncp;
register char *p;
int ncp;
char *p;
static int gflag = 0;
if (*s) {
@@ -285,7 +289,7 @@ emit (s, lineno)
}
}
incr()
void incr()
{
store(ll++);
if (ll > llh)
@@ -299,7 +303,7 @@ incr()
fetch(ll);
}
decr()
void decr()
{
if (ll > mustwr - PL) {
store(ll--);

View File

@@ -11,9 +11,14 @@ char *ldr[3];
FILE *ib1;
FILE *ib2;
FILE *openfil();
main(argc,argv)
char *argv[];
static FILE *openfil(char *s);
static int rd(FILE *file, char *buf);
static void wr(char *str, int n);
static void copy(FILE *ibuf, char *lbuf, int n);
static int compare(char *a, char *b);
int main(int argc, char *argv[])
{
int l;
char lb1[LB], lb2[LB];
@@ -29,8 +34,7 @@ char *argv[];
case '1':
if (!one) {
one = 1;
ldr[1][0] =
ldr[2][l--] = '\0';
ldr[1][0] = ldr[2][l--] = '\0';
}
break;
case '2':
@@ -60,45 +64,46 @@ char *argv[];
ib1 = openfil(argv[1]);
ib2 = openfil(argv[2]);
if (rd(ib1, lb1) < 0) {
if(rd(ib2,lb2) < 0) exit(0);
if (rd(ib2, lb2) < 0)
exit(0);
copy(ib2, lb2, 2);
}
if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
if (rd(ib2, lb2) < 0)
copy(ib1, lb1, 1);
while (1) {
switch (compare(lb1, lb2)) {
case 0:
wr(lb1, 3);
if (rd(ib1, lb1) < 0) {
if(rd(ib2,lb2) < 0) exit(0);
if (rd(ib2, lb2) < 0)
exit(0);
copy(ib2, lb2, 2);
}
if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
if (rd(ib2, lb2) < 0)
copy(ib1, lb1, 1);
continue;
case 1:
wr(lb1, 1);
if(rd(ib1,lb1) < 0) copy(ib2,lb2,2);
if (rd(ib1, lb1) < 0)
copy(ib2, lb2, 2);
continue;
case 2:
wr(lb2, 2);
if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
if (rd(ib2, lb2) < 0)
copy(ib1, lb1, 1);
continue;
}
}
}
rd(file,buf)
FILE *file;
char *buf;
int rd(FILE *file, char *buf)
{
int i, c;
register int i, c;
i = 0;
while ((c = getc(file)) != EOF) {
*buf = c;
@@ -112,29 +117,27 @@ char *buf;
return (-1);
}
wr(str,n)
char *str;
void wr(char *str, int n)
{
switch (n) {
case 1:
if(one) return;
if (one)
return;
break;
case 2:
if(two) return;
if (two)
return;
break;
case 3:
if(three) return;
if (three)
return;
}
printf("%s%s\n", ldr[n - 1], str);
}
copy(ibuf,lbuf,n)
FILE *ibuf;
char *lbuf;
void copy(FILE *ibuf, char *lbuf, int n)
{
do {
wr(lbuf, n);
@@ -143,20 +146,21 @@ char *lbuf;
exit(0);
}
compare(a,b)
char *a,*b;
int compare(char *a, char *b)
{
register char *ra,*rb;
char *ra, *rb;
ra = --a;
rb = --b;
while (*++ra == *++rb)
if(*ra == '\0') return(0);
if(*ra < *rb) return(1);
if (*ra == '\0')
return (0);
if (*ra < *rb)
return (1);
return (2);
}
FILE *openfil(s)
char *s;
FILE *openfil(char *s)
{
FILE *b;
if (s[0] == '-' && s[1] == 0)

View File

@@ -11,7 +11,7 @@ OBJS = compress.o
CFLAGS += -DUSERMEM=1024 -Wall -Werror
compress: $(OBJS)
${CC} ${LDFLAGS} -o $@.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o $@.elf ${OBJS} ${LIBS}
${OBJDUMP} -S $@.elf > $@.dis
${SIZE} $@.elf
${ELF2AOUT} $@.elf $@

View File

@@ -11,6 +11,8 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/dir.h>
@@ -20,7 +22,12 @@ int iflag;
int rflag;
int pflag;
main(argc, argv)
static void Perror(char *s);
static int copy(char *from, char *to);
static int rcopy(char *from, char *to);
static int setimes(char *path, struct stat *statp);
int main(argc, argv)
int argc;
char **argv;
{
@@ -67,7 +74,7 @@ usage:
exit(1);
}
copy(from, to)
int copy(from, to)
char *from, *to;
{
int fold, fnew, n, exists;
@@ -172,7 +179,7 @@ copy(from, to)
return (0);
}
rcopy(from, to)
int rcopy(from, to)
char *from, *to;
{
DIR *fold = opendir(from);
@@ -225,7 +232,7 @@ setimes(path, statp)
return (0);
}
Perror(s)
void Perror(s)
char *s;
{
fprintf(stderr, "cp: ");

View File

@@ -16,7 +16,7 @@ CFLAGS += -DGCC_COMPAT -DHAVE_CPP_VARARG_MACRO_GCC
all: cpp $(MAN)
cpp: $(OBJS)
${CC} ${LDFLAGS} -o cpp.elf $(OBJS) ${LIBS}
${LD} ${LDFLAGS} -o cpp.elf $(OBJS) ${LIBS}
${OBJDUMP} -S cpp.elf > cpp.dis
${SIZE} cpp.elf
${ELF2AOUT} cpp.elf $@ && rm cpp.elf

4
src/cmd/cron/Makefile Executable file → Normal file
View File

@@ -84,13 +84,13 @@ lint:
|grep -v "constant argument to NOT" 2>&1
cron: $(CRON_OBJ)
${CC} ${LDFLAGS} -o $@.elf ${CRON_OBJ} ${LIBS}
${LD} ${LDFLAGS} -o $@.elf ${CRON_OBJ} ${LIBS}
${OBJDUMP} -S $@.elf > $@.dis
${SIZE} $@.elf
${ELF2AOUT} $@.elf $@
crontab: $(CRONTAB_OBJ)
${CC} ${LDFLAGS} -o $@.elf ${CRONTAB_OBJ} ${LIBS}
${LD} ${LDFLAGS} -o $@.elf ${CRONTAB_OBJ} ${LIBS}
${OBJDUMP} -S $@.elf > $@.dis
${SIZE} $@.elf
${ELF2AOUT} $@.elf $@

0
src/cmd/cron/README Executable file → Normal file
View File

0
src/cmd/cron/README.2BSD Executable file → Normal file
View File

0
src/cmd/cron/bitstring.3 Executable file → Normal file
View File

0
src/cmd/cron/bitstring.h Executable file → Normal file
View File

15
src/cmd/cron/compat.c Executable file → Normal file
View File

@@ -15,15 +15,9 @@
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: compat.c,v 1.6 1994/01/15 20:43:43 vixie Exp $";
#endif
/* vix 30dec93 [broke this out of misc.c - see RCS log for history]
* vix 15jan87 [added TIOCNOTTY, thanks csg@pyramid]
*/
#include "cron.h"
#include <stdio.h>
@@ -40,14 +34,13 @@ setsid()
int newpgrp;
register int fd;
newpgrp = setpgrp(0, getpid());
if ((fd = open(_PATH_TTY, 2)) >= 0)
{
newpgrp = setpgrp();
if ((fd = open(_PATH_TTY, 2)) >= 0) {
(void) ioctl(fd, TIOCNOTTY, (char*)0);
(void) close(fd);
}
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1)
{
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
(void)dup2(fd, 0);
(void)dup2(fd, 1);
(void)dup2(fd, 2);

6
src/cmd/cron/compat.h Executable file → Normal file
View File

@@ -15,13 +15,9 @@
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
/*
* $Id: compat.h,v 1.8 1994/01/15 20:43:43 vixie Exp $
*/
#ifndef __P
#define __P(x) ()
#define const
//#define const
#endif
/*****************************************************************/

16
src/cmd/cron/config.h Executable file → Normal file
View File

@@ -20,10 +20,6 @@
* $Id: config.h,v 2.6 1994/01/15 20:43:43 vixie Exp $
*/
#if !defined(_PATH_SENDMAIL)
# define _PATH_SENDMAIL "/usr/lib/sendmail"
#endif /*SENDMAIL*/
/*
* these are site-dependent
*/
@@ -49,15 +45,15 @@
* -or0s = Option Readtimeout -- don't time out
*/
/* #define MAILCMD "/bin/mail" /*-*/
/* #define MAILARGS "%s -d %s" /*-*/
// #define MAILCMD "/bin/mail" /*-*/
// #define MAILARGS "%s -d %s" /*-*/
/* -d = undocumented but common flag: deliver locally?
*/
/* #define MAILCMD "/usr/mmdf/bin/submit" /*-*/
/* #define MAILARGS "%s -mlrxto %s" /*-*/
// #define MAILCMD "/usr/mmdf/bin/submit" /*-*/
// #define MAILARGS "%s -mlrxto %s" /*-*/
/* #define MAIL_DATE /*-*/
// #define MAIL_DATE /*-*/
/* should we include an ersatz Date: header in
* generated mail? if you are using sendmail
* for MAILCMD, it is better to let sendmail
@@ -68,7 +64,7 @@
* defined but neither exists, should crontab(1) be
* usable only by root?
*/
/*#define ALLOW_ONLY_ROOT /*-*/
//#define ALLOW_ONLY_ROOT /*-*/
/* if you want to use syslog(3) instead of appending
* to CRONDIR/LOG_FILE (/var/cron/log, e.g.), define

0
src/cmd/cron/cron.8 Executable file → Normal file
View File

5
src/cmd/cron/cron.c Executable file → Normal file
View File

@@ -14,11 +14,6 @@
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && defined(DOSCCS)
static char sccsid[] = "@(#)cron.c 2.11.1 (2.11BSD) 1999/08/05";
#endif
#define MAIN_PROGRAM
#include "cron.h"

4
src/cmd/cron/cron.h Executable file → Normal file
View File

@@ -150,7 +150,7 @@ typedef struct _entry {
char **envp;
char *cmd;
bitstr_t bit_decl(minute, MINUTE_COUNT);
bitstr_t bit_decl(hour, HOUR_COUNT);
bitstr_t bit_decl(hour, HOUR_COUNT+1);
bitstr_t bit_decl(dom, DOM_COUNT);
bitstr_t bit_decl(month, MONTH_COUNT);
bitstr_t bit_decl(dow, DOW_COUNT);
@@ -273,3 +273,5 @@ extern int DebugFlags;
extern char *DebugFlagNames[];
# endif /* DEBUGGING */
#endif /*MAIN_PROGRAM*/
int swap_uids_back(void);

0
src/cmd/cron/crontab.1 Executable file → Normal file
View File

0
src/cmd/cron/crontab.5 Executable file → Normal file
View File

2
src/cmd/cron/crontab.c Executable file → Normal file
View File

@@ -21,7 +21,6 @@ static char sccsid[] = "@(#) crontab.c 2.13.1 (2.11BSD) 1999/8/9";
* vix 02may87 [RCS has the rest of the log]
* vix 26jan87 [original]
*/
#define MAIN_PROGRAM
#include "cron.h"
@@ -96,6 +95,7 @@ main(argc, argv)
}
exitstatus = OK_EXIT;
switch (Option) {
case opt_unknown: break;
case opt_list: list_cmd();
break;
case opt_delete: delete_cmd();

6
src/cmd/cron/database.c Executable file → Normal file
View File

@@ -15,14 +15,8 @@
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: database.c,v 2.8 1994/01/15 20:43:43 vixie Exp $";
#endif
/* vix 26jan87 [RCS has the log]
*/
#include "cron.h"
#include <fcntl.h>
#include <sys/stat.h>

12
src/cmd/cron/do_command.c Executable file → Normal file
View File

@@ -14,13 +14,9 @@
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: do_command.c,v 2.12 1994/01/15 20:43:43 vixie Exp $";
#endif
#include "cron.h"
#include <sys/signal.h>
#include <grp.h>
#if defined(SYSLOG)
# include <syslog.h>
#endif
@@ -77,7 +73,7 @@ child_process(e, u)
/* mark ourselves as different to PS command watchers by upshifting
* our program name. This has no effect on some kernels.
*/
for (input_data = ProgramName; ch = *input_data; input_data++)
for (input_data = ProgramName; (ch = *input_data); input_data++)
*input_data = (islower(ch) ? toupper(ch) : ch);
/* discover some useful and important environment settings
@@ -106,7 +102,7 @@ child_process(e, u)
* but that happens later.
*/
escaped = FALSE;
for (input_data = e->cmd; ch = *input_data; input_data++) {
for (input_data = e->cmd; (ch = *input_data); input_data++) {
if (escaped) {
escaped = FALSE;
continue;
@@ -251,7 +247,7 @@ child_process(e, u)
* % -> \n
* \x -> \x for all x != %
*/
while (ch = *input_data++) {
while ((ch = *input_data++)) {
if (escaped) {
if (ch != '%')
putc('\\', out);

5
src/cmd/cron/entry.c Executable file → Normal file
View File

@@ -15,10 +15,6 @@
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && defined(DOSCCS)
static char sccsid[] = "@(#)entry.c 2.12.2 (2.11BSD) 1999/08/05";
#endif
/* vix 26jan87 [RCS'd; rest of log is in RCS file]
* vix 01jan87 [added line-level error recovery]
* vix 31dec86 [added /step to the from-to range, per bob@acornrc]
@@ -26,6 +22,7 @@ static char sccsid[] = "@(#)entry.c 2.12.2 (2.11BSD) 1999/08/05";
*/
#include "cron.h"
#include <strings.h>
typedef enum ecode {
e_none, e_minute, e_hour, e_dom, e_month, e_dow,

9
src/cmd/cron/env.c Executable file → Normal file
View File

@@ -14,15 +14,8 @@
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: env.c,v 2.7 1994/01/26 02:25:50 vixie Exp vixie $";
#endif
#include "cron.h"
char **
env_init()
{
@@ -168,7 +161,7 @@ env_get(name, envp)
register int len = strlen(name);
register char *p, *q;
while (p = *envp++) {
while ((p = *envp++)) {
if (!(q = strchr(p, '=')))
continue;
if ((q - p) == len && !strncmp(p, name, len))

6
src/cmd/cron/externs.h Executable file → Normal file
View File

@@ -14,15 +14,9 @@
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/dir.h>
#define DIR_T struct direct
//#define WEXITSTATUS(x) ((x).w_retcode)
//#define WTERMSIG(x) ((x).w_termsig)
//#define WCOREDUMP(x) ((x).w_coredump)
extern int setsid __P((void));

0
src/cmd/cron/grot/CHANGES Executable file → Normal file
View File

0
src/cmd/cron/grot/CONVERSION Executable file → Normal file
View File

0
src/cmd/cron/grot/FEATURES Executable file → Normal file
View File

0
src/cmd/cron/grot/INSTALL Executable file → Normal file
View File

0
src/cmd/cron/grot/MAIL Executable file → Normal file
View File

0
src/cmd/cron/grot/MANIFEST Executable file → Normal file
View File

0
src/cmd/cron/grot/THANKS Executable file → Normal file
View File

0
src/cmd/cron/grot/diffs Executable file → Normal file
View File

7
src/cmd/cron/job.c Executable file → Normal file
View File

@@ -14,15 +14,8 @@
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: job.c,v 1.6 1994/01/15 20:43:43 vixie Exp $";
#endif
#include "cron.h"
typedef struct _job {
struct _job *next;
entry *e;

6
src/cmd/cron/misc.c Executable file → Normal file
View File

@@ -15,15 +15,9 @@
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: misc.c,v 2.9 1994/01/15 20:43:43 vixie Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
* vix 30dec86 [written]
*/
#include "cron.h"
#include <sys/time.h>
#include <sys/file.h>

0
src/cmd/cron/pathnames.h Executable file → Normal file
View File

5
src/cmd/cron/popen.c Executable file → Normal file
View File

@@ -22,11 +22,6 @@
/* this came out of the ftpd sources; it's been modified to avoid the
* globbing stuff since we don't need it. also execvp instead of execv.
*/
#if !defined(lint) && defined(DOSCCS)
static char sccsid[] = "@(#)popen.c 5.7.2 (2.11BSD) 1999/08/05";
#endif
#include "cron.h"
#include <errno.h>
#include <sys/signal.h>

0
src/cmd/cron/putman.sh Executable file → Normal file
View File

7
src/cmd/cron/user.c Executable file → Normal file
View File

@@ -15,17 +15,10 @@
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: user.c,v 2.8 1994/01/15 20:43:43 vixie Exp $";
#endif
/* vix 26jan87 [log is in RCS file]
*/
#include "cron.h"
void
free_user(u)
user *u;

View File

@@ -22,7 +22,7 @@ OBJS = alloc.o printf.o sh.char.o sh.dir.o sh.dol.o \
all: csh
csh: ${OBJS}
${CC} ${LDFLAGS} -o csh.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o csh.elf ${OBJS} ${LIBS}
${OBJDUMP} -S csh.elf > csh.dis
${SIZE} csh.elf
${ELF2AOUT} csh.elf $@ && rm csh.elf

View File

@@ -13,7 +13,7 @@ OBJS = $(BIN).o
all: $(BIN)
$(BIN): ${OBJS}
${CC} ${LDFLAGS} -o $@.elf ${OBJS} ${LIBS}
${LD} ${LDFLAGS} -o $@.elf ${OBJS} ${LIBS}
${OBJDUMP} -S $@.elf > $@.dis
${SIZE} $@.elf
${ELF2AOUT} $@.elf $@

Some files were not shown because too many files have changed in this diff Show More