/usr/share/nickle/examples/smlng/context.5c is in nickle 2.77-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | /*
* Copyright © 2001 Keith Packard and Carl Worth
* All Rights Reserved. See the file COPYING in this directory
* for licensing information.
*/
int style_b = 1;
int style_em = 2;
int style_i = 4;
int style_s = 8;
int style_tt = 16;
int[*] colornames = {'r', 'g', 'b', 'c', 'm', 'y', 'k', 'w'};
typedef struct {
int styles;
int underline; /* "root underline" is 0 */
int color; /* "root color" is -1 */
int size; /* "root size" is -1 */
} context;
*context no_context = reference ((context) {});
context root_context = (context) {
.styles=0, .underline=0, .color=-1, .size=-1
};
public exception UnknownColor (int name);
int function color_index_for_name(int n) {
int i;
for (i=0; i<dim(colornames); i++)
if (colornames[i] == n)
return i;
raise UnknownColor (n);
}
function context_set (*context c, string value)
{
switch (value) {
case "B":
c->styles |= style_b;
break;
case "EM":
if ((c->styles & style_s) == 0) {
c->styles ^= style_em;
}
break;
case "I":
c->styles |= style_i;
break;
case "PL":
c->styles &= ~(style_s | style_em | style_i | style_b | style_tt);
c->underline = 0;
break;
case "S":
c->styles |= style_s;
c->styles &= ~style_em;
break;
case "TT":
c->styles |= style_tt;
break;
case "U":
if (c->underline < 3) {
c->underline++;
}
break;
default:
if (value[0] >= '0' && value[0] <= '9') {
c->size = string_to_integer(value);
} else {
c->color = color_index_for_name(value[0]);
}
}
}
function context_dump (context c)
{
printf("%s %s %s %s %s %d %s %s ",
(c.styles & style_b) != 0 ? "B" : "-",
(c.styles & style_em) != 0 ? "EM" : "--",
(c.styles & style_i) != 0 ? "I" : "-",
(c.styles & style_s) != 0 ? "S" : "-",
(c.styles & style_tt) != 0 ? "TT" : "--",
c.underline,
(c.color >= 0) ? String::new (colornames[c.color]) : "-",
(c.size >= 0) ? String::new (c.size) : "-");
}
|