home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pDos / DosNotiM.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  4.1 KB  |  164 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 08 Jan 1997 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>DosNotiM.c<<   08 Jan 1997    13:01:44 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/ex/DosNotiM p:pLib/StartCode.o p:/pOS_RKRM/pDos/DosNotiM.c p:pLib/StdIO.o -l pOSStub -l pOS
  10.  
  11. /***********************************************************
  12.   pOS programing example - Copyright (C) 1995-97 proDAD
  13.  
  14.   This code was written as an easy to understand example,
  15.   how to program pOS features. It is provided 'as-is',
  16.   without any express or implied warranty.
  17.  
  18.   Permission is hereby granted to use, copy and modify
  19.   this source code for any purpose, without fee, subject
  20.   to the following conditions:
  21.  
  22.     (1) This notice may not be removed or altered from any
  23.         source distribution.
  24.  
  25.     (2) Altered source versions must be plainly marked as
  26.         such, and must not be misrepresented as being
  27.         the original source code.
  28.  
  29.     (3) If only executable code is distributed, then the
  30.         accompanying documentation have to state that
  31.         "this software is based in part on examples of
  32.         the pOS developer packet".
  33.  
  34.     (4) Permission for use of this code is granted only
  35.         if the user accepts full responsibility for any
  36.         undesirable consequences. proDAD accept NO LIABILITY
  37.         for damages of any kind.
  38.  
  39.   ©proDAD
  40. ***********************************************************/
  41.  
  42. /*\
  43. *** Example:
  44. ***
  45. \*/
  46.  
  47.  
  48. #define __COMPUTER_AMIGA 1
  49. #define NOMYDEBUG
  50.  
  51. #include "p:pExec/Types.h"
  52. #include "p:pExec/Memory.h"
  53. #include "p:pExec/MsgPort.h"
  54. #include "p:pDOS/ArgTags.h"
  55. #include "p:pDOS/DosBase.h"
  56. #include "p:pDOS/DosSig.h"
  57. #include "p:pDOS/DosErrors.h"
  58. #include "p:pDOS/Notify.h"
  59. #include "p:proto/pLibExt.h"
  60. #include "p:proto/pExec2.h"
  61. #include "p:proto/pDOS2.h"
  62.  
  63. #ifdef _____ME_____
  64.   #include "grund/inc_string.h"
  65.   #include "grund/inc_stdio.h"
  66. #else
  67.  #ifdef __cplusplus
  68.  extern "C" {
  69.  #endif
  70.   #include <string.h>
  71.   #include <stdio.h>
  72.  #ifdef __cplusplus
  73.  }
  74.  #endif
  75. #endif
  76.  
  77.  
  78. const CHAR *HelpText=
  79. ""
  80. ;
  81.  
  82. const CHAR *PrgHeader=
  83. "Control Dos-Buffers";
  84.  
  85. const CHAR *PrgVerText=
  86. "$VER: 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Burkarth)";
  87.  
  88.  
  89.  
  90. /*----------------------------------
  91. -----------------------------------*/
  92. #ifdef __cplusplus
  93. extern "C"
  94. #endif
  95.  
  96. VOID main()
  97. {
  98.   struct pOS_DosArgs* Args;
  99.   ULONG Ops[1]={0};
  100.  
  101.   Args=pOS_ReadDosArgs(
  102. // 0
  103. "NAME/A/M",
  104. Ops,sizeof(Ops)/sizeof(ULONG),
  105.  
  106.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  107.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  108.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  109.     TAG_END);
  110.  
  111.   if(Args) {
  112.     pOS_MsgPort Port;
  113.     pOS_DosNotifyReq *Notify;
  114.     dosname_t **Names;
  115.     ULONG Sigs=0;
  116.     UWORD i,Num;
  117.  
  118.     for(Num=0, Names=(dosname_t**)Ops[0]; Names[Num]; ++Num); // Counting Names
  119.  
  120.     if(Notify=(pOS_DosNotifyReq*)
  121.               pOS_AllocMem(sizeof(pOS_DosNotifyReq)*Num,MEMF_PUBLIC)) {
  122.  
  123.       pOS_ConstructMsgPort(&Port);
  124.       for(i=0; i<Num; ++i) pOS_ConstructDosMsgNotify(&Notify[i],Names[i],0,&Port);
  125.  
  126.       for(i=0; i<Num; ++i) {
  127.         if(!pOS_DosStartNotify(&Notify[i])) {
  128.           Notify[i].nr_Name=NULL;
  129.           pOS_PrintDosErr(NULL,Names[i],0);
  130.         }
  131.       }
  132.       printf("Notification is installed, press Ctrl-C for abort.\n");
  133.  
  134.       while( !(Sigs & DOSSIGF_CTRL_C) ) {
  135.         const pOS_DosNotifyReq* Req;
  136.         pOS_DosNotifyMessage *Msg;
  137.  
  138.         Sigs=pOS_WaitSignal(DOSSIGF_CTRL_C | (1<<Port.mp_SigBit) );
  139.  
  140.         while(Msg=(pOS_DosNotifyMessage*)pOS_GetMsg(&Port)) {
  141.           Req=Msg->nm_NReq;
  142.           printf("Notification: <%s> Code=%ld\n",Req->nr_FullName,Msg->nm_Code);
  143.           pOS_ReplyMsg(&Msg->nm_Message);
  144.         }
  145.       }
  146.  
  147.  
  148.       for(i=0; i<Num; ++i) {
  149.         if(Notify[i].nr_Name) pOS_DestructDosNotify(&Notify[i]);
  150.       }
  151.  
  152.       printf("Notification is removed.\n");
  153.  
  154.       pOS_DestructMsgPort(&Port);
  155.       pOS_FreeMem(Notify,sizeof(pOS_DosNotifyReq)*Num);
  156.     }
  157.     else printf("No Mem\n");
  158.  
  159.     pOS_DeleteDosArgs(Args);
  160.   }
  161. }
  162.  
  163.  
  164.