]> ncurses.scripts.mit.edu Git - ncurses.git/blob - misc/makedef.cmd
ncurses 6.2 - patch 20200829
[ncurses.git] / misc / makedef.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: makedef.cmd,v 1.6 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  * makedef.cmd - update a DLL export list using a newly created library file\r
37  *               in a.out format, plus an old .DEF file.\r
38  *\r
39  * standard output gets a sorted list with all entrypoints with entrycodes.\r
40  * This list, plus a few .def sentences (LIBRARY, DESCRIPTION and EXPORT)\r
41  * is used to build a new .def file.\r
42  *\r
43  * `_nc_*' symbols are ignored.\r
44  *\r
45  * returns 1 when the old def_file is corrupted -- that is, export items are\r
46  * not properly formatted.\r
47  *\r
48  * returns 0 if everything went OK.\r
49  */\r
50 \r
51 parse arg lib_file def_file\r
52 \r
53 lib_file = translate(lib_file,'\','/')\r
54 def_file = translate(def_file,'\','/')\r
55 \r
56 call CleanQueue\r
57 \r
58 /*\r
59  * `codes' is the stem that links a code to every symbol\r
60  * `names' is the stem where symbols are stored sequentially\r
61  * `last' is the index of the last symbol defined\r
62  */\r
63 last   = 0\r
64 used.  = 0\r
65 codes. = 0\r
66 names. = ''\r
67 \r
68 tmp_name = 'foo.tmp'\r
69 \r
70 /*\r
71  * This sed expression cleans empty lines, comments and special .DEF\r
72  * commands, such as LIBRARY..., EXPORTS..., etc\r
73  */\r
74 tidy_up  = '"/^[A-Z]/d;s/[      ][      ]*/ /g;s/;.*$//g;s/^[ ]*//g;/^[ ]*$/d"'\r
75 \r
76 /*\r
77  * First we find all public symbols (functions and variables). Next we\r
78  * concatenate this list with the old one, sorting it and wiping out\r
79  * all unused data (comments, DLL directives, blanks, etc). All this\r
80  * information is pushed into a REXX private list with the RXQUEUE\r
81  * utility program.\r
82  */\r
83 '@echo off'\r
84 'emxexp -u' lib_file '>' tmp_name\r
85 'cat' tmp_name def_file '| sed' tidy_up '| sort > foo2.tmp'\r
86 'type foo2.tmp | rxqueue'\r
87 'del' tmp_name '1>NUL'\r
88 \r
89 /*\r
90  * This loop runs over the queue items\r
91  */\r
92 do while queued() > 0\r
93    /*\r
94     * We retrieve the symbol name (NEW_NAME) and its number (NEW_NUMBER)\r
95     * When the line comes from `emximp's output, there's no number, so\r
96     * we assign it the special value 0.\r
97     */\r
98    parse pull new_symbol '@'new_code rest\r
99    if Left(new_symbol,1) = '"' then\r
100       parse var new_symbol '"' new_name '"' rest\r
101    else\r
102       do\r
103       echo 'Symbol 'new_symbol' was not quoted'\r
104       new_name = new_symbol\r
105       end\r
106 \r
107    if new_code = '' then\r
108       new_code = 0\r
109    /*\r
110     * Here, one would place all smart checks that would kill unused symbols.\r
111     * However, export tables are not that big, so why bothering?\r
112    if Left(new_name,4) = '_nc_' then\r
113       iterate\r
114     */\r
115    /*\r
116     * The algorithm:\r
117     *   IF (this is the 2nd time the symbol appears) THEN\r
118     *           (this symbol comes from a .DEF file)\r
119     *           it has a valid code that we store\r
120     *           we mark that code as used\r
121     *   ELIF (it has no number) THEN\r
122     *           (it's a new symbol)\r
123     *           we increase the counter of defined symbols\r
124     *           we assign it the special number 0\r
125     *           (later on it'll be assigned an unused export code)\r
126     *   ELSE\r
127     *           this symbol was in the old DLL and it's no longer\r
128     *           here, so we skip it.\r
129     */\r
130    select\r
131       when new_name = '' then\r
132          'echo Warning: empty symbol found 1>&2'\r
133       when names.last = new_name then\r
134          do\r
135          codes.last = new_code\r
136          used.new_code = 1\r
137          end\r
138       when new_code = 0 then\r
139          do\r
140          last = last + 1\r
141          names.last = new_name\r
142          codes.last = 0\r
143          end\r
144    otherwise\r
145       'echo Warning: symbol "'new_name'" has disappeared 1>&2'\r
146    end /* select */\r
147 end /* do while queued() */\r
148 \r
149 /*\r
150  * Finally we scan the stem, writing out all symbols with export codes.\r
151  * Those that did not have a valid one (just 0) are assigned a new one.\r
152  */\r
153 new_code = 1\r
154 inx = 1\r
155 do while inx <= last\r
156    if codes.inx = 0 then\r
157       do\r
158       do while used.new_code \= 0\r
159          new_code = new_code + 1\r
160       end\r
161       codes.inx = new_code\r
162       used.new_code = 1\r
163       end\r
164    say '        "'names.inx'"   @'codes.inx'    NONAME'\r
165    inx = inx + 1\r
166 end\r
167 'del foo2.tmp 1>NUL'\r
168 exit 0\r
169 \r
170 /*\r
171  * Cleans the REXX queue by pulling and forgetting every line.\r
172  * This is needed, at least, when `makedef.cmd' starts, because an aborted\r
173  * REXX program might have left some rubbish in.\r
174  */\r
175 CleanQueue: procedure\r
176    do while queued() > 0\r
177       parse pull foo\r
178    end\r
179 return\r
180 \r