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