Example #1
0
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line args */
     char *argv[])			/* I - Command-line arguments */
{
  FILE		*fp;			/* File to print */
  int		copies;			/* Number of copies left */
  char		line[1024];		/* Line/buffer from stream/file */
  size_t	linelen;		/* Length of line */
  ppd_file_t	*ppd;			/* PPD file */


 /*
  * Check command-line...
  */

  if (argc < 6 || argc > 7)
  {
    _cupsLangPrintf(stderr,
                    _("Usage: %s job-id user title copies options [file]"),
		    argv[0]);
    return (1);
  }

  if (argc == 6)
  {
    copies = 1;
    fp     = stdin;
  }
  else
  {
    copies = atoi(argv[4]);
    fp     = fopen(argv[6], "rb");

    if (!fp)
    {
      perror(argv[6]);
      return (1);
    }
  }

 /*
  * Open the PPD file as needed...
  */

  ppd = ppdOpenFile(getenv("PPD"));

 /*
  * Copy the print file to stdout...
  */

  while (copies > 0)
  {
    copies --;

    if (ppd && ppd->jcl_begin)
      fputs(ppd->jcl_begin, stdout);
    if (ppd && ppd->jcl_ps)
      fputs(ppd->jcl_ps, stdout);

    if (!ppd || ppd->language_level == 1)
    {
     /*
      * Use setsoftwareiomode for BCP mode...
      */

      puts("%!PS-Adobe-3.0 ExitServer");
      puts("%%Title: (BCP - Level 1)");
      puts("%%EndComments");
      puts("%%BeginExitServer: 0");
      puts("serverdict begin 0 exitserver");
      puts("%%EndExitServer");
      puts("statusdict begin");
      puts("/setsoftwareiomode known {100 setsoftwareiomode}");
      puts("end");
      puts("%EOF");
    }
    else
    {
     /*
      * Use setdevparams for BCP mode...
      */

      puts("%!PS-Adobe-3.0");
      puts("%%Title: (BCP - Level 2)");
      puts("%%EndComments");
      puts("currentsysparams");
      puts("/CurInputDevice 2 copy known {");
      puts("get");
      puts("<</Protocol /Binary>> setdevparams");
      puts("}{");
      puts("pop pop");
      puts("} ifelse");
      puts("%EOF");
    }

    if (ppd && ppd->jcl_end)
      fputs(ppd->jcl_end, stdout);
    else if (!ppd || ppd->num_filters == 0)
      putchar(0x04);

   /*
    * Loop until we see end-of-file...
    */

    do
    {
      linelen = sizeof(line);
      if (psgets(line, &linelen, fp) == NULL)
	break;
    }
    while (pswrite(line, linelen) > 0);

    fflush(stdout);
  }

  return (0);
}
Example #2
0
File: tbcp.c Project: jelmer/cups
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line args */
     char *argv[])			/* I - Command-line arguments */
{
  FILE		*fp;			/* File to print */
  int		copies;			/* Number of copies left */
  char		line[1024];		/* Line/buffer from stream/file */
  size_t	linelen;		/* Length of line */


 /*
  * Check command-line...
  */

  if (argc < 6 || argc > 7)
  {
    _cupsLangPrintf(stderr,
                    _("Usage: %s job-id user title copies options [file]"),
		    argv[0]);
    return (1);
  }

  if (argc == 6)
  {
    copies = 1;
    fp     = stdin;
  }
  else
  {
    copies = atoi(argv[4]);
    fp     = fopen(argv[6], "rb");

    if (!fp)
    {
      perror(argv[6]);
      return (1);
    }
  }

 /*
  * Copy the print file to stdout...
  */

  while (copies > 0)
  {
    copies --;

   /*
    * Read the first line...
    */

    linelen = sizeof(line);
    if (!psgets(line, &linelen, fp))
      break;

   /*
    * Handle leading PJL fun...
    */

    if (!strncmp(line, "\033%-12345X", 9) || !strncmp(line, "@PJL ", 5))
    {
     /*
      * Yup, we have leading PJL fun, so copy it until we hit a line
      * with "ENTER LANGUAGE"...
      */

      while (strstr(line, "ENTER LANGUAGE") == NULL)
      {
        fwrite(line, 1, linelen, stdout);

	linelen = sizeof(line);
	if (psgets(line, &linelen, fp) == NULL)
          break;
      }
    }
    else
    {
     /*
      * No PJL stuff, just add the UEL...
      */

      fputs("\033%-12345X", stdout);
    }

   /*
    * Switch to TBCP mode...
    */

    fputs("\001M", stdout);

   /*
    * Loop until we see end-of-file...
    */

    while (pswrite(line, linelen, stdout) > 0)
    {
      linelen = sizeof(line);
      if (psgets(line, &linelen, fp) == NULL)
	break;
    }

    fflush(stdout);
  }

  return (0);
}