1166124Srafan/****************************************************************************
2166124Srafan * Copyright (c) 1998,2006 Free Software Foundation, Inc.                   *
3166124Srafan *                                                                          *
4166124Srafan * Permission is hereby granted, free of charge, to any person obtaining a  *
5166124Srafan * copy of this software and associated documentation files (the            *
6166124Srafan * "Software"), to deal in the Software without restriction, including      *
7166124Srafan * without limitation the rights to use, copy, modify, merge, publish,      *
8166124Srafan * distribute, distribute with modifications, sublicense, and/or sell       *
9166124Srafan * copies of the Software, and to permit persons to whom the Software is    *
10166124Srafan * furnished to do so, subject to the following conditions:                 *
11166124Srafan *                                                                          *
12166124Srafan * The above copyright notice and this permission notice shall be included  *
13166124Srafan * in all copies or substantial portions of the Software.                   *
14166124Srafan *                                                                          *
15166124Srafan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16166124Srafan * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17166124Srafan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18166124Srafan * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19166124Srafan * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20166124Srafan * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21166124Srafan * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22166124Srafan *                                                                          *
23166124Srafan * Except as contained in this notice, the name(s) of the above copyright   *
24166124Srafan * holders shall not be used in advertising or otherwise to promote the     *
25166124Srafan * sale, use or other dealings in this Software without prior written       *
26166124Srafan * authorization.                                                           *
27166124Srafan ****************************************************************************/
28166124Srafan
2950276Speter/*
30166124Srafan * $Id: chkdef.cmd,v 1.3 2006/04/22 23:14:50 tom Exp $
3150276Speter *
3250276Speter * Author:  Juan Jose Garcia Ripoll <worm@arrakis.es>.
3350276Speter * Webpage: http://www.arrakis.es/~worm/
3450276Speter *
3550276Speter * chkdef.cmd - checks that a .def file has no conflicts and is properly
3650276Speter *		formatted.
3750276Speter *
3850276Speter * returns nonzero if two symbols have the same code or a line has a wrong
3950276Speter * format.
4050276Speter *
4150276Speter * returns 0 otherwise
4250276Speter *
4350276Speter * the standard output shows conflicts.
4450276Speter */
4550276Speterparse arg def_file
4650276Speter
4750276Speterdef_file = translate(def_file,'\','/')
4850276Speter
4950276Spetercall CleanQueue
5050276Speter
5150276Speter/*
5250276Speter * `cmp' is zero when the file is valid
5350276Speter * `codes' associates a name to a code
5450276Speter * `names' associates a code to a name
5550276Speter */
5650276Spetercmp    = 0
5750276Spetercodes. = 0
5850276Speternames. = ''
5950276Speter
6050276Speter/*
6150276Speter * This sed expression cleans empty lines, comments and special .DEF
6250276Speter * commands, such as LIBRARY..., EXPORTS..., etc
6350276Speter */
6450276Spetertidy_up  = '"s/[ 	][ 	]*/ /g;s/;.*//g;/^[ ]*$/d;/^[a-zA-Z]/d;"'
6550276Speter
6650276Speter/*
6750276Speter * First we find all public symbols from the original DLL. All this
6850276Speter * information is pushed into a REXX private list with the RXQUEUE
6950276Speter * utility program.
7050276Speter */
7150276Speter'@echo off'
7250276Speter'type' def_file '| sed' tidy_up '| sort | rxqueue'
7350276Speter
7450276Speterdo while queued() > 0
7550276Speter   /*
7650276Speter    * We retrieve the symbol name (NEW_NAME) and its code (NEW_CODE)
7750276Speter    */
7850276Speter   parse pull '"' new_name '"' '@'new_code rest
7950276Speter   select
8050276Speter      when (new_code = '') | (new_name = '') then
8150276Speter         /* The input was not properly formatted */
8250276Speter         do
8350276Speter         say 'Error: symbol "'new_name'" has no export code or is empty'
8450276Speter         cmp = 1
8550276Speter         end
8650276Speter      when codes.new_name \= 0 then
8750276Speter         /* This symbol was already defined */
8850276Speter         if codes.new_name \= new_code then
8950276Speter            do
9050276Speter	    cmp = 2
9150276Speter 	    say 'Symbol "'new_name'" multiply defined'
9250276Speter	    end
9350276Speter      when names.new_code \= '' then
9450276Speter         /* This code was already assigned to a symbol */
9550276Speter         if names.new_code \= new_name then
9650276Speter            do
9750276Speter            cmp = 3
9850276Speter	    say 'Conflict with "'names.new_code'" & "'new_name'" being @'new_code
9950276Speter            end
10050276Speter      otherwise
10150276Speter         do
10250276Speter         codes.new_name = new_code
10350276Speter         names.new_code = new_name
10450276Speter         end
10550276Speter   end  /* select */
10650276Speterend
10750276Speter
10850276Speterexit cmp
10950276Speter
11050276SpeterCleanQueue: procedure
11150276Speter	do while queued() > 0
11250276Speter	   parse pull foo
11350276Speter	end
11450276Speterreturn
115