home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / c / ch137_e.lha / CHelpRef.ttx < prev    next >
Text File  |  1992-10-03  |  3KB  |  127 lines

  1. /*
  2. ** $VER: CHelpRef.ttx 1.2 (03 Oct 1992)
  3. **
  4. ** Written by Magnus Holmgren.
  5. **
  6. ** Display the CHelp reference for the word currently under the
  7. ** cursor. If no word under cursor, ask for one.
  8. **
  9. ** Requires the file libs:rexxsupport.library, and the following
  10. ** files to be available in your command path:
  11. **
  12. ** ARunBack      (can be replaced)
  13. ** CHelp         (can be replaced .. NOT! :)
  14. ** WaitForPort   (part of the ARexx distribution)
  15. ** Delete        (not really neccessary..)
  16. **
  17. */
  18.  
  19. OPTIONS RESULTS
  20. PARSE ARG Word
  21.  
  22. /* Name of file that CHelp creates. Adjust according to your config */
  23.  
  24. LookUpFile = 'T:CHelp.Lup'
  25.  
  26. /*
  27. ** We try to find the word to reference first, so that we can move the
  28. ** cursor while the script is working.
  29. */
  30.  
  31. IF Word = "" THEN DO
  32.   GetChar        /* Need to check character under cursor */
  33.   Char = RESULT
  34.   GetWord        /* Get the word under the cursor */
  35.  
  36.   /*
  37.   ** Check if cursor is placed over "whitespace". Needed, since
  38.   ** GetWord returns the word _closest_ to the cursor.
  39.   */
  40.  
  41.   IF Char = ' ' | Char = '09'X | Char = '0a'X | Char = '00'X THEN DO
  42.     /* Ask for a reference */
  43.     RequestStr PROMPT '"Enter word to reference"'
  44.   END
  45.  
  46.   /* Only use the RESULT value if the requester wasn't canceled */
  47.  
  48.   IF RC = 0 THEN Word = RESULT
  49.  
  50. END
  51.  
  52. IF Word = "" | Word = "WORD" THEN DO
  53.   SetStatusBar 'No word to reference'
  54.   EXIT
  55. END
  56.  
  57. /* Make sure rexxsupport.library is available */
  58.  
  59. IF ~SHOW( 'L', 'rexxsupport.library' ) THEN
  60.   CALL ADDLIB( 'rexxsupport.library', 0, -30 )
  61.  
  62. /* Make sure CHelp is around */
  63.  
  64. IF ~SHOW( 'P', 'CHELP1' ) THEN DO
  65.   SetStatusBar TEMPORARY 'Starting CHelp'
  66.  
  67.   /*
  68.   ** Start CHelp. If you don't have ARunBack, use e.g.
  69.   ** "Run >NIL: <NIL: CHelp -s"
  70.   */
  71.  
  72.   ADDRESS COMMAND 'ARunBack CHelp -s QUIET STACK 4096'
  73.  
  74.   /* And wait for it to load (up to 10 secs) */
  75.  
  76.   ADDRESS COMMAND 'WaitForPort CHELP1'
  77.  
  78.   IF ~SHOW( 'P', 'CHELP1' ) THEN DO  /* Did it load? */
  79.     SetStatusBar 'CHelp not found'   /* Nope */
  80.     EXIT
  81.   END
  82. END
  83.  
  84. Size = Reference( Word )    /* Try to get the reference */
  85.  
  86. IF Size = 0 THEN DO         /* Not found. Try again, without Tags part (if any) */
  87.   Offset = INDEX( Word, 'Tags' )
  88.   NewWord = Word
  89.  
  90.   IF Offset ~= 0 THEN DO
  91.     NewWord = LEFT( Word, Offset - 1 )
  92.     Size = Reference( NewWord )
  93.   END
  94.  
  95.   IF Size = 0 THEN DO       /* Not found. Try again, now with 'A' appended */
  96.     Size = Reference( NewWord || 'A' )
  97.   END
  98. END
  99.  
  100. IF Size ~= 0 THEN DO
  101.   ADDRESS 'TURBOTEXT' 'OpenDoc NAME ' || LookUpFile
  102.   ADDRESS VALUE RESULT
  103.   SetReadOnly ON
  104. END
  105. ELSE DO
  106.   SetStatusBar 'Reference "' || Word || '" not found'
  107. END
  108.  
  109. ADDRESS COMMAND 'Delete ' || LookUpFile
  110.  
  111. EXIT
  112.  
  113. /*
  114. ** Set appropriate message in titlebar, ask CHelp for the reference,
  115. ** and return the size of the file that CHelp creates.
  116. */
  117.  
  118. Reference: PROCEDURE EXPOSE LookUpFile
  119.  
  120.   PARSE ARG Word
  121.  
  122.   SetStatusBar TEMPORARY 'Searching for "' || Word || '"...'
  123.   ADDRESS 'CHELP1' LOOK Word
  124.   File = StateF( LookUpFile )  /* This requires rexxsupport.library */
  125.   PARSE VAR File Foo Size Bar  /* Extract size information */
  126.   RETURN Size
  127.