home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / commands / pf.lzh / PF / Source / pf2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-31  |  3.6 KB  |  135 lines

  1. /*---------------------------------------------------------*
  2.  | Author:  Maurizio Loreti, aka MLO or I3NOO.             |
  3.  | Address: University of Padova - Department of Physics   |
  4.  |          Via F. Marzolo, 8 - 35131 PADOVA - Italy       |
  5.  | Phone:   (39)(49) 844-313         FAX: (39)(49) 844-245 |
  6.  | E-Mail:  LORETI at IPDINFN (BITNET); or VAXFPD::LORETI  |
  7.  |         (DECnet) - VAXFPD is node 38.257 i.e. 39169; or |
  8.  |          LORETI@PADOVA.INFN.IT (INTERNET).              |
  9.  | Home: Via G. Donizetti 6 - 35010 CADONEGHE (PD) - Italy |
  10.  *---------------------------------------------------------*/
  11.  
  12. /*--------------------------------*
  13.  | PF.c - Short for PRINTFILES.c  |
  14.  | See the Read.Me file for help. |
  15.  *--------------------------------*/
  16.  
  17. #include <stdio.h>
  18. #include <stdarg.h>
  19. #include <exec/types.h>
  20. #include <intuition/intuition.h>
  21. #include <graphics/gfxbase.h>
  22. #include <libraries/dos.h>
  23. #include <libraries/reqbase.h>
  24. #include <devices/printer.h>
  25. #include "mlo.h"
  26. #include "pf2.h"
  27. #include "global.h"
  28.  
  29. main(
  30.   int argc,
  31.   char **argv
  32. ){
  33.  
  34. /**
  35.  | Main program: after having opened intuition library, look
  36.  | if we were started from CLI or Workbench; then process printer
  37.  | parameters; last, print selected files.
  38. **/
  39.  
  40.   Boolean select = False;             /* 'Some file selected' flag */
  41.   struct ESStructure *pESS;           /* 'Extended selection' pointer */
  42.   char fileName[FIL_MAX];             /* File name */
  43.   char dirName[DIR_MAX];              /* Directory name */
  44.   char target[TOT_MAX];               /* Complete name */
  45.   int i;
  46.  
  47.   IntuitionBase = LibOpen("intuition.library",  REVISION);
  48.  
  49.   if (argc) {
  50.     FromCLI = True;
  51.     argv    = Setup(&argc, argv);
  52.   } else {
  53.     FromCLI = False;
  54.     SetupWB();
  55.  
  56. /**
  57.  | Set file requester parameters
  58. **/
  59.  
  60.     fr.Title = "File(s) to print:";
  61.     fr.Dir   = dirName;
  62.     fr.File  = fileName;
  63.     fr.Flags = FRQSHOWINFOM | FRQCACHINGM | FRQINFOGADGETM |
  64.                FRQEXTSELECTM | FRQSAVINGM;
  65.     fr.MaxExtendedSelect = MAX_FILES;
  66.     fr.dirnamescolor     = fr.devicenamescolor  = RED_PEN;
  67.     fr.stringnamecolor   = fr.stringgadgetcolor = BLACK_PEN;
  68.     fr.boxbordercolor    = fr.gadgetboxcolor    = BLACK_PEN;
  69.   }
  70.  
  71.   InitPrinter();
  72.   bufferLength -= nBlanks;
  73.  
  74.   if (FromCLI) {
  75.     for (; argc--; argv++) {
  76.       DoOutput(*argv);
  77.     }
  78.   } else {
  79.     if (PageMode != SINGLE_PAGE)    SetSpecialMode();
  80.     FOREVER {
  81.       fileName[0] = NIHIL;
  82.       if (FileRequester(&fr)) {
  83.         select = True;
  84.         strcpy(target, dirName);
  85.         if ((i = strlen(target))  &&  target[i-1] != ':') {
  86.           target[i++] = '/';
  87.         }
  88.         if ((pESS = fr.ExtendedSelect) == NULL) {
  89.           strcpy(target+i, fileName);
  90.           DoOutput(target);
  91.         } else {
  92.           do {
  93.             strcpy(target+i, pESS->thefilename);
  94.             DoOutput(target);
  95.           } while ( (pESS = pESS->NextFile) != NULL);
  96.         }
  97.       } else {
  98.         break;
  99.       }
  100.     }
  101.  
  102.     if (!select) {
  103.       SimpleRequest("Printer initialised ... Good bye!");
  104.       Cleanup(SYS_NORMAL_CODE);
  105.     }
  106.   }
  107.  
  108.   FlushBuffers();
  109.   ExitProgram();
  110. }
  111.  
  112. void ErrMes(
  113.   char *mForm,                            /* Format */
  114.   ...                                     /* Optional arguments */
  115. ){
  116.  
  117. /**
  118.  | Print an error message: on stdout if started from CLI,
  119.  | in a requester if started from Workbench.
  120. **/
  121.  
  122.   char message[LINE_LENGTH];              /* Internal buffer */
  123.   va_list vl;                             /* Input argument pointer */
  124.  
  125.   va_start(vl, mForm);
  126.   vsprintf(message, mForm, vl);
  127.   va_end(vl);
  128.  
  129.   if (FromCLI) {
  130.     puts(message);
  131.   } else {
  132.     SimpleRequest(message);
  133.   }
  134. }
  135.