home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume4 / troff2lj-v2 / part01 / download.c < prev    next >
C/C++ Source or Header  |  1989-02-03  |  2KB  |  148 lines

  1. /*
  2.  * download - download an HP LaserJet font file
  3.  * Usage: download [-d] [-s#] fontfile...
  4.  *
  5.  * Options:
  6.  * -d    delete any previously existing soft fonts
  7.  * -s#    assign font i.d.'s starting with # (default 0)
  8.  *
  9.  * Writes to the standard output.  Should be piped to lpr/lp.
  10.  *
  11.  * David MacKenzie
  12.  * Latest revision: 07/19/88
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include "hpconfig.h"
  17.  
  18. main(argc, argv)
  19.     int     argc;
  20.     char  **argv;
  21. {
  22.     extern char *optarg;
  23.     extern int optind;
  24.     int     c;
  25.     int     fid = 0;
  26.  
  27.     translate();
  28.     
  29.     while ((c = getopt(argc, argv, "ds:")) != EOF)
  30.     switch (c) {
  31.     case 'd':
  32.         delfonts();
  33.         break;
  34.     case 's':
  35.         fid = atoi(optarg);
  36.         break;
  37.     default:
  38.         usage(argv[0]);
  39.     }
  40.  
  41.     if (optind == argc)
  42.     usage(argv[0]);
  43.     else
  44.         for (; optind < argc; ++optind)
  45.         download(argv[optind], fid++);
  46.  
  47.     exit(0);
  48. }
  49.  
  50. /*
  51.  * Open given font file; if leading directory is not specified, assume
  52.  * it's in the standard one.
  53.  */
  54. FILE *
  55. openfont(file)
  56.     register char *file;
  57. {
  58.     FILE *ff;
  59.     char    path[BUFSIZ];
  60.     
  61.     if (file[0] != '/')
  62.     strcpy(path, FONTDIR);
  63.     else
  64.     path[0] = 0;
  65.     strcat(path, file);
  66.     if (!(ff = fopen(path, "r")))
  67.     perror(path);
  68.     return ff;
  69. }
  70.  
  71. /*
  72.  * Send the codes to download a font file.
  73.  */
  74.  
  75. download(file, fid)
  76.     char   *file;
  77.     int     fid;
  78. {
  79.     FILE   *openfont();
  80.     FILE   *ff;
  81.     register int c;
  82.  
  83.     if (!(ff = openfont(file)))
  84.     return;
  85.     
  86.     specfid(fid);
  87.  
  88.     while ((c = getc(ff)) != EOF)
  89.     putc(c, stdout);
  90.     fclose(ff);
  91.  
  92.     select(fid);
  93. }
  94.  
  95. /*
  96.  * Make the font with the specified i.d. permanent.
  97.  */
  98.  
  99. select(fid)
  100.     int     fid;
  101. {
  102.     specfid(fid);
  103.     permanent();
  104. }
  105.  
  106. /*
  107.  * Specify font i.d.
  108.  */
  109. specfid(fid)
  110.     int     fid;
  111. {
  112.     printf("\033*c%dD", fid);
  113. }
  114.  
  115. /*
  116.  * Make the last specified font permanent (not cleared by printer reset).
  117.  */
  118. permanent()
  119. {
  120.     printf("\033*c5F");
  121. }
  122.  
  123. /*
  124.  * Delete all downloaded fonts, freeing up the printer's memory.
  125.  */
  126. delfonts()
  127. {
  128.     printf("\033*c0F");
  129. }
  130.  
  131. /*
  132.  * We assume there are no newline translations occurring on the printer
  133.  * port, so as not to mangle downloaded fonts.  Therefore, make sure
  134.  * that the printer is doing them.
  135.  * p. 2-45, 2: CR=>CR; LF=>CRLF; FF=>CRFF
  136.  */
  137. translate()
  138. {
  139.      printf("\033&k2G");
  140. }
  141.  
  142. usage(file)
  143.     char   *file;
  144. {
  145.     fprintf(stderr, "Usage: %s [-d] [-s#] fontfile...\n", file);
  146.     exit(1);
  147. }
  148.