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