Jspice3
output.c File Reference
#include "spice.h"
#include "cpdefs.h"
#include "scedio.h"
#include <varargs.h>
#include "suffix.h"
Include dependency graph for output.c:

Go to the source code of this file.

Macros

#define SHORT_SCEDIO
 
#define DEF_SCRHEIGHT   24
 
#define DEF_SCRWIDTH   80
 
#define bufputc(c)
 
#define MAXLEN   4096
 

Functions

static void outbufputc ()
 
static int fbufputc ()
 
static void promptreturn ()
 
void out_winsize (int *cols, int *rows)
 
void out_init ()
 
static int fbufputc (unsigned char c)
 
void out_send (char *string)
 
void out_printf (va_alist)
 
void out_wlprint (wordlist *wl)
 

Variables

bool out_moremode = true
 
bool out_isatty = true
 
int out_width
 
int out_height
 
static int xsize
 
static int ysize
 
static int xpos
 
static int ypos
 
static bool noprint
 
static bool nopause
 
static char staticbuf [BUFSIZ]
 
struct {
   int   count
 
   char *   ptr
 
ourbuf = { BUFSIZ, staticbuf }
 

Macro Definition Documentation

#define bufputc (   c)
Value:
( --ourbuf.count >= 0 ? ((int) \
(*ourbuf.ptr++ = (unsigned)(c))) : fbufputc((unsigned) (c)))
struct @17 ourbuf
static int fbufputc()
static double c
Definition: vectors.c:16

Definition at line 169 of file output.c.

#define DEF_SCRHEIGHT   24

Definition at line 31 of file output.c.

#define DEF_SCRWIDTH   80

Definition at line 32 of file output.c.

#define MAXLEN   4096

Definition at line 297 of file output.c.

#define SHORT_SCEDIO

Definition at line 16 of file output.c.

Function Documentation

static int fbufputc ( )
static
static int fbufputc ( unsigned char  c)
static

Definition at line 174 of file output.c.

177 {
178 
179  ourbuf.count = 0;
180  outbufputc();
181  ourbuf.count = BUFSIZ;
182  ourbuf.ptr = staticbuf;
183  bufputc(c);
184 
185 }
static void outbufputc()
Definition: output.c:159
struct @17 ourbuf
Definition: cddefs.h:177
#define bufputc(c)
Definition: output.c:169
static char staticbuf[BUFSIZ]
Definition: output.c:150
void out_init ( )

Definition at line 128 of file output.c.

129 {
130  bool moremode;
131 
132  noprint = nopause = false;
133 
134  if (!out_moremode || !cp_interactive)
135  out_isatty = false;
136 
137  if (!out_isatty)
138  return;
139 
141  ysize -= 2; /* Fudge room... */
142  xpos = ypos = 0;
143 
144  return;
145 }
static bool noprint
Definition: output.c:51
static int xsize
Definition: output.c:49
void out_winsize(int *cols, int *rows)
Definition: output.c:55
bool out_moremode
Definition: output.c:44
bool out_isatty
Definition: output.c:45
static bool nopause
Definition: output.c:51
bool cp_interactive
Definition: help.c:100
static int ysize
Definition: output.c:49
static int xpos
Definition: output.c:50
static int ypos
Definition: output.c:50
void out_printf ( va_alist  )

Definition at line 321 of file output.c.

323 {
324  va_list args;
325  char *fmt;
326  char buf[MAXLEN];
327 
328  va_start(args);
329  fmt = va_arg(args,char *);
330  (void) vsprintf(buf, fmt, args);
331  va_end(args);
332 
333  out_send(buf);
334  return;
335 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define MAXLEN
Definition: output.c:297
void out_send(char *string)
Definition: output.c:245
void out_send ( char *  string)

Definition at line 245 of file output.c.

248 {
249 
250  if (noprint)
251  return;
252 
253  if (SCEDline(string))
254  return;
255 
256  if (!out_isatty || nopause) {
257  fputs(string, cp_out);
258  return;
259  }
260  while (*string) {
261  switch (*string) {
262  case '\n':
263  xpos = 0;
264  ypos++;
265  break;
266  case '\f':
267  ypos = ysize;
268  xpos = 0;
269  break;
270  case '\t':
271  xpos = xpos / 8 + 1;
272  xpos *= 8;
273  break;
274  default:
275  xpos++;
276  break;
277  }
278  while (xpos >= xsize) {
279  xpos -= xsize;
280  ypos++;
281  }
282  if (ypos >= ysize) {
283  outbufputc(); /* out goes buffer */
284  promptreturn();
285  (void) fflush(cp_out);
286  ypos = xpos = 0;
287  }
288  bufputc(*string); /* we need to buffer these */
289  string++;
290  }
291  (void) outbufputc();
292  return;
293 }
static bool noprint
Definition: output.c:51
static int xsize
Definition: output.c:49
static void outbufputc()
Definition: output.c:159
bool out_isatty
Definition: output.c:45
static bool nopause
Definition: output.c:51
FILE * cp_out
Definition: help.c:101
static int ysize
Definition: output.c:49
static int xpos
Definition: output.c:50
static int ypos
Definition: output.c:50
int SCEDline(char *string)
Definition: scedstub.c:21
#define bufputc(c)
Definition: output.c:169
static void promptreturn()
Definition: output.c:189
void out_winsize ( int *  cols,
int *  rows 
)

Definition at line 55 of file output.c.

58 {
59  int x, y;
60 #ifdef TIOCGWINSZ
61  struct winsize ws;
62 #endif
63  char tbuf[4096], *s;
64 
65  x = y = 0;
66 
67  /* Figure out the screen size. We try, in order, TIOCGSIZE,
68  * tgetent(), and cp_getvar(height). Default is 24 x 80.
69  */
70 
71 #ifdef TIOCGWINSZ
72  if (!x || !y) {
73  (void) ioctl(fileno(stdout), TIOCGWINSZ, (char *) &ws);
74  x = ws.ws_col;
75  y = ws.ws_row;
76  }
77 #endif
78 
79 #ifdef HAVE_TGETENT
80  if (!x || !y) {
81  if ((s = getenv("TERM")) && (tgetent(tbuf, s) != -1)) {
82  x = tgetnum("co");
83  y = tgetnum("li");
84  if ((x <= 0) || (y <= 0))
85  x = y = 0;
86  }
87  }
88 #endif
89 
90  if (!x) {
91  if ((s = getenv("COLS"))) {
92  x = atoi(s);
93  if (x <= 0)
94  x = 0;
95  }
96  }
97 
98  if (!y) {
99  if ((s = getenv("LINES"))) {
100  y = atoi(s);
101  if (y <= 0)
102  y = 0;
103  }
104  }
105 
106  if (!x)
107  if (out_width > 0) x = out_width;
108  if (!y)
109  if (out_height > 0) y = out_height;
110 
111  if (!x)
112  x = DEF_SCRWIDTH;
113  if (!y)
114  y = DEF_SCRHEIGHT;
115 
116  if (cols != NULL)
117  *cols = x;
118  if (rows != NULL)
119  *rows = y;
120 
121  return;
122 }
Definition: cddefs.h:119
#define DEF_SCRWIDTH
Definition: output.c:32
char * getenv(char *c)
Definition: libfuncs.c:106
int out_width
Definition: output.c:46
#define NULL
Definition: spdefs.h:121
int out_height
Definition: output.c:47
#define DEF_SCRHEIGHT
Definition: output.c:31
void out_wlprint ( wordlist wl)

Definition at line 341 of file output.c.

345 {
346  wordlist *wlc = wl_copy(wl);
347 
348  cp_striplist(wlc);
349 
350  for (wl = wlc; wl; wl = wl->wl_next) {
351  out_send(wl->wl_word);
352  if (wl->wl_next)
353  out_send(" ");
354  }
355  wl_free(wlc);
356 }
void wl_free()
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
void cp_striplist()
char * wl_word
Definition: cpstd.h:22
void out_send(char *string)
Definition: output.c:245
wordlist * wl_copy()
static void outbufputc ( )
static

Definition at line 159 of file output.c.

160 {
161  if (ourbuf.count != BUFSIZ) {
162  fputs(staticbuf, cp_out);
163  bzero(staticbuf, BUFSIZ-ourbuf.count);
164  ourbuf.count = BUFSIZ;
165  ourbuf.ptr = staticbuf;
166  }
167 }
struct @17 ourbuf
int bzero(char *ptr, int num)
Definition: string.c:357
FILE * cp_out
Definition: help.c:101
static char staticbuf[BUFSIZ]
Definition: output.c:150
static void promptreturn ( )
static

Definition at line 189 of file output.c.

190 {
191  char buf[16];
192  int attr;
193  char *xx = " -- hit return for more, ? for help -- ";
194  char *menu =
195 "\nPossible responses:\n\
196  q : Discard the rest of the output.\n\
197  c : Continuously print the rest of the output.\n\
198  h,? : Print this help message.\n\
199  other : Print the next page of output.\n";
200 
201 moe:
202  fprintf(cp_out,"\n");
203  attr = getattr();
204  if (cp_out == stdout)
205  cprint(15,xx);
206  else {
207  (void) fprintf(cp_out,xx);
208  (void) fflush(cp_out);
209  }
210  if (cp_in == stdin)
211  *buf = cp_inchar(cp_in);
212  else if (!fgets(buf, 16, cp_in)) {
213  clearerr(cp_in);
214  *buf = 'q';
215  }
216  if (cp_out == stdout)
217  cprint(attr,"\r \r");
218 
219  switch (*buf) {
220  case 'q':
221  noprint = true;
222  break;
223  case 'c':
224  nopause = true;
225  break;
226  case '?':
227  case 'h':
228  if (cp_out = stdout) {
229  cprint(4,menu);
230  cprint(attr," \n"); /* keeps the cursor the attr color */
231  }
232  else {
233  fprintf(cp_out,menu);
234  }
235  goto moe;
236  }
237 }
static bool noprint
Definition: output.c:51
static char buf[MAXPROMPT]
Definition: arg.c:18
int cp_inchar()
static bool nopause
Definition: output.c:51
FILE * cp_out
Definition: help.c:101
FILE * cp_in
Definition: help.c:101
char getattr()
Definition: cprint.c:23
Definition: sced.h:363
void clearerr(FILE *fp)
Definition: libfuncs.c:116
void cprint(int clr, char *buf)
Definition: cprint.c:14

Variable Documentation

int count

Definition at line 152 of file output.c.

bool nopause
static

Definition at line 51 of file output.c.

bool noprint
static

Definition at line 51 of file output.c.

struct { ... } ourbuf
int out_height

Definition at line 47 of file output.c.

bool out_isatty = true

Definition at line 45 of file output.c.

bool out_moremode = true

Definition at line 44 of file output.c.

int out_width

Definition at line 46 of file output.c.

char* ptr

Definition at line 153 of file output.c.

char staticbuf[BUFSIZ]
static

Definition at line 150 of file output.c.

int xpos
static

Definition at line 50 of file output.c.

int xsize
static

Definition at line 49 of file output.c.

int ypos
static

Definition at line 50 of file output.c.

int ysize
static

Definition at line 49 of file output.c.