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