8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / ypcmd / nick.c
blob4ebf413233f8b4628fe75ea8c935c944831dbc3b
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
23 * Copyright (c) 1986-1992 by Sun Microsystems Inc.
26 #include <stdio.h>
27 #include <rpc/rpc.h>
28 #include <rpcsvc/yp_prot.h>
29 #include <rpcsvc/ypclnt.h>
30 #include <string.h>
31 #include <unistd.h>
33 #define MAXMAPS 500
34 /* number of nickname file entries arbitrarily limited */
36 static char NICKFILE[] = "/var/yp/nicknames";
37 static char *transtable[MAXMAPS];
40 * This will read nicknames from file /var/yp/nicknames
41 * and print it out or save it for future use.
43 void
44 maketable(dump)
45 int dump;
47 FILE *nickp;
48 int i = 0;
49 char nickbuf[2*YPMAXMAP+3], nickname[YPMAXMAP+1], mapname[YPMAXMAP+1];
51 if ((nickp = fopen(NICKFILE, "r")) == NULL) {
52 (void) fprintf(stderr, "nickname file %s does not exist\n",
53 NICKFILE);
54 exit(1);
56 while (fgets(nickbuf, YPMAXMAP, nickp) != NULL) {
57 if (strchr(nickbuf, '\n') == NULL) {
58 (void) fprintf(stderr,
59 "garbled nickname file %s\n", NICKFILE);
60 exit(1);
62 (void) memset(nickname, 0, YPMAXMAP+1);
63 (void) memset(mapname, 0, YPMAXMAP+1);
64 if (sscanf(nickbuf, "%s %s\n", nickname, mapname) != 2) {
65 (void) fprintf(stderr,
66 "garbled nickname file %s\n", NICKFILE);
67 exit(1);
69 if (!dump) {
70 transtable[i] = strdup(nickname);
71 transtable[i+1] = strdup(mapname);
72 i += 2;
73 transtable[i] = NULL;
74 } else {
75 printf("Use \"%s\"\tfor map \"%s\"\n",
76 nickname, mapname);
79 fclose(nickp);
83 * This will get the mapname for a given nickname from the file.
85 int
86 getmapname(nick, map)
87 char *nick, *map;
89 FILE *nickp;
90 char nickbuf[2*YPMAXMAP+3], nickname[YPMAXMAP+1];
92 if ((nickp = fopen(NICKFILE, "r")) == NULL)
93 return (0);
94 while (fgets(nickbuf, YPMAXMAP, nickp) != NULL) {
95 if (strchr(nickbuf, '\n') == NULL) {
96 fclose(nickp);
97 return (0);
99 (void) memset(nickname, 0, YPMAXMAP+1);
100 (void) memset(map, 0, YPMAXMAP+1);
101 if (sscanf(nickbuf, "%s %s\n", nickname, map) != 2) {
102 fclose(nickp);
103 return (0);
105 if (strcmp(nick, nickname) == 0) {
106 fclose(nickp);
107 return (1);
110 fclose(nickp);
111 return (0);