0
|
1 /* mhconfig.c - configure MH */
|
|
2 /* cc [-DSYS5] mhconfig.c -o mhconfig */
|
|
3 #ifndef lint
|
|
4 static char ident[] = "@(#)$Id$";
|
|
5 #endif /* lint */
|
|
6
|
|
7 #include <ctype.h>
|
|
8 #include <stdio.h>
|
|
9 #ifdef hpux
|
|
10 #define SYS5
|
|
11 #endif
|
|
12 #ifdef SYS5
|
|
13 #define index strchr
|
|
14 #define rindex strrchr
|
|
15 #endif /* SYS5 */
|
|
16
|
|
17 static void insopt(), mkopts();
|
|
18
|
|
19 extern char *strcpy(), *malloc(), *index(), *rindex();
|
|
20 #ifdef notdef
|
|
21 extern char *sprintf(); /* rely on stdio.h to declare this */
|
|
22 #endif
|
|
23
|
|
24 #define BANNER "This is %s, for generic UNIX (MH.6 configuration program)\n\n"
|
|
25
|
|
26
|
|
27 #define SED "config.sed"
|
|
28 #define SED2 "config2.sed"
|
|
29 #define SEDOC "doc/config.sed"
|
|
30 #define SEDOC2 "doc/config2.sed"
|
|
31 #define MAKE "../%s/Makefile"
|
|
32
|
|
33 #define WARNING "This file is automatically generated. Do not edit!"
|
|
34 #define MHRELEASE "6.8.4" /* for version: "Maj.min.pat" */
|
|
35 #define MHCENTERFOOT "MH.6.8" /* for nroff page footers */
|
|
36 #define MHLEFTFOOT "[mh.6]" /* [mh.6] MH.6.6 page# */
|
|
37
|
|
38 #ifdef MHSLIB_NOMINVER
|
|
39 #define MHSLIBVER "3" /* Shared library version (no minor version) */
|
|
40 #else /* MHSLIB_NOMINVER */
|
|
41 #define MHSLIBVER "3.2" /* Shared library version */
|
|
42 #endif /* MHSLIB_NOMINVER */
|
|
43
|
|
44 #define NOTOK (-1)
|
|
45
|
|
46 #define NULLCP ((char *) 0)
|
|
47
|
|
48 #define SVAL(s) (s ? s : "")
|
|
49
|
|
50 #define QUOTE '\\'
|
|
51
|
|
52 /* */
|
|
53
|
|
54 static int smtp = 0;
|
|
55 static int mpop = 0;
|
|
56 static int nntp = 0;
|
|
57 static int gzipman = 0;
|
|
58
|
|
59 static int sedP = 1;
|
|
60 static int filesP = 1;
|
|
61 static int docP = 1;
|
|
62 static int makeP = 1;
|
|
63
|
|
64 static char *myname = "mhconfig";
|
|
65 static char *config = NULL;
|
|
66 static char *myopts = NULL;
|
|
67
|
|
68 static char *binpath = "/usr/local";
|
|
69 static char *bbhome = "/usr/spool/bboards";
|
|
70 static char *bboards = "off";
|
|
71 static char *bbdelivery = "off";
|
|
72 static char *ccoptions = NULL;
|
|
73 static char *chownpath = "/etc/chown";
|
|
74 static char *sendmailpath = "/usr/lib/sendmail";
|
|
75 static char *compiler = "/bin/cc";
|
|
76 static char *cpp = "/lib/ccp";
|
|
77 static char *copy = "cp";
|
|
78 static char *curses = "-lcurses -ltermlib";
|
|
79 static char *debug = "off";
|
|
80 static char *editor = "prompter";
|
|
81 static char *etcpath = "/usr/local/lib/mh";
|
|
82 static char *ldoptions = NULL;
|
|
83 static char *ldoptlibs = NULL;
|
|
84 /* jp2c+ */
|
|
85 static int norespost = 0;
|
|
86 static char *ldoptlibs_post = NULL;
|
|
87 /* jp2c+ */
|
|
88 static char *lex = "lex -nt";
|
|
89 static char *ln = "ln";
|
|
90 static char *mailgroup = "off";
|
|
91 static char *mailpath = "/usr/spool/mail";
|
|
92 static char *maildir = NULL;
|
|
93 static char *mailfile = NULL;
|
|
94 static char *mancat = "man";
|
|
95 static char *mandir = "/usr/man";
|
|
96 static char *jmandir = NULL;
|
|
97 static char *manuals = "standard";
|
|
98 static char *mf = "off";
|
|
99 static char *mts = "sendmail";
|
|
100 static char *poppath = "/usr/etc";
|
|
101 static char *removeit = "mv -f";
|
|
102 static char *regtest = "off";
|
|
103 static char *oldload = "off";
|
|
104 static char *options = NULL;
|
|
105 static char *pop = "off";
|
|
106 static char *ranlib = "on";
|
|
107 static char *sharedlib = "off";
|
|
108 static char *signl = "int";
|
|
109 static char *slibdir = "/usr/local/lib";
|
|
110 static char *slflags = "-pic";
|
|
111 static char *sprntf = NULL;
|
|
112
|
|
113 /* */
|
|
114
|
|
115 #define unknown 0
|
|
116 #define mmdf 1
|
|
117 #define mmdf2 2
|
|
118 #define mh 3
|
|
119 #define sendmail 4
|
|
120 static int mtsnum = unknown;
|
|
121
|
|
122 static struct mtsopt {
|
|
123 char *mtskey;
|
|
124 char *optval;
|
|
125 int code;
|
|
126 int mtsflags;
|
|
127 #define NOFLAGS 0x00
|
|
128 #define DOSMTP 0x01
|
|
129 #define NOMF 0x02
|
|
130 } mtsopts[] = {
|
|
131 "mmdf", "MMDFMTS MMDFI", mmdf, NOFLAGS,
|
|
132 "mmdf/smtp", "SENDMTS SMTP", mmdf, DOSMTP,
|
|
133 "mmdf2", "MMDFMTS MMDFII", mmdf2, NOFLAGS,
|
|
134 "mmdf2/smtp", "SENDMTS MMDFII SMTP", mmdf2, DOSMTP,
|
|
135 "mh", "MHMTS", mh, NOFLAGS,
|
|
136 "sendmail", "SENDMTS", sendmail, NOMF,
|
|
137 "sendmail/smtp", "SENDMTS SMTP", sendmail, NOMF,
|
|
138 "zmailer", "ZMAILER SENDMTS", sendmail, NOMF,
|
|
139 "zmailer/smtp", "ZMAILER SENDMTS SMTP", sendmail, NOMF,
|
|
140 NULL, NULL, unknown, NOFLAGS
|
|
141 };
|
|
142
|
|
143 /* other options which cause sed BEGIN/END configuration changes */
|
|
144
|
|
145 static struct copt {
|
|
146 char *c_name;
|
|
147 int c_value;
|
|
148 } copts[] = {
|
|
149 "APOP", 0, /* authenticated pop */
|
|
150 "BSD43", 0, /* sgid ttys */
|
|
151 "BSD44", 0, /* manual headings */
|
|
152 "KPOP", 0, /* KERBEROS pop */
|
|
153 "HESIOD", 0,
|
|
154 /* NOTE: MIME_HEADERS must locate befer MIME */
|
|
155 "MIME_HEADERS", 0, /* RFC-2047 headers */
|
|
156 "MIME", 0, /* multi-media extensions */
|
|
157 "MPOP", 0, /* mobile pop */
|
|
158 "MSGID", 0, /* slocal dup surpression */
|
|
159 "NORUSERPASS", 0, /* no ruserpass(3) */
|
|
160 "TMA", 0, /* trusted mail */
|
|
161 "TTYD", 0,
|
|
162 "UCI", 0,
|
|
163 "RPOP", 0,
|
|
164 "READLINE", 0, /* use GNU readline() */
|
|
165 "JAPAN", 0, /* Japanization patch */
|
|
166 "MH_PLUS", 0, /* MH-plus patch */
|
|
167 NULL, 0
|
|
168 };
|
|
169
|
|
170
|
|
171
|
|
172 /* */
|
|
173
|
|
174 static struct bind {
|
|
175 char *keyword;
|
|
176
|
|
177 char **value;
|
|
178
|
|
179 int flags;
|
|
180 #define BD_NIL 0x00
|
|
181 #define BD_ADD 0x01
|
|
182 } binds[] = {
|
|
183 "bin", &binpath, BD_NIL,
|
|
184 "bbhome", &bbhome, BD_NIL,
|
|
185 "bboards", &bboards, BD_NIL,
|
|
186 "bbdelivery", &bbdelivery, BD_NIL,
|
|
187 "ccoptions", &ccoptions, BD_ADD,
|
|
188 "chown", &chownpath, BD_NIL,
|
|
189 "cc", &compiler, BD_NIL,
|
|
190 "cpp", &cpp, BD_NIL,
|
|
191 "cp", ©, BD_NIL,
|
|
192 "curses", &curses, BD_NIL,
|
|
193 "debug", &debug, BD_NIL,
|
|
194 "editor", &editor, BD_NIL,
|
|
195 "etc", &etcpath, BD_NIL,
|
|
196 "ldoptions", &ldoptions, BD_ADD,
|
|
197 "ldoptlibs", &ldoptlibs, BD_ADD,
|
|
198 "ldoptlibs_post", &ldoptlibs_post, BD_ADD,
|
|
199 "lex", &lex, BD_NIL,
|
|
200 "ln", &ln, BD_NIL,
|
|
201 "mail", &mailpath, BD_NIL,
|
|
202 "mailgroup", &mailgroup, BD_NIL,
|
|
203 "mandir", &mandir, BD_NIL,
|
|
204 "jmandir", &jmandir, BD_NIL,
|
|
205 "manuals", &manuals, BD_NIL,
|
|
206 "mf", &mf, BD_NIL,
|
|
207 "mts", &mts, BD_NIL,
|
|
208 "oldload", &oldload, BD_NIL,
|
|
209 "options", &options, BD_ADD,
|
|
210 "pop", &pop, BD_NIL,
|
|
211 "popdir", &poppath, BD_NIL,
|
|
212 "ranlib", &ranlib, BD_NIL,
|
|
213 "remove", &removeit, BD_NIL,
|
|
214 "regtest", ®test, BD_NIL,
|
|
215 "sendmail", &sendmailpath, BD_NIL,
|
|
216 "sharedlib", &sharedlib, BD_NIL,
|
|
217 "signal", &signl, BD_NIL,
|
|
218 "slflags", &slflags, BD_NIL,
|
|
219 "slibdir", &slibdir, BD_NIL,
|
|
220 "sprintf", &sprntf, BD_NIL,
|
|
221 NULL
|
|
222 };
|
|
223
|
|
224 /* */
|
|
225
|
|
226 char *files[] = {
|
|
227 "../support/bboards/bboards.daily",
|
|
228 "../support/bboards/bboards.weekly",
|
|
229 "../support/bboards/crontab",
|
|
230 "../support/bboards/MakeBBoards",
|
|
231 "../config/config.c",
|
|
232 "../zotnet/mts/mts.c",
|
|
233 "../zotnet/mts/mtstailor",
|
|
234 "../support/general/MailAliases",
|
|
235 "../mts/sendmail/bboardsMH.m4",
|
|
236 "../mts/sendmail/popMH.m4",
|
|
237 NULL
|
|
238 };
|
|
239
|
|
240 static struct pair {
|
|
241 char *infile;
|
|
242 char *outfile;
|
|
243 } makefiles[] = {
|
|
244 "makefiles/MH-Makefile", ".",
|
|
245 "makefiles/config","config",
|
|
246 "makefiles/dist","dist",
|
|
247 "makefiles/doc","doc",
|
|
248 "makefiles/mtsM","mts",
|
|
249 "makefiles/mts/mh","mts/mh",
|
|
250 "makefiles/mts/mmdf","mts/mmdf",
|
|
251 "makefiles/mts/sendmail","mts/sendmail",
|
|
252 "makefiles/papers","papers",
|
|
253 "makefiles/sbr","sbr",
|
|
254 "makefiles/supportM","support",
|
|
255 "makefiles/support/bboards","support/bboards",
|
|
256 "makefiles/support/general","support/general",
|
|
257 "makefiles/support/pop","support/pop",
|
|
258 "makefiles/uip","uip",
|
|
259 "makefiles/zotnetM","zotnet",
|
|
260 "makefiles/zotnet/bboards","zotnet/bboards",
|
|
261 "makefiles/zotnet/mf","zotnet/mf",
|
|
262 "makefiles/zotnet/mts","zotnet/mts",
|
|
263 "makefiles/zotnet/tws","zotnet/tws",
|
|
264 NULL
|
|
265 };
|
|
266
|
|
267
|
|
268 static do_sed(), do_sedfile(), do_files(), do_doc(), do_make();
|
|
269 static shell(), arginit(), add_option(), trim();
|
|
270
|
|
271 static char *stradd (), *strdup (), *tail ();
|
|
272
|
|
273 /* */
|
|
274
|
|
275 /* ARGSUSED */
|
|
276
|
|
277 main (argc, argv, envp)
|
|
278 int argc;
|
|
279 char **argv,
|
|
280 **envp;
|
|
281 {
|
|
282 arginit (argv);
|
|
283
|
|
284 if (sedP)
|
|
285 do_sed ();
|
|
286 if (filesP)
|
|
287 do_files ();
|
|
288 if (docP)
|
|
289 do_doc ();
|
|
290 if (makeP)
|
|
291 do_make ();
|
|
292
|
|
293 #ifdef notdef
|
|
294 printf ("Don't forget to edit \"config/mtstailor\"\n");
|
|
295 #endif
|
|
296 if (filesP || makeP)
|
|
297 printf ("Don't forget to run \"make clean\" in the top directory before compiling\n");
|
|
298
|
|
299 exit (0);
|
|
300 }
|
|
301
|
|
302 /* */
|
|
303
|
|
304 static do_sed () {
|
|
305 if (docP != 2)
|
|
306 do_sedfile (SED, SED2, 0);
|
|
307 do_sedfile (SEDOC, SEDOC2, smtp);
|
|
308 }
|
|
309
|
|
310 static do_alldoc (fp)
|
|
311 FILE *fp;
|
|
312 {
|
|
313 fprintf (fp, "%s\n%s\n%s\n%s\n", /* turn @BEGIN: XX into #ifdef XX */
|
|
314 "s!^@BEGIN: \\(.*\\)$!.br\\", /* for MH wizard manual set */
|
|
315 ".ti 0i\\",
|
|
316 "#ifdef \\1\\",
|
|
317 ".br!"
|
|
318 );
|
|
319 fprintf (fp, "%s\n%s\n%s\n%s\n",
|
|
320 "s!^@END: \\(.*\\)$!.br\\",
|
|
321 ".ti 0i\\",
|
|
322 "#endif /* \\1\\ */",
|
|
323 ".br!"
|
|
324 );
|
|
325 }
|
|
326
|
|
327 /* */
|
|
328
|
|
329 static do_sedfile (sed, sed2, flag)
|
|
330 char *sed, *sed2;
|
|
331 int flag;
|
|
332 {
|
|
333 int i;
|
|
334 FILE * fp;
|
|
335 struct copt *op;
|
|
336
|
|
337 if ((fp = fopen (sed, "w")) == NULL)
|
|
338 adios (sed, "unable to write");
|
|
339 printf ("generating %s\n", sed);
|
|
340
|
|
341 if (docP == 2) {
|
|
342 printf ("...using special all-doc format.\n");
|
|
343 printf ("Be sure to reconfigure before compiling.\n");
|
|
344 do_alldoc(fp); /* hack up doc/config.sed */
|
|
345 }
|
|
346
|
|
347 fprintf (fp, "s%%@(MHCONFIGFILE)%%%s%%g\n", SVAL(config));
|
|
348 fprintf (fp, "s%%@(MHWARNING)%%%s%%g\n", WARNING);
|
|
349 fprintf (fp, "s%%@(MHRELEASE)%%%s%%g\n", MHRELEASE);
|
|
350 fprintf (fp, "s%%@(MHCENTERFOOT)%%%s%%g\n", MHCENTERFOOT);
|
|
351 fprintf (fp, "s%%@(MHLEFTFOOT)%%%s%%g\n", MHLEFTFOOT);
|
|
352 fprintf (fp, "s%%@(MHBINPATH)%%%s%%g\n", SVAL (binpath));
|
|
353 fprintf (fp, "s%%@(MHETCPATH)%%%s%%g\n", SVAL (etcpath));
|
|
354 fprintf (fp, "s%%@(MHPOPDPATH)%%%s%%g\n", SVAL (poppath));
|
|
355 fprintf (fp, "s%%@(MHCHOWNPATH)%%%s%%g\n", SVAL (chownpath));
|
|
356 fprintf (fp, "s%%@(MHSENDMAILPATH)%%%s%%g\n", SVAL (sendmailpath));
|
|
357 fprintf (fp, "s%%@(MHDROPATH)%%%s%%g\n", SVAL (maildir));
|
|
358 fprintf (fp, "s%%@(MHDROPFIL)%%%s%%g\n", SVAL (mailfile));
|
|
359 if (maildir)
|
|
360 fprintf (fp, "s%%@(MHDROPLOC)%%%s/$USER%%g\n", SVAL (maildir));
|
|
361 else
|
|
362 fprintf (fp, "s%%@(MHDROPLOC)%%$HOME/%s%%g\n", SVAL (mailfile));
|
|
363 fprintf (fp, "s%%@(MHDROPHAK)%%%s%%g\n",/* HACK */
|
|
364 maildir ? maildir : "/usr/spool/mail");
|
|
365
|
|
366 fprintf (fp, "s%%@(MHMANDIR)%%%s%%g\n", mandir);
|
|
367 if (jmandir && *jmandir) {
|
|
368 fprintf (fp, "s%%@(MHJMANDIR)%%%s%%g\n", jmandir);
|
|
369 fprintf (fp, "/^@BEGIN: JMANUAL$/d\n/^@END: JMANUAL$/d\n");
|
|
370 } else
|
|
371 fprintf (fp, "/^@BEGIN: JMANUAL$/,/^@END: JMANUAL$/d\n");
|
|
372 fprintf (fp, "s%%@(MHCATMAN)%%%s%%g\n",
|
|
373 strcmp(mancat, "cat") == 0 ? "| nroff -man"
|
|
374 : gzipman ? "| gzip -9n" : "");
|
|
375 if (strcmp (manuals, "standard") == 0 || strcmp (manuals, "gen") == 0)
|
|
376 for (i = 1; i <= 8; i++) {
|
|
377 fprintf (fp, "s%%@(MHMANDIR%d)%%%s%d%%g\n", i, mancat, i);
|
|
378 fprintf (fp, "s%%@(MHMANEXT%d)%%%d%s%%g\n", i, i,
|
|
379 gzipman ? ".gz" : "");
|
|
380 }
|
|
381 else
|
|
382 for (i = 1; i <= 8; i++) {
|
|
383 fprintf (fp, "s%%@(MHMANDIR%d)%%%s%c%%g\n", i, mancat,
|
|
384 strcmp (manuals, "new") == 0 ? 'n'
|
|
385 : strcmp (manuals, "old") == 0 ? 'o'
|
|
386 : strcmp (manuals, "bsd44") == 0 ? i + '0'
|
|
387 : 'l');
|
|
388 fprintf (fp, "s%%@(MHMANEXT%d)%%%c%s%%g\n", i,
|
|
389 strcmp (manuals, "new") == 0 ? 'n'
|
|
390 : strcmp (manuals, "old") == 0 ? 'o'
|
|
391 : strcmp (manuals, "bsd44") == 0 ? '0'
|
|
392 : 'l', gzipman ? ".gz" : "");
|
|
393 }
|
|
394
|
|
395 /* */
|
|
396
|
|
397 if (strcmp (regtest, "on") == 0)
|
|
398 fprintf (fp, "s%%@(MHHOSTVER)%%%s%%g\n", "-n");
|
|
399 else
|
|
400 fprintf (fp, "s%%@(MHHOSTVER)%%%s%%g\n", "");
|
|
401
|
|
402 if (strcmp (manuals, "gen") == 0 || strcmp (manuals, "none") == 0)
|
|
403 fprintf (fp, "s%%@(MHMANGEN)%%%s%%g\n", "#"); /* comment char */
|
|
404 else
|
|
405 fprintf (fp, "s%%@(MHMANGEN)%%%s%%g\n", "");
|
|
406
|
|
407 fprintf (fp, "s%%@(MHEDITOR)%%%s%%g\n", SVAL (editor));
|
|
408 fprintf (fp, "s%%@(MHCONFIG)%%%s%%g\n", SVAL (myopts));
|
|
409 fprintf (fp, "s%%@(MHCOMPILER)%%%s%%g\n", SVAL (compiler));
|
|
410 fprintf (fp, "s%%@(MHCPP)%%%s%%g\n", SVAL (cpp));
|
|
411 fprintf (fp, "s%%@(CP)%%%s%%g\n", SVAL (copy));
|
|
412 fprintf (fp, "s%%@(LN)%%%s%%g\n", SVAL (ln));
|
|
413 fprintf (fp, "s%%@(LEX)%%%s%%g\n", SVAL (lex));
|
|
414 if (ccoptions)
|
|
415 fprintf (fp, "s%%@(MHOPTIONS)%%%s %s%%g\n",
|
|
416 SVAL (options), SVAL (ccoptions));
|
|
417 else
|
|
418 fprintf (fp, "s%%@(MHOPTIONS)%%%s %s%%g\n",
|
|
419 SVAL (options), "-O");
|
|
420 fprintf (fp, "s%%@(LDOPTIONS)%%%s%%g\n", SVAL (ldoptions));
|
|
421 fprintf (fp, "s%%@(LDOPTLIB)%%%s%%g\n", SVAL (ldoptlibs));
|
|
422 fprintf (fp, "s%%@(LDOPTLIB_POST)%%%s%%g\n",
|
|
423 SVAL (norespost ? ldoptlibs_post : ldoptlibs));
|
|
424 fprintf (fp, "s%%@(LDCURSES)%%%s%%g\n", SVAL (curses));
|
|
425
|
|
426 if (strcmp (bboards, "off") == 0)
|
|
427 fprintf (fp, "/^@BEGIN: BBOARDS$/,/^@END: BBOARDS$/d\n");
|
|
428 else
|
|
429 fprintf (fp, "/^@BEGIN: BBOARDS$/d\n/^@END: BBOARDS$/d\n");
|
|
430 fprintf (fp, "s%%@(BBHOME)%%%s%%g\n", SVAL (bbhome));
|
|
431 if (strcmp (bbdelivery, "off") == 0)
|
|
432 fprintf (fp, "/^@BEGIN: BBSERVER$/,/^@END: BBSERVER$/d\n");
|
|
433 else
|
|
434 fprintf (fp, "/^@BEGIN: BBSERVER$/d\n/^@END: BBSERVER$/d\n");
|
|
435
|
|
436 if (strcmp (debug, "on") == 0) {
|
|
437 fprintf (fp, "/^@BEGIN: DEBUG$/d\n/^@END: DEBUG$/d\n");
|
|
438 fprintf (fp, "/^@BEGIN: OPTIM$/,/^@END: OPTIM$/d\n");
|
|
439 }
|
|
440 else {
|
|
441 fprintf (fp, "/^@BEGIN: DEBUG$/,/^@END: DEBUG$/d\n");
|
|
442 fprintf (fp, "/^@BEGIN: OPTIM$/d\n/^@END: OPTIM$/d\n");
|
|
443 }
|
|
444
|
|
445 if (strcmp (mailgroup, "off")) { /* for SYS5 sgid-inc */
|
|
446 fprintf (fp, "/^@BEGIN: MAILGROUP$/d\n/^@END: MAILGROUP$/d\n");
|
|
447 fprintf (fp, "s%%@(MAILGROUP)%%%s%%g\n", SVAL (mailgroup));
|
|
448 }
|
|
449 else
|
|
450 fprintf (fp, "/^@BEGIN: MAILGROUP$/,/^@END: MAILGROUP$/d\n");
|
|
451
|
|
452 if (strcmp (oldload, "on") == 0)
|
|
453 fprintf (fp, "/^@BEGIN: OLDLOAD$/d\n/^@END: OLDLOAD$/d\n");
|
|
454 else
|
|
455 fprintf (fp, "/^@BEGIN: OLDLOAD$/,/^@END: OLDLOAD$/d\n");
|
|
456 if (strcmp (oldload, "off") == 0)
|
|
457 fprintf (fp, "/^@BEGIN: NEWLOAD$/d\n/^@END: NEWLOAD$/d\n");
|
|
458 else
|
|
459 fprintf (fp, "/^@BEGIN: NEWLOAD$/,/^@END: NEWLOAD$/d\n");
|
|
460
|
|
461 (void) fclose (fp);
|
|
462
|
|
463 /* */
|
|
464
|
|
465 /* We have to divide a script because some OS have a poor "sed". :-< */
|
|
466 if ((fp = fopen (sed2, "w")) == NULL)
|
|
467 adios (sed2, "unable to write");
|
|
468 printf ("generating %s\n", sed2);
|
|
469
|
|
470 if (strcmp (ranlib, "on") == 0) {
|
|
471 fprintf (fp, "/^@BEGIN: RANLIB$/d\n/^@END: RANLIB$/d\n");
|
|
472 fprintf (fp, "/^@BEGIN: LORDER$/,/^@END: LORDER$/d\n");
|
|
473 }
|
|
474 else {
|
|
475 fprintf (fp, "/^@BEGIN: LORDER$/d\n/^@END: LORDER$/d\n");
|
|
476 fprintf (fp, "/^@BEGIN: RANLIB$/,/^@END: RANLIB$/d\n");
|
|
477 }
|
|
478
|
|
479 if (strcmp (sharedlib, "off")) { /* if not off */
|
|
480 fprintf (fp, "/^@BEGIN: SHAREDLIB$/d\n/^@END: SHAREDLIB$/d\n");
|
|
481 fprintf (fp, "/^@BEGIN: STDLIB$/,/^@END: STDLIB$/d\n");
|
|
482 fprintf (fp, "s%%@(SLIBDIR)%%%s%%g\n", slibdir);
|
|
483 fprintf (fp, "s%%@(SLIBVER)%%%s%%g\n", MHSLIBVER);
|
|
484 fprintf (fp, "s%%@(SLFLAGS)%%%s%%g\n", SVAL(slflags));
|
|
485 if (strcmp (sharedlib, "secure") == 0)
|
|
486 fprintf (fp, "s%%@(SLDFLAG)%%-L%s%%g\n",slibdir);
|
|
487 else
|
|
488 fprintf (fp, "s%%@(SLDFLAG)%%%%g\n");
|
|
489 }
|
|
490 else {
|
|
491 fprintf (fp, "/^@BEGIN: STDLIB$/d\n/^@END: STDLIB$/d\n");
|
|
492 fprintf (fp, "/^@BEGIN: SHAREDLIB$/,/^@END: SHAREDLIB$/d\n");
|
|
493 }
|
|
494 if (strcmp (sharedlib, "sun4") == 0 || strcmp (sharedlib, "on") == 0)
|
|
495 fprintf (fp, "/^@BEGIN: SUN4SHLIB$/d\n/^@END: SUN4SHLIB$/d\n");
|
|
496 else
|
|
497 fprintf (fp, "/^@BEGIN: SUN4SHLIB$/,/^@END: SUN4SHLIB$/d\n");
|
|
498 if (strcmp (sharedlib, "sys5") == 0)
|
|
499 fprintf (fp, "/^@BEGIN: SYS5SHLIB$/d\n/^@END: SYS5SHLIB$/d\n");
|
|
500 else
|
|
501 fprintf (fp, "/^@BEGIN: SYS5SHLIB$/,/^@END: SYS5SHLIB$/d\n");
|
|
502 if (strcmp (sharedlib, "fbsd") == 0)
|
|
503 fprintf (fp, "/^@BEGIN: FBSDSHLIB$/d\n/^@END: FBSDSHLIB$/d\n");
|
|
504 else
|
|
505 fprintf (fp, "/^@BEGIN: FBSDSHLIB$/,/^@END: FBSDSHLIB$/d\n");
|
|
506 if (strcmp (sharedlib, "gnuelf") == 0)
|
|
507 fprintf (fp, "/^@BEGIN: GELFSHLIB$/d\n/^@END: GELFSHLIB$/d\n");
|
|
508 else
|
|
509 fprintf (fp, "/^@BEGIN: GELFSHLIB$/,/^@END: GELFSHLIB$/d\n");
|
|
510
|
|
511 /* */
|
|
512
|
|
513 if (flag || ((mtsnum == mmdf || mtsnum == mmdf2) && !smtp)) {
|
|
514 fprintf (fp, "/^@BEGIN: MMDFMTS$/d\n/^@END: MMDFMTS$/d\n");
|
|
515 if (mtsnum == mmdf)
|
|
516 fprintf (fp, "/^@BEGIN: MMDFIMTS$/d\n/^@END: MMDFIMTS$/d\n");
|
|
517 else
|
|
518 fprintf (fp, "/^@BEGIN: MMDFIMTS$/,/^@END: MMDFIMTS$/d\n");
|
|
519 if (mtsnum == mmdf2)
|
|
520 fprintf (fp, "/^@BEGIN: MMDFIIMTS$/d\n/^@END: MMDFIIMTS$/d\n");
|
|
521 else
|
|
522 fprintf (fp, "/^@BEGIN: MMDFIIMTS$/,/^@END: MMDFIIMTS$/d\n");
|
|
523 }
|
|
524 else {
|
|
525 fprintf (fp, "/^@BEGIN: MMDFMTS$/,/^@END: MMDFMTS$/d\n");
|
|
526 fprintf (fp, "/^@BEGIN: MMDFIMTS$/,/^@END: MMDFIMTS$/d\n");
|
|
527 fprintf (fp, "/^@BEGIN: MMDFIIMTS$/,/^@END: MMDFIIMTS$/d\n");
|
|
528 }
|
|
529
|
|
530 if (mtsnum == mh)
|
|
531 fprintf (fp, "/^@BEGIN: MHMTS$/d\n/^@END: MHMTS$/d\n");
|
|
532 else
|
|
533 fprintf (fp, "/^@BEGIN: MHMTS$/,/^@END: MHMTS$/d\n");
|
|
534
|
|
535 if (!flag && (mtsnum == sendmail || smtp))
|
|
536 fprintf (fp, "/^@BEGIN: SENDMTS$/d\n/^@END: SENDMTS$/d\n");
|
|
537 else
|
|
538 fprintf (fp, "/^@BEGIN: SENDMTS$/,/^@END: SENDMTS$/d\n");
|
|
539
|
|
540 switch (mtsnum) {
|
|
541 case mh:
|
|
542 case sendmail:
|
|
543 case mmdf:
|
|
544 fprintf (fp, "/^@BEGIN: SENDMTSHACK$/d\n/^@END: SENDMTSHACK$/d\n");
|
|
545 break;
|
|
546
|
|
547 default:
|
|
548 fprintf (fp, "/^@BEGIN: SENDMTSHACK$/,/^@END: SENDMTSHACK$/d\n");
|
|
549 break;
|
|
550 }
|
|
551
|
|
552 /* */
|
|
553
|
|
554 /* special hack for support/pop/popser.c */
|
|
555 fprintf (fp, "s%%@(POPUUMBOX)%%%s%%g\n",
|
|
556 mtsnum == sendmail ? "-DPOPUUMBOX" : "");
|
|
557
|
|
558 if (smtp)
|
|
559 fprintf (fp, "/^@BEGIN: SMTP$/d\n/^@END: SMTP$/d\n");
|
|
560 else
|
|
561 fprintf (fp, "/^@BEGIN: SMTP$/,/^@END: SMTP$/d\n");
|
|
562
|
|
563 if (strcmp (pop, "on") == 0) {
|
|
564 fprintf (fp, "/^@BEGIN: POP$/d\n/^@END: POP$/d\n");
|
|
565 fprintf (fp, "/^@BEGIN: POPSERVER$/d\n/^@END: POPSERVER$/d\n");
|
|
566 } else if (strcmp (pop, "client") == 0) {
|
|
567 fprintf (fp, "/^@BEGIN: POP$/d\n/^@END: POP$/d\n");
|
|
568 fprintf (fp, "/^@BEGIN: POPSERVER$/,/^@END: POPSERVER$/d\n");
|
|
569 } else {
|
|
570 fprintf (fp, "/^@BEGIN: POP$/,/^@END: POP$/d\n");
|
|
571 fprintf (fp, "/^@BEGIN: POPSERVER$/,/^@END: POPSERVER$/d\n");
|
|
572 }
|
|
573
|
|
574 if (strcmp (bboards, "pop") == 0)
|
|
575 fprintf (fp, "/^@BEGIN: BPOP$/d\n/^@END: BPOP$/d\n");
|
|
576 else
|
|
577 fprintf (fp, "/^@BEGIN: BPOP$/,/^@END: BPOP$/d\n");
|
|
578
|
|
579 if (strcmp (bboards, "nntp") == 0 || nntp)
|
|
580 fprintf (fp, "/^@BEGIN: NNTP$/d\n/^@END: NNTP$/d\n");
|
|
581 else
|
|
582 fprintf (fp, "/^@BEGIN: NNTP$/,/^@END: NNTP$/d\n");
|
|
583
|
|
584 if (strcmp (mf, "on") == 0)
|
|
585 fprintf (fp, "/^@BEGIN: MF$/d\n/^@END: MF$/d\n");
|
|
586 else
|
|
587 fprintf (fp, "/^@BEGIN: MF$/,/^@END: MF$/d\n");
|
|
588
|
|
589 fprintf (fp, "s%%@(MHREMOVE)%%%s%%g\n", SVAL (removeit));
|
|
590
|
|
591 for (op = copts; op->c_name; op++) {
|
|
592 fprintf (fp, op->c_value ? "/^@BEGIN: %s$/d\n/^@END: %s$/d\n" :
|
|
593 "/^@BEGIN: %s$/,/^@END: %s$/d\n",
|
|
594 op->c_name, op->c_name);
|
|
595 }
|
|
596
|
|
597 (void) fclose (fp);
|
|
598 }
|
|
599
|
|
600 /* */
|
|
601
|
|
602 static do_files () {
|
|
603 char **pp;
|
|
604
|
|
605 for (pp = files; *pp; pp++)
|
|
606 shell ("rm -f %s; sed -f %s < config/%s | sed -f %s > %s",
|
|
607 *pp, SED, tail (*pp), SED2, *pp);
|
|
608 }
|
|
609
|
|
610
|
|
611 static do_doc () {
|
|
612 shell ("./mhdoc");
|
|
613 }
|
|
614
|
|
615
|
|
616 static do_make () {
|
|
617 char buffer[BUFSIZ];
|
|
618 struct pair *pp;
|
|
619
|
|
620 for (pp = makefiles; pp -> infile; pp++) {
|
|
621 (void) sprintf (buffer, MAKE, pp -> outfile);
|
|
622 shell ("rm -f %s; sed -f %s < %s | sed -f %s > %s",
|
|
623 buffer, SED, pp -> infile, SED2, buffer);
|
|
624 }
|
|
625 }
|
|
626
|
|
627 /* */
|
|
628
|
|
629 /* VARARGS */
|
|
630
|
|
631 static shell (fmt, a, b, c, d, e)
|
|
632 char *fmt,
|
|
633 *a,
|
|
634 *b,
|
|
635 *c,
|
|
636 *d,
|
|
637 *e;
|
|
638 {
|
|
639 char buffer[BUFSIZ];
|
|
640
|
|
641 (void) sprintf (buffer, fmt, a, b, c, d, e);
|
|
642 printf ("%s\n", buffer);
|
|
643 (void) fflush (stdout);
|
|
644
|
|
645 if (system (buffer))
|
|
646 adios (NULLCP, "failed");
|
|
647 }
|
|
648
|
|
649 /* */
|
|
650
|
|
651 static arginit (vec)
|
|
652 char **vec;
|
|
653 {
|
|
654 int i;
|
|
655 char *ap,
|
|
656 *cp,
|
|
657 *dp,
|
|
658 buffer[BUFSIZ];
|
|
659 struct bind *bp;
|
|
660 FILE * fp;
|
|
661
|
|
662 myname = tail (*vec);
|
|
663 printf (BANNER, myname);
|
|
664 (void) fflush (stdout);
|
|
665
|
|
666 for (vec++; *vec; vec++) {
|
|
667 if (strcmp (*vec, "-D") == 0) {
|
|
668 sedP = 1; filesP = makeP = 0; docP = 2;
|
|
669 continue;
|
|
670 }
|
|
671 if (strcmp (*vec, "-s") == 0) {
|
|
672 sedP = !sedP;
|
|
673 continue;
|
|
674 }
|
|
675 if (strcmp (*vec, "-f") == 0) {
|
|
676 filesP = !filesP;
|
|
677 continue;
|
|
678 }
|
|
679 if (strcmp (*vec, "-d") == 0) {
|
|
680 docP = !docP;
|
|
681 continue;
|
|
682 }
|
|
683 if (strcmp (*vec, "-m") == 0) {
|
|
684 makeP = !makeP;
|
|
685 continue;
|
|
686 }
|
|
687 if (strcmp (*vec, "-help") == 0) {
|
|
688 printf ("usage: %s [opt] file\n", myname);
|
|
689 printf ("%s\n%s\n%s\n%s\n",
|
|
690 " -s\tno sed files", " -f\tno config files",
|
|
691 " -d\tno doc files", " -m\tno makefiles");
|
|
692 exit (0);
|
|
693 }
|
|
694 break;
|
|
695 }
|
|
696 if ((config = *vec) == NULL || vec[1] != NULL) /* no arg or too many */
|
|
697 adios (NULLCP, "usage: %s file", myname);
|
|
698
|
|
699 /* */
|
|
700
|
|
701 if ((fp = fopen (config, "r")) == NULL)
|
|
702 adios (config, "unable to read");
|
|
703
|
|
704 while (fgets (buffer, sizeof buffer, fp)) {
|
|
705 if (ap = index (buffer, '\n'))
|
|
706 *ap-- = '\0';
|
|
707 else
|
|
708 ap = &buffer[strlen (buffer) - 1];
|
|
709 while (ap >= buffer)
|
|
710 if (isspace (*ap))
|
|
711 *ap = '\0';
|
|
712 else
|
|
713 break;
|
|
714 for (cp = buffer; isspace (*cp); cp++)
|
|
715 continue;
|
|
716 if (*cp == '\0' || *cp == '#')
|
|
717 continue;
|
|
718 for (ap = cp; *ap; ap++)
|
|
719 if (isspace (*ap) || *ap == ':') {
|
|
720 *ap++ = '\0';
|
|
721 while (isspace (*ap))
|
|
722 ap++;
|
|
723 break;
|
|
724 }
|
|
725 for (bp = binds; bp -> keyword; bp++)
|
|
726 if (strcmp (bp -> keyword, cp) == 0)
|
|
727 break;
|
|
728 if (bp -> keyword == NULL)
|
|
729 adios (NULLCP, "unknown option %s in %s", cp, config);
|
|
730 else
|
|
731 if (*(bp -> value) == NULL || !(bp -> flags & BD_ADD))
|
|
732 *(bp -> value) = strdup (ap);
|
|
733 else
|
|
734 *(bp -> value) = stradd (ap, stradd (" ", *(bp -> value)));
|
|
735 }
|
|
736
|
|
737 (void) fclose (fp);
|
|
738
|
|
739 /* */
|
|
740
|
|
741 if (binpath == NULL)
|
|
742 adios (NULLCP, "bin must be specified in %s", config);
|
|
743 trim (binpath);
|
|
744
|
|
745 if (strcmp (bboards, "on") && strcmp (bboards, "off") &&
|
|
746 strcmp (bboards, "pop") && strcmp (bboards, "nntp"))
|
|
747 adios (NULLCP, "bboards should be %s not %s",
|
|
748 "either \"on\", \"off\", \"pop\" or \"nntp\"", bboards);
|
|
749 if (strcmp (bboards, "off") == 0 && strcmp (bbdelivery, "off"))
|
|
750 adios (NULLCP,
|
|
751 "you cannot have \"bbdelivery\" \"%s\" with \"bboards\" \"%s\"",
|
|
752 bbdelivery, bboards);
|
|
753 if (bbhome == NULL)
|
|
754 adios (NULLCP, "bbhome must be specified in %s", config);
|
|
755 trim (bbhome);
|
|
756
|
|
757 if (strcmp (debug, "on") && strcmp (debug, "off"))
|
|
758 adios (NULLCP, "debug should be either \"on\" or \"off\", not %s",
|
|
759 debug);
|
|
760
|
|
761 if (etcpath == NULL)
|
|
762 adios (NULLCP, "etc must be specified in %s", config);
|
|
763 trim (etcpath);
|
|
764
|
|
765 if (strcmp (mailgroup, "off")) /* if not "off" */
|
|
766 add_option ("MAILGROUP");
|
|
767 if (mailpath == NULL)
|
|
768 adios (NULLCP, "mail must be specified in %s", config);
|
|
769 trim (mailpath);
|
|
770 if (*mailpath == '/')
|
|
771 maildir = mailpath;
|
|
772 else
|
|
773 mailfile = mailpath;
|
|
774
|
|
775 if (cp = index (manuals, '/')) { /* "standard/cat" */
|
|
776 *cp++ = 0;
|
|
777 mancat = cp;
|
|
778 if (strcmp (mancat, "gzip") == 0) {
|
|
779 mancat = "man";
|
|
780 gzipman = 1;
|
|
781 } else
|
|
782 if (strcmp (mancat, "cat"))
|
|
783 adios (NULLCP,"invalid manuals setting: %s/%s",manuals, mancat);
|
|
784 }
|
|
785 if (strcmp (manuals, "standard")
|
|
786 && strcmp (manuals, "bsd44")
|
|
787 && strcmp (manuals, "local")
|
|
788 && strcmp (manuals, "new")
|
|
789 && strcmp (manuals, "old")
|
|
790 && strcmp (manuals, "gen")
|
|
791 && strcmp (manuals, "none"))
|
|
792 adios (NULLCP,"invalid manuals setting: %s",manuals);
|
|
793
|
|
794 if (mts == NULL)
|
|
795 adios (NULLCP, "mts must be specified in %s", config);
|
|
796 for (i = 0; mtsopts[i].mtskey; i++)
|
|
797 if (strcmp (mts, mtsopts[i].mtskey) == 0)
|
|
798 break;
|
|
799 if ((mtsnum = mtsopts[i].code) == unknown)
|
|
800 adios (NULLCP, "invalid mts setting: %s", mts);
|
|
801 add_option (mtsopts[i].optval);
|
|
802 smtp = mtsopts[i].mtsflags & DOSMTP;
|
|
803 if (mtsopts[i].mtsflags & NOMF)
|
|
804 mf = "off"; /* hack... */
|
|
805
|
|
806 if (strcmp (pop, "on") && strcmp (pop, "client") && strcmp (pop, "off"))
|
|
807 adios (NULLCP,
|
|
808 "pop should be either \"on\", \"client\" or \"off\", not %s",
|
|
809 pop);
|
|
810 if (strcmp (pop, "off"))
|
|
811 add_option ("POP");
|
|
812
|
|
813 if (strcmp (bboards, "pop") == 0) {
|
|
814 add_option ("BPOP");
|
|
815 if (strcmp (pop, "off") == 0)
|
|
816 adios (NULLCP,
|
|
817 "bboards \"pop\" requires pop \"on\" or \"client\"");
|
|
818 }
|
|
819 else if (strcmp (bboards, "nntp") == 0) {
|
|
820 add_option ("BPOP");/* used by msh.c & bbc.c, but see also pshsbr.c */
|
|
821 add_option ("NNTP");
|
|
822 if (mpop)
|
|
823 adios (NULLCP,
|
|
824 "bboards \"nntp\" is incompatible with \"options MPOP\"");
|
|
825 }
|
|
826
|
|
827 if (strcmp (mf, "on") && strcmp (mf, "off"))
|
|
828 adios (NULLCP, "mf should be either \"on\" or \"off\", not %s", mf);
|
|
829 if (strcmp (mf, "on") == 0)
|
|
830 add_option ("MF");
|
|
831
|
|
832 if (sprntf && strcmp (sprntf, "char *")) {/* this defaults to "char *" */
|
|
833 if (strcmp (sprntf, "int"))
|
|
834 adios (NULLCP,
|
|
835 "sprintf should be either \"int\" or \"char *\", not %s",
|
|
836 sprntf);
|
|
837 add_option ("SPRINTFTYPE=int");
|
|
838 }
|
|
839
|
|
840 if (strcmp (sharedlib, "on") && strcmp (sharedlib, "off")
|
|
841 && strcmp (sharedlib, "sun4") && strcmp (sharedlib, "sys5")
|
|
842 && strcmp (sharedlib, "fbsd") && strcmp (sharedlib, "gnuelf")
|
|
843 && strcmp (sharedlib, "secure"))
|
|
844 adios (NULLCP,
|
|
845 "sharedlib should be either \"sun4\", \"sys5\", \"fbsd\", \"gnuelf\" or \"off\", not %s",
|
|
846 sharedlib);
|
|
847
|
|
848 (void) sprintf(buffer, "TYPESIG=%s", signl);
|
|
849 add_option (buffer);
|
|
850
|
|
851 /* loop over options string and add -D ccoptions */
|
|
852
|
|
853 begin_myopt ();
|
|
854 if (cp = options) {
|
|
855 for (ap = cp; *ap; ap++)
|
|
856 if (isspace (*ap))
|
|
857 *ap = ' ';
|
|
858 options = NULL;
|
|
859 for (ap = cp; dp = index (ap, ' '); ap = dp) {
|
|
860 *dp++ = '\0';
|
|
861 add_myopt (ap);
|
|
862 (void) sprintf (buffer, "%s-D%s", options ? " " : "", ap);
|
|
863 ap = buffer;
|
|
864 options = stradd (ap, options);
|
|
865 while (isspace (*dp))
|
|
866 dp++;
|
|
867 }
|
|
868 if (*ap) {
|
|
869 add_myopt (ap);
|
|
870 (void) sprintf (buffer, "%s-D%s", options ? " " : "", ap);
|
|
871 ap = buffer;
|
|
872 options = stradd (ap, options);
|
|
873 }
|
|
874 free (cp);
|
|
875 }
|
|
876 end_myopt ();
|
|
877 if (strcmp (bboards, "nntp") == 0 && mpop)
|
|
878 adios (NULLCP,
|
|
879 "bboards \"nntp\" is incompatible with \"options MPOP\"");
|
|
880 }
|
|
881
|
|
882 /* */
|
|
883
|
|
884 static add_option (s)
|
|
885 char *s;
|
|
886 {
|
|
887 options = options ? stradd (s, stradd (" ", options)) : strdup (s);
|
|
888 }
|
|
889
|
|
890
|
|
891 begin_myopt () {
|
|
892 myopts = strdup ("char *options[] = {");
|
|
893 }
|
|
894
|
|
895
|
|
896 add_myopt (s)
|
|
897 char *s;
|
|
898 {
|
|
899 int len;
|
|
900 char *bp,
|
|
901 buffer[BUFSIZ];
|
|
902 struct copt *op;
|
|
903 static int nameoutput = 0;
|
|
904 static int linepos = 0;
|
|
905 static int outputlinelen = 72;
|
|
906
|
|
907 for (op = copts; op->c_name; op++)
|
|
908 if (!strncmp (op->c_name,s,strlen(op->c_name))) {
|
|
909 op->c_value = 1;
|
|
910 break;
|
|
911 }
|
|
912
|
|
913 if (strcmp (s, "NNTP") == 0)
|
|
914 nntp = 1;
|
|
915 if (strcmp (s, "MPOP") == 0) {
|
|
916 mpop = 1;
|
|
917 if (nntp)
|
|
918 adios (NULLCP,
|
|
919 "\"options MPOP\" is incompatible with \"options NNTP\"");
|
|
920 }
|
|
921 if (strcmp (s, "NORESPOST") == 0)
|
|
922 norespost = 1;
|
|
923 if (smtp && strcmp (s, "BERK") == 0) {
|
|
924 fprintf (stderr, "\"options BERK\" overriding smtp suffix...\n");
|
|
925 smtp = 0;
|
|
926 }
|
|
927 if (!nameoutput) {
|
|
928 printf ("%s: ", bp = "options");
|
|
929 linepos += (nameoutput = strlen (bp) + 2);
|
|
930 }
|
|
931 len = strlen (s);
|
|
932 if (linepos != nameoutput)
|
|
933 if (len + linepos + 3 > outputlinelen)
|
|
934 printf ("\n%*s", linepos = nameoutput, "");
|
|
935 else
|
|
936 printf (" "), linepos++;
|
|
937 printf ("[%s]", s);
|
|
938 linepos += len + 2;
|
|
939 (void) fflush (stdout);
|
|
940
|
|
941 bp = buffer;
|
|
942 *bp++ = '"';
|
|
943 while (*s) {
|
|
944 if (*s == '"')
|
|
945 *bp++ = QUOTE, *bp++ = QUOTE;
|
|
946 *bp++ = *s++;
|
|
947 }
|
|
948 (void) strcpy (bp, "\", ");
|
|
949 insopt (buffer);
|
|
950 }
|
|
951
|
|
952
|
|
953 end_myopt () {
|
|
954 printf ("\n");
|
|
955 (void) fflush (stdout);
|
|
956 mkopts();
|
|
957 myopts = stradd ("NULL};", myopts);
|
|
958 }
|
|
959
|
|
960 /* */
|
|
961
|
|
962 static trim (s)
|
|
963 char *s;
|
|
964 {
|
|
965 char *p;
|
|
966
|
|
967 if (s == NULL || (p = rindex (s, '/')) == NULL)
|
|
968 return;
|
|
969 if (*++p == '\0')
|
|
970 *--p = '\0';
|
|
971 }
|
|
972
|
|
973
|
|
974 static char *tail (s)
|
|
975 char *s;
|
|
976 {
|
|
977 char *p;
|
|
978
|
|
979 if (p = rindex (s, '/'))
|
|
980 p++;
|
|
981 return ((p == NULL || *p == '\0') ? s : p);
|
|
982 }
|
|
983
|
|
984 /* */
|
|
985
|
|
986 static char *stradd (s1, s2)
|
|
987 char *s1,
|
|
988 *s2;
|
|
989 {
|
|
990 char *p;
|
|
991
|
|
992 if (s1 == NULL || *s1 == '\0')
|
|
993 return s2;
|
|
994 if (s2 == NULL)
|
|
995 return strdup (s1);
|
|
996 if ((p = malloc ((unsigned) (strlen (s1) + strlen (s2) + 2))) == NULL)
|
|
997 adios (NULLCP, "insufficient memory");
|
|
998
|
|
999 (void) sprintf (p, "%s%s", s2, s1);
|
|
1000 if (s2)
|
|
1001 free (s2);
|
|
1002 return p;
|
|
1003 }
|
|
1004
|
|
1005
|
|
1006 static char *strdup (s)
|
|
1007 char *s;
|
|
1008 {
|
|
1009 char *p;
|
|
1010
|
|
1011 if ((p = malloc ((unsigned) (strlen (s) + 1))) == NULL)
|
|
1012 adios (NULLCP, "insufficient memory");
|
|
1013
|
|
1014 (void) strcpy (p, s);
|
|
1015 return p;
|
|
1016 }
|
|
1017
|
|
1018 /* */
|
|
1019
|
|
1020 #ifdef notdef
|
|
1021 /* these used to be for SYS5 machines, but now this is compiled
|
|
1022 * with -DSYS5 which redefines the SYS5 str[r]chr names to [r]index.
|
|
1023 */
|
|
1024 static char *index (s, c)
|
|
1025 char *s,
|
|
1026 c;
|
|
1027 {
|
|
1028 char i;
|
|
1029
|
|
1030 while (i = *s++)
|
|
1031 if (i == c)
|
|
1032 return (s - 1);
|
|
1033
|
|
1034 return NULL;
|
|
1035 }
|
|
1036
|
|
1037
|
|
1038 static char *rindex (s, c)
|
|
1039 char *s,
|
|
1040 c;
|
|
1041 {
|
|
1042 char i,
|
|
1043 *t;
|
|
1044
|
|
1045 t = NULL;
|
|
1046 while (i = *s++)
|
|
1047 if (i == c)
|
|
1048 t = s - 1;
|
|
1049
|
|
1050 return t;
|
|
1051 }
|
|
1052 #endif /* notdef */
|
|
1053
|
|
1054 /* */
|
|
1055
|
|
1056 /* VARARGS */
|
|
1057
|
|
1058 adios (what, fmt, a, b, c)
|
|
1059 char *what,
|
|
1060 *fmt,
|
|
1061 *a,
|
|
1062 *b,
|
|
1063 *c;
|
|
1064 {
|
|
1065 (void) fflush (stdout);
|
|
1066
|
|
1067 fprintf (stderr, "%s: ", myname);
|
|
1068 fprintf (stderr, fmt, a, b, c);
|
|
1069 if (what) {
|
|
1070 (void) fputc (' ', stderr);
|
|
1071 perror (what);
|
|
1072 }
|
|
1073 else
|
|
1074 (void) fputc ('\n', stderr);
|
|
1075
|
|
1076 exit (1);
|
|
1077 }
|
|
1078
|
|
1079 /* quick and dirty ordering of options for readability */
|
|
1080
|
|
1081 struct opt {
|
|
1082 char *s;
|
|
1083 struct opt *n;
|
|
1084 };
|
|
1085
|
|
1086 static struct opt *optp = (struct opt *)NULL;
|
|
1087
|
|
1088 static void
|
|
1089 insopt(s)
|
|
1090 char *s; /* string for sorting */
|
|
1091 {
|
|
1092 struct opt *p,
|
|
1093 *np,
|
|
1094 *lp = (struct opt *)NULL;
|
|
1095
|
|
1096 if ((np = (struct opt *) malloc ((unsigned) sizeof (struct opt))) ==
|
|
1097 (struct opt *)NULL)
|
|
1098 adios (NULL, "unable to malloc opt");
|
|
1099 np -> s = strdup(s);
|
|
1100 np -> n = (struct opt *)NULL;
|
|
1101
|
|
1102 for (p = optp; p; lp = p, p = p -> n) {
|
|
1103 if (strcmp (p->s, s) > 0)
|
|
1104 break;
|
|
1105 }
|
|
1106 if (p)
|
|
1107 np -> n = p;
|
|
1108 if (lp)
|
|
1109 lp -> n = np;
|
|
1110 else
|
|
1111 optp = np;
|
|
1112 }
|
|
1113
|
|
1114 static void
|
|
1115 mkopts()
|
|
1116 {
|
|
1117 struct opt *p;
|
|
1118
|
|
1119 for (p = optp; p; p = p -> n)
|
|
1120 myopts = stradd (p->s, myopts);
|
|
1121 }
|