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 INT LineLen1
, LineLen2
;
62 FILE *fp1
, *fp2
; // file pointers
63 PTCHAR Line1
= (TCHAR
*)malloc(STRBUF
* sizeof(TCHAR
));
64 PTCHAR Line2
= (TCHAR
*)malloc(STRBUF
* sizeof(TCHAR
));
65 TCHAR File1
[_MAX_PATH
], // file paths
67 BOOL bMatch
= TRUE
, // files match
68 bAscii
= FALSE
, // /A switch
69 bLineNos
= FALSE
; // /L switch
71 /* parse command line for options */
72 for (i
= 1; i
< argc
; i
++)
74 if (argv
[i
][0] == '/')
78 case 'A': bAscii
= TRUE
;
79 _tprintf(_T("/a not Supported\n")); /*FIXME: needs adding */
81 case 'L': bLineNos
= TRUE
;
82 _tprintf(_T("/l not supported\n")); /*FIXME: needs adding */
87 _tprintf(_T("Invalid switch - /%c\n"), argv
[i
][1]);
97 _tprintf(_T("Name of first file to compare: "));
98 fgets(File1
, _MAX_PATH
, stdin
);
99 for (i
=0; i
<_MAX_PATH
; i
++)
101 if (File1
[i
] == '\n')
108 _tprintf(_T("Name of second file to compare: "));
109 fgets(File2
, _MAX_PATH
, stdin
);
110 for (i
=0; i
<_MAX_PATH
; i
++)
112 if (File2
[i
] == '\n')
120 _tcsncpy(File1
, argv
[1], _MAX_PATH
);
121 _tprintf(_T("Name of second file to compare: "));
122 fgets(File2
, _MAX_PATH
, stdin
);
123 for (i
=0; i
<_MAX_PATH
; i
++)
125 if (File2
[i
] == '\n')
133 _tcsncpy(File1
, argv
[1], _MAX_PATH
);
134 _tcsncpy(File2
, argv
[2], _MAX_PATH
);
137 _tprintf(_T("Bad command line syntax\n"));
144 if ((fp1
= fopen(File1
, "r")) == NULL
)
146 _tprintf(_T("Can't find/open file: %s\n"), File1
);
149 if ((fp2
= fopen(File2
, "r")) == NULL
)
151 _tprintf(_T("Can't find/open file: %s\n"), File2
);
156 _tprintf(_T("Comparing %s and %s...\n"), File1
, File2
);
158 while ((LineLen1
= GetLine(Line1
, fp1
) != 0) &&
159 (LineLen2
= 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"));