2 * Copyright (c) 1997-1999 Erez Zadok
3 * Copyright (c) 1989 Jan-Simon Pendry
4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1989 The Regents of the University of California.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgment:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * $Id: fsi_util.c,v 1.2 1999/01/10 21:54:28 ezk Exp $
44 #endif /* HAVE_CONFIG_H */
49 /* static variables */
50 static int show_range = 10;
52 static int total_shown = 0;
53 static int total_mmm = 8;
74 if (total_mmm != -show_range + 1) {
80 sprintf(n, "%d", total_shown);
86 total_mmm = -show_range;
108 * Lots of ways of reporting errors...
111 error(char *fmt, ...)
117 fprintf(stderr, "%s: Error, ", progname);
118 fprintf(stderr, fmt, ap);
126 lerror(ioloc *l, char *fmt, ...)
132 fprintf(stderr, "%s:%d: ", l->i_file, l->i_line);
133 fprintf(stderr, fmt, ap);
141 lwarning(ioloc *l, char *fmt, ...)
147 fprintf(stderr, "%s:%d: ", l->i_file, l->i_line);
148 fprintf(stderr, fmt, ap);
155 fatal(char *fmt, ...)
161 fprintf(stderr, "%s: Fatal, ", progname);
162 fprintf(stderr, fmt, ap);
180 fprintf(stdout, "%s: ", progname);
181 fprintf(stdout, fmt, ap);
189 info_hdr(FILE *ef, char *info)
191 fprintf(ef, "# *** NOTE: This file contains %s info\n", info);
196 gen_hdr(FILE *ef, char *hn)
198 fprintf(ef, "# *** NOTE: Only for use on %s\n", hn);
203 make_banner(FILE *fp)
205 time_t t = time((time_t *) 0);
206 char *cp = ctime(&t);
210 # *** This file was automatically generated -- DO NOT EDIT HERE ***\n\
211 # \"%s\" run by %s@%s on %s\
214 progname, username, hostname, cp);
225 if (total_mmm > show_range) {
227 } else if (total_mmm == 0) {
237 show_area_being_processed(char *area, int n)
239 static char *last_area = 0;
250 if (!last_area || !STREQ(area, last_area)) {
254 total_mmm = show_range + 1;
256 (void) col_output(strlen(area) + 2);
257 fprintf(stdout, "[%s", area);
271 * Open a file with the given prefix and name
274 pref_open(char *pref, char *hn, void (*hdr) (FILE *, char *), char *arg)
279 sprintf(p, "%s%s", pref, hn);
280 log("Writing %s info for %s to %s", pref, hn, p);
286 error("can't open %s for writing", p);
296 return fclose(fp) == 0;
301 * Determine where Amd would automount the host/volname pair
304 compute_automount_point(char *buf, host *hp, char *vn)
306 sprintf(buf, "%s/%s%s", autodir, hp->h_lochost, vn);
311 xcalloc(int i, int s)
313 char *p = (char *) calloc(i, (unsigned) s);
316 fatal("Out of memory");
322 * Data constructors..
325 new_automount(char *name)
327 automount *ap = CALLOC(struct automount);
329 ap->a_ioloc = current_location();
334 show_new("automount");
340 new_auto_tree(char *def, qelem *ap)
342 auto_tree *tp = CALLOC(struct auto_tree);
344 tp->t_ioloc = current_location();
345 tp->t_defaults = def;
347 show_new("auto_tree");
355 host *hp = CALLOC(struct host);
357 hp->h_ioloc = current_location();
365 set_host(host *hp, int k, char *v)
369 if (hp->h_mask & m) {
370 yyerror("host field \"%s\" already set", host_strings[k]);
379 dict_ent *de = dict_locate(dict_of_hosts, v);
382 yyerror("duplicate host %s!", v);
384 dict_add(dict_of_hosts, v, (char *) hp);
386 domain_strip(p, hostname);
387 if (strchr(p, '.') != 0)
396 qelem *vq = (qelem *) v;
402 q = hp->h_config = new_que();
403 ins_que(vq, q->q_back);
409 qelem *vq = (qelem *) v;
415 q = hp->h_ether = new_que();
416 ins_que(vq, q->q_back);
442 ether_if *ep = CALLOC(struct ether_if);
445 ep->e_ioloc = current_location();
446 show_new("ether_if");
452 set_ether_if(ether_if *ep, int k, char *v)
456 if (ep->e_mask & m) {
457 yyerror("netif field \"%s\" already set", ether_if_strings[k]);
465 ep->e_inaddr.s_addr = inet_addr(v);
466 if (ep->e_inaddr.s_addr == (u_long) - 1)
467 yyerror("malformed IP dotted quad: %s", v);
475 if ((sscanf(v, "0x%lx", &nm) == 1 || sscanf(v, "%lx", &nm) == 1) && nm != 0)
476 ep->e_netmask = htonl(nm);
478 yyerror("malformed netmask: %s", v);
495 set_disk_fs(disk_fs *dp, int k, char *v)
499 if (dp->d_mask & m) {
500 yyerror("fs field \"%s\" already set", disk_fs_strings[k]);
524 dp->d_passno = atoi(v);
529 dp->d_freq = atoi(v);
534 dp->d_mount = &((fsi_mount *) v)->m_q;
547 disk_fs *dp = CALLOC(struct disk_fs);
549 dp->d_ioloc = current_location();
556 set_mount(fsi_mount *mp, int k, char *v)
560 if (mp->m_mask & m) {
561 yyerror("mount tree field \"%s\" already set", mount_strings[k]);
569 dict_add(dict_of_volnames, v, (char *) mp);
591 fsi_mount *fp = CALLOC(struct fsi_mount);
593 fp->m_ioloc = current_location();
600 set_fsmount(fsmount *fp, int k, char *v)
604 if (fp->f_mask & m) {
605 yyerror("mount field \"%s\" already set", fsmount_strings[k]);
645 fsmount *fp = CALLOC(struct fsmount);
647 fp->f_ioloc = current_location();
656 q->q_forw = q->q_back = q;
663 qelem *q = CALLOC(qelem);
671 ins_que(qelem *elem, qelem *pred)