Jspice3
moretext.c File Reference
#include "spice.h"
#include "sced.h"
#include "scedmacs.h"
Include dependency graph for moretext.c:

Go to the source code of this file.

Functions

static void init_more ()
 
static int more_prompt ()
 
void MoreText (int Left, int Bottom, int Right, int Top, FILE *Textfile, int color)
 
int MoreLine (char *line)
 
int EnableMore (int On)
 
int RepaintMore ()
 
int MorePageDisplay ()
 

Variables

static int UsePopup
 
static int MoreOn
 
static int DidInitMore
 
static int MoreShowed
 
static struct ka MoreBB
 
static char * MoreBuffer
 
static char * MoreLinePtr
 
static FILE * tmpfp
 
static char * tmpfn
 

Function Documentation

int EnableMore ( int  On)

Definition at line 193 of file moretext.c.

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 }
static char * MoreBuffer
Definition: moretext.c:26
static int UsePopup
Definition: moretext.c:21
static int MoreOn
Definition: moretext.c:22
DISPDEVICE * dispdev
Definition: display.c:112
int MorePageDisplay()
Definition: moretext.c:233
bool windows
Definition: plotdev.h:61
#define NULL
Definition: spdefs.h:121
#define True
Definition: scedstub.c:16
static int DidInitMore
Definition: moretext.c:23
static int MoreShowed
Definition: moretext.c:24
#define False
Definition: scedstub.c:15
void free()
static void init_more ( )
static

Definition at line 281 of file moretext.c.

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 }
long kaY
Definition: sced.h:113
static char * MoreBuffer
Definition: moretext.c:26
long kaRight
Definition: sced.h:112
long kaBottom
Definition: sced.h:112
#define gi_numtextcols
Definition: scedmacs.h:61
char * malloc()
struct ka * kvLargeCoarseViewport
Definition: sced.h:151
#define gi_fntheight
Definition: scedmacs.h:57
#define NULL
Definition: spdefs.h:121
static struct ka MoreBB
Definition: moretext.c:25
long kaTop
Definition: sced.h:112
#define True
Definition: scedstub.c:16
static int DidInitMore
Definition: moretext.c:23
struct kv * View
Definition: init.c:17
long kaLeft
Definition: sced.h:112
static int MoreShowed
Definition: moretext.c:24
#define gi_fntwidth
Definition: scedmacs.h:56
#define gi_numtextrows
Definition: scedmacs.h:60
static char * MoreLinePtr
Definition: moretext.c:26
void ShowPrompt(char *str)
Definition: scedstub.c:71
long kaX
Definition: sced.h:113
static int more_prompt ( )
static

Definition at line 316 of file moretext.c.

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
Definition: cddefs.h:119
void DevSetColor()
long kaBottom
Definition: sced.h:112
#define ERASE
Definition: scedmacs.h:11
#define gi_numtextcols
Definition: scedmacs.h:61
#define gi_fntheight
Definition: scedmacs.h:57
static struct ka MoreBB
Definition: moretext.c:25
long kaTop
Definition: sced.h:112
short FBGetchar()
long kaLeft
Definition: sced.h:112
#define MenuTextColor
Definition: sced.h:75
void FBText()
#define gi_numtextrows
Definition: scedmacs.h:60
#define False
Definition: scedstub.c:15
static char * MoreLinePtr
Definition: moretext.c:26
#define PIXEL_COORDINATE
Definition: scedmacs.h:16
int MoreLine ( char *  line)

Definition at line 130 of file moretext.c.

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 }
long kaY
Definition: sced.h:113
static FILE * tmpfp
Definition: moretext.c:27
static int more_prompt()
Definition: moretext.c:316
char * strcpy()
Definition: cddefs.h:119
static int UsePopup
Definition: moretext.c:21
static int MoreOn
Definition: moretext.c:22
long kaBottom
Definition: sced.h:112
#define gi_numtextcols
Definition: scedmacs.h:61
int MorePageDisplay()
Definition: moretext.c:233
#define gi_fntheight
Definition: scedmacs.h:57
Definition: fteinp.h:14
#define NULL
Definition: spdefs.h:121
static struct ka MoreBB
Definition: moretext.c:25
#define True
Definition: scedstub.c:16
static int DidInitMore
Definition: moretext.c:23
char * smktemp()
static double c
Definition: vectors.c:16
static int MoreShowed
Definition: moretext.c:24
static void init_more()
Definition: moretext.c:281
#define False
Definition: scedstub.c:15
static char * MoreLinePtr
Definition: moretext.c:26
void free()
static char * tmpfn
Definition: moretext.c:28
long kaX
Definition: sced.h:113
int MorePageDisplay ( )

Definition at line 233 of file moretext.c.

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 }
static char * MoreBuffer
Definition: moretext.c:26
static FILE * tmpfp
Definition: moretext.c:27
Definition: cddefs.h:119
static int UsePopup
Definition: moretext.c:21
void DevSetColor()
#define gi_numtextcols
Definition: scedmacs.h:61
void EraseLargeCoarseViewport()
Definition: viewport.c:583
#define gi_fntheight
Definition: scedmacs.h:57
#define NULL
Definition: spdefs.h:121
static struct ka MoreBB
Definition: moretext.c:25
long kaTop
Definition: sced.h:112
int unlink(char *fn)
Definition: libfuncs.c:96
#define True
Definition: scedstub.c:16
long kaLeft
Definition: sced.h:112
static int MoreShowed
Definition: moretext.c:24
void FBText()
#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
#define PIXEL_COORDINATE
Definition: scedmacs.h:16
void free()
static char * tmpfn
Definition: moretext.c:28
void MoreText ( int  Left,
int  Bottom,
int  Right,
int  Top,
FILE *  Textfile,
int  color 
)

Definition at line 40 of file moretext.c.

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 }
void DevSetColor()
void DevText()
#define gi_fntheight
Definition: scedmacs.h:57
long * Left
Definition: cd.c:1907
void DevBox()
#define NULL
Definition: spdefs.h:121
long * Top
Definition: cd.c:1907
long * Right
Definition: cd.c:1907
static double c
Definition: vectors.c:16
int DevGetchar()
#define MenuTextColor
Definition: sced.h:75
long * Bottom
Definition: cd.c:1907
#define gi_fntwidth
Definition: scedmacs.h:56
#define BackgroundColor
Definition: sced.h:73
int RepaintMore ( )

Definition at line 222 of file moretext.c.

224 {
225  if (!MoreOn || UsePopup)
226  return (False);
227  (void)MorePageDisplay();
228  return (True);
229 }
static int UsePopup
Definition: moretext.c:21
static int MoreOn
Definition: moretext.c:22
int MorePageDisplay()
Definition: moretext.c:233
#define True
Definition: scedstub.c:16
#define False
Definition: scedstub.c:15

Variable Documentation

int DidInitMore
static

Definition at line 23 of file moretext.c.

struct ka MoreBB
static

Definition at line 25 of file moretext.c.

char* MoreBuffer
static

Definition at line 26 of file moretext.c.

char * MoreLinePtr
static

Definition at line 26 of file moretext.c.

int MoreOn
static

Definition at line 22 of file moretext.c.

int MoreShowed
static

Definition at line 24 of file moretext.c.

char* tmpfn
static

Definition at line 28 of file moretext.c.

FILE* tmpfp
static

Definition at line 27 of file moretext.c.

int UsePopup
static

Definition at line 21 of file moretext.c.