home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / PRINT.CMM < prev    next >
Text File  |  1995-03-31  |  2KB  |  71 lines

  1. //*************************************
  2. //*** Print.cmm - Print a text file ***
  3. //*** ver.1                         ***
  4. //*************************************
  5.  
  6. #define DEFAULT_PRINTER_SPEC  "PRN"
  7.  
  8. main(argc,argv)
  9. {
  10.    if ( argc == 2 ) {
  11.       PrinterSpec = DEFAULT_PRINTER_SPEC;
  12.       FileSpec = argv[1];
  13.    } else if ( argc == 3 ) {
  14.       PrinterSpec = argv[1];
  15.       FileSpec = argv[2];
  16.    } else {
  17.       Instructions();
  18.    }
  19.  
  20.    // Open file to print
  21.    if ( !(fpIn = fopen(FileSpec,"rt")) ) {
  22.       printf("\aUnable to open \"%s\" for reading.\n\n",
  23.              FileSpec);
  24.       Instructions();
  25.    }
  26.    // Open printer to write to
  27.    if ( !(fpOut = fopen(PrinterSpec,"wt")) ) {
  28.       fclose(fpIn);
  29.       printf("\aUnable to open printer spec \"%s\" for output.\n\n",
  30.              PrinterSpec);
  31.       Instructions();
  32.    }
  33.  
  34.    // read each input line and write to output
  35.    while ( line = fgets(fpIn) ) {
  36.       if ( EOF == fputs(line,fpOut) ) {
  37.          fclose(fpOut); fclose(fpIn);
  38.          printf("\aError writing to output printer \"%s\"\n\n",
  39.                 PrinterSpec);
  40.          Instructions();
  41.       }
  42.    }
  43.  
  44.    // close files; all done
  45.    fclose(fpOut);
  46.    fclose(fpIn);
  47.    return EXIT_SUCCESS;
  48. }
  49.  
  50. Instructions()
  51. {
  52.    puts("\a");
  53.    puts(`Print.cmm - Print a text file to specified printer`)
  54.    puts(``)
  55.    puts(`USAGE: CEnvi Print.cmm [Printer] <FileSpec>`)
  56.    puts(``)
  57.    puts(`WHERE: Printer: Optional name of printer device; default is `
  58.         DEFAULT_PRINTER_SPEC)
  59.    puts(`       FileSpec: Specification of file to print`)
  60.    puts(``)
  61.    puts(`EXAMPLES: CEnvi Print C:\AutoExec.bat`)
  62.    puts(`          CEnvi Print LPT2 G:\MYTEXT.DOC`)
  63.    puts(``)
  64.    if ( defined(_WINDOWS_) && !defined(_SHELL_) ) {
  65.       puts(`Press any key to exit...`)
  66.       getch()
  67.    }
  68.    exit(EXIT_FAILURE);
  69. }
  70.  
  71.