cmd-inet/usr.sbin: remove -Wno-implicit-function-declaration
[unleashed.git] / usr / src / cmd / ypcmd / getlist.c
blob45467e290f7013fd90bc0aebacafd67aaf37824a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 * Copyright 1992 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * Portions of this source code were derived from Berkeley
31 * under license from the Regents of the University of
32 * California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include "ypsym.h"
41 extern void free();
42 extern char *strdup();
45 * Add a name to the list
47 static listofnames *
48 newname(str)
49 char *str;
51 listofnames *it;
52 char *copy;
54 if (str == NULL)
55 return (NULL);
56 copy = strdup(str);
57 if (copy == NULL)
58 return (NULL);
59 it = (listofnames *) malloc(sizeof (listofnames));
60 if (it == NULL) {
61 free(copy);
62 return (NULL);
64 it->name = copy;
65 it->nextname = NULL;
66 return (it);
70 * Assemble the list of names
72 listofnames *
73 names(filename)
74 char *filename;
76 listofnames *nameslist;
77 listofnames *end;
78 listofnames *nname;
79 FILE *fyle;
80 char line[256];
81 char name[256];
83 fyle = fopen(filename, "r");
84 if (fyle == NULL) {
85 return (NULL);
87 nameslist = NULL;
88 while (fgets(line, sizeof (line), fyle)) {
89 if (line[0] == '#') continue;
90 if (line[0] == '\0') continue;
91 if (line[0] == '\n') continue;
92 nname = newname(line);
93 if (nname) {
94 if (nameslist == NULL) {
95 nameslist = nname;
96 end = nname;
97 } else {
98 end->nextname = nname;
99 end = nname;
101 } else
102 fprintf(stderr,
103 "file %s bad malloc %s\n", filename, name);
105 fclose(fyle);
106 return (nameslist);
109 void
110 free_listofnames(locallist)
111 listofnames *locallist;
113 listofnames *next = (listofnames *)NULL;
115 for (; locallist; locallist = next) {
116 next = locallist->nextname;
117 if (locallist->name)
118 free(locallist->name);
119 free((char *)locallist);
124 #ifdef MAIN
125 main(argc, argv)
126 char **argv;
128 listofnames *list;
129 list = names(argv[1]);
130 #ifdef DEBUG
131 print_listofnames(list);
132 #endif
133 free_listofnames(list);
134 #ifdef DEBUG
135 printf("Done\n");
136 #endif
138 #endif
140 #ifdef DEBUG
141 void
142 print_listofnames(list)
143 listofnames *list;
145 if (list == NULL)
146 printf("NULL\n");
147 for (; list; list = list->nextname)
148 printf("%s\n", list->name);
150 #endif