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