~ubuntu-branches/ubuntu/gutsy/funnelweb-doc/gutsy

« back to all changes in this revision

Viewing changes to developer/implement_indentation.html

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2002-03-28 23:21:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020328232107-3d1jiqv1eqmco3j9
Tags: upstream-3.2d
ImportĀ upstreamĀ versionĀ 3.2d

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
 
2
            "http://www.w3.org/TR/REC-html40/loose.dtd">
 
3
 
 
4
<HTML>
 
5
<!--
 
6
***********************************************************************
 
7
FUNNELWEB MANUAL WEB PAGE
 
8
=========================
 
9
Copyright (c) Ross N. Williams 1992,1999. All rights reserved.
 
10
 
 
11
Permission is granted to redistribute and use this manual in
 
12
any medium, with or without modification, provided that all
 
13
notices (including, without limitation, the copyright
 
14
notice, this permission notice, any record of modification,
 
15
and all legal notices) are preserved on all copies, that all
 
16
modifications are clearly marked, and that modified versions
 
17
are not represented as the original version unless all the
 
18
modifications since the manual's original release by Ross N.
 
19
Williams (www.ross.net) consist of translations or other
 
20
transformations that alter only the manual's form, not its
 
21
content. THIS MANUAL IS PROVIDED "AS IS" AND WITHOUT ANY
 
22
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
 
23
LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
 
24
FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT PERMITTED BY
 
25
LAW THERE IS ABSOLUTELY NO WARRANTY.
 
26
 
 
27
***********************************************************************
 
28
-->
 
29
 
 
30
<HEAD>
 
31
<TITLE>3.5 Implementing Text Indentation</TITLE>
 
32
<STYLE TYPE="text/css"> <!-- A {text-decoration: none} // --> </STYLE>
 
33
</HEAD>
 
34
<BODY BACKGROUND="binary/background.gif"
 
35
      BGCOLOR="#FFFFFF"
 
36
      TEXT="#000000"
 
37
      VLINK="#660000"
 
38
      LINK="#FF0000"
 
39
      ALINK="#CC0000">
 
40
 
 
41
<TABLE WIDTH="590">
 
42
<TR>
 
43
<TD WIDTH="130" VALIGN="top">
 
44
<IMG SRC="binary/d_clear.gif" ALT="" WIDTH="130" HEIGHT="1"><BR>
 
45
 
 
46
<FONT SIZE="2">
 
47
<BR>
 
48
 
 
49
<A HREF="http://www.ross.net/"
 
50
 TARGET="rosshome"
 
51
 onClick="window.open('','rosshome','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
 
52
>
 
53
 <IMG SRC="binary/rossnet_logo.gif"
 
54
  WIDTH="64" HEIGHT="32"
 
55
  BORDER="0" ALT="RossNet"
 
56
  HSPACE="0" VSPACE="1"></A><BR>
 
57
<BR>
 
58
 
 
59
<A HREF="../index.shtml"
 
60
 TARGET="funnelweb"
 
61
 onClick="window.open('','funnelweb','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
 
62
>
 
63
 <IMG SRC="binary/linklogo.gif"
 
64
  WIDTH="64" HEIGHT="32"
 
65
  BORDER="0" ALT="FunnelWeb"
 
66
  HSPACE="0" VSPACE="1"></A><BR>
 
67
<BR>
 
68
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD BGCOLOR="#000000">
 
69
<A HREF="../reference/index.html"
 
70
 TARGET="funnelwebreference"
 
71
 onClick="window.open('','funnelwebreference','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
 
72
><FONT COLOR="#FFFFFF"><B>Reference</B></FONT></A><BR>
 
73
<BR>
 
74
<A HREF="../tutorial/index.html"
 
75
 TARGET="funnelwebtutorial"
 
76
 onClick="window.open('','funnelwebtutorial','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
 
77
><FONT COLOR="#FFFFFF"><B>Tutorial</B></FONT></A><BR>
 
78
<BR>
 
79
<A HREF="index.html"><FONT COLOR="#FFFFFF"><B>Developer</B></FONT></A><BR>
 
80
<A HREF="compile.html"><FONT COLOR="#FFFFFF">1 Compile</FONT></A><BR>
 
81
<A HREF="design.html"><FONT COLOR="#FFFFFF">2 Design</FONT></A><BR>
 
82
<A HREF="implement.html"><FONT COLOR="#FFFFFF">3 Implement</FONT></A><BR>
 
83
<A HREF="modify.html"><FONT COLOR="#FFFFFF">4 Modify</FONT></A><BR>
 
84
<A HREF="misc.html"><FONT COLOR="#FFFFFF">5 Misc</FONT></A><BR>
 
85
<A HREF="gpl.html"><FONT COLOR="#FFFFFF">6 Licence</FONT></A><BR>
 
86
 
 
87
<BR>
 
88
<A HREF="search.html"><FONT COLOR="#FFFFFF"><B>SEARCH</B></FONT></A><BR>
 
89
</FONT>
 
90
</TD></TR></TABLE>
 
91
 
 
92
 
 
93
</TD>
 
94
<TD WIDTH="460" VALIGN="top">
 
95
<FONT SIZE="3">
 
96
 
 
97
 
 
98
<A HREF="index.html"><IMG SRC="binary/title.gif"
 
99
 WIDTH="316" HEIGHT="24"
 
100
 BORDER="0" ALT="FunnelWeb Developer Manual"
 
101
 HSPACE="0" VSPACE="0"></A>
 
102
<P><FONT SIZE="5">3.5 Implementing Text Indentation</FONT><BR>
 
103
 
 
104
 
 
105
 
 
106
<P>At one point during the development of FunnelWeb, text
 
107
indentation was fully implemented. However, it was
 
108
subsequently removed because it was considered a dangerous
 
109
feature. This section records the way in which text
 
110
indentation was implemented so that if the feature ever has
 
111
to be put back, this technique can be used again.
 
112
 
 
113
<P>1. Create a new field in the <SAMP>sc_t</SAMP> record call
 
114
<SAMP>sc_postn</SAMP>.
 
115
 
 
116
<P>
 
117
<PRE>
 
118
      char *sc_postn; /* Pointer in the range [sc_first,sc_last+1].           */
 
119
                      /* It is the minimum possible value of sc_postn for     */
 
120
                      /* which EOL does not appear in *sc_postn..*sc_last.    */
 
121
                      /* i.e. Points to the byte following the first EOL in   */
 
122
                      /* the scrap or sc_first if EOL does not appear.        */
 
123
</PRE>
 
124
 
 
125
<P>2. Modify the scanner so that it generates this field.
 
126
Sendtext should be modified so that
 
127
it accepts an argument for the <SAMP>p_postn</SAMP> value.
 
128
 
 
129
<P>
 
130
<PRE>
 
131
LOCAL void sendtext P_((p_ps_t,char *,char *,char *,bool));
 
132
LOCAL void sendtext(p_tkps,p_first,p_last,p_postn,is_white)
 
133
/* Appends a text token to the end of the token list.                         */
 
134
/* IN: p_ps is a pointer to a position structure giving the position of the   */
 
135
/*     first character of the token.                                          */
 
136
/* IN: p_first and p_last point to the first and last byte of the text scrap. */
 
137
/* IN: p_postn has the same definition as sc_postn (see fwdata.h).            */
 
138
/* IN: is_white should be set to TRUE iff scrap is entirely whitespace.       */
 
139
p_ps_t p_tkps;
 
140
char  *p_first;
 
141
char  *p_last;
 
142
char  *p_postn;
 
143
bool   is_white;
 
144
{
 
145
 tk_t token;
 
146
 
 
147
 /* Empty text scraps should never be generated. */
 
148
 assert(p_first&lt;=p_last,"sendtext: Text scrap bounds are bad.");
 
149
 
 
150
 /* If ch=EOL then we should be scanning more text, not shipping it! */
 
151
 assert(ch!=EOL,"senttext: Shipping text while still more to scan.");
 
152
 
 
153
 /* Check that p_postn is in range. See definition in fwdata.h. */
 
154
 assert(p_first&lt;=p_postn && p_postn&lt;=p_last+1,
 
155
        "sendtext: p_postn is out of range.");
 
156
 
 
157
 /* Debug: Check the p_postn field using a brute force check. */
 
158
 {
 
159
  char *i,*j;
 
160
  j=p_first;
 
161
  for (i=p_first;i&lt;=p_last;i++)
 
162
     if (*i==EOL)
 
163
        j=i+1;
 
164
  assert(j==p_postn,"sendtext: sc_postn field is incorrect.");
 
165
 }
 
166
 
 
167
 /* Load the text token. */
 
168
 token.tk_kind        = TK_TEXT;
 
169
 ASSIGN(token.tk_ps,*p_tkps);
 
170
 token.tk_sc.sc_first = p_first;
 
171
 token.tk_sc.sc_last  = p_last;
 
172
 token.tk_sc.sc_postn = p_postn;
 
173
 token.tk_white       = is_white;
 
174
 token.tk_parno       = 0;
 
175
 ls_add(token_list,PV &token);
 
176
}
 
177
</PRE>
 
178
 
 
179
<P>Then all the calls to sendtext have to be changed:
 
180
 
 
181
<PRE>
 
182
/* @ instructs FunnelWeb to replace the special construct with the */
 
183
/* special character. Luckily one appears just before the @ !!     */
 
184
/* Note: FALSE is OK because space is not a legal specialch.       */
 
185
/* Note: Setting parameter p_postn to p_ch-1 is OK as EOL is not a */
 
186
/*       legal specialch.                                          */
 
187
sendtext(ps_spec,p_ch-1,p_ch-1,p_ch-1,FALSE);
 
188
break;
 
189
 
 
190
/* + instructs FunnelWeb to insert an EOL. We can't look to the end of */
 
191
/* the previous line to find an EOL as this might be the first line.   */
 
192
/* Running ahead to the end of the line is expensive, and having the   */
 
193
/* liner mini-package maintain a variable for it would be extra        */
 
194
/* housekeeping. Instead of all this, we just point to a static.       */
 
195
{CONST static char stateol = EOL;
 
196
 sendtext(&ps_spec,&stateol,&stateol,(&stateol)+1,TRUE);}
 
197
break;
 
198
 
 
199
/* If we hit something that ends a text token */
 
200
/* then we can transmit a white text token.   */
 
201
if (ch==specialch || ch==EOFCH)
 
202
   {sendtext(&ps_start,p_first,p_ch-1,MAX(p_sol,p_first),TRUE); return;}
 
203
 
 
204
/* Otherwise we have some more (non-white) text to scan. */
 
205
/* We can then send a non-white text token.              */
 
206
while (ch!=specialch && ch!=EOFCH)
 
207
   NEXTCH;
 
208
sendtext(&ps_start,p_first,p_ch-1,MAX(p_sol,p_first),FALSE);
 
209
</PRE>
 
210
 
 
211
The dump code needs to be changed too!
 
212
 
 
213
<PRE>
 
214
        wf_str(p_wf,"\"");
 
215
assert(token-&gt;tk_sc.sc_first !=NULL,"dm_tkls: NULL ptr1.");
 
216
assert(token-&gt;tk_sc.sc_last  !=NULL,"dm_tkls: NULL ptr2.");
 
217
for (i=token-&gt;tk_sc.sc_first; i&lt;=token-&gt;tk_sc.sc_last; i++)
 
218
  {
 
219
   if (i==token-&gt;tk_sc.sc_postn)
 
220
      wf_str(p_wf,"&lt;postn&gt;");
 
221
   if (*i=='\n')
 
222
      wf_wl(p_wf,"");
 
223
   else
 
224
      dm_byte(p_wf,*((ubyte_ *) i));
 
225
  }
 
226
if (i==token-&gt;tk_sc.sc_postn)
 
227
   wf_str(p_wf,"&lt;postn&gt;");
 
228
wf_str(p_wf,"\"");
 
229
}
 
230
</PRE>
 
231
 
 
232
<P>3. Over in the Tangle module, create a massive array of
 
233
pointers to scraps to be used as a stack. Maintain pointers
 
234
into the stack called <SAMP>current</SAMP> and <I>base</I>&nbsp;
 
235
(similar to the blank indentation variables). Implement the
 
236
following:
 
237
 
 
238
<P>
 
239
<UL>
 
240
 
 
241
<LI> To write out a scrap, scan it byte by byte. Output
 
242
each byte. When you hit an EOL, pop the stack back to
 
243
<SAMP>base</SAMP>. Then write out an EOL followed by the stack
 
244
contents but writing each scrap only from <SAMP>postn</SAMP> to
 
245
end end of each scrap. When you have finished the new scrap,
 
246
push it on the stack.
 
247
 
 
248
<LI> When you hit a new macro to expand, save
 
249
<SAMP>base</SAMP>. Restore it later.
 
250
 
 
251
</UL>
 
252
 
 
253
<P>The <SAMP>postn</SAMP> field solves the big problem of how
 
254
to cope with something like this:
 
255
 
 
256
<P>
 
257
<PRE>
 
258
The rain in Spain
 
259
falls mainly @&lt;on the plain@&gt;
 
260
</PRE>
 
261
 
 
262
<P>The trouble is that we want to text indent the lines in
 
263
<SAMP>@&lt;on the plain@&gt;</SAMP> with just "<TT>falls
 
264
                                                   mainly&nbsp;</TT>". However, this string is only part of a scrap. The
 
265
solution is to get the scanner to record, in the
 
266
<SAMP>postn</SAMP> field of each scrap, the position of the
 
267
first byte with a EOL-free run to the end of the scrap.
 
268
 
 
269
<P>This scheme is very efficient because all we are doing
 
270
is pushing and popping pointers to scraps on a stack array.
 
271
The main disadvantage is that the array must necessarily be
 
272
finite and would impose a limit on the depth of indentation
 
273
nesting.
 
274
 
 
275
 
 
276
<P>
 
277
<TABLE WIDTH="100%">
 
278
<TR>
 
279
<TD ALIGN="left"   VALIGN="bottom"><A HREF="implement_memory.html"><IMG SRC="binary/fw_left.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Prev"></A></TD>
 
280
<TD ALIGN="center" VALIGN="bottom"><A HREF="implement.html"><IMG SRC="binary/fw_up.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Up"></A></TD>
 
281
<TD ALIGN="right"  VALIGN="bottom"><A HREF="implement.html"><IMG SRC="binary/fw_up.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Up"></A></TD>
 
282
</TR>
 
283
</TABLE>
 
284
 
 
285
 
 
286
 
 
287
<P>
 
288
<HR>
 
289
<FONT SIZE="2">
 
290
<A HREF="mailto:webmaster@ross.net">Webmaster</A>&nbsp;&nbsp;&nbsp;
 
291
<A HREF="copyright.html">Copyright &copy; Ross N. Williams 1992,1999. All rights reserved.</A><BR>
 
292
</FONT>
 
293
 
 
294
</FONT>
 
295
</TD>
 
296
</TR>
 
297
</TABLE>
 
298
 
 
299
 
 
300
</BODY>
 
301
 
 
302
<!-- *********************************************************************** -->
 
303
<!--      End Of A FunnelWeb Manual Web Page (www.ross.net/funnelweb/)       -->
 
304
<!-- *********************************************************************** -->
 
305
 
 
306
</HTML>