Deleted Added
full compact
parse.c (50477) parse.c (80290)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
37#endif
38static const char rcsid[] =
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/usr.bin/hexdump/parse.c 50477 1999-08-28 01:08:13Z peter $";
39 "$FreeBSD: head/usr.bin/hexdump/parse.c 80290 2001-07-24 14:11:09Z obrien $";
40#endif /* not lint */
41
42#include <sys/types.h>
43
44#include <err.h>
45#include <fcntl.h>
46#include <stdio.h>
47#include <stdlib.h>

--- 34 unchanged lines hidden (view full) ---

82 char *fmt;
83{
84 unsigned char *p, *savep;
85 static FS **nextfs;
86 FS *tfs;
87 FU *tfu, **nextfu;
88
89 /* start new linked list of format units */
40#endif /* not lint */
41
42#include <sys/types.h>
43
44#include <err.h>
45#include <fcntl.h>
46#include <stdio.h>
47#include <stdlib.h>

--- 34 unchanged lines hidden (view full) ---

82 char *fmt;
83{
84 unsigned char *p, *savep;
85 static FS **nextfs;
86 FS *tfs;
87 FU *tfu, **nextfu;
88
89 /* start new linked list of format units */
90 tfs = emalloc(sizeof(FS));
90 if ((tfs = calloc(1, sizeof(FS))) == NULL)
91 err(1, NULL);
91 if (!fshead)
92 fshead = tfs;
93 else
94 *nextfs = tfs;
95 nextfs = &tfs->nextfs;
96 nextfu = &tfs->nextfu;
97
98 /* take the format string and break it up into format units */
99 for (p = fmt;;) {
100 /* skip leading white space */
101 for (; isspace(*p); ++p);
102 if (!*p)
103 break;
104
105 /* allocate a new format unit and link it in */
92 if (!fshead)
93 fshead = tfs;
94 else
95 *nextfs = tfs;
96 nextfs = &tfs->nextfs;
97 nextfu = &tfs->nextfu;
98
99 /* take the format string and break it up into format units */
100 for (p = fmt;;) {
101 /* skip leading white space */
102 for (; isspace(*p); ++p);
103 if (!*p)
104 break;
105
106 /* allocate a new format unit and link it in */
106 tfu = emalloc(sizeof(FU));
107 if ((tfu = calloc(1, sizeof(FU))) == NULL)
108 err(1, NULL);
107 *nextfu = tfu;
108 nextfu = &tfu->nextfu;
109 tfu->reps = 1;
110
111 /* if leading digit, repetition count */
112 if (isdigit(*p)) {
113 for (savep = p; isdigit(*p); ++p);
114 if (!isspace(*p) && *p != '/')

--- 21 unchanged lines hidden (view full) ---

136
137 /* format */
138 if (*p != '"')
139 badfmt(fmt);
140 for (savep = ++p; *p != '"';)
141 if (*p++ == 0)
142 badfmt(fmt);
143 if (!(tfu->fmt = malloc(p - savep + 1)))
109 *nextfu = tfu;
110 nextfu = &tfu->nextfu;
111 tfu->reps = 1;
112
113 /* if leading digit, repetition count */
114 if (isdigit(*p)) {
115 for (savep = p; isdigit(*p); ++p);
116 if (!isspace(*p) && *p != '/')

--- 21 unchanged lines hidden (view full) ---

138
139 /* format */
140 if (*p != '"')
141 badfmt(fmt);
142 for (savep = ++p; *p != '"';)
143 if (*p++ == 0)
144 badfmt(fmt);
145 if (!(tfu->fmt = malloc(p - savep + 1)))
144 nomem();
146 err(1, NULL);
145 (void) strncpy(tfu->fmt, savep, p - savep);
146 tfu->fmt[p - savep] = '\0';
147 escape(tfu->fmt);
148 p++;
149 }
150}
151
152static char *spec = ".#-+ 0123456789";

--- 64 unchanged lines hidden (view full) ---

217 int nconv, prec;
218
219 for (fu = fs->nextfu; fu; fu = fu->nextfu) {
220 /*
221 * Break each format unit into print units; each conversion
222 * character gets its own.
223 */
224 for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
147 (void) strncpy(tfu->fmt, savep, p - savep);
148 tfu->fmt[p - savep] = '\0';
149 escape(tfu->fmt);
150 p++;
151 }
152}
153
154static char *spec = ".#-+ 0123456789";

--- 64 unchanged lines hidden (view full) ---

219 int nconv, prec;
220
221 for (fu = fs->nextfu; fu; fu = fu->nextfu) {
222 /*
223 * Break each format unit into print units; each conversion
224 * character gets its own.
225 */
226 for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
225 pr = emalloc(sizeof(PR));
227 if ((pr = calloc(1, sizeof(PR))) == NULL)
228 err(1, NULL);
226 if (!fu->nextpr)
227 fu->nextpr = pr;
228 else
229 *nextpr = pr;
230
231 /* Skip preceding text and up to the next % sign. */
232 for (p1 = fmtp; *p1 && *p1 != '%'; ++p1);
233

--- 146 unchanged lines hidden (view full) ---

380 }
381
382 /*
383 * Copy to PR format string, set conversion character
384 * pointer, update original.
385 */
386 savech = *p2;
387 p1[0] = '\0';
229 if (!fu->nextpr)
230 fu->nextpr = pr;
231 else
232 *nextpr = pr;
233
234 /* Skip preceding text and up to the next % sign. */
235 for (p1 = fmtp; *p1 && *p1 != '%'; ++p1);
236

--- 146 unchanged lines hidden (view full) ---

383 }
384
385 /*
386 * Copy to PR format string, set conversion character
387 * pointer, update original.
388 */
389 savech = *p2;
390 p1[0] = '\0';
388 pr->fmt = emalloc(strlen(fmtp) + 2);
391 if ((pr->fmt = calloc(1, strlen(fmtp) + 2)) == NULL)
392 err(1, NULL);
389 (void)strcpy(pr->fmt, fmtp);
390 (void)strcat(pr->fmt, cs);
391 *p2 = savech;
392 pr->cchar = pr->fmt + (p1 - fmtp);
393 fmtp = p2;
394
395 /* Only one conversion character if byte count. */
396 if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++)

--- 114 unchanged lines hidden ---
393 (void)strcpy(pr->fmt, fmtp);
394 (void)strcat(pr->fmt, cs);
395 *p2 = savech;
396 pr->cchar = pr->fmt + (p1 - fmtp);
397 fmtp = p2;
398
399 /* Only one conversion character if byte count. */
400 if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++)

--- 114 unchanged lines hidden ---