more work on gen/

This commit is contained in:
Oliver Lehmann 2009-08-26 20:19:50 +00:00
parent df136b4173
commit 803bdadd85
53 changed files with 2538 additions and 50 deletions

View File

@ -1,16 +1,8 @@
__callex.o __callex.c C
a64l.o a64l.c C
abs.o abs.c C
atof.o atof.s ASM
atoi.o atoi.c C
atol.o atol.c C
bsearch.o bsearch.c C
clrerr.o clrerr.c C
cnvt.o cnvt.c C
crypt.o crypt.c C
ctermid.o ctermid.c C
ctime.o ctime.c C
ctype_.o ctype_.c C
cuserid.o cuserid.c C
data.o data.c C
decimal.o decimal.s ASM
@ -18,8 +10,6 @@ doprnt.o doprnt.c C
doscan.o doscan.c C
ecvt.o ecvt.s ASM
endopen.o endopen.c C
errlst.o errlst.c C
execvp.o execvp.c C
fdopen.o fdopen.c C
ffltioc.o ffltioc.c C
fgetc.o fgetc.c C
@ -35,41 +25,19 @@ freopen.o freopen.c C
fseek.o fseek.c C
ftell.o ftell.c C
getchar.o getchar.c C
getenv.o getenv.c C
getgrent.o getgrent.c C
getgrgid.o getgrgid.c C
getgrnam.o getgrnam.c C
getlogin.o getlogin.c C
getopt.o getopt.c C
getpass.o getpass.c C
getpw.o getpw.c C
getpwent.o getpwent.c C
getpwnam.o getpwnam.c C
getpwuid.o getpwuid.c C
gets.o gets.c C
getw.o getw.c C
goodmagic.o goodmagic.c C
index.o index.c C
isatty.o isatty.c C
l3.o l3.c C
l64a.o l64a.c C
length.o length.c C
lsearch.o lsearch.c C
malloc.o malloc.c C
mktemp.o mktemp.c C
mon.o mon.c C
mpx.o mpx.c C
nlist.o nlist.c C
perror.o perror.c C
popen.o popen.c C
pow10.o pow10.s ASM
printf.o printf.c C
putchar.o putchar.c C
putpwent.o putpwent.c C
puts.o puts.c C
putw.o putw.c C
qsort.o qsort.c C
rand.o rand.c C
rdwr.o rdwr.c C
readsym.o readsym.c C
rew.o rew.c C
@ -77,24 +45,8 @@ rindex.o rindex.c C
scanf.o scanf.c C
setbuf.o setbuf.c C
setret.o setret.s ASM
sleep.o sleep.c C
ssignal.o ssignal.c C
stfl.o ???
strcat.o strcat.c C
strchr.o strchr.c C
strcmp.o strcmp.c C
strcpy.o strcpy.c C
strcspn.o strcspn.c C
strlen.o strlen.c C
strncat.o strncat.c C
strncmp.o strncmp.c C
strncpy.o strncpy.c C
strout.o strout.c C
strpbrk.o strpbrk.c C
strrchr.o strrchr.c C
strspn.o strspn.c C
strtok.o strtok.c C
swab.o swab.c C
swap.o swap.c C
symscan.o symscan.c C
system.o system.c C
@ -102,6 +54,4 @@ tmpfile.o tmpfile.c C
tmpnam.o tmpnam.c C
tolower.o tolower.c C
toupper.o toupper.c C
ttyname.o ttyname.c C
ttyslot.o ttyslot.c C
ungetc.o ungetc.c C

View File

@ -71,3 +71,53 @@ cerror.o cerror.s ASM
cuexit.o cuexit.s ASM
fakcu.o fakcu.s ASM
mcount.o mcount.s ASM
a64l.o a64l.c C
abs.o abs.c C
atoi.o atoi.c C
atol.o atol.c C
bsearch.o bsearch.c C
crypt.o crypt.c C
ctime.o ctime.c C
ctype_.o ctype_.c C
errlst.o errlst.c C
execvp.o execvp.c C
getenv.o getenv.c C
getgrent.o getgrent.c C
getgrgid.o getgrgid.c C
getgrnam.o getgrnam.c C
getlogin.o getlogin.c C
getopt.o getopt.c C
getpw.o getpw.c C
getpwent.o getpwent.c C
getpwnam.o getpwnam.c C
getpwuid.o getpwuid.c C
isatty.o isatty.c C
l3.o l3.c C
l64a.o l64a.c C
lsearch.o lsearch.c C
malloc.o malloc.c C
mktemp.o mktemp.c C
mon.o mon.c C
nlist.o nlist.c C
perror.o perror.c C
putpwent.o putpwent.c C
qsort.o qsort.c C
rand.o rand.c C
sleep.o sleep.c C
ssignal.o ssignal.c C
strcat.o strcat.c C
strchr.o strchr.c C
strcmp.o strcmp.c C
strcpy.o strcpy.c C
strcspn.o strcspn.c C
strlen.o strlen.c C
strncat.o strncat.c C
strncmp.o strncmp.c C
strncpy.o strncpy.c C
strpbrk.o strpbrk.c C
strrchr.o strrchr.c C
strspn.o strspn.c C
strtok.o strtok.c C
swab.o swab.c C
ttyname.o ttyname.c C
ttyslot.o ttyslot.c C

View File

@ -0,0 +1,11 @@
ctime.o /z/src/libc/orig_obj/ctime.o differ: char 6, line 1
errlst.o /z/src/libc/orig_obj/errlst.o differ: char 5, line 1
execvp.o /z/src/libc/orig_obj/execvp.o differ: char 6, line 1
getgrent.o /z/src/libc/orig_obj/getgrent.o differ: char 132, line 1
l3.o /z/src/libc/orig_obj/l3.o differ: char 6, line 1
malloc.o /z/src/libc/orig_obj/malloc.o differ: char 5, line 1
nlist.o /z/src/libc/orig_obj/nlist.o differ: char 5, line 1
perror.o /z/src/libc/orig_obj/perror.o differ: char 6, line 1
qsort.o /z/src/libc/orig_obj/qsort.o differ: char 5, line 1
ttyname.o /z/src/libc/orig_obj/ttyname.o differ: char 5, line 1

View File

@ -0,0 +1,26 @@
/* @[$] a64l.c 2.1 09/12/83 11:18:54 - 87wega3.2. */
/*
* convert base 64 ascii to long int
* char set is [./0-9A-Za-z]
*/
long
a64l(s)
register char *s;
{
register i, c;
long l;
i = 0;
l = 0;
while ((c = *s++) != '\0') {
if (c >= 'a')
c -= 'a'-'Z'-1;
if (c >= 'A')
c -= 'A'-'9'-1;
l |= (long)(c - '.') << i;
i += 6;
}
return l;
}

View File

@ -0,0 +1,10 @@
/* @[$] abs.c 2.1 09/12/83 11:19:20 - 87wega3.2 */
int
abs(arg)
int arg;
{
if(arg < 0)
arg = -arg;
return(arg);
}

View File

@ -0,0 +1,26 @@
/* @[$] atoi.c 2.1 09/12/83 11:19:46 - 87wega3.2 */
atoi(p)
register char *p;
{
register int n;
register int f;
n = 0;
f = 0;
for(;;p++) {
switch(*p) {
case ' ':
case '\t':
continue;
case '-':
f++;
case '+':
p++;
}
break;
}
while(*p >= '0' && *p <= '9')
n = n*10 + *p++ - '0';
return(f? -n: n);
}

View File

@ -0,0 +1,27 @@
/* @[$] atol.c 2.1 09/12/83 11:20:00 - 87wega3.2 */
long
atol(p)
register char *p;
{
long n;
register int f;
n = 0;
f = 0;
for(;;p++) {
switch(*p) {
case ' ':
case '\t':
continue;
case '-':
f++;
case '+':
p++;
}
break;
}
while(*p >= '0' && *p <= '9')
n = n*10 + *p++ - '0';
return(f? -n: n);
}

View File

@ -0,0 +1,34 @@
/* @[$] bsearch.c 2.1 09/12/83 11:20:18 - 87wega3.2 */
/*
* Binary search algorithm, generalized from Knuth (6.2.1) Algorithm B.
*/
typedef char *POINTER;
POINTER
bsearch(key, base, nel, width, compar)
POINTER key; /* Key to be located */
POINTER base; /* Beginning of table */
int nel; /* Number of elements in the table */
int width; /* Width of an element */
int (*compar)(); /* Comparison function */
{
POINTER u = base+(nel-1)*width; /* Last element in table */
POINTER l = base; /* First element in table */
POINTER i; /* Approximate middle element of table*/
int res; /* Result of comparison */
while(u >= l) {
i = l+width*((nel-1)/2);
res = (*compar)(key, i);
if(res == 0)
return(i);
else if(res < 0)
u = i-width;
else
l = i+width;
nel = 1+(u-l)/width;
}
return(0);
}

View File

@ -0,0 +1,382 @@
/* @[$] crypt.c 2.1 09/12/83 11:20:53 - 87wega3.2 */
/*
* This program implements the
* Proposed Federal Information Processing
* Data Encryption Standard.
* See Federal Register, March 17, 1975 (40FR12134)
*/
/*
* Initial permutation,
*/
static char IP[] = {
58,50,42,34,26,18,10, 2,
60,52,44,36,28,20,12, 4,
62,54,46,38,30,22,14, 6,
64,56,48,40,32,24,16, 8,
57,49,41,33,25,17, 9, 1,
59,51,43,35,27,19,11, 3,
61,53,45,37,29,21,13, 5,
63,55,47,39,31,23,15, 7,
};
/*
* Final permutation, FP = IP^(-1)
*/
static char FP[] = {
40, 8,48,16,56,24,64,32,
39, 7,47,15,55,23,63,31,
38, 6,46,14,54,22,62,30,
37, 5,45,13,53,21,61,29,
36, 4,44,12,52,20,60,28,
35, 3,43,11,51,19,59,27,
34, 2,42,10,50,18,58,26,
33, 1,41, 9,49,17,57,25,
};
/*
* Permuted-choice 1 from the key bits
* to yield C and D.
* Note that bits 8,16... are left out:
* They are intended for a parity check.
*/
static char PC1_C[] = {
57,49,41,33,25,17, 9,
1,58,50,42,34,26,18,
10, 2,59,51,43,35,27,
19,11, 3,60,52,44,36,
};
static char PC1_D[] = {
63,55,47,39,31,23,15,
7,62,54,46,38,30,22,
14, 6,61,53,45,37,29,
21,13, 5,28,20,12, 4,
};
/*
* Sequence of shifts used for the key schedule.
*/
static char shifts[] = {
1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1,
};
/*
* Permuted-choice 2, to pick out the bits from
* the CD array that generate the key schedule.
*/
static char PC2_C[] = {
14,17,11,24, 1, 5,
3,28,15, 6,21,10,
23,19,12, 4,26, 8,
16, 7,27,20,13, 2,
};
static char PC2_D[] = {
41,52,31,37,47,55,
30,40,51,45,33,48,
44,49,39,56,34,53,
46,42,50,36,29,32,
};
/*
* The C and D arrays used to calculate the key schedule.
*/
static char C[28];
static char D[28];
/*
* The key schedule.
* Generated from the key.
*/
static char KS[16][48];
/*
* Set up the key schedule from the key.
*/
setkey(key)
char *key;
{
register i, j, k;
int t;
/*
* First, generate C and D by permuting
* the key. The low order bit of each
* 8-bit char is not used, so C and D are only 28
* bits apiece.
*/
for (i=0; i<28; i++) {
C[i] = key[PC1_C[i]-1];
D[i] = key[PC1_D[i]-1];
}
/*
* To generate Ki, rotate C and D according
* to schedule and pick up a permutation
* using PC2.
*/
for (i=0; i<16; i++) {
/*
* rotate.
*/
for (k=0; k<shifts[i]; k++) {
t = C[0];
for (j=0; j<28-1; j++)
C[j] = C[j+1];
C[27] = t;
t = D[0];
for (j=0; j<28-1; j++)
D[j] = D[j+1];
D[27] = t;
}
/*
* get Ki. Note C and D are concatenated.
*/
for (j=0; j<24; j++) {
KS[i][j] = C[PC2_C[j]-1];
KS[i][j+24] = D[PC2_D[j]-28-1];
}
}
}
/*
* The E bit-selection table.
*/
static char E[48];
static char e[] = {
32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9,
8, 9,10,11,12,13,
12,13,14,15,16,17,
16,17,18,19,20,21,
20,21,22,23,24,25,
24,25,26,27,28,29,
28,29,30,31,32, 1,
};
/*
* The 8 selection functions.
* For some reason, they give a 0-origin
* index, unlike everything else.
*/
static char S[8][64] = {
14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7,
0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8,
4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0,
15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13,
15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10,
3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5,
0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15,
13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9,
10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1,
13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7,
1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12,
7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15,
13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9,
10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4,
3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14,
2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9,
14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6,
4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14,
11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3,
12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11,
10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8,
9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6,
4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13,
4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1,
13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6,
1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2,
6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12,
13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7,
1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2,
7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8,
2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11,
};
/*
* P is a permutation on the selected combination
* of the current L and key.
*/
static char P[] = {
16, 7,20,21,
29,12,28,17,
1,15,23,26,
5,18,31,10,
2, 8,24,14,
32,27, 3, 9,
19,13,30, 6,
22,11, 4,25,
};
/*
* The current block, divided into 2 halves.
*/
static char L[32], R[32];
static char tempL[32];
static char f[32];
/*
* The combination of the key and the input, before selection.
*/
static char preS[48];
/*
* The payoff: encrypt a block.
*/
encrypt(block, edflag)
char *block;
{
int i, ii;
register t, j, k;
/*
* First, permute the bits in the input
*/
for (j=0; j<64; j++)
L[j] = block[IP[j]-1];
/*
* Perform an encryption operation 16 times.
*/
for (ii=0; ii<16; ii++) {
/*
* Set direction
*/
if (edflag)
i = 15-ii;
else
i = ii;
/*
* Save the R array,
* which will be the new L.
*/
for (j=0; j<32; j++)
tempL[j] = R[j];
/*
* Expand R to 48 bits using the E selector;
* exclusive-or with the current key bits.
*/
for (j=0; j<48; j++)
preS[j] = R[E[j]-1] ^ KS[i][j];
/*
* The pre-select bits are now considered
* in 8 groups of 6 bits each.
* The 8 selection functions map these
* 6-bit quantities into 4-bit quantities
* and the results permuted
* to make an f(R, K).
* The indexing into the selection functions
* is peculiar; it could be simplified by
* rewriting the tables.
*/
for (j=0; j<8; j++) {
t = 6*j;
k = S[j][(preS[t+0]<<5)+
(preS[t+1]<<3)+
(preS[t+2]<<2)+
(preS[t+3]<<1)+
(preS[t+4]<<0)+
(preS[t+5]<<4)];
t = 4*j;
f[t+0] = (k>>3)&01;
f[t+1] = (k>>2)&01;
f[t+2] = (k>>1)&01;
f[t+3] = (k>>0)&01;
}
/*
* The new R is L ^ f(R, K).
* The f here has to be permuted first, though.
*/
for (j=0; j<32; j++)
R[j] = L[j] ^ f[P[j]-1];
/*
* Finally, the new L (the original R)
* is copied back.
*/
for (j=0; j<32; j++)
L[j] = tempL[j];
}
/*
* The output L and R are reversed.
*/
for (j=0; j<32; j++) {
t = L[j];
L[j] = R[j];
R[j] = t;
}
/*
* The final output
* gets the inverse permutation of the very original.
*/
for (j=0; j<64; j++)
block[j] = L[FP[j]-1];
}
char *
crypt(pw,salt)
char *pw;
char *salt;
{
register i, j, c;
int temp;
static char block[66], iobuf[16];
for(i=0; i<66; i++)
block[i] = 0;
for(i=0; (c= *pw) && i<64; pw++){
for(j=0; j<7; j++, i++)
block[i] = (c>>(6-j)) & 01;
i++;
}
setkey(block);
for(i=0; i<66; i++)
block[i] = 0;
for(i=0;i<48;i++)
E[i] = e[i];
for(i=0;i<2;i++){
c = *salt++;
iobuf[i] = c;
if(c>'Z') c -= 6;
if(c>'9') c -= 7;
c -= '.';
for(j=0;j<6;j++){
if((c>>j) & 01){
temp = E[6*i+j];
E[6*i+j] = E[6*i+j+24];
E[6*i+j+24] = temp;
}
}
}
for(i=0; i<25; i++)
encrypt(block,0);
for(i=0; i<11; i++){
c = 0;
for(j=0; j<6; j++){
c <<= 1;
c |= block[6*i+j];
}
c += '.';
if(c>'9') c += 7;
if(c>'Z') c += 6;
iobuf[i+2] = c;
}
iobuf[i+2] = 0;
if(iobuf[1]==0)
iobuf[1] = iobuf[0];
return(iobuf);
}

View File

@ -0,0 +1,293 @@
/* @[$] ctime.c 2.3 09/12/83 11:21:43 - 87wega3.2 */
/*
* This routine converts time as follows.
* The epoch is 0000 Jan 1 1970 GMT.
* The argument time is in seconds since then.
* The localtime(t) entry returns a pointer to an array
* containing
* seconds (0-59)
* minutes (0-59)
* hours (0-23)
* day of month (1-31)
* month (0-11)
* year-1970
* weekday (0-6, Sun is 0)
* day of the year
* daylight savings flag
*
* The routine corrects for daylight saving
* time and will work in any time zone provided
* "timezone" is adjusted to the difference between
* Greenwich and local standard time (measured in seconds).
* In places like Michigan "daylight" must
* be initialized to 0 to prevent the conversion
* to daylight time.
* There is a table which accounts for the peculiarities
* undergone by daylight time in 1974-1975.
*
* The routine does not work
* in Saudi Arabia which runs on Solar time.
*
* asctime(tvec)
* where tvec is produced by localtime
* returns a ptr to a character string
* that has the ascii time in the form
* Thu Jan 01 00:00:00 1970n0\\
* 01234567890123456789012345
* 0 1 2
*
* ctime(t) just calls localtime, then asctime.
*
* tzset() looks for an environment variable named
* TZ. It should be in the form "ESTn" or "ESTnEDT",
* where "n" represents a string of digits with an optional
* negative sign (for locations east of Greenwich, England).
* If the variable is present, it will set the external
* variables "timezone", "daylight", and "tzname"
* appropriately. It is called by localtime, and
* may also be called explicitly by the user.
*/
#include <time.h>
char cbuf[26];
int dmsize[12] =
{
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
};
long timezone = 5*60*60;
char *tzname[] =
{
"EST",
"EDT",
};
int daylight = 1; /* Allow daylight conversion */
/*
* The following table is used for 1974 and 1975 and
* gives the day number of the first day after the Sunday of the
* change.
*/
struct {
int daylb;
int dayle;
} daytab[] = {
5, 333, /* 1974: Jan 6 - last Sun. in Nov */
58, 303, /* 1975: Last Sun. in Feb - last Sun in Oct */
};
struct tm *gmtime();
char *ct_numb();
struct tm *localtime();
char *ctime();
char *ct_num();
char *asctime();
char *
ctime(t)
long *t;
{
return(asctime(localtime(t)));
}
struct tm *
localtime(tim)
long *tim;
{
register int dayno;
register struct tm *ct;
register daylbegin, daylend;
long copyt;
tzset();
copyt = *tim - timezone;
ct = gmtime(&copyt);
dayno = ct->tm_yday;
daylbegin = 119; /* last Sun in Apr */
daylend = 303; /* Last Sun in Oct */
if (ct->tm_year==74 || ct->tm_year==75) {
daylbegin = daytab[ct->tm_year-74].daylb;
daylend = daytab[ct->tm_year-74].dayle;
}
daylbegin = sunday(ct, daylbegin);
daylend = sunday(ct, daylend);
if (daylight &&
(dayno>daylbegin || (dayno==daylbegin && ct->tm_hour>=2)) &&
(dayno<daylend || (dayno==daylend && ct->tm_hour<1))) {
copyt += 1*60*60;
ct = gmtime(&copyt);
ct->tm_isdst++;
}
return(ct);
}
/*
* The argument is a 0-origin day number.
* The value is the day number of the first
* Sunday on or after the day.
*/
sunday(t, d)
register struct tm *t;
register int d;
{
if (d >= 58)
d += dysize(t->tm_year) - 365;
return(d - (d - t->tm_yday + t->tm_wday + 700) % 7);
}
struct tm *
gmtime(tim)
long *tim;
{
register int d0, d1;
long hms, day;
register int *tp;
static struct tm xtime;
/*
* break initial number into days
*/
hms = *tim % 86400L;
day = *tim / 86400L;
if(hms < 0) {
hms += 86400L;
day -= 1;
}
tp = (int *) &xtime;
/*
* generate hours:minutes:seconds
*/
*tp++ = hms % 60;
d1 = hms / 60;
*tp++ = d1 % 60;
d1 /= 60;
*tp++ = d1;
/*
* day is the day number.
* generate day of the week.
* The addend is 4 mod 7 (1/1/1970 was Thursday)
*/
xtime.tm_wday = (day + 7340036L) % 7;
/*
* year number
*/
if(day >= 0) for(d1=70; day >= dysize(d1); d1++)
day -= dysize(d1);
else for(d1=70; day < 0; d1--)
day += dysize(d1-1);
xtime.tm_year = d1;
xtime.tm_yday = d0 = day;
/*
* generate month
*/
if(dysize(d1) == 366)
dmsize[1] = 29;
for(d1=0; d0 >= dmsize[d1]; d1++)
d0 -= dmsize[d1];
dmsize[1] = 28;
*tp++ = d0+1;
*tp++ = d1;
xtime.tm_isdst = 0;
return(&xtime);
}
char *
asctime(t)
struct tm *t;
{
register char *cp, *ncp;
register int *tp;
cp = cbuf;
for(ncp = "Day Mon 00 00:00:00 1900\n"; *cp++ = *ncp++;);
ncp = &"SunMonTueWedThuFriSat"[3*t->tm_wday];
cp = cbuf;
*cp++ = *ncp++;
*cp++ = *ncp++;
*cp++ = *ncp++;
cp++;
tp = &t->tm_mon;
ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[(*tp)*3];
*cp++ = *ncp++;
*cp++ = *ncp++;
*cp++ = *ncp++;
cp = ct_numb(cp, *--tp);
cp = ct_numb(cp, *--tp+100);
cp = ct_numb(cp, *--tp+100);
cp = ct_numb(cp, *--tp+100);
if(t->tm_year >= 100) {
cp[1] = '2';
cp[2] = '0';
}
cp += 2;
cp = ct_numb(cp, t->tm_year+100);
return(cbuf);
}
dysize(y)
{
if((y % 4) == 0)
return(366);
return(365);
}
char *
ct_numb(cp, n)
register char *cp;
{
cp++;
if(n >= 10)
*cp++ = (n/10)%10 + '0';
else
*cp++ = ' ';
*cp++ = n%10 + '0';
return(cp);
}
tzset()
{
register char *p, *q;
register int n;
int sign;
char *getenv();
if((p = getenv ("TZ")) && *p) {
n = 3;
q = tzname[0];
do *q++ = *p? *p++: ' ';
while(--n);
if(sign = *p == '-')
p++;
n = 0;
while(*p >= '0' && *p <= '9')
n = (n * 10) + *p++ - '0';
if(sign)
n = -n;
timezone = ((long) (n * 60)) * 60;
if(daylight = *p != '\0') {
q = tzname[1];
n = 3;
do *q++ = *p? *p++: ' ';
while(--n);
}
}
}

View File

@ -0,0 +1,41 @@
/* @[$] ctype_.c 2.1 09/12/83 11:22:28 - 87wega3.2 */
#include "ctype.h"
char _ctype[] = { 0,
/* 0 1 2 3 4 5 6 7 */
/* 0*/ _C, _C, _C, _C, _C, _C, _C, _C,
/* 10*/ _C, _S|_C, _S|_C, _S|_C, _S|_C, _S|_C, _C, _C,
/* 20*/ _C, _C, _C, _C, _C, _C, _C, _C,
/* 30*/ _C, _C, _C, _C, _C, _C, _C, _C,
/* 40*/ _S|_B, _P, _P, _P, _P, _P, _P, _P,
/* 50*/ _P, _P, _P, _P, _P, _P, _P, _P,
/* 60*/ _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X,
/* 70*/ _N|_X, _N|_X, _P, _P, _P, _P, _P, _P,
/*100*/ _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U,
/*110*/ _U, _U, _U, _U, _U, _U, _U, _U,
/*120*/ _U, _U, _U, _U, _U, _U, _U, _U,
/*130*/ _U, _U, _U, _P, _P, _P, _P, _P,
/*140*/ _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L,
/*150*/ _L, _L, _L, _L, _L, _L, _L, _L,
/*160*/ _L, _L, _L, _L, _L, _L, _L, _L,
/*170*/ _L, _L, _L, _P, _P, _P, _P, _C,
/*200*/ 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};

View File

@ -0,0 +1,40 @@
/* @[$] errlst.c 2.3 09/12/83 11:23:30 - 87wega3.2 */
char *sys_errlist[] = {
"Error 0",
"Not owner",
"No such file or directory",
"No such process",
"Interrupted system call",
"I/O error",
"No such device or address",
"Arg list too long",
"Exec format error",
"Bad file number",
"No children",
"No more processes",
"Not enough core",
"Permission denied",
"Bad address",
"Block device required",
"Mount device busy",
"File exists",
"Cross-device link",
"No such device",
"Not a directory",
"Is a directory",
"Invalid argument",
"File table overflow",
"Too many open files",
"Not a typewriter",
"Text file busy",
"File too large",
"No space left on device",
"Illegal seek",
"Read-only file system",
"Too many links",
"Broken pipe",
"Argument too large",
"Result too large",
};
int sys_nerr = { sizeof sys_errlist/sizeof sys_errlist[0] };

View File

@ -0,0 +1,85 @@
/* @[$] execvp.c 2.1 09/12/83 11:23:54 - 87wega3.2 */
/*
* execlp(name, arg,...,0) (like execl, but does path search)
* execvp(name, argv) (like execv, but does path search)
*/
#include <errno.h>
#define NULL 0
static char shell[] = "/bin/sh";
char *execat(), *getenv(), *strchr();
extern errno;
execlp(name, argv)
char *name, *argv;
{
return(execvp(name, &argv));
}
execvp(name, argv)
char *name, **argv;
{
char *pathstr;
register char *cp;
char fname[128];
char *newargs[256];
int i;
register unsigned etxtbsy = 1;
register eacces = 0;
if ((pathstr = getenv("PATH")) == NULL)
pathstr = ":/bin:/usr/bin";
cp = strchr(name, '/')? "": pathstr;
do {
cp = execat(cp, name, fname);
retry:
execv(fname, argv);
switch(errno) {
case ENOEXEC:
newargs[0] = "sh";
newargs[1] = fname;
for (i=1; newargs[i+1]=argv[i]; i++) {
if (i>=254) {
errno = E2BIG;
return(-1);
}
}
execv(shell, newargs);
return(-1);
case ETXTBSY:
if (++etxtbsy > 5)
return(-1);
sleep(etxtbsy);
goto retry;
case EACCES:
eacces++;
break;
case ENOMEM:
case E2BIG:
return(-1);
}
} while (cp);
if (eacces)
errno = EACCES;
return(-1);
}
static char *
execat(s1, s2, si)
register char *s1, *s2;
char *si;
{
register char *s;
s = si;
while (*s1 && *s1 != ':')
*s++ = *s1++;
if (si != s)
*s++ = '/';
while (*s2)
*s++ = *s2++;
*s = '\0';
return(*s1? ++s1: 0);
}

View File

@ -0,0 +1,42 @@
/* @[$] getenv.c 2.1 09/12/83 11:24:21 - 87wega3.2 */
/*
* getenv(name)
* returns ptr to value associated with name, if any, else NULL
*/
#define NULL 0
extern char **environ;
char *nvmatch();
char *
getenv(name)
register char *name;
{
register char **p = environ;
register char *v;
while (*p != NULL)
if ((v = nvmatch(name, *p++)) != NULL)
return(v);
return(NULL);
}
/*
* s1 is either name, or name=value
* s2 is name=value
* if names match, return value of s2, else NULL
* used for environment searching: see getenv
*/
static char *
nvmatch(s1, s2)
register char *s1, *s2;
{
while (*s1 == *s2++)
if (*s1++ == '=')
return(s2);
if (*s1 == '\0' && *(s2-1) == '=')
return(s2);
return(NULL);
}

View File

@ -0,0 +1,65 @@
/* @[$] getgrent.c 2.1 09/12/83 11:11:40 - 87wega3.2 */
#include <stdio.h>
#include <grp.h>
#define CL ':'
#define CM ','
#define NL '\n'
#define MAXGRP 100
static char GROUP[] = "/etc/group";
static FILE *grf = NULL;
static char line[BUFSIZ+1];
static struct group group;
static char *gr_mem[MAXGRP];
setgrent()
{
if( !grf )
grf = fopen( GROUP, "r" );
else
rewind( grf );
}
endgrent()
{
if( grf ){
fclose( grf );
grf = NULL;
}
}
static char *
grskip(p,c)
register char *p;
register c;
{
while( *p && *p != c ) ++p;
if( *p ) *p++ = 0;
return( p );
}
struct group *
getgrent()
{
register char *p, **q;
if( !grf && !(grf = fopen( GROUP, "r" )) )
return(NULL);
if( !(p = fgets( line, BUFSIZ, grf )) )
return(NULL);
group.gr_name = p;
group.gr_passwd = p = grskip(p,CL);
group.gr_gid = atoi( p = grskip(p,CL) );
group.gr_mem = gr_mem;
p = grskip(p,CL);
grskip(p,NL);
q = gr_mem;
while( *p ){
*q++ = p;
p = grskip(p,CM);
}
*q = NULL;
return( &group );
}

View File

@ -0,0 +1,16 @@
/* @[$] getgrgid.c 2.1 09/12/83 11:11:59 - 87wega3.2 */
#include <grp.h>
struct group *
getgrgid(gid)
register gid;
{
register struct group *p;
struct group *getgrent();
setgrent();
while( (p = getgrent()) && p->gr_gid != gid );
endgrent();
return(p);
}

View File

@ -0,0 +1,16 @@
/* @[$] getgrnam.c 2.1 09/12/83 11:12:14 - 87wega3.2. */
#include <grp.h>
struct group *
getgrnam(name)
register char *name;
{
register struct group *p;
struct group *getgrent();
setgrent();
while( (p = getgrent()) && strcmp(p->gr_name,name) );
endgrent();
return(p);
}

View File

@ -0,0 +1,33 @@
/* @[$] getlogin.c 2.2 09/12/83 11:24:36 - 87wega3.2 */
#include <utmp.h>
#define NULL 0
static char UTMP[] = "/etc/utmp";
static struct utmp ubuf;
char *
getlogin()
{
register me, uf;
register char *cp;
if((me = ttyslot()) < 0)
return NULL;
if((uf = open(UTMP, 0)) < 0)
return NULL;
lseek(uf, (long)(me * sizeof ubuf), 0);
if (read (uf, (char *) &ubuf, sizeof ubuf) != sizeof ubuf) {
close (uf);
return NULL;
}
close (uf);
if (ubuf.ut_name[0] == '\0')
return NULL;
ubuf.ut_name[8] = ' ';
for (cp=ubuf.ut_name; *cp++!=' ';)
;
*--cp = '\0';
return ubuf.ut_name;
}

View File

@ -0,0 +1,60 @@
/* @[$] getopt.c 2.1 09/12/83 11:35:50 - 87wega3.2 */
#include <stdio.h>
#define ERR(s, c) if(opterr){\
fputs(argv[0], stderr);\
fputs(s, stderr);\
fputc(c, stderr);\
fputc('\n', stderr);}
int opterr = 1;
int optind = 1;
int optopt;
char *optarg;
char *strchr();
int
getopt (argc, argv, opts)
char **argv, *opts;
{
static int sp = 1;
register c;
register char *cp;
if (sp == 1)
if (optind >= argc ||
argv[optind][0] != '-' || argv[optind][1] == '\0')
return EOF;
else if (strcmp(argv[optind], "--") == NULL) {
optind++;
return EOF;
}
optopt = c = argv[optind][sp];
if (c == ':' || (cp=strchr(opts, c)) == NULL) {
ERR (": illegal option -- ", c);
if (argv[optind][++sp] == '\0') {
optind++;
sp = 1;
}
return '?';
}
if (*++cp == ':') {
if (argv[optind][sp+1] != '\0')
optarg = &argv[optind++][sp+1];
else if (++optind >= argc) {
ERR (": option requires an argument -- ", c);
sp = 1;
return '?';
} else
optarg = argv[optind++];
sp = 1;
}
else {
if (argv[optind][++sp] == '\0') {
sp = 1;
optind++;
}
optarg=NULL;
}
return c;
}

View File

@ -0,0 +1,41 @@
/* @[$] getpw.c 2.1 09/12/83 11:12:46 - 87wega3.2. */
#include <stdio.h>
getpw(uid, buf)
int uid;
char buf[];
{
static FILE *pwf;
register n, c;
register char *bp;
if(pwf == 0)
pwf = fopen("/etc/passwd", "r");
if(pwf == NULL)
return(1);
rewind(pwf);
for (;;) {
bp = buf;
while((c=getc(pwf)) != '\n') {
if(c == EOF)
return(1);
*bp++ = c;
}
*bp++ = '\0';
bp = buf;
n = 3;
while(--n)
while((c = *bp++) != ':')
if(c == '\n')
return(1);
while((c = *bp++) != ':') {
if(c<'0' || c>'9')
continue;
n = n*10+c-'0';
}
if(n == uid)
return(0);
}
}

View File

@ -0,0 +1,76 @@
/* @[$] getpwent.c 2.1 09/12/83 11:13:03 - 87wega3.2 */
#include <stdio.h>
#include <pwd.h>
static char PASSWD[] = "/etc/passwd";
static char EMPTY[] = "";
static FILE *pwf = NULL;
static char line[BUFSIZ+1];
static struct passwd passwd;
setpwent()
{
if (pwf == NULL)
pwf = fopen (PASSWD, "r");
else
rewind (pwf);
}
endpwent()
{
if (pwf != NULL){
fclose (pwf);
pwf = NULL;
}
}
static char *
pwskip (p)
register char *p;
{
while (*p && *p != ':' && *p != '\n')
++p;
if (*p == '\n')
*p = '\0';
else if (*p)
*p++ = '\0';
return p;
}
struct passwd *
getpwent()
{
register char *p;
if (pwf == NULL) {
if ((pwf = fopen (PASSWD, "r")) == NULL)
return 0;
}
p = fgets (line, BUFSIZ, pwf);
if (p==NULL)
return 0;
passwd.pw_name = p;
p = pwskip (p);
passwd.pw_passwd = p;
p = pwskip (p);
passwd.pw_uid = atoi (p);
p = pwskip (p);
passwd.pw_gid = atoi (p);
passwd.pw_comment = EMPTY;
p = pwskip (p);
passwd.pw_gecos = p;
p = pwskip (p);
passwd.pw_dir = p;
p = pwskip (p);
passwd.pw_shell = p;
pwskip(p);
p = passwd.pw_passwd;
while (*p && *p != ',')
p++;
if (*p)
*p++ = '\0';
passwd.pw_age = p;
return &passwd;
}

View File

@ -0,0 +1,16 @@
/* @[$] getpwnam.c 2.1 09/12/83 11:13:23 - 87wega3.2 */
#include <pwd.h>
struct passwd *
getpwnam(name)
char *name;
{
register struct passwd *p;
struct passwd *getpwent();
setpwent();
while( (p = getpwent()) && strcmp(name,p->pw_name) );
endpwent();
return(p);
}

View File

@ -0,0 +1,16 @@
/* @[$] getpwuid.c 2.1 09/12/83 11:13:36 - 87wega3.2. */
#include <pwd.h>
struct passwd *
getpwuid(uid)
register uid;
{
register struct passwd *p;
struct passwd *getpwent();
setpwent();
while( (p = getpwent()) && p->pw_uid != uid );
endpwent();
return(p);
}

View File

@ -0,0 +1,16 @@
/* @[$] isatty.c 2.1 09/12/83 11:25:21 - 87wega3.2 */
/*
* Returns 1 iff file is a tty
*/
#include <sgtty.h>
isatty(f)
{
struct sgttyb ttyb;
if (gtty(f, &ttyb) < 0)
return(0);
return(1);
}

View File

@ -0,0 +1,40 @@
/* @[$] l3.c 2.1 09/12/83 11:25:34 - 87wega3.2 */
/*
* Convert longs to and from 3-byte disk addresses
*/
ltol3(cp, lp, n)
char *cp;
long *lp;
int n;
{
register i;
register char *a, *b;
a = cp;
b = (char *)lp;
for(i=0;i<n;i++) {
b++;
*a++ = *b++;
*a++ = *b++;
*a++ = *b++;
}
}
l3tol(lp, cp, n)
long *lp;
char *cp;
int n;
{
register i;
register char *a, *b;
a = (char *)lp;
b = cp;
for(i=0;i<n;i++) {
*a++ = 0;
*a++ = *b++;
*a++ = *b++;
*a++ = *b++;
}
}

View File

@ -0,0 +1,28 @@
/* @[$] l64a.c 2.1 09/12/83 11:25:49 - 87wega3.2 */
/*
* convert long int to base 64 ascii
* char set is [./0-9A-Za-z]
*/
char *
l64a(l)
long l;
{
register int i, c;
register char *s;
static char buf[7];
i = 6;
s = buf;
while (--i > 0 && l != 0) {
c = (l & 077) + '.';
if (c > '9')
c += 'A'-'9'-1;
if (c > 'Z')
c += 'a'-'Z'-1;
*s++ = c;
l >>= 6;
}
*s = '\0';
return buf;
}

View File

@ -0,0 +1,30 @@
/* @[$] lsearch.c 2.1 09/12/83 11:26:03 - 87wega3.2 */
/*
* Linear search algorithm, generalized from Knuth (6.1) Algorithm Q.
*/
typedef char *POINTER;
POINTER
lsearch(key, base, nelp, width, compar)
POINTER key; /* Key to be located */
POINTER base; /* Beginning of table */
int *nelp; /* Address of table size */
int width; /* Width of an element */
int (*compar)(); /* Comparison function */
{
POINTER test = base; /* Points to table elements */
POINTER next = base+(*nelp)*width; /* End of table */
POINTER strncpy();
strncpy(next, key, width);
while((*compar)(key, test) != 0)
test += width;
if(test == next)
(*nelp)++;
return(test);
}

View File

@ -0,0 +1,191 @@
/* @[$] malloc.c 3.3 09/12/83 10:32:30 - 87wega3.2
#ifdef debug
#define ASSERT(p) if(!(p))botch("p");else
botch(s)
char *s;
{
printf("assertion botched: %s\n",s);
abort();
}
#else
#define ASSERT(p)
#endif
/* avoid break bug */
#ifdef z8000
#define GRANULE 64
#else
#define GRANULE 0
#endif
/* C storage allocator
* circular first-fit strategy
* works with noncontiguous, but monotonically linked, arena
* each block is preceded by a ptr to the (pointer of)
* the next following block
* blocks are exact number of words long
* aligned to the data type requirements of ALIGN
* pointers to blocks must have BUSY bit 0
* bit in ptr is 1 for busy, 0 for idle
* gaps in arena are merely noted as busy blocks
* last block of arena (pointed to by alloct) is empty and
* has a pointer to first
* idle blocks are coalesced during space search
*
* a different implementation may need to redefine
* ALIGN, NALIGN, BLOCK, BUSY, INT
* where INT is integer type to which a pointer can be cast
*/
#define INT int
#define ALIGN int
#define NALIGN 1
#define WORD sizeof(union store)
#define BLOCK 1024 /* a multiple of WORD*/
#define BUSY 1
#define NULL 0
#define testbusy(p) ((INT)(p)&BUSY)
#define setbusy(p) (union store *)((INT)(p)|BUSY)
#define clearbusy(p) (union store *)((INT)(p)&~BUSY)
union store { union store *ptr;
ALIGN dummy[NALIGN];
int calloc; /*calloc clears an array of integers*/
};
static union store allocs[2]; /*initial arena*/
static union store *allocp; /*search ptr*/
static union store *alloct; /*arena top*/
static union store *allocx; /*for benefit of realloc*/
char *sbrk();
char *
malloc(nbytes)
unsigned nbytes;
{
register union store *p, *q;
register nw;
static temp; /*coroutines assume no auto*/
if(allocs[0].ptr==0) { /*first time*/
allocs[0].ptr = setbusy(&allocs[1]);
allocs[1].ptr = setbusy(&allocs[0]);
alloct = &allocs[1];
allocp = &allocs[0];
}
nw = (nbytes+WORD+WORD-1)/WORD;
ASSERT(allocp>=allocs && allocp<=alloct);
ASSERT(allock());
for(p=allocp; ; ) {
for(temp=0; ; ) {
if(!testbusy(p->ptr)) {
while(!testbusy((q=p->ptr)->ptr)) {
ASSERT(q>p&&q<alloct);
p->ptr = q->ptr;
}
if(q>=p+nw && p+nw>=p)
goto found;
}
q = p;
p = clearbusy(p->ptr);
if(p>q)
ASSERT(p<=alloct);
else if(q!=alloct || p!=allocs) {
ASSERT(q==alloct&&p==allocs);
return(NULL);
} else if(++temp>1)
break;
}
temp = ((nw+BLOCK/WORD)/(BLOCK/WORD))*(BLOCK/WORD);
q = (union store *)sbrk(0);
if(q+temp+GRANULE < q) {
return(NULL);
}
q = (union store *)sbrk(temp*WORD);
if((INT)q == -1) {
return(NULL);
}
ASSERT(q>alloct);
alloct->ptr = q;
if(q!=alloct+1)
alloct->ptr = setbusy(alloct->ptr);
alloct = q->ptr = q+temp-1;
alloct->ptr = setbusy(allocs);
}
found:
allocp = p + nw;
ASSERT(allocp<=alloct);
if(q>allocp) {
allocx = allocp->ptr;
allocp->ptr = p->ptr;
}
p->ptr = setbusy(allocp);
return((char *)(p+1));
}
/* freeing strategy tuned for LIFO allocation
*/
free(ap)
register char *ap;
{
register union store *p = (union store *)ap;
ASSERT(p>clearbusy(allocs[1].ptr)&&p<=alloct);
ASSERT(allock());
allocp = --p;
ASSERT(testbusy(p->ptr));
p->ptr = clearbusy(p->ptr);
ASSERT(p->ptr > allocp && p->ptr <= alloct);
}
/* realloc(p, nbytes) reallocates a block obtained from malloc()
* and freed since last call of malloc()
* to have new size nbytes, and old content
* returns new location, or 0 on failure
*/
char *
realloc(p, nbytes)
register union store *p;
unsigned nbytes;
{
register union store *q;
union store *s, *t;
register unsigned nw;
unsigned onw;
if(testbusy(p[-1].ptr))
free((char *)p);
onw = p[-1].ptr - p;
q = (union store *)malloc(nbytes);
if(q==NULL || q==p)
return((char *)q);
s = p;
t = q;
nw = (nbytes+WORD-1)/WORD;
if(nw<onw)
onw = nw;
while(onw--!=0)
*t++ = *s++;
if(q<p && q+nw>=p)
(q+(q+nw-p))->ptr = allocx;
return((char *)q);
}
#ifdef debug
allock()
{
#ifdef longdebug
register union store *p;
int x;
x = 0;
for(p= &allocs[0]; clearbusy(p->ptr) > p; p=clearbusy(p->ptr)) {
if(p==allocp)
x++;
}
ASSERT(p==alloct);
return(x==1|p==allocp);
#else
return(1);
#endif
}
#endif

View File

@ -0,0 +1,28 @@
/* @[$] mktemp.c 2.1 09/12/83 11:27:03 - 87wega3.2 */
char *
mktemp(as)
char *as;
{
register char *s;
register unsigned pid;
register i;
pid = getpid();
s = as;
while (*s++)
;
s--;
while (*--s == 'X') {
*s = (pid%10) + '0';
pid /= 10;
}
s++;
i = 'a';
while (access(as, 0) != -1) {
if (i=='z')
return("/");
*s = i++;
}
return(as);
}

View File

@ -0,0 +1,32 @@
/* @[$] mon.c 2.1 09/12/83 11:27:20 - 87wega3.2 */
monitor(lowpc, highpc, buf, bufsiz, cntsiz)
char *lowpc, *highpc;
int *buf, bufsiz;
{
register o;
static *sbuf, ssiz;
if (lowpc == 0) {
profil(0, 0, 0, 0);
o = creat("mon.out", 0666);
write(o, sbuf, ssiz<<1);
close(o);
return;
}
ssiz = bufsiz;
buf[0] = (int)lowpc;
buf[1] = (int)highpc;
buf[2] = cntsiz;
sbuf = buf;
buf += 3*(cntsiz+1);
bufsiz -= 3*(cntsiz+1);
if (bufsiz<=0)
return;
o = ((highpc - lowpc)>>1) & 077777;
if(bufsiz < o)
o = ((long)bufsiz<<15) / o;
else
o = 077777;
profil(buf, bufsiz<<1, lowpc, o<<1);
}

View File

@ -0,0 +1,66 @@
/* @[$] nlist.c 2.1 09/12/83 11:28:01 - 87wega3.2 */
#include <a.out.h>
#define SPACE 100 /* number of symbols read at a time */
nlist(name, list)
char *name;
struct nlist *list;
{
register struct nlist *p, *q;
int f, n, m, i;
long sa;
struct exec buf;
struct nlist space[SPACE];
struct ovkhdr ovk;
for(p = list; p->n_name[0]; p++) {
p->n_type = 0;
p->n_value = 0;
}
if((f = open(name, 0)) < 0)
return(-1);
read(f, (char *) &buf, sizeof(buf));
if(BADMAG(buf)) {
close(f);
return(-1);
}
sa = buf.a_text + (long) buf.a_data;
if ( buf.a_magic == A_MAGICO ) {
sa += (long)sizeof(ovk);
read( f, (char *) &ovk, sizeof(ovk));
for ( i = 0; i < 7 && ovk.ovsize[i]; i++ )
sa += (long)ovk.ovsize[i];
}
#ifdef vax
sa += buf.a_trsize + buf.a_drsize;
#endif
#ifdef z8000
if(buf.a_flag != 1) sa *= 2;
#endif
sa += sizeof(buf);
lseek(f, sa, 0);
n = buf.a_syms;
while(n){
m = sizeof(space);
if(n < sizeof(space))
m = n;
read(f, (char *) space, m);
n -= m;
for(q = space; (m -= sizeof(struct nlist)) >= 0; q++) {
for(p = list; p->n_name[0]; p++) {
for(i=0; i < 8; i++)
if(p->n_name[i] != q->n_name[i])
goto cont;
p->n_value = q->n_value;
p->n_type = q->n_type;
break;
cont: ;
}
}
}
close(f);
return(0);
}

View File

@ -0,0 +1,28 @@
/* @[$] perror.c 2.1 09/12/83 11:28:30 - 87wega3.2 */
/*
* Print the error indicated
* in the cerror cell.
*/
int errno;
extern int sys_nerr;
extern char *sys_errlist[];
perror(s)
char *s;
{
register char *c;
register n;
c = "Unknown error";
if(errno < sys_nerr)
c = sys_errlist[errno];
n = strlen(s);
if(n) {
write(2, s, n);
write(2, ": ", 2);
}
write(2, c, strlen(c));
write(2, "\n", 1);
}

View File

@ -0,0 +1,24 @@
/* @[$] putpwent.c 2.1 09/12/83 11:15:33 - 87wega3.2. */
#include <stdio.h>
#include <pwd.h>
/*
* format a password file entry
*/
putpwent(p, f)
register struct passwd *p;
register FILE *f;
{
fprintf(f, "%s:%s", p->pw_name, p->pw_passwd);
if ((*p->pw_age) != '\0')
fprintf(f, ",%s", p->pw_age);
fprintf(f, ":%u:%u:%s:%s:%s",
p->pw_uid, p->pw_gid,
p->pw_gecos,
p->pw_dir,
p->pw_shell
);
putc('\n', f);
return ferror(f);
}

View File

@ -0,0 +1,126 @@
/* @[$] qsort.c 2.1 09/12/83 11:29:11 - 87wega3.2 */
static int (*qscmp)();
static int qses;
int qsuflg; /* used by sort command */
qsort(a, n, es, fc)
char *a;
unsigned n;
int es;
int (*fc)();
{
qscmp = fc;
qses = es;
qs1(a, a+n*es);
}
static qs1(a, l)
char *a, *l;
{
register char *i, *j;
register es;
char **k;
char *lp, *hp;
int c;
unsigned n;
es = qses;
start:
if((n=l-a) <= es)
return;
n = es * (n / (2*es));
hp = lp = a+n;
i = a;
j = l-es;
for(;;) {
if(i < lp) {
if((c = (*qscmp)(i, lp)) == 0) {
qsexc(i, lp -= es);
continue;
}
if(c < 0) {
i += es;
continue;
}
}
loop:
if(j > hp) {
if((c = (*qscmp)(hp, j)) == 0) {
qsexc(hp += es, j);
goto loop;
}
if(c > 0) {
if(i == lp) {
qstexc(i, hp += es, j);
i = lp += es;
goto loop;
}
qsexc(i, j);
j -= es;
i += es;
continue;
}
j -= es;
goto loop;
}
if(i == lp) {
if(qsuflg)
/* nullify non-unique lines */
for(k=(char **)lp; k<(char **)hp;)
*(*++k) = '\0';
if(lp-a >= l-hp) {
qs1(hp+es, l);
l = lp;
} else {
qs1(a, lp);
a = hp+es;
}
goto start;
}
qstexc(j, lp -= es, i);
j = hp -= es;
}
}
static qsexc(i, j)
char *i, *j;
{
register char *ri, *rj, c;
int n;
n = qses;
ri = i;
rj = j;
do {
c = *ri;
*ri++ = *rj;
*rj++ = c;
} while(--n);
}
static qstexc(i, j, k)
char *i, *j, *k;
{
register char *ri, *rj, *rk;
int c;
int n;
n = qses;
ri = i;
rj = j;
rk = k;
do {
c = *ri;
*ri++ = *rk;
*rk++ = *rj;
*rj++ = c;
} while(--n);
}

View File

@ -0,0 +1,14 @@
/* @[$] rand.c 2.1 09/12/83 11:29:35 - 87wega3.2 */
static long randx = 1;
srand(x)
unsigned x;
{
randx = x;
}
rand()
{
return(((randx = randx * 1103515245L + 12345)>>16) & 0x7fff);
}

View File

@ -0,0 +1,59 @@
/* @[$] sleep.c 2.3 09/12/83 11:30:37 - 87wega3.2 */
/*
* Suspend the process for `sleep_tm' seconds - using alarm/pause
* system calls. If caller had an alarm already set to go off `n'
* seconds from now, then Case 1: (sleep_tm >= n) sleep for n, and
* cause the callers previously specified alarm interrupt routine
* to be executed, then return the value (sleep_tm - n) to the caller
* as the unslept amount of time, Case 2: (sleep_tm < n) sleep for
* sleep_tm, after which, reset alarm to go off when it would have
* anyway. In case process is aroused during sleep by any caught
* signal, then reset any prior alarm, as above, and return to the
* caller the (unsigned) quantity of (requested) seconds unslept.
*/
#include <signal.h>
unsigned
sleep(sleep_tm)
unsigned sleep_tm;
{
int alrm_flg, (*alrm_sig)(), awake();
unsigned unslept, alrm_tm, left_ovr, alarm();
if(sleep_tm == 0)
return(0);
alrm_tm = alarm(0); /* prev. alarm time */
alrm_sig = signal(SIGALRM, awake); /* prev. alarm prog */
alrm_flg = 0;
left_ovr = 0;
if(alrm_tm != 0) { /* skip all this if no prev. alarm */
if(alrm_tm > sleep_tm) { /* alarm set way-out */
alrm_tm -= sleep_tm;
++alrm_flg;
} else { /* alarm will shorten sleep time */
left_ovr = sleep_tm - alrm_tm;
sleep_tm = alrm_tm;
alrm_tm = 0;
--alrm_flg;
signal(SIGALRM, alrm_sig);
}
}
alarm(sleep_tm);
pause(); /* Some other signal may be caught,
returning here, in which case we
set-up to return to our caller */
unslept = alarm(0);
if(alrm_flg >= 0)
signal(SIGALRM, alrm_sig);
if(alrm_flg > 0 || (alrm_flg < 0 && unslept != 0))
alarm(alrm_tm + unslept);
return(left_ovr + unslept);
}
static
awake() {}

View File

@ -0,0 +1,44 @@
/* @[$] ssignal.c 2.1 09/12/83 11:30:56 - 87wega3.2 */
/*
* ssignal, gsignal: software signals
*/
#include <signal.h>
/* Highest allowable user signal number */
#define MAXSIG 16
/* Lowest allowable signal number (lowest user number is always 1) */
#define MINSIG (-4)
/* Table of signal values */
static int (*sigs[MAXSIG-MINSIG+1])();
int (*ssignal (sig, fn))()
register int sig, (*fn)();
{
register int (*savefn)();
if (sig >= MINSIG && sig <= MAXSIG) {
savefn = sigs[sig+MINSIG];
sigs[sig+MINSIG] = fn;
} else
savefn = SIG_DFL;
return savefn;
}
int gsignal (sig)
register int sig;
{
register int (*sigfn)();
if (sig < MINSIG || sig > MAXSIG
|| (sigfn = sigs[sig+MINSIG]) == SIG_DFL)
return 0;
else if (sigfn == SIG_IGN)
return 1;
else {
sigs[sig+MINSIG] = SIG_DFL;
return (*sigfn)(sig);
}
}

View File

@ -0,0 +1,21 @@
/* @[$] strcat.c 2.1 09/12/83 11:31:16 - 87wega3.2 */
/*
* Concatenate s2 on the end of s1. S1's space must be large enough.
* Return s1.
*/
char *
strcat(s1, s2)
register char *s1, *s2;
{
register char *os1;
os1 = s1;
while (*s1++)
;
--s1;
while (*s1++ = *s2++)
;
return(os1);
}

View File

@ -0,0 +1,19 @@
/* @[$] strchr.c 2.1 09/12/83 11:36:14 - 87wega3.2 */
/*
* Return the ptr in sp at which the character c appears;
* NULL if not found
*/
#define NULL 0
char *
strchr(sp, c)
register char *sp, c;
{
do {
if (*sp == c)
return(sp);
} while (*sp++);
return(NULL);
}

View File

@ -0,0 +1,15 @@
/* @[$] strcmp.c 2.1 09/12/83 11:31:30 - 87wega3.2 */
/*
* Compare strings: s1>s2: >0 s1==s2: 0 s1<s2: <0
*/
strcmp(s1, s2)
register char *s1, *s2;
{
while (*s1 == *s2++)
if (*s1++=='\0')
return(0);
return(*s1 - *--s2);
}

View File

@ -0,0 +1,18 @@
/* @[$] strcpy.c 2.1 09/12/83 11:31:44 - 87wega3.2 */
/*
* Copy string s2 to s1. s1 must be large enough.
* return s1
*/
char *
strcpy(s1, s2)
register char *s1, *s2;
{
register char *os1;
os1 = s1;
while (*s1++ = *s2++)
;
return(os1);
}

View File

@ -0,0 +1,21 @@
/* @[$] strcspn.c 2.1 09/12/83 11:36:27 - 87wega3.2 */
/*
* Return the number of characters in the maximum leading segment
* of string which consists solely of characters NOT from charset.
*/
int
strcspn(string, charset)
char *string;
register char *charset;
{
register char *p, *q;
for(q=string; *q != '\0'; ++q) {
for(p=charset; *p != '\0' && *p != *q; ++p)
;
if(*p != '\0')
break;
}
return(q-string);
}

View File

@ -0,0 +1,17 @@
/* @[$] strlen.c 2.1 09/12/83 11:31:59 - 87wega3.2 */
/*
* Returns the number of
* non-NULL bytes in string argument.
*/
strlen(s)
register char *s;
{
register n;
n = 0;
while (*s++)
n++;
return(n);
}

View File

@ -0,0 +1,26 @@
/* @[$] strncat.c 2.1 09/12/83 11:32:12 - 87wega3.2 */
/*
* Concatenate s2 on the end of s1. S1's space must be large enough.
* At most n characters are moved.
* Return s1.
*/
char *
strncat(s1, s2, n)
register char *s1, *s2;
register n;
{
register char *os1;
os1 = s1;
while (*s1++)
;
--s1;
while (*s1++ = *s2++)
if (--n < 0) {
*--s1 = '\0';
break;
}
return(os1);
}

View File

@ -0,0 +1,16 @@
/* @[$] strncmp.c 2.1 09/12/83 11:32:27 - 87wega3.2 */
/*
* Compare strings (at most n bytes): s1>s2: >0 s1==s2: 0 s1<s2: <0
*/
strncmp(s1, s2, n)
register char *s1, *s2;
register n;
{
while (--n >= 0 && *s1 == *s2++)
if (*s1++ == '\0')
return(0);
return(n<0 ? 0 : *s1 - *--s2);
}

View File

@ -0,0 +1,23 @@
/* @[$] strncpy.c 2.1 09/12/83 11:32:45 - 87wega3.2 */
/*
* Copy s2 to s1, truncating or null-padding to always copy n bytes
* return s1
*/
char *
strncpy(s1, s2, n)
register char *s1, *s2;
{
register i;
register char *os1;
os1 = s1;
for (i = 0; i < n; i++)
if ((*s1++ = *s2++) == '\0') {
while (++i < n)
*s1++ = '\0';
return(os1);
}
return(os1);
}

View File

@ -0,0 +1,24 @@
/* @[$] strpbrk.c 2.1 09/12/83 11:36:41 - 87wega3.2 */
/*
* Return ptr to first occurance of any character from `brkset'
* in the character string `string'; NULL if none exists.
*/
#define NULL (char *) 0
char *
strpbrk(string, brkset)
register char *string, *brkset;
{
register char *p;
do {
for(p=brkset; *p != '\0' && *p != *string; ++p)
;
if(*p != '\0')
return(string);
}
while(*string++);
return(NULL);
}

View File

@ -0,0 +1,22 @@
/* @[$] strrchr.c 2.1 09/12/83 11:36:55 - 87wega3.2 */
/*
* Return the ptr in sp at which the character c last
* appears; NULL if not found
*/
#define NULL 0
char *
strrchr(sp, c)
register char *sp, c;
{
register char *r;
r = NULL;
do {
if (*sp == c)
r = sp;
} while (*sp++);
return(r);
}

View File

@ -0,0 +1,21 @@
/* @[$] strspn.c 2.1 09/12/83 11:37:08 - 87wega3.2 */
/*
* Return the number of characters in the maximum leading segment
* of string which consists solely of characters from charset.
*/
int
strspn(string, charset)
char *string;
register char *charset;
{
register char *p, *q;
for(q=string; *q != '\0'; ++q) {
for(p=charset; *p != '\0' && *p != *q; ++p)
;
if(*p == '\0')
break;
}
return(q-string);
}

View File

@ -0,0 +1,36 @@
/* @[$] strtok.c 2.1 09/12/83 11:37:22 - 87wega3.2 */
/*
* uses strpbrk and strspn to break string into tokens on
* sequentially subsequent calls. returns NULL at end.
*/
#define NULL (char *) 0
char *
strtok(string, sepset)
char *string, *sepset;
{
int strspn();
char *strpbrk();
register char *p, *q, *r;
static char *savept;
if(string == NULL)
p = savept;
else
p = string;
if(p == 0)
return(NULL);
q = p + strspn(p, sepset);
if(*q == '\0')
return(NULL);
if((r = strpbrk(q, sepset)) == NULL)
savept = 0;
else {
*r = '\0';
p = r + strspn(r, sepset);
savept = (p > r)? ++p: ++r;
}
return(q);
}

View File

@ -0,0 +1,18 @@
/* @[$] swab.c 2.1 09/12/83 11:33:27 - 87wega3.2 */
/*
* Swap bytes in 16-bit [half-]words
* for going between the 11 and the interdata
*/
swab(pf, pt, n)
register short *pf, *pt;
register n;
{
n /= 2;
while (--n >= 0) {
*pt++ = (*pf << 8) + ((*pf >> 8) & 0377);
pf++;
}
}

View File

@ -0,0 +1,62 @@
/* @[$] ttyname.c 2.1 09/12/83 11:34:46 - 87wega3.2 */
/*
* ttyname(f): return "/dev/ttyXX" which the the name of the
* tty belonging to file f.
*
* This program works in two passes: the first pass tries to
* find the device by matchine device and inode numbers; if
* that doesn't work, it tries a second time, this time doing a
* stat on every file in /dev and trying to match device numbers
* only. If that fails too, NULL is returned.
*/
#define NULL 0
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/stat.h>
static char dev[] = "/dev/";
char *strcpy();
char *strcat();
char *
ttyname(f)
{
struct stat fsb;
struct stat tsb;
struct direct db;
static char rbuf[32];
register df, pass1;
if(isatty(f) == 0)
return(NULL);
if(fstat(f, &fsb) < 0)
return(NULL);
if((fsb.st_mode & S_IFMT) != S_IFCHR)
return(NULL);
if((df = open(dev, 0)) < 0)
return(NULL);
pass1 = 1;
do {
while(read(df, (char *)&db, sizeof(db)) == sizeof(db)) {
if(db.d_ino == 0)
continue;
if(pass1 && db.d_ino != fsb.st_ino)
continue;
strcpy(rbuf, dev);
strcat(rbuf, db.d_name);
if(stat(rbuf, &tsb) < 0)
continue;
if(tsb.st_rdev == fsb.st_rdev
&& (tsb.st_mode&S_IFMT) == S_IFCHR
&& (!pass1 || tsb.st_ino == fsb.st_ino)) {
close(df);
return(rbuf);
}
}
lseek(df, 0L, 0);
} while(pass1--);
close(df);
return(NULL);
}

View File

@ -0,0 +1,47 @@
/* @[$] ttyslot.c 2.2 09/12/83 11:35:07 - 87wega3.2 */
/*
* Return the number of the slot in the utmp file
* corresponding to the current user: try for file 0, 1, 2.
* Returns -1 if slot not found.
*/
#include <utmp.h>
char *ttyname();
char *strrchr();
static char utmp[] = "/etc/utmp";
#define NULL 0
ttyslot()
{
register char *tp, *p;
register int s, fd;
struct utmp ubuf;
if ((tp=ttyname(0))==NULL
&& (tp=ttyname(1))==NULL
&& (tp=ttyname(2))==NULL)
return -1;
if ((p = strrchr(tp, '/')) == NULL)
p = tp;
else
p++;
if ((fd=open(utmp, 0)) < 0)
return -1;
s = 0;
while (read (fd, (char *) &ubuf, sizeof ubuf) == sizeof ubuf) {
if (strncmp (p, ubuf.ut_line, sizeof ubuf.ut_line)==0) {
close(fd);
return s;
}
s++;
}
close(fd);
return -1;
}