home *** CD-ROM | disk | FTP | other *** search
/ Monster Disc 2: The Best of 1992 / MONSTER1.ISO / bbs / rbbs / rbbs-utl.zip / MAKETABS.BAS < prev    next >
BASIC Source File  |  1991-02-28  |  3KB  |  127 lines

  1. DEFINT A-Z
  2. PassedArguments$ = COMMAND$ + " "
  3. X = INSTR(" H h ? ", PassedArguments$)
  4. IF X > 0 THEN
  5.    CLS
  6.    PRINT "MAKETABS version 1.1 Copyright (c) 1991 by Ken Goosens"
  7.    PRINT "an RBBS utility to make an index tab for sorted file list"
  8.    PRINT
  9.    PRINT "Format:      MAKETABS <options>    where options are:"
  10.    PRINT
  11.    PRINT "/IN=<input file>                       Default:  FIDX.DEF"
  12.    PRINT "/OUT=<output file>                     Default:  FIDXT.DEF"
  13.    PRINT "/B  (run batch)                        Default:  (no)"
  14.    PRINT "/INDEXPOS=<column position to index>   Default:  1"
  15.    IF X > 1 THEN END
  16. END IF
  17.  
  18. ' Initialize
  19.  
  20. InFile$ = "FIDX.DEF"
  21. OutFile$ = "FIDXT.DEF"
  22. IndexPos = 1
  23. TRUE = -1
  24. FALSE = 0
  25. RunBatch = FALSE
  26.  
  27. ' Process Command Line
  28.  
  29. PassedArguments$ = UCASE$(PassedArguments$)
  30. X = INSTR(PassedArguments$, "/INDEXPOS=")
  31. IF X > 0 THEN
  32.    IndexPos = VAL(MID$(PassedArguments$, X + 10))
  33. END IF
  34. X = INSTR(PassedArguments$, "/IN=")
  35. IF X > 0 THEN
  36.    Y = INSTR(X, PassedArguments$, " ")
  37.    InFile$ = MID$(PassedArguments$, X + 4, Y - X - 4)
  38. END IF
  39. X = INSTR(PassedArguments$, "/OUT=")
  40. IF X > 0 THEN
  41.    Y = INSTR(X, PassedArguments$, " ")
  42.    OutFile$ = MID$(PassedArguments$, X + 5, Y - X - 5)
  43. END IF
  44. RunBatch = (INSTR(PassedArguments$, "/B ") > 0)
  45.  
  46. PRINT
  47. PRINT "File to Create Tabs for .. "; InFile$
  48. PRINT "TAB file to make ......... "; OutFile$
  49. PRINT "Position to index ........ "; IndexPos
  50. PRINT
  51. IF NOT RunBatch THEN
  52.    INPUT "A to abort, anything else runs"; ANS$
  53.    ANS$ = UCASE$(ANS$)
  54.    IF ANS$ = "A" THEN END
  55. END IF
  56.  
  57. StartRun! = TIMER
  58. DIM StartPos(36)
  59. CharsCounted$ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  60. OPEN InFile$ FOR INPUT AS #1
  61. FOR i = 1 TO 36
  62.    StartPos(i) = 0
  63. NEXT
  64. LinesRead = 0
  65. PRINT "Processing file "; InFile$; " ";
  66. ColPos = POS(0)
  67. WHILE NOT EOF(1)
  68.    LINE INPUT #1, A$
  69.    LinesRead = LinesRead + 1
  70.    LOCATE , ColPos
  71.    PRINT LinesRead;
  72.    IndexChar$ = MID$(A$, IndexPos, 1)
  73.    Position = INSTR(CharsCounted$, IndexChar$)
  74.    IF Position > 0 THEN
  75.       IF StartPos(Position) = 0 THEN
  76.          StartPos(Position) = LinesRead
  77.       END IF
  78.    END IF
  79. WEND
  80. CLOSE 1
  81.  
  82. OPEN OutFile$ FOR RANDOM AS #1 LEN = 72
  83. FIELD #1, 72 AS OutRec$
  84. PrevValue = 0
  85. ' put 1 in for leading 0's
  86. i = 1
  87. WHILE i < 37 AND StartPos (i) = 0
  88.    StartPos (i) = 1
  89.    i = i + 1
  90. WEND
  91. ' find last non-zero value
  92. i = 36
  93. WHILE i > 0 AND StartPos(i) = 0
  94.    i = i - 1
  95. WEND
  96. StartPos(36) = StartPos(i)
  97. ' propagate high values to left over 0's
  98. FOR i = 36 TO 1 STEP -1
  99.    IF StartPos(i) = 0 THEN
  100.       CurrentValue = 1
  101.       IF PrevValue > CurrentValue THEN
  102.          CurrentValue = PrevValue
  103.       END IF
  104.    ELSE
  105.       CurrentValue = StartPos(i)
  106.    END IF
  107.    StartPos(i) = CurrentValue
  108.    PrevValue = CurrentValue
  109. NEXT
  110. FOR i = 1 TO 36
  111.    MID$(OutRec$, 1 + 2 * (i - 1), 2) = MKI$(StartPos(i))
  112. NEXT
  113. PUT 1, 1
  114. CLOSE 1
  115. PRINT
  116. PRINT "Created TAB file "; OutFile$
  117. 'FOR i = 1 TO 36
  118. '   PRINT MID$(CharsCounted$, i, 1); StartPos(i); ". ";
  119. 'NEXT
  120. EndRun! = TIMER
  121. IF EndRun! < StartRun! THEN                                          ' 022891
  122.    EndRun! = EndRun! + 60!*60!*24!                                   ' 022891
  123. END IF                                                               ' 022891
  124. PRINT "Run time: "; (EndRun! - StartRun!)/60 ; " minutes"
  125. END
  126.  
  127.