Jspice3
Main Page
Data Structures
Files
File List
Globals
moretext.c
Go to the documentation of this file.
1
/***************************************************************************
2
SCED - Schematic Capture Editor
3
JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
4
Copyright 1990 Regents of the University of California. All rights reserved.
5
Authors: 1981 Giles C. Billingsley (parts of KIC layout editor)
6
1992 Stephen R. Whiteley
7
****************************************************************************/
8
9
#include "
spice.h
"
10
#include "
sced.h
"
11
#include "
scedmacs.h
"
12
13
/***********************************************************************
14
*
15
* Routines for "More" text presentation.
16
*
17
*
18
***********************************************************************/
19
20
21
static
int
UsePopup
;
/* don't use MORE, use a popup instead */
22
static
int
MoreOn
;
/* set while in MORE mode */
23
static
int
DidInitMore
;
/* initialized */
24
static
int
MoreShowed
;
/* nonzero if some characters in output */
25
static
struct
ka
MoreBB
;
26
static
char
*
MoreBuffer
, *
MoreLinePtr
;
27
static
FILE *
tmpfp
;
28
static
char
*
tmpfn
;
29
30
#ifdef __STDC__
31
static
void
init_more
(
void
);
32
static
int
more_prompt
(
void
);
33
#else
34
static
void
init_more
();
35
static
int
more_prompt
();
36
#endif
37
38
39
void
40
MoreText
(
Left
,
Bottom
,
Right
,
Top
,Textfile,color)
41
42
int
Left
;
43
int
Bottom
;
44
int
Right
;
45
int
Top
;
46
FILE *Textfile;
47
int
color;
48
{
49
/* this is not called under X */
50
char
cbuf[200];
/* 200 chars per line max */
51
int
c
,i;
52
int
linecount;
53
int
done = 0;
54
int
nlines;
55
int
nchars;
56
int
controlchar;
57
58
/* test to be sure of window area */
59
if
(Top < Bottom) {
60
i =
Top
;
61
Top =
Bottom
;
62
Bottom = i;
63
}
64
if
(Right < Left) {
65
i =
Right
;
66
Right =
Left
;
67
Left = i;
68
}
69
70
Left += 2;
71
Right -= 2;
72
Bottom += 2;
73
Top -= 2;
74
/* calculate parameters */
75
nlines = (Top -
Bottom
)/
gi_fntheight
;
76
nchars = (Right -
Left
)/
gi_fntwidth
;
77
if
(nchars > 200)
78
nchars = 200;
79
80
if
(nlines <= 0)
return
;
81
linecount = 1;
82
DevSetColor
(
BackgroundColor
);
83
DevBox
(Left - 2,Bottom - 2,Right + 2,Top + 2);
84
DevSetColor
(color);
85
while
(! done) {
86
i = 0;
87
controlchar = 0;
88
while
(i < nchars && (c = getc(Textfile)) !=
'\n'
&& c != EOF) {
89
if
(c == 9) {
/* tab */
90
cbuf[i++] =
' '
;
91
while
(i < nchars && (i % 8)) cbuf[i++] =
' '
;
92
}
93
else
if
(c <
' '
) {
94
if
(controlchar == 0) {
95
cbuf[i++] =
'^'
;
96
controlchar = 1;
97
ungetc(c,Textfile);
98
}
99
else
{
100
cbuf[i++] = c +
'@'
;
101
controlchar = 0;
102
}
103
}
104
else
if
(c <=
'~'
)
105
cbuf[i++] =
c
;
106
}
107
cbuf[i] =
'\0'
;
108
if
(c == EOF) done = 1;
109
DevText
(cbuf,Left,Top - (linecount) *
gi_fntheight
);
110
if
(done || ++linecount >= nlines) {
111
linecount = 1;
112
DevSetColor
(
MenuTextColor
);
113
if
(done)
114
DevText
(
"-DONE-"
,Left,Bottom);
115
else
116
DevText
(
"-MORE- (^D to exit)"
,Left,Bottom);
117
DevSetColor
(color);
118
c = (char)
DevGetchar
(
NULL
);
119
if
(c == 4)
120
done = 1;
121
DevSetColor
(
BackgroundColor
);
122
DevBox
(Left - 2,Bottom - 2,Right + 2,Top + 2);
123
DevSetColor
(color);
124
}
125
}
126
}
127
128
129
int
130
MoreLine
(
line
)
131
132
char *
line
;
133
{
134
char
*
s
,
c
, *next;
135
136
if
(!line)
return
(
False
);
137
if
(!
MoreOn
)
return
(
False
);
138
if
(
UsePopup
) {
139
if
(!
tmpfp
) {
140
tmpfn
=
smktemp
(
"sct"
);
141
tmpfp
= fopen(
tmpfn
,
"w+"
);
142
if
(!
tmpfp
) {
143
UsePopup
=
False
;
144
free
(
tmpfn
);
145
tmpfn
=
NULL
;
146
}
147
}
148
if
(
tmpfp
) {
149
if
(*(line + strlen(line) - 1) !=
'\n'
)
150
fprintf(
tmpfp
,
"%s\n"
, line);
151
else
152
fprintf(
tmpfp
, line);
153
MoreShowed
=
True
;
154
return
(
False
);
155
}
156
}
157
158
if
(!
DidInitMore
)
init_more
();
159
if
(!
DidInitMore
)
return
(
False
);
160
161
for
(s = line; s && *s; s = next) {
162
if
((next = strchr(s,
'\n'
)) !=
NULL
) {
163
*next =
'\0'
;
164
next++;
165
}
166
while
(strlen(s) >
MoreBB
.
kaX
) {
167
c = *(s +
MoreBB
.
kaX
);
168
*(s +
MoreBB
.
kaX
) =
'\0'
;
169
strcpy
(
MoreLinePtr
,s);
170
MoreLinePtr
+=
gi_numtextcols
+1;
171
MoreBB
.
kaY
-=
gi_fntheight
;
172
if
(
MoreBB
.
kaY
<
MoreBB
.
kaBottom
) {
173
MoreShowed
+=
MorePageDisplay
();
174
if
(
more_prompt
())
return
(
True
);
175
}
176
*(s +
MoreBB
.
kaX
) = c;
177
s +=
MoreBB
.
kaX
;
178
if
(!*s)
return
(
False
);
179
}
180
strcpy
(
MoreLinePtr
,s);
181
MoreLinePtr
+=
gi_numtextcols
+1;
182
MoreBB
.
kaY
-=
gi_fntheight
;
183
if
(
MoreBB
.
kaY
<
MoreBB
.
kaBottom
) {
184
MoreShowed
+=
MorePageDisplay
();
185
if
(
more_prompt
())
return
(
True
);
186
}
187
}
188
return
(
False
);
189
}
190
191
192
int
193
EnableMore
(On)
194
195
int On;
196
{
197
if
(On) {
198
MoreOn
=
True
;
199
if
(
dispdev
->
windows
) {
200
UsePopup
=
true
;
201
MoreShowed
=
False
;
202
}
203
}
204
else
{
205
MoreOn
=
False
;
206
if
(!
UsePopup
) {
207
if
(!
DidInitMore
)
return
(0);
208
MoreShowed
+=
MorePageDisplay
();
209
DidInitMore
=
False
;
210
free
(
MoreBuffer
);
211
MoreBuffer
=
NULL
;
212
}
213
else
{
214
MorePageDisplay
();
215
}
216
}
217
return
(
MoreShowed
);
218
}
219
220
221
int
222
RepaintMore
()
223
224
{
225
if
(!
MoreOn
||
UsePopup
)
226
return
(
False
);
227
(void)
MorePageDisplay
();
228
return
(
True
);
229
}
230
231
232
int
233
MorePageDisplay
()
234
235
/* returns False if nothing to print */
236
{
237
char
*
s
, *
t
;
238
int
Y
;
239
240
if
(
UsePopup
) {
241
if
(
tmpfp
) {
242
fflush(
tmpfp
);
243
rewind(
tmpfp
);
244
PopUpErrMessage
(
tmpfp
);
245
fclose(
tmpfp
);
246
unlink
(
tmpfn
);
247
free
(
tmpfn
);
248
tmpfp
=
NULL
;
249
tmpfn
=
NULL
;
250
}
251
return
(
MoreShowed
);
252
}
253
254
if
(
MoreLinePtr
==
MoreBuffer
)
255
return
(
False
);
256
257
/* return if only blank lines */
258
for
(s =
MoreBuffer
; s <
MoreLinePtr
; s +=
gi_numtextcols
+1) {
259
t = s;
260
while
(isspace(*t)) t++;
261
if
(*t ==
'\0'
)
262
continue
;
263
else
264
break
;
265
}
266
if
(*t ==
'\0'
)
267
return
(
False
);
268
269
EraseLargeCoarseViewport
();
270
DevSetColor
(
MoreTextColor
);
271
Y =
MoreBB
.
kaTop
-
gi_fntheight
;
272
for
(s =
MoreBuffer
; s <
MoreLinePtr
; s +=
gi_numtextcols
+1) {
273
FBText
(
PIXEL_COORDINATE
,(
int
)
MoreBB
.
kaLeft
,Y,s);
274
Y -=
gi_fntheight
;
275
}
276
return
(
True
);
277
}
278
279
280
static
void
281
init_more
()
282
283
{
284
int
i;
285
286
MoreBB
.
kaLeft
=
View
->
kvLargeCoarseViewport
->
kaLeft
+ 7;
287
MoreBB
.
kaBottom
=
View
->
kvLargeCoarseViewport
->
kaBottom
+
288
gi_fntheight
+ 1;
289
MoreBB
.
kaRight
=
View
->
kvLargeCoarseViewport
->
kaRight
- 1;
290
i =
View
->
kvLargeCoarseViewport
->
kaTop
- 1 -
MoreBB
.
kaBottom
;
291
i /=
gi_fntheight
;
292
MoreBB
.
kaTop
=
MoreBB
.
kaBottom
+ i*
gi_fntheight
;
293
MoreBB
.
kaX
= (
MoreBB
.
kaRight
-
MoreBB
.
kaLeft
)/
gi_fntwidth
;
294
MoreBB
.
kaY
=
MoreBB
.
kaTop
-
gi_fntheight
;
295
296
if
(
MoreBuffer
==
NULL
) {
297
MoreBuffer
=
malloc
(
gi_numtextrows
*(
gi_numtextcols
+1));
298
if
(
MoreBuffer
==
NULL
) {
299
ShowPrompt
(
"Error, Out of memory!"
);
300
return
;
301
}
302
}
303
MoreLinePtr
=
MoreBuffer
;
304
for
(i = 0; i <
gi_numtextrows
; i++) {
305
*
MoreLinePtr
=
'\0'
;
306
MoreLinePtr
+=
gi_numtextcols
+1;
307
}
308
MoreLinePtr
=
MoreBuffer
;
309
310
DidInitMore
=
True
;
311
MoreShowed
= 0;
312
}
313
314
315
static
int
316
more_prompt
()
317
318
{
319
int
i;
320
char
*
s
, InChar;
321
322
DevSetColor
(
MenuTextColor
);
323
FBText
(
PIXEL_COORDINATE
,(
int
)
MoreBB
.
kaLeft
,
324
(
int
)
MoreBB
.
kaBottom
-
gi_fntheight
,
" --More--"
);
325
InChar =
FBGetchar
(
ERASE
);
326
327
MoreBB
.
kaY
=
MoreBB
.
kaTop
-
gi_fntheight
;
328
s =
MoreBuffer
;
329
for
(i = 0; i <
gi_numtextrows
; i++) {
330
*s =
'\0'
;
331
s +=
gi_numtextcols
+1;
332
}
333
MoreLinePtr
=
MoreBuffer
;
334
335
/* can't do this */
336
/*
337
if (InChar == ESCAPE || InChar == 'q')
338
return (True);
339
*/
340
return
(
False
);
341
}
ka::kaY
long kaY
Definition:
sced.h:113
MoreBuffer
static char * MoreBuffer
Definition:
moretext.c:26
tmpfp
static FILE * tmpfp
Definition:
moretext.c:27
ka::kaRight
long kaRight
Definition:
sced.h:112
sced.h
more_prompt
static int more_prompt()
Definition:
moretext.c:316
strcpy
char * strcpy()
s
Definition:
cddefs.h:119
UsePopup
static int UsePopup
Definition:
moretext.c:21
DevSetColor
void DevSetColor()
MoreOn
static int MoreOn
Definition:
moretext.c:22
ka::kaBottom
long kaBottom
Definition:
sced.h:112
DevText
void DevText()
ERASE
#define ERASE
Definition:
scedmacs.h:11
dispdev
DISPDEVICE * dispdev
Definition:
display.c:112
gi_numtextcols
#define gi_numtextcols
Definition:
scedmacs.h:61
malloc
char * malloc()
EraseLargeCoarseViewport
void EraseLargeCoarseViewport()
Definition:
viewport.c:583
ka
Definition:
sced.h:111
MorePageDisplay
int MorePageDisplay()
Definition:
moretext.c:233
kv::kvLargeCoarseViewport
struct ka * kvLargeCoarseViewport
Definition:
sced.h:151
gi_fntheight
#define gi_fntheight
Definition:
scedmacs.h:57
Left
long * Left
Definition:
cd.c:1907
EnableMore
int EnableMore(int On)
Definition:
moretext.c:193
scedmacs.h
DISPDEVICE::windows
bool windows
Definition:
plotdev.h:61
line
Definition:
fteinp.h:14
DevBox
void DevBox()
NULL
#define NULL
Definition:
spdefs.h:121
MoreBB
static struct ka MoreBB
Definition:
moretext.c:25
ka::kaTop
long kaTop
Definition:
sced.h:112
Top
long * Top
Definition:
cd.c:1907
Right
long * Right
Definition:
cd.c:1907
unlink
int unlink(char *fn)
Definition:
libfuncs.c:96
True
#define True
Definition:
scedstub.c:16
FBGetchar
short FBGetchar()
DidInitMore
static int DidInitMore
Definition:
moretext.c:23
smktemp
char * smktemp()
View
struct kv * View
Definition:
init.c:17
c
static double c
Definition:
vectors.c:16
spice.h
ka::kaLeft
long kaLeft
Definition:
sced.h:112
MoreShowed
static int MoreShowed
Definition:
moretext.c:24
DevGetchar
int DevGetchar()
RepaintMore
int RepaintMore()
Definition:
moretext.c:222
MenuTextColor
#define MenuTextColor
Definition:
sced.h:75
MoreLine
int MoreLine(char *line)
Definition:
moretext.c:130
Bottom
long * Bottom
Definition:
cd.c:1907
FBText
void FBText()
init_more
static void init_more()
Definition:
moretext.c:281
gi_fntwidth
#define gi_fntwidth
Definition:
scedmacs.h:56
BackgroundColor
#define BackgroundColor
Definition:
sced.h:73
gi_numtextrows
#define gi_numtextrows
Definition:
scedmacs.h:60
MoreText
void MoreText(int Left, int Bottom, int Right, int Top, FILE *Textfile, int color)
Definition:
moretext.c:40
False
#define False
Definition:
scedstub.c:15
MoreTextColor
#define MoreTextColor
Definition:
sced.h:81
MoreLinePtr
static char * MoreLinePtr
Definition:
moretext.c:26
t
Definition:
cddefs.h:192
PopUpErrMessage
int PopUpErrMessage()
Y
long Y
Definition:
actions.c:450
ShowPrompt
void ShowPrompt(char *str)
Definition:
scedstub.c:71
PIXEL_COORDINATE
#define PIXEL_COORDINATE
Definition:
scedmacs.h:16
free
void free()
tmpfn
static char * tmpfn
Definition:
moretext.c:28
ka::kaX
long kaX
Definition:
sced.h:113
src
lib
sced
moretext.c
Generated by
1.8.11