00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "cawf.h"
00032 #include <ctype.h>
00033
00034
00035
00036
00037
00038
00039 _PROTOTYPE(static void nr_UL,(unsigned char *line, int brk));
00040 _PROTOTYPE(static void nr_Ub,(unsigned char *line, int brk));
00041 _PROTOTYPE(static void nr_Uc,(unsigned char *line, int brk));
00042 _PROTOTYPE(static void nr_Uf,(unsigned char *line, int brk));
00043 _PROTOTYPE(static void nr_Ur,(unsigned char *line, int brk));
00044 _PROTOTYPE(static void nr_ad,(unsigned char *line, int brk));
00045 _PROTOTYPE(static void nr_bp,(unsigned char *line, int brk));
00046 _PROTOTYPE(static void nr_br,(unsigned char *line, int brk));
00047 _PROTOTYPE(static void nr_ce,(unsigned char *line, int brk));
00048 _PROTOTYPE(static void nr_di,(unsigned char *line, int brk));
00049 _PROTOTYPE(static void nr_ds,(unsigned char *line, int brk));
00050 _PROTOTYPE(static void nr_fi,(unsigned char *line, int brk));
00051 _PROTOTYPE(static void nr_fl,(unsigned char *line, int brk));
00052 _PROTOTYPE(static void nr_ft,(unsigned char *line, int brk));
00053 _PROTOTYPE(static void nr_it,(unsigned char *line, int brk));
00054 _PROTOTYPE(static void nr_na,(unsigned char *line, int brk));
00055 _PROTOTYPE(static void nr_nf,(unsigned char *line, int brk));
00056 _PROTOTYPE(static void nr_ns,(unsigned char *line, int brk));
00057 _PROTOTYPE(static void nr_rm,(unsigned char *line, int brk));
00058 _PROTOTYPE(static void nr_rn,(unsigned char *line, int brk));
00059 _PROTOTYPE(static void nr_rr,(unsigned char *line, int brk));
00060 _PROTOTYPE(static void nr_rs,(unsigned char *line, int brk));
00061 _PROTOTYPE(static void nr_tm,(unsigned char *line, int brk));
00062 _PROTOTYPE(static void nr_tr,(unsigned char *line, int brk));
00063
00064 _PROTOTYPE(static void nr_nil,(unsigned char *line, int brk));
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 static struct nr_req {
00075 char *nm;
00076 void (*fun)();
00077 } NrReqt[] = {
00078 { "\\\"", nr_nil },
00079 { "^#", nr_UL },
00080 { "^=", nr_UL },
00081 { "^b", nr_Ub },
00082 { "^c", nr_Uc },
00083 { "^d", nr_nil },
00084 { "^e", nr_nil },
00085 { "^f", nr_Uf },
00086 { "^r", nr_Ur },
00087 { "^x", nr_nil },
00088 { "ad", nr_ad },
00089 { "bp", nr_bp },
00090 { "br", nr_br },
00091 { "ce", nr_ce },
00092 { "di", nr_di },
00093 { "ds", nr_ds },
00094 { "fi", nr_fi },
00095 { "fl", nr_fl },
00096 { "ft", nr_ft },
00097 { "hy", nr_nil },
00098 { "i0", nr_nil },
00099 { "it", nr_it },
00100 { "lg", nr_nil },
00101 { "li", nr_nil },
00102 { "na", nr_na },
00103 { "nf", nr_nf },
00104 { "ns", nr_ns },
00105 { "ps", nr_nil },
00106 { "rm", nr_rm },
00107 { "rn", nr_rn },
00108 { "rr", nr_rr },
00109 { "rs", nr_rs },
00110 { "tm", nr_tm },
00111 { "tr", nr_tr },
00112 { "vs", nr_nil },
00113 };
00114
00115
00116
00117
00118
00119 void
00120 Nreq(line, brk)
00121 unsigned char *line;
00122 int brk;
00123 {
00124 unsigned char c[3];
00125 int cmp, hi, low, mid;
00126
00127 c[0] = c[1] = c[2] = '\0';
00128 if ((c[0] = line[1]) != '\0')
00129 c[1] = line[2];
00130
00131 low = mid = 0;
00132 hi = sizeof(NrReqt) / sizeof(struct nr_req);
00133 while (low <= hi) {
00134 mid = (low + hi) / 2;
00135 if ((cmp = strcmp((char *)c, NrReqt[mid].nm)) < 0)
00136 hi = mid - 1;
00137 else if (cmp > 0)
00138 low = mid + 1;
00139 else {
00140 (void) (*NrReqt[mid].fun)(line, brk);
00141 return;
00142 }
00143 }
00144
00145
00146
00147 Error(WARN, LINE, " unknown request", NULL);
00148 }
00149
00150
00151
00152
00153
00154
00155 static void
00156 nr_ad(line, brk)
00157 unsigned char *line;
00158 int brk;
00159 {
00160 Pass3(NOBREAK, (unsigned char *)"both", NULL, 0);
00161 }
00162
00163
00164
00165
00166
00167
00168 static void
00169 nr_bp(line, brk)
00170 unsigned char *line;
00171 int brk;
00172 {
00173 Pass3(brk, (unsigned char *)"need", NULL, 999);
00174 }
00175
00176
00177
00178
00179
00180
00181 static void
00182 nr_br(line, brk)
00183 unsigned char *line;
00184 int brk;
00185 {
00186 Pass3(brk, (unsigned char *)"flush", NULL, 0);
00187 }
00188
00189
00190
00191
00192
00193
00194 static void
00195 nr_ce(line, brk)
00196 unsigned char *line;
00197 int brk;
00198 {
00199 unsigned char *s;
00200
00201 if ((s = Field(2, line, 0)) != NULL)
00202 Centering = atoi((char *)s);
00203 else
00204 Centering = 1;
00205 }
00206
00207
00208
00209
00210
00211
00212 static void
00213 nr_di(line, brk)
00214 unsigned char *line;
00215 int brk;
00216 {
00217 Pass3(DOBREAK, (unsigned char *)"flush", NULL, 0);
00218 Divert ^= 1;
00219 }
00220
00221
00222
00223
00224
00225
00226 static void
00227 nr_ds(line, brk)
00228 unsigned char *line;
00229 int brk;
00230 {
00231 unsigned char buf[MAXLINE];
00232 unsigned char nm[4], nm1[4];
00233 unsigned char *s1, *s2, *s3,
00234 *s4;
00235
00236 if (Asmname(&line[3], nm) == 0) {
00237 Error(WARN, LINE, " no name", NULL);
00238 return;
00239 }
00240 s1 = Field(3, line, 0);
00241 s2 = Findstr(nm, s1, 1);
00242 while (*s2 == '\\' && *(s2 + 1) == '*') {
00243 s2++;
00244 s3 = Asmcode(&s2, nm1);
00245 s2 = Findstr(nm1, NULL, 0);
00246 }
00247 if (Hdft) {
00248
00249
00250
00251
00252 if ((nm[0]=='L' || nm[0]=='C' || nm[0]=='R')
00253 && (nm[1]=='F' || nm[1]=='H')) {
00254 (void) sprintf((char *)buf, "%s", (char *)nm);
00255 Pass3(NOBREAK, buf, s2, 0);
00256 }
00257 }
00258 }
00259
00260
00261
00262
00263
00264
00265
00266 static void
00267 nr_fi(line, brk)
00268 unsigned char *line;
00269 int brk;
00270 {
00271 Fill = 1;
00272 Pass3(brk, (unsigned char *)"flush", NULL, 0);
00273 }
00274
00275
00276
00277
00278
00279
00280 static void
00281 nr_fl(line, brk)
00282 unsigned char *line;
00283 int brk;
00284 {
00285 Pass3(brk, (unsigned char *)"flush", NULL, 0);
00286 }
00287
00288
00289
00290
00291
00292
00293 static void
00294 nr_ft(line, brk)
00295 unsigned char *line;
00296 int brk;
00297 {
00298 int i;
00299
00300 if (line[3] == '\0' || line[4] == '\0')
00301 line[4] = 'P';
00302 if (line[4] == 'P') {
00303 Font[0] = Prevfont;
00304 return;
00305 }
00306 for (i = 0; Fcode[i].nm; i++) {
00307 if (Fcode[i].nm == line[4])
00308 break;
00309 }
00310 if (Fcode[i].status == '\0') {
00311 Error(WARN, LINE, " bad font code", NULL);
00312 return;
00313 }
00314 Prevfont = Font[0];
00315 Font[0] = line[4];
00316 }
00317
00318
00319
00320
00321
00322
00323 static void
00324 nr_it(line, brk)
00325 unsigned char *line;
00326 int brk;
00327
00328 {
00329 unsigned char buf[MAXLINE];
00330 int i;
00331 unsigned char *s1, *s2;
00332
00333 if ((s1 = Field(2, line, 0)) == NULL) {
00334 Free(&Aftnxt);
00335 return;
00336 }
00337 if ((i = atoi((char *)s1)) != 1) {
00338 Error(WARN, LINE, " first .it arg must be 1", NULL);
00339 return;
00340 }
00341 if ((s2 = Field(3, line, 0)) == NULL)
00342 Free(&Aftnxt);
00343 else {
00344 (void) sprintf((char *)buf, "%s,%s",
00345 (Aftnxt == NULL) ? "" : (char *)Aftnxt,
00346 (char *)s2);
00347 Free(&Aftnxt);
00348 Aftnxt = Newstr(buf);
00349 }
00350 }
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 static void
00371 nr_nil(line, brk)
00372 unsigned char *line;
00373 int brk;
00374 {
00375 }
00376
00377
00378
00379
00380
00381
00382 static void
00383 nr_na(line, brk)
00384 unsigned char *line;
00385 int brk;
00386 {
00387 Pass3(NOBREAK, (unsigned char *)"left", NULL, 0);
00388 }
00389
00390
00391
00392
00393
00394
00395 static void
00396 nr_nf(line, brk)
00397 unsigned char *line;
00398 int brk;
00399 {
00400 Fill = 0;
00401 Pass3(brk, (unsigned char *)"flush", NULL, 0);
00402 }
00403
00404
00405
00406
00407
00408
00409 static void
00410 nr_ns(line, brk)
00411 unsigned char *line;
00412 int brk;
00413 {
00414 Pass3(NOBREAK, (unsigned char *)"nospace", NULL, 0);
00415 }
00416
00417
00418
00419
00420
00421
00422 static void
00423 nr_rm(line, brk)
00424 unsigned char *line;
00425 int brk;
00426 {
00427 int i;
00428 unsigned char nm[4];
00429
00430 if (Asmname(&line[3], nm) == 0) {
00431 Error(WARN, LINE, " no name", NULL);
00432 return;
00433 }
00434 if ((i = Findmacro(nm, 0)) >= 0) {
00435 Delmacro(i);
00436 return;
00437 }
00438 (void) Findstr(nm, NULL, 0);
00439 if (Sx >= 0) {
00440 Delstr(Sx);
00441 return;
00442 }
00443 Error(WARN, LINE, " no macro/string", NULL);
00444 }
00445
00446
00447
00448
00449
00450
00451 static void
00452 nr_rn(line, brk)
00453 unsigned char *line;
00454 int brk;
00455 {
00456 int i, j;
00457 unsigned char nm[4], nm1[4];
00458 unsigned char *s1;
00459
00460 if ((s1 = Field(2, line, 0)) == NULL || Asmname(s1, nm) == 0) {
00461 Error(WARN, LINE, " no name", NULL);
00462 return;
00463 }
00464 if ((s1 = Field(3, line, 0)) == NULL || Asmname(s1, nm1) == 0) {
00465 Error(WARN, LINE, " no new name", NULL);
00466 return;
00467 }
00468 if ((i = Findmacro(nm, 0)) >= 0) {
00469 if ((j = Findmacro(nm1, 0)) >= 0)
00470 Delmacro(j);
00471 j = Findmacro(nm1, 1);
00472 Macrotab[j].bx = Macrotab[i].bx;
00473 Macrotab[i].bx = -1;
00474 Macrotab[j].ct = Macrotab[i].ct;
00475 Macrotab[i].ct = 0;
00476 Delmacro(i);
00477 return;
00478 }
00479 (void) Findstr(nm, NULL, 0);
00480 if ((i = Sx) >= 0) {
00481 (void) Findstr(nm1, Str[i].str, 1);
00482 Delstr(i);
00483 return;
00484 }
00485 if (Findmacro(nm1, 0) < 0)
00486 (void) Findmacro(nm1, 1);
00487 }
00488
00489
00490
00491
00492
00493
00494 static void
00495 nr_rr(line, brk)
00496 unsigned char *line;
00497 int brk;
00498 {
00499 int i;
00500 unsigned char nm[4];
00501
00502 if (Asmname(&line[3], nm) == 0) {
00503 Error(WARN, LINE, " no name", NULL);
00504 return;
00505 }
00506 if ((i = Findnum(nm, 0, 0)) < 0) {
00507 Error(WARN, LINE, " no register", NULL);
00508 return;
00509 }
00510 Delnum(i);
00511 }
00512
00513
00514
00515
00516
00517
00518 static void
00519 nr_rs(line, brk)
00520 unsigned char *line;
00521 int brk;
00522 {
00523 Pass3(NOBREAK, (unsigned char *)"yesspace", NULL, 0);
00524 }
00525
00526
00527
00528
00529
00530
00531 static void
00532 nr_tm(line, brk)
00533 unsigned char *line;
00534 int brk;
00535 {
00536 Pass3(MESSAGE, Inname, (line[3] == ' ') ? &line[4] : &line[3], NR);
00537 }
00538
00539
00540
00541
00542
00543
00544 static void
00545 nr_tr(line, brk)
00546 unsigned char *line;
00547 int brk;
00548 {
00549 unsigned char buf[MAXLINE];
00550 int i, j;
00551 unsigned char nm[4], nm1[4];
00552 unsigned char *s1, *s2;
00553 int trin, trout;
00554 unsigned char xbuf[MAXLINE];
00555
00556 if (line[3] != ' ') {
00557 Error(WARN, LINE, " unknown translation", NULL);
00558 return;
00559 }
00560 for (s1 = &line[4]; *s1;) {
00561 nm[1] = nm[2] = '\0';
00562 s2 = s1 + 1;
00563
00564
00565
00566 if (*s1 == '\\' && (*s2 == '*' || *s2 == '(')) {
00567 if (*s2 == '(') {
00568
00569
00570
00571 trin = 1;
00572 s1 = s2 + 1;
00573 if ((nm[0] = *s1) != '\0') {
00574 s1++;
00575 if ((nm[1] = *s1) != '\0')
00576 s1++;
00577 }
00578 } else {
00579
00580
00581
00582 s1 = Asmcode(&s2, nm);
00583 if (*s1)
00584 s1++;
00585 s2 = Findstr(nm, NULL, 0);
00586 if (*s2 != '\0') {
00587 if ((strlen((char *)s2) + strlen((char *)s1) + 1)
00588 >= MAXLINE)
00589 Error(WARN, LINE, " string too long: ", (char *)nm);
00590 else {
00591 (void) sprintf((char *)buf, "%s%s",
00592 (char *)s2, (char *)s1);
00593 (void) strcpy((char *)xbuf, (char *)buf);
00594 s1 = xbuf;
00595 }
00596 }
00597 continue;
00598 }
00599 } else {
00600
00601
00602
00603
00604 trin = 0;
00605 if ((nm[0] = *s1) != '\0')
00606 s1++;
00607 }
00608
00609
00610
00611
00612 assemble_output:
00613 nm1[1] = nm1[2] = '\0';
00614 if (*s1 == '\0') {
00615
00616
00617
00618
00619 trout = 0;
00620 nm1[0] = ' ';
00621 } else {
00622 s2 = s1 + 1;
00623 if (*s1 == '\\' && (*s2 == '(' || *s2 == '*')) {
00624 if (*s2 == '(') {
00625
00626
00627
00628 trout = 1;
00629 s1 = s2 + 1;
00630 if ((nm1[0] = *s1) != '\0') {
00631 s1++;
00632 if ((nm1[1] = *s1) != '\0')
00633 s1++;
00634 }
00635 } else {
00636
00637
00638
00639 s1 = Asmcode(&s2, nm1);
00640 if (*s1)
00641 s1++;
00642 s2 = Findstr(nm1, NULL, 0);
00643 if (*s2 != '\0') {
00644
00645
00646
00647 if ((strlen((char *)s2) + strlen((char *)s1) + 1)
00648 >= MAXLINE)
00649 Error(WARN, LINE, " string too long: ",
00650 (char *)nm);
00651 else {
00652 (void) sprintf((char *)buf, "%s%s", (char *)s2,
00653 (char *)s1);
00654 (void) strcpy((char *)xbuf, (char *)buf);
00655 s1 = xbuf;
00656 }
00657 }
00658 goto assemble_output;
00659 }
00660 } else {
00661 trout = 0;
00662 if ((nm1[0] = *s1) != '0')
00663 s1++;
00664 else
00665 nm1[0] = ' ';
00666 }
00667 }
00668
00669
00670
00671 switch (trin) {
00672
00673 case 0:
00674 switch (trout) {
00675
00676 case 0:
00677 Trtbl[(int)nm[0]] = nm1[0];
00678 break;
00679 case 1:
00680 if ((i = Findchar(nm1, 0, NULL, 0)) < 0
00681 || strlen((char *)Schar[i].str) != 1)
00682 Error(WARN, LINE, " bad named character: ",
00683 (char *)nm1);
00684 else
00685 Trtbl[(int)nm[0]] = *(Schar[i].str);
00686 break;
00687 }
00688 break;
00689 case 1:
00690 if ((i = Findchar(nm, 0, NULL, 0)) < 0)
00691 Error(WARN, LINE, " unknown named character: ", (char *)nm);
00692 else {
00693 switch (trout) {
00694
00695 case 0:
00696 Free(&Schar[i].str);
00697 Schar[i].str = Newstr(nm1);
00698 Schar[i].len = 1;
00699 break;
00700 case 1:
00701 if ((j = Findchar(nm1, 0, NULL, 0)) < 0)
00702 Error(WARN, LINE, " unknown named character: ",
00703 (char *)nm1);
00704 else
00705 (void) Findchar(nm, Schar[j].len, Schar[j].str, 1);
00706 break;
00707 }
00708 }
00709 break;
00710 }
00711 }
00712 }
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723 static void
00724 nr_Ub(line, brk)
00725 unsigned char *line;
00726 int brk;
00727 {
00728 int i;
00729 unsigned char *s1, *s2;
00730
00731 if ((s1 = Field(2, line, 0)) == NULL)
00732 return;
00733 if ((s2 = Field(3, line, 0)) == NULL)
00734 i = 0;
00735 else
00736 i = atoi((char *)s2);
00737 if (s1[0] == 'f' && s1[1] == 'h')
00738 Pass3(NOBREAK, (unsigned char *)"fph", NULL, i);
00739 else if (s1[0] == 'H' && s1[1] == 'F')
00740 Hdft = i;
00741 else if (s1[0] == 'N' && s1[1] == 'H') {
00742 for (i = 0; i < MAXNHNR; i++)
00743 Nhnr[i] = 0;
00744 } else
00745 Error(WARN, LINE, " unknown initialization", NULL);
00746 }
00747
00748
00749
00750
00751
00752
00753 static void
00754 nr_Uc(line, brk)
00755 unsigned char *line;
00756 int brk;
00757 {
00758 unsigned char buf[MAXLINE];
00759 int i;
00760 unsigned char *s1, *s2, *s3,
00761 *s4, *s5;
00762
00763 s2 = Field(2, line, 0);
00764 i = atoi((char *)Field(3, line, 0));
00765 s4 = Field(4, line, 0);
00766 if (i < 0 || i > MAXLINE/2 || *s2 == '\0') {
00767 Error(WARN, LINE, " bad character definition", NULL);
00768 return;
00769 }
00770 if (s4 == NULL)
00771 s4 = (unsigned char *)"";
00772 else if (*s4 == '"')
00773 s4++;
00774 s1 = buf;
00775 while ((s5 = (unsigned char *)strchr((char *)s4, '\\')) != NULL) {
00776 while (s5 > s4)
00777 *s1++ = *s4++;
00778 s4 = ++s5;
00779 if (*s5 == '\\')
00780 *s1++ = '\\';
00781 else if (*s5 == 'b')
00782 *s1++ = '\b';
00783 if (*s4)
00784 s4++;
00785 }
00786 while (*s1++ = *s4++)
00787 ;
00788 if (*s2 == 'h' && *(s2+1) == 'y')
00789 (void) Findhy(buf, i, 1);
00790 else
00791 (void) Findchar(s2, i, buf, 1);
00792 }
00793
00794
00795
00796
00797
00798
00799 static void
00800 nr_Uf(line, brk)
00801 unsigned char *line;
00802 int brk;
00803 {
00804 int i;
00805
00806 if (line[3] != '\0' && line[4] != '\0') {
00807 for (i = 0; Fcode[i].nm; i++) {
00808 if (line[4] == Fcode[i].nm) {
00809 Fcode[i].status = '1';
00810 return;
00811 }
00812 }
00813 }
00814 Error(WARN, LINE, " unknown font", NULL);
00815 }
00816
00817
00818
00819
00820
00821
00822 static void
00823 nr_Ur(line, brk)
00824 unsigned char *line;
00825 int brk;
00826 {
00827 unsigned char buf[MAXLINE];
00828 int i, j;
00829 double tval;
00830
00831 if ((i = atoi((char *)Field(3, line, 0))) <= 0
00832 || (j = atoi((char *)Field(4, line, 0))) <= 0) {
00833 Error(WARN, LINE, " bad cpi resolutions", NULL);
00834 return;
00835 }
00836 tval = (double) (240.0 / (double) i);
00837 if (Findscale((int)'m', tval, 1) < 0)
00838 Error(FATAL, LINE, " missing Scal['m']", NULL);
00839 Scalen = tval;
00840 if (Scalen <= 0.0) {
00841 (void) sprintf((char *)buf, " bad Scale['n'] (%f)", Scalen);
00842 Error(FATAL, LINE, (char *)buf, NULL);
00843 }
00844 if (Findscale((int)'n', tval, 1) < 0)
00845 Error(FATAL, LINE, " missing Scale['n']", NULL);
00846 Scalev = (double) (240.0 / (double) j);
00847 if (Scalev <= 0.0) {
00848 (void) sprintf((char *)buf, " bad Scale['v'] (%f)", Scalen);
00849 Error(FATAL, LINE, (char *)buf, NULL);
00850 }
00851 if (Findscale((int)'v', Scalev, 1) < 0)
00852 Error(FATAL, LINE, " missing Scale['v']", NULL);
00853 }
00854
00855
00856
00857
00858
00859
00860
00861
00862 static void
00863 nr_UL(line, brk)
00864 unsigned char *line;
00865 int brk;
00866 {
00867 unsigned char *s1;
00868
00869 if ((s1 = Field(2, line, 0)) != NULL)
00870 P2il = atoi((char *)s1) - 1;
00871 else
00872 P2il = 0;
00873 Lockil = (line[2] == '#') ? 0 : 1;
00874 Free(&P2name);
00875 if (Field(3, line, 1) != NULL) {
00876 P2name = F;
00877 F = NULL;
00878 } else
00879 P2name = NULL;
00880 }