2 * ReactOS Win32 Applications
3 * Copyright (C) 2005 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS comp utility
23 * PURPOSE: Compares the contents of two files
24 * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
39 /* getline: read a line, return length */
40 INT
GetLine(char *line
, FILE *in
)
42 if (fgets(line
, STRBUF
, in
) == NULL
)
48 /* print program usage */
51 _tprintf(_T("\nCompares the contents of two files or sets of files.\n\n"
52 "COMP [data1] [data2]\n\n"
53 " data1 Specifies location and name of first file to compare.\n"
54 " data2 Specifies location and name of second file to compare.\n"));
58 int _tmain (int argc
, TCHAR
*argv
[])
61 FILE *fp1
, *fp2
; // file pointers
62 PTCHAR Line1
= (TCHAR
*)malloc(STRBUF
* sizeof(TCHAR
));
63 PTCHAR Line2
= (TCHAR
*)malloc(STRBUF
* sizeof(TCHAR
));
64 TCHAR File1
[_MAX_PATH
], // file paths
66 BOOL bMatch
= TRUE
, // files match
67 bAscii
= FALSE
, // /A switch
68 bLineNos
= FALSE
; // /L switch
70 /* parse command line for options */
71 for (i
= 1; i
< argc
; i
++)
73 if (argv
[i
][0] == '/')
77 case 'A': bAscii
= TRUE
;
78 _tprintf(_T("/a not Supported\n")); (void)bAscii
; /*FIXME: needs adding */
80 case 'L': bLineNos
= TRUE
;
81 _tprintf(_T("/l not supported\n")); (void)bLineNos
; /*FIXME: needs adding */
86 _tprintf(_T("Invalid switch - /%c\n"), argv
[i
][1]);
96 _tprintf(_T("Name of first file to compare: "));
97 fgets(File1
, _MAX_PATH
, stdin
);
98 for (i
=0; i
<_MAX_PATH
; i
++)
100 if (File1
[i
] == '\n')
107 _tprintf(_T("Name of second file to compare: "));
108 fgets(File2
, _MAX_PATH
, stdin
);
109 for (i
=0; i
<_MAX_PATH
; i
++)
111 if (File2
[i
] == '\n')
119 _tcsncpy(File1
, argv
[1], _MAX_PATH
);
120 _tprintf(_T("Name of second file to compare: "));
121 fgets(File2
, _MAX_PATH
, stdin
);
122 for (i
=0; i
<_MAX_PATH
; i
++)
124 if (File2
[i
] == '\n')
132 _tcsncpy(File1
, argv
[1], _MAX_PATH
);
133 _tcsncpy(File2
, argv
[2], _MAX_PATH
);
136 _tprintf(_T("Bad command line syntax\n"));
143 if ((fp1
= fopen(File1
, "r")) == NULL
)
145 _tprintf(_T("Can't find/open file: %s\n"), File1
);
148 if ((fp2
= fopen(File2
, "r")) == NULL
)
150 _tprintf(_T("Can't find/open file: %s\n"), File2
);
156 _tprintf(_T("Comparing %s and %s...\n"), File1
, File2
);
158 while ((GetLine(Line1
, fp1
) != 0) &&
159 (GetLine(Line2
, fp2
) != 0))
162 while ((*Line1
!= '\0') && (*Line2
!= '\0'))
164 if (*Line1
!= *Line2
)
173 bMatch
? _tprintf(_T("Files compare OK\n")) : _tprintf(_T("Files are different sizes.\n"));