home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 134 / af134a.adf / PrintManager.lzx / PrintManager39 / Developer / pmcmdex.c < prev    next >
C/C++ Source or Header  |  2000-01-04  |  3KB  |  102 lines

  1. /*
  2. **
  3. **    This example shows how to use the
  4. **    PrintManager v39 API
  5. **
  6. **    Currently only @{PMCMD:NAMEJOB/}
  7. **    is available
  8. **
  9. */
  10.  
  11. #include <exec/execbase.h>
  12. #include <devices/printer.h>
  13.  
  14. #include <pragma/exec_lib.h>
  15. #include <pragma/dos_lib.h>
  16.  
  17. /****************************************************************************/
  18.  
  19. struct Library    *SysBase,
  20.             *DOSBase;
  21.             
  22. /****************************************************************************/
  23.  
  24. void main( void )
  25. {
  26.     /*
  27.     **    some boring stuff
  28.     */
  29.     SysBase = (*(struct Library **)4L);
  30.     
  31.     if( DOSBase = OpenLibrary( "dos.library", 0L ) )
  32.     {
  33.         /*
  34.         **    allocate msgport, ioreq and finally open printer.device
  35.         */
  36.         struct MsgPort    *mp;
  37.         struct IOStdReq    *ior;
  38.         
  39.         mp = CreateMsgPort();
  40.         
  41.         if( ior = (struct IOStdReq *) CreateIORequest( mp, sizeof(struct IODRPReq) ) )
  42.         {
  43.             if( !OpenDevice( "printer.device", 0L, (struct IORequest *)ior, 0L ) )
  44.             {
  45.                 /*
  46.                 **    now check if printmanager is running.
  47.                 **    because of speed reasons we can only send
  48.                 **    commands at the beginning of a job.
  49.                 */
  50.                 struct Device    *dev;
  51.                 
  52.                 dev = (struct Device *)FindName( &((struct ExecBase *)SysBase)->DeviceList, "spool.device" );
  53.                 /*
  54.                 **    only spool.device v40+ has this feature,
  55.                 **     so make sure we've the right beast
  56.                 */
  57.                 if( dev && ((struct Library *)dev)->lib_Version >= 40L )
  58.                 {
  59.                     /*
  60.                     **    now send the name
  61.                     **    the name is limited to 25 chars and MUST NOT
  62.                     **    contain ':/#?*' ...
  63.                     */
  64.                     ior->io_Data = "@{PMCMD:NAMEJOB/ALotOfBuckets.txt}";
  65.                     ior->io_Length = -1L; // I am a lazy bone ;)
  66.                     ior->io_Command = PRD_RAWWRITE; // Must be a raw write !!!
  67.                     DoIO( (struct IORequest *)ior );
  68.                 }
  69.                 /*
  70.                 **    continue as usual - here we just write some text ...
  71.                 */
  72.                 ior->io_Data =    "100 buckets of bits on the bus\n"
  73.                             "100 buckets of bits\n"
  74.                             "Take one down, short it to ground\n"
  75.                             "FF buckets of bits on the bus\n"
  76.                             "\n"
  77.                             "FF buckets of bits on the bus\n"
  78.                             "FF buckets of bits\n"
  79.                             "Take one down, short it to ground\n"
  80.                             "FE buckets of bits on the bus\n"
  81.                             "\n"
  82.                             "ad infinitum...\f";
  83.                 ior->io_Length = -1L;
  84.                 ior->io_Command = CMD_WRITE;
  85.                 DoIO( (struct IORequest *)ior );
  86.                 
  87.                 CloseDevice( (struct IORequest *)ior );
  88.             }
  89.             else PutStr( "Cannot open printer.device\n" );
  90.             
  91.             DeleteIORequest( (struct IORequest *)ior );
  92.         }
  93.         else PrintFault( ERROR_NO_FREE_STORE, NULL );
  94.         
  95.         DeleteMsgPort( mp );
  96.     
  97.         CloseLibrary( DOSBase );
  98.     }
  99. }
  100.  
  101. /****************************************************************************/
  102.