1/* 2 * $Id: cmpdef.cmd,v 1.2 1998/08/29 21:44:47 tom Exp $ 3 * 4 * Author: Juan Jose Garcia Ripoll <worm@arrakis.es>. 5 * Webpage: http://www.arrakis.es/~worm/ 6 * 7 * cmpdef.cmd - compares two .def files, checking whether they have 8 * the same entries with the same export codes. 9 * 10 * returns 0 if there are no conflicts between the files -- that is, 11 * the newer one can replace the older one. 12 * 13 * returns 1 when either of the files is not properly formatted and 14 * when there are conflicts: two symbols having the same export code. 15 * 16 * the standard output shows a list with newly added symbols, plus 17 * replaced symbols and conflicts. 18 */ 19parse arg def_file1 def_file2 20 21def_file1 = translate(def_file1,'\','/') 22def_file2 = translate(def_file2,'\','/') 23 24call CleanQueue 25 26/* 27 * `cmp' is zero when the last file is valid and upward compatible 28 * `numbers' is the stem where symbols are stored 29 */ 30cmp = 0 31names. = '' 32numbers. = 0 33 34/* 35 * This sed expression cleans empty lines, comments and special .DEF 36 * commands, such as LIBRARY..., EXPORTS..., etc 37 */ 38tidy_up = '"s/[ ][ ]*/ /g;s/;.*//g;/^[ ]*$/d;/^[a-zA-Z]/d;"' 39 40/* 41 * First we find all public symbols from the original DLL. All this 42 * information is pushed into a REXX private list with the RXQUEUE 43 * utility program. 44 */ 45'@echo off' 46'type' def_file1 '| sed' tidy_up '| sort | rxqueue' 47 48do while queued() > 0 49 /* 50 * We retrieve the symbol name (NAME) and its number (NUMBER) 51 */ 52 parse pull '"' name '"' '@'number rest 53 if number = '' || name = '' then 54 do 55 say 'Corrupted file' def_file1 56 say 'Symbol' name 'has no number' 57 exit 1 58 end 59 else 60 do 61 numbers.name = number 62 names.number = name 63 end 64end 65 66/* 67 * Now we find all public symbols from the new DLL, and compare. 68 */ 69'type' def_file2 '| sed' tidy_up '| sort | rxqueue' 70 71do while queued() > 0 72 parse pull '"' name '"' '@'number rest 73 if name = '' | number = '' then 74 do 75 say 'Corrupted file' def_file2 76 say 'Symbol' name 'has no number' 77 exit 1 78 end 79 if numbers.name = 0 then 80 do 81 cmp = 1 82 if names.number = '' then 83 say 'New symbol' name 'with code @'number 84 else 85 say 'Conflict old =' names.number ', new =' name 'at @'number 86 end 87 else if numbers.name \= number then 88 do 89 cmp = 1 90 say name 'Symbol' name 'changed from @'numbers.name 'to @'number 91 end 92end /* do */ 93 94exit cmp 95 96/* 97 * Cleans the REXX queue by pulling and forgetting every line. 98 * This is needed, at least, when `cmpdef.cmd' starts, because an aborted 99 * REXX program might have left some rubbish in. 100 */ 101CleanQueue: procedure 102 do while queued() > 0 103 parse pull foo 104 end 105return 106 107