REM File: Program Deadcode for Dndbbs Version v5.0a Release r2.0 Tweak t5.0a

REM Deadcode analyzer v1.3a for dndbbs main

REM $INCLUDE: 'io9.inc'

' declare functions
FUNCTION Form$(Var#)
 Form$=Format$(Var#,"#,##0;;"+Chr$(34)+"zero"+Chr$(34))
END FUNCTION

ON ERROR GOTO Error.Routine

DIM subroutines(1 TO 1024) AS STRING
DIM variable(1 TO 1024) AS INTEGER
DIM subnames(1 TO 16) AS STRING

COLOR 15, 0
PRINT "Deadcode analyzer v1.3a for Dndbbs."
COLOR 14, 0
PRINT "Press any key to start:";
LOCATE ,,1
WHILE INKEY$ = Nul
   Gosub TimeSlice
WEND
PRINT

' locate files
flagtotals = False
Restore ProgramData
DO
   Read MainSub$, v
   If MainSub$="-eof-" Then
      Exit Do
   Endif
   If Dir$(MainSub$)="" Then
      flagtotals = true
      exit do
   Endif
Loop
If flagtotals Then
   count=0
   color 15,0
   Print "The following files were not found:"
   color 14,0
   Restore ProgramData
   DO
      Read MainSub$, v
      If MainSub$="-eof-" Then
         color 7,0
         if count>0 then
            Print
         endif
         End
      Endif
      If Dir$(MainSub$)="" Then
         Mid$(MainSub$,1,1)=Ucase$(Mid$(MainSub$,1,1))
         Print MainSub$;Space$(15-Len(MainSub$));
         count=count+1
         If count=5 Then
            Print
            count=0
         Endif
      Endif
   Loop
Endif

' get analyze type
looptype = False
COLOR 15, 0
PRINT "Enter analyze type: (1)prompt (2)continuous: ";
LOCATE ,,1
DO
   Var$ = Nul
   WHILE Var$ = Nul
      Var$ = INKEY$
   WEND
   IF Var$ = "1" THEN
      Print "1"
      looptype = 1
      EXIT DO
   END IF
   IF Var$ = "2" THEN
      Print "2"
      looptype = 2
      EXIT DO
   END IF
   Gosub TimeSlice
LOOP

' process filenames
flagtotals = False
Restore ProgramData
DO
   ' load sub names
   READ MainSub$, TotalSubs
   IF MainSub$ = "-eof-" THEN
      EXIT DO
   END IF
   subnames(1) = MainSub$
   subcount = subcount + 1
   FOR Var1 = 1 TO TotalSubs - 1
      READ MainSub$, y
      subnames(Var1 + 1) = MainSub$
      subcount = subcount + 1
   NEXT
   ' process subs
   routinecount = False
   FOR Var1 = 1 TO 1024
      subroutines(Var1) = Nul
      variable(Var1) = False
   NEXT
   FOR Var1 = 1 TO TotalSubs
      programname$ = subnames(Var1)
      CLOSE
      OPEN programname$ FOR INPUT AS #1
      WHILE NOT EOF(1)
         LINE INPUT #1, programline$
         programline$ = LTRIM$(programline$)
         programline$ = LCASE$(programline$)
         IF LEFT$(programline$, 4) = "sub " THEN
            If Instr(ProgramLine$, "'") Then
               ProgramLine$ = RTRIM$(LEFT$(ProgramLine$, INSTR(ProgramLine$, "'") - 1))
            Endif
            programline$ = MID$(programline$, 5)
            programline$ = LTRIM$(programline$)
            IF INSTR(programline$, "(") THEN
               programline$ = LEFT$(programline$, INSTR(programline$, "(") - 1)
            END IF
            IF INSTR(programline$, "'") THEN
               programline$ = LEFT$(programline$, INSTR(programline$, "'") - 1)
            END IF
            programline$ = RTRIM$(programline$)
            lineexists = True
            IF routinecount > False THEN
               FOR arraycount = routinecount TO 1024
                  IF RTRIM$(subroutines(arraycount)) = Nul THEN
                     EXIT FOR
                  END IF
                  IF RTRIM$(subroutines(arraycount)) = programline$ THEN
                     lineexists = False
                     EXIT FOR
                  END IF
               NEXT
            END IF
            IF lineexists THEN
               routinecount = routinecount + 1
               subroutines(routinecount) = programline$
            END IF
         END IF
      WEND
   NEXT
   COLOR 15, 0
   VarQ$ = Lcase$(subnames(1))
   VarQ$ = Left$(VarQ$,Instr(VarQ$,".")-1)
   Mid$(VarQ$,1,1) = Ucase$(Mid$(VarQ$,1,1))
   PRINT VarQ$; ": ";
   VarQ$ = Form$(Cdbl(routinecount)) + " unique subroutine"
   IF routinecount>1 Then
      VarQ$=VarQ$+"s"
   END IF
   VarQ$=VarQ$+"."
   PRINT VarQ$
   totalunique = totalunique + routinecount
   FOR Var1 = 1 TO TotalSubs
      programname$ = subnames(Var1)
      CLOSE
      OPEN programname$ FOR INPUT AS #1
      COLOR 14, 0
      PRINT UCASE$(programname$); " ";
      WHILE NOT EOF(1)
         LINE INPUT #1, programline$
         programline$ = LTRIM$(programline$)
         programline$ = LCASE$(programline$)
         If Instr(ProgramLine$, "'") Then
            ProgramLine$ = RTRIM$(LEFT$(ProgramLine$, INSTR(ProgramLine$, "'") - 1))
         Endif
         IF LEFT$(programline$, 5) = "call " THEN
            programline$ = MID$(programline$, 6)
            programline$ = LTRIM$(programline$)
            IF INSTR(programline$, "(") THEN
               programline$ = LEFT$(programline$, INSTR(programline$, "(") - 1)
            END IF
            IF INSTR(programline$, "'") THEN
               programline$ = LEFT$(programline$, INSTR(programline$, "'") - 1)
            END IF
            programline$ = RTRIM$(programline$)
            lineexists = False
            FOR arraycount = 1 TO routinecount
               IF RTRIM$(subroutines(arraycount)) = programline$ THEN
                  lineexists = True
                  EXIT FOR
               END IF
            NEXT
            IF lineexists THEN
               variable(arraycount) = variable(arraycount) + 1
            END IF
         END IF
      WEND
   NEXT
   PRINT
   flag = False
   FOR count = 1 TO routinecount
      IF variable(count) = False THEN
         COLOR 15, 0
         PRINT subroutines(count); " is deadcode."
         flag = True
         flagtotals = True
      END IF
   NEXT
   IF flag = False THEN
      COLOR 15, 0
      PRINT "No deadcode found."
   END IF
   IF INKEY$ = CHR$(27) THEN
      EXIT DO
   END IF
   IF flag = True OR looptype = 1 THEN
      COLOR 14, 0
      PRINT "More(y/n):";
      LOCATE ,,1
      DO
         Var$ = Nul
         WHILE Var$ = Nul
            Var$ = INKEY$
            Gosub TimeSlice
         WEND
         SELECT CASE LCASE$(Var$)
         CASE "n"
            COLOR 7, 0
            PRINT
            END
         CASE "y"
            PRINT
            EXIT DO
         CASE CHR$(13)
            PRINT
            EXIT DO
         CASE CHR$(32)
            PRINT
            EXIT DO
         END SELECT
      LOOP
   END IF
   Gosub TimeSlice
LOOP
IF flagtotals = False THEN
   COLOR 15, 0
   PRINT "No deadcode found in any subprograms."
END IF
COLOR 15, 0
PRINT "Total unique subroutines: ";
PRINT Form$(Cdbl(totalunique)); " in: ";
PRINT Form$(Cdbl(subcount)); " programs."
COLOR 7, 0
END

TimeSlice:
 InregsX.AX=&H1680
 InregsX.BX=&H0000
 Call InterruptX(&H2F,InregsX,OutregsX)
 Return

programdata:
DATA "dndbbs.bas",10
DATA "dndsub1.bas",0
DATA "dndsub2.bas",0
DATA "dndsub3.bas",0
DATA "dndsub4.bas",0
DATA "dndsub5.bas",0
DATA "dndsub6.bas",0
DATA "dndsub7.bas",0
DATA "dndsub8.bas",0
DATA "dndsub9.bas",0

DATA "dndcnfg.bas",5
DATA "dndcnfg1.bas",0
DATA "dndcnfg2.bas",0
DATA "dndcnfg3.bas",0
DATA "dndcnfg4.bas",0

DATA "dndedit.bas",1
DATA "dndeditA.bas",1
DATA "dndeditB.bas",1
DATA "dndeditC.bas",1
DATA "dndeditD.bas",1
DATA "dndeditE.bas",1
DATA "dndeditF.bas",1
DATA "dndeditG.bas",1
DATA "dndeditH.bas",1
DATA "dndeditI.bas",1
DATA "dndeditJ.bas",1
DATA "dndeditK.bas",1
DATA "dndeditL.bas",1

DATA "dndsic.bas",5
DATA "dndsic1.bas",0
DATA "dndsic2.bas",0
DATA "dndsic3.bas",0
DATA "dndsic4.bas",0

DATA "editcmd1.bas",1
DATA "editcmd2.bas",1
DATA "editcmd3.bas",1
DATA "editcmd4.bas",1
DATA "editcmd5.bas",1
DATA "editcmd6.bas",1
DATA "editcmd7.bas",1
DATA "editcmd8.bas",1
DATA "editcmd9.bas",1
DATA "editcmdA.bas",2
DATA "edtcmdA1.bas",0
DATA "editcmdB.bas",1
DATA "editcmdC.bas",1
DATA "editcmdD.bas",1
DATA "editcmdE.bas",1
DATA "editcmdF.bas",1
DATA "editcmdG.bas",1

DATA "edit.bas",1

DATA "dndutil.bas",2
DATA "dndutil2.bas",0

DATA "dndinit.bas",1

DATA "dndinitf.bas",4
DATA "dndinit1.bas",0
DATA "dndinit3.bas",0
DATA "dndinit3.bas",0

DATA "dndinitg.bas",4
DATA "dndinit4.bas",0
DATA "dndinit5.bas",0
DATA "dndinit6.bas",0

DATA "dndcnvt.bas",1

DATA "dndcnvt2.bas",1

DATA "makecnfg.bas",1

DATA "makesys.bas",1

DATA "dndpack.bas",2
DATA "dndpack2.bas",0

DATA "-eof-",-1

Error.Routine:
PRINT "Error"; ERR; "file "; programname$
END
