cmpdef.cmd 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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: cmpdef.cmd,v 1.3 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. * cmpdef.cmd - compares two .def files, checking whether they have
  35. * the same entries with the same export codes.
  36. *
  37. * returns 0 if there are no conflicts between the files -- that is,
  38. * the newer one can replace the older one.
  39. *
  40. * returns 1 when either of the files is not properly formatted and
  41. * when there are conflicts: two symbols having the same export code.
  42. *
  43. * the standard output shows a list with newly added symbols, plus
  44. * replaced symbols and conflicts.
  45. */
  46. parse arg def_file1 def_file2
  47. def_file1 = translate(def_file1,'\','/')
  48. def_file2 = translate(def_file2,'\','/')
  49. call CleanQueue
  50. /*
  51. * `cmp' is zero when the last file is valid and upward compatible
  52. * `numbers' is the stem where symbols are stored
  53. */
  54. cmp = 0
  55. names. = ''
  56. numbers. = 0
  57. /*
  58. * This sed expression cleans empty lines, comments and special .DEF
  59. * commands, such as LIBRARY..., EXPORTS..., etc
  60. */
  61. tidy_up = '"s/[ ][ ]*/ /g;s/;.*//g;/^[ ]*$/d;/^[a-zA-Z]/d;"'
  62. /*
  63. * First we find all public symbols from the original DLL. All this
  64. * information is pushed into a REXX private list with the RXQUEUE
  65. * utility program.
  66. */
  67. '@echo off'
  68. 'type' def_file1 '| sed' tidy_up '| sort | rxqueue'
  69. do while queued() > 0
  70. /*
  71. * We retrieve the symbol name (NAME) and its number (NUMBER)
  72. */
  73. parse pull '"' name '"' '@'number rest
  74. if number = '' || name = '' then
  75. do
  76. say 'Corrupted file' def_file1
  77. say 'Symbol' name 'has no number'
  78. exit 1
  79. end
  80. else
  81. do
  82. numbers.name = number
  83. names.number = name
  84. end
  85. end
  86. /*
  87. * Now we find all public symbols from the new DLL, and compare.
  88. */
  89. 'type' def_file2 '| sed' tidy_up '| sort | rxqueue'
  90. do while queued() > 0
  91. parse pull '"' name '"' '@'number rest
  92. if name = '' | number = '' then
  93. do
  94. say 'Corrupted file' def_file2
  95. say 'Symbol' name 'has no number'
  96. exit 1
  97. end
  98. if numbers.name = 0 then
  99. do
  100. cmp = 1
  101. if names.number = '' then
  102. say 'New symbol' name 'with code @'number
  103. else
  104. say 'Conflict old =' names.number ', new =' name 'at @'number
  105. end
  106. else if numbers.name \= number then
  107. do
  108. cmp = 1
  109. say name 'Symbol' name 'changed from @'numbers.name 'to @'number
  110. end
  111. end /* do */
  112. exit cmp
  113. /*
  114. * Cleans the REXX queue by pulling and forgetting every line.
  115. * This is needed, at least, when `cmpdef.cmd' starts, because an aborted
  116. * REXX program might have left some rubbish in.
  117. */
  118. CleanQueue: procedure
  119. do while queued() > 0
  120. parse pull foo
  121. end
  122. return