DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T q

⟦70b17b2fa⟧ TextFile

    Length: 4654 (0x122e)
    Types: TextFile
    Names: »qmsf.c«

Derivation

└─⟦060c9c824⟧ Bits:30007080 DKUUG TeX 2/12/89
    └─⟦this⟧ »./DVIware/obsolete/mitdrivers/dvi2qms/qmsf.c« 

TextFile


/*
 *    qmsf.c - output filter for qms printers
 *
 *    Copyright 1985 Massachusetts Institute of Technology
 *    Author: CJL@OZ
 *
 *
 */

#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include "util.h"
#include "fonts.h"

/* \122 = 'R'. The MOBY_RESET string is constructed this way so 
 * this source text can be printed out on a QMS printer without resetting
 * the printer. */
#define MOBY_RESET	"\122eSeTrEsEtReSeT"
#define QUIC_ON		"\r^PY^-\r"
#define QUIC_OFF	"\r^-^PN^-\r"
#define DEFAULT_FONT	"^IS%05.5d^-"
#define DELETE_FONTS	"^DFEA^G^-"
#define CLEAR_OVERLAYS	"^DOC^Z^-"
#define SYNTAX		"^ISYNTAX%1.1d%1.1d%1.1d%1.1d%1.1d^-"
#define PORTRAIT	"^IOP^-"
#define V_MARGINS	"^IMV%05.5d%05.5d^-"
#define H_MARGINS	"^IMH%05.5d%05.5d^-"
#define TRAY		"^IF%1.1d%1.1d%1.1d%1.1d^-"
#define CHAR_SP		"^IC%04.4d^-"
#define LINE_SP		"^IL%04.4d^-"

extern char *rindex();
char *programname;
long charvec[4];
int devwidth,texwidth;
int ready = 0;
int length = 66;
int width = 94;
int charpos,charcol,onfirstpage;
int qms2400 = 0;

init_qms()
{
  int i;
  char *s = PXLDIR;

  /* Reset the printer. 
   * We can assume nothing about the current state of the printer.
   * So first set the printer to a known state.
   */
  printf(MOBY_RESET);		/* MOBY reset */
  printf(QUIC_ON);		/* Turn on QUIC */
  /* printf(DELETE_FONTS); */	/* Delete all downloaded fonts */
  printf(CLEAR_OVERLAYS);	/* Clear all overlays */
  printf(MOBY_RESET);		/* MOBY reset again */

  printf(QUIC_ON);		/* Turn on QUIC */
  printf(SYNTAX,0,0,0,0,0);	/* Ensure default SYNTAX */
  printf(PORTRAIT);		/* Portrait page orientation */
  printf(V_MARGINS,250,11000);	/* Vertical margins */
  printf(H_MARGINS,890,8500);	/* Horizontal margins */
  printf(CHAR_SP,0);		/* Turn off char spacing */
  printf(LINE_SP,620);		/* Vertical spacing */
  printf(DEFAULT_FONT,10);	/* Select the font I like */
  printf(SYNTAX,0,0,0,1,0);	/* Ensure default SYNTAX */
  if (qms2400)
    printf(TRAY,0,0,0,1);	/* Take first page from tray 2 */
  f_init(stdout,programname,&s,1,10,157876,1000,0);
  for (i = ' ';i < 0377;i++) charvec[i / 32] |= (1 << (i % 32));
  f_define_font(1,0,"","amtt10",1095,717619,0);
  i = 1;
  f_newpage(&i,charvec,1);
  f_use_font(1,&i);
  onfirstpage = ready = 1;
  charpos = charcol = 0;
};


dev_print_log()
{
}

term_qms()
{
  if (ready) {
    dochar('\f');
    ready = 0;
  }
  printf(QUIC_OFF);
  fflush(stdout);
};    

main(argc, argv) 
    int argc;
    char *argv[];
{
  register int ch;
  int i;

  programname = argv[0];
  if (!access("qms2400",0)) qms2400 = -1;
  for (i = 0; i < argc; i++) {
    if (argv[i][0] = '-') switch (argv[i][1]) {
    case 'w':
      sscanf(argv[i]+2,"%d",&width);
      break;

    case 'l':
      sscanf(argv[i]+2,"%d",&length);
      break;
    }
  }
  while (!ferror(stdin) && (ch = getchar()) != EOF) switch (ch) {
  case '\031':
    /*
     * lpd needs to use a different filter to
     * print data so stop what we are doing and
     * wait for lpd to restart us.
     */
    if ((ch = getchar()) == '\1') {
      term_qms();
      kill(getpid(), SIGSTOP);
      break;
    } else {
      ungetc(ch, stdin);
      ch = '\031';
    }
  default:
    dochar(ch);
  }
  term_qms();
  exit(0);
}

dochar (ch)
int ch;
{
  int i;

  if (ch < ' ') 
    switch (ch) {
    case '\b':
      if (!ready) break;
      if (charpos) { 
	charpos--;
	printf("^TR-%04.4d",devwidth);
      }
      break;

    case '\t':
      if (!ready) init_qms();
      for (i = 8 - charpos%8; i > 0; i--) dochar(' ');
      break;

    case '\n':
      if (!ready) init_qms();
      if (++charcol >= length) dochar('\f');
      else {
	putchar('\r');
	putchar('\n');
	charpos = 0;
      }
      break;

    case '\r':
      if (!ready) break;
      if (charpos != 0) {
	charpos = 0;
	putchar('\r');
      }
      break;

    case '\f':
      if (!ready || ((charpos == 0) && (charcol == 0))) break;
      charpos = 0;
      charcol = 0;
      putchar('\f');
      i = 1;
      f_newpage(&i,charvec,1);
      f_use_font(1,&i);
      fflush(stdout);
      if (qms2400 && onfirstpage) {
	printf(TRAY,2,0,0,0);	/* Take rest of paper from tray 1 */
      }
      onfirstpage = 0;
      break;
    
    default:
      if (!ready) init_qms();
      dochar('^'); dochar('\b'); dochar('|');
      dochar(ch+'A'-001);
      break;
    } else {
      if (!ready) init_qms();
      if (++charpos > width) {
	putchar('!');
	dochar('\n');
	dochar(ch);
      } else {
	f_use_char(ch,&texwidth,&devwidth);
	switch (ch) {
	case ' ':
	  printf("^TR%04.4d",devwidth);
	  break;
	  
	case '^':
	  putchar(ch);

	default:
	  putchar(ch);
	}
      }
    }
}