plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

t11.c (1274B)


      1 #include "a.h"
      2 
      3 /*
      4  * 11. Local Horizontal and Vertical Motions, and the Width Function.
      5  */
      6 
      7 int
      8 e_0(void)
      9 {
     10 	/* digit-width space */
     11 	return ' ';
     12 }
     13 
     14 int
     15 dv(int d)
     16 {
     17 	Rune sub[6];
     18 
     19 	d += getnr(L(".dv"));
     20 	nr(L(".dv"), d);
     21 
     22 	runestrcpy(sub, L("<sub>"));
     23 	sub[0] = Ult;
     24 	sub[4] = Ugt;
     25 	if(d < 0){
     26 		sub[3] = 'p';
     27 		ihtml(L(".dv"), sub);
     28 	}else if(d > 0)
     29 		ihtml(L(".dv"), sub);
     30 	else
     31 		ihtml(L(".dv"), nil);
     32 	return 0;
     33 }
     34 
     35 int
     36 e_v(void)
     37 {
     38 	dv(eval(getqarg()));
     39 	return 0;
     40 }
     41 
     42 int
     43 e_u(void)
     44 {
     45 	dv(eval(L("-0.5m")));
     46 	return 0;
     47 }
     48 
     49 int
     50 e_d(void)
     51 {
     52 	dv(eval(L("0.5m")));
     53 	return 0;
     54 }
     55 
     56 int
     57 e_r(void)
     58 {
     59 	dv(eval(L("-1m")));
     60 	return 0;
     61 }
     62 
     63 int
     64 e_h(void)
     65 {
     66 	getqarg();
     67 	return 0;
     68 }
     69 
     70 int
     71 e_w(void)
     72 {
     73 	Rune *a;
     74 	Rune buf[40];
     75 	static Rune zero;
     76 
     77 	a = getqarg();
     78 	if(a == nil){
     79 		warn("no arg for \\w");
     80 		a = &zero;
     81 	}
     82 	runesnprint(buf, sizeof buf, "%ld", runestrlen(a));
     83 	pushinputstring(buf);
     84 	nr(L("st"), 0);
     85 	nr(L("sb"), 0);
     86 	nr(L("ct"), 0);
     87 	return 0;
     88 }
     89 
     90 int
     91 e_k(void)
     92 {
     93 	getname();
     94 	warn("%Ck not available", backslash);
     95 	return 0;
     96 }
     97 
     98 void
     99 t11init(void)
    100 {
    101 	addesc('|', e_nop, 0);
    102 	addesc('^', e_nop, 0);
    103 	addesc('v', e_v, 0);
    104 	addesc('h', e_h, 0);
    105 	addesc('w', e_w, 0);
    106 	addesc('0', e_0, 0);
    107 	addesc('u', e_u, 0);
    108 	addesc('d', e_d, 0);
    109 	addesc('r', e_r, 0);
    110 	addesc('k', e_k, 0);
    111 }