-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathijs_server_epsonepl.c
1229 lines (1089 loc) · 28.6 KB
/
ijs_server_epsonepl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2003 Hin-Tak Leung, Roberto Ragusa
Adapted from IJS 0.34 ijs_server_example.c, with
reference to hpijs and gimp-print.
*/
/**
* Copyright (c) 2001-2002 artofcode LLC.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
**/
/* fdopen requires this */
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(HAVE_KERNEL_USB_DEVICE) || defined(HAVE_KERNEL_1284)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#endif
#include "ijs.h"
#include "ijs_server.h"
#include "epl_job.h"
#include "epl_bid.h"
#include "epl_time.h"
#define BUF_SIZE 4096
typedef struct _Epson_EPL_ParamList Epson_EPL_ParamList;
struct _Epson_EPL_ParamList {
Epson_EPL_ParamList *next;
char *key;
char *value;
int value_size;
};
static int
epson_epl_status_cb (void *status_cb_data,
IjsServerCtx *ctx,
IjsJobId job_id)
{
#ifdef EPL_DEBUG
fprintf (stderr, "epson_epl_status_cb\n");
#endif
return 0;
}
static int
epson_epl_list_cb (void *list_cb_data,
IjsServerCtx *ctx,
IjsJobId job_id,
char *val_buf,
int val_size)
{
const char *param_list = "OutputFile,OutputFD,DeviceManufacturer,DeviceModel,PageImageFormat,Dpi,Width,Height,BitsPerSample,ByteSex,ColorSpace,NumChan,PaperSize,PrintableArea,PrintableTopLeft,TopLeft,Quality,EplDpi,EplRitech,EplDensity,EplTonerSave,EplPaperType,EplCopies";
int size = strlen (param_list);
#ifdef EPL_DEBUG
fprintf (stderr, "epson_epl_list_cb\n");
#endif
if (size > val_size)
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_EBUF\n");
#endif
return IJS_EBUF;
}
memcpy (val_buf, param_list, size);
return size;
}
static int
epson_epl_enum_cb (void *enum_cb_data,
IjsServerCtx *ctx,
IjsJobId job_id,
const char *key,
char *val_buf,
int val_size)
{
const char *val = NULL;
#ifdef EPL_DEBUG
fprintf (stderr, "epson_epl_enum_cb\n");
#endif
if (!strcmp (key, "ColorSpace"))
val = "DeviceGray";
else if (!strcmp (key, "DeviceManufacturer"))
val = "Epson";
else if (!strcmp (key, "DeviceModel"))
val = "EPL5700L,EPL5800L,EPL5900L,EPL6100L,EPL6200L";
else if (!strcmp (key, "PageImageFormat"))
val = "Raster";
else if (!strcmp (key, "EplDpi"))
val = "600,300,Class600,Class1200";
else if (!strcmp (key, "EplRitech"))
val = "on, off";
else if (!strcmp (key, "EplDensity"))
val = "3,1,2,4,5";
else if (!strcmp (key, "EplTonerSave"))
val = "off, on";
else if (!strcmp (key, "EplPaperType"))
val = "0,1,2,3";
else if (!strcmp (key, "EplCopies"))
val = "1,2,3,4,5,6";
if (val == NULL)
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_EUNKPARAM\n");
#endif
return IJS_EUNKPARAM;
}
else
{
int size = strlen (val);
if (size > val_size)
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_EBUF\n");
#endif
return IJS_EBUF;
}
memcpy (val_buf, val, size);
return size;
}
}
/* A C implementation of /^(\d\.+\-eE)+x(\d\.+\-eE)+$/ */
static int
epson_epl_parse_wxh (const char *val, int size,
double *pw, double *ph)
{
char buf[256];
char *tail;
int i;
for (i = 0; i < size; i++)
if (val[i] == 'x')
break;
if (i + 1 >= size)
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_ESYNTAX\n");
#endif
return IJS_ESYNTAX;
}
if (i >= sizeof(buf))
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_EBUF\n");
#endif
return IJS_EBUF;
}
memcpy (buf, val, i);
buf[i] = 0;
*pw = strtod (buf, &tail);
if (tail == buf)
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_ESYNTAX\n");
#endif
return IJS_ESYNTAX;
}
if (size - i > sizeof(buf))
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_EBUF\n");
#endif
return IJS_EBUF;
}
memcpy (buf, val + i + 1, size - i - 1);
buf[size - i - 1] = 0;
*ph = strtod (buf, &tail);
if (tail == buf)
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_ESYNTAX\n");
#endif
return IJS_ESYNTAX;
}
return 0;
}
/**
* epson_epl_find_key: Search parameter list for key.
*
* @key: key to look up
*
* Return value: Epson_EPL_ParamList entry matching @key, or NULL.
**/
static Epson_EPL_ParamList *
epson_epl_find_key (Epson_EPL_ParamList *pl, const char *key)
{
Epson_EPL_ParamList *curs;
for (curs = pl; curs != NULL; curs = curs->next)
{
if (!strcmp (curs->key, key))
return curs;
}
return NULL;
}
static int
set_param (Epson_EPL_ParamList **ppl, const char *key, const char *value, int value_size)
{
int key_len = strlen (key);
Epson_EPL_ParamList *pl;
#ifdef EPL_DEBUG
fprintf(stderr," set_param: %s=",key);
fwrite (value, 1, value_size, stderr);
fputs ("\n", stderr);
#endif
pl = epson_epl_find_key (*ppl, key);
if (pl == NULL)
{
pl = (Epson_EPL_ParamList *)malloc (sizeof (Epson_EPL_ParamList));
pl->next = *ppl;
pl->key = malloc (key_len + 1);
memcpy (pl->key, key, key_len + 1);
*ppl = pl;
}
else
{
free (pl->value);
}
pl->value = malloc (value_size);
memcpy (pl->value, value, value_size);
pl->value_size = value_size;
return 0;
}
/**
* @printable: An array in which to store the printable area.
*
* On return, @printable = PrintableArea[0:1] + TopLeft[0:1]
**/
static int
epson_epl_compute_printable (Epson_EPL_ParamList *pl, double printable[4])
{
Epson_EPL_ParamList *curs;
double width, height;
int code;
double margin = 0.167; /* The unprintable margin */
curs = epson_epl_find_key (pl, "PaperSize");
if (curs == NULL)
return -1;
code = epson_epl_parse_wxh (curs->value, curs->value_size, &width, &height);
if (code == 0)
{
/* We impose symmetric margins */
printable[0] = width - 2 * margin;
printable[1] = height - 2 * margin;
printable[2] = margin;
printable[3] = margin;
}
return code;
}
/*
static int
epson_epl_compute_offset (Epson_EPL_ParamList *pl, IjsPageHeader *ph,
double *px0, double *py0)
{
Epson_EPL_ParamList *curs;
double width, height;
double top, left;
int code;
*px0 = 0;
*py0 = 0;
curs = epson_epl_find_key (pl, "PaperSize");
if (curs == NULL)
return -1;
code = epson_epl_parse_wxh (curs->value, curs->value_size, &width, &height);
if (code == 0)
{
curs = epson_epl_find_key (pl, "TopLeft");
if (curs != NULL)
{
code = epson_epl_parse_wxh (curs->value, curs->value_size,
&top, &left);
}
else
{
double printable[4];
code = epson_epl_compute_printable (pl, printable);
if (code == 0)
{
top = printable[2];
left = printable[3];
}
}
}
if (code == 0)
{
*px0 = left;
*py0 = height - ph->height / ph->yres - top;
}
return code;
}
*/
static int
epson_epl_get_cb (void *get_cb_data,
IjsServerCtx *ctx,
IjsJobId job_id,
const char *key,
char *val_buf,
int val_size)
{
Epson_EPL_ParamList *pl = *(Epson_EPL_ParamList **)get_cb_data;
Epson_EPL_ParamList *curs;
const char *val = NULL;
char buf[256];
int code;
#ifdef EPL_DEBUG
fprintf (stderr, "epson_epl_get_cb: %s\n", key);
#endif
curs = epson_epl_find_key (pl, key);
if (curs != NULL)
{
if (curs->value_size > val_size)
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_EBUF\n");
#endif
return IJS_EBUF;
}
memcpy (val_buf, curs->value, curs->value_size);
return curs->value_size;
}
if (!strcmp (key, "PrintableArea") || !strcmp (key, "PrintableTopLeft"))
{
double printable[4];
int off = !strcmp (key, "PrintableArea") ? 0 : 2;
code = epson_epl_compute_printable (pl, printable);
if (code == 0)
{
sprintf (buf, "%gx%g", printable[off + 0], printable[off + 1]);
val = buf;
}
}
if (!strcmp (key, "DeviceManufacturer"))
val = "Epson";
else if (!strcmp (key, "DeviceModel"))
val = "undefined"; /* this *has* to be set from the client */
else if (!strcmp (key, "PageImageFormat"))
val = "Raster";
else if (!strcmp (key, "Dpi"))
val = "600x600";
if (val == NULL)
{
#ifdef EPL_DEBUG
fprintf (stderr, "epson_epl_get_cb: Failed key %s\n", key);
#endif
return IJS_EUNKPARAM;
}
else
{
int size = strlen (val);
#ifdef EPL_DEBUG
fprintf (stderr, "epson_epl_get_cb: Success key = %s, val = %s\n",
key,
val);
#endif
if (size > val_size)
{
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_EBUF\n");
#endif
return IJS_EBUF;
}
memcpy (val_buf, val, size);
return size;
}
}
static int
epson_epl_set_cb (void *set_cb_data, IjsServerCtx *ctx, IjsJobId job_id,
const char *key, const char *value, int value_size)
{
Epson_EPL_ParamList **ppl = (Epson_EPL_ParamList **)set_cb_data;
int code;
char buf[256];
#ifdef EPL_DEBUG
fprintf (stderr, "epson_epl_set_cb: key:'%s',value:'", key);
fwrite (value, 1, value_size, stderr);
fputs ("'\n", stderr);
#endif
/* Convert value to a zero-terminated string */
if( value_size >= sizeof(buf)){
#ifdef EPL_DEBUG
fprintf (stderr, "IJS_EBUF\n");
return IJS_EBUF;
#endif
}
memcpy (buf, value, value_size);
buf[value_size] = 0;
/* Handle side effects of parameters */
if (!strcmp (key, "PaperSize"))
{
/* Setting PaperSize affects PrintableArea, which is used by ghostscript */
double width, height;
code = epson_epl_parse_wxh (value, value_size, &width, &height);
if (code < 0)
return code;
}
if (!strcmp (key, "EplDpi"))
{
/* Setting EplDpi affects Dpi, which is used by ghostscript */
char *s;
if(!strcmp (buf, "300"))
{
s = "300x300";
}
else if(!strcmp (buf, "Class600"))
{
s = "600x300";
}
else if(!strcmp (buf, "600"))
{
s = "600x600";
}
else if(!strcmp (buf, "Class1200"))
{
s = "1200x600";
}
else
{
return IJS_ERANGE;
}
code = set_param (ppl, "Dpi", s, strlen (s));
if (code < 0)
return code; /* because we can't go on setting EplDpi */
}
if (!strcmp (key, "PrintableArea"))
{
/* This can't be set */
fprintf (stderr, "Setting %s is not allowed\n", key);
return IJS_ERANGE;
}
if (!strcmp (key, "PrintableTopLeft"))
{
/* This can't be set */
fprintf (stderr, "Setting %s is not allowed\n", key);
return IJS_ERANGE;
}
/* Update parameter list */
code = set_param (ppl, key, value, value_size);
if (code < 0)
return code;
return 0;
}
/**
* Finds a parameter in the param list, and allocates a null terminated
* string with the value.
**/
static char *
find_param (Epson_EPL_ParamList *pl, const char *key)
{
Epson_EPL_ParamList *curs;
char *result;
curs = epson_epl_find_key (pl, key);
if (curs == NULL)
return NULL;
result = malloc (curs->value_size + 1);
memcpy (result, curs->value, curs->value_size);
result[curs->value_size] = 0;
return result;
}
static void
free_param_list (Epson_EPL_ParamList *pl)
{
Epson_EPL_ParamList *next;
for (; pl != NULL; pl = next)
{
next = pl->next;
free (pl->key);
free (pl->value);
free (pl);
}
}
static int
pl_to_epljobinfo (Epson_EPL_ParamList *pl, IjsPageHeader ph, EPL_job_info *epl_job_info)
{
char *fn;
char *s;
/* Check options */
#ifdef EPL_DEBUG
fprintf(stderr, "settings:\n");
#endif
if (epl_job_info->outfile == NULL)
{
fn = find_param (pl, "OutputFile");
/* todo: check error! */
if (fn == NULL)
{
fn = find_param (pl, "OutputFD");
if (fn != NULL)
{
epl_job_info->outfile = fdopen (atoi (fn), "wb");
}
}
else
{
epl_job_info->outfile = fopen (fn, "wb");
}
if (epl_job_info->outfile == NULL)
{
fprintf (stderr, "can't open output file %s\n", fn);
fclose (stdin);
fclose (stdout);
return 1;
}
if (fn != NULL)
free (fn);
}
/* DeviceModel */
s = find_param(pl, "DeviceModel");
if (s == NULL)
{
fprintf(stderr, "Printer DeviceModel not set, aborting!\n");
return 1;
}
if (strcmp(s, "EPL5700L") == 0)
{
epl_job_info->model = MODEL_5700L ;
}
else if (strcmp(s, "EPL5800L") == 0)
{
epl_job_info->model = MODEL_5800L ;
}
else if (strcmp(s, "EPL5900L") == 0)
{
epl_job_info->model = MODEL_5900L ;
}
else if (strcmp(s, "EPL6100L") == 0)
{
epl_job_info->model = MODEL_6100L ;
}
else if (strcmp(s, "EPL6200L") == 0)
{
epl_job_info->model = MODEL_6200L ;
}
else
{
fprintf(stderr, "Unknown Printer %s, aborting!\n", s);
return 1;
}
#ifdef EPL_DEBUG
fprintf(stderr, " Using protocol for %s\n",printername[epl_job_info->model]);
#endif
/* PaperSize */
s = find_param(pl, "PaperSize");
if (s == NULL)
{
fprintf(stderr, "PaperSize not set, using default (A4 210x297mm)\n");
epl_job_info->paper_size_mm_h = 210;
epl_job_info->paper_size_mm_v = 297;
}
else
{
double width, height;
int code;
code = epson_epl_parse_wxh (s, strlen(s), &width, &height);
if (code == 0)
{
epl_job_info->paper_size_mm_h = (int)(width * 25.4 + 0.5);
epl_job_info->paper_size_mm_v = (int)(height * 25.4 + 0.5);
}
else
{
fprintf(stderr, "Unparsable PaperSize %s, aborting!\n", s);
return 1;
}
#ifdef EPL_DEBUG
fprintf(stderr, " Papersize is %s inches\n", s);
#endif
}
/* EplDpi */
s = find_param(pl, "EplDpi");
if (s == NULL)
{
fprintf(stderr, "EplDpi not set, using default (600)\n");
epl_job_info->dpi_h = 600;
epl_job_info->dpi_v = 600;
}
else if (strcmp(s, "300") == 0)
{
epl_job_info->dpi_h = 300;
epl_job_info->dpi_v = 300;
}
else if (strcmp(s, "Class600") == 0)
{
epl_job_info->dpi_h = 600;
epl_job_info->dpi_v = 300;
}
else if (strcmp(s, "600") == 0)
{
epl_job_info->dpi_h = 600;
epl_job_info->dpi_v = 600;
}
else if (strcmp(s, "Class1200") == 0)
{
epl_job_info->dpi_h = 1200;
epl_job_info->dpi_v = 600;
}
else
{
fprintf(stderr, "Unknown EplDpi value %s, aborting!\n", s);
return 1;
}
#ifdef EPL_DEBUG
fprintf(stderr, " Printing at DPI %s\n", s);
#endif
/* EplRitech */
s = find_param(pl, "EplRitech");
if (s == NULL)
{
fprintf(stderr, "EplRitech not set, using default (on)\n");
epl_job_info->ritech = 1;
}
else if (strcmp(s, "on") == 0)
{
epl_job_info->ritech = 1;
}
else if (strcmp(s, "off") == 0)
{
epl_job_info->ritech = 0;
}
else
{
fprintf(stderr, "Unknown EplRitech value %s, aborting!\n", s);
return 1;
}
#ifdef EPL_DEBUG
fprintf(stderr, " Ritech is %s\n", s);
#endif
/* EplDensity */
s = find_param(pl, "EplDensity");
if (s == NULL)
{
fprintf(stderr, "EplDensity not set, using default (3)\n");
epl_job_info->density = 3;
}
else if (strcmp(s, "1") == 0)
{
epl_job_info->density = 1;
}
else if (strcmp(s, "2") == 0)
{
epl_job_info->density = 2;
}
else if (strcmp(s, "3") == 0)
{
epl_job_info->density = 3;
}
else if (strcmp(s, "4") == 0)
{
epl_job_info->density = 4;
}
else if (strcmp(s, "5") == 0)
{
epl_job_info->density = 5;
}
else
{
fprintf(stderr, "Unknown EplDensity value %s, aborting!\n", s);
return 1;
}
#ifdef EPL_DEBUG
fprintf(stderr, " Density is %s\n", s);
#endif
/* EplTonerSave */
s = find_param(pl, "EplTonerSave");
if (s == NULL)
{
fprintf(stderr, "EplTonerSave not set, using default (off)\n");
epl_job_info->toner_save = 0;
}
else if (strcmp(s, "on") == 0)
{
epl_job_info->toner_save = 1;
}
else if (strcmp(s, "off") == 0)
{
epl_job_info->toner_save = 0;
}
else
{
fprintf(stderr, "Unknown EplTonerSave value %s, aborting!\n", s);
return 1;
}
#ifdef EPL_DEBUG
fprintf(stderr, " TonerSave is %s\n", s);
#endif
/* EplPaperType */
s = find_param(pl, "EplPaperType");
if (s == NULL)
{
fprintf(stderr, "EplPaperType not set, using default Normal (0)\n");
epl_job_info->papertype = 0;
}
else if ((strcmp(s, "0") == 0) || (strcmp(s, "Normal") == 0))
{
epl_job_info->papertype = 0;
}
else if ((strcmp(s, "1") == 0) || (strcmp(s, "Thick") == 0))
{
epl_job_info->papertype = 1;
}
else if ((strcmp(s, "2") == 0) || (strcmp(s, "Thicker") == 0))
{
epl_job_info->papertype = 2;
}
else if ((strcmp(s, "3") == 0) || (strcmp(s, "Transparency") == 0))
{
epl_job_info->papertype = 3;
}
else
{
fprintf(stderr, "Unknown EplPaperType value %s, aborting!\n", s);
return 1;
}
#ifdef EPL_DEBUG
fprintf(stderr, " PaperType is %s\n", s);
#endif
/* EplCopies */
s = find_param(pl, "EplCopies");
if (s == NULL)
{
fprintf(stderr, "EplCopies not set, using default (1)\n");
epl_job_info->copies = 1;
}
else
{
epl_job_info->copies = atoi(s);
if(!epl_job_info->copies)
{
fprintf(stderr, "Unknown EplCopies value %s, aborting!\n", s);
return 1;
}
else
{
fprintf(stderr, "Printing %d copies\n", epl_job_info->copies);
}
}
/* Number of channels */
if ((ph.n_chan != 1) && (ph.n_chan != 3))
{
fprintf(stderr, "Number of channels is %i (unsupported), aborting!\n",
ph.n_chan);
return 1;
}
/* Bits per sample */
if ((ph.bps != 1) && (ph.bps != 8))
{
fprintf(stderr, "Bit per sample is %i (unsupported), aborting!\n",
ph.bps);
return 1;
}
/* BitMap Size */
epl_job_info->pixel_h = ph.width;
epl_job_info->pixel_v = ph.height;
fprintf(stderr, " Bitmap size %ix%i (%gx%g in)\n",
epl_job_info->pixel_h,
epl_job_info->pixel_v,
(double)epl_job_info->pixel_h / epl_job_info->dpi_h,
(double)epl_job_info->pixel_v / epl_job_info->dpi_v);
/* Dpi of the bitmap */
if (ph.xres != (double)epl_job_info->dpi_h
|| ph.yres != (double)epl_job_info->dpi_v)
{
fprintf(stderr, "Dpi of bitmap (%gx%g) is different from selected dpi (%gx%g)",
ph.xres,
(double)epl_job_info->dpi_h,
ph.yres,
(double)epl_job_info->dpi_v);
return 1;
}
/* Flow Control */
s = find_param(pl, "EplFlowControl");
if (s == NULL)
{
epl_job_info->connectivity = VIA_STDOUT_PIPE;
}
else if (strcmp(s, "off") == 0)
{
epl_job_info->connectivity = VIA_STDOUT_PIPE;
}
else if (strcmp(s, "nowhere") == 0)
{
epl_job_info->connectivity = VIA_NOWHERE;
}
#ifdef HAVE_LIBUSB
else if (strcmp(s, "libusb") == 0)
{
fprintf(stderr, "Using libusb\n");
epl_job_info->connectivity = VIA_LIBUSB;
}
#endif
#ifdef HAVE_LIBIEEE1284
else if (strcmp(s, "libieee1284") == 0)
{
fprintf(stderr, "Using libieee1284\n");
epl_job_info->connectivity = VIA_LIBIEEE1284;
}
#endif
#ifdef HAVE_KERNEL_USB_DEVICE
/* We catch both /dev/usb/lp[0-9] and /dev/usblp[0-9] */
else if (strncmp(s, "/dev/usb",8) == 0)
{
fprintf(stderr, "Using kernel usb device\n");
if (epl_job_info->connectivity != VIA_KERNEL_USB)
{
epl_job_info->connectivity = VIA_KERNEL_USB;
epl_job_info->kernel_fd = open(s, O_RDWR |O_SYNC);
if (epl_job_info->kernel_fd < 0)
{
fprintf(stderr, "Can't open device %s, aborting!\n", s);
perror("Kernel device");
return 1;
}
}
}
#endif
#ifdef HAVE_KERNEL_1284
/* We catch /dev/lp[0-9] */
else if (strncmp(s, "/dev/lp",7) == 0)
{
fprintf(stderr, "Using kernel parallel port device\n");
if (epl_job_info->connectivity != VIA_KERNEL_1284)
{
epl_job_info->connectivity = VIA_KERNEL_1284;
epl_job_info->kernel_fd = open(s, O_RDWR |O_SYNC);
if (epl_job_info->kernel_fd < 0)
{
fprintf(stderr, "Can't open device %s, aborting!\n", s);
perror("Kernel device");
return 1;
}
}
}
#endif
else
{
fprintf(stderr, "Unknown FlowControl option %s, aborting!\n", s);
return 1;
}
/* If we get here, all it's OK */
return 0;
}
static void
epljobinfo_cleanup (EPL_job_info *epl_job_info)
{
if (epl_job_info->outfile)
fclose (epl_job_info->outfile);
}
int
main (int argc, char **argv)
{
IjsServerCtx *ctx;
IjsPageHeader ph;
int status;
Epson_EPL_ParamList *pl = NULL;
EPL_job_info *epl_job_info = NULL;
int epl_job_started = EPL_JOB_STARTED_NO;
int current_page_number = 1;
if (argc > 1) /* the IJS plugin is being run stand-alone */
{
/* we'll try to get status if the plugin is being run stand-alone */
epl_status(argc, argv);
exit(0);
}
ctx = ijs_server_init ();
if (ctx == NULL)
return (1);
ijs_server_install_status_cb (ctx, epson_epl_status_cb, &pl);
ijs_server_install_list_cb (ctx, epson_epl_list_cb, &pl);
ijs_server_install_enum_cb (ctx, epson_epl_enum_cb, &pl);
ijs_server_install_set_cb (ctx, epson_epl_set_cb, &pl);
ijs_server_install_get_cb (ctx, epson_epl_get_cb, &pl);
#ifdef EPL_DEBUG
fprintf(stderr, "Try to allocate %lu byte of memory for job info\n",sizeof(EPL_job_info));
#endif
epl_job_info = (EPL_job_info *)calloc(1, sizeof(EPL_job_info));
if (epl_job_info == NULL) {
#ifdef EPL_DEBUG
fprintf(stderr, "Job info memory allocation failed\n");
#endif
exit(1);
}
/* The file handle has a danger of being used before initialized */
epl_job_info->connectivity = PRE_INIT;
epl_job_info->outfile = NULL;
do
{
int total_bytes, bytes_left;
Epson_EPL_ParamList *curs;