home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d832 / term.lha / Term / term-3.1-Source.lha / termAmigaGuide.c < prev    next >
C/C++ Source or Header  |  1993-01-11  |  6KB  |  351 lines

  1. /*
  2. **    termAmigaGuide.c
  3. **
  4. **    AmigaGuide support routines
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Local data. */
  13.  
  14. STATIC STRPTR             ContextList[32];
  15. STATIC AMIGAGUIDECONTEXT     Context;
  16. STATIC struct NewAmigaGuide     NewGuide;
  17. STATIC struct Process        *GuideProcess;
  18. STATIC LONG             GuideContextID = CONTEXT_MAIN;
  19.  
  20.     /* GuideServer(VOID):
  21.      *
  22.      *    AmigaGuide server, handles all the signal processing.
  23.      */
  24.  
  25. STATIC VOID __saveds
  26. GuideServer(VOID)
  27. {
  28.         /* Open the help text file asynchronously... */
  29.  
  30.     if(Context = OpenAmigaGuideAsync(&NewGuide,TAG_DONE))
  31.     {
  32.         ULONG    GuideMask,
  33.             Signals;
  34.         BYTE    Done = FALSE;
  35.  
  36.             /* Pick up the signal notification mask. */
  37.  
  38.         GuideMask = AmigaGuideSignal(Context);
  39.  
  40.             /* Clear the context stack. */
  41.  
  42.         SetAmigaGuideContext(Context,0,TAG_DONE);
  43.  
  44.             /* Flag the main process to continue. */
  45.  
  46.         Signal(ThisProcess,SIG_HANDSHAKE);
  47.  
  48.             /* Go into input loop. */
  49.  
  50.         do
  51.         {
  52.                 /* Wait for a signal... */
  53.  
  54.             Signals = Wait(SIG_KILL | GuideMask);
  55.  
  56.                 /* Are we to quit? */
  57.  
  58.             if(Signals & SIG_KILL)
  59.                 Done = TRUE;
  60.  
  61.                 /* Process icoming AmigaGuide messages. */
  62.  
  63.             if(Signals & GuideMask)
  64.             {
  65.                 struct AmigaGuideMsg *GuideMessage;
  66.  
  67.                 while(GuideMessage = GetAmigaGuideMsg(Context))
  68.                     ReplyAmigaGuideMsg(GuideMessage);
  69.             }
  70.         }
  71.         while(!Done);
  72.  
  73.             /* Close the help text file. */
  74.  
  75.         CloseAmigaGuide(Context);
  76.     }
  77.  
  78.         /* Lock & quit. */
  79.  
  80.     Forbid();
  81.  
  82.     GuideProcess = NULL;
  83.  
  84.     Signal(ThisProcess,SIG_HANDSHAKE);
  85. }
  86.  
  87.     /* GuideLaunch(LONG ContextID):
  88.      *
  89.      *    Launch the AmigaGuide help file server.
  90.      */
  91.  
  92. STATIC BYTE
  93. GuideLaunch(LONG ContextID)
  94. {
  95.         /* Is the main program running and is this the
  96.          * main program to make the call?
  97.          */
  98.  
  99.     if(Window && SysBase -> ThisTask == ThisProcess)
  100.     {
  101.             /* Is the help file server already running? */
  102.  
  103.         if(!GuideProcess)
  104.         {
  105.             BYTE IsValidFile = TRUE;
  106.  
  107.                 /* Do we have a valid AmigaGuide file name? */
  108.  
  109.             if(Config -> PathConfig -> HelpFile[0])
  110.             {
  111.                 if(!GetFileSize(Config -> PathConfig -> HelpFile))
  112.                     IsValidFile = FALSE;
  113.             }
  114.             else
  115.                 IsValidFile = FALSE;
  116.  
  117.                 /* Do we have a valid AmigaGuide file name? */
  118.  
  119.             if(!IsValidFile)
  120.             {
  121.                     /* Don't pop up the file requester if any
  122.                      * time-critical services are currently running!
  123.                      */
  124.  
  125.                 if(ContextID == CONTEXT_TRANSFER || ContextID == CONTEXT_DIAL)
  126.                 {
  127.                     DisplayBeep(Window -> WScreen);
  128.  
  129.                     return(FALSE);
  130.                 }
  131.                 else
  132.                 {
  133.                     struct FileRequester    *FileRequest;
  134.                     UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  135.                                  DummyName[40];
  136.  
  137.                         /* Provide a default name if necessary. */
  138.  
  139.                     if(!Config -> PathConfig -> HelpFile[0])
  140.                         strcpy(Config -> PathConfig -> HelpFile,"PROGDIR:term.guide");
  141.  
  142.                         /* Block the windows. */
  143.  
  144.                     BlockWindows();
  145.  
  146.                         /* Get file and path name. */
  147.  
  148.                     strcpy(DummyBuffer,Config -> PathConfig -> HelpFile);
  149.  
  150.                     if(DummyBuffer[0])
  151.                     {
  152.                         STRPTR DummyChar;
  153.  
  154.                         if(FilePart(DummyBuffer) == DummyBuffer)
  155.                         {
  156.                             strcpy(DummyName,DummyBuffer);
  157.  
  158.                             DummyBuffer[0] = 0;
  159.                         }
  160.                         else
  161.                         {
  162.                             strcpy(DummyName,FilePart(DummyBuffer));
  163.  
  164.                             DummyChar = PathPart(DummyBuffer);
  165.  
  166.                             *DummyChar = 0;
  167.                         }
  168.                     }
  169.                     else
  170.                         DummyName[0] = 0;
  171.  
  172.                         /* Get the help text file name. */
  173.  
  174.                     if(FileRequest = GetFile(LocaleString(MSG_PATHPANEL_SELECT_HELP_FILE_TXT),DummyBuffer,DummyName,DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT)))
  175.                     {
  176.                         if(GetFileSize(DummyBuffer))
  177.                         {
  178.                             strcpy(Config -> PathConfig -> HelpFile,DummyBuffer);
  179.  
  180.                             IsValidFile = TRUE;
  181.                         }
  182.  
  183.                         FreeAslRequest(FileRequest);
  184.                     }
  185.  
  186.                         /* Release the windows... */
  187.  
  188.                     ReleaseWindows();
  189.                 }
  190.             }
  191.  
  192.                 /* Do we finally have a valid file name? */
  193.  
  194.             if(IsValidFile)
  195.             {
  196.                     /* Provide the context node names (note: language
  197.                      * specific!).
  198.                      */
  199.  
  200.                 LocalizeString(ContextList,MSG_TERMAMIGAGUIDE_NODE_00_TXT,MSG_TERMAMIGAGUIDE_NODE_29_TXT);
  201.  
  202.                     /* Open amigaguide.library, note: in order to stay
  203.                      * out of trouble only available under Kickstart 3.0.
  204.                      */
  205.  
  206.                 if(AmigaGuideBase = OpenLibrary("amigaguide.library",39))
  207.                 {
  208.                         /* Clear the instance. */
  209.  
  210.                     memset(&NewGuide,0,sizeof(struct NewAmigaGuide));
  211.  
  212.                         /* Fill in the structure. */
  213.  
  214.                     NewGuide . nag_BaseName        = "termHelp";
  215.                     NewGuide . nag_Name        = Config -> PathConfig -> HelpFile;
  216.                     NewGuide . nag_ClientPort    = "TERM_HELP";
  217.                     NewGuide . nag_Context        = ContextList;
  218.                     NewGuide . nag_Screen        = Window -> WScreen;
  219.  
  220.                         /* Launch the server process and
  221.                          * wait for reply.
  222.                          */
  223.  
  224.                     Forbid();
  225.  
  226.                     if(GuideProcess = CreateNewProcTags(
  227.                         NP_Entry,    GuideServer,
  228.                         NP_Name,    "term AmigaGuide process",
  229.                     TAG_DONE))
  230.                     {
  231.                         SetSignal(0,SIG_HANDSHAKE);
  232.  
  233.                         Wait(SIG_HANDSHAKE);
  234.                     }
  235.  
  236.                     Permit();
  237.  
  238.                         /* Is the server running? */
  239.  
  240.                     if(!GuideProcess)
  241.                     {
  242.                         CloseLibrary(AmigaGuideBase);
  243.  
  244.                         AmigaGuideBase = NULL;
  245.                     }
  246.                 }
  247.             }
  248.         }
  249.  
  250.             /* Pop the main screen to the front if necessary. */
  251.  
  252.         if(GuideProcess)
  253.         {
  254.             ScreenToFront(Window -> WScreen);
  255.  
  256.             return(TRUE);
  257.         }
  258.         else
  259.         {
  260.             DisplayBeep(Window -> WScreen);
  261.  
  262.             return(FALSE);
  263.         }
  264.     }
  265.     else
  266.     {
  267.         if(GuideProcess && Window)
  268.         {
  269.             ScreenToFront(Window -> WScreen);
  270.  
  271.             return(TRUE);
  272.         }
  273.         else
  274.             return(FALSE);
  275.     }
  276. }
  277.  
  278.     /* GuideCleanup():
  279.      *
  280.      *    Terminate the AmigaGuide server and free the
  281.      *    associated resources.
  282.      */
  283.  
  284. VOID
  285. GuideCleanup()
  286. {
  287.     if(GuideProcess)
  288.     {
  289.         Forbid();
  290.  
  291.         Signal(GuideProcess,SIG_KILL);
  292.  
  293.         SetSignal(0,SIG_HANDSHAKE);
  294.  
  295.         Wait(SIG_HANDSHAKE);
  296.  
  297.         Permit();
  298.     }
  299.  
  300.     if(AmigaGuideBase)
  301.     {
  302.         CloseLibrary(AmigaGuideBase);
  303.  
  304.         AmigaGuideBase = NULL;
  305.     }
  306. }
  307.  
  308.     /* GuideContext(LONG NewContextID):
  309.      *
  310.      *    Set the global AmigaGuide context.
  311.      */
  312.  
  313. VOID
  314. GuideContext(LONG NewContextID)
  315. {
  316.     GuideContextID = NewContextID;
  317. }
  318.  
  319.     /* GuideSetup():
  320.      *
  321.      *    Try to display the currently selected AmigaGuide
  322.      *    help text.
  323.      */
  324.  
  325. VOID
  326. GuideSetup()
  327. {
  328.     if(GuideLaunch(GuideContextID))
  329.     {
  330.         SendAmigaGuideCmd(Context,NULL,
  331.             AGA_Context,GuideContextID,
  332.         TAG_DONE);
  333.     }
  334. }
  335.  
  336.     /* GuideDisplay(LONG ContextID):
  337.      *
  338.      *    Try to display an AmigaGuide help text.
  339.      */
  340.  
  341. VOID
  342. GuideDisplay(LONG ContextID)
  343. {
  344.     if(GuideLaunch(ContextID))
  345.     {
  346.         SendAmigaGuideCmd(Context,NULL,
  347.             AGA_Context,ContextID,
  348.         TAG_DONE);
  349.     }
  350. }
  351.