forked from cmatsuoka/figlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
figlet.c
2203 lines (1857 loc) · 55.9 KB
/
figlet.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
/****************************************************************************
FIGlet Copyright 1991, 1993, 1994 Glenn Chappell and Ian Chai
FIGlet Copyright 1996, 1997, 1998, 1999, 2000, 2001 John Cowan
FIGlet Copyright 2002 Christiaan Keet
FIGlet Copyright 2011, 2012 Claudio Matsuoka
Portions written by Paul Burton and Christiaan Keet
Internet: <[email protected]>
FIGlet, along with the various FIGlet fonts and documentation, is
copyrighted under the provisions of the New BSD License (3-clause)
(as listed in the file "LICENSE" which is included in this package)
****************************************************************************/
#define DATE "31 May 2012"
#define VERSION "2.2.5"
#define VERSION_INT 20205
/* FIGlet (Frank, Ian & Glenn's Letters) */
/* by Glenn Chappell */
/* Apr 1991 */
/* Automatic file addition by Ian Chai May 1991 */
/* Punctuation and numbers addition by Ian Chai Jan 1993 */
/* Full ASCII by Glenn Chappell Feb 1993 */
/* Line-breaking, general rewrite by Glenn Chappell Mar 1993 */
/* Hard blanks by Glenn Chappell Apr 1993 */
/* Release 2.0 5 Aug 1993 */
/* Right-to-left printing, extended char set by Glenn Chappell Dec 1993 */
/* Control files by Glenn Chappell Feb 1994 */
/* Release 2.1 12 Aug 1994 */
/* Release 2.1.1 25 Aug 1994 */
/* Release 2.1.2 by Gilbert (Mad Programmer) Healton: Add -A command line
option. Sept 8, 1996 */
/* Release 2.2 by John Cowan: multibyte inputs, compressed fonts,
mapping tables, kerning/smushing options. */
/* Release 2.2.1 by Christiaan Keet: minor updates including readmes
FAQs and comments. 13 July 2002. The new official FIGlet website is
http://www.figlet.org/ */
/* Release 2.2.2 by Christiaan Keet: License changed from "Artistic License"
to "Academic Free License" as agreed by FIGlet authors. 05 July 2005 */
/* Release 2.2.3 by Claudio Matsuoka, 12 Jan 2011: BSD license, fixes */
/* Release 2.2.4 by Claudio Matsuoka, 26 Jan 2011: tlf2 font support */
/* Release 2.2.5 by Claudio Matsuoka, 31 May 2012: flc licensing, minor fixes */
/*---------------------------------------------------------------------------
DEFAULTFONTDIR and DEFAULTFONTFILE should be defined in the Makefile.
DEFAULTFONTDIR is the full path name of the directory in which FIGlet
will search first for fonts (the ".flf" files).
DEFAULTFONTFILE is the filename of the font to be used if no other
is specified (standard.flf is recommended, but any other can be
used). This file should reside in the directory specified by
DEFAULTFONTDIR.
---------------------------------------------------------------------------*/
#ifndef DEFAULTFONTDIR
#define DEFAULTFONTDIR "fonts"
#endif
#ifndef DEFAULTFONTFILE
#define DEFAULTFONTFILE "standard.flf"
#endif
#include <stdio.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h> /* Needed for get_columns */
#if defined(unix) || defined(__unix__) || defined(__APPLE__)
#include <unistd.h>
#include <sys/ioctl.h> /* Needed for get_columns */
#endif
#ifdef TLF_FONTS
#include <wchar.h>
#include <wctype.h>
#include "utf8.h"
#endif
#include "zipio.h" /* Package for reading compressed files */
#define MYSTRLEN(x) ((int)strlen(x)) /* Eliminate ANSI problem */
#define DIRSEP '/'
#define DIRSEP2 '\\'
/* Leave alone for Unix and MS-DOS/Windows!
Note: '/' also used in filename in get_columns(). */
#define FONTFILESUFFIX ".flf"
#define FONTFILEMAGICNUMBER "flf2"
#define FSUFFIXLEN MYSTRLEN(FONTFILESUFFIX)
#define CONTROLFILESUFFIX ".flc"
#define CONTROLFILEMAGICNUMBER "flc2" /* no longer used in 2.2 */
#define CSUFFIXLEN MYSTRLEN(CONTROLFILESUFFIX)
#define DEFAULTCOLUMNS (code_comments ? 140 : 80)
#define MAXLEN 255 /* Maximum character width */
/* Add support for Sam Hocevar's TOIlet fonts */
#ifdef TLF_FONTS
#define TOILETFILESUFFIX ".tlf"
#define TOILETFILEMAGICNUMBER "tlf2"
#define TSUFFIXLEN MYSTRLEN(TOILETFILESUFFIX)
int toiletfont; /* true if font is a TOIlet TLF font */
#endif
/****************************************************************************
Globals dealing with chars that are read
****************************************************************************/
typedef long inchr; /* "char" read from stdin */
inchr *inchrline; /* Alloc'd inchr inchrline[inchrlinelenlimit+1]; */
/* Note: not null-terminated. */
int inchrlinelen,inchrlinelenlimit;
inchr deutsch[7] = {196, 214, 220, 228, 246, 252, 223};
/* Latin-1 codes for German letters, respectively:
LATIN CAPITAL LETTER A WITH DIAERESIS = A-umlaut
LATIN CAPITAL LETTER O WITH DIAERESIS = O-umlaut
LATIN CAPITAL LETTER U WITH DIAERESIS = U-umlaut
LATIN SMALL LETTER A WITH DIAERESIS = a-umlaut
LATIN SMALL LETTER O WITH DIAERESIS = o-umlaut
LATIN SMALL LETTER U WITH DIAERESIS = u-umlaut
LATIN SMALL LETTER SHARP S = ess-zed
*/
int hzmode; /* true if reading double-bytes in HZ mode */
int gndbl[4]; /* gndbl[n] is true if Gn is double-byte */
inchr gn[4]; /* Gn character sets: ASCII, Latin-1, none, none */
int gl; /* 0-3 specifies left-half Gn character set */
int gr; /* 0-3 specifies right-half Gn character set */
const char* code_comments = NULL; /* Generate C/C++/Java code comments */
int Myargc; /* to avoid passing around argc and argv */
char **Myargv;
int cpp_code_comments() {
return code_comments && !strcmp(code_comments, "cpp");
}
int python_code_comments() {
return code_comments && !strcmp(code_comments, "python");
}
/****************************************************************************
Globals dealing with chars that are written
****************************************************************************/
#ifdef TLF_FONTS
typedef wchar_t outchr; /* "char" written to stdout */
#define STRLEN(x) wcslen(x)
#define STRCPY(x,y) wcscpy((x),(y))
#define STRCAT(x,y) wcscat((x),(y))
#define ISSPACE(x) iswspace(x)
#else
typedef char outchr; /* "char" written to stdout */
#define STRLEN(x) MYSTRLEN(x)
#define STRCPY(x,y) strcpy((x),(y))
#define STRCAT(x,y) strcat((x),(y))
#define ISSPACE(x) isspace(x)
#endif
typedef struct fc {
inchr ord;
outchr **thechar; /* Alloc'd char thechar[charheight][]; */
struct fc *next;
} fcharnode;
fcharnode *fcharlist;
outchr **currchar;
int currcharwidth;
int previouscharwidth;
outchr **outputline; /* Alloc'd char outputline[charheight][outlinelenlimit+1]; */
int outlinelen;
/****************************************************************************
Globals dealing with command file storage
****************************************************************************/
typedef struct cfn {
char *thename;
struct cfn *next;
} cfnamenode;
cfnamenode *cfilelist,**cfilelistend;
typedef struct cm {
int thecommand;
inchr rangelo;
inchr rangehi;
inchr offset;
struct cm *next;
} comnode;
comnode *commandlist,**commandlistend;
/****************************************************************************
Globals affected by command line options
****************************************************************************/
int deutschflag,justification,paragraphflag,right2left,multibyte;
int cmdinput;
#define SM_SMUSH 128
#define SM_KERN 64
#define SM_EQUAL 1
#define SM_LOWLINE 2
#define SM_HIERARCHY 4
#define SM_PAIR 8
#define SM_BIGX 16
#define SM_HARDBLANK 32
int smushmode;
#define SMO_NO 0 /* no command-line smushmode */
#define SMO_YES 1 /* use command-line smushmode, ignore font smushmode */
#define SMO_FORCE 2 /* logically OR command-line and font smushmodes */
int smushoverride;
int outputwidth;
int outlinelenlimit;
char *fontdirname,*fontname;
/****************************************************************************
Globals read from font file
****************************************************************************/
char hardblank;
int charheight;
/****************************************************************************
Name of program, used in error messages
****************************************************************************/
char *myname;
#ifdef TIOCGWINSZ
/****************************************************************************
get_columns
Determines the number of columns of /dev/tty. Returns the number of
columns, or -1 if error. May return 0 if columns unknown.
Requires include files <fcntl.h> and <sys/ioctl.h>.
by Glenn Chappell & Ian Chai 14 Apr 1993
****************************************************************************/
int get_columns()
{
if(!code_comments) {
struct winsize ws;
int fd,result;
if ((fd = open("/dev/tty",O_WRONLY))<0) return -1;
result = ioctl(fd,TIOCGWINSZ,&ws);
close(fd);
return result?-1:ws.ws_col;
} else {
return 0;
}
}
#endif /* ifdef TIOCGWINSZ */
/****************************************************************************
myalloc
Calls malloc. If malloc returns error, prints error message and
quits.
****************************************************************************/
#ifdef __STDC__
char *myalloc(size_t size)
#else
char *myalloc(size)
int size;
#endif
{
char *ptr;
#ifndef __STDC__
extern void *malloc();
#endif
if ((ptr = (char*)malloc(size))==NULL) {
fprintf(stderr,"%s: Out of memory\n",myname);
exit(1);
}
else {
return ptr;
}
}
/****************************************************************************
hasdirsep
Returns true if s1 contains a DIRSEP or DIRSEP2 character.
****************************************************************************/
int hasdirsep(s1)
char *s1;
{
if (strchr(s1, DIRSEP)) return 1;
else if (strchr(s1, DIRSEP2)) return 1;
else return 0;
}
/****************************************************************************
suffixcmp
Returns true if s2 is a suffix of s1; uses case-blind comparison.
****************************************************************************/
int suffixcmp(s1, s2)
char *s1;
char *s2;
{
int len1, len2;
len1 = MYSTRLEN(s1);
len2 = MYSTRLEN(s2);
if (len2 > len1) return 0;
s1 += len1 - len2;
while (*s1) {
if (tolower(*s1) != tolower(*s2)) return 0;
s1++;
s2++;
}
return 1;
}
/****************************************************************************
skiptoeol
Skips to the end of a line, given a stream. Handles \r, \n, or \r\n.
****************************************************************************/
void skiptoeol(fp)
ZFILE *fp;
{
int dummy;
while (dummy=Zgetc(fp),dummy!=EOF) {
if (dummy == '\n') return;
if (dummy == '\r') {
dummy = Zgetc(fp);
if (dummy != EOF && dummy != '\n') Zungetc(dummy,fp);
return;
}
}
}
/****************************************************************************
myfgets
Local version of fgets. Handles \r, \n, and \r\n terminators.
****************************************************************************/
char *myfgets(line,maxlen,fp)
char *line;
int maxlen;
ZFILE *fp;
{
int c = 0;
char *p;
p = line;
while((c=Zgetc(fp))!=EOF&&maxlen) {
*p++ = c;
maxlen--;
if (c=='\n') break;
if (c=='\r') {
c = Zgetc(fp);
if (c != EOF && c != '\n') Zungetc(c,fp);
*(p-1) = '\n';
break;
}
}
*p = 0;
return (c==EOF) ? NULL : line;
}
/****************************************************************************
usageerr
Prints "Usage: ...." line to the given stream.
****************************************************************************/
void printusage(out)
FILE *out;
{
fprintf(out,
"Usage: %s [ -cklnoprstvxDELNRSWX ] [ -d fontdirectory ]\n",
myname);
fprintf(out,
" [ -f fontfile ] [ -m smushmode ] [ -w outputwidth ]\n");
fprintf(out,
" [ -C controlfile ] [ -I infocode ] [ message ]\n");
}
/****************************************************************************
printinfo
Prints version and copyright message, or utility information.
****************************************************************************/
void printinfo(infonum)
int infonum;
{
switch (infonum) {
case 0: /* Copyright message */
printf("FIGlet Copyright (C) 1991-2012 Glenn Chappell, Ian Chai, ");
printf("John Cowan,\nChristiaan Keet and Claudio Matsuoka\n");
printf("Internet: <[email protected]> ");
printf("Version: %s, date: %s\n\n",VERSION,DATE);
printf("FIGlet, along with the various FIGlet fonts");
printf(" and documentation, may be\n");
printf("freely copied and distributed.\n\n");
printf("If you use FIGlet, please send an");
printf(" e-mail message to <[email protected]>.\n\n");
printf("The latest version of FIGlet is available from the");
printf(" web site,\n\thttp://www.figlet.org/\n\n");
printusage(stdout);
break;
case 1: /* Version (integer) */
printf("%d\n",VERSION_INT);
break;
case 2: /* Font directory */
printf("%s\n",fontdirname);
break;
case 3: /* Font */
printf("%s\n",fontname);
break;
case 4: /* Outputwidth */
printf("%d\n",outputwidth);
break;
case 5: /* Font formats */
printf("%s", FONTFILEMAGICNUMBER);
#ifdef TLF_FONTS
printf(" %s", TOILETFILEMAGICNUMBER);
#endif
printf("\n");
}
}
/****************************************************************************
readmagic
Reads a four-character magic string from a stream.
****************************************************************************/
void readmagic(fp,magic)
ZFILE *fp;
char *magic;
{
int i;
for (i=0;i<4;i++) {
magic[i] = Zgetc(fp);
}
magic[4] = 0;
}
/****************************************************************************
skipws
Skips whitespace characters from a stream.
****************************************************************************/
void skipws(fp)
ZFILE *fp;
{
int c;
while (c=Zgetc(fp),isascii(c)&&isspace(c)) ;
Zungetc(c,fp);
}
/****************************************************************************
readnum
Reads a number from a stream. Accepts "0" prefix for octal and
"0x" or "0X" for hexadecimal. Ignores leading whitespace.
****************************************************************************/
void readnum(fp,nump)
ZFILE *fp;
inchr *nump;
{
int acc = 0;
char *p;
int c;
int base;
int sign = 1;
char digits[] = "0123456789ABCDEF";
skipws(fp);
c = Zgetc(fp);
if (c=='-') {
sign = -1;
}
else {
Zungetc(c,fp);
}
c = Zgetc(fp);
if (c=='0') {
c = Zgetc(fp);
if (c=='x'||c=='X') {
base = 16;
}
else {
base = 8;
Zungetc(c,fp);
}
}
else {
base = 10;
Zungetc(c,fp);
}
while((c=Zgetc(fp))!=EOF) {
c=toupper(c);
p=strchr(digits,c);
if (!p) {
Zungetc(c,fp);
*nump = acc * sign;
return;
}
acc = acc*base+(p-digits);
}
*nump = acc * sign;
}
/****************************************************************************
readTchar
Reads a control file "T" command character specification.
Character is a single byte, an escape sequence, or
an escaped numeric.
****************************************************************************/
inchr readTchar(fp)
ZFILE *fp;
{
inchr thechar;
char next;
thechar=Zgetc(fp);
if (thechar=='\n' || thechar=='\r') { /* Handle badly-formatted file */
Zungetc(thechar,fp);
return '\0';
}
if (thechar!='\\') return thechar;
next=Zgetc(fp);
switch(next) {
case 'a':
return 7;
case 'b':
return 8;
case 'e':
return 27;
case 'f':
return 12;
case 'n':
return 10;
case 'r':
return 13;
case 't':
return 9;
case 'v':
return 11;
default:
if (next=='-' || next=='x' || (next>='0' && next<='9')) {
Zungetc(next,fp);
readnum(fp,&thechar);
return thechar;
}
return next;
}
}
/****************************************************************************
charsetname
Get a Tchar representing a charset name, or 0 if none available.
Called in getcharset().
****************************************************************************/
inchr charsetname(fp)
ZFILE *fp;
{
inchr result;
result = readTchar(fp);
if (result == '\n' || result == '\r') {
result = 0;
Zungetc(result,fp);
}
return result;
}
/****************************************************************************
charset
Processes "g[0123]" character set specifier
Called in readcontrol().
****************************************************************************/
void charset(n, controlfile)
int n;
ZFILE *controlfile;
{
int ch;
skipws(controlfile);
if (Zgetc(controlfile) != '9') {
skiptoeol(controlfile);
return;
}
ch = Zgetc(controlfile);
if (ch == '6') {
gn[n] = 65536L * charsetname(controlfile) + 0x80;
gndbl[n] = 0;
skiptoeol(controlfile);
return;
}
if (ch != '4') {
skiptoeol(controlfile);
return;
}
ch = Zgetc(controlfile);
if (ch == 'x') {
if (Zgetc(controlfile) != '9') {
skiptoeol(controlfile);
return;
}
if (Zgetc(controlfile) != '4') {
skiptoeol(controlfile);
return;
}
skipws(controlfile);
gn[n] = 65536L * charsetname(controlfile);
gndbl[n] = 1;
skiptoeol(controlfile);
return;
}
Zungetc(ch, controlfile);
skipws(controlfile);
gn[n] = 65536L * charsetname(controlfile);
gndbl[n] = 0;
return;
}
/****************************************************************************
FIGopen
Given a FIGlet font or control file name and suffix, return the file
or NULL if not found
****************************************************************************/
ZFILE *FIGopen(name,suffix)
char *name;
char *suffix;
{
char *fontpath;
ZFILE *fontfile;
struct stat st;
int namelen;
namelen = MYSTRLEN(fontdirname);
fontpath = (char*)alloca(sizeof(char)*
(namelen+MYSTRLEN(name)+MYSTRLEN(suffix)+2));
fontfile = NULL;
if (!hasdirsep(name)) { /* not a full path name */
strcpy(fontpath,fontdirname);
fontpath[namelen] = DIRSEP;
fontpath[namelen+1] = '\0';
strcat(fontpath,name);
strcat(fontpath,suffix);
if(stat(fontpath,&st)==0) goto ok;
}
/* just append suffix */
strcpy(fontpath,name);
strcat(fontpath,suffix);
if(stat(fontpath,&st)==0) goto ok;
return NULL;
ok:
fontfile = Zopen(fontpath,"rb");
return fontfile;
}
/****************************************************************************
readcontrol
Allocates memory and reads in the given control file.
Called in readcontrolfiles().
****************************************************************************/
void readcontrol(controlname)
char *controlname;
{
inchr firstch,lastch;
char dashcheck;
inchr offset;
int command;
ZFILE *controlfile;
controlfile = FIGopen(controlname,CONTROLFILESUFFIX);
if (controlfile==NULL) {
fprintf(stderr,"%s: %s: Unable to open control file\n",myname,
controlname);
exit(1);
}
(*commandlistend) = (comnode*)myalloc(sizeof(comnode));
(*commandlistend)->thecommand = 0; /* Begin with a freeze command */
commandlistend = &(*commandlistend)->next;
(*commandlistend) = NULL;
while(command=Zgetc(controlfile),command!=EOF) {
switch (command) {
case 't': /* Translate */
skipws(controlfile);
firstch=readTchar(controlfile);
if ((dashcheck=Zgetc(controlfile))=='-') {
lastch=readTchar(controlfile);
}
else {
Zungetc(dashcheck,controlfile);
lastch=firstch;
}
skipws(controlfile);
offset=readTchar(controlfile)-firstch;
skiptoeol(controlfile);
(*commandlistend) = (comnode*)myalloc(sizeof(comnode));
(*commandlistend)->thecommand = 1;
(*commandlistend)->rangelo = firstch;
(*commandlistend)->rangehi = lastch;
(*commandlistend)->offset = offset;
commandlistend = &(*commandlistend)->next;
(*commandlistend) = NULL;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '-':
/* Mapping table entry */
Zungetc(command,controlfile);
readnum(controlfile,&firstch);
skipws(controlfile);
readnum(controlfile,&lastch);
offset=lastch-firstch;
lastch=firstch;
skiptoeol(controlfile);
(*commandlistend) = (comnode*)myalloc(sizeof(comnode));
(*commandlistend)->thecommand = 1;
(*commandlistend)->rangelo = firstch;
(*commandlistend)->rangehi = lastch;
(*commandlistend)->offset = offset;
commandlistend = &(*commandlistend)->next;
(*commandlistend) = NULL;
break;
case 'f': /* freeze */
skiptoeol(controlfile);
(*commandlistend) = (comnode*)myalloc(sizeof(comnode));
(*commandlistend)->thecommand = 0;
commandlistend = &(*commandlistend)->next;
(*commandlistend) = NULL;
break;
case 'b': /* DBCS input mode */
multibyte = 1;
break;
case 'u': /* UTF-8 input mode */
multibyte = 2;
break;
case 'h': /* HZ input mode */
multibyte = 3;
break;
case 'j': /* Shift-JIS input mode */
multibyte = 4;
break;
case 'g': /* ISO 2022 character set choices */
multibyte = 0;
skipws(controlfile);
command=Zgetc(controlfile);
switch (command) {
case '0': /* define G0 charset */
charset(0, controlfile);
break;
case '1': /* set G1 charset */
charset(1, controlfile);
break;
case '2': /* set G2 charset */
charset(2, controlfile);
break;
case '3': /* set G3 charset */
charset(3, controlfile);
break;
case 'l': case 'L': /* define left half */
skipws(controlfile);
gl = Zgetc(controlfile) - '0';
skiptoeol(controlfile);
break;
case 'r': case 'R': /* define right half */
skipws(controlfile);
gr = Zgetc(controlfile) - '0';
skiptoeol(controlfile);
break;
default: /* meaningless "g" command */
skiptoeol(controlfile);
}
case '\r': case '\n': /* blank line */
break;
default: /* Includes '#' */
skiptoeol(controlfile);
}
}
Zclose(controlfile);
}
/****************************************************************************
readcontrolfiles
Reads in the controlfiles names in cfilelist. Uses readcontrol.
Called in main().
****************************************************************************/
void readcontrolfiles()
{
cfnamenode *cfnptr;
for (cfnptr=cfilelist;cfnptr!=NULL;cfnptr=cfnptr->next) {
readcontrol(cfnptr->thename);
}
}
/****************************************************************************
clearcfilelist
Clears the control file list. Assumes thename does not need freeing.
****************************************************************************/
void clearcfilelist()
{
cfnamenode *cfnptr1,*cfnptr2;
cfnptr1 = cfilelist;
while (cfnptr1 != NULL) {
cfnptr2 = cfnptr1->next;
free(cfnptr1);
cfnptr1 = cfnptr2;
}
cfilelist = NULL;
cfilelistend = &cfilelist;
}
/****************************************************************************
getparams
Handles all command-line parameters. Puts all parameters within
bounds.
****************************************************************************/
void getparams()
{
extern char *optarg;
extern int optind;
int c; /* "Should" be a char -- need int for "!= -1" test*/
int columns,infoprint;
char *controlname,*env;
if ((myname = strrchr(Myargv[0],DIRSEP))!=NULL) {
myname++;
}
else {
myname = Myargv[0];
}
fontdirname = DEFAULTFONTDIR;
env = getenv("FIGLET_FONTDIR");
if (env!=NULL) {
fontdirname = env;
}
fontname = DEFAULTFONTFILE;
cfilelist = NULL;
cfilelistend = &cfilelist;
commandlist = NULL;
commandlistend = &commandlist;
smushoverride = SMO_NO;
deutschflag = 0;
justification = -1;
right2left = -1;
paragraphflag = 0;
infoprint = -1;
cmdinput = 0;
outputwidth = DEFAULTCOLUMNS;
gn[1] = 0x80;
gr = 1;
while ((c = getopt(Myargc,Myargv,"ADEXLRI:xlcrpntj:vm:w:d:f:C:NFskSWo"))!= -1) {
/* Note: -F is not a legal option -- prints a special err message. */
switch (c) {
case 'j':
if (optarg && *optarg == '=') {
++optarg;
}
code_comments = optarg;
break;
case 'A':
cmdinput = 1;
break;
case 'D':
deutschflag = 1;
break;
case 'E':
deutschflag = 0;
break;
case 'X':
right2left = -1;
break;
case 'L':
right2left = 0;
break;
case 'R':
right2left = 1;
break;
case 'x':
justification = -1;
break;
case 'l':
justification = 0;
break;
case 'c':
justification = 1;
break;
case 'r':
justification = 2;
break;
case 'p':
paragraphflag = 1;
break;
case 'n':