~ubuntu-branches/ubuntu/gutsy/inform/gutsy

« back to all changes in this revision

Viewing changes to include/znsi.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Baker
  • Date: 2004-03-29 23:52:44 UTC
  • Revision ID: james.westby@ubuntu.com-20040329235244-fox1z1yv7d6vojoo
Tags: upstream-6.30
ImportĀ upstreamĀ versionĀ 6.30

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
2
!                                    A control-code add on system for 
 
3
!   ZNSI                             istring.h
 
4
! Version 1                          by L. Ross Raszewski
 
5
!
 
6
! A brief explanation:
 
7
!  I was coding up an array of stings to be printed by a function in a game I
 
8
!  was writng, when it occured to me that I wanted to used colored text, and, 
 
9
!  unfortunately, Inform requires the unsightly kludge of doing this:
 
10
!  print "The last word in this sentence should be in ";
 
11
!  @set_colour 3 0;
 
12
!  print "red";
 
13
!  @set_colour 1 0;
 
14
!  print "."
 
15
!  So, I decided to write a library that would let me abbreviate control codes
 
16
!  in the text of a string.  Hence ZNSI.
 
17
!  ZNSI is a set of control sequences which may be inserted into a string and
 
18
!  and run at print-time.  It uses the string-printing facilities of the
 
19
!  Istring library.
 
20
!  In order to print a sequence of control characters, use the function 
 
21
!  LPrintString (or Printstring, for string arrays). The following 
 
22
!  control sequences have been defined: (all sequences start with the
 
23
!  character '[' and are case sensitive)
 
24
!  Sequence:    Effect:                 Sequence:  Effect:
 
25
!  "[N"         default font and color  "[7"       Foreground: Magenta
 
26
!  "[B"         Bold font               "[8"       Foreground: Cyan
 
27
!  "[U"         Underline font          "[9"       Foreground: White
 
28
!  "[R"         Reverse font            "[d"       Background: Default
 
29
!  "[F"         Monospace font          "[r"       Background: red
 
30
!  "[f"         Proportional font       "[g"       Background: green
 
31
!  "[1"         Foreground: default     "[y"       Background: Yellow
 
32
!  "[2"         Foreground: black       "[l"       Background: Blue
 
33
!  "[3"         Foreground: Red         "[m"       Background: Magenta
 
34
!  "[4"         Foreground: Green       "[c"       Background: Cyan
 
35
!  "[5"         Foreground: Yellow      "[w"       Background: White
 
36
!  "[6"         Foreground: Blue        "[b"       Background: Black
 
37
!  "[["         Print the character '[' 
 
38
!
 
39
! So, the above example would become:
 
40
! LPrintString("The last word of this sentence should be in [3red[1.");
 
41
!
 
42
! Other examples:
 
43
! To print:
 
44
!   Some words are *bold*, while others are [bracketed].
 
45
! do this:
 
46
! LPrintString("Some words are [Bbold[N, while others are [[bracketed].");
 
47
!
 
48
! Any invalid control sequence will be printed without the '[' delimiter,
 
49
! so LPrintString("[A New Day]"); would print:
 
50
!   A New Day]
 
51
!
 
52
! StrLen and Lstrlen will return the number of non-control characters in
 
53
! a string.
 
54
!
 
55
! This file must be included BEFORE  Istring.h in order to work properly.
 
56
! If you are including utility.h, include it BEFORE this library,
 
57
! otherwise ZNSI will redefine the Emphasis function.
 
58
!
 
59
! Let me know what you think.  I'm also accepting suggestions for new
 
60
! control codes...
 
61
! rraszews@acm.org
 
62
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
63
system_file;
 
64
Default NORMAL 0;
 
65
Default BOLD   1;
 
66
Default UNDERLINE 2;
 
67
Default REVERSE 4;
 
68
 
 
69
 
 
70
Constant ZNSI_Symbols 22;
 
71
Array ZNSI --> 'N' Emphasis 0
 
72
               'B' Emphasis BOLD
 
73
               'U' Emphasis UNDERLINE
 
74
               'R' Emphasis REVERSE
 
75
               'F' SetFont  1
 
76
               'f' SetFont  0
 
77
               '1' SetCol   1
 
78
               '2' SetCol   2
 
79
               '3' SetCol   3
 
80
               '4' SetCol   4
 
81
               '5' SetCol   5
 
82
               '7' SetCol   7
 
83
               '8' SetCol   8
 
84
               '6' SetCol   6
 
85
               '9' SetCol   9
 
86
               'd' SetBCol  1
 
87
               'b' SetBCol  2
 
88
               'r' SetBCol  3
 
89
               'g' SetBCol  4
 
90
               'y' SetBCol  5
 
91
               'l' SetBCol  6
 
92
               'm' SetBCol  7
 
93
               'c' SetBCol  8
 
94
               'w' SetBCol  9;
 
95
 
 
96
[ ZNSI_Lookup char j;
 
97
  for(j=0:j<ZNSI_Symbols:j++)
 
98
   if (char==ZNSI-->(3*j))
 
99
     return (3*j)+1;
 
100
  rfalse;
 
101
];
 
102
 
 
103
Ifndef Emphasis;
 
104
[ Emphasis n;
 
105
switch(n){
 
106
0: style roman; 
 
107
   @set_colour 1 1;
 
108
1: style bold;
 
109
2: style underline;
 
110
4: style reverse;
 
111
}
 
112
];
 
113
Endif;
 
114
 
 
115
 
 
116
[ PrintString str i j;
 
117
   for(:i<(str-->0):i++)
 
118
   {
 
119
    if (str->(i+2)=='['){
 
120
     @sound_effect 3;
 
121
     i++;
 
122
     j=ZNSI_Lookup(str->(i+2));
 
123
     if (j>0) indirect(ZNSI-->j,ZNSI-->(j+1));
 
124
     else print (char) str->(i+2);
 
125
    } else
 
126
    print (char) str->(i+2);
 
127
   }
 
128
   return i-2;
 
129
];
 
130
 
 
131
[ StrLen Str i k;
 
132
   for(:i<(str-->0):i++)
 
133
   {
 
134
    if (str->(i+2)=='['){
 
135
     i++;
 
136
     if (ZNSI_Lookup(str->(i+2))<=0) k++;
 
137
    } else k++;
 
138
   }
 
139
  return k;
 
140
];
 
141
         
 
142
[ Justify str width align pad_chr i;
 
143
   EmptyString(StringBuffer2,width+Zchars(str),pad_chr);
 
144
   i=StrLen(str);
 
145
   if (align==LEFT or 0) i=0;
 
146
   else if (align==RIGHT) i=width-i;
 
147
   else if (align==CENTERED) i=(width-i)/2;
 
148
   StrCpy(StringBuffer2,str,i);
 
149
   StringBuffer2-->0=width+Zchars(str);
 
150
   PrintString(StringBuffer2);
 
151
];
 
152
[ ZChars Str i k;
 
153
   for(:i<(str-->0):i++)
 
154
    if (str->(i+2)=='['){
 
155
     k++; i++;
 
156
     if (ZNSI_Lookup(str->(i+2))>0) k++;
 
157
   }
 
158
  return k;
 
159
];
 
160
[ SetFont i;
 
161
 if (i) font off;
 
162
 else font on;
 
163
];
 
164
 
 
165
[ SetCol i;
 
166
  if ((0->1)&1)  @set_colour i 0;
 
167
];
 
168
[ SetBCol i;
 
169
  if ((0->1)&1)  @set_colour 0 i;
 
170
];