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