+/*\r
+ * $Id: cmpdef.cmd,v 1.2 1998/08/29 21:44:47 tom Exp $\r
+ *\r
+ * Author: Juan Jose Garcia Ripoll <worm@arrakis.es>.\r
+ * Webpage: http://www.arrakis.es/~worm/\r
+ *\r
+ * cmpdef.cmd - compares two .def files, checking whether they have\r
+ * the same entries with the same export codes.\r
+ *\r
+ * returns 0 if there are no conflicts between the files -- that is,\r
+ * the newer one can replace the older one.\r
+ *\r
+ * returns 1 when either of the files is not properly formatted and\r
+ * when there are conflicts: two symbols having the same export code.\r
+ *\r
+ * the standard output shows a list with newly added symbols, plus\r
+ * replaced symbols and conflicts.\r
+ */\r
+parse arg def_file1 def_file2\r
+\r
+def_file1 = translate(def_file1,'\','/')\r
+def_file2 = translate(def_file2,'\','/')\r
+\r
+call CleanQueue\r
+\r
+/*\r
+ * `cmp' is zero when the last file is valid and upward compatible\r
+ * `numbers' is the stem where symbols are stored\r
+ */\r
+cmp = 0\r
+names. = ''\r
+numbers. = 0\r
+\r
+/*\r
+ * This sed expression cleans empty lines, comments and special .DEF\r
+ * commands, such as LIBRARY..., EXPORTS..., etc\r
+ */\r
+tidy_up = '"s/[ ][ ]*/ /g;s/;.*//g;/^[ ]*$/d;/^[a-zA-Z]/d;"'\r
+\r
+/*\r
+ * First we find all public symbols from the original DLL. All this\r
+ * information is pushed into a REXX private list with the RXQUEUE\r
+ * utility program.\r
+ */\r
+'@echo off'\r
+'type' def_file1 '| sed' tidy_up '| sort | rxqueue'\r
+\r
+do while queued() > 0\r
+ /*\r
+ * We retrieve the symbol name (NAME) and its number (NUMBER)\r
+ */\r
+ parse pull '"' name '"' '@'number rest\r
+ if number = '' || name = '' then\r
+ do\r
+ say 'Corrupted file' def_file1\r
+ say 'Symbol' name 'has no number'\r
+ exit 1\r
+ end\r
+ else\r
+ do\r
+ numbers.name = number\r
+ names.number = name\r
+ end\r
+end\r
+\r
+/*\r
+ * Now we find all public symbols from the new DLL, and compare.\r
+ */\r
+'type' def_file2 '| sed' tidy_up '| sort | rxqueue'\r
+\r
+do while queued() > 0\r
+ parse pull '"' name '"' '@'number rest\r
+ if name = '' | number = '' then\r
+ do\r
+ say 'Corrupted file' def_file2\r
+ say 'Symbol' name 'has no number'\r
+ exit 1\r
+ end\r
+ if numbers.name = 0 then\r
+ do\r
+ cmp = 1\r
+ if names.number = '' then\r
+ say 'New symbol' name 'with code @'number\r
+ else\r
+ say 'Conflict old =' names.number ', new =' name 'at @'number\r
+ end\r
+ else if numbers.name \= number then\r
+ do\r
+ cmp = 1\r
+ say name 'Symbol' name 'changed from @'numbers.name 'to @'number\r
+ end\r
+end /* do */\r
+\r
+exit cmp\r
+\r
+/*\r
+ * Cleans the REXX queue by pulling and forgetting every line.\r
+ * This is needed, at least, when `cmpdef.cmd' starts, because an aborted\r
+ * REXX program might have left some rubbish in.\r
+ */\r
+CleanQueue: procedure\r
+ do while queued() > 0\r
+ parse pull foo\r
+ end\r
+return\r
+\r