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