Update basename, cal, cat, cb, chgrp, chmod, cmp, col, comm, cp, dd.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
main(argc, argv)
|
||||
int main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
register char *p1, *p2, *p3;
|
||||
|
||||
@@ -11,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;
|
||||
}
|
||||
|
||||
@@ -9,20 +9,24 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* #define OPTSIZE BUFSIZ /* define this only if not 4.2 BSD or beyond */
|
||||
// #define OPTSIZE BUFSIZ /* define this only if not 4.2 BSD or beyond */
|
||||
|
||||
int bflg, eflg, nflg, sflg, tflg, uflg, vflg;
|
||||
int spaced, col, lno, inlin, ibsize, obsize;
|
||||
|
||||
main(argc, argv)
|
||||
static void copyopt(FILE *f);
|
||||
static int fastcat(int fd);
|
||||
|
||||
int main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
int fflg = 0;
|
||||
register FILE *fi;
|
||||
register c;
|
||||
FILE *fi;
|
||||
int c;
|
||||
int dev, ino = -1;
|
||||
struct stat statb;
|
||||
int retval = 0;
|
||||
@@ -121,10 +125,10 @@ char **argv;
|
||||
exit(retval);
|
||||
}
|
||||
|
||||
copyopt(f)
|
||||
register FILE *f;
|
||||
void copyopt(f)
|
||||
FILE *f;
|
||||
{
|
||||
register int c;
|
||||
int c;
|
||||
|
||||
top:
|
||||
c = getc(f);
|
||||
@@ -168,11 +172,11 @@ top:
|
||||
goto top;
|
||||
}
|
||||
|
||||
fastcat(fd)
|
||||
register int fd;
|
||||
int fastcat(fd)
|
||||
int fd;
|
||||
{
|
||||
register int buffsize, n, nwritten, offset;
|
||||
register char *buff;
|
||||
int buffsize, n, nwritten, offset;
|
||||
char *buff;
|
||||
struct stat statbuff;
|
||||
|
||||
#ifndef OPTSIZE
|
||||
|
||||
278
src/cmd/cb.c
278
src/cmd/cb.c
@@ -1,104 +1,107 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int slevel[10];
|
||||
int clevel = 0;
|
||||
int clevel = 0;
|
||||
int spflg[20][10];
|
||||
int sind[20][10];
|
||||
int siflev[10];
|
||||
int sifflg[10];
|
||||
int iflev = 0;
|
||||
int ifflg = -1;
|
||||
int level = 0;
|
||||
int ind[10] = {
|
||||
0,0,0,0,0,0,0,0,0,0 };
|
||||
int eflg = 0;
|
||||
int paren = 0;
|
||||
int pflg[10] = {
|
||||
0,0,0,0,0,0,0,0,0,0 };
|
||||
char lchar;
|
||||
char pchar;
|
||||
int aflg = 0;
|
||||
int iflev = 0;
|
||||
int ifflg = -1;
|
||||
int level = 0;
|
||||
int ind[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
int eflg = 0;
|
||||
int paren = 0;
|
||||
int pflg[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
char lchar;
|
||||
char pchar;
|
||||
int aflg = 0;
|
||||
int ct;
|
||||
int stabs[20][10];
|
||||
int qflg = 0;
|
||||
char *wif[] = {
|
||||
"if",0};
|
||||
char *welse[] = {
|
||||
"else",0};
|
||||
char *wfor[] = {
|
||||
"for",0};
|
||||
char *wds[] = {
|
||||
"case","default",0};
|
||||
int j = 0;
|
||||
char string[200];
|
||||
char cc;
|
||||
int sflg = 1;
|
||||
int peek = -1;
|
||||
int tabs = 0;
|
||||
int qflg = 0;
|
||||
char *wif[] = { "if", 0 };
|
||||
char *welse[] = { "else", 0 };
|
||||
char *wfor[] = { "for", 0 };
|
||||
char *wds[] = { "case", "default", 0 };
|
||||
int j = 0;
|
||||
char string[200];
|
||||
char cc;
|
||||
int sflg = 1;
|
||||
int peek = -1;
|
||||
int tabs = 0;
|
||||
int lastchar;
|
||||
int c;
|
||||
int getstr();
|
||||
|
||||
putstr()
|
||||
static void ptabs(void);
|
||||
static int getch(void);
|
||||
static int lookup(char *tab[]);
|
||||
static void gotelse(void);
|
||||
static int getnl(void);
|
||||
static void comment(void);
|
||||
static int getstr(void);
|
||||
|
||||
void putstr()
|
||||
{
|
||||
if(j > 0){
|
||||
if(sflg != 0){
|
||||
if (j > 0) {
|
||||
if (sflg != 0) {
|
||||
ptabs();
|
||||
sflg = 0;
|
||||
if(aflg == 1){
|
||||
if (aflg == 1) {
|
||||
aflg = 0;
|
||||
if(tabs > 0)printf(" ");
|
||||
if (tabs > 0)
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
string[j] = '\0';
|
||||
printf("%s",string);
|
||||
printf("%s", string);
|
||||
j = 0;
|
||||
}
|
||||
else{
|
||||
if(sflg != 0){
|
||||
} else {
|
||||
if (sflg != 0) {
|
||||
sflg = 0;
|
||||
aflg = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char argv[];
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
while((c = getch()) != EOF){
|
||||
switch(c){
|
||||
while ((c = getch()) != EOF) {
|
||||
switch (c) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
if(lookup(welse) == 1){
|
||||
if (lookup(welse) == 1) {
|
||||
gotelse();
|
||||
if(sflg == 0 || j > 0)string[j++] = c;
|
||||
if (sflg == 0 || j > 0)
|
||||
string[j++] = c;
|
||||
putstr();
|
||||
sflg = 0;
|
||||
continue;
|
||||
}
|
||||
if(sflg == 0 || j > 0)string[j++] = c;
|
||||
if (sflg == 0 || j > 0)
|
||||
string[j++] = c;
|
||||
continue;
|
||||
case '\n':
|
||||
if((eflg = lookup(welse)) == 1)gotelse();
|
||||
if ((eflg = lookup(welse)) == 1)
|
||||
gotelse();
|
||||
putstr();
|
||||
printf("\n");
|
||||
sflg = 1;
|
||||
if(eflg == 1){
|
||||
if (eflg == 1) {
|
||||
pflg[level]++;
|
||||
tabs++;
|
||||
}
|
||||
else
|
||||
if(pchar == lchar)
|
||||
aflg = 1;
|
||||
} else if (pchar == lchar)
|
||||
aflg = 1;
|
||||
continue;
|
||||
case '{':
|
||||
if(lookup(welse) == 1)gotelse();
|
||||
if (lookup(welse) == 1)
|
||||
gotelse();
|
||||
siflev[clevel] = iflev;
|
||||
sifflg[clevel] = ifflg;
|
||||
iflev = ifflg = 0;
|
||||
clevel++;
|
||||
if(sflg == 1 && pflg[level] != 0){
|
||||
if (sflg == 1 && pflg[level] != 0) {
|
||||
pflg[level]--;
|
||||
tabs--;
|
||||
}
|
||||
@@ -109,7 +112,7 @@ main(argc, argv)
|
||||
printf("\n");
|
||||
tabs++;
|
||||
sflg = 1;
|
||||
if(pflg[level] > 0){
|
||||
if (pflg[level] > 0) {
|
||||
ind[level] = 1;
|
||||
level++;
|
||||
slevel[level] = clevel;
|
||||
@@ -117,26 +120,29 @@ main(argc, argv)
|
||||
continue;
|
||||
case '}':
|
||||
clevel--;
|
||||
if((iflev = siflev[clevel]-1) < 0)iflev = 0;
|
||||
if ((iflev = siflev[clevel] - 1) < 0)
|
||||
iflev = 0;
|
||||
ifflg = sifflg[clevel];
|
||||
if(pflg[level] >0 && ind[level] == 0){
|
||||
if (pflg[level] > 0 && ind[level] == 0) {
|
||||
tabs -= pflg[level];
|
||||
pflg[level] = 0;
|
||||
}
|
||||
putstr();
|
||||
tabs--;
|
||||
ptabs();
|
||||
if((peek = getch()) == ';'){
|
||||
printf("%c;",c);
|
||||
if ((peek = getch()) == ';') {
|
||||
printf("%c;", c);
|
||||
peek = -1;
|
||||
}
|
||||
else printf("%c",c);
|
||||
} else
|
||||
printf("%c", c);
|
||||
getnl();
|
||||
putstr();
|
||||
printf("\n");
|
||||
sflg = 1;
|
||||
if(clevel < slevel[level])if(level > 0)level--;
|
||||
if(ind[level] != 0){
|
||||
if (clevel < slevel[level])
|
||||
if (level > 0)
|
||||
level--;
|
||||
if (ind[level] != 0) {
|
||||
tabs -= pflg[level];
|
||||
pflg[level] = 0;
|
||||
ind[level] = 0;
|
||||
@@ -145,18 +151,18 @@ main(argc, argv)
|
||||
case '"':
|
||||
case '\'':
|
||||
string[j++] = c;
|
||||
while((cc = getch()) != c){
|
||||
while ((cc = getch()) != c) {
|
||||
string[j++] = cc;
|
||||
if(cc == '\\'){
|
||||
if (cc == '\\') {
|
||||
string[j++] = getch();
|
||||
}
|
||||
if(cc == '\n'){
|
||||
if (cc == '\n') {
|
||||
putstr();
|
||||
sflg = 1;
|
||||
}
|
||||
}
|
||||
string[j++] = cc;
|
||||
if(getnl() == 1){
|
||||
if (getnl() == 1) {
|
||||
lchar = cc;
|
||||
peek = '\n';
|
||||
}
|
||||
@@ -164,7 +170,7 @@ main(argc, argv)
|
||||
case ';':
|
||||
string[j++] = c;
|
||||
putstr();
|
||||
if(pflg[level] > 0 && ind[level] == 0){
|
||||
if (pflg[level] > 0 && ind[level] == 0) {
|
||||
tabs -= pflg[level];
|
||||
pflg[level] = 0;
|
||||
}
|
||||
@@ -172,11 +178,14 @@ main(argc, argv)
|
||||
putstr();
|
||||
printf("\n");
|
||||
sflg = 1;
|
||||
if(iflev > 0)
|
||||
if(ifflg == 1){iflev--;
|
||||
if (iflev > 0) {
|
||||
if (ifflg == 1) {
|
||||
iflev--;
|
||||
ifflg = 0;
|
||||
} else {
|
||||
iflev = 0;
|
||||
}
|
||||
else iflev = 0;
|
||||
}
|
||||
continue;
|
||||
case '\\':
|
||||
string[j++] = c;
|
||||
@@ -188,20 +197,19 @@ main(argc, argv)
|
||||
continue;
|
||||
case ':':
|
||||
string[j++] = c;
|
||||
if(qflg == 1){
|
||||
if (qflg == 1) {
|
||||
qflg = 0;
|
||||
continue;
|
||||
}
|
||||
if(lookup(wds) == 0){
|
||||
if (lookup(wds) == 0) {
|
||||
sflg = 0;
|
||||
putstr();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
tabs--;
|
||||
putstr();
|
||||
tabs++;
|
||||
}
|
||||
if((peek = getch()) == ';'){
|
||||
if ((peek = getch()) == ';') {
|
||||
printf(";");
|
||||
peek = -1;
|
||||
}
|
||||
@@ -212,7 +220,8 @@ main(argc, argv)
|
||||
continue;
|
||||
case '/':
|
||||
string[j++] = c;
|
||||
if((peek = getch()) != '*')continue;
|
||||
if ((peek = getch()) != '*')
|
||||
continue;
|
||||
string[j++] = peek;
|
||||
peek = -1;
|
||||
comment();
|
||||
@@ -221,10 +230,11 @@ main(argc, argv)
|
||||
paren--;
|
||||
string[j++] = c;
|
||||
putstr();
|
||||
if(getnl() == 1){
|
||||
if (getnl() == 1) {
|
||||
peek = '\n';
|
||||
if(paren != 0)aflg = 1;
|
||||
else if(tabs > 0){
|
||||
if (paren != 0)
|
||||
aflg = 1;
|
||||
else if (tabs > 0) {
|
||||
pflg[level]++;
|
||||
tabs++;
|
||||
ind[level] = 0;
|
||||
@@ -233,7 +243,8 @@ main(argc, argv)
|
||||
continue;
|
||||
case '#':
|
||||
string[j++] = c;
|
||||
while((cc = getch()) != '\n')string[j++] = cc;
|
||||
while ((cc = getch()) != '\n')
|
||||
string[j++] = cc;
|
||||
string[j++] = cc;
|
||||
sflg = 0;
|
||||
putstr();
|
||||
@@ -242,20 +253,22 @@ main(argc, argv)
|
||||
case '(':
|
||||
string[j++] = c;
|
||||
paren++;
|
||||
if(lookup(wfor) == 1){
|
||||
while((c = getstr()) != ';');
|
||||
ct=0;
|
||||
cont:
|
||||
while((c = getstr()) != ')'){
|
||||
if(c == '(') ct++;
|
||||
if (lookup(wfor) == 1) {
|
||||
while ((c = getstr()) != ';')
|
||||
;
|
||||
ct = 0;
|
||||
cont:
|
||||
while ((c = getstr()) != ')') {
|
||||
if (c == '(')
|
||||
ct++;
|
||||
}
|
||||
if(ct != 0){
|
||||
if (ct != 0) {
|
||||
ct--;
|
||||
goto cont;
|
||||
}
|
||||
paren--;
|
||||
putstr();
|
||||
if(getnl() == 1){
|
||||
if (getnl() == 1) {
|
||||
peek = '\n';
|
||||
pflg[level]++;
|
||||
tabs++;
|
||||
@@ -263,7 +276,7 @@ cont:
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(lookup(wif) == 1){
|
||||
if (lookup(wif) == 1) {
|
||||
putstr();
|
||||
stabs[clevel][iflev] = tabs;
|
||||
spflg[clevel][iflev] = pflg[level];
|
||||
@@ -274,62 +287,71 @@ cont:
|
||||
continue;
|
||||
default:
|
||||
string[j++] = c;
|
||||
if(c != ',')lchar = c;
|
||||
if (c != ',')
|
||||
lchar = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ptabs()
|
||||
void ptabs()
|
||||
{
|
||||
int i;
|
||||
for(i=0; i < tabs; i++)printf("\t");
|
||||
for (i = 0; i < tabs; i++)
|
||||
printf("\t");
|
||||
}
|
||||
|
||||
getch()
|
||||
int getch()
|
||||
{
|
||||
if(peek < 0 && lastchar != ' ' && lastchar != '\t')pchar = lastchar;
|
||||
lastchar = (peek<0) ? getc(stdin):peek;
|
||||
if (peek < 0 && lastchar != ' ' && lastchar != '\t')
|
||||
pchar = lastchar;
|
||||
lastchar = (peek < 0) ? getc(stdin) : peek;
|
||||
peek = -1;
|
||||
return(lastchar);
|
||||
return (lastchar);
|
||||
}
|
||||
|
||||
lookup(tab)
|
||||
char *tab[];
|
||||
int lookup(tab)
|
||||
char *tab[];
|
||||
{
|
||||
char r;
|
||||
int l,kk,k,i;
|
||||
if(j < 1)return(0);
|
||||
kk=0;
|
||||
while(string[kk] == ' ')kk++;
|
||||
for(i=0; tab[i] != 0; i++){
|
||||
l=0;
|
||||
for(k=kk;(r = tab[i][l++]) == string[k] && r != '\0';k++);
|
||||
if(r == '\0' && (string[k] < 'a' || string[k] > 'z' || k >= j))return(1);
|
||||
int l, kk, k, i;
|
||||
if (j < 1)
|
||||
return (0);
|
||||
kk = 0;
|
||||
while (string[kk] == ' ')
|
||||
kk++;
|
||||
for (i = 0; tab[i] != 0; i++) {
|
||||
l = 0;
|
||||
for (k = kk; (r = tab[i][l++]) == string[k] && r != '\0'; k++)
|
||||
;
|
||||
if (r == '\0' && (string[k] < 'a' || string[k] > 'z' || k >= j))
|
||||
return (1);
|
||||
}
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
getstr()
|
||||
int getstr()
|
||||
{
|
||||
char ch;
|
||||
beg:
|
||||
if((ch = string[j++] = getch()) == '\\'){
|
||||
if ((ch = string[j++] = getch()) == '\\') {
|
||||
string[j++] = getch();
|
||||
goto beg;
|
||||
}
|
||||
if(ch == '\'' || ch == '"'){
|
||||
while((cc = string[j++] = getch()) != ch)if(cc == '\\')string[j++] = getch();
|
||||
if (ch == '\'' || ch == '"') {
|
||||
while ((cc = string[j++] = getch()) != ch)
|
||||
if (cc == '\\')
|
||||
string[j++] = getch();
|
||||
goto beg;
|
||||
}
|
||||
if(ch == '\n'){
|
||||
if (ch == '\n') {
|
||||
putstr();
|
||||
aflg = 1;
|
||||
goto beg;
|
||||
}
|
||||
else return(ch);
|
||||
} else
|
||||
return (ch);
|
||||
}
|
||||
|
||||
gotelse()
|
||||
void gotelse()
|
||||
{
|
||||
tabs = stabs[clevel][iflev];
|
||||
pflg[level] = spflg[clevel][iflev];
|
||||
@@ -337,38 +359,38 @@ gotelse()
|
||||
ifflg = 1;
|
||||
}
|
||||
|
||||
getnl()
|
||||
int getnl()
|
||||
{
|
||||
while((peek = getch()) == '\t' || peek == ' '){
|
||||
while ((peek = getch()) == '\t' || peek == ' ') {
|
||||
string[j++] = peek;
|
||||
peek = -1;
|
||||
}
|
||||
if((peek = getch()) == '/'){
|
||||
if ((peek = getch()) == '/') {
|
||||
peek = -1;
|
||||
if((peek = getch()) == '*'){
|
||||
if ((peek = getch()) == '*') {
|
||||
string[j++] = '/';
|
||||
string[j++] = '*';
|
||||
peek = -1;
|
||||
comment();
|
||||
}
|
||||
else string[j++] = '/';
|
||||
} else
|
||||
string[j++] = '/';
|
||||
}
|
||||
if((peek = getch()) == '\n'){
|
||||
if ((peek = getch()) == '\n') {
|
||||
peek = -1;
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
comment()
|
||||
void comment()
|
||||
{
|
||||
int i = j;
|
||||
|
||||
while ((c = getch()) != EOF) {
|
||||
string[j++] = c;
|
||||
switch(c) {
|
||||
switch (c) {
|
||||
case '/':
|
||||
if (j > i + 1 && string[j-2] == '*')
|
||||
if (j > i + 1 && string[j - 2] == '*')
|
||||
return;
|
||||
break;
|
||||
case '\n':
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/dir.h>
|
||||
|
||||
struct group *gr;
|
||||
@@ -27,12 +30,18 @@ int status;
|
||||
int fflag, rflag;
|
||||
static char *fchdirmsg = "Can't fchdir() back to starting directory";
|
||||
|
||||
main(argc, argv)
|
||||
static void fatal(int status, char *fmt, ...);
|
||||
static int isnumber(char *s);
|
||||
static int Perror(char *s);
|
||||
static int error(char *fmt, ...);
|
||||
static int chownr(char *dir, uid_t uid, gid_t gid, int savedir);
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
register c, i;
|
||||
register char *cp;
|
||||
int c, i;
|
||||
char *cp;
|
||||
int fcurdir;
|
||||
|
||||
argc--, argv++;
|
||||
@@ -107,25 +116,25 @@ ok:
|
||||
exit(status);
|
||||
}
|
||||
|
||||
isnumber(s)
|
||||
int isnumber(s)
|
||||
char *s;
|
||||
{
|
||||
register int c;
|
||||
int c;
|
||||
|
||||
while (c = *s++)
|
||||
while ((c = *s++))
|
||||
if (!isdigit(c))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
chownr(dir, uid, gid, savedir)
|
||||
int chownr(dir, uid, gid, savedir)
|
||||
char *dir;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
int savedir;
|
||||
{
|
||||
register DIR *dirp;
|
||||
register struct direct *dp;
|
||||
DIR *dirp;
|
||||
struct direct *dp;
|
||||
struct stat st;
|
||||
int ecode;
|
||||
|
||||
@@ -173,33 +182,37 @@ chownr(dir, uid, gid, savedir)
|
||||
return (ecode);
|
||||
}
|
||||
|
||||
error(fmt, a)
|
||||
char *fmt, *a;
|
||||
int verror(char *fmt, va_list args)
|
||||
{
|
||||
|
||||
if (!fflag) {
|
||||
fprintf(stderr, "chgrp: ");
|
||||
fprintf(stderr, fmt, a);
|
||||
vfprintf(stderr, fmt, args);
|
||||
putc('\n', stderr);
|
||||
}
|
||||
return (!fflag);
|
||||
}
|
||||
|
||||
/* VARARGS */
|
||||
fatal(status, fmt, a)
|
||||
int status;
|
||||
char *fmt, *a;
|
||||
int error(char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int status = verror(fmt, args);
|
||||
va_end(args);
|
||||
return status;
|
||||
}
|
||||
|
||||
void fatal(int status, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fflag = 0;
|
||||
(void) error(fmt, a);
|
||||
verror(fmt, args);
|
||||
va_end(args);
|
||||
exit(status);
|
||||
}
|
||||
|
||||
Perror(s)
|
||||
char *s;
|
||||
int Perror(char *s)
|
||||
{
|
||||
|
||||
if (!fflag) {
|
||||
fprintf(stderr, "chgrp: ");
|
||||
perror(s);
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -24,11 +27,21 @@ int status;
|
||||
int fflag;
|
||||
int rflag;
|
||||
|
||||
main(argc, argv)
|
||||
static void fatal(int status, char *fmt, ...);
|
||||
static int Perror(char *s);
|
||||
static int error(char *fmt, ...);
|
||||
static int newmode(unsigned nm);
|
||||
static int chmodr(char *dir, int mode, int savedir);
|
||||
static int abss(void);
|
||||
static int who(void);
|
||||
static int what(void);
|
||||
static int where(int om);
|
||||
|
||||
int main(argc, argv)
|
||||
char *argv[];
|
||||
{
|
||||
register char *p, *flags;
|
||||
register int i;
|
||||
char *p, *flags;
|
||||
int i;
|
||||
struct stat st;
|
||||
int fcurdir;
|
||||
|
||||
@@ -89,13 +102,13 @@ done:
|
||||
exit(status);
|
||||
}
|
||||
|
||||
chmodr(dir, mode, savedir)
|
||||
int chmodr(dir, mode, savedir)
|
||||
char *dir;
|
||||
int mode;
|
||||
int savedir;
|
||||
{
|
||||
register DIR *dirp;
|
||||
register struct direct *dp;
|
||||
DIR *dirp;
|
||||
struct direct *dp;
|
||||
struct stat st;
|
||||
int ecode;
|
||||
|
||||
@@ -140,32 +153,37 @@ chmodr(dir, mode, savedir)
|
||||
return (ecode);
|
||||
}
|
||||
|
||||
error(fmt, a)
|
||||
char *fmt, *a;
|
||||
int verror(char *fmt, va_list args)
|
||||
{
|
||||
|
||||
if (!fflag) {
|
||||
fprintf(stderr, "chmod: ");
|
||||
fprintf(stderr, fmt, a);
|
||||
vfprintf(stderr, fmt, args);
|
||||
putc('\n', stderr);
|
||||
}
|
||||
return (!fflag);
|
||||
}
|
||||
|
||||
fatal(status, fmt, a)
|
||||
int status;
|
||||
char *fmt, *a;
|
||||
int error(char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int status = verror(fmt, args);
|
||||
va_end(args);
|
||||
return status;
|
||||
}
|
||||
|
||||
void fatal(int status, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fflag = 0;
|
||||
(void) error(fmt, a);
|
||||
verror(fmt, args);
|
||||
va_end(args);
|
||||
exit(status);
|
||||
}
|
||||
|
||||
Perror(s)
|
||||
char *s;
|
||||
int Perror(char *s)
|
||||
{
|
||||
|
||||
if (!fflag) {
|
||||
fprintf(stderr, "chmod: ");
|
||||
perror(s);
|
||||
@@ -173,10 +191,10 @@ Perror(s)
|
||||
return (!fflag);
|
||||
}
|
||||
|
||||
newmode(nm)
|
||||
int newmode(nm)
|
||||
unsigned nm;
|
||||
{
|
||||
register o, m, b;
|
||||
int o, m, b;
|
||||
int savem;
|
||||
|
||||
ms = modestring;
|
||||
@@ -186,7 +204,7 @@ newmode(nm)
|
||||
return (m);
|
||||
do {
|
||||
m = who();
|
||||
while (o = what()) {
|
||||
while ((o = what())) {
|
||||
b = where(nm);
|
||||
switch (o) {
|
||||
case '+':
|
||||
@@ -207,9 +225,9 @@ newmode(nm)
|
||||
return (nm);
|
||||
}
|
||||
|
||||
abss()
|
||||
int abss()
|
||||
{
|
||||
register c, i;
|
||||
int c, i;
|
||||
|
||||
i = 0;
|
||||
while ((c = *ms++) >= '0' && c <= '7')
|
||||
@@ -229,9 +247,9 @@ abss()
|
||||
#define SETID 06000 /* set[ug]id */
|
||||
#define STICKY 01000 /* sticky bit */
|
||||
|
||||
who()
|
||||
int who()
|
||||
{
|
||||
register m;
|
||||
int m;
|
||||
|
||||
m = 0;
|
||||
for (;;) switch (*ms++) {
|
||||
@@ -255,7 +273,7 @@ who()
|
||||
}
|
||||
}
|
||||
|
||||
what()
|
||||
int what()
|
||||
{
|
||||
|
||||
switch (*ms) {
|
||||
@@ -267,10 +285,10 @@ what()
|
||||
return (0);
|
||||
}
|
||||
|
||||
where(om)
|
||||
register om;
|
||||
int where(om)
|
||||
int om;
|
||||
{
|
||||
register m;
|
||||
int m;
|
||||
|
||||
m = 0;
|
||||
switch (*ms) {
|
||||
|
||||
134
src/cmd/cmp.c
134
src/cmd/cmp.c
@@ -9,34 +9,36 @@
|
||||
* software without specific written prior permission. This software
|
||||
* is provided ``as is'' without express or implied warranty.
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define DIFF 1 /* found differences */
|
||||
#define ERR 2 /* error during run */
|
||||
#define NO 0 /* no/false */
|
||||
#define OK 0 /* didn't find differences */
|
||||
#define YES 1 /* yes/true */
|
||||
#define DIFF 1 /* found differences */
|
||||
#define ERR 2 /* error during run */
|
||||
#define NO 0 /* no/false */
|
||||
#define OK 0 /* didn't find differences */
|
||||
#define YES 1 /* yes/true */
|
||||
|
||||
static int fd1, fd2, /* file descriptors */
|
||||
silent = NO; /* if silent run */
|
||||
static short all = NO; /* if report all differences */
|
||||
static u_char buf1[MAXBSIZE], /* read buffers */
|
||||
buf2[MAXBSIZE];
|
||||
static char *file1, *file2; /* file names */
|
||||
static int fd1, fd2, /* file descriptors */
|
||||
silent = NO; /* if silent run */
|
||||
static short all = NO; /* if report all differences */
|
||||
static u_char buf1[MAXBSIZE], /* read buffers */
|
||||
buf2[MAXBSIZE];
|
||||
static char *file1, *file2; /* file names */
|
||||
|
||||
/*
|
||||
* error --
|
||||
* print I/O error message and die
|
||||
*/
|
||||
static
|
||||
error(filename)
|
||||
char *filename;
|
||||
static void error(char *filename)
|
||||
{
|
||||
extern int errno;
|
||||
int sverrno;
|
||||
@@ -54,9 +56,7 @@ error(filename)
|
||||
* endoffile --
|
||||
* print end-of-file message and exit indicating the files were different
|
||||
*/
|
||||
static
|
||||
endoffile(filename)
|
||||
char *filename;
|
||||
static void endoffile(char *filename)
|
||||
{
|
||||
/* 32V put this message on stdout, S5 does it on stderr. */
|
||||
if (!silent)
|
||||
@@ -68,14 +68,13 @@ endoffile(filename)
|
||||
* skip --
|
||||
* skip first part of file
|
||||
*/
|
||||
static
|
||||
skip(dist, fd, fname)
|
||||
register u_long dist; /* length in bytes, to skip */
|
||||
register int fd; /* file descriptor */
|
||||
char *fname; /* file name for error */
|
||||
static void skip(
|
||||
u_long dist, /* length in bytes, to skip */
|
||||
int fd, /* file descriptor */
|
||||
char *fname) /* file name for error */
|
||||
{
|
||||
register int rlen; /* read length */
|
||||
register int nread;
|
||||
register int rlen; /* read length */
|
||||
register int nread;
|
||||
|
||||
for (; dist; dist -= rlen) {
|
||||
rlen = MIN(dist, sizeof(buf1));
|
||||
@@ -88,18 +87,17 @@ skip(dist, fd, fname)
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
cmp()
|
||||
static void cmp()
|
||||
{
|
||||
register u_char *C1, *C2; /* traveling pointers */
|
||||
register int cnt, /* counter */
|
||||
len1, len2; /* read lengths */
|
||||
register long byte, /* byte count */
|
||||
line; /* line count */
|
||||
short dfound = NO; /* if difference found */
|
||||
register u_char *C1, *C2; /* traveling pointers */
|
||||
register int cnt, /* counter */
|
||||
len1, len2; /* read lengths */
|
||||
register long byte, /* byte count */
|
||||
line; /* line count */
|
||||
short dfound = NO; /* if difference found */
|
||||
|
||||
for (byte = 0, line = 1;;) {
|
||||
switch(len1 = read(fd1, buf1, MAXBSIZE)) {
|
||||
switch (len1 = read(fd1, buf1, MAXBSIZE)) {
|
||||
case -1:
|
||||
error(file1);
|
||||
case 0:
|
||||
@@ -107,13 +105,13 @@ cmp()
|
||||
* read of file 1 just failed, find out
|
||||
* if there's anything left in file 2
|
||||
*/
|
||||
switch(read(fd2, buf2, 1)) {
|
||||
case -1:
|
||||
error(file2);
|
||||
case 0:
|
||||
exit(dfound ? DIFF : OK);
|
||||
default:
|
||||
endoffile(file1);
|
||||
switch (read(fd2, buf2, 1)) {
|
||||
case -1:
|
||||
error(file2);
|
||||
case 0:
|
||||
exit(dfound ? DIFF : OK);
|
||||
default:
|
||||
endoffile(file1);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@@ -133,18 +131,17 @@ cmp()
|
||||
if (*C1 != *C2)
|
||||
printf("%6ld %3o %3o\n", byte, *C1, *C2);
|
||||
}
|
||||
}
|
||||
else for (C1 = buf1, C2 = buf2;; ++C1, ++C2) {
|
||||
++byte;
|
||||
if (*C1 != *C2) {
|
||||
printf("%s %s differ: char %ld, line %ld\n", file1, file2, byte, line);
|
||||
exit(DIFF);
|
||||
} else
|
||||
for (C1 = buf1, C2 = buf2;; ++C1, ++C2) {
|
||||
++byte;
|
||||
if (*C1 != *C2) {
|
||||
printf("%s %s differ: char %ld, line %ld\n", file1, file2, byte, line);
|
||||
exit(DIFF);
|
||||
}
|
||||
if (*C1 == '\n')
|
||||
++line;
|
||||
}
|
||||
if (*C1 == '\n')
|
||||
++line;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
byte += len2;
|
||||
/*
|
||||
* here's the real performance problem, we've got to
|
||||
@@ -171,44 +168,37 @@ cmp()
|
||||
* otoi --
|
||||
* octal/decimal string to u_long
|
||||
*/
|
||||
static u_long
|
||||
otoi(C)
|
||||
register char *C; /* argument string */
|
||||
static u_long otoi(char *C)
|
||||
{
|
||||
register u_long val; /* return value */
|
||||
register int base; /* number base */
|
||||
register u_long val; /* return value */
|
||||
register int base; /* number base */
|
||||
|
||||
base = (*C == '0') ? 8 : 10;
|
||||
for (val = 0; isdigit(*C); ++C)
|
||||
val = val * base + *C - '0';
|
||||
return(val);
|
||||
return (val);
|
||||
}
|
||||
|
||||
/*
|
||||
* usage --
|
||||
* print usage and die
|
||||
*/
|
||||
static
|
||||
usage()
|
||||
static void usage()
|
||||
{
|
||||
fputs("usage: cmp [-ls] file1 file2 [skip1] [skip2]\n", stderr);
|
||||
exit(ERR);
|
||||
}
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "ls")) != EOF)
|
||||
switch(ch) {
|
||||
case 'l': /* print all differences */
|
||||
switch (ch) {
|
||||
case 'l': /* print all differences */
|
||||
all = YES;
|
||||
break;
|
||||
case 's': /* silent run */
|
||||
case 's': /* silent run */
|
||||
silent = YES;
|
||||
break;
|
||||
case '?':
|
||||
|
||||
@@ -18,23 +18,27 @@ int cp, lp;
|
||||
int ll, llh, mustwr;
|
||||
int pcp = 0;
|
||||
char *pgmname;
|
||||
char *strcpy();
|
||||
|
||||
main (argc, argv)
|
||||
static void incr(void);
|
||||
static void decr(void);
|
||||
static void outc(char c);
|
||||
static void emit(char *s, int lineno);
|
||||
|
||||
int main(argc, argv)
|
||||
int argc; char **argv;
|
||||
{
|
||||
int i;
|
||||
int greek;
|
||||
register int c;
|
||||
int c;
|
||||
|
||||
pgmname = argv[0];
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
register char *p;
|
||||
char *p;
|
||||
if (*argv[i] != '-') {
|
||||
fprintf (stderr, "%s: bad option %s\n",
|
||||
fprintf(stderr, "%s: bad option %s\n",
|
||||
pgmname, argv[i]);
|
||||
exit (2);
|
||||
exit(2);
|
||||
}
|
||||
for (p = argv[i]+1; *p; p++) {
|
||||
switch (*p) {
|
||||
@@ -51,9 +55,9 @@ main (argc, argv)
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf (stderr, "%s: bad option letter %c\n",
|
||||
fprintf(stderr, "%s: bad option letter %c\n",
|
||||
pgmname, *p);
|
||||
exit (2);
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,13 +158,12 @@ main (argc, argv)
|
||||
|
||||
for (i=0; i<PL; i++)
|
||||
if (page[(mustwr+i)%PL] != 0)
|
||||
emit (page[(mustwr+i) % PL], mustwr+i-PL);
|
||||
emit (" ", (llh + 1) & -2);
|
||||
emit(page[(mustwr+i) % PL], mustwr+i-PL);
|
||||
emit(" ", (llh + 1) & -2);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
outc (c)
|
||||
register char c;
|
||||
void outc(char c)
|
||||
{
|
||||
if (lp > cp) {
|
||||
line = lbuff;
|
||||
@@ -189,7 +192,7 @@ outc (c)
|
||||
if (bflag || *line == '\0' || *line == ' ')
|
||||
*line = c;
|
||||
else {
|
||||
register char c1, c2, c3;
|
||||
char c1, c2, c3;
|
||||
c1 = *++line;
|
||||
*line++ = '\b';
|
||||
c2 = *line;
|
||||
@@ -205,22 +208,22 @@ outc (c)
|
||||
}
|
||||
}
|
||||
|
||||
store (lno)
|
||||
void store(lno)
|
||||
{
|
||||
lno %= PL;
|
||||
if (page[lno] != 0)
|
||||
free (page[lno]);
|
||||
free(page[lno]);
|
||||
page[lno] = malloc((unsigned)strlen(lbuff) + 2);
|
||||
if (page[lno] == 0) {
|
||||
fprintf (stderr, "%s: no storage\n", pgmname);
|
||||
exit (2);
|
||||
fprintf(stderr, "%s: no storage\n", pgmname);
|
||||
exit(2);
|
||||
}
|
||||
strcpy (page[lno],lbuff);
|
||||
strcpy(page[lno],lbuff);
|
||||
}
|
||||
|
||||
fetch(lno)
|
||||
void fetch(lno)
|
||||
{
|
||||
register char *p;
|
||||
char *p;
|
||||
|
||||
lno %= PL;
|
||||
p = lbuff;
|
||||
@@ -229,30 +232,31 @@ fetch(lno)
|
||||
line = lbuff;
|
||||
lp = 0;
|
||||
if (page[lno])
|
||||
strcpy (line, page[lno]);
|
||||
strcpy(line, page[lno]);
|
||||
}
|
||||
emit (s, lineno)
|
||||
|
||||
void emit(s, lineno)
|
||||
char *s;
|
||||
int lineno;
|
||||
{
|
||||
static int cline = 0;
|
||||
register int ncp;
|
||||
register char *p;
|
||||
int ncp;
|
||||
char *p;
|
||||
static int gflag = 0;
|
||||
|
||||
if (*s) {
|
||||
while (cline < lineno - 1) {
|
||||
putchar ('\n');
|
||||
putchar('\n');
|
||||
pcp = 0;
|
||||
cline += 2;
|
||||
}
|
||||
if (cline != lineno) {
|
||||
putchar (ESC);
|
||||
putchar ('9');
|
||||
putchar(ESC);
|
||||
putchar('9');
|
||||
cline++;
|
||||
}
|
||||
if (pcp)
|
||||
putchar ('\r');
|
||||
putchar('\r');
|
||||
pcp = 0;
|
||||
p = s;
|
||||
while (*p) {
|
||||
@@ -260,23 +264,23 @@ emit (s, lineno)
|
||||
while (*p++ == ' ') {
|
||||
if ((++ncp & 7) == 0 && hflag) {
|
||||
pcp = ncp;
|
||||
putchar ('\t');
|
||||
putchar('\t');
|
||||
}
|
||||
}
|
||||
if (!*--p)
|
||||
break;
|
||||
while (pcp < ncp) {
|
||||
putchar (' ');
|
||||
putchar(' ');
|
||||
pcp++;
|
||||
}
|
||||
if (gflag != (*p & GREEK) && *p != '\b') {
|
||||
if (gflag)
|
||||
putchar (SI);
|
||||
putchar(SI);
|
||||
else
|
||||
putchar (SO);
|
||||
putchar(SO);
|
||||
gflag ^= GREEK;
|
||||
}
|
||||
putchar (*p & ~GREEK);
|
||||
putchar(*p & ~GREEK);
|
||||
if (*p++ == '\b')
|
||||
pcp--;
|
||||
else
|
||||
@@ -285,24 +289,24 @@ emit (s, lineno)
|
||||
}
|
||||
}
|
||||
|
||||
incr()
|
||||
void incr()
|
||||
{
|
||||
store (ll++);
|
||||
store(ll++);
|
||||
if (ll > llh)
|
||||
llh = ll;
|
||||
if (ll >= mustwr && page[ll%PL]) {
|
||||
emit (page[ll%PL], ll - PL);
|
||||
emit(page[ll%PL], ll - PL);
|
||||
mustwr++;
|
||||
free (page[ll%PL]);
|
||||
free(page[ll%PL]);
|
||||
page[ll%PL] = 0;
|
||||
}
|
||||
fetch (ll);
|
||||
fetch(ll);
|
||||
}
|
||||
|
||||
decr()
|
||||
void decr()
|
||||
{
|
||||
if (ll > mustwr - PL) {
|
||||
store (ll--);
|
||||
fetch (ll);
|
||||
store(ll--);
|
||||
fetch(ll);
|
||||
}
|
||||
}
|
||||
|
||||
168
src/cmd/comm.c
168
src/cmd/comm.c
@@ -7,34 +7,38 @@ int one;
|
||||
int two;
|
||||
int three;
|
||||
|
||||
char *ldr[3];
|
||||
char *ldr[3];
|
||||
|
||||
FILE *ib1;
|
||||
FILE *ib2;
|
||||
FILE *openfil();
|
||||
main(argc,argv)
|
||||
char *argv[];
|
||||
|
||||
static FILE *openfil(char *s);
|
||||
static int rd(FILE *file, char *buf);
|
||||
static void wr(char *str, int n);
|
||||
static void copy(FILE *ibuf, char *lbuf, int n);
|
||||
static int compare(char *a, char *b);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int l;
|
||||
char lb1[LB],lb2[LB];
|
||||
char lb1[LB], lb2[LB];
|
||||
|
||||
ldr[0] = "";
|
||||
ldr[1] = "\t";
|
||||
ldr[2] = "\t\t";
|
||||
if(argc > 1) {
|
||||
if(*argv[1] == '-' && argv[1][1] != 0) {
|
||||
if (argc > 1) {
|
||||
if (*argv[1] == '-' && argv[1][1] != 0) {
|
||||
l = 1;
|
||||
while(*++argv[1]) {
|
||||
switch(*argv[1]) {
|
||||
case'1':
|
||||
if(!one) {
|
||||
while (*++argv[1]) {
|
||||
switch (*argv[1]) {
|
||||
case '1':
|
||||
if (!one) {
|
||||
one = 1;
|
||||
ldr[1][0] =
|
||||
ldr[2][l--] = '\0';
|
||||
ldr[1][0] = ldr[2][l--] = '\0';
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
if(!two) {
|
||||
if (!two) {
|
||||
two = 1;
|
||||
ldr[2][l--] = '\0';
|
||||
}
|
||||
@@ -43,8 +47,8 @@ char *argv[];
|
||||
three = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"comm: illegal flag\n");
|
||||
exit(1);
|
||||
fprintf(stderr, "comm: illegal flag\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
argv++;
|
||||
@@ -52,118 +56,118 @@ char *argv[];
|
||||
}
|
||||
}
|
||||
|
||||
if(argc < 3) {
|
||||
fprintf(stderr,"comm: arg count\n");
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "comm: arg count\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ib1 = openfil(argv[1]);
|
||||
ib2 = openfil(argv[2]);
|
||||
|
||||
|
||||
if(rd(ib1,lb1) < 0) {
|
||||
if(rd(ib2,lb2) < 0) exit(0);
|
||||
copy(ib2,lb2,2);
|
||||
if (rd(ib1, lb1) < 0) {
|
||||
if (rd(ib2, lb2) < 0)
|
||||
exit(0);
|
||||
copy(ib2, lb2, 2);
|
||||
}
|
||||
if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
|
||||
if (rd(ib2, lb2) < 0)
|
||||
copy(ib1, lb1, 1);
|
||||
|
||||
while(1) {
|
||||
while (1) {
|
||||
switch (compare(lb1, lb2)) {
|
||||
case 0:
|
||||
wr(lb1, 3);
|
||||
if (rd(ib1, lb1) < 0) {
|
||||
if (rd(ib2, lb2) < 0)
|
||||
exit(0);
|
||||
copy(ib2, lb2, 2);
|
||||
}
|
||||
if (rd(ib2, lb2) < 0)
|
||||
copy(ib1, lb1, 1);
|
||||
continue;
|
||||
|
||||
switch(compare(lb1,lb2)) {
|
||||
case 1:
|
||||
wr(lb1, 1);
|
||||
if (rd(ib1, lb1) < 0)
|
||||
copy(ib2, lb2, 2);
|
||||
continue;
|
||||
|
||||
case 0:
|
||||
wr(lb1,3);
|
||||
if(rd(ib1,lb1) < 0) {
|
||||
if(rd(ib2,lb2) < 0) exit(0);
|
||||
copy(ib2,lb2,2);
|
||||
}
|
||||
if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
|
||||
continue;
|
||||
|
||||
case 1:
|
||||
wr(lb1,1);
|
||||
if(rd(ib1,lb1) < 0) copy(ib2,lb2,2);
|
||||
continue;
|
||||
|
||||
case 2:
|
||||
wr(lb2,2);
|
||||
if(rd(ib2,lb2) < 0) copy(ib1,lb1,1);
|
||||
continue;
|
||||
case 2:
|
||||
wr(lb2, 2);
|
||||
if (rd(ib2, lb2) < 0)
|
||||
copy(ib1, lb1, 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rd(file,buf)
|
||||
FILE *file;
|
||||
char *buf;
|
||||
int rd(FILE *file, char *buf)
|
||||
{
|
||||
int i, c;
|
||||
|
||||
register int i, c;
|
||||
i = 0;
|
||||
while((c = getc(file)) != EOF) {
|
||||
while ((c = getc(file)) != EOF) {
|
||||
*buf = c;
|
||||
if(c == '\n' || i > LB-2) {
|
||||
if (c == '\n' || i > LB - 2) {
|
||||
*buf = '\0';
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
i++;
|
||||
buf++;
|
||||
}
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
wr(str,n)
|
||||
char *str;
|
||||
void wr(char *str, int n)
|
||||
{
|
||||
switch (n) {
|
||||
case 1:
|
||||
if (one)
|
||||
return;
|
||||
break;
|
||||
|
||||
switch(n) {
|
||||
case 2:
|
||||
if (two)
|
||||
return;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if(one) return;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if(two) return;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if(three) return;
|
||||
case 3:
|
||||
if (three)
|
||||
return;
|
||||
}
|
||||
printf("%s%s\n",ldr[n-1],str);
|
||||
printf("%s%s\n", ldr[n - 1], str);
|
||||
}
|
||||
|
||||
copy(ibuf,lbuf,n)
|
||||
FILE *ibuf;
|
||||
char *lbuf;
|
||||
void copy(FILE *ibuf, char *lbuf, int n)
|
||||
{
|
||||
do {
|
||||
wr(lbuf,n);
|
||||
} while(rd(ibuf,lbuf) >= 0);
|
||||
wr(lbuf, n);
|
||||
} while (rd(ibuf, lbuf) >= 0);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
compare(a,b)
|
||||
char *a,*b;
|
||||
int compare(char *a, char *b)
|
||||
{
|
||||
register char *ra,*rb;
|
||||
char *ra, *rb;
|
||||
|
||||
ra = --a;
|
||||
rb = --b;
|
||||
while(*++ra == *++rb)
|
||||
if(*ra == '\0') return(0);
|
||||
if(*ra < *rb) return(1);
|
||||
return(2);
|
||||
while (*++ra == *++rb)
|
||||
if (*ra == '\0')
|
||||
return (0);
|
||||
if (*ra < *rb)
|
||||
return (1);
|
||||
return (2);
|
||||
}
|
||||
FILE *openfil(s)
|
||||
char *s;
|
||||
|
||||
FILE *openfil(char *s)
|
||||
{
|
||||
FILE *b;
|
||||
if(s[0]=='-' && s[1]==0)
|
||||
if (s[0] == '-' && s[1] == 0)
|
||||
b = stdin;
|
||||
else if((b=fopen(s,"r")) == NULL) {
|
||||
else if ((b = fopen(s, "r")) == NULL) {
|
||||
perror(s);
|
||||
exit(1);
|
||||
}
|
||||
return(b);
|
||||
return (b);
|
||||
}
|
||||
|
||||
15
src/cmd/cp.c
15
src/cmd/cp.c
@@ -11,6 +11,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/dir.h>
|
||||
@@ -20,7 +22,12 @@ int iflag;
|
||||
int rflag;
|
||||
int pflag;
|
||||
|
||||
main(argc, argv)
|
||||
static void Perror(char *s);
|
||||
static int copy(char *from, char *to);
|
||||
static int rcopy(char *from, char *to);
|
||||
static int setimes(char *path, struct stat *statp);
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
@@ -67,7 +74,7 @@ usage:
|
||||
exit(1);
|
||||
}
|
||||
|
||||
copy(from, to)
|
||||
int copy(from, to)
|
||||
char *from, *to;
|
||||
{
|
||||
int fold, fnew, n, exists;
|
||||
@@ -172,7 +179,7 @@ copy(from, to)
|
||||
return (0);
|
||||
}
|
||||
|
||||
rcopy(from, to)
|
||||
int rcopy(from, to)
|
||||
char *from, *to;
|
||||
{
|
||||
DIR *fold = opendir(from);
|
||||
@@ -225,7 +232,7 @@ setimes(path, statp)
|
||||
return (0);
|
||||
}
|
||||
|
||||
Perror(s)
|
||||
void Perror(s)
|
||||
char *s;
|
||||
{
|
||||
fprintf(stderr, "cp: ");
|
||||
|
||||
501
src/cmd/dd.c
501
src/cmd/dd.c
@@ -1,26 +1,27 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define BIG 2147483647
|
||||
#define LCASE 01
|
||||
#define UCASE 02
|
||||
#define SWAB 04
|
||||
#define NERR 010
|
||||
#define SYNC 020
|
||||
#define LCASE 01
|
||||
#define UCASE 02
|
||||
#define SWAB 04
|
||||
#define NERR 010
|
||||
#define SYNC 020
|
||||
|
||||
int cflag;
|
||||
int fflag;
|
||||
int skip;
|
||||
int seekn;
|
||||
int count;
|
||||
int files = 1;
|
||||
char *string;
|
||||
char *ifile;
|
||||
char *ofile;
|
||||
char *ibuf;
|
||||
char *obuf;
|
||||
char *sbrk();
|
||||
int files = 1;
|
||||
char *string;
|
||||
char *ifile;
|
||||
char *ofile;
|
||||
char *ibuf;
|
||||
char *obuf;
|
||||
int ibs = 512;
|
||||
int obs = 512;
|
||||
int bs;
|
||||
@@ -35,130 +36,83 @@ int nopr;
|
||||
int ntrunc;
|
||||
int ibf;
|
||||
int obf;
|
||||
char *op;
|
||||
char *op;
|
||||
int nspace;
|
||||
char etoa[] = {
|
||||
0000,0001,0002,0003,0234,0011,0206,0177,
|
||||
0227,0215,0216,0013,0014,0015,0016,0017,
|
||||
0020,0021,0022,0023,0235,0205,0010,0207,
|
||||
0030,0031,0222,0217,0034,0035,0036,0037,
|
||||
0200,0201,0202,0203,0204,0012,0027,0033,
|
||||
0210,0211,0212,0213,0214,0005,0006,0007,
|
||||
0220,0221,0026,0223,0224,0225,0226,0004,
|
||||
0230,0231,0232,0233,0024,0025,0236,0032,
|
||||
0040,0240,0241,0242,0243,0244,0245,0246,
|
||||
0247,0250,0133,0056,0074,0050,0053,0041,
|
||||
0046,0251,0252,0253,0254,0255,0256,0257,
|
||||
0260,0261,0135,0044,0052,0051,0073,0136,
|
||||
0055,0057,0262,0263,0264,0265,0266,0267,
|
||||
0270,0271,0174,0054,0045,0137,0076,0077,
|
||||
0272,0273,0274,0275,0276,0277,0300,0301,
|
||||
0302,0140,0072,0043,0100,0047,0075,0042,
|
||||
0303,0141,0142,0143,0144,0145,0146,0147,
|
||||
0150,0151,0304,0305,0306,0307,0310,0311,
|
||||
0312,0152,0153,0154,0155,0156,0157,0160,
|
||||
0161,0162,0313,0314,0315,0316,0317,0320,
|
||||
0321,0176,0163,0164,0165,0166,0167,0170,
|
||||
0171,0172,0322,0323,0324,0325,0326,0327,
|
||||
0330,0331,0332,0333,0334,0335,0336,0337,
|
||||
0340,0341,0342,0343,0344,0345,0346,0347,
|
||||
0173,0101,0102,0103,0104,0105,0106,0107,
|
||||
0110,0111,0350,0351,0352,0353,0354,0355,
|
||||
0175,0112,0113,0114,0115,0116,0117,0120,
|
||||
0121,0122,0356,0357,0360,0361,0362,0363,
|
||||
0134,0237,0123,0124,0125,0126,0127,0130,
|
||||
0131,0132,0364,0365,0366,0367,0370,0371,
|
||||
0060,0061,0062,0063,0064,0065,0066,0067,
|
||||
0070,0071,0372,0373,0374,0375,0376,0377,
|
||||
char etoa[] = {
|
||||
0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177, 0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017,
|
||||
0020, 0021, 0022, 0023, 0235, 0205, 0010, 0207, 0030, 0031, 0222, 0217, 0034, 0035, 0036, 0037,
|
||||
0200, 0201, 0202, 0203, 0204, 0012, 0027, 0033, 0210, 0211, 0212, 0213, 0214, 0005, 0006, 0007,
|
||||
0220, 0221, 0026, 0223, 0224, 0225, 0226, 0004, 0230, 0231, 0232, 0233, 0024, 0025, 0236, 0032,
|
||||
0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247, 0250, 0133, 0056, 0074, 0050, 0053, 0041,
|
||||
0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257, 0260, 0261, 0135, 0044, 0052, 0051, 0073, 0136,
|
||||
0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267, 0270, 0271, 0174, 0054, 0045, 0137, 0076, 0077,
|
||||
0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301, 0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042,
|
||||
0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147, 0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311,
|
||||
0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160, 0161, 0162, 0313, 0314, 0315, 0316, 0317, 0320,
|
||||
0321, 0176, 0163, 0164, 0165, 0166, 0167, 0170, 0171, 0172, 0322, 0323, 0324, 0325, 0326, 0327,
|
||||
0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
|
||||
0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355,
|
||||
0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120, 0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363,
|
||||
0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130, 0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371,
|
||||
0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, 0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377,
|
||||
};
|
||||
char atoe[] = {
|
||||
0000,0001,0002,0003,0067,0055,0056,0057,
|
||||
0026,0005,0045,0013,0014,0015,0016,0017,
|
||||
0020,0021,0022,0023,0074,0075,0062,0046,
|
||||
0030,0031,0077,0047,0034,0035,0036,0037,
|
||||
0100,0117,0177,0173,0133,0154,0120,0175,
|
||||
0115,0135,0134,0116,0153,0140,0113,0141,
|
||||
0360,0361,0362,0363,0364,0365,0366,0367,
|
||||
0370,0371,0172,0136,0114,0176,0156,0157,
|
||||
0174,0301,0302,0303,0304,0305,0306,0307,
|
||||
0310,0311,0321,0322,0323,0324,0325,0326,
|
||||
0327,0330,0331,0342,0343,0344,0345,0346,
|
||||
0347,0350,0351,0112,0340,0132,0137,0155,
|
||||
0171,0201,0202,0203,0204,0205,0206,0207,
|
||||
0210,0211,0221,0222,0223,0224,0225,0226,
|
||||
0227,0230,0231,0242,0243,0244,0245,0246,
|
||||
0247,0250,0251,0300,0152,0320,0241,0007,
|
||||
0040,0041,0042,0043,0044,0025,0006,0027,
|
||||
0050,0051,0052,0053,0054,0011,0012,0033,
|
||||
0060,0061,0032,0063,0064,0065,0066,0010,
|
||||
0070,0071,0072,0073,0004,0024,0076,0341,
|
||||
0101,0102,0103,0104,0105,0106,0107,0110,
|
||||
0111,0121,0122,0123,0124,0125,0126,0127,
|
||||
0130,0131,0142,0143,0144,0145,0146,0147,
|
||||
0150,0151,0160,0161,0162,0163,0164,0165,
|
||||
0166,0167,0170,0200,0212,0213,0214,0215,
|
||||
0216,0217,0220,0232,0233,0234,0235,0236,
|
||||
0237,0240,0252,0253,0254,0255,0256,0257,
|
||||
0260,0261,0262,0263,0264,0265,0266,0267,
|
||||
0270,0271,0272,0273,0274,0275,0276,0277,
|
||||
0312,0313,0314,0315,0316,0317,0332,0333,
|
||||
0334,0335,0336,0337,0352,0353,0354,0355,
|
||||
0356,0357,0372,0373,0374,0375,0376,0377,
|
||||
char atoe[] = {
|
||||
0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017,
|
||||
0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037,
|
||||
0100, 0117, 0177, 0173, 0133, 0154, 0120, 0175, 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141,
|
||||
0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157,
|
||||
0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326,
|
||||
0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, 0347, 0350, 0351, 0112, 0340, 0132, 0137, 0155,
|
||||
0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226,
|
||||
0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, 0247, 0250, 0251, 0300, 0152, 0320, 0241, 0007,
|
||||
0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033,
|
||||
0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341,
|
||||
0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
|
||||
0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165,
|
||||
0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, 0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236,
|
||||
0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
|
||||
0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333,
|
||||
0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377,
|
||||
};
|
||||
char atoibm[] =
|
||||
{
|
||||
0000,0001,0002,0003,0067,0055,0056,0057,
|
||||
0026,0005,0045,0013,0014,0015,0016,0017,
|
||||
0020,0021,0022,0023,0074,0075,0062,0046,
|
||||
0030,0031,0077,0047,0034,0035,0036,0037,
|
||||
0100,0132,0177,0173,0133,0154,0120,0175,
|
||||
0115,0135,0134,0116,0153,0140,0113,0141,
|
||||
0360,0361,0362,0363,0364,0365,0366,0367,
|
||||
0370,0371,0172,0136,0114,0176,0156,0157,
|
||||
0174,0301,0302,0303,0304,0305,0306,0307,
|
||||
0310,0311,0321,0322,0323,0324,0325,0326,
|
||||
0327,0330,0331,0342,0343,0344,0345,0346,
|
||||
0347,0350,0351,0255,0340,0275,0137,0155,
|
||||
0171,0201,0202,0203,0204,0205,0206,0207,
|
||||
0210,0211,0221,0222,0223,0224,0225,0226,
|
||||
0227,0230,0231,0242,0243,0244,0245,0246,
|
||||
0247,0250,0251,0300,0117,0320,0241,0007,
|
||||
0040,0041,0042,0043,0044,0025,0006,0027,
|
||||
0050,0051,0052,0053,0054,0011,0012,0033,
|
||||
0060,0061,0032,0063,0064,0065,0066,0010,
|
||||
0070,0071,0072,0073,0004,0024,0076,0341,
|
||||
0101,0102,0103,0104,0105,0106,0107,0110,
|
||||
0111,0121,0122,0123,0124,0125,0126,0127,
|
||||
0130,0131,0142,0143,0144,0145,0146,0147,
|
||||
0150,0151,0160,0161,0162,0163,0164,0165,
|
||||
0166,0167,0170,0200,0212,0213,0214,0215,
|
||||
0216,0217,0220,0232,0233,0234,0235,0236,
|
||||
0237,0240,0252,0253,0254,0255,0256,0257,
|
||||
0260,0261,0262,0263,0264,0265,0266,0267,
|
||||
0270,0271,0272,0273,0274,0275,0276,0277,
|
||||
0312,0313,0314,0315,0316,0317,0332,0333,
|
||||
0334,0335,0336,0337,0352,0353,0354,0355,
|
||||
0356,0357,0372,0373,0374,0375,0376,0377,
|
||||
char atoibm[] = {
|
||||
0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, 0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017,
|
||||
0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, 0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037,
|
||||
0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, 0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141,
|
||||
0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, 0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157,
|
||||
0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, 0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326,
|
||||
0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, 0347, 0350, 0351, 0255, 0340, 0275, 0137, 0155,
|
||||
0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, 0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226,
|
||||
0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, 0247, 0250, 0251, 0300, 0117, 0320, 0241, 0007,
|
||||
0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, 0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033,
|
||||
0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, 0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341,
|
||||
0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, 0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
|
||||
0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, 0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165,
|
||||
0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, 0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236,
|
||||
0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
|
||||
0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, 0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333,
|
||||
0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, 0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377,
|
||||
};
|
||||
|
||||
void
|
||||
term(status)
|
||||
int status;
|
||||
static void stats(void);
|
||||
static void null(int c);
|
||||
|
||||
void term(int status)
|
||||
{
|
||||
stats();
|
||||
exit(status);
|
||||
}
|
||||
|
||||
flsh()
|
||||
void flsh()
|
||||
{
|
||||
register c;
|
||||
int c;
|
||||
|
||||
if(obc) {
|
||||
if(obc == obs)
|
||||
nofr++; else
|
||||
if (obc) {
|
||||
if (obc == obs)
|
||||
nofr++;
|
||||
else
|
||||
nopr++;
|
||||
c = write(obf, obuf, obc);
|
||||
if(c != obc) {
|
||||
if (c != obc) {
|
||||
perror("write");
|
||||
term(1);
|
||||
}
|
||||
@@ -166,256 +120,251 @@ flsh()
|
||||
}
|
||||
}
|
||||
|
||||
match(s)
|
||||
char *s;
|
||||
int match(char *s)
|
||||
{
|
||||
register char *cs;
|
||||
char *cs;
|
||||
|
||||
cs = string;
|
||||
while(*cs++ == *s)
|
||||
if(*s++ == '\0')
|
||||
goto true;
|
||||
if(*s != '\0')
|
||||
return(0);
|
||||
while (*cs++ == *s)
|
||||
if (*s++ == '\0')
|
||||
goto matched;
|
||||
if (*s != '\0')
|
||||
return (0);
|
||||
|
||||
true:
|
||||
matched:
|
||||
cs--;
|
||||
string = cs;
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
number(big)
|
||||
int number(int big)
|
||||
{
|
||||
register char *cs;
|
||||
char *cs;
|
||||
long n;
|
||||
|
||||
cs = string;
|
||||
n = 0;
|
||||
while(*cs >= '0' && *cs <= '9')
|
||||
n = n*10 + *cs++ - '0';
|
||||
for(;;)
|
||||
switch(*cs++) {
|
||||
while (*cs >= '0' && *cs <= '9')
|
||||
n = n * 10 + *cs++ - '0';
|
||||
for (;;)
|
||||
switch (*cs++) {
|
||||
case 'k':
|
||||
n *= 1024;
|
||||
continue;
|
||||
|
||||
case 'k':
|
||||
n *= 1024;
|
||||
continue;
|
||||
case 'w':
|
||||
n *= sizeof(int);
|
||||
continue;
|
||||
|
||||
case 'w':
|
||||
n *= sizeof(int);
|
||||
continue;
|
||||
case 'b':
|
||||
n *= 512;
|
||||
continue;
|
||||
|
||||
case 'b':
|
||||
n *= 512;
|
||||
continue;
|
||||
case '*':
|
||||
case 'x':
|
||||
string = cs;
|
||||
n *= number(BIG);
|
||||
|
||||
case '*':
|
||||
case 'x':
|
||||
string = cs;
|
||||
n *= number(BIG);
|
||||
|
||||
case '\0':
|
||||
if (n>=big || n<0) {
|
||||
fprintf(stderr, "dd: argument %D out of range\n", n);
|
||||
exit(1);
|
||||
case '\0':
|
||||
if (n >= big || n < 0) {
|
||||
fprintf(stderr, "dd: argument %D out of range\n", n);
|
||||
exit(1);
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
/* never gets here */
|
||||
}
|
||||
|
||||
cnull(cc)
|
||||
void cnull(int cc)
|
||||
{
|
||||
register c;
|
||||
int c;
|
||||
|
||||
c = cc;
|
||||
if(cflag&UCASE && c>='a' && c<='z')
|
||||
c += 'A'-'a';
|
||||
if(cflag&LCASE && c>='A' && c<='Z')
|
||||
c += 'a'-'A';
|
||||
if (cflag & UCASE && c >= 'a' && c <= 'z')
|
||||
c += 'A' - 'a';
|
||||
if (cflag & LCASE && c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
null(c);
|
||||
}
|
||||
|
||||
null(c)
|
||||
void null(int c)
|
||||
{
|
||||
|
||||
*op = c;
|
||||
op++;
|
||||
if(++obc >= obs) {
|
||||
if (++obc >= obs) {
|
||||
flsh();
|
||||
op = obuf;
|
||||
}
|
||||
}
|
||||
|
||||
ascii(cc)
|
||||
void ascii(int cc)
|
||||
{
|
||||
register c;
|
||||
int c;
|
||||
|
||||
c = etoa[cc] & 0377;
|
||||
if(cbs == 0) {
|
||||
if (cbs == 0) {
|
||||
cnull(c);
|
||||
return;
|
||||
}
|
||||
if(c == ' ') {
|
||||
if (c == ' ') {
|
||||
nspace++;
|
||||
goto out;
|
||||
}
|
||||
while(nspace > 0) {
|
||||
while (nspace > 0) {
|
||||
null(' ');
|
||||
nspace--;
|
||||
}
|
||||
cnull(c);
|
||||
|
||||
out:
|
||||
if(++cbc >= cbs) {
|
||||
if (++cbc >= cbs) {
|
||||
null('\n');
|
||||
cbc = 0;
|
||||
nspace = 0;
|
||||
}
|
||||
}
|
||||
|
||||
unblock(cc)
|
||||
void unblock(int cc)
|
||||
{
|
||||
register c;
|
||||
int c;
|
||||
|
||||
c = cc & 0377;
|
||||
if(cbs == 0) {
|
||||
if (cbs == 0) {
|
||||
cnull(c);
|
||||
return;
|
||||
}
|
||||
if(c == ' ') {
|
||||
if (c == ' ') {
|
||||
nspace++;
|
||||
goto out;
|
||||
}
|
||||
while(nspace > 0) {
|
||||
while (nspace > 0) {
|
||||
null(' ');
|
||||
nspace--;
|
||||
}
|
||||
cnull(c);
|
||||
|
||||
out:
|
||||
if(++cbc >= cbs) {
|
||||
if (++cbc >= cbs) {
|
||||
null('\n');
|
||||
cbc = 0;
|
||||
nspace = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ebcdic(cc)
|
||||
void ebcdic(int cc)
|
||||
{
|
||||
register c;
|
||||
int c;
|
||||
|
||||
c = cc;
|
||||
if(cflag&UCASE && c>='a' && c<='z')
|
||||
c += 'A'-'a';
|
||||
if(cflag&LCASE && c>='A' && c<='Z')
|
||||
c += 'a'-'A';
|
||||
if (cflag & UCASE && c >= 'a' && c <= 'z')
|
||||
c += 'A' - 'a';
|
||||
if (cflag & LCASE && c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
c = atoe[c] & 0377;
|
||||
if(cbs == 0) {
|
||||
if (cbs == 0) {
|
||||
null(c);
|
||||
return;
|
||||
}
|
||||
if(cc == '\n') {
|
||||
while(cbc < cbs) {
|
||||
if (cc == '\n') {
|
||||
while (cbc < cbs) {
|
||||
null(atoe[' ']);
|
||||
cbc++;
|
||||
}
|
||||
cbc = 0;
|
||||
return;
|
||||
}
|
||||
if(cbc == cbs)
|
||||
if (cbc == cbs)
|
||||
ntrunc++;
|
||||
cbc++;
|
||||
if(cbc <= cbs)
|
||||
if (cbc <= cbs)
|
||||
null(c);
|
||||
}
|
||||
|
||||
ibm(cc)
|
||||
void ibm(int cc)
|
||||
{
|
||||
register c;
|
||||
int c;
|
||||
|
||||
c = cc;
|
||||
if(cflag&UCASE && c>='a' && c<='z')
|
||||
c += 'A'-'a';
|
||||
if(cflag&LCASE && c>='A' && c<='Z')
|
||||
c += 'a'-'A';
|
||||
if (cflag & UCASE && c >= 'a' && c <= 'z')
|
||||
c += 'A' - 'a';
|
||||
if (cflag & LCASE && c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
c = atoibm[c] & 0377;
|
||||
if(cbs == 0) {
|
||||
if (cbs == 0) {
|
||||
null(c);
|
||||
return;
|
||||
}
|
||||
if(cc == '\n') {
|
||||
while(cbc < cbs) {
|
||||
if (cc == '\n') {
|
||||
while (cbc < cbs) {
|
||||
null(atoibm[' ']);
|
||||
cbc++;
|
||||
}
|
||||
cbc = 0;
|
||||
return;
|
||||
}
|
||||
if(cbc == cbs)
|
||||
if (cbc == cbs)
|
||||
ntrunc++;
|
||||
cbc++;
|
||||
if(cbc <= cbs)
|
||||
if (cbc <= cbs)
|
||||
null(c);
|
||||
}
|
||||
|
||||
block(cc)
|
||||
void block(int cc)
|
||||
{
|
||||
register c;
|
||||
int c;
|
||||
|
||||
c = cc;
|
||||
if(cflag&UCASE && c>='a' && c<='z')
|
||||
c += 'A'-'a';
|
||||
if(cflag&LCASE && c>='A' && c<='Z')
|
||||
c += 'a'-'A';
|
||||
if (cflag & UCASE && c >= 'a' && c <= 'z')
|
||||
c += 'A' - 'a';
|
||||
if (cflag & LCASE && c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
c &= 0377;
|
||||
if(cbs == 0) {
|
||||
if (cbs == 0) {
|
||||
null(c);
|
||||
return;
|
||||
}
|
||||
if(cc == '\n') {
|
||||
while(cbc < cbs) {
|
||||
if (cc == '\n') {
|
||||
while (cbc < cbs) {
|
||||
null(' ');
|
||||
cbc++;
|
||||
}
|
||||
cbc = 0;
|
||||
return;
|
||||
}
|
||||
if(cbc == cbs)
|
||||
if (cbc == cbs)
|
||||
ntrunc++;
|
||||
cbc++;
|
||||
if(cbc <= cbs)
|
||||
if (cbc <= cbs)
|
||||
null(c);
|
||||
}
|
||||
|
||||
stats()
|
||||
void stats()
|
||||
{
|
||||
fprintf(stderr,"%u+%u records in\n", nifr, nipr);
|
||||
fprintf(stderr,"%u+%u records out\n", nofr, nopr);
|
||||
if(ntrunc)
|
||||
fprintf(stderr,"%u truncated records\n", ntrunc);
|
||||
fprintf(stderr, "%u+%u records in\n", nifr, nipr);
|
||||
fprintf(stderr, "%u+%u records out\n", nofr, nopr);
|
||||
if (ntrunc)
|
||||
fprintf(stderr, "%u truncated records\n", ntrunc);
|
||||
}
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int (*conv)();
|
||||
register char *ip;
|
||||
register c;
|
||||
void (*conv)(int);
|
||||
char *ip;
|
||||
int c;
|
||||
int a;
|
||||
|
||||
conv = null;
|
||||
for(c=1; c<argc; c++) {
|
||||
for (c = 1; c < argc; c++) {
|
||||
string = argv[c];
|
||||
if(match("ibs=")) {
|
||||
if (match("ibs=")) {
|
||||
ibs = number(BIG);
|
||||
continue;
|
||||
}
|
||||
if(match("obs=")) {
|
||||
if (match("obs=")) {
|
||||
obs = number(BIG);
|
||||
continue;
|
||||
}
|
||||
if(match("cbs=")) {
|
||||
if (match("cbs=")) {
|
||||
cbs = number(BIG);
|
||||
continue;
|
||||
}
|
||||
@@ -423,87 +372,87 @@ char **argv;
|
||||
bs = number(BIG);
|
||||
continue;
|
||||
}
|
||||
if(match("if=")) {
|
||||
if (match("if=")) {
|
||||
ifile = string;
|
||||
continue;
|
||||
}
|
||||
if(match("of=")) {
|
||||
if (match("of=")) {
|
||||
ofile = string;
|
||||
continue;
|
||||
}
|
||||
if(match("skip=")) {
|
||||
if (match("skip=")) {
|
||||
skip = number(BIG);
|
||||
continue;
|
||||
}
|
||||
if(match("seek=")) {
|
||||
if (match("seek=")) {
|
||||
seekn = number(BIG);
|
||||
continue;
|
||||
}
|
||||
if(match("count=")) {
|
||||
if (match("count=")) {
|
||||
count = number(BIG);
|
||||
continue;
|
||||
}
|
||||
if(match("files=")) {
|
||||
if (match("files=")) {
|
||||
files = number(BIG);
|
||||
continue;
|
||||
}
|
||||
if(match("conv=")) {
|
||||
if (match("conv=")) {
|
||||
cloop:
|
||||
if(match(","))
|
||||
if (match(","))
|
||||
goto cloop;
|
||||
if(*string == '\0')
|
||||
if (*string == '\0')
|
||||
continue;
|
||||
if(match("ebcdic")) {
|
||||
if (match("ebcdic")) {
|
||||
conv = ebcdic;
|
||||
goto cloop;
|
||||
}
|
||||
if(match("ibm")) {
|
||||
if (match("ibm")) {
|
||||
conv = ibm;
|
||||
goto cloop;
|
||||
}
|
||||
if(match("ascii")) {
|
||||
if (match("ascii")) {
|
||||
conv = ascii;
|
||||
goto cloop;
|
||||
}
|
||||
if(match("block")) {
|
||||
if (match("block")) {
|
||||
conv = block;
|
||||
goto cloop;
|
||||
}
|
||||
if(match("unblock")) {
|
||||
if (match("unblock")) {
|
||||
conv = unblock;
|
||||
goto cloop;
|
||||
}
|
||||
if(match("lcase")) {
|
||||
if (match("lcase")) {
|
||||
cflag |= LCASE;
|
||||
goto cloop;
|
||||
}
|
||||
if(match("ucase")) {
|
||||
if (match("ucase")) {
|
||||
cflag |= UCASE;
|
||||
goto cloop;
|
||||
}
|
||||
if(match("swab")) {
|
||||
if (match("swab")) {
|
||||
cflag |= SWAB;
|
||||
goto cloop;
|
||||
}
|
||||
if(match("noerror")) {
|
||||
if (match("noerror")) {
|
||||
cflag |= NERR;
|
||||
goto cloop;
|
||||
}
|
||||
if(match("sync")) {
|
||||
if (match("sync")) {
|
||||
cflag |= SYNC;
|
||||
goto cloop;
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"bad arg: %s\n", string);
|
||||
fprintf(stderr, "bad arg: %s\n", string);
|
||||
exit(1);
|
||||
}
|
||||
if(conv == null && cflag&(LCASE|UCASE))
|
||||
if (conv == null && cflag & (LCASE | UCASE))
|
||||
conv = cnull;
|
||||
if (ifile)
|
||||
ibf = open(ifile, 0);
|
||||
else
|
||||
ibf = dup(0);
|
||||
if(ibf < 0) {
|
||||
if (ibf < 0) {
|
||||
perror(ifile);
|
||||
exit(1);
|
||||
}
|
||||
@@ -511,8 +460,8 @@ char **argv;
|
||||
obf = creat(ofile, 0666);
|
||||
else
|
||||
obf = dup(1);
|
||||
if(obf < 0) {
|
||||
fprintf(stderr,"cannot create: %s\n", ofile);
|
||||
if (obf < 0) {
|
||||
fprintf(stderr, "cannot create: %s\n", ofile);
|
||||
exit(1);
|
||||
}
|
||||
if (bs) {
|
||||
@@ -520,8 +469,8 @@ char **argv;
|
||||
if (conv == null)
|
||||
fflag++;
|
||||
}
|
||||
if(ibs == 0 || obs == 0) {
|
||||
fprintf(stderr,"counts: cannot be zero\n");
|
||||
if (ibs == 0 || obs == 0) {
|
||||
fprintf(stderr, "counts: cannot be zero\n");
|
||||
exit(1);
|
||||
}
|
||||
ibuf = sbrk(ibs);
|
||||
@@ -529,8 +478,8 @@ char **argv;
|
||||
obuf = ibuf;
|
||||
else
|
||||
obuf = sbrk(obs);
|
||||
sbrk(64); /* For good measure */
|
||||
if(ibuf == (char *)-1 || obuf == (char *)-1) {
|
||||
sbrk(64); /* For good measure */
|
||||
if (ibuf == (char *)-1 || obuf == (char *)-1) {
|
||||
fprintf(stderr, "not enough memory\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -541,54 +490,54 @@ char **argv;
|
||||
|
||||
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
||||
signal(SIGINT, term);
|
||||
while(skip) {
|
||||
while (skip) {
|
||||
read(ibf, ibuf, ibs);
|
||||
skip--;
|
||||
}
|
||||
while(seekn) {
|
||||
while (seekn) {
|
||||
lseek(obf, (long)obs, 1);
|
||||
seekn--;
|
||||
}
|
||||
|
||||
loop:
|
||||
if(ibc-- == 0) {
|
||||
if (ibc-- == 0) {
|
||||
ibc = 0;
|
||||
if(count==0 || nifr+nipr!=count) {
|
||||
if(cflag&(NERR|SYNC))
|
||||
for(ip=ibuf+ibs; ip>ibuf;)
|
||||
*--ip = 0;
|
||||
if (count == 0 || nifr + nipr != count) {
|
||||
if (cflag & (NERR | SYNC))
|
||||
for (ip = ibuf + ibs; ip > ibuf;)
|
||||
*--ip = 0;
|
||||
ibc = read(ibf, ibuf, ibs);
|
||||
}
|
||||
if(ibc == -1) {
|
||||
if (ibc == -1) {
|
||||
perror("read");
|
||||
if((cflag&NERR) == 0) {
|
||||
if ((cflag & NERR) == 0) {
|
||||
flsh();
|
||||
term(1);
|
||||
}
|
||||
ibc = 0;
|
||||
for(c=0; c<ibs; c++)
|
||||
if(ibuf[c] != 0)
|
||||
for (c = 0; c < ibs; c++)
|
||||
if (ibuf[c] != 0)
|
||||
ibc = c;
|
||||
stats();
|
||||
}
|
||||
if(ibc == 0 && --files<=0) {
|
||||
if (ibc == 0 && --files <= 0) {
|
||||
flsh();
|
||||
term(0);
|
||||
}
|
||||
if(ibc != ibs) {
|
||||
if (ibc != ibs) {
|
||||
nipr++;
|
||||
if(cflag&SYNC)
|
||||
if (cflag & SYNC)
|
||||
ibc = ibs;
|
||||
} else
|
||||
nifr++;
|
||||
ip = ibuf;
|
||||
c = ibc >> 1;
|
||||
if(cflag&SWAB && c)
|
||||
do {
|
||||
a = *ip++;
|
||||
ip[-1] = *ip;
|
||||
*ip++ = a;
|
||||
} while(--c);
|
||||
if (cflag & SWAB && c)
|
||||
do {
|
||||
a = *ip++;
|
||||
ip[-1] = *ip;
|
||||
*ip++ = a;
|
||||
} while (--c);
|
||||
ip = ibuf;
|
||||
if (fflag) {
|
||||
obc = ibc;
|
||||
|
||||
Reference in New Issue
Block a user