Repository navigation
Expand file tree
/
Copy pathm.c
More file actions
executable file
·141 lines (127 loc) · 2.37 KB
/
Copy pathm.c
File metadata and controls
executable file
·141 lines (127 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
8000
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* a small awk clone
*
* (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi
*
* Absolutely no warranty. Use this software with your own risk.
*
* Permission to use, copy, modify and distribute this software for any
* purpose and without fee is hereby granted, provided that the above
* copyright and disclaimer notice.
*
* This program was written to fit into 64K+64K memory of the Minix 1.2.
*/
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include "awk.h"
extern char **FS, **FILENAME;
extern char record[];
extern FILE *ifp;
NODE *parse();
CELL *execute();
FILE *efopen(), *fopen();
char *strsave();
int xargc;
char **xargv;
char *srcprg;
FILE *pfp;
char *cmd;
#if 0
int iflg; /* interactive mode */
#endif
main(argc, argv) char **argv;
{
char *s, *strpbrk(), *strchr();
void onint();
#ifdef DOS
_sharg(&argc, &argv);
#endif
signal(SIGINT, onint);
signal(SIGFPE, onint);
cmd = argv[0];
init();
while (--argc > 0 && (*++argv)[0] == '-')
for (s = argv[0]+1; *s; s++)
if (strcmp(argv[0], "-") == 0)
break;
else
switch (*s) {
#if 0
case 'i':
iflg++;
pfp = stdin;
interactive();
/* no return */
#endif
case 'F':
*FS = ++s;
break;
case 'f':
if (*(s+1))
s++;
else {
argc--; s = *++argv;
}
pfp = efopen(s, "r");
s += strlen(s) - 1;
break;
}
xargc = argc; xargv = argv;
if (pfp == NULL && xargc > 0) {
srcprg = *xargv++; xargc--;
}
/*
if (pfp == NULL && xargc > 0) {
643B
if (strpbrk(xargv[0], " !$^()={}[];<>,/~") != NULL) {
sprintf(record, "%s\n", xargv[0]);
srcprg = strsave(record);
}
else {
sprintf(record, "%s.awk", xargv[0]);
if ((pfp = fopen(record, "r")) == NULL)
error("can't open %s", record);
}
xargc--; xargv++;
}
*/
while (*xargv != NULL && strchr(*xargv, '=') != NULL) {
setvar(*xargv++);
xargc--;
}
initarg(cmd, xargc, xargv);
if (xargc == 0) {
ifp = stdin; *FILENAME = "-";
}
parse();
closeall();
exit(0);
}
FILE *
efopen(file, mode) char *file, *mode;
{
FILE *fp, *fopen();
if ((fp = fopen(file, mode)) == NULL)
error("cannot open %s", file);
return fp;
}
error(s, t) char *s, *t;
{
extern double *NR;
fprintf(stderr, "awk: ");
fprintf(stderr, s, t);
fprintf(stderr, "\n");
if (NR != NULL) {
fprintf(stderr, "record number %g\n", *NR);
}
#ifdef DOS
closeall();
#endif
exit(1);
}
void
onint(i)
{
closeall();
exit(0x80 | i);
}