Changeset 293 for GPL/trunk/tools


Ignore:
Timestamp:
Feb 17, 2008, 8:39:48 PM (17 years ago)
Author:
Brendan Oakley
Message:

Wat2map fixes from tickets #80 and #58

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk/tools/wat2map.cmd

    r32 r293  
    1 /* $Id: wat2map.cmd,v 1.1.1.1 2003/07/02 13:57:04 eleph Exp $ */
     1/*
     2 * Includes fixes from Helper script MapSym.cmd by Knut (aka bird).
     3 *
     4 * Copyright (c) 2002 knut st. osmundsen (bird@anduin.net)
     5 *
     6 * Project Odin Software License can be found in LICENSE.TXT
     7 *
     8 */
    29
    310/* SCCSID = %W% %E% */
     
    4754/* <End of helpText> - don't modify this string - used to flag end of help. */
    4855/****************************************************************************/
    49 CALL RXFUNCADD 'sysloadfuncs','rexxutil','sysloadfuncs'
    50 call sysloadfuncs
    51 
    52 Parse Arg arg1 arg2 rest
     56
     57Parse arg arg1 arg2
     58
    5359If (Length( arg1 ) = 0) | (Verify( arg1, '/-?' ) = 0) Then Do;
    5460   Do i = 1 to 1000
     
    5763      Say helpText
    5864   End;
    59    Return
     65   Return 1
    6066End;
    61 If Length( arg2 ) = 0 Then Do;
     67
     68If Length( arg2 ) == 0 Then Do;
    6269   Say " Way to go Beaver... How about an out-put file name ?"
    63    Return
     70   Return 2
    6471End;
    6572mapFile = arg1          /* Can be Null, in which case we pull from stdin. */
    6673outFile = arg2
     74fFlatMode = 0;
    6775
    6876/* erase outfile */  /* kill the old map file */
     
    7381Do While Lines( mapFile ) <> 0
    7482   watcomText = LineIn( mapFile )
    75    Parse Value watcomText With "Executable Image: " fileName "." fileExt
    76 
    77    If fileName <> "" Then Do;   /* Found match */
    78       call lineout outfile ,' '
    79       call lineout outfile ,' ' || fileName
    80       call lineout outfile ,' '
    81       Leave;                    /* Break from loop. */
     83   /*Parse Value watcomText With "Executable Image: " fileName "." fileExt*/
     84   Parse Value watcomText With "Executable Image: " sFilename
     85   If (sFilename <> '') Then Do;
     86      sFilename = filespec('name', sFilename);
     87      Parse Var sFilename fileName "." fileExt
     88      If fileName <> "" Then Do;   /* Found match */
     89         call lineout outfile ,' '
     90         call lineout outfile ,' ' || fileName
     91         call lineout outfile ,' '
     92         Leave;                    /* Break from loop. */
     93      End;
    8294   End;
    8395End
    8496If Lines( mapFile ) = 0 Then Do;        /* If end of file ... */
    8597   Say "Error:  Expected to find line with text 'Executable Image:' "
    86    Return
     98   Return 3
    8799End
    88100
     
    97109If Lines( mapFile ) = 0 Then Do;        /* If end of file ... */
    98110   Say "Error:  Expected to find line with text 'Segments ... Size' "
    99    Return
    100 End
    101 junk = LineIn( mapFile )       /* Discard a couple lines of formatting. */
    102 junk = LineIn( mapFile )
    103 
     111   Return 4
     112End
     113
     114
     115junk = LineIn( mapFile )      /* Discard a couple lines of formatting. */
     116junk = LineIn( mapFile )      /* Discard a couple lines of formatting. */
    104117/*--- 4.  Translate segment table.  ---*/
    105 call lineout outfile , " Start     Length     Name                   Class"
    106 Do While Lines( mapFile ) <> 0
    107    watcomText = LineIn( mapFile )
    108    Parse Value watcomText With segName className groupName address size .
     118/*"Segment                Class          Group          Address         Size"*/
     119iClass = pos('Class', watcomText);
     120iGroup = pos('Group', watcomText);
     121iAddress = pos('Address', watcomText);
     122iSize = pos('Size', watcomText);
     123
     124call lineout outfile , " Start         Length     Name                   Class"  /* bird bird bird fixed!!! */
     125Do While Lines( mapFile ) <> 0
     126   watcomText = LineIn( mapFile )
     127   /* do it the hard way to make sure we support spaces segment names. */
     128   segName = strip(substr(watcomText, 1, iClass-1));
    109129   If segName = "" Then Leave;          /* Empty line, break from loop. */
    110    length = Substr( size, 4, 5 ) || 'H     '
     130   className = strip(substr(watcomText, iClass, iGroup-iClass));
     131   groupName = strip(substr(watcomText, iGroup, iAddress-iGroup));
     132   address = strip(substr(watcomText, iAddress, iSize-iAddress));
     133   size = strip(substr(watcomText, iSize));
     134   if (pos(':', address) <= 0) then     /* NT binaries doesn't have a segment number. */
     135   do
     136      fFlatMode = 1;
     137      address = '0001:'||address;
     138   end
     139   length = right(strip(strip(size), 'L', '0'), 9, '0') || 'H     '
    111140   segName = Left( segName, 23 )
    112141   call lineout outfile ,' ' || address || ' ' || length || segName || className
     
    124153Do While Lines( mapFile ) <> 0
    125154   watcomText = LineIn( mapFile )
    126    Parse Value watcomText With seg ':' ofs 10 . 16 declaration
     155   Parse Value watcomText With seg ':' ofs 14 . 16 declaration
     156   if (fFlatMode) then
     157   do
     158      seg = '0001';
     159      Parse Value watcomText With ofs 9 . 16 declaration
     160   end
     161   else
     162   do  /* kso: more workarounds */
     163       if (is_Hex(seg) & length(ofs) > 4 & \is_Hex(substr(ofs,5,1))) then
     164           ofs = '0000'||left(ofs,4);
     165   end
     166   /*say ofs  '-'declaration*/
    127167   is_Adress = (is_Hex(seg) = 1) & (is_Hex(ofs) = 1)
    128    If (is_Adress = 1) Then Do;
    129 
     168   If ((is_Adress = 1) & (seg <> '0000')) Then Do;          /* bird: skip symbols with segment 0. (__DOSseg__) */
    130169      /*--- Haven't done the work to xlate operator symbols - skip the line. */
    131170      If Pos( '::operator', declaration ) <> 0 Then Iterate;
     
    158197      call lineout outfile ,' ' || seg || ':' || ofs || '       ' || declaration
    159198   End;
     199
     200   /* check for entry point, if found we add it and quit. */
     201   if (pos('Entry point address', watcomText) > 0) then
     202   do
     203       parse var watcomText 'Entry point address:' sEntryPoint
     204       if (pos(':', sEntryPoint) <= 0) then
     205           sEntryPoint = '0001:'||strip(sEntryPoint);
     206       call lineout outfile, ''
     207       call lineout outfile, 'Program entry point at' strip(sEntryPoint)
     208       leave;
     209   end
    160210End; /* End While through symbol section, end of input file. */
    161211
    162 Return;  /* End of program.  */
     212call stream outfile, 'c', 'close';
     213call stream mapfile, 'c', 'close';
     214
     215Return 0;  /* End of program.  */
    163216
    164217/*--- Helper subroutines. ---*/
     
    184237      Return StripMatchedParen( string )
    185238   End;
    186 End;
     239return;
    187240
    188241ReplaceSubstr:
     
    198251   End;
    199252   Return string
    200 End;
     253return;
    201254
    202255is_Hex:
     
    204257   Parse Arg string
    205258   Return (Length(string) > 0) &  (Verify( string, '0123456789abcdefABCDEF' ) = 0)
    206 End;
     259return;
Note: See TracChangeset for help on using the changeset viewer.