home *** CD-ROM | disk | FTP | other *** search
/ PC Home 49 / PC_Home_Issue_49.iso / winprogs / childenc / oecdemo / textfile / jumpcode.txt < prev    next >
Encoding:
Text File  |  1996-05-28  |  5.5 KB  |  163 lines

  1. on getLastLinePos theStr,startLine,endLine,charPos,theChar
  2.   global endLinePtr,nextChar,gErrGlobal
  3.   put 0 into gErrGlobal
  4.   if startLine = endLine then exit
  5.   put integer((startLine + endLine)/2) into  testLine  
  6.   if char charPos of line testLine  of theStr = theChar then
  7.     if char charPos of line (testLine + 1 ) of theStr > theChar then
  8.       put testLine into endLinePtr
  9.       put  char charPos of line  testLine+ 1 of theStr into nextChar
  10.       exit
  11.     else if testLine = endLine then
  12.       put testLine into endLinePtr
  13.       exit
  14.     end if
  15.   else  if char charPos of line testLine +1 of theStr = theChar then
  16.     if char charPos of line (testLine + 2 ) of theStr > theChar then
  17.       put testLine+1 into endLinePtr
  18.       put  char charPos of line  testLine+ 2 of theStr into nextChar
  19.       exit
  20.     else if (testLine +1) = endLine then
  21.       put testLine+1 into endLinePtr
  22.       exit
  23.     end if
  24.   end if
  25.   put startLine && testLine && endLine
  26.   if  startLine =testLine then 
  27.     -- theChar not found
  28.     put 1 into gErrGlobal
  29.     exit
  30.   end if
  31.   if  char charPos of line  testLine of theStr > theChar then
  32.     getLastLinePos theStr,startLine,testLine,charPos,theChar
  33.   else  if  char charPos of line  testLine of theStr <= theChar then
  34.     getLastLinePos theStr,testLine,endLine,charPos,theChar
  35.   end if
  36. end
  37.  
  38. on getFirstLinePos theStr,startLine,endLine,charPos,theChar
  39.   global offsetPtr,nextChar,gErrGlobal
  40.   put 0 into gErrGlobal
  41.   put integer((startLine + endLine)/2) into testLine  
  42.   if startLine = endLine then  -- only one line with current string
  43.     if  char charPos of line startLine of theStr <> theChar then
  44.       put 1 into gErrGlobal
  45.     end if
  46.     exit
  47.   end if
  48.   
  49.   if char charPos of line testLine of theStr < theChar then
  50.     if char charPos of line (testLine + 1) of theStr = theChar then
  51.       -- line where sought char first occurs
  52.       put testLine+1 into offsetPtr
  53.       put  char charPos of line  testLine+ 1 of theStr into nextChar
  54.       exit
  55.     else if char charPos of line (testLine + 1) of theStr >theChar then
  56.       -- char not found next line contains another char
  57.       put 1 into gErrGlobal
  58.       exit
  59.     else  if (testLine + 1) = endLine then -- char not found at all
  60.       put 1 into gErrGlobal
  61.       exit
  62.     end if
  63.   end if
  64.   -- put startLine && testLine && endLine
  65.   if startLine = testLine then 
  66.     -- theChar not found
  67.     -- put 1 into gErrGlobal
  68.     exit
  69.   end if
  70.   if  char charPos of line  testLine of theStr >= theChar then
  71.     getFirstLinePos theStr,startLine,testLine,charPos,theChar
  72.   else  if  char charPos of line  testLine of theStr < theChar then
  73.     getFirstLinePos theStr,testLine,endLine,charPos,theChar
  74.   end if
  75. end
  76.  
  77. on keyDown
  78.   global menuText,tempText,displayLines,indexText
  79.   global CR,endLinePtr,offsetPtr,LinePtrs
  80.   put the number of chars of field 442 into fldLen
  81.   if not integerP(fldLen) then put 0 into fldLen
  82.   put 0 into dontAdd
  83.   dontpassEvent
  84.   put the Key into theKey
  85.   if charToNum(theKey) = 13 then 
  86.     exit
  87.   else if charToNum(theKey) = 8 then --delete key
  88.     delete char the number of chars of field 442 of field 442
  89.     put char the number of chars of field 442 of field 442 into theChar
  90.     put fldLen - 1 into fldLen
  91.     put value(item 1 of line fldLen + 1 of LinePtrs) into offsetPtr
  92.     put value(item 2 of line fldLen + 1 of LinePtrs) into endLinePtr
  93.     put  item 3 of line fldLen of LinePtrs into theChar
  94.     delete line fldLen + 1 of LinePtrs
  95.     put 1 into dontAdd
  96.   else if charToNum(theKey) < 32 then 
  97.     exit
  98.   end if
  99.   if fldLen = 0 then
  100.     if dontAdd <> 1 then
  101.       set offsetPtr to 0
  102.       put capitalise(theKey) into theChar
  103.       put theChar after field 442
  104.       put the number of lines of indexText into endLine
  105.       --linePtrs is used to regenerate prev list configs when chars are deleted in text entry field
  106.       put 1 & "," & endLine & "," & theChar  into linePtrs
  107.       getFirstLinePos indexText,1,endLine,1,theChar
  108.       if testError()= 1  then
  109.         exit
  110.       end if
  111.       put endLine into endLinePtr
  112.       getLastLinePos indexText,offsetPtr,endLinePtr,1,theChar
  113.       if testError()= 1  then exit 
  114.     end if
  115.   else
  116.     if dontAdd <> 1 then
  117.       put theKey into theChar
  118.       put theChar  after field 442
  119.       put CR & offsetPtr & "," & endLinePtr & "," & theChar after linePtrs
  120.       -- put offsetPtr&&endLinePtr&&  theChar
  121.       put offsetPtr into oldOffsetPtr
  122.       put endLinePtr into oldEndLinePtr
  123.       getFirstLinePos indexText,offsetPtr,endLinePtr,fldLen + 1,theChar
  124.       if testError()= 1  then 
  125.         delete char the number of chars of field 442 of field 442
  126.         exit
  127.       end if
  128.       -- put offsetPtr&&endLinePtr&&fldLen + 1&&theChar
  129.       getLastLinePos indexText,oldOffsetPtr,oldEndLinePtr,fldLen + 1,theChar
  130.       put offsetPtr&&endLinePtr&&fldLen + 1&&theChar
  131.       
  132.       if testError()= 1  then
  133.         exit
  134.       end if
  135.     end if
  136.   end if
  137.   
  138.   if offsetPtr > 0 then
  139.     put line offsetPtr to (offsetPtr +displayLines - 1)of  menuText into tempText
  140.     put tempText into field 441
  141.     if the locH of sprite 48 < 1000 then
  142.       put the locV of sprite 48 into theLocV
  143.       set the visible of sprite 48 to 0
  144.       put theLocV + the textHeight of field 441*offsetPtr  into theLocV
  145.       set the locV of sprite 48 to theLocV
  146.       if theLocV < the bottom of sprite 39 and theLocV >= the top of sprite 39 then
  147.         set the visible of sprite 48 to 1
  148.       end if
  149.     end if
  150.     exit
  151.   end if
  152. end
  153.  
  154. on testError
  155.   global gErrGlobal
  156.   if gErrGlobal = 1 then 
  157.     put 0 into gErrGlobal
  158.     return 1
  159.   else
  160.     return 0
  161.   end if
  162. end
  163.