Deleted Added
full compact
mkheaders.c (100472) mkheaders.c (110895)
1/*
2 * Copyright (c) 1980, 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[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
37#endif
38static const char rcsid[] =
1/*
2 * Copyright (c) 1980, 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[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/usr.sbin/config/mkheaders.c 100472 2002-07-21 23:31:43Z peter $";
39 "$FreeBSD: head/usr.sbin/config/mkheaders.c 110895 2003-02-15 02:26:13Z ru $";
40#endif /* not lint */
41
42/*
43 * Make all the .h files for the optional entries
44 */
45
46#include <ctype.h>
47#include <err.h>

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

59headers(void)
60{
61 struct file_list *fl;
62 struct device *dp;
63 int match;
64 int errors;
65
66 errors = 0;
40#endif /* not lint */
41
42/*
43 * Make all the .h files for the optional entries
44 */
45
46#include <ctype.h>
47#include <err.h>

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

59headers(void)
60{
61 struct file_list *fl;
62 struct device *dp;
63 int match;
64 int errors;
65
66 errors = 0;
67 for (fl = ftab; fl != 0; fl = fl->f_next) {
67 STAILQ_FOREACH(fl, &ftab, f_next) {
68 if (fl->f_needs != 0) {
69 match = 0;
68 if (fl->f_needs != 0) {
69 match = 0;
70 for (dp = dtab; dp != 0; dp = dp->d_next) {
70 STAILQ_FOREACH(dp, &dtab, d_next) {
71 if (eq(dp->d_name, fl->f_needs)) {
72 match++;
73 dp->d_done |= DEVDONE;
74 }
75 }
76 if (fl->f_flags & NEED_COUNT)
77 errors += do_header(fl->f_needs, match);
78 }
79 }
71 if (eq(dp->d_name, fl->f_needs)) {
72 match++;
73 dp->d_done |= DEVDONE;
74 }
75 }
76 if (fl->f_flags & NEED_COUNT)
77 errors += do_header(fl->f_needs, match);
78 }
79 }
80 for (dp = dtab; dp != 0; dp = dp->d_next) {
80 STAILQ_FOREACH(dp, &dtab, d_next) {
81 if (!(dp->d_done & DEVDONE)) {
82 warnx("Error: device \"%s\" is unknown",
83 dp->d_name);
84 errors++;
85 }
86 if (dp->d_count == UNKNOWN)
87 continue;
88 match = 0;
81 if (!(dp->d_done & DEVDONE)) {
82 warnx("Error: device \"%s\" is unknown",
83 dp->d_name);
84 errors++;
85 }
86 if (dp->d_count == UNKNOWN)
87 continue;
88 match = 0;
89 for (fl = ftab; fl != 0; fl = fl->f_next) {
89 STAILQ_FOREACH(fl, &ftab, f_next) {
90 if (fl->f_needs == 0)
91 continue;
92 if ((fl->f_flags & NEED_COUNT) == 0)
93 continue;
94 if (eq(dp->d_name, fl->f_needs)) {
95 match++;
96 break;
97 }

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

105 if (errors)
106 errx(1, "%d errors", errors);
107}
108
109static int
110do_header(char *dev, int match)
111{
112 char *file, *name, *inw;
90 if (fl->f_needs == 0)
91 continue;
92 if ((fl->f_flags & NEED_COUNT) == 0)
93 continue;
94 if (eq(dp->d_name, fl->f_needs)) {
95 match++;
96 break;
97 }

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

105 if (errors)
106 errx(1, "%d errors", errors);
107}
108
109static int
110do_header(char *dev, int match)
111{
112 char *file, *name, *inw;
113 struct file_list *fl, *fl_head, *tflp;
113 struct file_list *fl, *tflp;
114 struct file_list_head fl_head;
114 struct device *dp;
115 FILE *inf, *outf;
116 int inc, oldcount;
117 int count, hicount;
118 int errors;
119
120 /*
121 * After this loop, "count" will be the actual number of units,
122 * and "hicount" will be the highest unit declared. do_header()
123 * must use this higher of these values.
124 */
125 errors = 0;
115 struct device *dp;
116 FILE *inf, *outf;
117 int inc, oldcount;
118 int count, hicount;
119 int errors;
120
121 /*
122 * After this loop, "count" will be the actual number of units,
123 * and "hicount" will be the highest unit declared. do_header()
124 * must use this higher of these values.
125 */
126 errors = 0;
126 for (hicount = count = 0, dp = dtab; dp != 0; dp = dp->d_next) {
127 hicount = count = 0;
128 STAILQ_FOREACH(dp, &dtab, d_next) {
127 if (eq(dp->d_name, dev)) {
128 if (dp->d_count == UNKNOWN) {
129 warnx("Device \"%s\" requires a count", dev);
130 return 1;
131 }
132 count = dp->d_count;
133 break;
134 }

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

143 if (inf == 0) {
144 outf = fopen(file, "w");
145 if (outf == 0)
146 err(1, "%s", file);
147 fprintf(outf, "#define %s %d\n", name, count);
148 (void) fclose(outf);
149 return 0;
150 }
129 if (eq(dp->d_name, dev)) {
130 if (dp->d_count == UNKNOWN) {
131 warnx("Device \"%s\" requires a count", dev);
132 return 1;
133 }
134 count = dp->d_count;
135 break;
136 }

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

145 if (inf == 0) {
146 outf = fopen(file, "w");
147 if (outf == 0)
148 err(1, "%s", file);
149 fprintf(outf, "#define %s %d\n", name, count);
150 (void) fclose(outf);
151 return 0;
152 }
151 fl_head = NULL;
153 STAILQ_INIT(&fl_head);
152 for (;;) {
153 char *cp;
154 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
155 break;
156 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
157 break;
158 inw = ns(inw);
159 cp = get_word(inf);

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

166 }
167 cp = get_word(inf);
168 if (cp == (char *)EOF)
169 break;
170 fl = (struct file_list *) malloc(sizeof *fl);
171 bzero(fl, sizeof(*fl));
172 fl->f_fn = inw; /* malloced */
173 fl->f_type = inc;
154 for (;;) {
155 char *cp;
156 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
157 break;
158 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
159 break;
160 inw = ns(inw);
161 cp = get_word(inf);

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

168 }
169 cp = get_word(inf);
170 if (cp == (char *)EOF)
171 break;
172 fl = (struct file_list *) malloc(sizeof *fl);
173 bzero(fl, sizeof(*fl));
174 fl->f_fn = inw; /* malloced */
175 fl->f_type = inc;
174 fl->f_next = fl_head;
175 fl_head = fl;
176 STAILQ_INSERT_HEAD(&fl_head, fl, f_next);
176 }
177 (void) fclose(inf);
178 if (count == oldcount) {
177 }
178 (void) fclose(inf);
179 if (count == oldcount) {
179 for (fl = fl_head; fl != NULL; fl = tflp) {
180 tflp = fl->f_next;
180 for (fl = STAILQ_FIRST(&fl_head); fl != NULL; fl = tflp) {
181 tflp = STAILQ_NEXT(fl, f_next);
181 free(fl->f_fn);
182 free(fl);
183 }
184 return 0;
185 }
186 if (oldcount == -1) {
187 fl = (struct file_list *) malloc(sizeof *fl);
188 bzero(fl, sizeof(*fl));
189 fl->f_fn = ns(name);
190 fl->f_type = count;
182 free(fl->f_fn);
183 free(fl);
184 }
185 return 0;
186 }
187 if (oldcount == -1) {
188 fl = (struct file_list *) malloc(sizeof *fl);
189 bzero(fl, sizeof(*fl));
190 fl->f_fn = ns(name);
191 fl->f_type = count;
191 fl->f_next = fl_head;
192 fl_head = fl;
192 STAILQ_INSERT_HEAD(&fl_head, fl, f_next);
193 }
194 outf = fopen(file, "w");
195 if (outf == 0)
196 err(1, "%s", file);
193 }
194 outf = fopen(file, "w");
195 if (outf == 0)
196 err(1, "%s", file);
197 for (fl = fl_head; fl != NULL; fl = tflp) {
197 for (fl = STAILQ_FIRST(&fl_head); fl != NULL; fl = tflp) {
198 fprintf(outf,
199 "#define %s %u\n", fl->f_fn, count ? fl->f_type : 0);
198 fprintf(outf,
199 "#define %s %u\n", fl->f_fn, count ? fl->f_type : 0);
200 tflp = fl->f_next;
200 tflp = STAILQ_NEXT(fl, f_next);
201 free(fl->f_fn);
202 free(fl);
203 }
204 (void) fclose(outf);
205 return 0;
206}
207
208/*

--- 27 unchanged lines hidden ---
201 free(fl->f_fn);
202 free(fl);
203 }
204 (void) fclose(outf);
205 return 0;
206}
207
208/*

--- 27 unchanged lines hidden ---