1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
2
"http://www.w3.org/TR/REC-html40/loose.dtd">
6
***********************************************************************
7
FUNNELWEB MANUAL WEB PAGE
8
=========================
9
Copyright (c) Ross N. Williams 1992,1999. All rights reserved.
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.
27
***********************************************************************
31
<TITLE>3.5 Implementing Text Indentation</TITLE>
32
<STYLE TYPE="text/css"> <!-- A {text-decoration: none} // --> </STYLE>
34
<BODY BACKGROUND="binary/background.gif"
43
<TD WIDTH="130" VALIGN="top">
44
<IMG SRC="binary/d_clear.gif" ALT="" WIDTH="130" HEIGHT="1"><BR>
49
<A HREF="http://www.ross.net/"
51
onClick="window.open('','rosshome','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
53
<IMG SRC="binary/rossnet_logo.gif"
54
WIDTH="64" HEIGHT="32"
55
BORDER="0" ALT="RossNet"
56
HSPACE="0" VSPACE="1"></A><BR>
59
<A HREF="../index.shtml"
61
onClick="window.open('','funnelweb','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
63
<IMG SRC="binary/linklogo.gif"
64
WIDTH="64" HEIGHT="32"
65
BORDER="0" ALT="FunnelWeb"
66
HSPACE="0" VSPACE="1"></A><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>
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>
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>
88
<A HREF="search.html"><FONT COLOR="#FFFFFF"><B>SEARCH</B></FONT></A><BR>
94
<TD WIDTH="460" VALIGN="top">
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>
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.
113
<P>1. Create a new field in the <SAMP>sc_t</SAMP> record call
114
<SAMP>sc_postn</SAMP>.
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. */
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.
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. */
147
/* Empty text scraps should never be generated. */
148
assert(p_first<=p_last,"sendtext: Text scrap bounds are bad.");
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.");
153
/* Check that p_postn is in range. See definition in fwdata.h. */
154
assert(p_first<=p_postn && p_postn<=p_last+1,
155
"sendtext: p_postn is out of range.");
157
/* Debug: Check the p_postn field using a brute force check. */
161
for (i=p_first;i<=p_last;i++)
164
assert(j==p_postn,"sendtext: sc_postn field is incorrect.");
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;
175
ls_add(token_list,PV &token);
179
<P>Then all the calls to sendtext have to be changed:
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);
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);}
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;}
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)
208
sendtext(&ps_start,p_first,p_ch-1,MAX(p_sol,p_first),FALSE);
211
The dump code needs to be changed too!
215
assert(token->tk_sc.sc_first !=NULL,"dm_tkls: NULL ptr1.");
216
assert(token->tk_sc.sc_last !=NULL,"dm_tkls: NULL ptr2.");
217
for (i=token->tk_sc.sc_first; i<=token->tk_sc.sc_last; i++)
219
if (i==token->tk_sc.sc_postn)
220
wf_str(p_wf,"<postn>");
224
dm_byte(p_wf,*((ubyte_ *) i));
226
if (i==token->tk_sc.sc_postn)
227
wf_str(p_wf,"<postn>");
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>
235
(similar to the blank indentation variables). Implement the
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.
248
<LI> When you hit a new macro to expand, save
249
<SAMP>base</SAMP>. Restore it later.
253
<P>The <SAMP>postn</SAMP> field solves the big problem of how
254
to cope with something like this:
259
falls mainly @<on the plain@>
262
<P>The trouble is that we want to text indent the lines in
263
<SAMP>@<on the plain@></SAMP> with just "<TT>falls
264
mainly </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.
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
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>
290
<A HREF="mailto:webmaster@ross.net">Webmaster</A>
291
<A HREF="copyright.html">Copyright © Ross N. Williams 1992,1999. All rights reserved.</A><BR>
302
<!-- *********************************************************************** -->
303
<!-- End Of A FunnelWeb Manual Web Page (www.ross.net/funnelweb/) -->
304
<!-- *********************************************************************** -->