2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: fclndir.c /main/3 1995/11/08 11:39:49 rswiston $ */
24 /* Copyright (c) 1987-1990 Hewlett-Packard Co.
26 Fclndir.c compares two files, ignoring C line directives that appear
27 within them as well as blank lines, and leading white space. It exits
28 with an error code of 0 if the files are the same, 1 if they differ, and
29 2 if the program was called incorrectly.
32 /* Feb. 11, 1991, CED: Added v2 fixes to v3 version of fclndir.
33 Thus, both versions now copy the source file to the target if
45 /* different defined to be 0 as of 12-1-89, because fclndir now does
46 the file-copy if the files are different, or if the second file
47 doesn't exist. (different used to be 1.) --ced */
58 char linedir[] = "#line" ;
59 char *p = linedir, *q = linedir + 1 ;
69 char *pfile1, char *pfile2
75 FILE *file, struct data *data
87 fputs("Usage: fclndir file1 (=source) file2 (=target)\n", stderr) ;
90 if (! (one = fopen(argv[1], "r"))) {
91 fprintf(stderr, "ERROR: source file unavailable: %s\n", argv[1]) ;
94 if (! (two = fopen(argv[2], "r"))) {
95 fprintf(stderr, "No target file %s; copying source file...\n", argv[2]) ;
96 /* call to copyfile entered by ced, 12-29-89. */
97 copyfile(argv[1],argv[2]);
100 data1.linestart = data2.linestart = TRUE ;
101 data1.p = data2.p = linedir ;
102 data1.q = data2.q = linedir + 1 ;
103 c1 = nextchar(one, &data1) ;
104 c2 = nextchar(two, &data2) ;
105 while (c1 != EOF && c2 != EOF) {
107 fprintf(stderr, "%s and %s are different; copying source...\n",
109 /* call to copyfile entered by ced, 12-1-89. */
110 copyfile(argv[1],argv[2]);
113 c1 = nextchar(one, &data1) ;
114 c2 = nextchar(two, &data2) ;
117 fprintf(stderr, "%s and %s are different; copying source...\n",
119 /* call to copyfile entered by ced, 12-1-89. */
120 copyfile(argv[1],argv[2]);
123 fprintf(stderr, "%s and %s are the same\n", argv[1], argv[2]) ;
127 /* copyfile inserted by ced, 12-1-89. */
128 void copyfile(pfile1,pfile2)
129 char *pfile1, *pfile2;
134 /* malloc space for the system command: two filenames, plus a command,
135 spaces, and the terminating null */
136 pcmd = (char *) malloc(strlen(pfile1) + strlen(pfile2) + 8);
138 ret = sprintf(pcmd,"copy %s %s",pfile1,pfile2);
140 ret = sprintf(pcmd,"cp %s %s",pfile1,pfile2);
143 ret = sprintf(pcmd,"touch %s",pfile2);
147 int nextchar(file, data)
151 while (data->linestart) {
152 data->linestart = FALSE ;
153 for (data->p = linedir ; *data->p; data->p++)
154 if ((data->c = getc(file)) != (int) *data->p) break ;
155 /* Found a line directive, skip remainder of line */
157 data->c = getc(file) ;
158 while (data->c != '\n' && data->c != EOF)
159 data->c = getc(file) ;
160 data->linestart = TRUE ;
163 /* Check for leading blanks */
164 else if (data->p == linedir) {
165 while (data->c == ' ' || data->c == '\t') data->c = getc(file) ;
166 if (data->c == '\n') {
167 data->linestart = TRUE ;
172 /* Line began with a prefix of #line */
176 if (data->q < data->p) return(*data->q++) ;
177 else if (data->q++ != data->p) data->c = getc(file) ;
178 if (data->c == '\n') data->linestart = TRUE ;