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