makedef.cmd 6.3 KB

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