home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 2 / CDPD_II_2352.bin / scope / 051-075 / scopedisk62 / quicklib / quicklib.bas < prev    next >
BASIC Source File  |  1992-10-27  |  5KB  |  227 lines

  1. '* * * * * * * * * * * * * * 
  2. '*                         *
  3. '*    QUICK_LIB            *
  4. '*                         *
  5. '*                         *
  6. '*  Source code            *
  7. '*      by                 *
  8. '*  Robert D'Asto          *
  9. '*                         *
  10. '* * * * * * * * * * * * * *
  11.  
  12. '************************************
  13. '*
  14. '* copyright 1988 PiM Publications
  15. '*
  16. '* this program appeared in the March '89
  17. '* issue of Amazing Computing [PO Box 869,
  18. '* Fall River, MA 02722,  508-678-4200]
  19. '*   reproduced and distributed with
  20. '*      permission
  21. '*
  22. '*  Typed in and somewhat tweaked up by
  23. '*      Bernie Cosell (cosell@bbn.com)
  24. '*  The version in AC worked fine, so if this
  25. '*  one doesn't, I screwed up either in my typing
  26. '*  or in my "improvements"
  27. '*
  28. '***************************************
  29.  
  30.  
  31. ON BREAK GOSUB endit
  32. BREAK ON
  33.  
  34. MENU 1,0,1," Quick Lib "
  35. MENU 1,1,1," Load bmap "
  36. MENU 1,2,1," Quit      "
  37.  
  38. MENU 2,0,0,"           "
  39. MENU 3,0,0,"           "
  40. MENU 4,0,0,"           "
  41.  
  42. ON MENU GOSUB MenuSort
  43. MENU ON
  44.  
  45. WHILE -1
  46.   SLEEP
  47. WEND
  48.  
  49. MenuSort:
  50.   IF MENU(1) = 1 THEN GOSUB Loadbmap
  51.   IF MENU(1) = 2 THEN GOSUB endit
  52. RETURN
  53.  
  54. Loadbmap:
  55.   bmap.name$ = ""
  56.   lib.name$ = ""
  57.   subname$ = ""
  58.   Q$ = CHR$(34)
  59.   CLS
  60. startload:
  61.   PRINT
  62.   INPUT "Name of library to load "; b$
  63.   IF RIGHT$(b$, 5) <> ".bmap" THEN
  64.     IF RIGHT$(b$, 8) = ".library" THEN
  65.       b$ = LEFT$(b$, LEN(b$) - 8) + ".bmap"
  66.     ELSE
  67.       PRINT
  68.       PRINT "Spelling is incorrect or file"
  69.       PRINT "is misnamed.  A bmap file name"
  70.       PRINT "must end with " + Q$ + ".bmap" + Q$ + "."
  71.       GOTO startload
  72.     END IF
  73.   END IF
  74.   
  75.   ON ERROR GOTO CatchError
  76.   GotError = 0
  77.  
  78.   OPEN b$ FOR INPUT AS 1
  79.   IF GotError THEN
  80.     GotError = 0
  81.     OPEN ":" + b$ FOR INPUT AS 1
  82.     IF GotError THEN
  83.       GotError = 0
  84.       OPEN "libs:" + b$ FOR INPUT AS 1
  85.       IF GotError THEN
  86.         ON ERROR GOTO 0
  87.         PRINT
  88.         PRINT "Can't find bmap for library " + Q$ + b$ + Q$
  89.         GOTO startload
  90.       END IF
  91.     END IF
  92.   END IF
  93.   ON ERROR GOTO 0
  94.         
  95.   bmap$ = INPUT$ (LOF(1), 1)
  96.   CLOSE 1
  97.   
  98. 'extract name of library from
  99. 'full pathname entered above
  100.   startpoint% = LEN(b$) - 5
  101.   namelen% = 1
  102.   control% = 100
  103.  
  104.   WHILE startpoint% > 0 AND 96 < control%  AND control% < 123  
  105.     control% = ASC(MID$(b$, startpoint%, 1))
  106.     startpoint% = startpoint% - 1
  107.     namelen% = namelen% + 1
  108.   WEND
  109.  
  110.   IF control% <= 96 OR 123 <= control% THEN
  111.     n$ = MID$(b$, startpoint%+2, namelen%-2)
  112.   ELSE
  113.     n$ = MID$(b$, startpoint%+1, namelen%-1)
  114.   END IF  
  115.   
  116. 'use name extracted above to
  117. 'create appropriate names for
  118. 'library, bmap and subprogram
  119.   bmap.name$ = n$ + ".bmap"
  120.   lib.name$ = n$ + ".library"
  121.   subname$ = "Init." + n$ + ".lib"
  122.   
  123. 'call the GetRoutine sub, passing the
  124. 'complete bmap and above names to it
  125.   GetRoutine bmap$, lib.name$, bmap.name$, subname$
  126.   NewCycle
  127. RETURN
  128.  
  129. endit:
  130.   MENU RESET
  131.   END
  132. RETURN
  133.  
  134.  
  135. ' Little bit of machinery to allow errors to be caught easily
  136. CatchError:
  137.   GotError = -1
  138. RESUME NEXT
  139.   
  140.   
  141. SUB GetRoutine (bmap$, lib$, bn$, s$) STATIC
  142.   CLS
  143. Start:
  144.   routine$ = ""
  145.   fd$ = ""
  146.   Q$ = CHR$(34)
  147.  
  148.   PRINT
  149.   PRINT "Name of first " + lib$ + " routine"
  150.   INPUT "you wish to use "; routine$
  151.   IF routine$ = "" THEN Start
  152.   
  153. Again:
  154.   
  155. 'find routine within the bmap
  156.   offset% = INSTR(bmap$, routine$ + CHR$(0))
  157.   
  158.   IF offset% = 0 THEN
  159.     PRINT "I can't find " + Q$ + routine$ + Q$ + " in this library."
  160.     PRINT "Check spelling."
  161.     PRINT
  162.     GOTO ReType
  163.   END IF
  164.   
  165.   fd$ = fd$ + "  fd$ = fd$ + " + Q$ + routine$ + Q$
  166.   fd$ = fd$ + " + chr$(0)" + CHR$(10) + "  "
  167.   length% = LEN(routine$)+1
  168.   count% = offset% + length%
  169.   fd$ = fd$ + "fd$=fd$+"
  170.   
  171. 'extract offset and parameter data
  172. 'for this routine from the bmap
  173.   char$ = ""
  174.   WHILE char$ <> CHR$(0)
  175.     char$ = MID$(bmap$, count%, 1)
  176.     fd$ = fd$ + "CHR$(" + MID$(STR$(ASC(char$)),2) + ")" + "+"
  177.     count% = count% + 1
  178.   WEND
  179.   
  180.   newlength% = LEN(fd$) - 1
  181.   fd$ = LEFT$(fd$, newlength%)
  182.   fd$ = fd$ + CHR$(10)
  183.   
  184.   PRINT
  185.   PRINT "Thank you.  ";
  186. ReType:
  187.   PRINT "Next routine "
  188.   INPUT "(if none press RETURN) ", routine$
  189.   IF routine$ = "" THEN
  190.     GOTO GoOn
  191.   ELSEIF routine$ = CHR$(127) THEN
  192.     GOTO Start
  193.   ELSE
  194.     GOTO Again
  195.   END IF
  196.   
  197. GoOn:
  198.   final.length% = LEN(fd$) - 1
  199.   fd$ = LEFT$(fd$, final.length%)
  200.   PRINT
  201.   INPUT "name of destination file "; destfile$
  202.   IF destfile$ = "" THEN GoOn
  203.   F$ = " for output as 1"
  204.   OPEN destfile$ FOR OUTPUT AS 1
  205.   PRINT #1, ""
  206.   PRINT #1, "SUB " + s$ + " STATIC"
  207.   PRINT #1, fd$
  208.   PRINT #1, "  OPEN " + Q$ + "RAM:" + bn$ + Q$ + F$
  209.   PRINT #1, "  PRINT #1, fd$;"
  210.   PRINT #1, "  CLOSE 1"
  211.   PRINT #1, "  LIBRARY " + Q$ + "RAM:" + lib$ + Q$
  212.   PRINT #1, "END SUB"
  213.   CLOSE 1
  214.   EXIT SUB
  215. END SUB
  216.  
  217. SUB NewCycle STATIC
  218.   CLS
  219.   Q$ = CHR$(34)
  220.   PRINT "If you wish to use routines"
  221.   PRINT "from another library select"
  222.   PRINT Q$ + "Load bmap" + Q$ + "from menu."
  223.   EXIT SUB
  224. END SUB
  225.  
  226.  
  227.