xref: /freebsd/contrib/ncurses/misc/chkdef.cmd (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
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: chkdef.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 * chkdef.cmd - checks that a .def file has no conflicts and is properly
37 *		formatted.
38 *
39 * returns nonzero if two symbols have the same code or a line has a wrong
40 * format.
41 *
42 * returns 0 otherwise
43 *
44 * the standard output shows conflicts.
45 */
46parse arg def_file
47
48def_file = translate(def_file,'\','/')
49
50call CleanQueue
51
52/*
53 * `cmp' is zero when the file is valid
54 * `codes' associates a name to a code
55 * `names' associates a code to a name
56 */
57cmp    = 0
58codes. = 0
59names. = ''
60
61/*
62 * This sed expression cleans empty lines, comments and special .DEF
63 * commands, such as LIBRARY..., EXPORTS..., etc
64 */
65tidy_up  = '"s/[ 	][ 	]*/ /g;s/;.*//g;/^[ ]*$/d;/^[a-zA-Z]/d;"'
66
67/*
68 * First we find all public symbols from the original DLL. All this
69 * information is pushed into a REXX private list with the RXQUEUE
70 * utility program.
71 */
72'@echo off'
73'type' def_file '| sed' tidy_up '| sort | rxqueue'
74
75do while queued() > 0
76   /*
77    * We retrieve the symbol name (NEW_NAME) and its code (NEW_CODE)
78    */
79   parse pull '"' new_name '"' '@'new_code rest
80   select
81      when (new_code = '') | (new_name = '') then
82         /* The input was not properly formatted */
83         do
84         say 'Error: symbol "'new_name'" has no export code or is empty'
85         cmp = 1
86         end
87      when codes.new_name \= 0 then
88         /* This symbol was already defined */
89         if codes.new_name \= new_code then
90            do
91	    cmp = 2
92 	    say 'Symbol "'new_name'" multiply defined'
93	    end
94      when names.new_code \= '' then
95         /* This code was already assigned to a symbol */
96         if names.new_code \= new_name then
97            do
98            cmp = 3
99	    say 'Conflict with "'names.new_code'" & "'new_name'" being @'new_code
100            end
101      otherwise
102         do
103         codes.new_name = new_code
104         names.new_code = new_name
105         end
106   end  /* select */
107end
108
109exit cmp
110
111CleanQueue: procedure
112	do while queued() > 0
113	   parse pull foo
114	end
115return
116