home *** CD-ROM | disk | FTP | other *** search
/ Amiga GigaPD 3 / Amiga_GigaPD_v3_3of3.iso / amiga-magazin / ungepackt / mai_94 / disk2 / amigaguide / agbeispiel / agbeispiel.c < prev    next >
C/C++ Source or Header  |  1993-06-25  |  7KB  |  327 lines

  1. /*
  2. **
  3. ** Beispiel zur AmigaGuide-Library
  4. **
  5. **
  6. ** von Stephan Fuhrmann
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #include <proto/dos.h>
  14. #include <proto/exec.h>
  15. #include <proto/graphics.h>
  16. #include <proto/amigaguide.h>
  17. #include <proto/intuition.h>
  18.  
  19. #include <exec/execbase.h>
  20. #include <libraries/amigaguide.h>
  21. #include <utility/hooks.h>
  22.  
  23. extern struct ExecBase *SysBase;
  24. struct Library *AmigaGuideBase;
  25.  
  26. char prozessor[80];
  27. char matheprozessor[80];
  28. char betriebssystem[80];
  29.  
  30.  
  31. STRPTR Cont[]=
  32. {
  33.     "MAIN",
  34.     "ABOUT"
  35. };
  36.  
  37. /* diese Funktion ruft spΣter "hostEntry" auf */
  38. ULONG __asm hookEntry(
  39.     register __a0 struct Hook *h,
  40.     register __a2 VOID *obj,
  41.     register __a1 VOID *msg)
  42. {
  43.     /* Pass the parameters on the stack */
  44.     return ((h->h_SubEntry)(h, obj, msg));
  45. }
  46.  
  47. /* diese Funktion behandelt die AmigaGuideHost-Nachrichten */
  48. ULONG __saveds __stdargs hostEntry(struct Hook *h,STRPTR db,Msg msg)
  49. {
  50.     ULONG ergebnis=0;
  51.     
  52.     switch (msg->MethodID)
  53.     {
  54.         case HM_FINDNODE:
  55.         {
  56.             struct opFindHost *opfh=(struct opFindHost *)msg;
  57.  
  58.             printf ("FindNode [%s]\n",opfh->ofh_Node);
  59.  
  60.             if (!stricmp(opfh->ofh_Node,"MAIN"))
  61.                 ergebnis=1;
  62.  
  63.             if (!stricmp(opfh->ofh_Node,"CPU"))
  64.             {
  65.                 opfh->ofh_Title="Prozessor";
  66.                 ergebnis=1;
  67.             }
  68.  
  69.             if (!stricmp(opfh->ofh_Node,"FPU"))
  70.             {
  71.                 opfh->ofh_Title="Mathe-Prozessor";
  72.                 ergebnis=1;
  73.             }
  74.  
  75.             if (!stricmp(opfh->ofh_Node,"OS"))
  76.             {
  77.                 opfh->ofh_Title="Betriebssystem-Version";
  78.                 ergebnis=1;
  79.             }
  80.  
  81.             break;
  82.         }
  83.         case HM_OPENNODE:
  84.         {
  85.             struct opNodeIO *opni=(struct opNodeIO *)msg;
  86.  
  87.             printf ("OpenNode [%s]\n",opni->onm_Node);
  88.  
  89.             if (!stricmp(opni->onm_Node,"CPU"))
  90.             {
  91.                 ULONG len;
  92.                 ULONG proz=68000;
  93.  
  94.                 if (SysBase->AttnFlags & AFF_68040)
  95.                     proz+=40;
  96.                 else
  97.                 {
  98.                     if (SysBase->AttnFlags & AFF_68030)
  99.                         proz+=30;
  100.                     else
  101.                     {
  102.                         if (SysBase->AttnFlags & AFF_68020)
  103.                             proz+=20;
  104.                         else
  105.                         {
  106.                             if (SysBase->AttnFlags & AFF_68010)
  107.                                 proz+=10;
  108.                         }
  109.                     }
  110.                 }
  111.  
  112.                 opni->onm_DocBuffer=prozessor;
  113.  
  114.                 len=sprintf (prozessor,"Sie besitzen einen Motorola %ld Prozessor!\n",proz);
  115.  
  116.                 opni->onm_BuffLen=len;
  117.                 opni->onm_Flags=HTNF_KEEP|HTNF_ASCII;
  118.  
  119.                 ergebnis=1;
  120.             }
  121.  
  122.             if (!stricmp(opni->onm_Node,"FPU"))
  123.             {
  124.                 ULONG len;
  125.                 ULONG proz=0;
  126.  
  127.                 if (!(SysBase->AttnFlags & AFF_68881))
  128.                     proz=0;
  129.                 else
  130.                 {
  131.                     if (SysBase->AttnFlags & AFF_FPU40)
  132.                         proz=68040;
  133.                     else
  134.                     {
  135.                         if (SysBase->AttnFlags & AFF_68882)
  136.                             proz=68882;
  137.                         else
  138.                         {
  139.                             if (SysBase->AttnFlags & AFF_68881)
  140.                                 proz=68881;
  141.                         }
  142.                     }
  143.                 }
  144.  
  145.                 opni->onm_DocBuffer=matheprozessor;
  146.  
  147.                 if (proz)
  148.                     len=sprintf (matheprozessor,"Sie besitzen einen Motorola %ld Coprozessor!\n",proz);
  149.                 else
  150.                     len=sprintf (matheprozessor,"Sie besitzen keinen Motorola Coprozessor!\n");
  151.  
  152.                 opni->onm_BuffLen=len;
  153.                 opni->onm_Flags=HTNF_KEEP|HTNF_ASCII;
  154.  
  155.                 ergebnis=1;
  156.             }
  157.  
  158.             if (!stricmp(opni->onm_Node,"OS"))
  159.             {
  160.                 ULONG len;
  161.  
  162.                 opni->onm_DocBuffer=betriebssystem;
  163.  
  164.                 len=sprintf (betriebssystem,"Ihr Amiga verfⁿgt ⁿber das Betriebssystem v%ld.%ld!\n",SysBase->LibNode.lib_Version,SysBase->SoftVer);
  165.  
  166.                 opni->onm_BuffLen=len;
  167.                 opni->onm_Flags=HTNF_KEEP|HTNF_ASCII;
  168.  
  169.                 ergebnis=1;
  170.             }
  171.  
  172.             break;
  173.         }
  174.  
  175.         case HM_CLOSENODE:
  176.         {
  177.             struct opNodeIO *opni=(struct opNodeIO *)msg;
  178.  
  179.             printf ("CloseNode [%s]\n",opni->onm_Node);
  180.  
  181.  
  182.             break;
  183.         }
  184.         case HM_EXPUNGE:
  185.         {
  186.             printf ("Expunge\n");
  187.             break;
  188.         }        
  189.     }
  190.  
  191.     return (ergebnis);
  192. }
  193.  
  194. void main(void)
  195. {
  196.     struct Hook hook;
  197.     struct NewAmigaGuide NAG;
  198.  
  199.     AMIGAGUIDECONTEXT MyContext;
  200.     AMIGAGUIDEHOST MyHost;
  201.  
  202.     if (AmigaGuideBase=OpenLibrary ("amigaguide.library",33))
  203.     {
  204.  
  205.         ULONG sigs,agsig,bekommen;
  206.         struct AmigaGuideMsg *agm;
  207.         int schluss=0;
  208.  
  209.         /* Dokument ist im aktuellen Verzeichnis */
  210.         NAG.nag_Lock=CurrentDir(CurrentDir(0));
  211.         NAG.nag_Name="SystemDaten.guide";
  212.         NAG.nag_Screen=0;
  213.         NAG.nag_PubScreen=0;
  214.         NAG.nag_HostPort=0;
  215.         NAG.nag_ClientPort="SystemDaten-HELP";
  216.         NAG.nag_BaseName="SystemDaten";
  217.         /* beim Start alles Laden */
  218.         NAG.nag_Flags=HTF_LOAD_ALL;
  219.         NAG.nag_Context=0;
  220.         NAG.nag_Node=0;
  221.         NAG.nag_Line=0;
  222.         NAG.nag_Extens=0;
  223.         NAG.nag_Client=0;
  224.  
  225.         hook.h_Entry=(ULONG (* )())hookEntry;
  226.         hook.h_SubEntry=(ULONG (* )())hostEntry;
  227.  
  228.         /* Host einrichten */
  229.         if (MyHost=AddAmigaGuideHost (&hook,"ExampleHost", NULL))
  230.         {
  231.             /* Asynchronen Proze▀ starten */
  232.             if (MyContext=OpenAmigaGuideAsyncA(&NAG,0))
  233.             {
  234.                 /* Signal d. Dokumentes herausfinden */
  235.                 agsig=AmigaGuideSignal (MyContext);
  236.  
  237.                 sigs=agsig | SIGBREAKF_CTRL_C;
  238.                 printf ("Bitte aktivieren Sie dieses Fenster, drⁿcken Sie CTRL-C und klicken\n");
  239.                 printf ("Sie auf das Schlie▀-Symbol, um das Programm zu beenden.\n");
  240.  
  241.                 /* warten, bis Proze▀ 'oben' ist */
  242.                 Delay (2);
  243.  
  244.                 /* Inhaltsverzeichnis auf den Schirm bringen */
  245.                 SendAmigaGuideCmdA (MyContext,"ALINK MAIN",0);
  246.  
  247.                 do
  248.                 {
  249.                     /* auf alle Signale warten */
  250.                     bekommen=Wait (sigs);
  251.  
  252.                     if (bekommen &áagsig)
  253.                     {
  254.                         while (agm=GetAmigaGuideMsg(MyContext))
  255.                         {
  256.                             printf ("Message bekommen: ");
  257.                             switch (agm->agm_Type)
  258.                             {
  259.                                 case StartupMsgID:
  260.                                     printf ("StartupMsgID\n");
  261.                                     break;
  262.                                 case LoginToolID:
  263.                                     printf ("LoginToolID\n");
  264.                                     break;
  265.                                 case LogoutToolID:
  266.                                     printf ("LogoutToolID\n");
  267.                                     break;
  268.                                 case ShutdownMsgID:
  269.                                     printf ("ShutdownMsgID\n");
  270.                                     break;
  271.                                 case ActivateToolID:
  272.                                     printf ("ActivateToolID\n");
  273.                                     break;
  274.                                 case DeactivateToolID:
  275.                                     printf ("DeactivateToolID\n");
  276.                                     break;
  277.                                 case ActiveToolID:
  278.                                     printf ("ActiveToolID\n");
  279.                                     break;
  280.                                 case InactiveToolID:
  281.                                     printf ("InactiveToolID\n");
  282.                                     break;
  283.                                 case ToolStatusID:
  284.                                     printf ("ToolStatusID\n");
  285.                                     break;
  286.                                 case ToolCmdID:
  287.                                     printf ("ToolCmdID\n");
  288.                                     break;
  289.                                 case ToolCmdReplyID:
  290.                                     printf ("ToolCmdReplyID\n");
  291.                                     break;
  292.                                 case ShutdownToolID:
  293.                                     printf ("ShutdownToolID\n");
  294.                                     break;
  295.                                 default:
  296.                                     printf ("Unbekannt!\n");
  297.                             }
  298.  
  299.                             if (agm->agm_Pri_Ret)
  300.                                 printf ("Fehler: %s!",GetAmigaGuideString (agm->agm_Sec_Ret));
  301.  
  302.                             ReplyAmigaGuideMsg (agm);
  303.                         }
  304.                     }
  305.                 } while (!(bekommen & SIGBREAKF_CTRL_C) && !schluss);
  306.  
  307.                 CloseAmigaGuide (MyContext);
  308.             }
  309.             else
  310.                 printf ("Konnte AmigaGuide-Dokument nicht ÷ffnen!\n");
  311.  
  312.             /* Schleife, bis Host entfernt */
  313.             while (RemoveAmigaGuideHost (MyHost,0)>0)
  314.             {
  315.                 /* Verz÷gerung, damit das Multitasking nicht belastet wird */
  316.                 Delay (1);
  317.             }
  318.         }
  319.         else
  320.             printf ("Konnte Host nicht einrichten (lΣuft noch einer?)!\n");
  321.  
  322.         CloseLibrary (AmigaGuideBase);
  323.     }
  324.     else
  325.         puts ("Konnte AmigaGuide-Library nicht ÷ffnen!");
  326. }
  327.