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