8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / ypcmd / revnetgroup / util.c
blobcde75016b5046c1d20b2ad7fb81678f4fcfe7e3a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <stdio.h>
27 #include <string.h>
28 #include "util.h"
34 * This is just like fgets, but recognizes that "\\n" signals a continuation
35 * of a line
37 char *
38 getaline(line, maxlen, fp)
39 char *line;
40 int maxlen;
41 FILE *fp;
43 register char *p;
44 register char *start;
45 int c;
47 start = line;
49 nextline:
50 if (fgets(start, maxlen, fp) == NULL) {
51 return (NULL);
53 for (p = start; *p; p++) {
54 if (*p == '\n') {
55 if (p > start && *(p-1) == '\\') {
56 start = p - 1;
57 maxlen++;
58 goto nextline;
59 } else {
60 return (line);
63 maxlen--;
67 * Input line is too long. Rest of the line needs to be discarded.
68 * Reinsert the last char into the stream. This is done so that
69 * in case the last char read is '\' and it is followed by a '\n'
70 * then the next line too can be discarded.
72 if (p > start)
73 (void) ungetc(*(p-1), fp);
76 * Discard the rest of the line
78 while ((c = getc(fp)) != EOF) {
79 if (c == '\n')
80 break;
81 else if (c == '\\') {
83 * Ignore the next character except EOF
85 if (getc(fp) == EOF)
86 break;
90 maxlen = strlen(line) + 1;
93 * Certain functions expects a newline in the buffer.
95 if (maxlen >= 2)
96 line[maxlen - 2] = '\n';
97 (void) fprintf(stderr, "Following line too long - remaining chars "
98 "ignored\n--- %s", line);
99 return (line);
103 void
104 fatal(message)
105 char *message;
107 (void) fprintf(stderr, "fatal error: %s\n", message);
108 exit(1);