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

##### Functions

    adj               X
    adjleft           X
    adjright          X
    centre            X
    character         X
    charval           X
    concat            X
    concato           X
    convert           X
    mk_text           X
    repeat            X
    strval            X
    trim              X

##### Macros

    Centre            X
    Left              X
    Right             X

       1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
       2: /* $Header: B1tex.c,v 1.1 84/06/28 00:48:59 timo Exp $ */
       3:
       4: /* B texts */
       5: #include "b.h"
       6: #include "b1obj.h"
       7: #include "B1tlt.h" /* for Cts */
       8:
       9: Visible value mk_text(m) string m; {
      10:     value v; intlet len= strlen(m);
      11:     v= grab_tex(len);
      12:     strcpy(Str(v), m);
      13:     return v;
      14: }
      15:
      16: Visible bool character(v) value v; {
      17:     if (Is_text(v) && Length(v) == 1) return Yes;
      18:     else return No;
      19: }
      20:
      21: Visible char charval(v) value v; {
      22:     if (!Is_text(v) || Length(v) != 1) error("value not a character");
      23:     return *Str(v);
      24: }
      25:
      26: Visible string strval(v) value v; {
      27:     return Str(v);
      28: }
      29:
      30: Visible value concat(s, t) value s, t; {
      31:     value c;
      32:     if (s->type != Tex) error("in t^u, t is not a text");
      33:     else if (t->type != Tex) error("in t^u, t is a text, but u is not");
      34:     c= grab_tex(Length(s)+Length(t));
      35:     strcpy(Str(c), Str(s)); strcpy(Str(c)+Length(s), Str(t));
      36:     return c;
      37: }
      38:
      39: Hidden Procedure concato(s, t) value *s; string t; {
      40:     if ((*s)->type != Tex) error("attempt to join text with non-text");
      41:     xtndtex(s, strlen(t));
      42:     strcat(Str(*s), t);
      43: }
      44:
      45: Visible value trim(v, B, C) value v; intlet B, C; {
      46:     intlet len= Length(v), k; value w;
      47:     string vp= Str(v)+B, wp;
      48:     if (v->type != Tex) error("trim (@ or |) applied to non-text");
      49:     if (B < 0 || C < 0 || B+C > len)
      50:         error("trim (@ or |) out of bounds");
      51:     w= grab_tex(len-=(B+C)); wp= Str(w);
      52:     Overall *wp++= *vp++; *wp= '\0';
      53:     return w;
      54: }
      55:
      56: Visible value repeat(x, y) value x, y; {
      57:     value r; intlet i= propintlet(intval(y)); intlet xl= Length(x), p, q;
      58:     string rp, xp;
      59:     if (x->type != Tex) error("in t^^n, t is not a text");
      60:     if (i < 0) error("in t^^n, n is negative");
      61:     r= grab_tex(propintlet(i*xl)); rp= Str(r);
      62:     for (p= 0; p < i; p++) {
      63:         xp= Str(x);
      64:         for (q= 0; q < xl; q++) *rp++= *xp++;
      65:     }
      66:     *rp= '\0';
      67:     return r;
      68: }
      69:
      70: #define Left 'L'
      71: #define Right 'R'
      72: #define Centre 'C'
      73:
      74: Hidden value adj(x, y, side) value x, y; literal side; {
      75:     value r, v= convert(x, Yes, Yes); int i= intval(y);
      76:     intlet lv= Length(v), la, k, ls, rs;
      77:     string rp, vp;
      78:     la= propintlet(i) - lv;
      79:     if (la <= 0) return v;
      80:     r= grab_tex(lv+la); rp= Str(r); vp= Str(v);
      81:
      82:     if (side == Left) { ls= 0; rs= la; }
      83:     else if (side == Centre) { ls= la/2; rs= (la+1)/2; }
      84:     else { ls= la; rs= 0; }
      85:
      86:     for (k= 0; k < ls; k++) *rp++= ' ';
      87:     for (k= 0; k < lv; k++) *rp++= *vp++;
      88:     for (k= 0; k < rs; k++) *rp++= ' ';
      89:     *rp= 0;
      90:     release(v);
      91:     return r;
      92: }
      93:
      94: Visible value adjleft(x, y) value x, y; {
      95:     return adj(x, y, Left);
      96: }
      97:
      98: Visible value centre(x, y) value x, y; {
      99:     return adj(x, y, Centre);
     100: }
     101:
     102: Visible value adjright(x, y) value x, y; {
     103:     return adj(x, y, Right);
     104: }
     105:
     106: /* For reasons of efficiency, wri does not always call convert but writes
     107:    directly on the standard output. Modifications in convert should
     108:    be mirrored by changes in wri and vice versa. */
     109:
     110: Visible value convert(v, coll, outer) value v; bool coll, outer; {
     111:     literal type= v->type; intlet len= Length(v), k; value *vp= Ats(v);
     112:     value t, cv;
     113:     switch (type) {
     114:     case Num:
     115:         return mk_text(convnum(v));
     116:     case Tex:
     117:         if (outer) return copy(v);
     118:         else {string tp= (string) vp; char cs[2];
     119:             cs[1]= '\0';
     120:             t= mk_text("'");
     121:             Overall {
     122:                 cs[0]= *tp++;
     123:                 concato(&t, cs);
     124:                 if (cs[0] == '\'' || cs[0] == '`')
     125:                     concato(&t, cs);
     126:             }
     127:             concato(&t, "'");
     128:             return t;
     129:         }
     130:     case Com:
     131:         outer&= coll;
     132:         t= mk_text(coll ? "" : "(");
     133:         Overall {
     134:             concato(&t, Str(cv= convert(*vp++, No, outer)));
     135:             release(cv);
     136:             if (k != len-1) concato(&t, outer ? " " : ", ");
     137:         }
     138:         if (!coll) concato(&t, ")");
     139:         return t;
     140:     case Lis: case ELT:
     141:         t= mk_text("{");
     142:         Overall {
     143:             concato(&t, Str(cv= convert(*vp++, No, No)));
     144:             release(cv);
     145:             if (k != len-1) concato(&t, "; ");
     146:         }
     147:         concato(&t, "}");
     148:         return t;
     149:     case Tab:
     150:         t= mk_text("{");
     151:         Overall {
     152:             concato(&t, "[");
     153:             concato(&t, Str(cv= convert(Cts(*vp), Yes, No)));
     154:             release(cv);
     155:             concato(&t, "]: ");
     156:             concato(&t, Str(cv= convert(Dts(*vp++), No, No)));
     157:             release(cv);
     158:             if (k != len-1) concato(&t, "; ");
     159:         }
     160:         concato(&t, "}");
     161:         return t;
     162:     default:
     163:         syserr("converting value of unknown type");
     164:         return (value) Dummy;
     165:     }
     166: }

#### Defined functions

adj defined in line 74; used 3 times

- in line 95-103(3)

adjleft defined in line 94; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 71

adjright defined in line 102; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 73

centre defined in line 98; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 72

character defined in line 16; used 3 times

- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 59
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 440-445(2)

charval defined in line 21; used 8 times

- in /usr/src/new/PORT/B/src/bsmall/B1lis.c line 72(2)
- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 62
- in /usr/src/new/PORT/B/src/bsmall/b2err.c line 51
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 447(2)
- in /usr/src/new/PORT/B/src/bsmall/b2fil.c line 109
- in /usr/src/new/PORT/B/src/bsmall/b2scr.c line 132

concat defined in line 30; used 11 times

- in /usr/src/new/PORT/B/src/bsmall/B1obj.c line 20-22(3)
- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 65
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 362, 376
- in /usr/src/new/PORT/B/src/bsmall/b2fil.c line 137-139(3)
- in /usr/src/new/PORT/B/src/bsmall/b2loc.c line 97-98(2)

concato defined in line 39; used 15 times

- in line 123-127(3), 134-160(12)

convert defined in line 110; used 10 times

- in line 75, 134, 143, 153-156(2)
- in /usr/src/new/PORT/B/src/bsmall/B1obj.c line 21-23(2)
- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 75
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 402
- in /usr/src/new/PORT/B/src/bsmall/b2fil.c line 139

mk_text defined in line 9; used 30 times

- in line 115-120(2), 132, 141, 150
- in /usr/src/new/PORT/B/src/bsmall/B1lis.c line 77
- in /usr/src/new/PORT/B/src/bsmall/B1obj.c line 20-22(2)
- in /usr/src/new/PORT/B/src/bsmall/B1tlt.c line 77, 113, 205
- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 61
- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 73, 155
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 360-362(2)
- in /usr/src/new/PORT/B/src/bsmall/b2fil.c line 70, 131-135(2)
- in /usr/src/new/PORT/B/src/bsmall/b2fpr.c line 87, 102, 163, 193
- in /usr/src/new/PORT/B/src/bsmall/b2mai.c line 69
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 408, 461-465(2)
- in /usr/src/new/PORT/B/src/bsmall/b2typ.c line 47, 60
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 541

repeat defined in line 56; used 1 times

- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 69

strval defined in line 26; used 14 times

- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 63
- in /usr/src/new/PORT/B/src/bsmall/b2cmd.c line 447
- in /usr/src/new/PORT/B/src/bsmall/b2fil.c line 51, 95, 118-121(2), 161
- in /usr/src/new/PORT/B/src/bsmall/b2sou.c line 46, 94, 231, 252, 392, 434
- in /usr/src/new/PORT/B/src/bsmall/b2uni.c line 175

trim defined in line 45; used 6 times

- in /usr/src/new/PORT/B/src/bsmall/b1obj.h line 68
- in /usr/src/new/PORT/B/src/bsmall/b2exp.c line 263
- in /usr/src/new/PORT/B/src/bsmall/b2fil.c line 144
- in /usr/src/new/PORT/B/src/bsmall/b2loc.c line 95-96(2)
- in /usr/src/new/PORT/B/src/bsmall/b2tes.c line 192

#### Defined macros

Centre defined in line 72; used 2 times

- in line 83, 99

Left defined in line 70; used 2 times

- in line 82, 95

Right defined in line 71; used 1 times

- in line 103

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