Jspice3
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;
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;
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;
122  DevBox(Left - 2,Bottom - 2,Right + 2,Top + 2);
123  DevSetColor(color);
124  }
125  }
126 }
127 
128 
129 int
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);
172  if (MoreBB.kaY < MoreBB.kaBottom) {
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);
183  if (MoreBB.kaY < MoreBB.kaBottom) {
185  if (more_prompt()) return (True);
186  }
187  }
188  return (False);
189 }
190 
191 
192 int
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);
209  DidInitMore = False;
210  free(MoreBuffer);
211  MoreBuffer = NULL;
212  }
213  else {
214  MorePageDisplay();
215  }
216  }
217  return (MoreShowed);
218 }
219 
220 
221 int
223 
224 {
225  if (!MoreOn || UsePopup)
226  return (False);
227  (void)MorePageDisplay();
228  return (True);
229 }
230 
231 
232 int
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);
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 
271  Y = MoreBB.kaTop - gi_fntheight;
272  for (s = MoreBuffer; s < MoreLinePtr; s += gi_numtextcols+1) {
274  Y -= gi_fntheight;
275  }
276  return (True);
277 }
278 
279 
280 static void
282 
283 {
284  int i;
285 
288  gi_fntheight + 1;
291  i /= gi_fntheight;
295 
296  if (MoreBuffer == NULL) {
298  if (MoreBuffer == NULL) {
299  ShowPrompt("Error, Out of memory!");
300  return;
301  }
302  }
304  for (i = 0; i < gi_numtextrows; i++) {
305  *MoreLinePtr = '\0';
307  }
309 
310  DidInitMore = True;
311  MoreShowed = 0;
312 }
313 
314 
315 static int
317 
318 {
319  int i;
320  char *s, InChar;
321 
324  (int)MoreBB.kaBottom - gi_fntheight," --More--");
325  InChar = FBGetchar(ERASE);
326 
328  s = MoreBuffer;
329  for (i = 0; i < gi_numtextrows; i++) {
330  *s = '\0';
331  s += gi_numtextcols+1;
332  }
334 
335  /* can't do this */
336  /*
337  if (InChar == ESCAPE || InChar == 'q')
338  return (True);
339  */
340  return (False);
341 }
long kaY
Definition: sced.h:113
static char * MoreBuffer
Definition: moretext.c:26
static FILE * tmpfp
Definition: moretext.c:27
long kaRight
Definition: sced.h:112
static int more_prompt()
Definition: moretext.c:316
char * strcpy()
Definition: cddefs.h:119
static int UsePopup
Definition: moretext.c:21
void DevSetColor()
static int MoreOn
Definition: moretext.c:22
long kaBottom
Definition: sced.h:112
void DevText()
#define ERASE
Definition: scedmacs.h:11
DISPDEVICE * dispdev
Definition: display.c:112
#define gi_numtextcols
Definition: scedmacs.h:61
char * malloc()
void EraseLargeCoarseViewport()
Definition: viewport.c:583
Definition: sced.h:111
int MorePageDisplay()
Definition: moretext.c:233
struct ka * kvLargeCoarseViewport
Definition: sced.h:151
#define gi_fntheight
Definition: scedmacs.h:57
long * Left
Definition: cd.c:1907
int EnableMore(int On)
Definition: moretext.c:193
bool windows
Definition: plotdev.h:61
Definition: fteinp.h:14
void DevBox()
#define NULL
Definition: spdefs.h:121
static struct ka MoreBB
Definition: moretext.c:25
long kaTop
Definition: sced.h:112
long * Top
Definition: cd.c:1907
long * Right
Definition: cd.c:1907
int unlink(char *fn)
Definition: libfuncs.c:96
#define True
Definition: scedstub.c:16
short FBGetchar()
static int DidInitMore
Definition: moretext.c:23
char * smktemp()
struct kv * View
Definition: init.c:17
static double c
Definition: vectors.c:16
long kaLeft
Definition: sced.h:112
static int MoreShowed
Definition: moretext.c:24
int DevGetchar()
int RepaintMore()
Definition: moretext.c:222
#define MenuTextColor
Definition: sced.h:75
int MoreLine(char *line)
Definition: moretext.c:130
long * Bottom
Definition: cd.c:1907
void FBText()
static void init_more()
Definition: moretext.c:281
#define gi_fntwidth
Definition: scedmacs.h:56
#define BackgroundColor
Definition: sced.h:73
#define gi_numtextrows
Definition: scedmacs.h:60
void MoreText(int Left, int Bottom, int Right, int Top, FILE *Textfile, int color)
Definition: moretext.c:40
#define False
Definition: scedstub.c:15
#define MoreTextColor
Definition: sced.h:81
static char * MoreLinePtr
Definition: moretext.c:26
Definition: cddefs.h:192
int PopUpErrMessage()
long Y
Definition: actions.c:450
void ShowPrompt(char *str)
Definition: scedstub.c:71
#define PIXEL_COORDINATE
Definition: scedmacs.h:16
void free()
static char * tmpfn
Definition: moretext.c:28
long kaX
Definition: sced.h:113