Jspice3
mkhpplot.c File Reference
#include "mfb.h"
#include "mfbP.h"
#include <dos.h>
#include <sys/types.h>
#include <sys/stat.h>
Include dependency graph for mkhpplot.c:

Go to the source code of this file.

Functions

static Bool dump ()
 
char * malloc ()
 
Bool makehpplot ()
 
Bool rasterize (FILE *fp)
 
void PrinterErrmsg (char *msg1, char *msg2)
 
Bool PrinterPortStatus (int which)
 
static Bool dump (long size, FILE *fp)
 
void SetPrinterDevice (char *device)
 

Variables

static char * hmsg = "hit any key to continue"
 
static char hc_device [10] = {'p','r','n'}
 
static int hc_port
 

Function Documentation

static Bool dump ( )
static
static Bool dump ( long  size,
FILE *  fp 
)
static

Definition at line 246 of file mkhpplot.c.

251 {
252  int i;
253  unsigned char *c;
254  static char *buf;
255  int bsize = 8192;
256  FILE *op;
257  union REGS r;
258 
259  if (!buf) buf = malloc(bsize);
260  if (!buf) {
261  PrinterErrmsg("Error: Out of memory.",hmsg);
262  (void)MFBGetchar();
263  return (true);
264  }
265 
266  op = fopen(hc_device,"wb");
267  if (!op) {
268  sprintf(buf,"Error: Printer driver %s not found.",hc_device);
269  PrinterErrmsg(buf,hmsg);
270  (void)MFBGetchar();
271  return (true);
272  }
273  PrinterErrmsg("Printing ...",NULL);
274 
275  if (bsize > size) bsize = size;
276 
277  /* put driver in raw mode */
278  r.x.bx = fileno(op);
279  r.x.dx = 0xa0;
280  r.x.ax = 0x4401;
281  int86(0x21,&r,&r);
282 
283  while (size >= bsize) {
284  fread(buf,bsize,1,fp);
285  for (i = 0; i < bsize; i++)
286  putc(buf[i],op);
287  size -= bsize;
288  }
289  if (size) {
290  fread(buf,size,1,fp);
291  for (i = 0; i < size; i++)
292  putc(buf[i],op);
293  }
294  PrinterErrmsg("Done",NULL);
295  fclose(op);
296  return (false);
297 }
static char buf[MAXPROMPT]
Definition: arg.c:18
void PrinterErrmsg(char *msg1, char *msg2)
Definition: mkhpplot.c:196
#define NULL
Definition: spdefs.h:121
int MFBGetchar()
Definition: mfbopen.c:259
static double c
Definition: vectors.c:16
Definition: fteparse.h:28
static char hc_device[10]
Definition: mkhpplot.c:21
Definition: cddefs.h:162
static char * hmsg
Definition: mkhpplot.c:20
char * malloc()
Bool makehpplot ( )

Definition at line 26 of file mkhpplot.c.

29 {
30  FILE *fp;
31  struct stat b;
32  int er;
33 
34 
35  fp = fopen("hpplot","wb");
36 
37  if (!fp) {
38  PrinterErrmsg("Error: Can't open output file.",hmsg);
39  (void)MFBGetchar();
40  return (true);
41  }
42 
43  if (rasterize(fp)) {
44  PrinterErrmsg("Error: Rasterization failed.",hmsg);
45  (void)MFBGetchar();
46  return (true);
47  }
48  fclose(fp);
49 
50  if (hc_port >= 0) {
51  while (PrinterPortStatus(hc_port)) {
52  PrinterErrmsg("Error: Printer is not accessible.",
53  "Hit any key to continue, q to abort:");
54  if ((char)MFBGetchar() == 'q')
55  return (true);
56  }
57  }
58  if (stat("hpplot",&b)) {
59  PrinterErrmsg("Error: File \"hpplot\" not found.\n",hmsg);
60  (void)MFBGetchar();
61  return (true);
62  }
63 
64  fp = fopen("hpplot","rb");
65 
66  if (!fp) {
67  PrinterErrmsg("Error: File \"hpplot\" not found.\n",hmsg);
68  (void)MFBGetchar();
69  return (true);
70  }
71  er = dump((long) b.st_size,fp);
72  fclose(fp);
73  return (er);
74 }
void PrinterErrmsg(char *msg1, char *msg2)
Definition: mkhpplot.c:196
static int hc_port
Definition: mkhpplot.c:22
int MFBGetchar()
Definition: mfbopen.c:259
static Bool dump()
Bool rasterize(FILE *fp)
Definition: mkhpplot.c:78
static char * hmsg
Definition: mkhpplot.c:20
Bool PrinterPortStatus(int which)
Definition: mkhpplot.c:228
char* malloc ( )
void PrinterErrmsg ( char *  msg1,
char *  msg2 
)

Definition at line 196 of file mkhpplot.c.

199 {
200  int x,y,w,h;
201  int l,r,t,b;
202 
203  w = MFBInfo(FONTWIDTH);
204  h = MFBInfo(FONTHEIGHT);
205  x = MFBInfo(MAXX)/2;
206  y = MFBInfo(MAXY)/2;
207  l = x - 19*w;
208  r = x + 19*w;
209  t = y + 2*h;
210  b = y - 2*h;
211 
212  MFBSetColor(0);
213  MFBBox(l,b,r,t);
214  MFBSetColor(1);
215  MFBLine(l,b,r,b);
216  MFBDrawLineTo(r,t);
217  MFBDrawLineTo(l,t);
218  MFBDrawLineTo(l,b);
219  MFBSetColor(2);
220  if (msg1)
221  MFBText(msg1,l+w,t-2*h,0);
222  if (msg2)
223  MFBText(msg2,l+w,t-3*h,0);
224 }
#define MAXY
Definition: mfb.h:522
#define FONTWIDTH
Definition: mfb.h:546
Definition: cddefs.h:169
Definition: cddefs.h:312
int MFBInfo()
void MFBText()
void MFBLine()
int MFBSetColor()
void MFBDrawLineTo()
#define MAXX
Definition: mfb.h:521
Definition: cddefs.h:162
#define FONTHEIGHT
Definition: mfb.h:545
void MFBBox()
Definition: cddefs.h:192
Bool PrinterPortStatus ( int  which)

Definition at line 228 of file mkhpplot.c.

230 {
231  int i;
232  union REGS r;
233 
234  r.x.ax = 0x0200;
235  r.x.dx = which;
236  int86(0x17,&r,&r);
237  i = r.x.ax;
238  i >>= 8;
239  /* bit 5 out of paper, bit 3 io error, bit 0 timed out */
240  if (i & 0x29) return (true);
241  return (false);
242 }
Definition: cddefs.h:162
Bool rasterize ( FILE *  fp)

Definition at line 78 of file mkhpplot.c.

82 {
83  int i, j, k, kk, len, isdev = 0;
84  char *rgen;
85  union { unsigned short o[2]; long l; } p1;
86  char cbuf, *buf, *c;
87  unsigned char mask, chr;
88  union REGS r;
89  if (!fp) return (true);
90 
91  r.x.bx = fileno(fp);
92  r.x.ax = 0x4400;
93  int86(0x21,&r,&r);
94  i = r.x.dx;
95  if (i & 0x80) { /* output is a device */
96 
97  isdev = 1;
98  /* put driver in raw mode */
99  r.x.bx = fileno(fp);
100  r.x.dx = 0xa0;
101  r.x.ax = 0x4401;
102  int86(0x21,&r,&r);
103  }
104 
105  buf = malloc(pc.bytpline + 8);
106  if (!buf) {
107  PrinterErrmsg("Out of memory!",NULL);
108  return (true);
109  }
110 
111  if (pc.mfbMODE != 4)
112 
113  /* X cursor position 250
114  * Y cursor position 400
115  * resolution 100 dpi
116  * start raster graphics at current position
117  */
118 
119  fprintf(fp,"\033*p250X\033*p400Y\033*t100R\033*r1A");
120 
121  /* raster line header */
122  sprintf(buf,"\033*b%dW",pc.bytpline);
123  len = strlen(buf);
124 
125  if (pc.mfbMODE & 2) {
126  cbuf = inp(0x3cd);
127  cbuf >>= 4;
128  p1.l = 0L;
129  for (i = 0; i < pc.ysize; i++) {
130  c = buf + len;
131  mask = 0x80;
132  chr = 0;
133  for (j = 0; j < pc.xsize; j++) {
134  if (cbuf != p1.o[1])
135  outp(0x3cd,(cbuf = p1.o[1]) << 4);
136  if (*(pc.base+p1.o[0]))
137  chr |= mask;
138  mask = (mask >> 1) | (mask << 7);
139  if (mask & 0x80) {
140  *c++ = chr;
141  chr = 0;
142  }
143  p1.l++;
144  }
145  if (isdev) {
146  for (kk = 0; kk < pc.bytpline+len; kk++)
147  putc(buf[kk],fp);
148  }
149  else {
150  if (fwrite(buf,1,pc.bytpline+len,fp) != pc.bytpline+len) {
151  free(buf);
152  return (true);
153  }
154  }
155  }
156  if (pc.mfbMODE != 4)
157  /* end raster graphics, form feed */
158  fprintf(fp,"\033*rB\014");
159  fflush(fp);
160  free(buf);
161  return (false);
162  }
163 
164  rgen = pc.base;
165  for (i = 0; i < pc.ysize; i++) {
166  c = buf + len;
167  for (j = 0; j < pc.bytpline; j++) {
168  *c = '\0';
169  for (k = 0; k < 4; k++) {
170  outpw(0x3ce,k << 8 | 4);
171  *c |= *rgen;
172  }
173  rgen++;
174  c++;
175  }
176  if (isdev) {
177  for (kk = 0; kk < pc.bytpline+len; kk++)
178  putc(buf[kk],fp);
179  }
180  else {
181  if (fwrite(buf,1,pc.bytpline+len,fp) != pc.bytpline+len) {
182  free(buf);
183  return (true);
184  }
185  }
186  }
187  if (pc.mfbMODE != 4)
188  fprintf(fp,"\033*rB\014");
189  fflush(fp);
190  free(buf);
191  return (false);
192 }
static char buf[MAXPROMPT]
Definition: arg.c:18
int mfbMODE
Definition: mfbp.h:41
Definition: cddefs.h:312
void PrinterErrmsg(char *msg1, char *msg2)
Definition: mkhpplot.c:196
#define L
Definition: parse.c:442
int ysize
Definition: mfbp.h:54
vidmptr base
Definition: mfbp.h:38
#define NULL
Definition: spdefs.h:121
static double c
Definition: vectors.c:16
Definition: cddefs.h:142
int xsize
Definition: mfbp.h:53
int bytpline
Definition: mfbp.h:39
Definition: cddefs.h:162
struct mfbpc pc
Definition: mfbopen.c:14
void free()
char * malloc()
void SetPrinterDevice ( char *  device)

Definition at line 301 of file mkhpplot.c.

304 {
305  strlwr(device);
306  if (device) {
307  if (!strcmp(device,"prn") || !strcmp(device,"lpt1"))
308  hc_port = 0;
309  else if (!strcmp(device,"lpt2"))
310  hc_port = 1;
311  else if (!strcmp(device,"lpt3"))
312  hc_port = 2;
313  else if (!strcmp(device,"lpt4"))
314  hc_port = 3;
315  else
316  hc_port = -1;
317  strncpy(hc_device,device,8);
318  hc_device[8] = '\0';
319  }
320  else {
321  strcpy(hc_device,"prn");
322  hc_port = 0;
323  }
324 }
DISPDEVICE device[]
Definition: display.c:24
char * strcpy()
static int hc_port
Definition: mkhpplot.c:22
static char hc_device[10]
Definition: mkhpplot.c:21

Variable Documentation

char hc_device[10] = {'p','r','n'}
static

Definition at line 21 of file mkhpplot.c.

int hc_port
static

Definition at line 22 of file mkhpplot.c.

char* hmsg = "hit any key to continue"
static

Definition at line 20 of file mkhpplot.c.