| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <string.h> |
| 4 |
/* $ApsCVS: src/apsfilter/contrib/okidisplay/okidisplay.c,v 1.2 2000/04/16 11:42:12 andreas Exp $ */ |
| 5 |
/* This program is supposed to insert a "PROGRAM LC DISPLAY" escape sequence */ |
| 6 |
/* into an already HPLJ convert byte stream. The byte stream is passed through*/ |
| 7 |
/* and at the appropriate place the ESC sequence to write into the LCDisplay */ |
| 8 |
/* is inserted (that is, after the initial ESC E reset sequence(s)). */ |
| 9 |
/* Martin Kraemer, March 1995 */ |
| 10 |
|
| 11 |
|
| 12 |
typedef struct |
| 13 |
{ |
| 14 |
unsigned char MSB, LSB; |
| 15 |
} WORD; |
| 16 |
|
| 17 |
static struct HEADER |
| 18 |
{ |
| 19 |
WORD Header; /* == 10, 0 */ |
| 20 |
unsigned char Format; /* == 0 */ |
| 21 |
unsigned char Continue; /* == 0 */ |
| 22 |
unsigned char When; /* 0:Vor Druck; 1:Nach Druck; 2:Nach Komplettdruck */ |
| 23 |
unsigned char GoOffline; /* 1:Go Offline; 2:Stay Online */ |
| 24 |
unsigned char WaitForRecover; /* 0:No Waiting; 1:Wait for [RECOVER] Keypress */ |
| 25 |
unsigned char Resv; /* == 0 */ |
| 26 |
WORD StrLen; /* Anzahl Bytes in Text */ |
| 27 |
} OkiHeader = { |
| 28 |
{ 0, 10 }, |
| 29 |
0, |
| 30 |
0, |
| 31 |
0, /* Vor Seitendruck */ |
| 32 |
2, /* bleibt OnLine */ |
| 33 |
0, /* kein Warten auf [RECOVER] Taste */ |
| 34 |
0, /* fest==0 */ |
| 35 |
{ 0, 0 } /* Laenge wird eingefuellt. */ |
| 36 |
}; |
| 37 |
|
| 38 |
static inline void |
| 39 |
SetWord (WORD *Dest, unsigned Value) |
| 40 |
{ |
| 41 |
Dest->MSB = (Value >> 8) & 0xFF; |
| 42 |
Dest->LSB = Value & 0xFF; |
| 43 |
} |
| 44 |
|
| 45 |
#define ESC '\033' |
| 46 |
|
| 47 |
void |
| 48 |
main(int argc, char *argv[]) |
| 49 |
{ |
| 50 |
char *buf=NULL; |
| 51 |
int first[2], count=0; |
| 52 |
int i; |
| 53 |
|
| 54 |
while (count == 0 && (first[0] = getchar()) != EOF) |
| 55 |
{ |
| 56 |
++count; |
| 57 |
if (first[0] == ESC) |
| 58 |
if ((first[1] = getchar()) != EOF) |
| 59 |
{ |
| 60 |
++count; |
| 61 |
if (first[1] == 'E') |
| 62 |
{ |
| 63 |
/* RESET Sequence wird _vor_ dem Rest ausgegeben. */ |
| 64 |
putchar (first[0]); |
| 65 |
putchar (first[1]); |
| 66 |
count=0; /* Alles gedruckt: nichts mehr gepuffert. */ |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
/* Concatenate all strings, separated by spaces */ |
| 72 |
for (i=1; i<argc; ++i) |
| 73 |
{ |
| 74 |
if (buf == NULL) |
| 75 |
buf = strdup(argv[i]); |
| 76 |
else |
| 77 |
{ |
| 78 |
buf = realloc (buf, strlen(buf)+strlen(argv[i])+sizeof(" ")); |
| 79 |
if (buf != NULL && strlen(argv[i]) > 0) |
| 80 |
strcat(strcat(buf," "), argv[i]); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
/* Print buffer prefixed by the defined HEADER structure: */ |
| 85 |
if (buf == NULL) |
| 86 |
{ |
| 87 |
fprintf (stderr, "Usage: %s some strings... <inputfile >/dev/lp\n", argv[0]); |
| 88 |
fprintf (stderr, " $Id: okidisplay.c,v 1.1.1.1 1998/05/12 21:36:26 andreas Exp $\n"); |
| 89 |
exit(1); |
| 90 |
} |
| 91 |
else |
| 92 |
{ |
| 93 |
SetWord (&OkiHeader.StrLen, strlen(buf)); |
| 94 |
fprintf (stdout, "\033/d%dW", sizeof(OkiHeader)+strlen(buf)); |
| 95 |
fwrite ((void *) &OkiHeader, sizeof(OkiHeader), 1, stdout); |
| 96 |
fwrite ((void *) buf, strlen(buf), 1, stdout); |
| 97 |
} |
| 98 |
|
| 99 |
/* print any remaining buffered characters: */ |
| 100 |
for (i=0; i<count; ++i) |
| 101 |
putchar (first[i]); |
| 102 |
|
| 103 |
while ((i = getchar()) != EOF) |
| 104 |
putchar(i); |
| 105 |
|
| 106 |
exit(0); |
| 107 |
} |