home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-3 / lockpub.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  5KB  |  114 lines

  1. /*
  2.  * V36 Lock public screen list example
  3.  *
  4.  * Compiled with SAS/C 6.56:  sc NMINC STRMERGE NOSTKCHK LINK lockpub.c
  5.  * Use V36 include files.
  6.  *
  7.  * Copyright (c) 1990 Commodore-Amiga, Inc.
  8.  *
  9.  * This example is provided in electronic form by Commodore-Amiga,
  10.  * Inc. for use with the Amiga Mail Volume II technical publication.
  11.  * Amiga Mail Volume II contains additional information on the correct
  12.  * usage of the techniques and operating system functions presented in
  13.  * these examples.  The source and executable code of these examples may
  14.  * only be distributed in free electronic form, via bulletin board or
  15.  * as part of a fully non-commercial and freely redistributable
  16.  * diskette.  Both the source and executable code (including comments)
  17.  * must be included, without modification, in any copy.  This example
  18.  * may not be published in printed form or distributed with any
  19.  * commercial product. However, the programming techniques and support
  20.  * routines set forth in these examples may be used in the development
  21.  * of original executable software products for Commodore Amiga
  22.  * computers.
  23.  *
  24.  * All other rights reserved.
  25.  *
  26.  * This example is provided "as-is" and is subject to change; no
  27.  * warranties are made.  All use is at your own risk. No liability or
  28.  * responsibility is assumed.
  29.  *
  30.  */
  31.  
  32. #include <string.h>
  33.  
  34. #include <intuition/intuition.h>
  35. #include <intuition/screens.h>
  36. #include <exec/memory.h>
  37. #include <exec/lists.h>
  38.  
  39. #include <clib/intuition_protos.h>
  40. #include <clib/exec_protos.h>
  41. #include <clib/alib_protos.h>
  42.  
  43. void main (void);
  44.  
  45. struct IntuitionBase *IntuitionBase;
  46.  
  47. void main(void)
  48. {
  49.  
  50.     struct List *publist;
  51.     struct List *copy_publist;
  52.     struct PubScreenNode *psnode;
  53.     struct PubScreenNode *copy_psnode;
  54.  
  55.     /* fails silently if not V36 */
  56.     if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  57.         if (copy_publist = AllocMem(sizeof(struct List), MEMF_CLEAR)) {
  58.             NewList(copy_publist);
  59.  
  60.             /* Lock the public screen list */
  61.             publist = LockPubScreenList();
  62.  
  63.             /* and copy it */
  64.             for (psnode = (struct PubScreenNode *)publist->lh_Head;
  65.                      psnode->psn_Node.ln_Succ;
  66.                      psnode = (struct PubScreenNode *)psnode->psn_Node.ln_Succ) {
  67.                 if (copy_psnode = AllocMem(sizeof(struct PubScreenNode), MEMF_CLEAR)) {
  68.                     /* Copy the structure */
  69.                     *copy_psnode = *psnode;
  70.  
  71.                     /* ln_Name points to the public screen name, make your own copy */
  72.                     if (copy_psnode->psn_Node.ln_Name =
  73.                             AllocMem(strlen(psnode->psn_Node.ln_Name) + 1, MEMF_CLEAR))
  74.                         strcpy(copy_psnode->psn_Node.ln_Name, psnode->psn_Node.ln_Name);
  75.                     else
  76.                         printf("Not enough memory to copy screen name\n");
  77.  
  78.                     AddTail(copy_publist, (struct Node *)copy_psnode);
  79.                 } else {
  80.                     printf("out of memory\n");
  81.                     break;
  82.                 }
  83.            }
  84.            UnlockPubScreenList();
  85.  
  86.            psnode = (struct PubScreenNode *)copy_publist->lh_Head;
  87.            while (copy_psnode = (struct PubScreenNode *)psnode->psn_Node.ln_Succ) {
  88.                 printf("%s\n", psnode->psn_Node.ln_Name);
  89.  
  90.                 printf("psn_Screen       0x%lx\n", psnode->psn_Screen);
  91.                                                                /* a pointer to the public screen */
  92.                 printf("psn_Flags        0x%lx\n", psnode->psn_Flags);
  93.                                                                /* the flags */
  94.                 printf("psn_VisitorCount %ld\n", psnode->psn_VisitorCount);
  95.                                                                /* the number of visitorwindows */
  96.                 printf("psn_SigTask      0x%lx\n", psnode->psn_SigTask);
  97.                                                                /* The task to signal when the */
  98.                                                                /* visitor is gone */
  99.                 printf("psn_SigBit       %ld\n\n", psnode->psn_SigBit);
  100.                                                                /* The signalbit number to use */
  101.                                                                /* to signal the task */
  102.  
  103.                 if (psnode->psn_Node.ln_Name)
  104.                     FreeMem(psnode->psn_Node.ln_Name, strlen(psnode->psn_Node.ln_Name) + 1);
  105.                 Remove((struct Node *)psnode);
  106.                 FreeMem(psnode, sizeof(struct PubScreenNode));
  107.                 psnode = copy_psnode;
  108.            }
  109.            FreeMem(copy_publist, sizeof(struct List));
  110.         }
  111.         CloseLibrary(IntuitionBase);
  112.     }
  113. }
  114.