112 Commits

Author SHA1 Message Date
Serge
ba2871aa34 Update commands bc, egrep, expr, iostat, mail, ps, su, vmstat, wall, write. 2022-07-10 22:14:32 -07:00
Serge
edde805980 Update tail, tar, tee, time, touch, tr, tsort, tty, uniq, w, wc, whereis, who. 2022-07-10 20:07:46 -07:00
Serge
db74d0da32 Update pwd, rev, rm, rmail, rmdir, size, sleep, sort, split, sum, sync. 2022-07-10 19:03:28 -07:00
Serge
1253330adc Update kill, last, ln, mesg, mkdir, mv, nice, od, pagesize, pr, printenv. 2022-07-10 18:33:12 -07:00
Serge
26e2d7dd5e Update du, echo, ed, fgrep, file, grep, head, hostid, join. 2022-07-10 17:35:59 -07:00
Serge
9c3b2e0d9a Update basename, cal, cat, cb, chgrp, chmod, cmp, col, comm, cp, dd. 2022-07-10 16:33:56 -07:00
Serge
51da6c0e6e Update pstat, reboot, shutdown, update, vipw, virus. 2022-07-10 15:00:28 -07:00
Serge
dbe1779a29 Update mkfs, mknod, mkpasswd, mount. 2022-07-10 14:19:42 -07:00
Serge
c6f46414ed Update getty. 2022-06-19 20:44:39 -07:00
Serge
552f5ed4c2 Update chroot and fsck. 2022-06-18 22:53:38 -07:00
Serge
2d61fa76c3 Update yacc. 2022-06-18 22:44:41 -07:00
Serge
72d7321b45 Reindent yacc sources. 2022-06-18 22:00:26 -07:00
Serge
82817c9308 Update uucp. 2022-06-18 21:50:44 -07:00
Serge
c849b8f1f8 Update date2 and tip. 2022-06-18 15:10:26 -07:00
Serge
1febcc5f9f Update cron and gtest. 2022-06-18 14:51:24 -07:00
Serge
7b1d52abff Update src/cmd/Makefile. 2022-06-12 22:49:06 -07:00
Serge
2f2d84e6a0 Update stty, sysctl, test, uname, xargs, zmodem. 2022-06-12 21:53:58 -07:00
Serge
6794c38ff4 Update smlrc. 2022-06-12 20:02:11 -07:00
Serge
840cd1db8b Update smallc. 2022-06-12 19:46:53 -07:00
Serge
f6602a8a6d Update cmd/sh. 2022-05-28 00:39:33 -07:00
Serge
97dfd3ae89 Update sed. 2022-05-27 21:54:16 -07:00
Serge
e728e7f25d Update cmd/re and scm. 2022-05-27 21:12:40 -07:00
Serge
146bae8a98 Update cmd/picoc. 2022-05-27 20:39:20 -07:00
Serge
724973121b Update cmd/more. 2022-05-27 19:24:20 -07:00
Serge
cc59786ed6 Update man, md5 and med. 2022-05-27 18:32:55 -07:00
Serge
4c51256273 Update cmd/login. 2022-05-27 18:11:42 -07:00
Serge
27ddb2eef0 Update lex and ls. 2022-05-27 17:47:38 -07:00
Serge
c213981071 Update glcdtest, hostname, id. 2022-05-27 17:22:07 -07:00
Serge
75302a4eec Implement sqrtf() as a wrapper around sqrt(), for simplicity. 2022-05-27 17:14:04 -07:00
Serge
2252835438 Update cmd/find. 2022-05-27 16:08:38 -07:00
Serge
9e2d5993f6 Update diff and emg. 2022-05-27 02:26:28 -07:00
Serge
a47779d9d6 Update cmd/dc. 2022-05-27 01:23:51 -07:00
Serge
bd9f0208d2 Fix chpass. 2022-05-27 00:46:24 -07:00
Serge
4fdec2101b Move libclang into libc.
Catch all warnings.
2022-05-27 00:20:07 -07:00
Serge
9c50b5a97d Update kernel makefiles. 2022-05-26 00:55:10 -07:00
Serge
37d1b00b7c Update awk. 2022-05-26 00:50:08 -07:00
Serge
716151b46f Update awk and libm. 2022-05-26 00:23:40 -07:00
Serge
8458c9e3c4 Fix linking of user programs.
Start fixing awk.
2022-05-25 23:05:45 -07:00
Serge
4e2c809150 Fix linker script.
Skip empty GNU_STACK section in elf2aout utility.
2022-05-25 22:33:30 -07:00
Serge
ef83392732 Add library libclang: low level support routines from
llvm-project/compiler-rt/lib/builtins collection.
2022-05-25 21:36:20 -07:00
Serge
9d5c61e023 adb: declare all global variables as extern, and define them in main.c. 2022-05-25 20:21:33 -07:00
Serge
d5002ad0ac Use LD for linking mips binaries, not CC.
Fix a few incompatibilities in C sources.
2022-05-25 19:23:39 -07:00
Serge
00c4bf1ea1 Modify makefile in lib/startup to pass options to external assembler. 2022-05-25 18:17:29 -07:00
Serge
9f617eb6fe Modify build scripts for clang.
Disable -mips16 flag for now.
Fix a few issues and incompatibilities detected by compiler.
2022-05-25 17:38:22 -07:00
Serge Vakulenko
71faeb6c76 Disable mount option in fsutil. No need for libfuse anymore.
Fix build issues in virtualmips simulator.
2022-05-25 16:11:07 -07:00
Serge Vakulenko
a0c256c1f0 Virus editor crashed when colon command line exceeded 4 bytes.
Fixed issue #79.
2019-02-17 14:24:26 -08:00
Serge Vakulenko
9d8ad7ccf5 Configure gpanel driver for Duinomite board. 2018-01-30 20:35:01 -08:00
Serge Vakulenko
a5d7f4ea99 Gpanel driver: add support for ILI9481 LCD controller. 2018-01-30 20:22:36 -08:00
Serge Vakulenko
435d3c34cf Fix build errors and warnings in zoneinfo and virtualmips. 2018-01-30 20:20:38 -08:00
Serge Vakulenko
0e39621fea Merge pull request #77 from 610t/master
Retern to legacy implement for expr(1) etc.
2017-02-14 23:25:59 -08:00
Takeshi MUTOH
7477abe7f3 Retern to legacy implement for expr(1) etc. 2017-02-12 06:19:13 +09:00
Serge Vakulenko
7075769d7c Merge pull request #76 from vasily122/insert-int
insert definitions of INT in some functions
2016-12-31 14:10:02 -08:00
vasily122
f5452b74de insert definitions of INT in some functions 2016-11-04 13:46:37 +00:00
Matt Jenkins
f3dbdc7615 Got Yacc compiling and running 2016-07-14 00:06:12 +01:00
Matt Jenkins
66e5cd88c0 Fixed UECIDE compiler location detection 2016-07-14 00:04:45 +01:00
Matt Jenkins
0583055d00 Added PONTECH Quick240 2016-07-14 00:02:22 +01:00
Matt Jenkins
aea2050c49 Merge branch 'master' of github.com:RetroBSD/retrobsd 2016-07-13 16:02:46 +01:00
Serge Vakulenko
5fde14ecea Fix bus frequency and gpio configuration for eMega board. 2016-07-12 17:39:08 -07:00
Serge Vakulenko
ca67f33a30 Autobuild: add Olimex Duinomite-eMega board. 2016-07-07 20:46:14 -07:00
Matt Jenkins
20238b7208 Merge branch 'master' of github.com:RetroBSD/retrobsd 2016-07-03 16:48:42 +01:00
Serge Vakulenko
1a7125b892 Merge pull request #74 from ibara/master
RetroBSD now builds on FreeBSD.
2016-06-23 10:23:34 -07:00
Brian Callahan
d048ee200e RetroBSD now builds on FreeBSD. 2016-06-13 06:47:48 -04:00
Matt Jenkins
6ddcb56e2a Made elf2aout compilable for windows under linux 2016-02-15 15:12:21 +00:00
Serge Vakulenko
148bb1cac6 Merge pull request #72 from alexfru/master
Improve *printf()
2016-01-24 22:16:14 -08:00
Alexey Frunze
b2bde490b4 Improve *printf()
- support %i in addition to %d
- print the sign when printing 0 with %+d
2016-01-24 18:38:58 -08:00
Serge Vakulenko
e1d3583dcd Merge pull request #71 from alexfru/master
Fix infinite loop in ldexp(0.0, any).
2016-01-24 01:55:25 -08:00
Alexey Frunze
21f8d60095 Fix infinite loop in ldexp(0.0, any). 2016-01-24 01:43:24 -08:00
Serge Vakulenko
6457d878c0 Merge pull request #70 from alexfru/master
Floating point improvements
2016-01-23 22:57:05 -08:00
Alexey Frunze
e5c844eff2 Floating point improvements
- Smaller C: fix a bug in __func__ introduced with
  float-related changes
- make *printf() print floats greater than 1e25
- make *printf() print the plus sign when the format
  includes "+", e.g. printf("%+f\n", 1.0);
- clean up and complete prototypes in <math.h>
- remove non-standard HUGE and LOGHUGE from <math.h>
- add HUGE_VAL to <math.h>
- express some hard-coded limits in terms of constants
  from <float.h>
- uncomment prototypes of several floating point
  conversion functions in <stdlib.h> for Smaller C
2016-01-23 19:47:14 -08:00
Serge Vakulenko
4e90456341 Merge pull request #69 from alexfru/master
Floats in Smaller C!
2016-01-16 23:35:14 -08:00
Alexey Frunze
bfc3125556 Floats in Smaller C!
double is an alias for float. IOW, only 32-bit
single precision floats are supported. This isn't
conformant, but OK for some embedded systems (e.g.
RetroBSD) and simple compilers like this.

Also, the following operators are not supported with
floats at the moment: ++, --, +=, -=, *=, /=.
But +, -, *, /, =, ||, &&, ?:, !, comparison, casts,
if/while/for are OK.
2016-01-16 22:45:42 -08:00
Serge Vakulenko
fa094d1744 libc: add missing functions __fixunssfsi() and __floatunsisf(). 2016-01-03 00:21:39 -08:00
Serge Vakulenko
b7a3d6f665 Enable uarts for pic32-retrobsd board.
Fix build issues with fuse library path on Mac OS X.
2015-12-30 19:20:37 -08:00
Serge Vakulenko
fb05f20fbe Merge pull request #66 from ibara/master
Update to emg-2.0
2015-12-17 22:21:49 -08:00
Brian Callahan
e050ac6ee6 Update to emg-2.0 2015-12-18 01:13:00 -05:00
Serge Vakulenko
8dd0fb4860 Flappy game: reduce flickering. 2015-12-03 21:43:43 -08:00
Serge Vakulenko
6028db705a Gpanel spi driver: read ID4 register to identify the ili9341 chip. 2015-12-03 21:25:57 -08:00
Serge Vakulenko
6d501bfc7c Update flappy game. 2015-11-30 12:47:45 -08:00
Serge Vakulenko
09205046a4 Move ILI9341 defines to a separate include file. 2015-11-28 00:44:40 -08:00
Serge Vakulenko
ac9ef0eee9 Add sgpanel driver: a generic TFT LCD graphics panel with SPI interface.
Currently only ILI8341 chip is supported.
2015-11-28 00:17:01 -08:00
Serge Vakulenko
e073fcbd64 SD driver: print information about the CMD6 function groups. 2015-11-27 17:26:09 -08:00
Serge Vakulenko
0507073b60 SD driver: use CMD6 command to switch the card into high-speed mode. 2015-11-26 17:25:25 -08:00
Serge Vakulenko
76cb491c09 Flappy Bird game: save high score to a file. 2015-11-23 13:41:13 -08:00
Serge Vakulenko
f3f28ceca5 Fix bug in gpanel fill triangle routine. 2015-11-22 15:04:41 -08:00
Serge Vakulenko
e3c86f0ffa Update Flappy Bird game. 2015-11-22 14:34:44 -08:00
Serge Vakulenko
7503ce7856 Add Flappy Bird game. 2015-11-22 01:47:52 -08:00
Serge Vakulenko
1a1daf15a3 Update ILI9341 LCD driver. 2015-11-22 00:19:14 -08:00
Serge Vakulenko
a40bcee878 Extend gpanel library with fill rectangle routine. 2015-11-21 23:10:45 -08:00
Serge Vakulenko
e67e939fb9 Add aclock game. 2015-11-20 22:44:37 -08:00
Serge Vakulenko
9027547fa6 Mend a font direction in ST7781 portrait unside down mode. 2015-11-20 21:54:34 -08:00
Serge Vakulenko
7c2aa43862 Fix bug in ST7781 driver. Set landscape mode by default. 2015-11-20 21:43:27 -08:00
Serge Vakulenko
8988b8b013 Reuse ili9341 routines for nt35702 display. 2015-11-19 22:10:52 -08:00
Serge Vakulenko
d2940a8719 Fix screen orientation in the ILI9341 LCD driver. 2015-11-19 19:55:07 -08:00
Serge Vakulenko
be1726a662 Draw a BSD logo on the LCD display at start. 2015-11-19 19:04:23 -08:00
Serge Vakulenko
2fd36d9175 Update ILI9341 LCD driver. 2015-11-17 19:25:39 -08:00
Serge Vakulenko
6f0a48330c LCD driver: add support for Samsung S6D04H0 (not finished yet). 2015-11-16 22:15:40 -08:00
Serge Vakulenko
4dd9308e25 Merge branch 'master' of https://github.com/RetroBSD/retrobsd 2015-11-15 14:15:13 -08:00
Serge Vakulenko
98f3efcb70 Increase the max number of processes (NPROC) from 10 to 25. 2015-11-15 14:14:18 -08:00
Serge Vakulenko
2e716e099c LCD driver: fix garbage when a glyph extends off screen. 2015-11-15 13:39:08 -08:00
Serge Vakulenko
03ed62db5d Libm: add 32-bit variant of fmod() function. 2015-11-06 20:40:45 -08:00
Serge Vakulenko
c46bd3c1e9 Enable optimization by size (-Os) by default for all user binaries. 2015-11-03 22:03:52 -08:00
Serge Vakulenko
a673c028f8 Add ubw32 board to the autobuild list. 2015-11-03 21:37:50 -08:00
Serge Vakulenko
7ddf7686a3 Enable mips16e instruction set for all user binaries. 2015-11-03 21:36:31 -08:00
Serge Vakulenko
abcfb06b0b Merge gpanel branch. 2015-10-31 21:12:50 -07:00
Serge Vakulenko
e00196ee21 Merge branch 'master' into gpanel-driver 2015-10-31 21:11:38 -07:00
Serge Vakulenko
5b04c6b168 Add driver for ILI9341 display controller. 2015-10-31 21:09:44 -07:00
Serge Vakulenko
7f69510488 Gpanel driver: use gamma values from NT35702 datasheet. 2015-10-31 19:58:41 -07:00
Serge Vakulenko
058b6c4de0 Add support for NT35702 display controller. 2015-10-31 19:25:26 -07:00
Serge Vakulenko
1e4005cc4b Split the gpanel driver into chip-specific and generic parts. 2015-10-31 14:57:45 -07:00
Serge Vakulenko
66a7727085 Rename swtft -> gpanel. 2015-10-31 13:26:27 -07:00
Serge Vakulenko
2bfd3df2a6 Merge pull request #65 from alexfru/master
virtualmips: improve MIPS16e: save/restore, sdbbp
2015-10-31 00:52:49 -07:00
Alexey Frunze
162f0d34b5 virtualmips: improve MIPS16e: save/restore, sdbbp 2015-10-31 00:45:15 -07:00
652 changed files with 32592 additions and 16803 deletions

1
.gitignore vendored
View File

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

View File

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

View File

@@ -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.

View File

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

View File

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

View File

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

2
include/inttypes.h Normal file
View File

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

View File

@@ -4,16 +4,16 @@
* specifies the terms and conditions for redistribution.
*/
double fabs(), floor(), ceil(), fmod(), ldexp();
double sqrt(), hypot(), atof();
double sin(), cos(), tan(), asin(), acos(), atan(), atan2();
double exp(), log(), log10(), pow();
double sinh(), cosh(), tanh();
double gamma();
double j0(), j1(), jn(), y0(), y1(), yn();
double fabs(double), floor(double), ceil(double);
double sqrt(double), hypot(double, double);
double sin(double), cos(double), tan(double);
double asin(double), acos(double), atan(double), atan2(double, double);
double exp(double), log(double), log10(double), pow(double, double);
double sinh(double), cosh(double), tanh(double);
double j0(double), j1(double), jn(int, double);
double y0(double), y1(double), yn(int, double);
#define HUGE 1.701411733192644270e38
#define LOGHUGE 39
#define HUGE_VAL 3.40282347e+38 /* TBD??? use infinity? */
int isnanf(float x);
int isnan(double x);

7
include/regex.h Normal file
View File

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

37
include/stdbool.h Normal file
View File

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

View File

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

View File

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

View File

@@ -57,51 +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);
#ifndef __SMALLER_C__
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
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_ */

View File

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

View File

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

View File

@@ -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

View File

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

View File

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

View File

@@ -2,7 +2,7 @@ TOPSRC = $(shell cd ..; pwd)
SUBDIR = startup libc libm libcurses libtermlib libwiznet libreadline libgpanel
PROG = ar as aout ld nm ranlib size strip
CFLAGS += -std=gnu89 -fno-builtin -g -Werror -Wall -DCROSS -I. \
CFLAGS = -Os -std=gnu89 -fno-builtin -g -Werror -Wall -DCROSS -I. \
-idirafter $(TOPSRC)/include \
-idirafter $(TOPSRC)/src/cmd/ar \
-idirafter $(TOPSRC)/src/cmd/as

View File

@@ -8,7 +8,7 @@ vpath %.c $(LIBCDIR)/mips/sys $(LIBCDIR)/gen $(LIBCDIR)/stdio \
$(LIBCDIR)/stdlib $(LIBCDIR)/string $(LIBCDIR)/inet \
$(LIBCDIR)/compat $(LIBCDIR)/runtime
CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
CFLAGS = -Os -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
ASFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -I$(LIBCDIR)/mips/sys
# modules which can not use SYSCALL and must be assembled from sources. The
@@ -95,7 +95,8 @@ OBJS += creat.o ftime.o gethostid.o memccpy.o memchr.o \
# libc/runtime
OBJS += addsf3.o comparesf2.o divsf3.o fixsfsi.o floatsisf.o \
mulsf3.o negsf2.o subsf3.o sc_case.o
mulsf3.o negsf2.o subsf3.o sc_case.o fixunssfsi.o \
floatunsisf.o
all: ../libc.a

View File

@@ -3,7 +3,7 @@ include $(TOPSRC)/target.mk
vpath %.c $(TOPSRC)/src/libcurses
CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
CFLAGS = -Os -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
OBJS = addch.o addstr.o box.o clear.o clrtobot.o clrtoeol.o cr_put.o \
cr_tty.o curses.o delch.o deleteln.o delwin.o endwin.o erase.o \

View File

@@ -3,10 +3,10 @@ include $(TOPSRC)/target.mk
vpath %.c $(TOPSRC)/src/libgpanel
CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
CFLAGS = -Os -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
OBJS = open.o clear.o pixel.o line.o rect.o fill.o circle.o \
image.o char.o text.o text_width.o
OBJS = open.o clear.o pixel.o line.o rect.o fill.o fill_triangle.o \
circle.o image.o char.o text.o text_width.o
all: ../libgpanel.a

View File

@@ -3,7 +3,7 @@ include $(TOPSRC)/target.mk
vpath %.c $(TOPSRC)/src/libm
CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
CFLAGS = -Os -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
OBJS = asin.o atan.o exp.o erf.o floor.o fmod.o hypot.o j0.o j1.o \
jn.o log.o pow.o sin.o sinh.o sqrt.o tan.o tanh.o

View File

@@ -3,7 +3,7 @@ include $(TOPSRC)/target.mk
vpath %.c $(TOPSRC)/src/libreadline
CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
CFLAGS = -Os -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
OBJS = readline.o

View File

@@ -3,7 +3,7 @@ include $(TOPSRC)/target.mk
vpath %.c $(TOPSRC)/src/libtermlib
CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
CFLAGS = -Os -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
OBJS = termcap.o tgoto.o tputs.o tcattr.o

View File

@@ -3,7 +3,7 @@ include $(TOPSRC)/target.mk
vpath %.c $(TOPSRC)/src/libwiznet
CFLAGS += -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
CFLAGS = -Os -B$(TOPSRC)/lib/ $(DEFS) -Wa,-x -Wall -Werror
OBJS = w5100.o socket.o ethernet.o client.o server.o udp.o

View File

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

View File

@@ -605,6 +605,7 @@ file /bin/whoami
file /bin/write
mode 02755
file /bin/xargs
file /bin/yacc
file /bin/zcat
link /bin/[
@@ -671,6 +672,7 @@ default
filemode 0775
dir /games
file /games/adventure
file /games/aclock
file /games/arithmetic
file /games/atc
file /games/backgammon
@@ -1116,6 +1118,7 @@ file /share/examples/gpanel/Makefile
file /share/examples/gpanel/circle.c
file /share/examples/gpanel/color.c
file /share/examples/gpanel/fill.c
file /share/examples/gpanel/flappy.c
file /share/examples/gpanel/font.c
file /share/examples/gpanel/line.c
file /share/examples/gpanel/pixel.c
@@ -1129,6 +1132,7 @@ file /share/examples/gpanel/fonts/digits20.c
file /share/examples/gpanel/fonts/digits32.c
file /share/examples/gpanel/fonts/lucidasans11.c
file /share/examples/gpanel/fonts/lucidasans15.c
file /share/examples/gpanel/fonts/lucidasans28.c
file /share/examples/gpanel/fonts/lucidasans7.c
file /share/examples/gpanel/fonts/lucidasans9.c
file /share/examples/gpanel/fonts/verdana7.c

View File

@@ -1,9 +1,9 @@
CC = cc
LIBS = -lgpanel
PROG = tft tftetris pixel line rect fill circle font color speed
PROG = tft tftetris pixel line rect fill circle font color speed flappy
FONTS = 5x7.o 6x9.o digits20.o digits32.o lucidasans11.o lucidasans15.o \
lucidasans7.o lucidasans9.o verdana7.o
lucidasans28.o lucidasans7.o lucidasans9.o verdana7.o
all: $(PROG)
@@ -37,6 +37,9 @@ color: color.c
speed: speed.c lucidasans15.o
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) speed.c lucidasans15.o $(LIBS)
flappy: flappy.c lucidasans15.o lucidasans28.o
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) flappy.c lucidasans15.o lucidasans28.o $(LIBS)
font: font.c $(FONTS)
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) font.c $(FONTS) $(LIBS)
@@ -58,6 +61,9 @@ lucidasans11.o: fonts/lucidasans11.c
lucidasans15.o: fonts/lucidasans15.c
$(CC) $(CFLAGS) -o $@ -c $?
lucidasans28.o: fonts/lucidasans28.c
$(CC) $(CFLAGS) -o $@ -c $?
lucidasans7.o: fonts/lucidasans7.c
$(CC) $(CFLAGS) -o $@ -c $?

View File

@@ -0,0 +1,439 @@
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sgtty.h>
#include <sys/time.h>
#include <sys/gpanel.h>
/*
* Assign human-readable names to some common 16-bit color values:
*/
#define BLACK 0x0000
#define BLUE 0x002F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
/*
* Redraw every 50 msec
*/
#define DRAW_LOOP_INTERVAL 50
/*
* File name for saving the high score.
*/
#define SCORE_FILENAME "flappy.score"
/*
* Data from external font files.
*/
extern const struct gpanel_font_t font_lucidasans15;
extern const struct gpanel_font_t font_lucidasans28;
int wing;
int fx, fy, fall_rate;
int pillar_pos, gap_pos;
int score;
int high_score = 0;
int running = 0;
int crashed = 0;
int scr_press = 0;
time_t next_draw_time;
void rect(int color, int x, int y, int w, int h)
{
gpanel_rect(color, x, y, x+w-1, y+h-1);
}
void fill(int color, int x, int y, int w, int h)
{
gpanel_fill(color, x, y, x+w-1, y+h-1);
}
void draw_pillar(int x, int gap)
{
if (x >= 320)
return;
fill(GREEN, x+2, 2, 46, gap-4);
fill(GREEN, x+2, gap+92, 46, 136-gap);
rect(BLACK, x, 0, 50, gap);
rect(BLACK, x+1, 1, 48, gap-2);
rect(BLACK, x, gap+90, 50, 140-gap);
rect(BLACK, x+1, gap+91, 48, 138-gap);
}
void clear_pillar(int x, int gap)
{
if (x >= 320)
return;
/* "Cheat" slightly and just clear the right hand pixels
* to help minimise flicker, the rest will be overdrawn. */
fill(BLUE, x+45, 0, 5, gap);
fill(BLUE, x+45, gap+90, 5, 140-gap);
}
void clear_flappy(int x, int y)
{
fill(BLUE, x, y, 34, 24);
}
void draw_flappy(int x, int y)
{
/* Upper & lower body */
fill(BLACK, x+2, y+8, 2, 10);
fill(BLACK, x+4, y+6, 2, 2);
fill(BLACK, x+6, y+4, 2, 2);
fill(BLACK, x+8, y+2, 4, 2);
fill(BLACK, x+12, y, 12, 2);
fill(BLACK, x+24, y+2, 2, 2);
fill(BLACK, x+26, y+4, 2, 2);
fill(BLACK, x+28, y+6, 2, 6);
fill(BLACK, x+10, y+22, 10, 2);
fill(BLACK, x+4, y+18, 2, 2);
fill(BLACK, x+6, y+20, 4, 2);
/* Body fill */
fill(YELLOW, x+12, y+2, 6, 2);
fill(YELLOW, x+8, y+4, 8, 2);
fill(YELLOW, x+6, y+6, 10, 2);
fill(YELLOW, x+4, y+8, 12, 2);
fill(YELLOW, x+4, y+10, 14, 2);
fill(YELLOW, x+4, y+12, 16, 2);
fill(YELLOW, x+4, y+14, 14, 2);
fill(YELLOW, x+4, y+16, 12, 2);
fill(YELLOW, x+6, y+18, 12, 2);
fill(YELLOW, x+10, y+20, 10, 2);
/* Eye */
fill(BLACK, x+18, y+2, 2, 2);
fill(BLACK, x+16, y+4, 2, 6);
fill(BLACK, x+18, y+10, 2, 2);
fill(WHITE, x+18, y+4, 2, 6);
fill(WHITE, x+20, y+2, 4, 10);
fill(WHITE, x+24, y+4, 2, 8);
fill(WHITE, x+26, y+6, 2, 6);
fill(BLACK, x+24, y+6, 2, 4);
/* Beak */
fill(BLACK, x+20, y+12, 12, 2);
fill(BLACK, x+18, y+14, 2, 2);
fill(RED, x+20, y+14, 12, 2);
fill(BLACK, x+32, y+14, 2, 2);
fill(BLACK, x+16, y+16, 2, 2);
fill(RED, x+18, y+16, 2, 2);
fill(BLACK, x+20, y+16, 12, 2);
fill(BLACK, x+18, y+18, 2, 2);
fill(RED, x+20, y+18, 10, 2);
fill(BLACK, x+30, y+18, 2, 2);
fill(BLACK, x+20, y+20, 10, 2);
}
/*
* Wing down.
*/
void draw_wing1(int x, int y)
{
fill(BLACK, x, y+14, 2, 6);
fill(BLACK, x+2, y+20, 8, 2);
fill(BLACK, x+2, y+12, 10, 2);
fill(BLACK, x+12, y+14, 2, 2);
fill(BLACK, x+10, y+16, 2, 2);
fill(WHITE, x+2, y+14, 8, 6);
fill(BLACK, x+8, y+18, 2, 2);
fill(WHITE, x+10, y+14, 2, 2);
}
/*
* Wing middle.
*/
void draw_wing2(int x, int y)
{
fill(BLACK, x+2, y+10, 10, 2);
fill(BLACK, x+2, y+16, 10, 2);
fill(BLACK, x, y+12, 2, 4);
fill(BLACK, x+12, y+12, 2, 4);
fill(WHITE, x+2, y+12, 10, 4);
}
/*
* Wing up.
*/
void draw_wing3(int x, int y)
{
fill(BLACK, x+2, y+6, 8, 2);
fill(BLACK, x, y+8, 2, 6);
fill(BLACK, x+10, y+8, 2, 2);
fill(BLACK, x+12, y+10, 2, 4);
fill(BLACK, x+10, y+14, 2, 2);
fill(BLACK, x+2, y+14, 2, 2);
fill(BLACK, x+4, y+16, 6, 2);
fill(WHITE, x+2, y+8, 8, 6);
fill(WHITE, x+4, y+14, 6, 2);
fill(WHITE, x+10, y+10, 2, 4);
}
time_t millis()
{
struct timeval tv;
gettimeofday(&tv, 0);
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
void start_game()
{
fx = 50;
fy = 125;
fall_rate = -1;
pillar_pos = 320;
gap_pos = 60;
crashed = 0;
score = 0;
gpanel_clear(BLUE, 0, 0);
gpanel_text(&font_lucidasans28, WHITE, BLUE, 10, 10,
"Flappy Bird");
gpanel_text(&font_lucidasans15, WHITE, BLUE, 50, 180,
"(Press Space to start)");
char score_line[80];
sprintf(score_line, "High Score: %u", high_score);
gpanel_text(&font_lucidasans28, GREEN, BLUE, 10, 60, score_line);
/* Draw ground. */
int tx, ty = 230;
for (tx = 0; tx <= 300; tx += 20) {
gpanel_fill_triangle(GREEN, tx, ty, tx+9, ty, tx, ty+9);
gpanel_fill_triangle(YELLOW, tx+9, ty+9, tx+9, ty, tx, ty+9);
gpanel_fill_triangle(YELLOW, tx+10, ty, tx+19, ty, tx+10, ty+9);
gpanel_fill_triangle(GREEN, tx+19, ty+9, tx+19, ty, tx+10, ty+9);
}
next_draw_time = millis() + DRAW_LOOP_INTERVAL;
}
void draw_loop()
{
/* Clear moving items. */
clear_pillar(pillar_pos, gap_pos);
/* Move items. */
if (running) {
clear_flappy(fx, fy);
fy += fall_rate;
fall_rate++;
pillar_pos -= 5;
if (pillar_pos == 0) {
score++;
}
else if (pillar_pos < -50) {
pillar_pos = 320;
gap_pos = 20 + random() % 100;
}
}
/* Draw moving items & animate. */
draw_flappy(fx, fy);
draw_pillar(pillar_pos, gap_pos);
switch (wing) {
case 0:
case 1:
draw_wing1(fx, fy);
break;
case 2:
case 3:
draw_wing2(fx, fy);
break;
case 4:
case 5:
draw_wing3(fx, fy);
break;
}
wing++;
if (wing == 6)
wing = 0;
}
/*
* Write high score value to file.
*/
void save_score()
{
int fd, nbytes;
char line[80];
fd = open(SCORE_FILENAME, O_WRONLY | O_CREAT, 0644);
if (fd < 0) {
perror(SCORE_FILENAME);
return;
}
sprintf(line, "%u\n", high_score);
nbytes = strlen(line);
if (write(fd, line, nbytes) != nbytes)
perror(SCORE_FILENAME);
close(fd);
}
/*
* Read high score value from file.
*/
void load_score()
{
int fd, nbytes;
char line[80];
fd = open(SCORE_FILENAME, O_RDONLY);
if (fd < 0) {
/* No high score file yet. */
return;
}
nbytes = read(fd, line, sizeof(line));
if (nbytes <= 0) {
if (nbytes < 0)
perror(SCORE_FILENAME);
return;
}
close(fd);
high_score = strtol(line, 0, 0);
}
void check_collision()
{
/* Collision with ground. */
if (fy > 206)
crashed = 1;
/* Collision with pillar. */
if (fx + 34 > pillar_pos && fx < pillar_pos + 50)
if (fy < gap_pos || fy + 24 > gap_pos + 90)
crashed = 1;
if (crashed) {
gpanel_text(&font_lucidasans28, RED, BLUE, 50, 50, "Game Over!");
char score_line[80];
sprintf(score_line, "Score: %u", score);
gpanel_text(&font_lucidasans28, RED, BLUE, 50, 100, score_line);
if (score > high_score) {
high_score = score;
gpanel_text(&font_lucidasans28, RED, BLUE, 50, 150, "NEW HIGH!");
save_score();
}
/* Stop animation. */
running = 0;
/* Delay to stop any last minute clicks from restarting immediately. */
sleep(1);
}
}
#if 1
#ifndef SDL
struct sgttyb origtty, newtty;
#endif
/*
* Terminate the game when ^C pressed.
*/
void quit(int sig)
{
signal(SIGINT, SIG_IGN);
#ifndef SDL
if (newtty.sg_flags != 0)
ioctl(0, TIOCSETP, &origtty);
#endif
gpanel_close();
exit(0);
}
/*
* Return 1 when any key is pressed on console.
*/
int get_input()
{
#ifdef SDL
extern int gpanel_input(void);
return gpanel_input();
#else
if (newtty.sg_flags == 0) {
ioctl(0, TIOCGETP, &origtty);
newtty = origtty;
newtty.sg_flags &= ~(ECHO|XTABS);
newtty.sg_flags |= CBREAK;
ioctl(0, TIOCSETP, &newtty);
}
int nchars = 0;
ioctl(0, FIONREAD, &nchars);
if (nchars <= 0)
return 0;
char c;
read(0, &c, 1);
return 1;
#endif
}
#endif
int main()
{
char *devname = "/dev/tft0";
int xsize = 320, ysize = 240;
signal(SIGINT, quit);
if (gpanel_open(devname) < 0) {
printf("Cannot open %s\n", devname);
exit(-1);
}
gpanel_clear(BLUE, &xsize, &ysize);
load_score();
start_game();
for (;;) {
if (millis() > next_draw_time && !crashed) {
draw_loop();
check_collision();
next_draw_time += DRAW_LOOP_INTERVAL;
}
usleep(10000);
/* Get user input. */
int user_input = get_input();
/* Process "user input". */
if (user_input > 0 && !scr_press) {
if (crashed) {
/* Restart game. */
start_game();
}
else if (!running) {
/* Clear text & start scrolling. */
gpanel_fill(BLUE, 0, 0, 320-1, 100);
gpanel_fill(BLUE, 0, 180, 320-1, 205);
running = 1;
} else {
/* Fly up. */
fall_rate = -8;
scr_press = 1;
}
} else if (user_input == 0 && scr_press) {
/* Attempt to throttle presses. */
scr_press = 0;
}
}
}

View File

@@ -1,5 +1,5 @@
CFLAGS = -Wall -O -g
LDFLAGS = -lpng
LDFLAGS = -L/opt/local/lib -lpng
FONTS = digits32.c \
digits20.c \
@@ -47,6 +47,11 @@ lucidasans15.c: convbdf ttf/Lucida_Sans_Unicode.ttf
./convbdf -u164 -a5 -d5 lucidasans15.bdf
rm -f lucidasans15.bdf
lucidasans28.c: convbdf ttf/Lucida_Sans_Unicode.ttf
-otf2bdf -p 28 -l "$(CHARSET)" ttf/Lucida_Sans_Unicode.ttf > lucidasans28.bdf
./convbdf -u164 -a11 -d9 lucidasans28.bdf
rm -f lucidasans28.bdf
lucidasans9.c: convbdf ttf/Lucida_Sans_Unicode.ttf
-otf2bdf -p 9 -l "$(CHARSET)" ttf/Lucida_Sans_Unicode.ttf > lucidasans9.bdf
./convbdf -u164 -a2 -d3 lucidasans9.bdf

File diff suppressed because it is too large Load Diff

View File

@@ -16,15 +16,15 @@ SUBDIR = adb adc-demo aout ar as awk basic calendar cc chflags \
man md5 med more nm passwd pdc picoc portio printf pwm \
ranlib re renice retroforth scm sed setty sh sl smallc \
smlrc smux stty sysctl test uname wiznet xargs \
zmodem gtest msec unixbench cron compress date2 tip \
talloc uucp
zmodem gtest msec cron compress date2 tip \
talloc uucp yacc
# /sbin
SUBDIR += chown chroot disktool fsck getty init \
mkfs mknod mkpasswd mount pstat \
reboot shutdown umount update vipw virus
# TODO: ccom lex m4 yacc reloc sre pforth
# TODO: ccom lex m4 reloc sre pforth
# Shell scripts that need only be installed and are never removed.
#
@@ -73,7 +73,8 @@ FRC:
# $(STD) $(SETUID) $(KMEM) $(OPERATOR) $(TTY) strip
%: %.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@.elf $< $(LIBS)
$(CC) $(CFLAGS) -c $<
$(LD) $(LDFLAGS) -o $@.elf $@.o $(LIBS)
$(OBJDUMP) -S $@.elf > $@.dis
$(SIZE) $@.elf
$(ELF2AOUT) $@.elf $@ && /bin/rm $@.elf

View File

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

View File

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

View File

@@ -91,6 +91,7 @@ exform(fcount, ifp, itype, ptype)
struct {
long sa;
int sb, sc;
double sd; /* assume double = float = 32 bits */
} fw;
while (fcount > 0) {
@@ -225,18 +226,20 @@ exform(fcount, ifp, itype, ptype)
break;
case 'f':
*(double *)&fw = 0.0;
case 'F':
fw.sd = 0.0;
fw.sa = wx;
print("%-16.9f", *(double *)&fw);
print("%-16.9f", fw.sd);
dotinc = 4;
break;
#if 0
/* 64-bit double not supported */
case 'F':
fw.sa = wx;
print("%-32.18F", *(double *)&fw);
dotinc = 8;
break;
#endif
case 'n': case 'N':
printc('\n');
dotinc = 0;

View File

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

View File

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

View File

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

View File

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

View File

@@ -38,6 +38,7 @@
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <time.h>
# include <errno.h>
# include <getopt.h>
#else

View File

@@ -97,7 +97,7 @@ typedef struct {
/* Header structure internal format. */
typedef struct {
off_t size; /* size of the object in bytes */
long date; /* date */
time_t date; /* date */
int lname; /* size of the long name in bytes */
int gid; /* group */
int uid; /* owner */

View File

@@ -91,7 +91,8 @@ delete(argv)
SETCF(tfd, tname, afd, archive, NOPAD);
copy_ar(&cf, size);
(void)close(tfd);
(void)ftruncate(afd, size + SARMAG);
if (ftruncate(afd, size + SARMAG) < 0)
/* ignore */;
close_archive(afd);
if (*argv) {

View File

@@ -136,7 +136,8 @@ move(argv)
cf.rfd = tfd3;
copy_ar(&cf, size);
(void)ftruncate(afd, tsize + SARMAG);
if (ftruncate(afd, tsize + SARMAG) < 0)
/* ignore */;
close_archive(afd);
if (*argv) {

View File

@@ -190,7 +190,8 @@ append: while ((file = *argv++) != 0) {
cf.rfd = tfd2;
copy_ar(&cf, size);
(void)ftruncate(afd, tsize + SARMAG);
if (ftruncate(afd, tsize + SARMAG) < 0)
/* ignore */;
close_archive(afd);
return(err);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "awk.def.h"
#include "awk.h"
@@ -13,12 +14,12 @@ int svargc;
char **svargv, **xargv;
extern FILE *yyin; /* lex input file */
char *lexprog; /* points to program argument if it exists */
extern errorflag; /* non-zero if any syntax errors; set by yyerror */
int filefd, symnum, ansfd;
char *filelist;
extern int maxsym, errno;
extern int maxsym;
int
main(argc, argv)
int argc;
char *argv[];
@@ -29,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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -15,7 +15,6 @@
* only. IE: A is equivalent to A0 ... Z$ is equivalent to Z0$
*
* Statements:
* BEEP freq,ms - Generate a BEEP on the PC speaker
* CLEAR - Erase variables only
* CLOSE#n - Close file (0-9) opened with OPEN
* DATA - Enter "inline" data statements
@@ -155,7 +154,7 @@
#define SAVE 25
#define LOAD 26
#define DELAY 27
#define BEEP 28
//#define BEEP 28
#define DOS 29
#define OUT 30
@@ -279,11 +278,6 @@ int eval_sub(void);
WINDOW *win;
void beep (int i, int t)
{
printf("BEEP not implemented yet, at line %u\n", line);
}
void delay (int msec)
{
usleep (msec * 1000);
@@ -1371,11 +1365,6 @@ input: if (ii == -1)
case SRND:
srandom(eval_num());
break;
case BEEP:
i = eval_num();
expect(',');
beep(i, eval_num());
break;
case DOS:
eval_char();
fflush(stdout);

View File

@@ -1,5 +1,8 @@
%{
int *getout();
int *getout(void);
int getch(void);
int cpeek(int c, int yes, int no);
void yyerror(char *s);
%}
%right '='
%left '+' '-'
@@ -39,12 +42,12 @@ int *pre, *post;
%%
start :
| start stat tail
= output( $2 );
= output( (int*) $2 );
| start def dargs ')' '{' dlist slist '}'
={ bundle( 6,pre, $7, post ,"0",numb[lev],"Q");
conout( $$, $2 );
={ 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];

View File

@@ -11,11 +11,15 @@ char *smon[]= {
};
char string[432];
main(argc, argv)
static int number(char *str);
static void cal(int m, int y, char *p, int w);
static void pstr(char *str, int n);
static int jan1(int yr);
int main(argc, argv)
char *argv[];
{
register y, i, j;
int m;
int y, i, j, m;
if(argc < 2) {
printf("usage: cal [month] year\n");
@@ -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;
}

View File

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

View File

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

View File

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

View File

@@ -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':

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -9,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 '?':

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

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

View File

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

View File

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

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

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

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

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

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

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

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

@@ -15,15 +15,9 @@
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
*/
#if !defined(lint) && !defined(LINT)
static char rcsid[] = "$Id: compat.c,v 1.6 1994/01/15 20:43:43 vixie Exp $";
#endif
/* vix 30dec93 [broke this out of misc.c - see RCS log for history]
* vix 15jan87 [added TIOCNOTTY, thanks csg@pyramid]
*/
#include "cron.h"
#include <stdio.h>
@@ -40,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
View File

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

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

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

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

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

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

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