]>
Commit | Line | Data |
---|---|---|
f3f86c75 | 1 | /* $Header$ */ |
2 | ||
3 | /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */ | |
4 | /* For copying and distribution information, please see the file */ | |
5 | /* <mit-copyright.h>. */ | |
6 | ||
7 | ||
8 | #include <mit-copyright.h> | |
9 | #include <stdio.h> | |
10 | #include <sys/file.h> | |
11 | #include <ctype.h> | |
12 | ||
13 | char prefix[256]; | |
14 | ||
15 | main(argc, argv) | |
16 | int argc; | |
17 | char **argv; | |
18 | { | |
19 | ## char *db; | |
20 | ||
21 | if (argc == 2) | |
22 | db = argv[1]; | |
23 | else | |
24 | db = "sms"; | |
25 | ||
26 | printf("Prefix of backup to restore: "); | |
27 | fflush(stdout); | |
28 | if (gets(prefix) == NULL) { | |
29 | return 1; | |
30 | } | |
31 | ||
32 | printf("Opening database..."); | |
33 | fflush(stdout); | |
34 | ## ingres db | |
35 | printf("done\n"); | |
36 | ||
37 | do_users(); | |
38 | do_finger(); | |
39 | do_mach(); | |
40 | do_clu(); | |
41 | do_mcm(); | |
42 | do_cld(); | |
43 | do_servers(); | |
44 | do_serverhosts(); | |
45 | do_list(); | |
46 | do_maillists(); | |
47 | do_groups(); | |
48 | do_members(); | |
49 | do_strings(); | |
50 | do_pobox(); | |
51 | do_nfsphys(); | |
52 | do_filesys(); | |
53 | do_nfsquota(); | |
54 | do_services(); | |
55 | do_printcap(); | |
56 | do_alias(); | |
57 | do_values(); | |
58 | ||
59 | printf("All done.\n"); | |
60 | ## exit | |
61 | } | |
62 | ||
63 | char field_chars[] = { | |
64 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* ^@ - ^O */ | |
65 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ^P - ^_ */ | |
66 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* SP - / */ | |
67 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* 0 - ? */ | |
68 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */ | |
69 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* P - _ */ | |
70 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ | |
71 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* p - ^? */ | |
72 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
73 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
74 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
75 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
76 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
77 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
78 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
79 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
80 | }; | |
81 | ||
82 | ||
83 | int parse_int(f) | |
84 | register FILE *f; | |
85 | { | |
86 | register int c; | |
87 | register int val = 0; | |
88 | register int sign = 1; | |
89 | while ((c = getc(f)) != EOF && field_chars[c] == 0) { | |
90 | if (c == '-') sign = -1; | |
91 | else if (isdigit(c)) { | |
92 | val *= 10; | |
93 | val += (c - '0'); | |
94 | } else (void) fprintf(stderr,"non-digit in numeric field\n"); | |
95 | } | |
96 | (void) ungetc(c, f); | |
97 | return(val * sign); | |
98 | } | |
99 | ||
100 | void parse_str(f, buf, len) | |
101 | register FILE *f; | |
102 | register char *buf; | |
103 | register int len; /* incl trailing NULL */ | |
104 | { | |
105 | register int c; | |
106 | ||
107 | while ((c = getc(f)) != EOF && field_chars[c] == 0 && len > 0) { | |
108 | if (c == '\\') { | |
109 | c = getc(f); | |
110 | if (isdigit(c)) { | |
111 | /* Expect three-digit octal number.. */ | |
112 | register int c1, c2; | |
113 | c1 = getc(f); | |
114 | c2 = getc(f); | |
115 | if (!isdigit(c1) || !isdigit(c2)) | |
116 | punt("Broken \\###"); | |
117 | /* Convert to ASCII code: */ | |
118 | *buf++ = (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0'); | |
119 | } else if (c == '\\' || c == ':') { | |
120 | *buf++ = c; | |
121 | --len; | |
122 | } else punt ("Broken '\\'"); | |
123 | } else { | |
124 | *buf++ = c; | |
125 | --len; | |
126 | } | |
127 | } | |
128 | if (c == EOF) | |
129 | return; | |
130 | ||
131 | if (c != EOF && c != ':' && c != '\n') { | |
132 | fprintf(stderr, "Field too wide, truncated\n"); | |
133 | while ((c = getc(f)) != EOF && c != ':' && c != '\n'); | |
134 | (void) ungetc(c, f); | |
135 | } else { | |
136 | *buf++ = 0; | |
137 | (void) ungetc(c, f); | |
138 | } | |
139 | } | |
140 | ||
141 | void parse_sep(f) | |
142 | FILE *f; | |
143 | { | |
144 | if (getc(f) != ':') punt("Expected colon"); | |
145 | } | |
146 | void parse_nl(f) | |
147 | FILE *f; | |
148 | { | |
149 | if (getc(f) != '\n') punt("Expected newline"); | |
150 | } | |
151 | ||
152 | ||
153 | FILE *open_file(suffix) | |
154 | char *suffix; | |
155 | { | |
156 | char name[BUFSIZ]; | |
157 | int fd; | |
158 | FILE *f; | |
159 | ||
160 | sprintf(name, "%s/%s", prefix, suffix); | |
161 | ||
162 | fd = open(name, O_RDONLY, 0); | |
163 | if (fd < 0) { | |
164 | punt(name); | |
165 | } | |
166 | f = fdopen(fd, "r"); | |
167 | if (f == NULL) { | |
168 | fprintf(stderr, "fdopen of "); | |
169 | punt(name); | |
170 | } | |
171 | fprintf(stderr, "Working on %s\n", name); | |
172 | return(f); | |
173 | } | |
174 | ||
175 | punt(s) | |
176 | char *s; | |
177 | { | |
178 | printf("exiting: %s\n", s); | |
179 | exit(1); | |
180 | } | |
181 | ||
182 | static int count; | |
183 | static int interval; | |
184 | ||
185 | start_counter(x) | |
186 | int x; | |
187 | { | |
188 | count = 0; | |
189 | interval = x; | |
190 | } | |
191 | ||
192 | inc_count() | |
193 | { | |
194 | if (count++ % interval == 0) { | |
195 | printf("\r%d...", count - 1); | |
196 | fflush(stdout); | |
197 | } | |
198 | } | |
199 | ||
200 | end_counter() | |
201 | { | |
202 | printf("\r%d items processed.\n", count); | |
203 | } |