home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / pbsyntax.zip / PBSYNTAX.BAS < prev    next >
BASIC Source File  |  1994-08-18  |  7KB  |  307 lines

  1. $compile exe
  2. $COM 0
  3. $SOUND 10
  4. $STRING 4
  5. $error ALL off
  6. $LIB ALL OFF
  7.  
  8. defint a-z
  9. %FALSE = 0
  10. %TRUE = NOT %FALSE
  11. $IF 0
  12.    Syntax.BAS -- This program runs in the backgorund and is intended to
  13.                  highlight the PB keywords.
  14.  
  15.    PBSyntax <options>
  16.              /r  -  go resident
  17.              /u  -  unload from memory
  18.              /x  - debug info
  19.              /m  - force monochrome
  20. $ENDIF
  21.  
  22.  %black = 0
  23.  %blue  = 1
  24.  %green = 2
  25.  %cyan  = 3
  26.  %red   = 4
  27.  %magenta = 5
  28.  %brown = 6
  29.  %white = 7
  30.  %gray  = 8
  31.  %ltblue = 9
  32.  %ltgreen = 10
  33.  %ltcyan = 11
  34.  %ltred = 12
  35.  %ltmagenta = 13
  36.  %yellow = 14
  37.  %highwhite = 15
  38.  %blink = 16
  39.  
  40. StartUp:
  41.  
  42. TYPE colordefs
  43.   KeywordAttr as byte
  44.   CommentAttr as byte
  45.   CompilerAttr   as byte
  46. END TYPE
  47.  
  48. dim scolors as colordefs
  49.  
  50. TYPE screencell
  51.   stext as byte
  52.   attr  as byte
  53. END TYPE
  54.  
  55.  public scolors
  56.  
  57.  'you can change the colors below to whatever you wish
  58.  scolors.KeyWordAttr = %Black * 16 + %Yellow
  59.  scolors.CommentAttr = %Black * 16 + %Green
  60.  scolors.CompilerAttr = %Black * 16 + %Cyan
  61.  
  62.   x& = SETMEM(-700000)
  63.   x& = SETMEM(5000)
  64.  
  65.   usercommand$ = UCASE$(COMMAND$)   'save command line
  66.  
  67.   IF INSTR(usercommand$, "/R") > 0 THEN
  68.     RunAsTSR% = -1
  69.   END IF
  70.  
  71.   IF INSTR(usercommand$,"/M") THEN ForceMono% = -1
  72.  
  73.   IF INSTR(usercommand$,"/U") THEN 'Uninstall
  74.     REG 1, &HCCCC : REG 2, 1: REG 4, 254    ' pass code 1 in reg 2
  75.     CALL INTERRUPT &H2F   'Tell the resident copy to unload
  76.     IF REG(1)=&HCCCC AND REG(4)=254 AND REG(2)=1 THEN _
  77.         PRINT "PBSyntax Not Loaded ..."      'No tsr is loaded
  78.     END
  79.   END IF
  80.  
  81.   POPUP MULTIPLEX &HCCCC, 254   ' reg AX and DX get this pattern as an ID
  82.   REG 1, &HCCCC : REG 2,0: REG 4, 254  ' set pattern to check for already installed
  83.   CALL INTERRUPT &H2F           ' do the multiplex interrrupt
  84.   IF REG(2) <> 0 THEN
  85.        PRINT "PBSyntax Already Installed ....."
  86.        BEEP
  87.        END 'we were already installed
  88.   END IF
  89.  
  90.  
  91.   DIM PBKeyWords$(1:400), PBWordTypes%(1:400)
  92.   public PBKeyWords$(), PBWordTypes%(), MaxKeyWords%
  93.  
  94.   MaxKeyWords%= LoadKeyWords
  95.   IF MaxKeyWords < 1 THEN
  96.     PRINT "No Key Words Loaded"
  97.     BEEP
  98.     END
  99.   END IF
  100.  
  101.   Checking% = %True               'default to active
  102.   POPUP TIMER 18                  'every second
  103.   POPUP KEY CHR$(&H08,&H01,&H70)  'Alt-Esc
  104.   POPUP MULTIPLEX &HCCCC, 254     'reg AX and DX get this pattern as an ID
  105.   POPUP SLEEP USING EMS
  106.  
  107. WHILE NOT Terminated%
  108.  MainLoop:
  109.  
  110.   popmethod% = POPUP(4)
  111.   IF popmethod% = 16 AND REG(2)=1 THEN   'unload
  112.     PRINT "Unloading .."
  113.     REG 1, &HCCCC : REG 2,3: REG 4, 254  ' Alter AX,bx,DX to show we were here
  114.     EXIT LOOP
  115.   END IF
  116.  
  117.   IF popmethod% = 16 AND REG(1)=&HCCCC AND REG(4)=254 THEN
  118.     REG(1), &HCCCC : REG(4),254 : REG(2),3
  119.     POPUP SLEEP
  120.     GOTO MainLOOP
  121.   END IF
  122.  
  123.   IF popmethod% = 1 THEN
  124.     Checking% = NOT Checking%
  125.     IF Checking% = %False THEN
  126.       POPUP TIMER OFF
  127.       GOTO SkipProcessing
  128.     ELSE
  129.       POPUP TIMER ON
  130.     END IF
  131.   END IF
  132.  
  133.   'make sure we have a good screen mode
  134.  
  135.   IF pbvScrnMode <> 7 AND pbvScrnMode <> 0 THEN
  136.       IF LEN(DIR$("Modeerr.log")) = 0 THEN
  137.         EFile = FREEFILE
  138.         OPEN "O",#EFile,"Modeerr.log"
  139.         WRITE #EFile, STR$(pbvScrnMode)
  140.         CLOSE #EFile
  141.       END IF
  142.       POPUP SLEEP
  143.       GOTO MainLoop
  144.   END IF
  145.  
  146.   CALL HiLightKeyWords
  147.  
  148. SkipProcessing:
  149.   POPUP SLEEP
  150.  
  151. WEND
  152.  
  153. ShutDown:
  154.   Counter% = 1
  155.   IF RunAsTSR% THEN   'give it 5 seconds to uninstall
  156.     POPUP TIMER 9     'popup at .5 second intervals for a max of 10 times
  157.     REG(2), 0
  158.     INCR Counter%
  159.     WHILE Counter% < 10
  160.       POPUP SLEEP
  161.       INCR Counter%
  162.       IF POPUP(1) THEN
  163.         PRINT "PBSyntax Removed from Memory"
  164.         END
  165.       END IF
  166.     WEND
  167.     PRINT "Can NOT Remove PBSyntax ..."
  168.   END IF
  169.   END
  170.  
  171. SUB HiLightKeyWords
  172.  
  173.   'get number of lines on the screen
  174.   NumLines% = 25
  175.  
  176.   DIM ABSOLUTE BIOS(&H300) AS INTEGER AT 0
  177.  
  178.   IF pbvScrnCard > 3 THEN   'ega or better
  179.      NumLines% = (BIOS(&H242) AND 255) + 1
  180.   END IF
  181.  
  182.   ERASE BIOS
  183.  
  184.   MaxCells% = 80 * NumLines%
  185.  
  186.   IF pbvScrnMode = 7 THEN
  187.     DIM Screenarea(1:4000) as screencell at &HB000
  188.   ELSE
  189.     DIM Screenarea(1:MaxCells%) as screencell at &HB800
  190.   END IF
  191.  
  192.   'for quick and dirty reasons, we check the whole pb entry area
  193.   'mainly in case of scroll down or up
  194.  
  195.   currow = 3  'PB starts at line 3, column 2
  196.   curcol = 2
  197.  
  198.   FOR temprow = currow TO NumLines%  'search for last pb window line
  199.     IF screenarea(((temprow-1) * 80) + 1).stext = 192 THEN
  200.       lastrow = temprow-1
  201.       EXIT FOR
  202.     END IF
  203.   NEXT
  204.  
  205.   'see if we have an active edit screen .. this is done by checking for the
  206.   'status line of the bottom, pb turns off the status when doing something else
  207.  
  208.   'determines where the ascii code 180 is this is beginning of the
  209.   'pb area showing row:column
  210.  
  211.   Statuscell% = Lastrow*80 + 3
  212.   IF screenarea(StatusCell%).stext <> 180 THEN EXIT SUB
  213.  
  214.   maxcell = ((lastrow-1) * 80) + 79
  215.   currentcell = ((currow-1) * 80) + curcol
  216.   beginofline = ((currow-1) * 80) + 1
  217.  
  218.   tempword$ = ""
  219.   FoundQuote% = %FALSE
  220.  
  221.   WHILE currentcell < maxcell
  222.     SELECT CASE screenarea(currentcell).stext
  223.       CASE 13,32,40,41,44: GOSUB ChangeAttr     'CR,space,parens,comma
  224.       CASE 39 : TempData$ = CHR$(39)   'single quote
  225.                 INCR currentcell
  226.                 GOSUB RemarkTheLine
  227.       CASE 34:  FoundQuote% = NOT FoundQuote%
  228.       CASE ELSE : TempWord$ = TempWord$ + CHR$(screenarea(currentcell).stext)
  229.     END SELECT
  230.     INCR currentcell
  231.     IF currentcell MOD 80 = 1 THEN
  232.       FoundQuote% = %False
  233.       INCR currentcell
  234.       TempWord$ = ""
  235.     END IF
  236.   WEND
  237.   ERASE screenarea
  238.   EXIT SUB
  239.  
  240. ChangeAttr:
  241.  IF LEN(TempWord$) = 0 THEN RETURN
  242.  IF FoundQuote% THEN RETURN   'no highlights within quote marks
  243.  TempData$ = UCASE$(TempWord$)
  244.  ARRAY SCAN PBKeyWords$() FOR MaxKeyWords%, =TempData$, to found%
  245.  
  246.  IF found% = 0 THEN
  247.    TempWord$ = ""
  248.    RETURN
  249.  END IF
  250.  
  251.  IF PBWordTypes(found%) = 3 THEN  'check for a remark
  252.    GOSUB RemarkTheLine
  253.    TempWord$ = ""
  254.    RETURN
  255.  END IF
  256.  
  257.  newAttr? = scolors.KeyWordAttr   'default to keyword
  258.  
  259.  IF PBWordTypes(found%) = 1 THEN newattr? = scolors.CompilerAttr
  260.  
  261.  TempCell = currentcell - LEN(TempData$)
  262.  WHILE TempCell < currentcell
  263.    screenarea(Tempcell).attr = newattr?
  264.    INCR TempCell
  265.  WEND
  266.  
  267.  TempWord$ = ""
  268.  RETURN
  269.  
  270. RemarkTheLine:
  271.  currentcell = currentcell - LEN(TempData$)
  272.  WHILE currentcell MOD 80 > 0
  273.    screenarea(currentcell).attr = scolors.CommentAttr
  274.    INCR currentcell
  275.  WEND
  276.  TempWord$ = ""
  277.  RETURN
  278.  
  279. END SUB
  280.  
  281. FUNCTION LoadKeyWords
  282.   'see if we can find data file with key words
  283.   IF LEN(DIR$("PBSyntax.DEF")) = 0 THEN
  284.     BEEP
  285.     PRINT "Can not find PBSyntax.DEF"
  286.     LoadKeyWords = -1
  287.     EXIT FUNCTION
  288.   END IF
  289.  
  290.   inFile% = FREEFILE
  291.   OPEN "I",#inFile%, "PBSyntax.DEF"
  292.   WHILE NOT EOF(inFile%) AND MaxWords% < 350
  293.     INCR MaxWords%
  294.     INPUT #inFile%, a$
  295.     IF LEFT$(a$,2) = "**" THEN
  296.       CurWordType% = VAL(MID$(a$,3,1))
  297.     ELSE
  298.       PBKeyWords$(MaxWords%) = UCASE$(a$)
  299.       PBWordTypes(MaxWords%) = CurWordType%
  300.     END IF
  301.   WEND
  302.   CLOSE #inFile%
  303.   LoadKeyWords = MaxWords%
  304.  
  305. END FUNCTION
  306.  
  307.