]> ncurses.scripts.mit.edu Git - ncurses.git/blob - misc/chkdef.cmd
ncurses 6.2 - patch 20200919
[ncurses.git] / misc / chkdef.cmd
1 /****************************************************************************\r
2  * Copyright 2020 Thomas E. Dickey                                          *\r
3  * Copyright 1998,2006 Free Software Foundation, Inc.                       *\r
4  *                                                                          *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a  *\r
6  * copy of this software and associated documentation files (the            *\r
7  * "Software"), to deal in the Software without restriction, including      *\r
8  * without limitation the rights to use, copy, modify, merge, publish,      *\r
9  * distribute, distribute with modifications, sublicense, and/or sell       *\r
10  * copies of the Software, and to permit persons to whom the Software is    *\r
11  * furnished to do so, subject to the following conditions:                 *\r
12  *                                                                          *\r
13  * The above copyright notice and this permission notice shall be included  *\r
14  * in all copies or substantial portions of the Software.                   *\r
15  *                                                                          *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *\r
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *\r
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *\r
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *\r
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *\r
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *\r
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *\r
23  *                                                                          *\r
24  * Except as contained in this notice, the name(s) of the above copyright   *\r
25  * holders shall not be used in advertising or otherwise to promote the     *\r
26  * sale, use or other dealings in this Software without prior written       *\r
27  * authorization.                                                           *\r
28  ****************************************************************************/\r
29 \r
30 /*\r
31  * $Id: chkdef.cmd,v 1.4 2020/02/02 23:34:34 tom Exp $\r
32  *\r
33  * Author:  Juan Jose Garcia Ripoll <worm@arrakis.es>.\r
34  * Webpage: http://www.arrakis.es/~worm/\r
35  *\r
36  * chkdef.cmd - checks that a .def file has no conflicts and is properly\r
37  *              formatted.\r
38  *\r
39  * returns nonzero if two symbols have the same code or a line has a wrong\r
40  * format.\r
41  *\r
42  * returns 0 otherwise\r
43  *\r
44  * the standard output shows conflicts.\r
45  */\r
46 parse arg def_file\r
47 \r
48 def_file = translate(def_file,'\','/')\r
49 \r
50 call CleanQueue\r
51 \r
52 /*\r
53  * `cmp' is zero when the file is valid\r
54  * `codes' associates a name to a code\r
55  * `names' associates a code to a name\r
56  */\r
57 cmp    = 0\r
58 codes. = 0\r
59 names. = ''\r
60 \r
61 /*\r
62  * This sed expression cleans empty lines, comments and special .DEF\r
63  * commands, such as LIBRARY..., EXPORTS..., etc\r
64  */\r
65 tidy_up  = '"s/[        ][      ]*/ /g;s/;.*//g;/^[ ]*$/d;/^[a-zA-Z]/d;"'\r
66 \r
67 /*\r
68  * First we find all public symbols from the original DLL. All this\r
69  * information is pushed into a REXX private list with the RXQUEUE\r
70  * utility program.\r
71  */\r
72 '@echo off'\r
73 'type' def_file '| sed' tidy_up '| sort | rxqueue'\r
74 \r
75 do while queued() > 0\r
76    /*\r
77     * We retrieve the symbol name (NEW_NAME) and its code (NEW_CODE)\r
78     */\r
79    parse pull '"' new_name '"' '@'new_code rest\r
80    select\r
81       when (new_code = '') | (new_name = '') then\r
82          /* The input was not properly formatted */\r
83          do\r
84          say 'Error: symbol "'new_name'" has no export code or is empty'\r
85          cmp = 1\r
86          end\r
87       when codes.new_name \= 0 then\r
88          /* This symbol was already defined */\r
89          if codes.new_name \= new_code then\r
90             do\r
91             cmp = 2\r
92             say 'Symbol "'new_name'" multiply defined'\r
93             end\r
94       when names.new_code \= '' then\r
95          /* This code was already assigned to a symbol */\r
96          if names.new_code \= new_name then\r
97             do\r
98             cmp = 3\r
99             say 'Conflict with "'names.new_code'" & "'new_name'" being @'new_code\r
100             end\r
101       otherwise\r
102          do\r
103          codes.new_name = new_code\r
104          names.new_code = new_name\r
105          end\r
106    end  /* select */\r
107 end\r
108 \r
109 exit cmp\r
110 \r
111 CleanQueue: procedure\r
112         do while queued() > 0\r
113            parse pull foo\r
114         end\r
115 return\r