+++ /dev/null
-/*\r
- * ReactOS Win32 Applications\r
- * Copyright (C) 2005 ReactOS Team\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-/*\r
- * COPYRIGHT: See COPYING in the top level directory\r
- * PROJECT: ReactOS comp utility\r
- * FILE: comp.c\r
- * PURPOSE: Compares the contents of two files\r
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)\r
- * REVISIONS:\r
- * GM 25/09/05 Created\r
- *\r
- */\r
-\r
-\r
-#include <windows.h>\r
-#include <tchar.h>\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#define STRBUF 1024\r
-\r
-/* getline: read a line, return length */\r
-INT GetLine(char *line, FILE *in)\r
-{\r
- if (fgets(line, STRBUF, in) == NULL)\r
- return 0;\r
- else\r
- return strlen(line);\r
-}\r
-\r
-/* print program usage */\r
-VOID Usage(VOID)\r
-{\r
- _tprintf(_T("\nCompares the contents of two files or sets of files.\n\n"\r
- "COMP [data1] [data2]\n\n"\r
- " data1 Specifies location and name of first file to compare.\n"\r
- " data2 Specifies location and name of second file to compare.\n"));\r
-}\r
-\r
-\r
-int _tmain (int argc, TCHAR *argv[])\r
-{\r
- INT i;\r
- INT LineLen1, LineLen2;\r
- FILE *fp1, *fp2; // file pointers\r
- PTCHAR Line1 = (TCHAR *)malloc(STRBUF * sizeof(TCHAR));\r
- PTCHAR Line2 = (TCHAR *)malloc(STRBUF * sizeof(TCHAR));\r
- TCHAR File1[_MAX_PATH], // file paths\r
- File2[_MAX_PATH];\r
- BOOL bMatch = TRUE, // files match\r
- bAscii = FALSE, // /A switch\r
- bLineNos = FALSE; // /L switch\r
-\r
- /* parse command line for options */\r
- for (i = 1; i < argc; i++)\r
- {\r
- if (argv[i][0] == '/')\r
- {\r
- --argc;\r
- switch (argv[i][1]) {\r
- case 'A': bAscii = TRUE;\r
- _tprintf(_T("/a not Supported\n")); /*FIXME: needs adding */\r
- break;\r
- case 'L': bLineNos = TRUE;\r
- _tprintf(_T("/l not supported\n")); /*FIXME: needs adding */\r
- break;\r
- case '?': Usage();\r
- return EXIT_SUCCESS;\r
- default:\r
- _tprintf(_T("Invalid switch - /%c\n"), argv[i][1]);\r
- Usage();\r
- return EXIT_FAILURE;\r
- }\r
- }\r
- }\r
-\r
- switch (argc)\r
- {\r
- case 1 :\r
- _tprintf(_T("Name of first file to compare: "));\r
- fgets(File1, _MAX_PATH, stdin);\r
- for (i=0; i<_MAX_PATH; i++)\r
- {\r
- if (File1[i] == '\n')\r
- {\r
- File1[i] = '\0';\r
- break;\r
- }\r
- }\r
-\r
- _tprintf(_T("Name of second file to compare: "));\r
- fgets(File2, _MAX_PATH, stdin);\r
- for (i=0; i<_MAX_PATH; i++)\r
- {\r
- if (File2[i] == '\n')\r
- {\r
- File2[i] = '\0';\r
- break;\r
- }\r
- }\r
- break;\r
- case 2 :\r
- _tcsncpy(File1, argv[1], _MAX_PATH);\r
- _tprintf(_T("Name of second file to compare: "));\r
- fgets(File2, _MAX_PATH, stdin);\r
- for (i=0; i<_MAX_PATH; i++)\r
- {\r
- if (File2[i] == '\n')\r
- {\r
- File2[i] = '\0';\r
- break;\r
- }\r
- }\r
- break;\r
- case 3 :\r
- _tcsncpy(File1, argv[1], _MAX_PATH);\r
- _tcsncpy(File2, argv[2], _MAX_PATH);\r
- break;\r
- default :\r
- _tprintf(_T("Bad command line syntax\n"));\r
- return EXIT_FAILURE;\r
- break;\r
- }\r
-\r
-\r
-\r
- if ((fp1 = fopen(File1, "r")) == NULL)\r
- {\r
- _tprintf(_T("Can't find/open file: %s\n"), File1);\r
- return EXIT_FAILURE;\r
- }\r
- if ((fp2 = fopen(File2, "r")) == NULL)\r
- {\r
- _tprintf(_T("Can't find/open file: %s\n"), File2);\r
- return EXIT_FAILURE;\r
- }\r
-\r
-\r
- _tprintf(_T("Comparing %s and %s...\n"), File1, File2);\r
-\r
- while ((LineLen1 = GetLine(Line1, fp1) != 0) &&\r
- (LineLen2 = GetLine(Line2, fp2) != 0))\r
- {\r
- // LineCount++;\r
- while ((*Line1 != '\0') && (*Line2 != '\0'))\r
- {\r
- if (*Line1 != *Line2)\r
- {\r
- bMatch = FALSE;\r
- break;\r
- }\r
- Line1++, Line2++;\r
- }\r
- }\r
-\r
- bMatch ? _tprintf(_T("Files compare OK\n")) : _tprintf(_T("Files are different sizes.\n"));\r
-\r
- fclose(fp1);\r
- fclose(fp2);\r
-\r
-\r
- return EXIT_SUCCESS;\r
-}\r
-/* EOF */\r