home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d07xx / d0770.lha / Uedit / Jenkins2.LZH / IdentifierSearch < prev    next >
Text File  |  1991-04-08  |  9KB  |  245 lines

  1. ===== IdentifierSearch ======================================
  2.  
  3. (c) 1990 Robert A. Jenkins, Ph.D.
  4. 22901 Shagbark Lane
  5. Miller Woods, IL 60411
  6. (708) 758-7063
  7. ALL RIGHTS RESERVED
  8. Rick Stiles can distribute as he pleases
  9.  
  10. =============================================================================
  11. These three commands are for Modula-2 programming.
  12.  
  13. The standard configuration search is insensitive to the surrounding.  That can
  14. make a search for an indentifier quite a pain, if it happens to occur inside
  15. other identifiers, as in searching for "tempLoc" when you have also used
  16. "tempLocPtr".  Worse yet, try searching for an index identifier like "i" with
  17. the standard search.  Also, it is confusing to have to type in the search
  18. string.  If you do not find a match, it might be because you mistyped the
  19. string.
  20.  
  21. There are two simple id search commands: shftCtl-f and shftCtl-b.  Put the
  22. cursor on an identifier and shftCtl-f will copy the identifier to the usual
  23. search buffer (buf49) in case you want to do ordinary searching with F9 and
  24. shft-F9.  Then it searches forward for an identical identifier.  The search is
  25. case sensitive, but it restores the searchCaps flag to whatever value it had.
  26. ShftCtl-b searches backward.
  27.  
  28. If it finds a match it inverts it just like the standard search command does,
  29. but if it doesn't find a match somewhere else, the one under the cursor
  30. remains inverted.  So if you hit shftCtl-f or shftCtl-b again it will pick up
  31. the word or phrase again.  So the two commands work just like f9 and shft-f9,
  32. except that they search for identifiers, not just any string that matches, and
  33. they don't cancel the invert when no match is found.
  34.  
  35. The commands also enable you to search for complex phrases without fear of
  36. typing errors.  Invert the phrase for which you want to search and place the
  37. cursor in the invert region.  Then hit shftCtl-f or shftCtl-b and it will pick
  38. up the invert and search for it.  Quite handy for looking for
  39.                transactionPtr^.numberOfShares Traded :=
  40. and the like when you are trying to find out whether and where a variable got
  41. initiated.  Including the := makes sure that you find only those places where
  42. a value is assigned, not where the value was used.
  43.  
  44. There is another command which greatly assists with cleaning up your import
  45. lists.  Put the cursor on an identifier, or in an invert of a phrase, and hit
  46. shftCtl-i.  It will pick up the identifier (or phrase) and search forward,
  47. then drop you into a loop where hitting f or b will search forward or
  48. backward.  Hitting s or e will move to the start of the file and search
  49. forward or the the end of the file and search backward.  Exit the loop with q.
  50. When it fails to find another occurrence it returns you to the next identifier
  51. in the list and drops out of the loop.  So if the identifier is never used you
  52. just jump to the next identifier.  If it is used, you can walk around forward
  53. and backward looking at where it is used.  The s and e options give you some
  54. control over the walking.  If you tire of walking around, just hit q and you
  55. will pop back to the next identifier in the list.  If you want to stay where
  56. you are, hit some other key (like mouse down) and you will drop out of the
  57. loop with the cursor positioned on the last occurrence you found.
  58.  
  59. This command is handy for searching around for other uses of the identifier,
  60. after which you can always return to where you were when you started browsing.
  61. There are two awkwardnesses.  If you happen to start with the last occurrence
  62. you automatically drop out of the loop because the search forward fails.  If
  63. you use the e option you will miss the last occurrence if it happens to be
  64. absolutely the last thing in the file, which will never happen in a Modula-2
  65. file.
  66.  
  67. buf49 = search string
  68. buf50 = message
  69. n50 = flag(0=false,1=searchCapsTrue)
  70. n51 = flag(-1=backward,1=forward)
  71. n52 = flag(0=else,1=shftCtl-i)
  72. n53 = flag(0=first search,1=else)
  73. n54,
  74. n55 = fbq input in shftCtl-i loop
  75. n56 = flag(0=search FALSE,1=search TRUE)
  76. locI = location of next identifier in the list (bookmark d)
  77. =============================================================================
  78. Pick up word or hilited phrase and search forward
  79. <shftCtl-f:
  80. equateNum(n51,1)
  81. equateNum(n52,0)
  82. runKey(14)
  83. >Sunday 24-Feb-91 14:26:34
  84.  
  85. Pick up word or hilited phrase and search backward
  86. <shftCtl-b:
  87. equateNum(n51,-1)
  88. equateNum(n52,0)
  89. runKey(14)
  90. >Sunday 24-Feb-91 12:39:15
  91.  
  92. Scan for identifier using fb loop, starting at sFile
  93. <shftCtl-i:
  94. equateNum(n51,1)  ..n51=1=search forward
  95. equateNum(n52,1)  ..n52=1=fb loop
  96. equateNum(n53,0)  ..n53=0=first search
  97.  
  98. LABEL(0) ..fb loop
  99. runKey(14)
  100. if (eqNum(n56,0)) return
  101. putMsg("f=forward, b=backward, s=sFile, e=eFile, q=quit")
  102. getKeyVAL(n54,n55)
  103. switch(n55) {
  104.    case("f") {equateNum(n51,1) }
  105.    case("b") {equateNum(n51,-1) }
  106.    case("s") {moveCursor(curFile,sFile) 
  107.               equateNum(n51,1) }
  108.    case("e") {moveCursor(curFile,eFile) 
  109.               moveCursor(curFile,sChar) 
  110.               equateNum(n51,-1) }
  111.    case("q") {putMsg("Quit fb id search, returned to next id") 
  112.               moveCursor(curFile,locI)
  113.               vScroll(atCursor)
  114.               return}
  115.    default   {putMsg("Quit fb id search") 
  116.               vScroll(atCursor)
  117.               return} }
  118. goto label(0)
  119. >Sunday 24-Feb-91 18:43:21
  120.  
  121. Identifier search
  122. <14:
  123. ..if fbq loop search, but not first time, skip ahead and use old id
  124. if (eqNum(n52,1) & eqNum(n53,1)) goto label(0)
  125.  
  126. ..make search case sensitive
  127. if (not getFlag(curFile,searchCaps)) {
  128.    equateNum(n50,1)
  129.    flipFlag(curFile,searchCaps) }
  130. ..get identifier or phrase
  131. if (!((eqLoc(curFile,atCursor,sInvert)) |
  132.     ((gtLoc(curFile,atCursor,sInvert) &
  133.     gtLoc(curFile,eInvert,atCursor))))) {
  134.    ..find identifier under cursor
  135.    ..in Modula an identifier is strictly alphanumeric
  136.    ..note that sWord-eWord includes alpha, digits, and "'"
  137.    if (is(curFile,"'") | !(is(curFile,alpha) | is(curFile,digit))) {
  138.       putMsg("CURSOR IS NOT ON AN IDENTIFIER")
  139.       return }
  140.    while ((is(curFile,alpha) | is(curFile,digit)) & !is(curFile,"'")) incLoc(curFile,atCursor)
  141.    ..alertUser ("right end of id")
  142.    equateLoc(curFile,eInvert,atCursor)
  143.    decLoc(curFile,atCursor)
  144.    while ((is(curFile,alpha) | is(curFile,digit)) & !is(curFile,"'")) decLoc(curFile,atCursor)
  145.    incLoc(curFile,atCursor)
  146.    ..alertUser ("left end of id")
  147.    equateLoc(curFile,sInvert,atCursor) }
  148.    
  149. ..before searching find next word in file (import list?), for next search
  150. moveCursor(curFile,eWord)
  151. moveCursor(curFile,eWord)
  152. moveCursor(curFile,sWord) 
  153. ..set bookmark d in case we want to return
  154. equateLoc(curFile,locI,atCursor)
  155. if (eqNum(n51,1)) .. searching fwd
  156.       moveCursor(curFile,eInvert)
  157.    else 
  158.       moveCursor(curFile,sInvert)
  159. ..alertUser("ready to search")
  160.  
  161. LABEL(0)
  162. if (eqNum(n52,1)) {    ..in fb loop
  163.    ..putMsg(n51) alertUser("fb loop LABEL(0): see n51")
  164.    if (eqNum(n53,0)) {                              ..first search, pick up id
  165.          equateNum(n53,1)}
  166.       else                                             ..not first, use old id
  167.          goto label(1) }
  168. ..store id in search buffer
  169. freeBuf(buf49)
  170. insertRgn(buf49,sFile,curFile,invert)
  171.  
  172. label(1)
  173. setSearch(buf49)
  174. ..putMsg(buf49)
  175. ..alertUser("got search")
  176. while(gtLoc(curFile,eFile,atCursor)) {
  177.    if (search (curFile,sInvert,eInvert,n51)) {
  178.          putMsg(buf49)
  179.          ..alertUser("found candidate")
  180.          ..check for whole word
  181.          equateLoc(curFile,locA,sInvert)
  182.          equateLoc(curFile,locB,eInvert)
  183.          decLoc(curFile,atCursor)
  184.          ..alertUser("checking left")
  185.          if (is(curFile,alpha) | is(curFile,digit)) {
  186.             ..alertUser("alpha|numeric on left")
  187.             goto label(2) } ..look for another candidate
  188.          moveCursor(curFile,eInvert)
  189.          ..alertUser("checking right")
  190.          if (is(curFile,alpha) | is(curFile,digit)) {
  191.             ..alertUser("alpha on right")
  192.             goto label(2) }  ..look for another candidate
  193.          decLoc(curfile,atCursor)
  194.          if (eqNum(n50,1)) flipFlag(curFile,searchCaps)
  195.          refreshDisplay
  196.          freeBuf(buf50)
  197.          insertRgn(buf50,sFile,"Next occurrance",all)
  198.          putMsg(buf50)
  199.          equateNum(n56,1) ..search=TRUE
  200.          return }
  201.       else {
  202.          equateNum(n56,0) ..search=FALSE, quit fb loop
  203.          if (eqNum(n52,1)) { ..in fb loop
  204.                putMsg("SEARCH FAILED returned to next id in list")
  205.                moveCursor(curFile,locI) }
  206.             else { ..simple search fwrd or bkwrd
  207.                if (eqNum(n51,-1)) {
  208.                      putMsg("SEARCH FAILED, no match above here")
  209.                      moveCursor(curFile,sInvert) }
  210.                   else {
  211.                      putMsg("SEARCH FAILED, no match below here")
  212.                      moveCursor(curFile,eInvert)
  213.                      moveCursor(curFile,sChar) } }
  214.          vScroll(atCursor)
  215.          return }
  216.    LABEL(2)  ..found embedded candidate, go to next word and search again
  217.    if (eqNum(n51,1)) 
  218.          moveCursor(curFile,eWord)
  219.       else 
  220.          moveCursor(curFile,sWord)
  221. }
  222. >Sunday 24-Feb-91 18:40:10
  223.  
  224. Test suite
  225. ============
  226. solo
  227. it
  228. digit
  229. digitize
  230. digit
  231. Test Case and it is a Test Case
  232. test case and it is the test case
  233. test this case test too
  234. blah blah test case
  235. TraceSTRING ('word', word);
  236. TraceSTRING ('word', word);
  237. INC(var34);
  238. INC(var)
  239. INC(var2)
  240. INC(var)
  241. DEC(var2)
  242. DEC(var3)
  243. DEC(var2)
  244. Test Case and it is a Test Case
  245.