home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d035 / consolewindow.lha / ConsoleWindow / console.c next >
Encoding:
C/C++ Source or Header  |  1986-09-09  |  3.1 KB  |  121 lines

  1. /*************************************************************************
  2.  * (C) 1986 Commodore-Amiga
  3.  * Example program to demonstrate finding the CON: window pointer
  4.  * by Andy Finkel and Robert (Kodiak) Burns
  5.  *
  6.  * Use it any way you like, as long as the copyright notice is left on.
  7.  *
  8.  ************************************************************************/
  9. #include    "exec/types.h"
  10. #include    "exec/ports.h"
  11. #include    "exec/io.h"
  12. #include    "exec/memory.h"
  13. #include    "devices/console.h"
  14. #include    "devices/conunit.h"
  15. #include    "libraries/dos.h"
  16. #include    "libraries/dosextens.h"
  17. #include    "intuition/intuitionbase.h"
  18. #include    "workbench/startup.h"
  19. #include    "workbench/workbench.h"
  20.  
  21. extern struct Library *OpenLibrary();
  22. struct IntuitionBase *IntuitionBase = 0;
  23.  
  24. struct MsgPort iorp = {
  25.     {0, 0, NT_MSGPORT, 0, 0}, 0,
  26.     -1,                /* initialize signal to -1 */
  27.     0,
  28.                 /* start with empty list */
  29.     {&iorp.mp_MsgList.lh_Tail, 0, &iorp.mp_MsgList.lh_Head, 0, 0}
  30. };
  31. struct IOStdReq ior = {
  32.     {{0, 0, 0, 0, 0}, &iorp, 0},
  33.     0                /* device is zero */
  34. };
  35.  
  36.  
  37.  
  38. cleanup(code)
  39. {
  40.     if (ior.io_Device != 0) {
  41.     if (iorp.mp_SigBit != -1) {
  42.         FreeSignal(iorp.mp_SigBit);
  43.     }
  44.     CloseDevice(&ior);
  45.     }
  46.     CloseLibrary(IntuitionBase);
  47.   
  48.     exit(20);
  49. }
  50.  
  51. main(argc, argv)
  52. int argc;
  53. char *argv[];
  54. {
  55.     struct MsgPort *con;
  56.     UBYTE *s1, *s2;
  57.     struct StandardPacket *packet;
  58.     struct InfoData *id;
  59.     short i;
  60.  
  61.     if ((IntuitionBase = OpenLibrary("intuition.library", 0)) == 0) {
  62.     exit(20);
  63.     }
  64.  
  65.     /* open the console device */
  66.     if ((OpenDevice("console.device", -1, &ior, 0)) != 0) {
  67.     cleanup(0);
  68.     exit(30);
  69.     }
  70.  
  71.     /* set up the message port in the I/O request */
  72.     if ((iorp.mp_SigBit = AllocSignal(-1)) < 0) {
  73.     cleanup(0);
  74.     exit(35);
  75.     }
  76.     iorp.mp_SigTask = (struct Task *) FindTask((char *) NULL);
  77.  
  78.  
  79.     /* try to find console associated with calling process */
  80.     /* if started from CLI, than is                */
  81.     if ((iorp.mp_SigTask->tc_Node.ln_Type == NT_PROCESS)&&(argc != 0)) {
  82.     con = (struct MsgPort *) 
  83.         ((struct Process *) iorp.mp_SigTask) -> pr_ConsoleTask;
  84.     if (con != 0) {
  85.         if ((packet = (struct StandardPacket *)
  86.             AllocMem(sizeof(*packet), MEMF_CLEAR))) {
  87.         if ((id = (struct id *) AllocMem(sizeof(*id), MEMF_CLEAR))) {
  88.             /* this is the console handlers packet port */
  89.             packet->sp_Msg.mn_Node.ln_Name = &(packet->sp_Pkt);
  90.             packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
  91.             packet->sp_Pkt.dp_Port = &iorp;
  92.             packet->sp_Pkt.dp_Type = ACTION_DISK_INFO;
  93.             packet->sp_Pkt.dp_Arg1 = ((ULONG) id) >> 2;
  94.             PutMsg(con, packet);
  95.             WaitPort(&iorp);
  96.             /* using the window directly here */
  97.             WindowToBack(id->id_VolumeNode);
  98.             WindowToFront(id->id_VolumeNode);
  99.             if ((id->id_InUse) && 
  100.             (IntuitionBase->LibNode.lib_Version >= 33)) {
  101.  
  102.             /* new DOS: IOB for console.device */
  103.             /* using the console directly here */
  104.             ior.io_Unit =
  105.                 ((struct IOStdReq *) id->id_InUse)->io_Unit;
  106.             ior.io_Command = CMD_WRITE;
  107.             ior.io_Data = "HELLO WORLD\n";
  108.             ior.io_Length = 12;
  109.             DoIO(&ior);
  110.             }
  111.             FreeMem(id, sizeof(*id));
  112.         }
  113.         FreeMem(packet, sizeof(*packet));
  114.         }
  115.     }
  116.     }
  117.     ior.io_Unit = (struct Unit *) -1;
  118.     cleanup(0);
  119. }
  120.  
  121.