-
Notifications
You must be signed in to change notification settings - Fork 3
/
exr.c
104 lines (98 loc) · 1.71 KB
/
exr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
#include <errno.h>
#include <sys/types.h>
#ifdef USE_SYS_SYSMACROS_H
# include <sys/sysmacros.h>
#endif
#ifdef USE_SYS_MKDEV_H
# include <sys/mkdev.h>
#endif
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "ex.h"
#include "ex_io.h"
/*
* Ex - a text editor
* Bill Joy UCB June 1977
*/
void
rop(int c)
{
register int i;
struct stat stbuf;
int magic;
io = open(file, O_RDONLY);
if (io < 0) {
if (c == 'e' && errno == ENOENT)
value(EDITED)++;
ioerror();
}
if (value(EDITANY) == 0) {
if (fstat(io, &stbuf))
ioerror();
switch (stbuf.st_mode & S_IFMT) {
case S_IFBLK:
error(" Block special file");
case S_IFCHR:
if (gTTY(io) == 0)
error(" Teletype");
if (major(stbuf.st_dev) == DVNLMAJ
&& minor(stbuf.st_dev) == DVNLMIN)
break;
error(" Character special file");
case S_IFDIR:
error(" Directory");
case S_IFREG:
i = read(io, &magic, 2);
lseek(io, 0, SEEK_SET);
if (i != 2)
break;
switch (magic) {
case 0404:
error(" Pascal object");
case 0405:
error(" Overlay executable");
case 0407:
error(" Executable");
case 0410:
error(" Pure executbable");
case 0411:
error(" Separate executable");
case 0177545:
error(" Archive");
case 0177555:
error(" Old archive");
default:
if (magic & 0100200)
error(" Non-ascii file");
break;
}
}
}
if (c == 'r')
setdot();
else
setall();
rop2();
rop3(c);
}
void
rop2(void)
{
deletenone();
clrstats();
append(getfile, addr2);
}
void
rop3(int c)
{
if (iostats() == 0)
if (c == 'e')
value(EDITED)++;
if (c == 'e')
undkind = UNDNONE;
if (laste) {
laste = 0;
ex_sync();
}
}