home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / rsyssrc.lha / RSysList.c < prev    next >
C/C++ Source or Header  |  1993-09-25  |  6KB  |  303 lines

  1. /*
  2. ***************************************************************************
  3. *
  4. * Datei:
  5. *    RSysList.c
  6. *
  7. * Inhalt:
  8. *
  9. *      --- Globale Routinen ---
  10. *
  11. *    int CountDevices ( long mask );
  12. *    int CountIntuiObjects ( int typ );
  13. *    int CountMemory ( void );
  14. *    int CountNodes ( struct List *list );
  15. *    int NoEntries ( void );
  16. *    void KillList ( void );
  17. *    void RefreshList ( int type );
  18. *    void RestoreList ( void );
  19. *    void SaveCurrentList ( void );
  20. *
  21. *      --- Lokale  Routinen ---
  22. *
  23. *
  24. * Bemerkungen:
  25. *    Listenverwaltung von RSys, Zählroutinen und interne Liste.
  26. *
  27. * Erstellungsdatum:
  28. *    07-Jul-93    Rolf Böhme
  29. *
  30. * Änderungen:
  31. *    07-Jul-93    Rolf Böhme    Erstellung
  32. *
  33. ***************************************************************************
  34. */
  35.  
  36. #include "RSys.h"
  37.  
  38.    /*
  39.     * CountIntuiObjects() zählt Screens oder Fenster,
  40.     * abhängig von Typ
  41.     */
  42. int
  43. CountIntuiObjects(int typ)
  44. {
  45.    int   wincount = 0,
  46.          scrcount = 0;
  47.    register struct Window *win;
  48.    register struct Screen *scr;
  49.    ULONG lock;
  50.  
  51.    lock = LockIBase(NULL);
  52.  
  53.    for (scr = IntuitionBase->FirstScreen; scr; scr = scr->NextScreen)
  54.    {
  55.       scrcount++;
  56.  
  57.       for (win = scr->FirstWindow; win; win = win->NextWindow) wincount++;
  58.    }
  59.  
  60.    UnlockIBase(lock);
  61.  
  62.    return ((typ == SCREENS) ? scrcount : wincount);
  63. }
  64.  
  65.    /*
  66.     * CountDevices() zählt im System angemeldete Devices
  67.     * entsprechend der übergebenen Maske
  68.     */
  69. int
  70. CountDevices(long mask)
  71. {
  72.    int   count = 0;
  73.    struct DosList *dl;
  74.  
  75.    dl = LockDosList(mask | LDF_READ);
  76.  
  77.    while (dl = NextDosEntry(dl, mask | LDF_READ)) count++;
  78.  
  79.    UnLockDosList(mask | LDF_READ);
  80.  
  81.    return count;
  82. }
  83.  
  84.    /*
  85.     * CountNodes() zählt die Elemente einer Liste
  86.     */
  87. int
  88. CountNodes(struct List *list)
  89. {
  90.    int   count = 0;
  91.    register struct Node *node;
  92.  
  93.    Forbid();
  94.  
  95.    for (node = list->lh_Head; node->ln_Succ; node = node->ln_Succ) count++;
  96.  
  97.    Permit();
  98.  
  99.    return count;
  100. }
  101.  
  102.    /*
  103.     * CountMemory() zählt die Memory-Chunks
  104.     */
  105. int
  106. CountMemory(void)
  107. {
  108.    int   count = 0;
  109.    register struct Node *node;
  110.    register struct MemChunk *Loop;
  111.  
  112.    Disable();
  113.  
  114.    for (node = SysBase->MemList.lh_Head; node->ln_Succ; node = node->ln_Succ)
  115.    {
  116.       count++;
  117.       for (Loop = ((struct MemHeader *) node)->mh_First; Loop; Loop = Loop->mc_Next) count++;
  118.    }
  119.  
  120.    Enable();
  121.  
  122.    return count;
  123. }
  124.  
  125.    /*
  126.     * NoEntries() gibt FALSE zurück, falls keine Einträge zum
  127.     * Anzeigen da sind. In diesem Falle wird das ListView auf
  128.     * dem Hauptfenster initialisiert
  129.     */
  130. int
  131. NoEntries(void)
  132. {
  133.    DPOS;
  134.  
  135.    if (countentries == 0)
  136.    {
  137.       RefreshListView();
  138.       PrintStatistics();
  139.  
  140.       return TRUE;
  141.    }
  142.  
  143.    PrintInfo("Creating list...", NO_SPEAK, 0);
  144.  
  145.    return FALSE;
  146. }
  147.  
  148.    /*
  149.     * RefreshList() erneuert die anzuzeigende Liste im
  150.     * Hauptfenster
  151.     */
  152. void
  153. RefreshList(int type)
  154. {
  155.    DPOS;
  156.  
  157.    if(!SysWnd) return;
  158.  
  159.    if (type <= GD_HardwareGad)
  160.    {
  161.       EmptyListView();
  162.       PrintHeader((enum ListTypes)type, NULL);
  163.    }
  164.  
  165.    topentry = 0;
  166.  
  167.    if(type < LASTTYPE) (*(EntryAttr[type].ea_func))();
  168.  
  169.    actualfindnode = GetNode(&ListeLVList, topentry);
  170.    actualfindnodenum = topentry;
  171.  
  172.    PrintStatistics();
  173.  
  174.    return;
  175. }
  176.  
  177. ScrollEntry *SaveEntries = NULL;
  178. struct List SavedList;
  179. int   SaveID;
  180. int   Savecountentries;
  181.  
  182.    /*
  183.     * SaveCurrentList() speichert die aktuelle Liste im
  184.     * Hauptfenster intern ab.  Diese kann dann wieder
  185.     * eingeladen werden
  186.     */
  187. void
  188. SaveCurrentList(void)
  189. {
  190.    int   i;
  191.  
  192.    DPOS;
  193.  
  194.    HandleHelp(MN_SaveCurrentList);
  195.  
  196.    if (SaveEntries && (NOT(Question(SysWnd, "Internal List exist! Do you want create a new list?", YES))))
  197.    {
  198.       PrintStatistics();
  199.       return;
  200.    }
  201.  
  202.    KillList();
  203.  
  204.    SaveEntries = (ScrollEntry *) MyAllocVec(countentries * sizeof(ScrollEntry),
  205.                                             MEMF_CLEAR | MEMF_ANY, NO_KILL);
  206.    if (SaveEntries)
  207.    {
  208.       struct Node *node = ListeLVList.lh_Head;
  209.  
  210.       NewList(&SavedList);
  211.  
  212.       SaveID = LastID;
  213.       Savecountentries = countentries;
  214.  
  215.       for (i = 0; (i < countentries) && node; i++)
  216.       {
  217.          CopyMem((APTR) node, (APTR) & (SaveEntries[i].se_Node), sizeof(ScrollEntry));
  218.  
  219.          AddTail(&SavedList, &SaveEntries[i].se_Node);
  220.  
  221.          node = node->ln_Succ;
  222.       }
  223.  
  224.       PrintInfo("Current list saved", SPEAK, SEC);
  225.  
  226.       PrintStatistics();
  227.    }
  228.  
  229.    return;
  230. }
  231.  
  232.    /*
  233.     * RestoreList() stellt die vorher intern abgespeicherte
  234.     * Liste aus dem Hauptfenster wieder her und erneuert das
  235.     * ListView
  236.     */
  237. void
  238. RestoreList(void)
  239. {
  240.    int   i;
  241.  
  242.    DPOS;
  243.  
  244.    HandleHelp(MN_RestoreList);
  245.  
  246.    if (SaveEntries)
  247.    {
  248.       struct Node *node = SavedList.lh_Head;
  249.  
  250.       LastID = SaveID;
  251.       countentries = Savecountentries;
  252.  
  253.       PrintHeader((enum ListTypes)LastID, NULL);
  254.  
  255.       EmptyListView();
  256.  
  257.       PrintInfo("Restore saved list", NO_SPEAK, 0);
  258.  
  259.       Entries = AllocScrollEntries(Savecountentries);
  260.  
  261.       for (i = 0; (i < Savecountentries) && node; i++)
  262.       {
  263.          CopyMem((APTR) node, (APTR) & (Entries[i].se_Node), sizeof(ScrollEntry));
  264.  
  265.          Entries[i].se_Node.ln_Name = Entries[i].se_Entry;
  266.  
  267.          AddNodeToList(i, NO_SORT, 0);
  268.  
  269.          node = node->ln_Succ;
  270.       }
  271.  
  272.       RefreshListView();
  273.  
  274.       PrintInfo("Previous saved list restored", SPEAK, 0);
  275.    }
  276.    else ErrorHandle("No internal list", LIST_NODE_ERR, SAVED_FAIL, NO_KILL);
  277.  
  278.    return;
  279. }
  280.  
  281.    /*
  282.     * KillList() gibt den Speicher der intern abgespeicherten
  283.     * Liste wieder frei
  284.     */
  285. void
  286. KillList(void)
  287. {
  288.    DPOS;
  289.  
  290.    HandleHelp(MN_KillList);
  291.  
  292.    if (SaveEntries)
  293.    {
  294.       MyFreeVec(SaveEntries);
  295.       SaveEntries = NULL;
  296.  
  297.       PrintInfo("Last saved list killed", SPEAK, SEC);
  298.       PrintStatistics();
  299.    }
  300.  
  301.    return;
  302. }
  303.