8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / print / conv_fix / conv_fix.c
blob2833b106bb505a5ba11c5085cb32dc436ed313f4
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 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <locale.h>
33 #include <sys/file.h>
34 #include <fcntl.h>
35 #include <errno.h>
37 extern char *optarg;
40 * FUNCTION:
41 * static char *_file_getline(FILE *fp)
42 * INPUT:
43 * FILE *fp - file pointer to read from
44 * OUTPUT:
45 * char *(return) - an entry from the stream
46 * DESCRIPTION:
47 * This routine will read in a line at a time. If the line ends in a
48 * newline, it returns. If the line ends in a backslash newline, it
49 * continues reading more. It will ignore lines that start in # or
50 * blank lines.
52 static char *
53 _file_getline(FILE *fp)
55 char entry[BUFSIZ], *tmp;
56 int size;
58 size = sizeof (entry);
59 tmp = entry;
61 /* find an entry */
62 while (fgets(tmp, size, fp)) {
63 if ((tmp == entry) && ((*tmp == '#') || (*tmp == '\n'))) {
64 continue;
65 } else {
66 if ((*tmp == '#') || (*tmp == '\n')) {
67 *tmp = NULL;
68 break;
71 size -= strlen(tmp);
72 tmp += strlen(tmp);
74 if (*(tmp-2) != '\\')
75 break;
77 size -= 2;
78 tmp -= 2;
82 if (tmp == entry)
83 return (NULL);
84 else
85 return (strdup(entry));
88 int
89 main(int ac, char *av[])
91 int c;
92 char file[80], ofile[80];
93 char *cp;
94 FILE *fp, *fp2;
96 (void) setlocale(LC_ALL, "");
98 #if !defined(TEXT_DOMAIN)
99 #define TEXT_DOMAIN "SYS_TEST"
100 #endif
101 (void) textdomain(TEXT_DOMAIN);
103 while ((c = getopt(ac, av, "f:o:")) != EOF)
105 switch (c) {
106 case 'f':
107 (void) strlcpy(file, optarg, sizeof (file));
108 break;
109 case 'o':
110 (void) strlcpy(ofile, optarg, sizeof (ofile));
111 break;
112 default:
113 (void) fprintf(stderr, gettext(
114 "Usage: %s [-f file] [-o output file]\n"),
115 av[0]);
116 return (1);
119 if ((fp = fopen(file, "r")) != NULL) {
120 int fd;
122 fd = open(ofile, O_RDWR|O_APPEND);
123 if ((fd < 0) && (errno == ENOENT))
124 fd = open(ofile, O_RDWR|O_CREAT|O_EXCL, 0644);
126 if (fd < 0) {
127 (void) fprintf(stderr,
128 gettext("Error trying to open file.\n"));
129 return (1);
132 lseek(fd, 0, SEEK_END);
134 if ((fp2 = fdopen(fd, "a")) != NULL) {
135 while ((cp = _file_getline(fp)) != NULL) {
136 (void) fprintf(fp2, "%s", cp);
138 return (0);
139 } else {
140 (void) fprintf(stderr,
141 gettext("Error trying to open file.\n"));
142 return (1);
144 } else {
145 (void) fprintf(stderr,
146 gettext("Error trying to open file.\n"));
147 return (1);