# 2.11BSD#431 - /usr/src/new/PORT/B/src/bsmall/b2scr.c

##### Functions

    initscr           X
    is_intended       X
    line              X
    newline           X
    putch             X
    re_files          X
    re_screen         X
    redirect          X
    vs_ifile          X
    wri               X
    wri_space         X
    writ              X

##### Variables

    Eof               X
    Eof0              X
    active_reads      X
    at_nwl            X
    cmd_prompt        X
    eg_prompt         X
    filtered          X
    interactive       X
    last_was_text     X
    lwt               X
    outeractive       X
    qn_prompt         X
    raw_prompt        X
    read_interactive  X
    reading           X
    wnwl              X
    woa               X

##### Macros

    LAST_CHANCE       X
    NO_THEN           X
    Putch_sp          X
    USE_YES_OR_NO     X

       1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
       2: /* $Header: b2scr.c,v 1.2 84/07/17 09:51:48 frank Exp $ */
       3:
       4: /* B screen handling */
       5: #include "b.h"
       6: #include "b1obj.h"
       7: #include "b0con.h" /*for CLEAR_EOF*/
       8: #include "b2scr.h"
       9: #include "b2fil.h"
      10:
      11: bool interactive, read_interactive, outeractive, filtered;
      12: bool at_nwl= Yes; /*Yes if currently at the start of an output line*/
      13: bool Eof, Eof0;
      14: FILE *ofile= stdout; bool woa, wnwl;
      15: FILE *ifile;        /* input file */
      16: FILE *sv_ifile;     /* copy of ifile for restoring after switching to read unit */
      17: value iname= Vnil;  /* input name */
      18:
      19: jmp_buf reading[MAX_NMB_ACT_READS];
      20: intlet active_reads;
      21:
      22: string cmd_prompt= ">>> "; /* commands  */
      23: string eg_prompt=  "?\b";  /* READ EG   */
      24: string raw_prompt= "?\b";  /* READ RAW  */
      25: string qn_prompt=  "?\b";  /* questions */
      26:
      27:
      28: #define USE_YES_OR_NO \
      29: "\r*** Answer with yes or no (or use interrupt to duck the question)\n"
      30:
      31: #define LAST_CHANCE \
      32: "*** This is your last chance. Take it. I really don't know what you want if\n\
      33:     %s\n\
      34:     So answer the question\n"
      35:
      36: #define NO_THEN \
      37: "*** Well, I shall assume that your refusal to answer the question means no!\n"
      38:
      39: Visible bool is_intended(m) string m; {
      40:     char answer; intlet try, k;
      41:     if (!interactive) return Yes;
      42:     if (outeractive) line();
      43:     fprintf(stderr, "*** %s\n", m);
      44:     for (try= 1; try<=4; try++){
      45:         answer= '?';
      46:         if (outeractive) at_nwl= No;
      47:         fprintf(stderr, qn_prompt);
      48:         while ((k= getchar()) != EOF && k != '\n') {
      49:             if ((k == ' ' || k == '\t'));
      50:             else if (answer == '?') answer= k;
      51:         }
      52:         if (k == EOF) {
      53:             if (filtered) bye(0); /* Editor has died */
      54:             CLEAR_EOF;
      55:         }
      56:         if (k == EOF && try < 4) {
      57:             fprintf(stderr, USE_YES_OR_NO);
      58:             if (outeractive) at_nwl= Yes;
      59:         } else {
      60:             if (outeractive && k == '\n') at_nwl= Yes;
      61:             if (answer == 'y' || answer == 'Y') return Yes;
      62:             if (answer == 'n' || answer == 'N') return No;
      63:             if (outeractive) line();
      64:             fprintf(stderr,
      65:                 try == 1 ? "*** Please answer with yes or no\n" :
      66:                 try == 2 ? "*** Just yes or no, please\n" :
      67:                 try == 3 ? LAST_CHANCE :
      68:                 NO_THEN, m);
      69:         }
      70:     } /* end for */
      71:     return No;
      72: }
      73:
      74: Visible Procedure redirect(of) FILE *of; {
      75:     ofile= of;
      76:     if (of == stdout) {
      77:         outeractive= woa;
      78:         at_nwl= wnwl;
      79:     } else {
      80:         woa= outeractive; outeractive= No;
      81:         wnwl= at_nwl; at_nwl= Yes;
      82:     }
      83: }
      84:
      85: Hidden Procedure putch(c) char c; {
      86:     putc(c, ofile);
      87:     if (c == '\n') at_nwl= Yes;
      88:     else at_nwl= No;
      89: }
      90:
      91: Visible Procedure newline() {
      92:     putch('\n');
      93:     fflush(stdout);
      94: }
      95:
      96: Visible Procedure line() {
      97:     if (!at_nwl) newline();
      98: }
      99:
     100: Visible Procedure wri_space() { /* Experiment: no space before outer strings */
     101:     if (!at_nwl) putch(' ');
     102: }
     103:
     104: Visible Procedure writ(v) value v; {
     105:     wri(v, Yes, Yes, No);
     106:     fflush(stdout);
     107: }
     108:
     109: #define Putch_sp() {if (!perm) putch(' ');}
     110:
     111: bool lwt, last_was_text= No;
     112:
     113: Visible Procedure wri(v, coll, outer, perm) value v; bool coll, outer, perm; {
     114:     if (outer && !at_nwl && (!Is_text(v) || !last_was_text)
     115:           && (!Is_compound(v) || !coll)) putch(' ');
     116:     lwt= No;
     117:     if (Is_number(v)) {
     118:         if (perm) printnum(ofile, v);
     119:         else {
     120:             string cp= convnum(v);
     121:             while(*cp) putch(*cp++);
     122:         }
     123:     } else if (Is_text(v)) {
     124:         value ch; char c;
     125:         value s= size(v); int k, len;
     126:         if (large(s)) error("text too long to output");
     127:         else { len= intval(s); release(s); }
     128:         lwt= outer;
     129:         if (!outer) putch('\'');
     130:         k_Over_len {
     131:             ch= thof(k+1, v);
     132:             putch(c= charval(ch));
     133:             if (!outer && (c == '\'' || c == '`'))
     134:                 putch(c);
     135:             release(ch);
     136:         }
     137:         if (!outer) putch('\'');
     138:     } else if (Is_compound(v)) {
     139:         intlet k, len= Nfields(v);
     140:         outer&= coll;
     141:         if (!coll) putch('(');
     142:         k_Overfields {
     143:             wri(*field(v, k), No, outer, perm);
     144:             if (!Lastfield(k)) {
     145:                 if (!outer){
     146:                     putch(',');
     147:                     Putch_sp();
     148:                 }
     149:             }
     150:         }
     151:         if (!coll) putch(')');
     152:     } else if (Is_list(v) || Is_ELT(v)) {
     153:         value ve; value s= size(v); int k, len;
     154:         if (large(s)) error("list too big to output");
     155:         else { len= intval(s); release(s); }
     156:         putch('{');
     157:         k_Over_len {
     158:             wri(ve= thof(k+1, v), No, No, perm);
     159:             release(ve);
     160:             if (!Last(k)) {
     161:                 putch(';');
     162:                 Putch_sp();
     163:             }
     164:         }
     165:         putch('}');
     166:     } else if (Is_table(v)) {
     167:         value s= size(v); int k, len;
     168:         if (large(s)) error("table too big to output");
     169:         else { len= intval(s); release(s); }
     170:         putch('{');
     171:         k_Over_len {
     172:             putch('['); wri(*key(v, k), Yes, No, perm);
     173:             putch(']'); putch(':'); Putch_sp();
     174:             wri(*assoc(v, k), No, No, perm);
     175:             if (!Last(k)) {
     176:                 putch(';');
     177:                 Putch_sp();
     178:             }
     179:         }
     180:         putch('}');
     181:     } else {
     182:         if (bugs) { putch('?'); putch(Type(v)); putch('?'); }
     183:         else syserr("writing value of unknown type");
     184:     }
     185:     last_was_text= lwt;
     186: }
     187:
     188: Visible Procedure vs_ifile() {
     189:     ifile= sv_ifile;
     190: }
     191:
     192: Visible Procedure re_files() {
     193:     if (interactive && sv_ifile != ifile) {
     194:         if (ifile != stdin) fclose(ifile);
     195:         vs_ifile();
     196:         Eof= Eof0= No;
     197:     }
     198: }
     199:
     200: Visible Procedure initscr() {
     201:     read_interactive= f_interactive(stdin) || filtered;
     202:     outeractive= f_interactive(stdout) || filtered;
     203: }
     204:
     205: Visible Procedure re_screen() {
     206:     sv_ifile= ifile;
     207:     interactive= f_interactive(ifile) || (ifile == stdin && filtered);
     208: }

#### Defined functions

initscr defined in line 200; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b2mai.c line 107

is_intended defined in line 33; used 3 times

- in /usr/src/new/PORT/B/src/bsmall/b2scr.h line 14
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 88, 153

line defined in line 96; used 5 times

- in line 42, 63
- in /usr/src/new/PORT/B/src/bsmall/B1val.c line 149
- in /usr/src/new/PORT/B/src/bsmall/b2err.c line 26
- in /usr/src/new/PORT/B/src/bsmall/b2syn.c line 214

newline defined in line 91; used 6 times

- in line 97
- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 197, 203, 218
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 341, 437

putch defined in line 85; used 24 times

- in line 92, 101, 109, 115, 121, 129-182(19)

re_files defined in line 192; used 2 times

- in /usr/src/new/PORT/B/src/bsmall/b2mai.c line 118, 133

re_screen defined in line 205; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b2mai.c line 114

redirect defined in line 74; used 2 times

- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 436-439(2)

vs_ifile defined in line 188; used 6 times

- in line 195
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 48, 63, 233, 239, 366

wri defined in line 113; used 8 times

- in line 105, 143, 158, 172-174(2)
- in /usr/src/new/PORT/B/src/bsmall/B1val.c line 149
- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 444
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 437

wri_space defined in line 100; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 339

writ defined in line 104; used 2 times

- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 214
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 338

#### Defined variables

Eof defined in line 13; used 1 times

- in line 196

Eof0 defined in line 13; used 1 times

- in line 196

active_reads defined in line 20; never used
at_nwl defined in line 12; used 11 times

- in line 46, 58-60(2), 78-81(3), 87-88(2), 97-101(2), 114

cmd_prompt defined in line 22; never used
eg_prompt defined in line 23; never used
filtered defined in line 11; used 4 times

- in line 53, 201-207(3)

interactive defined in line 11; used 3 times

- in line 41, 193, 207

last_was_text defined in line 111; used 2 times

- in line 114, 185

lwt defined in line 111; used 3 times

- in line 116, 128, 185

outeractive defined in line 11; used 9 times

- in line 42-46(2), 58-63(3), 77-80(3), 202

qn_prompt defined in line 25; used 1 times

- in line 47

raw_prompt defined in line 24; never used
read_interactive defined in line 11; used 1 times

- in line 201

reading defined in line 19; never used
wnwl defined in line 14; used 2 times

- in line 78-81(2)

woa defined in line 14; used 2 times

- in line 77-80(2)

#### Defined macros

LAST_CHANCE defined in line 31; used 1 times

- in line 67

NO_THEN defined in line 36; used 1 times

- in line 68

Putch_sp defined in line 109; used 4 times

- in line 147, 162, 173-177(2)

USE_YES_OR_NO defined in line 28; used 1 times

- in line 57

Last modified: 1985-08-27 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1310 |