1/**************************************************************************** 2 * Copyright 2020,2021 Thomas E. Dickey * 3 * Copyright 1998,2006 Free Software Foundation, Inc. * 4 * * 5 * Permission is hereby granted, free of charge, to any person obtaining a * 6 * copy of this software and associated documentation files (the * 7 * "Software"), to deal in the Software without restriction, including * 8 * without limitation the rights to use, copy, modify, merge, publish, * 9 * distribute, distribute with modifications, sublicense, and/or sell * 10 * copies of the Software, and to permit persons to whom the Software is * 11 * furnished to do so, subject to the following conditions: * 12 * * 13 * The above copyright notice and this permission notice shall be included * 14 * in all copies or substantial portions of the Software. * 15 * * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 23 * * 24 * Except as contained in this notice, the name(s) of the above copyright * 25 * holders shall not be used in advertising or otherwise to promote the * 26 * sale, use or other dealings in this Software without prior written * 27 * authorization. * 28 ****************************************************************************/ 29 30/* 31 * $Id: makedef.cmd,v 1.7 2021/09/04 10:52:55 tom Exp $ 32 * 33 * Author: Juan Jose Garcia Ripoll <worm@arrakis.es>. 34 * Webpage: http://www.arrakis.es/~worm/ 35 * 36 * makedef.cmd - update a DLL export list using a newly created library file 37 * in a.out format, plus an old .DEF file. 38 * 39 * standard output gets a sorted list with all entrypoints with entrycodes. 40 * This list, plus a few .def sentences (LIBRARY, DESCRIPTION and EXPORT) 41 * is used to build a new .def file. 42 * 43 * `_nc_*' symbols are ignored. 44 * 45 * returns 1 when the old def_file is corrupted -- that is, export items are 46 * not properly formatted. 47 * 48 * returns 0 if everything went OK. 49 */ 50 51parse arg lib_file def_file 52 53lib_file = translate(lib_file,'\','/') 54def_file = translate(def_file,'\','/') 55 56call CleanQueue 57 58/* 59 * `codes' is the stem that links a code to every symbol 60 * `names' is the stem where symbols are stored sequentially 61 * `last' is the index of the last symbol defined 62 */ 63last = 0 64used. = 0 65codes. = 0 66names. = '' 67 68tmp_name = 'foo.tmp' 69 70/* 71 * This sed expression cleans empty lines, comments and special .DEF 72 * commands, such as LIBRARY..., EXPORTS..., etc 73 */ 74tidy_up = '"/^[A-Z]/d;s/[ ][ ]*/ /g;s/;.*$//g;s/^[ ]*//g;/^[ ]*$/d"' 75 76/* 77 * First we find all public symbols (functions and variables). Next we 78 * concatenate this list with the old one, sorting it and wiping out 79 * all unused data (comments, DLL directives, blanks, etc). All this 80 * information is pushed into a REXX private list with the RXQUEUE 81 * utility program. 82 */ 83'@echo off' 84'emxexp -u' lib_file '>' tmp_name 85'cat' tmp_name def_file '| sed' tidy_up '| sort > foo2.tmp' 86'type foo2.tmp | rxqueue' 87'del' tmp_name '1>NUL' 88 89/* 90 * This loop runs over the queue items 91 */ 92do while queued() > 0 93 /* 94 * We retrieve the symbol name (NEW_NAME) and its number (NEW_NUMBER) 95 * When the line comes from `emximp's output, there's no number, so 96 * we assign it the special value 0. 97 */ 98 parse pull new_symbol '@'new_code rest 99 if Left(new_symbol,1) = '"' then 100 parse var new_symbol '"' new_name '"' rest 101 else 102 do 103 echo 'Symbol 'new_symbol' was not quoted' 104 new_name = new_symbol 105 end 106 107 if new_code = '' then 108 new_code = 0 109 /* 110 * Here, one would place all smart checks that would kill unused symbols. 111 * However, export tables are not that big, so why bothering? 112 if Left(new_name,4) = '_nc_' then 113 iterate 114 */ 115 /* 116 * The algorithm: 117 * IF (this is the 2nd time the symbol appears) THEN 118 * (this symbol comes from a .DEF file) 119 * it has a valid code that we store 120 * we mark that code as used 121 * ELIF (it has no number) THEN 122 * (it is a new symbol) 123 * we increase the counter of defined symbols 124 * we assign it the special number 0 125 * (later on it'll be assigned an unused export code) 126 * ELSE 127 * this symbol was in the old DLL and it is no longer 128 * here, so we skip it. 129 */ 130 select 131 when new_name = '' then 132 'echo Warning: empty symbol found 1>&2' 133 when names.last = new_name then 134 do 135 codes.last = new_code 136 used.new_code = 1 137 end 138 when new_code = 0 then 139 do 140 last = last + 1 141 names.last = new_name 142 codes.last = 0 143 end 144 otherwise 145 'echo Warning: symbol "'new_name'" has disappeared 1>&2' 146 end /* select */ 147end /* do while queued() */ 148 149/* 150 * Finally we scan the stem, writing out all symbols with export codes. 151 * Those that did not have a valid one (just 0) are assigned a new one. 152 */ 153new_code = 1 154inx = 1 155do while inx <= last 156 if codes.inx = 0 then 157 do 158 do while used.new_code \= 0 159 new_code = new_code + 1 160 end 161 codes.inx = new_code 162 used.new_code = 1 163 end 164 say ' "'names.inx'" @'codes.inx' NONAME' 165 inx = inx + 1 166end 167'del foo2.tmp 1>NUL' 168exit 0 169 170/* 171 * Cleans the REXX queue by pulling and forgetting every line. 172 * This is needed, at least, when `makedef.cmd' starts, because an aborted 173 * REXX program might have left some rubbish in. 174 */ 175CleanQueue: procedure 176 do while queued() > 0 177 parse pull foo 178 end 179return 180 181