Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / mhparam.c
1 /* mhparam.c - print mh_profile values */
2 #ifndef lint
3 static char ident[] = "@(#)$Id: mhparam.c,v 1.9 1993/09/01 23:00:59 jromine Exp $";
4 #endif  /* lint */
5 /* contributed by Jeffrey C Honig <Jeffrey_C_Honig@cornell.edu> */
6
7 #include "../h/mh.h"
8 #include <stdio.h>
9
10 extern char *mhlibdir;          /* NB: this will change soon */
11 char *sbackup = SBACKUP;
12 char *slink = LINK;
13
14 /* \f */
15
16 static struct swit switches[] = {
17 #define COMPSW  0
18     "components", 0,
19 #define NCOMPSW 1
20     "nocomponents", 0,
21 #define ALLSW   2
22     "all", 0,
23 #define HELPSW  3
24     "help", 4,
25
26     NULL, 0
27 };
28
29 static char *p_find();
30
31 /* \f */
32
33 /* ARGSUSED */
34
35 main(argc, argv)
36         int argc;
37         char *argv[];
38 {
39     int     i,
40             all = 0,
41             compp = 0,
42             components = -1,
43             missed = 0;
44     char   *cp,
45             buf[100],
46           **ap,
47           **argp,
48            *arguments[MAXARGS],
49            *comps[MAXARGS];
50
51     invo_name = r1bindex (argv[0], '/');
52     if ((cp = m_find (invo_name)) != NULL) {
53         ap = brkstring (cp = getcpy (cp), " ", "\n");
54         ap = copyip (ap, arguments);
55     }
56     else
57         ap = arguments;
58     (void) copyip (argv + 1, ap);
59     argp = arguments;
60
61 /* \f */
62
63     while (cp = *argp++) {
64         if (*cp == '-')
65             switch (smatch (++cp, switches)) {
66                 case AMBIGSW: 
67                     ambigsw (cp, switches);
68                     done (1);
69                 case UNKWNSW: 
70                     adios (NULLCP, "-%s unknown", cp);
71                 case HELPSW: 
72                     (void) sprintf (buf, "%s [profile-components] [switches]",
73                             invo_name);
74                     help (buf, switches);
75                     done (1);
76
77                 case COMPSW:
78                     components = 1;
79                     break;
80                 case NCOMPSW:
81                     components = 0;
82                     break;
83
84                 case ALLSW:
85                     all = 1;
86                     break;
87
88             }
89         else 
90             comps[compp++] = cp;
91     }
92
93 /* \f */
94
95     if (all) {
96         register struct node   *np;
97
98         if (compp)
99             advise(NULLCP, "profile-components ignored with -all");
100
101         if (components >= 0)
102             advise(NULLCP, "-%scomponents ignored with -all",
103                    components ? "" : "no");
104       
105         m_getdefs ();
106         for (np = m_defs; np; np = np -> n_next)
107             printf("%s:\t%s\n", np -> n_name, np -> n_field);
108     } else {
109         if (components < 0)
110             components = compp > 1;
111
112         for (i = 0; i < compp; i++)  {
113             register char *value = m_find(comps[i]);
114
115             if (!value)
116                 value = p_find(comps[i]);
117
118             if (value) {
119                 if (components)
120                     printf("%s:\t", comps[i]);
121
122                 printf("%s\n", value);
123             } else
124                 missed++;
125         }
126     }
127     
128     done (missed);
129 }
130
131 static struct procs {
132         char    *p_name;
133         char    **p_field;
134 } procs [] = {
135      { "context",       &context        },
136      { "faceproc",      &faceproc       },
137      { "fileproc",      &fileproc       },
138      { "foldprot",      &foldprot       },
139      { "incproc",       &incproc        },
140      { "installproc",   &installproc    },
141      { "lproc",         &lproc          },
142      { "mailproc",      &mailproc       },
143      { "mhlproc",       &mhlproc        },
144      { "moreproc",      &moreproc       },
145      { "msgprot",       &msgprot        },
146      { "mshproc",       &mshproc        },
147      { "packproc",      &packproc       },
148      { "postproc",      &postproc       },
149      { "rmfproc",       &rmfproc        },
150      { "rmmproc",       &rmmproc        },
151      { "sendproc",      &sendproc       },
152      { "showproc",      &showproc       },
153      { "slocalproc",    &slocalproc     },
154      { "version",       &version        },
155      { "vmhproc",       &vmhproc        },
156      { "whatnowproc",   &whatnowproc    },
157      { "whomproc",      &whomproc       },
158      { "libdir",        &mhlibdir       },
159      { "sbackup",       &sbackup        },
160      { "link",          &slink          },
161
162      { NULL, NULL },
163 };
164
165 static char *p_find(str)
166 register char *str;
167 {
168     register struct procs *ps;
169
170     for (ps = procs; ps->p_name; ps++)
171         if (uleq (ps -> p_name, str))
172             return (*ps -> p_field);
173
174     return NULL;
175 }