Compare commits
45 Commits
uecide-too
...
clang
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba2871aa34 | ||
|
|
edde805980 | ||
|
|
db74d0da32 | ||
|
|
1253330adc | ||
|
|
26e2d7dd5e | ||
|
|
9c3b2e0d9a | ||
|
|
51da6c0e6e | ||
|
|
dbe1779a29 | ||
|
|
c6f46414ed | ||
|
|
552f5ed4c2 | ||
|
|
2d61fa76c3 | ||
|
|
72d7321b45 | ||
|
|
82817c9308 | ||
|
|
c849b8f1f8 | ||
|
|
1febcc5f9f | ||
|
|
7b1d52abff | ||
|
|
2f2d84e6a0 | ||
|
|
6794c38ff4 | ||
|
|
840cd1db8b | ||
|
|
f6602a8a6d | ||
|
|
97dfd3ae89 | ||
|
|
e728e7f25d | ||
|
|
146bae8a98 | ||
|
|
724973121b | ||
|
|
cc59786ed6 | ||
|
|
4c51256273 | ||
|
|
27ddb2eef0 | ||
|
|
c213981071 | ||
|
|
75302a4eec | ||
|
|
2252835438 | ||
|
|
9e2d5993f6 | ||
|
|
a47779d9d6 | ||
|
|
bd9f0208d2 | ||
|
|
4fdec2101b | ||
|
|
9c50b5a97d | ||
|
|
37d1b00b7c | ||
|
|
716151b46f | ||
|
|
8458c9e3c4 | ||
|
|
4e2c809150 | ||
|
|
ef83392732 | ||
|
|
9d5c61e023 | ||
|
|
d5002ad0ac | ||
|
|
00c4bf1ea1 | ||
|
|
9f617eb6fe | ||
|
|
71faeb6c76 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -26,3 +26,4 @@
|
||||
*.img
|
||||
|
||||
Makefile.user
|
||||
TODO
|
||||
|
||||
3
Makefile
3
Makefile
@@ -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
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ Berkeley YACC, GNU bison, flex, groff, ELF library and FUSE library.
|
||||
Under Ubuntu, for example, you can do it by command:
|
||||
|
||||
```shell
|
||||
$ sudo apt-get install bison byacc flex groff-base libelf-dev libfuse-dev
|
||||
$ sudo apt-get install bison byacc flex groff-base libelf-dev
|
||||
```
|
||||
|
||||
You can change a desired filesystem size and swap area size, as required.
|
||||
|
||||
8
cross.mk
8
cross.mk
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
2
include/inttypes.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
7
include/regex.h
Normal file
7
include/regex.h
Normal 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
37
include/stdbool.h
Normal 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 */
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -57,49 +57,49 @@
|
||||
typedef unsigned size_t;
|
||||
#endif
|
||||
|
||||
void abort (void);
|
||||
int abs (int);
|
||||
int atexit (void (*)(void));
|
||||
int atoi (const char *);
|
||||
long atol (const char *);
|
||||
void *calloc (size_t, size_t);
|
||||
void exit (int);
|
||||
void free (void *);
|
||||
char *getenv (const char *);
|
||||
long labs (long);
|
||||
void *malloc (size_t);
|
||||
char *mktemp (char *);
|
||||
int mkstemp (char *);
|
||||
void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
|
||||
int rand (void);
|
||||
void *realloc (void*, size_t);
|
||||
void srand (unsigned);
|
||||
long strtol (const char *, char **, int);
|
||||
unsigned long strtoul (const char *, char **, int);
|
||||
int system (const char *);
|
||||
void abort(void);
|
||||
int abs(int);
|
||||
int atexit(void (*)(void));
|
||||
int atoi(const char *);
|
||||
long atol(const char *);
|
||||
void *calloc(size_t, size_t);
|
||||
void exit(int);
|
||||
void free(void *);
|
||||
char *getenv(const char *);
|
||||
long labs(long);
|
||||
void *malloc(size_t);
|
||||
char *mktemp(char *);
|
||||
int mkstemp(char *);
|
||||
void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
|
||||
int rand(void);
|
||||
void *realloc(void*, size_t);
|
||||
void srand(unsigned);
|
||||
long strtol(const char *, char **, int);
|
||||
unsigned long strtoul(const char *, char **, int);
|
||||
int system(const char *);
|
||||
|
||||
int putenv (char *string);
|
||||
int setenv (const char *name, const char *value, int overwrite);
|
||||
int unsetenv (const char *name);
|
||||
char *_findenv (const char *name, int *offset);
|
||||
int putenv(char *string);
|
||||
int setenv(const char *name, const char *value, int overwrite);
|
||||
int unsetenv(const char *name);
|
||||
char *_findenv(const char *name, int *offset);
|
||||
|
||||
void *alloca (size_t size);
|
||||
void *alloca(size_t size);
|
||||
|
||||
int daemon (int, int);
|
||||
char *devname (int dev, int type);
|
||||
int getloadavg (unsigned loadavg[], int nelem);
|
||||
int daemon(int, int);
|
||||
char *devname(int dev, int type);
|
||||
int getloadavg(unsigned loadavg[], int nelem);
|
||||
|
||||
extern char *suboptarg; /* getsubopt(3) external variable */
|
||||
int getsubopt (char **, char **, char **);
|
||||
int getsubopt(char **, char **, char **);
|
||||
|
||||
long random (void);
|
||||
char *setstate (char *);
|
||||
void srandom (unsigned);
|
||||
long random(void);
|
||||
char *setstate(char *);
|
||||
void srandom(unsigned);
|
||||
|
||||
double atof (const char *);
|
||||
double strtod (const char *, char **);
|
||||
char *ecvt (double, int, int *, int *);
|
||||
char *fcvt (double, int, int *, int *);
|
||||
char *gcvt (double, int, char *);
|
||||
double atof(const char *);
|
||||
double strtod(const char *, char **);
|
||||
char *ecvt(double, int, int *, int *);
|
||||
char *fcvt(double, int, int *, int *);
|
||||
char *gcvt(double, int, char *);
|
||||
|
||||
#endif /* _STDLIB_H_ */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
116
include/unistd.h
116
include/unistd.h
@@ -57,14 +57,16 @@
|
||||
#define X_OK 1 /* Test for execute permission. */
|
||||
#define F_OK 0 /* Test for existence. */
|
||||
|
||||
void _exit (int);
|
||||
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();
|
||||
@@ -73,12 +75,12 @@ off_t lseek();
|
||||
ssize_t read();
|
||||
unsigned int sleep();
|
||||
char *ttyname();
|
||||
ssize_t write (int fd, const void *buf, size_t count);
|
||||
int truncate (const char *path, off_t length);
|
||||
int ftruncate (int fd, off_t length);
|
||||
ssize_t write(int fd, const void *buf, size_t count);
|
||||
int truncate(const char *path, off_t length);
|
||||
int ftruncate(int fd, off_t length);
|
||||
|
||||
void *brk (const void *addr);
|
||||
int _brk (const void *addr);
|
||||
void *brk(const void *addr);
|
||||
int _brk(const void *addr);
|
||||
char *crypt();
|
||||
void endusershell();
|
||||
long gethostid();
|
||||
@@ -88,60 +90,74 @@ char *getwd();
|
||||
void psignal();
|
||||
extern char *sys_siglist[];
|
||||
char *re_comp();
|
||||
void *sbrk (int incr);
|
||||
void *sbrk(int incr);
|
||||
int sethostid();
|
||||
void setusershell();
|
||||
void sync();
|
||||
void sync(void);
|
||||
unsigned int ualarm();
|
||||
void usleep();
|
||||
int pause (void);
|
||||
int pause(void);
|
||||
pid_t vfork();
|
||||
|
||||
int pipe (int pipefd[2]);
|
||||
int close (int fd);
|
||||
int dup (int oldfd);
|
||||
int dup2 (int oldfd, int newfd);
|
||||
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 nice (int inc);
|
||||
int setuid (uid_t uid);
|
||||
int setgid (gid_t gid);
|
||||
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 isatty (int fd);
|
||||
int chdir (const char *path);
|
||||
int fchdir (int fd);
|
||||
int chflags (const char *path, u_long flags);
|
||||
int fchflags (int fd, u_long flags);
|
||||
int getgroups (int size, gid_t list[]);
|
||||
int getdtablesize (void);
|
||||
int rmdir (const char *pathname);
|
||||
int pipe(int pipefd[2]);
|
||||
int close(int fd);
|
||||
int dup(int oldfd);
|
||||
int dup2(int oldfd, int newfd);
|
||||
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);
|
||||
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);
|
||||
int chflags(const char *path, u_long flags);
|
||||
int fchflags(int fd, u_long flags);
|
||||
int getgroups(int size, gid_t list[]);
|
||||
int getdtablesize(void);
|
||||
int rmdir(const char *pathname);
|
||||
|
||||
struct stat;
|
||||
int stat (const char *path, struct stat *buf);
|
||||
int fstat (int fd, struct stat *buf);
|
||||
int lstat (const char *path, struct stat *buf);
|
||||
int stat(const char *path, struct stat *buf);
|
||||
int fstat(int fd, struct stat *buf);
|
||||
int lstat(const char *path, struct stat *buf);
|
||||
|
||||
int execl (const char *path, const char *arg0, ... /* NULL */);
|
||||
int execle (const char *path, const char *arg0, ... /* NULL, char *envp[] */);
|
||||
int execlp (const char *file, const char *arg0, ... /* NULL */);
|
||||
int execl(const char *path, const char *arg0, ... /* NULL */);
|
||||
int execle(const char *path, const char *arg0, ... /* NULL, char *envp[] */);
|
||||
int execlp(const char *file, const char *arg0, ... /* NULL */);
|
||||
|
||||
int execv (const char *path, char *const argv[]);
|
||||
int execve (const char *path, char *const arg0[], char *const envp[]);
|
||||
int execvp (const char *file, char *const argv[]);
|
||||
int execv(const char *path, char *const argv[]);
|
||||
int execve(const char *path, char *const arg0[], char *const envp[]);
|
||||
int execvp(const char *file, char *const argv[]);
|
||||
|
||||
extern char **environ; /* Environment, from crt0. */
|
||||
extern const char *__progname; /* Program name, from crt0. */
|
||||
|
||||
int getopt (int argc, char * const argv[], const char *optstring);
|
||||
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 */
|
||||
@@ -151,14 +167,14 @@ extern int opterr, optind, optopt;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void err (int eval, const char *fmt, ...);
|
||||
void errx (int eval, const char *fmt, ...);
|
||||
void warn (const char *fmt, ...);
|
||||
void warnx (const char *fmt, ...);
|
||||
void verr (int eval, const char *fmt, va_list ap);
|
||||
void verrx (int eval, const char *fmt, va_list ap);
|
||||
void vwarn (const char *fmt, va_list ap);
|
||||
void vwarnx (const char *fmt, va_list ap);
|
||||
void err(int eval, const char *fmt, ...);
|
||||
void errx(int eval, const char *fmt, ...);
|
||||
void warn(const char *fmt, ...);
|
||||
void warnx(const char *fmt, ...);
|
||||
void verr(int eval, const char *fmt, va_list ap);
|
||||
void verrx(int eval, const char *fmt, va_list ap);
|
||||
void vwarn(const char *fmt, va_list ap);
|
||||
void vwarnx(const char *fmt, va_list ap);
|
||||
|
||||
#ifndef _VA_LIST_
|
||||
# undef va_list
|
||||
|
||||
@@ -25,3 +25,5 @@ struct utmp {
|
||||
char ut_host[UT_HOSTSIZE];
|
||||
long ut_time;
|
||||
};
|
||||
|
||||
void login(struct utmp *ut);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 [];
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 $@
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,10 +219,10 @@ 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); }
|
||||
| '$' { PUTS("regex $"); $$ = op2(CHAR, (node *) 0 ,(node *) 0); }
|
||||
| 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
|
||||
{ PUTS("regex CAT"); $$ = op2(CAT, $1, $2); }
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,10 +30,10 @@ 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");
|
||||
if (yyin == NULL)
|
||||
@@ -92,6 +93,7 @@ main(argc, argv)
|
||||
exit(errorflag);
|
||||
}
|
||||
|
||||
int
|
||||
yywrap()
|
||||
{
|
||||
return(1);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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", " * "},
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
e y.tab.h
|
||||
1,$g!/#define /d
|
||||
1,$g/YYSTYPE/d
|
||||
1,$s/# *define *//
|
||||
1,$s/^/{"/
|
||||
1,$s/ /", /
|
||||
|
||||
@@ -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;
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
main(argc, argv)
|
||||
int main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
register char *p1, *p2, *p3;
|
||||
|
||||
@@ -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
|
||||
|
||||
111
src/cmd/bc.y
111
src/cmd/bc.y
@@ -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 );
|
||||
={ bundle(6, pre, $7, post, "0", numb[lev], "Q");
|
||||
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];
|
||||
|
||||
|
||||
@@ -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");
|
||||
@@ -24,10 +28,9 @@ char *argv[];
|
||||
if(argc == 2)
|
||||
goto xlong;
|
||||
|
||||
/*
|
||||
* print out just month
|
||||
*/
|
||||
|
||||
/*
|
||||
* print out just month
|
||||
*/
|
||||
m = number(argv[1]);
|
||||
if(m<1 || m>12)
|
||||
goto badarg;
|
||||
@@ -41,10 +44,9 @@ char *argv[];
|
||||
pstr(string+i, 24);
|
||||
exit(0);
|
||||
|
||||
/*
|
||||
* print out complete year
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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,36 +175,32 @@ char *p;
|
||||
* return day of the week
|
||||
* of jan 1 of given year
|
||||
*/
|
||||
|
||||
jan1(yr)
|
||||
int jan1(yr)
|
||||
{
|
||||
register y, d;
|
||||
|
||||
/*
|
||||
* normal gregorian calendar
|
||||
* one extra day per four years
|
||||
*/
|
||||
int y, d;
|
||||
|
||||
/*
|
||||
* normal gregorian calendar
|
||||
* one extra day per four years
|
||||
*/
|
||||
y = yr;
|
||||
d = 4+y+(y+3)/4;
|
||||
|
||||
/*
|
||||
* julian calendar
|
||||
* regular gregorian
|
||||
* less three days per 400
|
||||
*/
|
||||
|
||||
if(y > 1800) {
|
||||
/*
|
||||
* julian calendar
|
||||
* regular gregorian
|
||||
* less three days per 400
|
||||
*/
|
||||
if (y > 1800) {
|
||||
d -= (y-1701)/100;
|
||||
d += (y-1601)/400;
|
||||
}
|
||||
|
||||
/*
|
||||
* great calendar changeover instant
|
||||
*/
|
||||
|
||||
if(y > 1752)
|
||||
/*
|
||||
* great calendar changeover instant
|
||||
*/
|
||||
if (y > 1752)
|
||||
d += 3;
|
||||
|
||||
return(d%7);
|
||||
return d % 7;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -290,7 +291,7 @@ opencal()
|
||||
return (NULL);
|
||||
errx(1, "no calendar file.");
|
||||
}
|
||||
if (pipe(pdes) < 0)
|
||||
if (pipe(pdes) < 0)
|
||||
return (NULL);
|
||||
switch (vfork()) {
|
||||
case -1: /* error */
|
||||
@@ -339,14 +340,14 @@ closecal(fp)
|
||||
(void)rewind(fp);
|
||||
if (fstat(fileno(fp), &sbuf) || !sbuf.st_size)
|
||||
goto done;
|
||||
if (pipe(pdes) < 0)
|
||||
if (pipe(pdes) < 0)
|
||||
goto done;
|
||||
switch (vfork()) {
|
||||
case -1: /* error */
|
||||
(void)close(pdes[0]);
|
||||
(void)close(pdes[1]);
|
||||
goto done;
|
||||
case 0:
|
||||
case 0:
|
||||
/* child -- set stdin to pipe output */
|
||||
if (pdes[0] != STDIN_FILENO) {
|
||||
(void)dup2(pdes[0], STDIN_FILENO);
|
||||
|
||||
@@ -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
|
||||
|
||||
278
src/cmd/cb.c
278
src/cmd/cb.c
@@ -1,104 +1,107 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int slevel[10];
|
||||
int clevel = 0;
|
||||
int clevel = 0;
|
||||
int spflg[20][10];
|
||||
int sind[20][10];
|
||||
int siflev[10];
|
||||
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 eflg = 0;
|
||||
int paren = 0;
|
||||
int pflg[10] = {
|
||||
0,0,0,0,0,0,0,0,0,0 };
|
||||
char lchar;
|
||||
char pchar;
|
||||
int aflg = 0;
|
||||
int iflev = 0;
|
||||
int ifflg = -1;
|
||||
int level = 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 };
|
||||
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};
|
||||
int j = 0;
|
||||
char string[200];
|
||||
char cc;
|
||||
int sflg = 1;
|
||||
int peek = -1;
|
||||
int tabs = 0;
|
||||
int qflg = 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;
|
||||
int sflg = 1;
|
||||
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){
|
||||
if (j > 0) {
|
||||
if (sflg != 0) {
|
||||
ptabs();
|
||||
sflg = 0;
|
||||
if(aflg == 1){
|
||||
if (aflg == 1) {
|
||||
aflg = 0;
|
||||
if(tabs > 0)printf(" ");
|
||||
if (tabs > 0)
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
string[j] = '\0';
|
||||
printf("%s",string);
|
||||
printf("%s", string);
|
||||
j = 0;
|
||||
}
|
||||
else{
|
||||
if(sflg != 0){
|
||||
} else {
|
||||
if (sflg != 0) {
|
||||
sflg = 0;
|
||||
aflg = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char argv[];
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
while((c = getch()) != EOF){
|
||||
switch(c){
|
||||
while ((c = getch()) != EOF) {
|
||||
switch (c) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
if(lookup(welse) == 1){
|
||||
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){
|
||||
if (eflg == 1) {
|
||||
pflg[level]++;
|
||||
tabs++;
|
||||
}
|
||||
else
|
||||
if(pchar == lchar)
|
||||
aflg = 1;
|
||||
} 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;
|
||||
clevel++;
|
||||
if(sflg == 1 && pflg[level] != 0){
|
||||
if (sflg == 1 && pflg[level] != 0) {
|
||||
pflg[level]--;
|
||||
tabs--;
|
||||
}
|
||||
@@ -109,7 +112,7 @@ main(argc, argv)
|
||||
printf("\n");
|
||||
tabs++;
|
||||
sflg = 1;
|
||||
if(pflg[level] > 0){
|
||||
if (pflg[level] > 0) {
|
||||
ind[level] = 1;
|
||||
level++;
|
||||
slevel[level] = clevel;
|
||||
@@ -117,26 +120,29 @@ 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){
|
||||
if (pflg[level] > 0 && ind[level] == 0) {
|
||||
tabs -= pflg[level];
|
||||
pflg[level] = 0;
|
||||
}
|
||||
putstr();
|
||||
tabs--;
|
||||
ptabs();
|
||||
if((peek = getch()) == ';'){
|
||||
printf("%c;",c);
|
||||
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(ind[level] != 0){
|
||||
if (clevel < slevel[level])
|
||||
if (level > 0)
|
||||
level--;
|
||||
if (ind[level] != 0) {
|
||||
tabs -= pflg[level];
|
||||
pflg[level] = 0;
|
||||
ind[level] = 0;
|
||||
@@ -145,18 +151,18 @@ main(argc, argv)
|
||||
case '"':
|
||||
case '\'':
|
||||
string[j++] = c;
|
||||
while((cc = getch()) != c){
|
||||
while ((cc = getch()) != c) {
|
||||
string[j++] = cc;
|
||||
if(cc == '\\'){
|
||||
if (cc == '\\') {
|
||||
string[j++] = getch();
|
||||
}
|
||||
if(cc == '\n'){
|
||||
if (cc == '\n') {
|
||||
putstr();
|
||||
sflg = 1;
|
||||
}
|
||||
}
|
||||
string[j++] = cc;
|
||||
if(getnl() == 1){
|
||||
if (getnl() == 1) {
|
||||
lchar = cc;
|
||||
peek = '\n';
|
||||
}
|
||||
@@ -164,7 +170,7 @@ main(argc, argv)
|
||||
case ';':
|
||||
string[j++] = c;
|
||||
putstr();
|
||||
if(pflg[level] > 0 && ind[level] == 0){
|
||||
if (pflg[level] > 0 && 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;
|
||||
@@ -188,20 +197,19 @@ main(argc, argv)
|
||||
continue;
|
||||
case ':':
|
||||
string[j++] = c;
|
||||
if(qflg == 1){
|
||||
if (qflg == 1) {
|
||||
qflg = 0;
|
||||
continue;
|
||||
}
|
||||
if(lookup(wds) == 0){
|
||||
if (lookup(wds) == 0) {
|
||||
sflg = 0;
|
||||
putstr();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
tabs--;
|
||||
putstr();
|
||||
tabs++;
|
||||
}
|
||||
if((peek = getch()) == ';'){
|
||||
if ((peek = getch()) == ';') {
|
||||
printf(";");
|
||||
peek = -1;
|
||||
}
|
||||
@@ -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();
|
||||
@@ -221,10 +230,11 @@ main(argc, argv)
|
||||
paren--;
|
||||
string[j++] = c;
|
||||
putstr();
|
||||
if(getnl() == 1){
|
||||
if (getnl() == 1) {
|
||||
peek = '\n';
|
||||
if(paren != 0)aflg = 1;
|
||||
else if(tabs > 0){
|
||||
if (paren != 0)
|
||||
aflg = 1;
|
||||
else if (tabs > 0) {
|
||||
pflg[level]++;
|
||||
tabs++;
|
||||
ind[level] = 0;
|
||||
@@ -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();
|
||||
@@ -242,20 +253,22 @@ main(argc, argv)
|
||||
case '(':
|
||||
string[j++] = c;
|
||||
paren++;
|
||||
if(lookup(wfor) == 1){
|
||||
while((c = getstr()) != ';');
|
||||
ct=0;
|
||||
cont:
|
||||
while((c = getstr()) != ')'){
|
||||
if(c == '(') ct++;
|
||||
if (lookup(wfor) == 1) {
|
||||
while ((c = getstr()) != ';')
|
||||
;
|
||||
ct = 0;
|
||||
cont:
|
||||
while ((c = getstr()) != ')') {
|
||||
if (c == '(')
|
||||
ct++;
|
||||
}
|
||||
if(ct != 0){
|
||||
if (ct != 0) {
|
||||
ct--;
|
||||
goto cont;
|
||||
}
|
||||
paren--;
|
||||
putstr();
|
||||
if(getnl() == 1){
|
||||
if (getnl() == 1) {
|
||||
peek = '\n';
|
||||
pflg[level]++;
|
||||
tabs++;
|
||||
@@ -263,7 +276,7 @@ cont:
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(lookup(wif) == 1){
|
||||
if (lookup(wif) == 1) {
|
||||
putstr();
|
||||
stabs[clevel][iflev] = tabs;
|
||||
spflg[clevel][iflev] = pflg[level];
|
||||
@@ -274,62 +287,71 @@ 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;
|
||||
lastchar = (peek<0) ? getc(stdin):peek;
|
||||
if (peek < 0 && lastchar != ' ' && lastchar != '\t')
|
||||
pchar = lastchar;
|
||||
lastchar = (peek < 0) ? getc(stdin) : peek;
|
||||
peek = -1;
|
||||
return(lastchar);
|
||||
return (lastchar);
|
||||
}
|
||||
|
||||
lookup(tab)
|
||||
char *tab[];
|
||||
int lookup(tab)
|
||||
char *tab[];
|
||||
{
|
||||
char r;
|
||||
int l,kk,k,i;
|
||||
if(j < 1)return(0);
|
||||
kk=0;
|
||||
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);
|
||||
int l, kk, k, i;
|
||||
if (j < 1)
|
||||
return (0);
|
||||
kk = 0;
|
||||
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);
|
||||
}
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
getstr()
|
||||
int getstr()
|
||||
{
|
||||
char ch;
|
||||
beg:
|
||||
if((ch = string[j++] = getch()) == '\\'){
|
||||
if ((ch = string[j++] = getch()) == '\\') {
|
||||
string[j++] = getch();
|
||||
goto beg;
|
||||
}
|
||||
if(ch == '\'' || ch == '"'){
|
||||
while((cc = string[j++] = getch()) != ch)if(cc == '\\')string[j++] = getch();
|
||||
if (ch == '\'' || ch == '"') {
|
||||
while ((cc = string[j++] = getch()) != ch)
|
||||
if (cc == '\\')
|
||||
string[j++] = getch();
|
||||
goto beg;
|
||||
}
|
||||
if(ch == '\n'){
|
||||
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,38 +359,38 @@ gotelse()
|
||||
ifflg = 1;
|
||||
}
|
||||
|
||||
getnl()
|
||||
int getnl()
|
||||
{
|
||||
while((peek = getch()) == '\t' || peek == ' '){
|
||||
while ((peek = getch()) == '\t' || peek == ' ') {
|
||||
string[j++] = peek;
|
||||
peek = -1;
|
||||
}
|
||||
if((peek = getch()) == '/'){
|
||||
if ((peek = getch()) == '/') {
|
||||
peek = -1;
|
||||
if((peek = getch()) == '*'){
|
||||
if ((peek = getch()) == '*') {
|
||||
string[j++] = '/';
|
||||
string[j++] = '*';
|
||||
peek = -1;
|
||||
comment();
|
||||
}
|
||||
else string[j++] = '/';
|
||||
} else
|
||||
string[j++] = '/';
|
||||
}
|
||||
if((peek = getch()) == '\n'){
|
||||
if ((peek = getch()) == '\n') {
|
||||
peek = -1;
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
comment()
|
||||
void comment()
|
||||
{
|
||||
int i = j;
|
||||
|
||||
while ((c = getch()) != EOF) {
|
||||
string[j++] = c;
|
||||
switch(c) {
|
||||
switch (c) {
|
||||
case '/':
|
||||
if (j > i + 1 && string[j-2] == '*')
|
||||
if (j > i + 1 && string[j - 2] == '*')
|
||||
return;
|
||||
break;
|
||||
case '\n':
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
{
|
||||
@@ -150,41 +116,80 @@ chownr(dir, uid, gid, savedir)
|
||||
(ecode = Perror(dp->d_name)))
|
||||
break;
|
||||
}
|
||||
if (fchdir(savedir) < 0)
|
||||
fatal(255, fchdirmsg);
|
||||
if (fchdir(savedir) < 0)
|
||||
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);
|
||||
}
|
||||
argv++, argc--;
|
||||
}
|
||||
return (!fflag);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -22,3 +22,5 @@ struct entry {
|
||||
};
|
||||
|
||||
extern uid_t uid;
|
||||
|
||||
void print(FILE *fp, struct passwd *pw);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
134
src/cmd/cmp.c
134
src/cmd/cmp.c
@@ -9,34 +9,36 @@
|
||||
* 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 */
|
||||
#define NO 0 /* no/false */
|
||||
#define OK 0 /* didn't find differences */
|
||||
#define YES 1 /* yes/true */
|
||||
#define DIFF 1 /* found differences */
|
||||
#define ERR 2 /* error during run */
|
||||
#define NO 0 /* no/false */
|
||||
#define OK 0 /* didn't find differences */
|
||||
#define YES 1 /* yes/true */
|
||||
|
||||
static int fd1, fd2, /* file descriptors */
|
||||
silent = NO; /* if silent run */
|
||||
static short all = NO; /* if report all differences */
|
||||
static u_char buf1[MAXBSIZE], /* read buffers */
|
||||
buf2[MAXBSIZE];
|
||||
static char *file1, *file2; /* file names */
|
||||
static int fd1, fd2, /* file descriptors */
|
||||
silent = NO; /* if silent run */
|
||||
static short all = NO; /* if report all differences */
|
||||
static u_char buf1[MAXBSIZE], /* read buffers */
|
||||
buf2[MAXBSIZE];
|
||||
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,14 +68,13 @@ 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;
|
||||
register int rlen; /* read length */
|
||||
register int nread;
|
||||
|
||||
for (; dist; dist -= rlen) {
|
||||
rlen = MIN(dist, sizeof(buf1));
|
||||
@@ -88,18 +87,17 @@ skip(dist, fd, fname)
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
cmp()
|
||||
static void cmp()
|
||||
{
|
||||
register u_char *C1, *C2; /* traveling pointers */
|
||||
register int cnt, /* counter */
|
||||
len1, len2; /* read lengths */
|
||||
register long byte, /* byte count */
|
||||
line; /* line count */
|
||||
short dfound = NO; /* if difference found */
|
||||
register u_char *C1, *C2; /* traveling pointers */
|
||||
register int cnt, /* counter */
|
||||
len1, len2; /* read lengths */
|
||||
register long byte, /* byte count */
|
||||
line; /* line count */
|
||||
short dfound = NO; /* if difference found */
|
||||
|
||||
for (byte = 0, line = 1;;) {
|
||||
switch(len1 = read(fd1, buf1, MAXBSIZE)) {
|
||||
switch (len1 = read(fd1, buf1, MAXBSIZE)) {
|
||||
case -1:
|
||||
error(file1);
|
||||
case 0:
|
||||
@@ -107,13 +105,13 @@ cmp()
|
||||
* read of file 1 just failed, find out
|
||||
* if there's anything left in file 2
|
||||
*/
|
||||
switch(read(fd2, buf2, 1)) {
|
||||
case -1:
|
||||
error(file2);
|
||||
case 0:
|
||||
exit(dfound ? DIFF : OK);
|
||||
default:
|
||||
endoffile(file1);
|
||||
switch (read(fd2, buf2, 1)) {
|
||||
case -1:
|
||||
error(file2);
|
||||
case 0:
|
||||
exit(dfound ? DIFF : OK);
|
||||
default:
|
||||
endoffile(file1);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@@ -133,18 +131,17 @@ cmp()
|
||||
if (*C1 != *C2)
|
||||
printf("%6ld %3o %3o\n", byte, *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);
|
||||
exit(DIFF);
|
||||
} 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);
|
||||
exit(DIFF);
|
||||
}
|
||||
if (*C1 == '\n')
|
||||
++line;
|
||||
}
|
||||
if (*C1 == '\n')
|
||||
++line;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
byte += len2;
|
||||
/*
|
||||
* here's the real performance problem, we've got to
|
||||
@@ -171,44 +168,37 @@ 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 */
|
||||
register u_long val; /* return value */
|
||||
register int base; /* number base */
|
||||
|
||||
base = (*C == '0') ? 8 : 10;
|
||||
for (val = 0; isdigit(*C); ++C)
|
||||
val = val * base + *C - '0';
|
||||
return(val);
|
||||
return (val);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
switch(ch) {
|
||||
case 'l': /* print all differences */
|
||||
switch (ch) {
|
||||
case 'l': /* print all differences */
|
||||
all = YES;
|
||||
break;
|
||||
case 's': /* silent run */
|
||||
case 's': /* silent run */
|
||||
silent = YES;
|
||||
break;
|
||||
case '?':
|
||||
|
||||
@@ -18,23 +18,27 @@ 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",
|
||||
fprintf(stderr, "%s: bad option %s\n",
|
||||
pgmname, argv[i]);
|
||||
exit (2);
|
||||
exit(2);
|
||||
}
|
||||
for (p = argv[i]+1; *p; p++) {
|
||||
switch (*p) {
|
||||
@@ -51,9 +55,9 @@ main (argc, argv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf (stderr, "%s: bad option letter %c\n",
|
||||
fprintf(stderr, "%s: bad option letter %c\n",
|
||||
pgmname, *p);
|
||||
exit (2);
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,13 +158,12 @@ main (argc, argv)
|
||||
|
||||
for (i=0; i<PL; i++)
|
||||
if (page[(mustwr+i)%PL] != 0)
|
||||
emit (page[(mustwr+i) % PL], mustwr+i-PL);
|
||||
emit (" ", (llh + 1) & -2);
|
||||
emit(page[(mustwr+i) % PL], mustwr+i-PL);
|
||||
emit(" ", (llh + 1) & -2);
|
||||
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,22 +208,22 @@ outc (c)
|
||||
}
|
||||
}
|
||||
|
||||
store (lno)
|
||||
void store(lno)
|
||||
{
|
||||
lno %= PL;
|
||||
if (page[lno] != 0)
|
||||
free (page[lno]);
|
||||
free(page[lno]);
|
||||
page[lno] = malloc((unsigned)strlen(lbuff) + 2);
|
||||
if (page[lno] == 0) {
|
||||
fprintf (stderr, "%s: no storage\n", pgmname);
|
||||
exit (2);
|
||||
fprintf(stderr, "%s: no storage\n", pgmname);
|
||||
exit(2);
|
||||
}
|
||||
strcpy (page[lno],lbuff);
|
||||
strcpy(page[lno],lbuff);
|
||||
}
|
||||
|
||||
fetch(lno)
|
||||
void fetch(lno)
|
||||
{
|
||||
register char *p;
|
||||
char *p;
|
||||
|
||||
lno %= PL;
|
||||
p = lbuff;
|
||||
@@ -229,30 +232,31 @@ fetch(lno)
|
||||
line = lbuff;
|
||||
lp = 0;
|
||||
if (page[lno])
|
||||
strcpy (line, 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) {
|
||||
while (cline < lineno - 1) {
|
||||
putchar ('\n');
|
||||
putchar('\n');
|
||||
pcp = 0;
|
||||
cline += 2;
|
||||
}
|
||||
if (cline != lineno) {
|
||||
putchar (ESC);
|
||||
putchar ('9');
|
||||
putchar(ESC);
|
||||
putchar('9');
|
||||
cline++;
|
||||
}
|
||||
if (pcp)
|
||||
putchar ('\r');
|
||||
putchar('\r');
|
||||
pcp = 0;
|
||||
p = s;
|
||||
while (*p) {
|
||||
@@ -260,23 +264,23 @@ emit (s, lineno)
|
||||
while (*p++ == ' ') {
|
||||
if ((++ncp & 7) == 0 && hflag) {
|
||||
pcp = ncp;
|
||||
putchar ('\t');
|
||||
putchar('\t');
|
||||
}
|
||||
}
|
||||
if (!*--p)
|
||||
break;
|
||||
while (pcp < ncp) {
|
||||
putchar (' ');
|
||||
putchar(' ');
|
||||
pcp++;
|
||||
}
|
||||
if (gflag != (*p & GREEK) && *p != '\b') {
|
||||
if (gflag)
|
||||
putchar (SI);
|
||||
putchar(SI);
|
||||
else
|
||||
putchar (SO);
|
||||
putchar(SO);
|
||||
gflag ^= GREEK;
|
||||
}
|
||||
putchar (*p & ~GREEK);
|
||||
putchar(*p & ~GREEK);
|
||||
if (*p++ == '\b')
|
||||
pcp--;
|
||||
else
|
||||
@@ -285,24 +289,24 @@ emit (s, lineno)
|
||||
}
|
||||
}
|
||||
|
||||
incr()
|
||||
void incr()
|
||||
{
|
||||
store (ll++);
|
||||
store(ll++);
|
||||
if (ll > llh)
|
||||
llh = ll;
|
||||
if (ll >= mustwr && page[ll%PL]) {
|
||||
emit (page[ll%PL], ll - PL);
|
||||
emit(page[ll%PL], ll - PL);
|
||||
mustwr++;
|
||||
free (page[ll%PL]);
|
||||
free(page[ll%PL]);
|
||||
page[ll%PL] = 0;
|
||||
}
|
||||
fetch (ll);
|
||||
fetch(ll);
|
||||
}
|
||||
|
||||
decr()
|
||||
void decr()
|
||||
{
|
||||
if (ll > mustwr - PL) {
|
||||
store (ll--);
|
||||
fetch (ll);
|
||||
store(ll--);
|
||||
fetch(ll);
|
||||
}
|
||||
}
|
||||
|
||||
168
src/cmd/comm.c
168
src/cmd/comm.c
@@ -7,34 +7,38 @@ int one;
|
||||
int two;
|
||||
int three;
|
||||
|
||||
char *ldr[3];
|
||||
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];
|
||||
char lb1[LB], lb2[LB];
|
||||
|
||||
ldr[0] = "";
|
||||
ldr[1] = "\t";
|
||||
ldr[2] = "\t\t";
|
||||
if(argc > 1) {
|
||||
if(*argv[1] == '-' && argv[1][1] != 0) {
|
||||
if (argc > 1) {
|
||||
if (*argv[1] == '-' && argv[1][1] != 0) {
|
||||
l = 1;
|
||||
while(*++argv[1]) {
|
||||
switch(*argv[1]) {
|
||||
case'1':
|
||||
if(!one) {
|
||||
while (*++argv[1]) {
|
||||
switch (*argv[1]) {
|
||||
case '1':
|
||||
if (!one) {
|
||||
one = 1;
|
||||
ldr[1][0] =
|
||||
ldr[2][l--] = '\0';
|
||||
ldr[1][0] = ldr[2][l--] = '\0';
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if(!two) {
|
||||
if (!two) {
|
||||
two = 1;
|
||||
ldr[2][l--] = '\0';
|
||||
}
|
||||
@@ -43,8 +47,8 @@ char *argv[];
|
||||
three = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"comm: illegal flag\n");
|
||||
exit(1);
|
||||
fprintf(stderr, "comm: illegal flag\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
argv++;
|
||||
@@ -52,118 +56,118 @@ char *argv[];
|
||||
}
|
||||
}
|
||||
|
||||
if(argc < 3) {
|
||||
fprintf(stderr,"comm: arg count\n");
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "comm: arg count\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ib1 = openfil(argv[1]);
|
||||
ib2 = openfil(argv[2]);
|
||||
|
||||
|
||||
if(rd(ib1,lb1) < 0) {
|
||||
if(rd(ib2,lb2) < 0) exit(0);
|
||||
copy(ib2,lb2,2);
|
||||
if (rd(ib1, lb1) < 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) {
|
||||
while (1) {
|
||||
switch (compare(lb1, lb2)) {
|
||||
case 0:
|
||||
wr(lb1, 3);
|
||||
if (rd(ib1, lb1) < 0) {
|
||||
if (rd(ib2, lb2) < 0)
|
||||
exit(0);
|
||||
copy(ib2, lb2, 2);
|
||||
}
|
||||
if (rd(ib2, lb2) < 0)
|
||||
copy(ib1, lb1, 1);
|
||||
continue;
|
||||
|
||||
switch(compare(lb1,lb2)) {
|
||||
case 1:
|
||||
wr(lb1, 1);
|
||||
if (rd(ib1, lb1) < 0)
|
||||
copy(ib2, lb2, 2);
|
||||
continue;
|
||||
|
||||
case 0:
|
||||
wr(lb1,3);
|
||||
if(rd(ib1,lb1) < 0) {
|
||||
if(rd(ib2,lb2) < 0) exit(0);
|
||||
copy(ib2,lb2,2);
|
||||
}
|
||||
if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
|
||||
continue;
|
||||
|
||||
case 1:
|
||||
wr(lb1,1);
|
||||
if(rd(ib1,lb1) < 0) copy(ib2,lb2,2);
|
||||
continue;
|
||||
|
||||
case 2:
|
||||
wr(lb2,2);
|
||||
if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
|
||||
continue;
|
||||
case 2:
|
||||
wr(lb2, 2);
|
||||
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) {
|
||||
while ((c = getc(file)) != EOF) {
|
||||
*buf = c;
|
||||
if(c == '\n' || i > LB-2) {
|
||||
if (c == '\n' || i > LB - 2) {
|
||||
*buf = '\0';
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
buf++;
|
||||
}
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
wr(str,n)
|
||||
char *str;
|
||||
void wr(char *str, int n)
|
||||
{
|
||||
switch (n) {
|
||||
case 1:
|
||||
if (one)
|
||||
return;
|
||||
break;
|
||||
|
||||
switch(n) {
|
||||
case 2:
|
||||
if (two)
|
||||
return;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if(one) return;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if(two) return;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if(three) return;
|
||||
case 3:
|
||||
if (three)
|
||||
return;
|
||||
}
|
||||
printf("%s%s\n",ldr[n-1],str);
|
||||
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);
|
||||
} while(rd(ibuf,lbuf) >= 0);
|
||||
wr(lbuf, n);
|
||||
} while (rd(ibuf, lbuf) >= 0);
|
||||
|
||||
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);
|
||||
return(2);
|
||||
while (*++ra == *++rb)
|
||||
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)
|
||||
if (s[0] == '-' && s[1] == 0)
|
||||
b = stdin;
|
||||
else if((b=fopen(s,"r")) == NULL) {
|
||||
else if ((b = fopen(s, "r")) == NULL) {
|
||||
perror(s);
|
||||
exit(1);
|
||||
}
|
||||
return(b);
|
||||
return (b);
|
||||
}
|
||||
|
||||
@@ -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 $@
|
||||
|
||||
15
src/cmd/cp.c
15
src/cmd/cp.c
@@ -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: ");
|
||||
|
||||
@@ -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
4
src/cmd/cron/Makefile
Executable file → Normal 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
0
src/cmd/cron/README
Executable file → Normal file
0
src/cmd/cron/README.2BSD
Executable file → Normal file
0
src/cmd/cron/README.2BSD
Executable file → Normal file
0
src/cmd/cron/bitstring.3
Executable file → Normal file
0
src/cmd/cron/bitstring.3
Executable file → Normal file
0
src/cmd/cron/bitstring.h
Executable file → Normal file
0
src/cmd/cron/bitstring.h
Executable file → Normal file
21
src/cmd/cron/compat.c
Executable file → Normal file
21
src/cmd/cron/compat.c
Executable file → Normal 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,19 +34,18 @@ 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);
|
||||
if (fd > 2)
|
||||
if (fd > 2)
|
||||
(void)close(fd);
|
||||
}
|
||||
}
|
||||
return newpgrp;
|
||||
}
|
||||
|
||||
6
src/cmd/cron/compat.h
Executable file → Normal file
6
src/cmd/cron/compat.h
Executable file → Normal 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
16
src/cmd/cron/config.h
Executable file → Normal 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
0
src/cmd/cron/cron.8
Executable file → Normal file
9
src/cmd/cron/cron.c
Executable file → Normal file
9
src/cmd/cron/cron.c
Executable file → Normal 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"
|
||||
@@ -138,7 +133,7 @@ static void
|
||||
cron_tick(db)
|
||||
cron_db *db;
|
||||
{
|
||||
register struct tm *tm = localtime(&TargetTime);
|
||||
register struct tm *tm = localtime(&TargetTime);
|
||||
register int minute, hour, dom, month, dow;
|
||||
register user *u;
|
||||
register entry *e;
|
||||
@@ -191,7 +186,7 @@ cron_tick(db)
|
||||
*/
|
||||
static void
|
||||
cron_sync() {
|
||||
register struct tm *tm;
|
||||
register struct tm *tm;
|
||||
|
||||
TargetTime = time((time_t*)0);
|
||||
tm = localtime(&TargetTime);
|
||||
|
||||
6
src/cmd/cron/cron.h
Executable file → Normal file
6
src/cmd/cron/cron.h
Executable file → Normal file
@@ -145,12 +145,12 @@
|
||||
|
||||
typedef struct _entry {
|
||||
struct _entry *next;
|
||||
uid_t uid;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
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
0
src/cmd/cron/crontab.1
Executable file → Normal file
0
src/cmd/cron/crontab.5
Executable file → Normal file
0
src/cmd/cron/crontab.5
Executable file → Normal file
6
src/cmd/cron/crontab.c
Executable file → Normal file
6
src/cmd/cron/crontab.c
Executable file → Normal 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();
|
||||
@@ -109,7 +109,7 @@ main(argc, argv)
|
||||
exit(0);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
parse_args(argc, argv)
|
||||
@@ -459,7 +459,7 @@ edit_cmd() {
|
||||
done:
|
||||
log_it(RealUser, Pid, "END EDIT", User);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* returns 0 on success
|
||||
* -1 on syntax error
|
||||
|
||||
6
src/cmd/cron/database.c
Executable file → Normal file
6
src/cmd/cron/database.c
Executable file → Normal 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>
|
||||
|
||||
16
src/cmd/cron/do_command.c
Executable file → Normal file
16
src/cmd/cron/do_command.c
Executable file → Normal 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
|
||||
@@ -96,7 +92,7 @@ child_process(e, u)
|
||||
*/
|
||||
pipe(stdin_pipe); /* child's stdin */
|
||||
pipe(stdout_pipe); /* child's stdout */
|
||||
|
||||
|
||||
/* since we are a forked process, we can diddle the command string
|
||||
* we were passed -- nobody else is going to use it again, right?
|
||||
*
|
||||
@@ -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);
|
||||
@@ -324,7 +320,7 @@ child_process(e, u)
|
||||
*/
|
||||
mailto = usernm;
|
||||
}
|
||||
|
||||
|
||||
/* if we are supposed to be mailing, MAILTO will
|
||||
* be non-NULL. only in this case should we set
|
||||
* up the mail command and subjects and stuff...
|
||||
|
||||
9
src/cmd/cron/entry.c
Executable file → Normal file
9
src/cmd/cron/entry.c
Executable file → Normal 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,
|
||||
@@ -269,7 +266,7 @@ load_entry(file, error_func, pw, envp)
|
||||
* too bad we don't know in advance how long it will be, since we
|
||||
* need to malloc a string for it... so, we limit it to MAX_COMMAND.
|
||||
* XXX - should use realloc().
|
||||
*/
|
||||
*/
|
||||
ch = get_string(cmd, MAX_COMMAND, file, "\n");
|
||||
|
||||
/* a file without a \n before the EOF is rude, so we'll complain...
|
||||
@@ -319,7 +316,7 @@ get_list(bits, low, high, names, ch, file)
|
||||
|
||||
/* list = range {"," range}
|
||||
*/
|
||||
|
||||
|
||||
/* clear the bit string, since the default is 'off'. DONT add an
|
||||
* extra bit here, that's done in the macro!
|
||||
*/
|
||||
|
||||
9
src/cmd/cron/env.c
Executable file → Normal file
9
src/cmd/cron/env.c
Executable file → Normal 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
6
src/cmd/cron/externs.h
Executable file → Normal 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
0
src/cmd/cron/grot/CHANGES
Executable file → Normal file
0
src/cmd/cron/grot/CONVERSION
Executable file → Normal file
0
src/cmd/cron/grot/CONVERSION
Executable file → Normal file
0
src/cmd/cron/grot/FEATURES
Executable file → Normal file
0
src/cmd/cron/grot/FEATURES
Executable file → Normal file
0
src/cmd/cron/grot/INSTALL
Executable file → Normal file
0
src/cmd/cron/grot/INSTALL
Executable file → Normal file
0
src/cmd/cron/grot/MAIL
Executable file → Normal file
0
src/cmd/cron/grot/MAIL
Executable file → Normal file
0
src/cmd/cron/grot/MANIFEST
Executable file → Normal file
0
src/cmd/cron/grot/MANIFEST
Executable file → Normal file
0
src/cmd/cron/grot/THANKS
Executable file → Normal file
0
src/cmd/cron/grot/THANKS
Executable file → Normal file
0
src/cmd/cron/grot/diffs
Executable file → Normal file
0
src/cmd/cron/grot/diffs
Executable file → Normal file
7
src/cmd/cron/job.c
Executable file → Normal file
7
src/cmd/cron/job.c
Executable file → Normal 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;
|
||||
|
||||
8
src/cmd/cron/misc.c
Executable file → Normal file
8
src/cmd/cron/misc.c
Executable file → Normal 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>
|
||||
@@ -622,7 +616,7 @@ arpadate(clock)
|
||||
time_t t = clock ?*clock :time(0L);
|
||||
struct tm *tm = localtime(&t);
|
||||
static char ret[30]; /* zone name might be >3 chars */
|
||||
|
||||
|
||||
(void) sprintf(ret, "%s, %2d %s %2d %02d:%02d:%02d %s",
|
||||
DowNames[tm->tm_wday],
|
||||
tm->tm_mday,
|
||||
|
||||
0
src/cmd/cron/pathnames.h
Executable file → Normal file
0
src/cmd/cron/pathnames.h
Executable file → Normal file
5
src/cmd/cron/popen.c
Executable file → Normal file
5
src/cmd/cron/popen.c
Executable file → Normal 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
0
src/cmd/cron/putman.sh
Executable file → Normal file
9
src/cmd/cron/user.c
Executable file → Normal file
9
src/cmd/cron/user.c
Executable file → Normal 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;
|
||||
@@ -67,7 +60,7 @@ load_user(crontab_fd, pw, name)
|
||||
u->name = strdup(name);
|
||||
u->crontab = NULL;
|
||||
|
||||
/*
|
||||
/*
|
||||
* init environment. this will be copied/augmented for each entry.
|
||||
*/
|
||||
envp = env_init();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user