home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / ETOOLS.ZIP / LISTIT.CMD < prev    next >
OS/2 REXX Batch file  |  1992-09-01  |  6KB  |  189 lines

  1. /* rexx */
  2. /* this will create an easel listing file to stdout */
  3. /* trace results*/
  4. ARG filenam.1
  5.  
  6. /*------------------------------------------------------------*/
  7. /*   CHECK IF ARGUMENT WAS ENTERED, IF NOT REQUEST FILE NAME  */
  8. /*------------------------------------------------------------*/
  9. IF LENGTH(filenam.1) = 0 THEN
  10.    DO
  11.    SAY 'ENTER DRIVER FILE NAME: '
  12.    PULL filenam.1
  13.    END
  14.  
  15. pad = "000"
  16. filenumber = 1
  17. lines.1 = 0
  18. fileptr = 1
  19. filedone.1 = "no"
  20. numberofsubs = 0
  21. CRLF = D2C(13) || D2C(10)    /* setup crlf string */
  22.  
  23. /*------------------------------------------------------------*/
  24. /* DO UNTIL EOF                                               */
  25. /*------------------------------------------------------------*/
  26. INREC = LINEIN(filenam.1)
  27. DO while filedone.1 = "no"
  28.    do while filedone.fileptr = "no"         /*lines(filenam.fileptr) > 0*/
  29.       lines.fileptr = lines.fileptr + 1     /* increment line counter
  30.                                                for current file         */
  31.       if fileptr < 10 then                  /* adjust spacing for file  */
  32.          filestring = "0" || fileptr
  33.       else
  34.          filestring = fileptr
  35.  
  36.       linestring = lines.fileptr            /* setup header string      */
  37.       linestring = substr(pad,1,(4 -length(linestring))) || linestring
  38.       CurrentLine = filestring || "." || linestring || " " || INREC
  39.       say CurrentLine    /* put the line w/ number to stdout */
  40.  
  41.       if (CheckforVar('include "')) then
  42.          call ProcessInclude
  43.       if (CheckforVar('subroutine ')) then
  44.          call ProcessSubroutine
  45.       if (CheckforVar('call ')) then
  46.          call ProcessCall
  47.  
  48.       if (insub = 'yes') then       /* in process of subroutine */
  49.          if (CheckforVar(')')) then  /* end of sub dec */
  50.             do
  51.                insub = 'no'
  52.                if (CheckforVar(' is')) then  /* found definition */
  53.                   def.foundsub = def.foundsub substr(CurrentLine,1,8)
  54.                else                          /* found declaration */
  55.                   dec.foundsub = dec.foundsub substr(CurrentLine,1,8)
  56.             end
  57.  
  58.  
  59.       if lines(filenam.fileptr) = 0 then     /* done w/ this file */
  60.          filedone.fileptr = "yes"
  61.       else
  62.          INREC = LINEIN(filenam.fileptr)
  63.  
  64.    end   /* while current file */
  65.    filedone.fileptr = "yes"
  66.    junk = lineout(filenam.fileptr)   /* close the file */
  67.    fileptr = fileptr - 1
  68.    INREC = LINEIN(filenam.fileptr)   /* get the next previous file */
  69. end
  70.  
  71. /*******************************/
  72. /*  now create the xref report */
  73. /*******************************/
  74. say " "
  75. say "***-----------***"
  76. say "*   File Xref   *"
  77. say "***-----------***"
  78. say
  79. do X = 1 to filenumber
  80.    if X<10 then
  81.       say "0" || X || " " || filenam.X
  82.    else
  83.       say X || " " || filenam.X
  84. end
  85. say
  86. say "***-------------***"
  87. say "* Subroutine Xref *"
  88. say "***-------------***"
  89. say
  90. do Y = 1 to numberofsubs
  91.    say 'sub:' sub.Y
  92.    say 'dec:' dec.Y
  93.    say 'def:' def.Y
  94.    say 'cal:' cal.Y
  95.    say
  96. end
  97. exit
  98.  
  99. /* search for the name of the subroutine for xref */
  100. SearchSub:
  101.    foundsub = 0
  102.    if (numberofsubs > 0) then
  103.       do x=1 to numberofsubs
  104.          if sub.x = subname then
  105.             do
  106.                foundsub = x
  107.                leave
  108.             end
  109.       end
  110.    if foundsub = 0 then
  111.       do
  112.          numberofsubs = numberofsubs + 1
  113.          foundsub = numberofsubs
  114.          sub.numberofsubs = subname
  115.          def.numberofsubs = ""
  116.          dec.numberofsubs = ""
  117.          cal.numberofsubs = ""
  118.          calwidth.numberofsubs = 6
  119.       end
  120.    return 0
  121.  
  122. /* get the subroutine name to search and set insub to yes to continue
  123.     processing until ')' found */
  124. ProcessSubroutine:
  125.    subsearch1 = 'subroutine '
  126.    subsearch2 = '('
  127.    parse var INREC (subsearch1) subname (subsearch2) junk
  128.    subname = word(subname,1)
  129.    call SearchSub
  130.    insub = 'yes'
  131.    /* foundsub = index number */
  132.    return 0
  133.  
  134. /* get the subroutine name to search and xref */
  135. ProcessCall:
  136.    callsearch1 = 'call '
  137.    callsearch2 = '('
  138.    parse var INREC (callsearch1) subname (callsearch2) junk
  139.    subname = word(subname,1)
  140.    call SearchSub
  141.    /* foundsub = index number */
  142.    cal.foundsub = cal.foundsub substr(CurrentLine,1,7)
  143.    calwidth.foundsub = calwidth.foundsub + 8
  144.    if (calwidth.foundsub) > 77 then   /* set word wrap */
  145.       do
  146.          cal.foundsub = cal.foundsub || CRLF || "     "
  147.          calwidth.foundsub = 6
  148.       end
  149.    return 0
  150.  
  151. /* setup next file for include */
  152. ProcessInclude:
  153.    incsearch = 'include "'
  154.    parse var INREC (incsearch) incfile
  155.    incfile = word(incfile,1)
  156.    incfile = substr(incfile,1,(length(incfile)-1))
  157.    if (LINES(incfile) > 0) then
  158.       do
  159.          say " "
  160.          say "***---------------------***"
  161.          say "*   " incfile
  162.          say "***---------------------***"
  163.          say " "
  164.          filenumber = filenumber + 1
  165.          filedone.filenumber = "no"
  166.          fileptr = filenumber
  167.          filenam.filenumber = incfile
  168.          lines.fileptr = 0
  169.       end
  170.    return 0
  171.  
  172. /* search for occurance of searchval and return 1 or 0 */
  173. CheckforVar:
  174.  
  175. PARSE ARG searchval
  176.  
  177.    incfile = ""
  178.    PARSE VAR currentline comment '"' rest  /* get rid of quoted strings! */
  179.    comment = comment || '"'
  180.    PARSE VAR comment front '#' rest        /* get rid of comments! */
  181.  
  182.    if (SUBSTR(searchval,1,1) <> "#") then
  183.       PARSE VAR front testsearch (searchval) junk
  184.       if (LENGTH(testsearch) = LENGTH(front)) then
  185.          return 0
  186.       else
  187.          return 1
  188.  
  189.