Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /****************************************************************************
|
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2020 Thomas E. Dickey *
|
| 3 | * Copyright 1998,2006 Free Software Foundation, Inc. *
|
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 4 | * *
|
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a *
|
| 6 | * copy of this software and associated documentation files (the *
|
| 7 | * "Software"), to deal in the Software without restriction, including *
|
| 8 | * without limitation the rights to use, copy, modify, merge, publish, *
|
| 9 | * distribute, distribute with modifications, sublicense, and/or sell *
|
| 10 | * copies of the Software, and to permit persons to whom the Software is *
|
| 11 | * furnished to do so, subject to the following conditions: *
|
| 12 | * *
|
| 13 | * The above copyright notice and this permission notice shall be included *
|
| 14 | * in all copies or substantial portions of the Software. *
|
| 15 | * *
|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
| 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
| 19 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
| 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
| 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
| 22 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
| 23 | * *
|
| 24 | * Except as contained in this notice, the name(s) of the above copyright *
|
| 25 | * holders shall not be used in advertising or otherwise to promote the *
|
| 26 | * sale, use or other dealings in this Software without prior written *
|
| 27 | * authorization. *
|
| 28 | ****************************************************************************/
|
| 29 |
|
| 30 | /*
|
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 31 | * $Id: cmpdef.cmd,v 1.4 2020/02/02 23:34:34 tom Exp $
|
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 32 | *
|
| 33 | * Author: Juan Jose Garcia Ripoll <worm@arrakis.es>.
|
| 34 | * Webpage: http://www.arrakis.es/~worm/
|
| 35 | *
|
| 36 | * cmpdef.cmd - compares two .def files, checking whether they have
|
| 37 | * the same entries with the same export codes.
|
| 38 | *
|
| 39 | * returns 0 if there are no conflicts between the files -- that is,
|
| 40 | * the newer one can replace the older one.
|
| 41 | *
|
| 42 | * returns 1 when either of the files is not properly formatted and
|
| 43 | * when there are conflicts: two symbols having the same export code.
|
| 44 | *
|
| 45 | * the standard output shows a list with newly added symbols, plus
|
| 46 | * replaced symbols and conflicts.
|
| 47 | */
|
| 48 | parse arg def_file1 def_file2
|
| 49 |
|
| 50 | def_file1 = translate(def_file1,'\','/')
|
| 51 | def_file2 = translate(def_file2,'\','/')
|
| 52 |
|
| 53 | call CleanQueue
|
| 54 |
|
| 55 | /*
|
| 56 | * `cmp' is zero when the last file is valid and upward compatible
|
| 57 | * `numbers' is the stem where symbols are stored
|
| 58 | */
|
| 59 | cmp = 0
|
| 60 | names. = ''
|
| 61 | numbers. = 0
|
| 62 |
|
| 63 | /*
|
| 64 | * This sed expression cleans empty lines, comments and special .DEF
|
| 65 | * commands, such as LIBRARY..., EXPORTS..., etc
|
| 66 | */
|
| 67 | tidy_up = '"s/[ ][ ]*/ /g;s/;.*//g;/^[ ]*$/d;/^[a-zA-Z]/d;"'
|
| 68 |
|
| 69 | /*
|
| 70 | * First we find all public symbols from the original DLL. All this
|
| 71 | * information is pushed into a REXX private list with the RXQUEUE
|
| 72 | * utility program.
|
| 73 | */
|
| 74 | '@echo off'
|
| 75 | 'type' def_file1 '| sed' tidy_up '| sort | rxqueue'
|
| 76 |
|
| 77 | do while queued() > 0
|
| 78 | /*
|
| 79 | * We retrieve the symbol name (NAME) and its number (NUMBER)
|
| 80 | */
|
| 81 | parse pull '"' name '"' '@'number rest
|
| 82 | if number = '' || name = '' then
|
| 83 | do
|
| 84 | say 'Corrupted file' def_file1
|
| 85 | say 'Symbol' name 'has no number'
|
| 86 | exit 1
|
| 87 | end
|
| 88 | else
|
| 89 | do
|
| 90 | numbers.name = number
|
| 91 | names.number = name
|
| 92 | end
|
| 93 | end
|
| 94 |
|
| 95 | /*
|
| 96 | * Now we find all public symbols from the new DLL, and compare.
|
| 97 | */
|
| 98 | 'type' def_file2 '| sed' tidy_up '| sort | rxqueue'
|
| 99 |
|
| 100 | do while queued() > 0
|
| 101 | parse pull '"' name '"' '@'number rest
|
| 102 | if name = '' | number = '' then
|
| 103 | do
|
| 104 | say 'Corrupted file' def_file2
|
| 105 | say 'Symbol' name 'has no number'
|
| 106 | exit 1
|
| 107 | end
|
| 108 | if numbers.name = 0 then
|
| 109 | do
|
| 110 | cmp = 1
|
| 111 | if names.number = '' then
|
| 112 | say 'New symbol' name 'with code @'number
|
| 113 | else
|
| 114 | say 'Conflict old =' names.number ', new =' name 'at @'number
|
| 115 | end
|
| 116 | else if numbers.name \= number then
|
| 117 | do
|
| 118 | cmp = 1
|
| 119 | say name 'Symbol' name 'changed from @'numbers.name 'to @'number
|
| 120 | end
|
| 121 | end /* do */
|
| 122 |
|
| 123 | exit cmp
|
| 124 |
|
| 125 | /*
|
| 126 | * Cleans the REXX queue by pulling and forgetting every line.
|
| 127 | * This is needed, at least, when `cmpdef.cmd' starts, because an aborted
|
| 128 | * REXX program might have left some rubbish in.
|
| 129 | */
|
| 130 | CleanQueue: procedure
|
| 131 | do while queued() > 0
|
| 132 | parse pull foo
|
| 133 | end
|
| 134 | return
|
| 135 |
|