home *** CD-ROM | disk | FTP | other *** search
/ YPA: Your Privacy Assured / YPA.ISO / other_goodies / utilities / amigaguid.lha / AmigaGuide / AG_V39 / Source / HyperBrowser / dnh.c < prev    next >
C/C++ Source or Header  |  1993-01-08  |  5KB  |  251 lines

  1. /* dnh.c
  2.  *
  3.  * (c) Copyright 1992 Commodore-Amiga, Inc.  All rights reserved.
  4.  *
  5.  * This software is provided as-is and is subject to change; no warranties
  6.  * are made.  All use is at your own risk.  No liability or responsibility
  7.  * is assumed.
  8.  *
  9.  */
  10.  
  11. #include "hyperbrowser.h"
  12.  
  13. /*****************************************************************************/
  14.  
  15. #define    DB(x)    ;
  16.  
  17. /*****************************************************************************/
  18.  
  19. STRPTR nodeNames[] =
  20. {
  21.     "MAIN",
  22.     "MEMORY",
  23.  
  24.     "LIBRARYLIST",
  25.     "LIBRARY",
  26.     "DEVICELIST",
  27.     "DEVICE",
  28.  
  29.     "CLASSLIST",
  30.     "CLASS",
  31.     "SCREENLIST",
  32.     "SCREEN",
  33.     "WINDOW",
  34.     "GADGETLIST",
  35.     "GADGET",
  36.     NULL,
  37. };
  38.  
  39. STRPTR nodeTitles[] =
  40. {
  41.     "HyperBrowser",
  42.     "Memory",
  43.  
  44.     "Exec Library List",
  45.     "Library Information",
  46.     "Exec Device List",
  47.     "Device Information",
  48.  
  49.     "Intuition BOOPSI Class List",
  50.     "Intuition BOOPSI Class Information",
  51.     "Intuition Screen List",
  52.     "Screen Information",
  53.     "Window Information",
  54.     "Gadget List",
  55.     "Gadget Information",
  56. };
  57.  
  58. enum
  59. {
  60.     NM_MAIN,
  61.     NM_MEMORY,
  62.  
  63.     NM_LIBRARYLIST,
  64.     NM_LIBRARY,
  65.     NM_DEVICELIST,
  66.     NM_DEVICE,
  67.  
  68.     NM_CLASSLIST,
  69.     NM_CLASS,
  70.     NM_SCREENLIST,
  71.     NM_SCREEN,
  72.     NM_WINDOW,
  73.     NM_GADGETLIST,
  74.     NM_GADGET,
  75. };
  76.  
  77. #define    BEGIN    '('
  78. #define    END    ')'
  79.  
  80. /*****************************************************************************/
  81.  
  82. LONG Tokenize (struct GlobalData * gd, STRPTR name, ULONG * address)
  83. {
  84.     UBYTE buffer[32];
  85.     BOOL good = TRUE;
  86.     ULONG total = 0;
  87.     LONG i, j, k;
  88.     BYTE digit;
  89.     BYTE ch;
  90.  
  91.     /* See if it is the MAIN node */
  92.     if (Stricmp (name, nodeNames[0]) == 0)
  93.     return NM_MAIN;
  94.  
  95.     /* Chop the prefix from the node name */
  96.     strcpy (buffer, &name[strlen (BASENAME) + 1]);
  97.  
  98.     i = k = 0;
  99.     j = strlen (buffer);
  100.     while (i < j)
  101.     {
  102.     /* Search for an address */
  103.     if (buffer[i++] == BEGIN)
  104.     {
  105.         /* Terminate the buffer */
  106.         buffer[(i - 2)] = 0;
  107.  
  108.         /* Build the hex value string */
  109.         while ((i < j) && (buffer[i] != END) && good)
  110.         {
  111.         ch = ToUpper (buffer[i++]);
  112.         digit = ch - '0';
  113.         if (digit < 0 || digit > 9)
  114.         {
  115.             digit = ch - 'A';
  116.             if (digit >= 0 && digit < 6)
  117.             digit += 10;
  118.             else
  119.             good = FALSE;
  120.         }
  121.         total = UMult32 (total, 16) + digit;
  122.         }
  123.  
  124.         /* Able to convert it? */
  125.         if (good)
  126.         *address = total;
  127.  
  128.         /* All done parsing */
  129.         i = j;
  130.     }
  131.     }
  132.  
  133.     /* Find the token */
  134.     for (i = 0; nodeNames[i]; i++)
  135.     if (Stricmp (buffer, nodeNames[i]) == 0)
  136.         return i;
  137.     return -1;
  138. }
  139.  
  140. /*****************************************************************************/
  141.  
  142. ULONG ASM nodehost (REG (a0) struct Hook * h, REG (a2) STRPTR o, REG (a1) Msg msg)
  143. {
  144.     struct GlobalData *gd = (struct GlobalData *) h->h_Data;
  145.     struct opFindHost *ofh = (struct opFindHost *) msg;
  146.     struct opNodeIO *onm = (struct opNodeIO *) msg;
  147.     ULONG retval = FALSE;
  148.     ULONG address;
  149.     LONG token;
  150.  
  151.     switch (msg->MethodID)
  152.     {
  153.     case HM_FINDNODE:
  154.         DB (kprintf ("find : \"%s\" : ", ofh->ofh_Node));
  155.         /* We have to have a MAIN node, even if we never use it */
  156.         if (Stricmp (ofh->ofh_Node, nodeNames[0]) == 0)
  157.         {
  158.         /* Show that it is ours */
  159.         DB (kprintf ("found\n"));
  160.         retval = TRUE;
  161.         }
  162.         /* Is it one of our nodes? */
  163.         else if ((Strnicmp (ofh->ofh_Node, BASENAME, BASENAME_LENGTH) == 0) &&
  164.              ((token = Tokenize (gd, ofh->ofh_Node, &address)) >= 0))
  165.         {
  166.         /* Show that it is ours */
  167.         DB (kprintf ("found\n"));
  168.         retval = TRUE;
  169.  
  170.         /* Set the node title */
  171.         ofh->ofh_Title = nodeTitles[token];
  172.  
  173.         /* Don't let any browsing occur */
  174.         ofh->ofh_Next = ofh->ofh_Prev = ofh->ofh_Node;
  175.         }
  176.         else
  177.         {
  178.         DB (kprintf ("not found\n"));
  179.         }
  180.         break;
  181.  
  182.     case HM_OPENNODE:
  183.         DB (kprintf ("open %s\n", onm->onm_Node));
  184.  
  185.         /* Set the buffer pointer */
  186.         gd->gd_Node[0] = 0;
  187.  
  188.         /* Build the document */
  189.         switch (token = Tokenize (gd, onm->onm_Node, &address))
  190.         {
  191.         case NM_MEMORY:
  192.             showmemory (gd, address);
  193.             break;
  194.  
  195.             /* EXEC INFORMATION */
  196.         case NM_LIBRARYLIST:
  197.             showlibrarylist (gd);
  198.             break;
  199.  
  200.         case NM_LIBRARY:
  201.             showlibrary (gd, address);
  202.             break;
  203.  
  204.         case NM_DEVICELIST:
  205.             showdevicelist (gd);
  206.             break;
  207.  
  208.         case NM_DEVICE:
  209.             showdevice (gd, address);
  210.             break;
  211.  
  212.             /* INTUITION INFORMATION */
  213.         case NM_CLASSLIST:
  214.             showclasslist (gd);
  215.             break;
  216.  
  217.         case NM_SCREENLIST:
  218.             showscreenlist (gd);
  219.             break;
  220.  
  221.         case NM_SCREEN:
  222.             showscreen (gd, address);
  223.             break;
  224.  
  225.         case NM_WINDOW:
  226.             showwindow (gd, address);
  227.             break;
  228.         }
  229.  
  230.         /* Prepare the buffer information */
  231.         onm->onm_DocBuffer = gd->gd_Node;
  232.         onm->onm_BuffLen = strlen (onm->onm_DocBuffer);
  233.  
  234.         /* Remove the node from the database when done */
  235.         onm->onm_Flags |= HTNF_CLEAN;
  236.  
  237.         /* Show successful open */
  238.         retval = TRUE;
  239.         break;
  240.  
  241.     case HM_CLOSENODE:
  242.         DB (kprintf ("close %s\n", onm->onm_Node));
  243.         retval = TRUE;
  244.         break;
  245.  
  246.     case HM_EXPUNGE:
  247.         break;
  248.     }
  249.     return retval;
  250. }
  251.