Jspice3
mfbtext.c
Go to the documentation of this file.
1 /**********
2 Copyright 1990 Regents of the University of California. All rights reserved.
3 Author: -C- 1982 Giles C. Billingsley
4 **********/
5 /*
6  * mfbtext.c
7  *
8  * sccsid "@(#)mfbtext.c 1.9 9/3/83"
9  *
10  * MFB is a graphics package that was developed by the integrated
11  * circuits group of the Electronics Research Laboratory and the
12  * Department of Electrical Engineering and Computer Sciences at
13  * the University of California, Berkeley, California. The programs
14  * in MFB are available free of charge to any interested party.
15  * The sale, resale, or use of these program for profit without the
16  * express written consent of the Department of Electrical Engineering
17  * and Computer Sciences, University of California, Berkeley, California,
18  * is forbidden.
19  */
20 
21 
22 #include "spice.h"
23 #include "mfb.h"
24 
25 #define MFBFORMAT MFBCurrent->strings
26 
27 
28 /**************************************************************************
29  *
30  * MFBText
31  *
32  * MFBText contains MFB routines for the management of graphtext.
33  *
34  **************************************************************************/
35 
36 void
38 int Left;
39 int Bottom;
40 int Right;
41 int Top;
42 FILE *Textfile;
43 {
44  char cbuf[200]; /* 200 chars per line max */
45  int c,i;
46  int linecount;
47  int done = 0;
48  int oldfillpattern;
49  int oldforeground;
50  int nlines;
51  int nchars;
52  int controlchar;
53 
54  /* test to be sure of window area */
55  if(Top < Bottom)
56  MFBSwapInt(Top,Bottom);
57  if(Right < Left)
58  MFBSwapInt(Left,Right);
59 
60  /* calculate parameters */
61  nlines = (Top - Bottom)/MFBCurrent->fontHeight;
62  nchars = (Right - Left)/(MFBCurrent->fontWidth + MFBCurrent->fontXOffset);
63  nchars = MFBmin(nchars,200);
64 
65  /* save old style ID's */
66  oldforeground = MFBCurrent->fgColorId;
67  oldfillpattern = MFBCurrent->fillPattern;
68 
69  if(nlines <= 0) return;
70  linecount = 1;
72  MFBSetColor(0);
73  MFBBox(Left,Bottom,Right,Top);
74  MFBSetColor(oldforeground);
75  while(! done) {
76  i = 0;
77  controlchar = 0;
78  while(i < nchars && (c = getc(Textfile)) != '\n' && c != EOF){
79  if(c == 9){ /* tab */
80  cbuf[i++] = ' ';
81  while(i < nchars && (i % 8) != 0) cbuf[i++] = ' ';
82  }
83  else if(c < ' '){
84  if(controlchar == 0){
85  cbuf[i++] = '^';
86  controlchar = 1;
87  (void) ungetc(c,Textfile);
88  }
89  else{
90  cbuf[i++] = c + '@';
91  controlchar = 0;
92  }
93  }
94  else if(c <= '~')
95  cbuf[i++] = c;
96  }
97  cbuf[i] = 0;
98  if(c == EOF) done = 1;
99  MFBText(cbuf,Left,Top - (linecount) * MFBCurrent->fontHeight,0);
100  MFBUpdate();
101  if(done || ++linecount >= nlines){
102  linecount = 1;
103  if(done)
104  MFBText("-DONE-",Left,Bottom,0);
105  else
106  MFBText("-MORE- (^D to exit)",Left,Bottom,0);
107  MFBUpdate();
108  c = (*MFBCurrent->kybrd_getchar)();
109  if(c == 4)
110  done = 1;
111  MFBSetColor(0);
112  MFBBox(Left,Bottom,Right,Top);
113  MFBSetColor(oldforeground);
114  }
115  }
116  MFBSetFillPattern(oldfillpattern);
117 }
118 
119 
120 void
122 int Left;
123 int Bottom;
124 int Right;
125 int Top;
126 FILE *Textfile;
127 {
128  char cbuf[200]; /* 200 chars per line max */
129  int c,i,j;
130  int curline; /* current line in the textfile */
131  int linecount;
132  int done = 0;
133  int oldfillpattern;
134  int oldforeground;
135  int nlines;
136  int nchars;
137  int controlchar;
138 
139  /* test to be sure of window area */
140  if(Top < Bottom)
141  MFBSwapInt(Top,Bottom);
142  if(Right < Left)
143  MFBSwapInt(Left,Right);
144 
145  /* calculate parameters */
146  nlines = (Top - Bottom)/MFBCurrent->fontHeight;
147  nchars = (Right - Left)/(MFBCurrent->fontWidth + MFBCurrent->fontXOffset);
148  nchars = MFBmin(nchars,200);
149 
150  /* save old style ID's */
151  oldforeground = MFBCurrent->fgColorId;
152  oldfillpattern = MFBCurrent->fillPattern;
153 
154  if(nlines <= 0) return;
155  curline = 1;
157  MFBSetColor(0);
158  MFBBox(Left,Bottom,Right,Top);
159  MFBSetColor(oldforeground);
160  while( !done ){
161  rewind(Textfile);
162  /* skip first curline's */
163  for(i = 1; i < curline; ++i){
164  while((c = getc(Textfile)) != '\n' && c != EOF) ;
165  }
166  /* output nlines of text */
167  linecount = 0;
168  for(j = 1; j < nlines; ++j){
169  i = 0;
170  controlchar = 0;
171  while(i < nchars && (c = getc(Textfile)) != '\n' && c != EOF){
172  if(c == 9){ /* tab */
173  cbuf[i++] = ' ';
174  while(i < nchars && (i % 8) != 0) cbuf[i++] = ' ';
175  }
176  else if(c < ' '){
177  if(controlchar == 0){
178  cbuf[i++] = '^';
179  controlchar = 1;
180  (void) ungetc(c,Textfile);
181  }
182  else{
183  cbuf[i++] = c + '@';
184  controlchar = 0;
185  }
186  }
187  else if(c <= '~')
188  cbuf[i++] = c;
189  }
190  if(c == '\n') ++linecount;
191  cbuf[i] = 0;
192  MFBText(cbuf,Left,Top - (j) * MFBCurrent->fontHeight,0);
193  MFBUpdate();
194  if(c == EOF){
195  j = nlines;
196  done = 1;
197  }
198  }
199  if(done)
200  MFBText("-DONE-",Left,Bottom,0);
201  else
202  MFBText("-MORE- (^D to exit, ^U to scroll up)",Left,Bottom,0);
203  MFBUpdate();
204  c = (*MFBCurrent->kybrd_getchar)();
205  --linecount;
206  if(c == 4)
207  done = 1;
208  else if(c == 21){
209  curline -= linecount;
210  if(curline < 1)
211  curline = 1;
212  }
213  else
214  curline += linecount;
215  MFBSetColor(0);
216  MFBBox(Left,Bottom,Right,Top);
217  MFBSetColor(oldforeground);
218  }
219  MFBSetFillPattern(oldfillpattern);
220 }
int fgColorId
Definition: mfb.h:267
int fontWidth
Definition: mfb.h:251
long * Left
Definition: cd.c:1907
int fontXOffset
Definition: mfb.h:252
void MFBText(char *s, int x, int y, int r)
Definition: mfbtext.c:54
#define MFBmin(a, b)
Definition: mfb.h:34
int(* kybrd_getchar)()
Definition: mfb.h:296
long * Top
Definition: cd.c:1907
long * Right
Definition: cd.c:1907
int fillPattern
Definition: mfb.h:268
int fontHeight
Definition: mfb.h:250
void MFBMore(int Left, int Bottom, int Right, int Top, FILE *Textfile)
Definition: mfbtext.c:37
int MFBSetColor()
static double c
Definition: vectors.c:16
MFB * MFBCurrent
Definition: mfbopen.c:13
MFBSetFillPattern(int styleId)
Definition: mfbbasic.c:288
long * Bottom
Definition: cd.c:1907
int MFBUpdate()
Definition: mfbopen.c:252
#define MFBSwapInt(f1, f2)
Definition: mfb.h:35
void MFBScroll(int Left, int Bottom, int Right, int Top, FILE *Textfile)
Definition: mfbtext.c:121
void MFBBox()