Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / dp.c,v
1 head    1.7;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.7
9 date    92.12.15.00.20.22;      author jromine; state Exp;
10 branches;
11 next    1.6;
12
13 1.6
14 date    92.11.04.00.41.38;      author jromine; state Exp;
15 branches;
16 next    1.5;
17
18 1.5
19 date    92.02.05.07.26.30;      author jromine; state Exp;
20 branches;
21 next    1.4;
22
23 1.4
24 date    92.01.31.22.09.26;      author jromine; state Exp;
25 branches;
26 next    1.3;
27
28 1.3
29 date    90.04.05.15.01.00;      author sources; state Exp;
30 branches;
31 next    1.2;
32
33 1.2
34 date    90.02.06.13.17.52;      author sources; state Exp;
35 branches;
36 next    1.1;
37
38 1.1
39 date    90.02.06.13.17.41;      author sources; state Exp;
40 branches;
41 next    ;
42
43
44 desc
45 @@
46
47
48 1.7
49 log
50 @endif sugar
51 @
52 text
53 @/* dp.c  - parse dates 822-style */
54 #ifndef lint
55 static char ident[] = "@@(#)$Id: dp.c,v 1.6 1992/11/04 00:41:38 jromine Exp jromine $";
56 #endif  /* lint */
57
58 #include "../h/mh.h"
59 #include "../h/formatsbr.h"
60 #include "../zotnet/tws.h"
61 #include <stdio.h>
62 #ifdef LOCALE
63 #include        <locale.h>
64 #endif
65
66
67 #define NDATES  100
68
69 #define WIDTH   78
70 #define WBUFSIZ BUFSIZ
71
72 #define FORMAT  "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
73
74 /* \f */
75
76 static struct swit switches[] = {
77 #define FORMSW  0
78     "form formatfile", 0,
79 #define FMTSW   1
80     "format string", 5,
81
82 #define WIDSW   2
83     "width columns", 0,
84
85 #define HELPSW  3
86     "help", 4,
87
88     NULL, 0
89 };
90
91 /* \f */
92
93 static struct format *fmt;
94
95 static int dat[5];
96
97 static int      process();
98 /* \f */
99
100 /* ARGSUSED */
101
102 main (argc, argv)
103 int argc;
104 char **argv;
105 {
106     int     datep = 0,
107             width = 0,
108             status = 0;
109     char   *cp,
110            *form = NULL,
111            *format = NULL,
112            *nfs,
113             buf[80],
114           **ap,
115           **argp,
116            *arguments[MAXARGS],
117            *dates[NDATES];
118
119 #ifdef LOCALE
120         setlocale(LC_ALL, "");
121 #endif
122     invo_name = r1bindex (argv[0], '/');
123     if ((cp = m_find (invo_name)) != NULL) {
124         ap = brkstring (cp = getcpy (cp), " ", "\n");
125         ap = copyip (ap, arguments);
126     }
127     else
128         ap = arguments;
129     (void) copyip (argv + 1, ap);
130     argp = arguments;
131
132 /* \f */
133
134     while (cp = *argp++) {
135         if (*cp == '-')
136             switch (smatch (++cp, switches)) {
137                 case AMBIGSW: 
138                     ambigsw (cp, switches);
139                     done (1);
140                 case UNKWNSW: 
141                     adios (NULLCP, "-%s unknown", cp);
142                 case HELPSW: 
143                     (void) sprintf (buf, "%s [switches] dates ...", invo_name);
144                     help (buf, switches);
145                     done (1);
146
147                 case FORMSW: 
148                     if (!(form = *argp++) || *form == '-')
149                         adios (NULLCP, "missing argument to %s", argp[-2]);
150                     format = NULL;
151                     continue;
152                 case FMTSW: 
153                     if (!(format = *argp++) || *format == '-')
154                         adios (NULLCP, "missing argument to %s", argp[-2]);
155                     form = NULL;
156                     continue;
157
158                 case WIDSW: 
159                     if (!(cp = *argp++) || *cp == '-')
160                         adios (NULLCP, "missing argument to %s", argp[-2]);
161                     width = atoi (cp);
162                     continue;
163             }
164         if (datep > NDATES)
165             adios (NULLCP, "more than %d dates", NDATES);
166         else
167             dates[datep++] = cp;
168     }
169     dates[datep] = NULL;
170
171 /* \f */
172
173     if (datep == 0)
174         adios (NULLCP, "usage: %s [switches] dates ...", invo_name);
175
176     nfs = new_fs (form, format, FORMAT);
177     if (width == 0) {
178         if ((width = sc_width ()) < WIDTH / 2)
179             width = WIDTH / 2;
180         width -= 2;
181     }
182     if (width > WBUFSIZ)
183         width = WBUFSIZ;
184     (void) fmt_compile (nfs, &fmt);
185     dat[0] = dat[1] = dat[2] = dat[4] = 0;
186     dat[3] = width;
187
188     for (datep = 0; dates[datep]; datep++)
189         status += process (dates[datep], width);
190
191     m_update ();
192
193     done (status);
194 }
195
196 /* \f */
197
198 static  int process (date, length)
199 register char   *date;
200 int     length;
201 {
202     int     status = 0;
203     char    buffer[WBUFSIZ + 1];
204     register struct comp   *cptr;
205
206     FINDCOMP (cptr, "text");
207     if (cptr)
208         cptr -> c_text = date;
209     (void) fmtscan (fmt, buffer, length, dat);
210     (void) fputs (buffer, stdout);
211
212     return status;
213 }
214 @
215
216
217 1.6
218 log
219 @LOCALE
220 @
221 text
222 @d3 2
223 a4 2
224 static char ident[] = "@@(#)$Id: dp.c,v 1.5 1992/02/05 07:26:30 jromine Exp jromine $";
225 #endif  lint
226 @
227
228
229 1.5
230 log
231 @put unseen sequence in mh-format
232 @
233 text
234 @d3 1
235 a3 1
236 static char ident[] = "@@(#)$Id: dp.c,v 1.4 1992/01/31 22:09:26 jromine Exp jromine $";
237 d10 3
238 d67 3
239 @
240
241
242 1.4
243 log
244 @kerberos
245 @
246 text
247 @d3 1
248 a3 1
249 static char ident[] = "@@(#)$Id: dp.c,v 1.3 1990/04/05 15:01:00 sources Exp jromine $";
250 d40 1
251 a40 1
252 static int dat[4];
253 d127 1
254 a127 1
255     dat[0] = dat[1] = dat[2] = 0;
256 @
257
258
259 1.3
260 log
261 @add ID
262 @
263 text
264 @d3 1
265 a3 1
266 static char ident[] = "@@(#)$Id:$";
267 d33 1
268 a33 1
269     NULL, NULL
270 @
271
272
273 1.2
274 log
275 @ANSI Compilance
276 @
277 text
278 @d2 3
279 @
280
281
282 1.1
283 log
284 @Initial revision
285 @
286 text
287 @d39 1
288 @