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