1 /*-
2 * Copyright (c) 1980 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)setfmt.c 5.2 (Berkeley) 04/12/91";
10 #endif /* not lint */
11
12 #include "defs.h"
13 #include "format.h"
14
15 #define GLITCH '\2'
16
17 extern char *fmtptr, *s_init;
18 extern int fmt_strings;
19
20 setfmt(lp)
21 struct Labelblock *lp;
22 {
23 int fmt_len, frmt_str_lab;
24 char *s, *lexline();
25
26 s = lexline(&fmt_len);
27 preven(ALILONG);
28 prlabel(asmfile, lp->labelno);
29 if( pars_f(s) != 0) {
30 err_fmt(fmt_len);
31 } else {
32 fprintf( asmfile, ".word %d\n", FMT_COMP ); /* precompiled format */
33 fprintf( asmfile, ".word %d\n", pc );
34 frmt_str_lab = newlabel(); /* to mark loc of format string */
35 prcona( asmfile, frmt_str_lab );
36 putshrts( syl, sizeof(struct syl)/SZSHORT*pc );
37 }
38 if( fmt_strings ) pruse( asmfile, USEINIT) ;
39 prlabel(asmfile, frmt_str_lab );
40 putstr(asmfile, s, fmt_len);
41 if( fmt_strings ) pruse( asmfile, USECONST) ;
42 flline();
43 }
44
45 LOCAL
putshrts(words,count)46 putshrts( words, count )
47 short *words;
48 {
49 while ( count-- > 0 )
50 fprintf( asmfile, ".word %d\n", *words++ );
51 }
52
53 static char *fmt_seg_ptr;
54
55 LOCAL
err_fmt(fmt_len)56 err_fmt(fmt_len)
57 {
58 int i;
59 char *ep, *end_ptr = s_init+fmt_len;
60 char fmt_seg[50];
61
62 fmt_seg_ptr = fmt_seg;
63 i = fmtptr - s_init;
64 ep = fmtptr - (i<25?i:25);
65 i = i + 5;
66 while(i && *ep && ep<end_ptr)
67 {
68 if(ep==fmtptr) save_char('|',fmt_seg);
69 save_char(*ep);
70 ep++; i--;
71 }
72 *fmt_seg_ptr++ = '\0';
73 errstr("Error in format: %s", fmt_seg);
74 }
75
76 LOCAL
save_char(c)77 save_char(c)
78 int c;
79 {
80 c &= 0177;
81 if( c == GLITCH ) {
82 c = '"';
83 } else if (c < ' ' || c == 0177) {
84 *fmt_seg_ptr++ ='^';
85 c ^= 0100;
86 }
87 *fmt_seg_ptr++ = c;
88 }
89