summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
58f9b40)
By default, breaks are no longer allowed between lines in a `prog'
environment. `\\+' introduces some vertical whitespace and allows a
break. `\\-' introduces a little space, but doesn't allow a break.
The following simple mixin class is suggested.
\begin{prog}
The following simple mixin class is suggested.
\begin{prog}
- [nick = disposable] \\*
- class DisposableObject : SodObject \{ \\*[\jot] \ind
- void release() \{ ; \} \\*
- \quad /\=\+* Release resources held by the receiver. */ \-\- \\*[\jot]
- \} \\[\bigskipamount]
- code c : user \{ \\* \ind
- /\=\+* Free object p's instance storage. If p is a DisposableObject \\*
- {}* then release its resources beforehand. \\*
- {}*/ \- \\*
- void free_instance(void *p) \\*
- \{ \\* \ind
- DisposableObject *d = SOD_CONVERT(DisposableObject, p); \\*
- if (d) DisposableObject_release(d); \\*
- free(d); \- \\*
- \} \- \\*
+ [nick = disposable] \\
+ class DisposableObject : SodObject \{ \\- \ind
+ void release() \{ ; \} \\
+ \quad /* Release resources held by the receiver. */ \- \\-
+ \}
+ \\+
+ code c : user \{ \\- \ind
+ /\=\+* Free object p's instance storage. If p is a DisposableObject \\
+ {}* then release its resources beforehand. \\
+ {}*/ \- \\
+ void free_instance(void *p) \\
+ \{ \\ \ind
+ DisposableObject *d = SOD_CONVERT(DisposableObject, p); \\
+ if (d) DisposableObject_release(d); \\
+ free(d); \- \\
+ \} \- \\
%% Environment for setting programs. Newlines are explicit, because
%% otherwise I need comments in weird places to make the vertical spacing
%% come out properly. You can write `\obeylines' if you really want to.
%% Environment for setting programs. Newlines are explicit, because
%% otherwise I need comments in weird places to make the vertical spacing
%% come out properly. You can write `\obeylines' if you really want to.
-\def\prog{\codeface\quote\tabbing}
+\def\prog{\let\prog@@cr\@tabcr\let\@tabcr\@progcr\codeface\quote\tabbing}
\def\endprog{\endtabbing\endquote}
\def\ind{\quad\=\+\kill}
\def\endprog{\endtabbing\endquote}
\def\ind{\quad\=\+\kill}
+\def\@progcr{\futurelet\@tempa\@progcr@i}
+{\def\:{\gdef\@progcr@sp}\: {\@progcr}}
+\def\@progcr@i{%
+ \ifx\@tempa\@sptoken\let\next@\@progcr@sp\else
+ \if1\ifx\@tempa[1\else
+ \ifx\@tempa*1\else
+ 0\fi\fi
+ \let\next@\prog@@cr\else
+ \if1\ifx\@tempa+1\else
+ \ifx\@tempa-1\else
+ 0\fi\fi
+ \let\next@\@progcr@ii\else
+ \let\next@\@progcr@a\fi\fi\fi
+ \next@}
+\def\@progcr@a{\prog@@cr*{}\ignorespaces}
+\def\@progcr@ii#1{\csname @progcr@#1\endcsname\ignorespaces}
+\@namedef{@progcr@+}{\prog@@cr[\medskipamount]}
+\@namedef{@progcr@-}{\prog@@cr*[\jot]}
%% Put a chunk of text in a box.
\newenvironment{boxy}[1][\q@]{%
%% Put a chunk of text in a box.
\newenvironment{boxy}[1][\q@]{%
\if@nobreak\else\par\goodbreak\fi%
\global\@dheadfirsttrue%
\begingroup%
\if@nobreak\else\par\goodbreak\fi%
\global\@dheadfirsttrue%
\begingroup%
\let\@endparenv\relax%
\clubpenalty\@M \widowpenalty\@M \interlinepenalty50%
\let\@endparenv\relax%
\clubpenalty\@M \widowpenalty\@M \interlinepenalty50%
\endgroup%
\penalty\@M\@afterheading%
\list{}{\rightmargin\z@\topsep\z@}\item%
\endgroup%
\penalty\@M\@afterheading%
\list{}{\rightmargin\z@\topsep\z@}\item%
union $B$__ichainu_$i$ $i$; \\
\quad$\vdots$ \- \\
\};
union $B$__ichainu_$i$ $i$; \\
\quad$\vdots$ \- \\
\};
typedef struct $C$__ichain_$h$ $C$;
\end{prog}
typedef struct $C$__ichain_$h$ $C$;
\end{prog}
\quad$\vdots$ \- \\
\} $c$; \- \\
\};
\quad$\vdots$ \- \\
\} $c$; \- \\
\};
extern const union $C$__vtu_$h$ $C$__vtable_$h$;
\end{prog}
extern const union $C$__vtu_$h$ $C$__vtable_$h$;
\end{prog}
Of course, this means that your build system needs to become more
complicated. If you use \man{make}{1}, then something like
\begin{prog}
Of course, this means that your build system needs to become more
complicated. If you use \man{make}{1}, then something like
\begin{prog}
.SUFFIXES: .sod .c .h \\
.sod.c:; \$(SOD) -tc \$< \\
.sod.h:; \$(SOD) -th \$<
.SUFFIXES: .sod .c .h \\
.sod.c:; \$(SOD) -tc \$< \\
.sod.h:; \$(SOD) -th \$<
The following is a simple Sod input file.
\begin{prog}
The following is a simple Sod input file.
\begin{prog}
-/* -*-sod-*- */ \\
-\\
-code c : includes \{ \\
-\#include "greeter.h" \\
-\} \\
-\\
-code h : includes \{ \\
-\#include <stdio.h> \\
-\#include <sod/sod.h> \\
-\} \\
-\\
-class Greeter : SodObject \{ \\ \ind
- void greet(FILE *fp) \{ \\ \ind
- fputs("Hello, world!\textbackslash n", fp); \- \\
- \} \- \\
-\}
+ /* -*-sod-*- */
+ \\+
+ code c : includes \{ \\
+ \#include "greeter.h" \\
+ \}
+ \\+
+ code h : includes \{ \\
+ \#include <stdio.h> \\
+ \#include <sod/sod.h> \\
+ \}
+ \\+
+ class Greeter : SodObject \{ \\ \ind
+ void greet(FILE *fp) \{ \\ \ind
+ fputs("Hello, world!\textbackslash n", fp); \- \\
+ \} \- \\
+ \}
\end{prog}
Save it as @"greeter.sod", and run
\begin{prog}
\end{prog}
Save it as @"greeter.sod", and run
\begin{prog}
\end{prog}
This will create files @"greeter.c" and @"greeter.h" in the current
directory. Here's how we might use such a simple thing.
\begin{prog}
\end{prog}
This will create files @"greeter.c" and @"greeter.h" in the current
directory. Here's how we might use such a simple thing.
\begin{prog}
-\#include "greeter.h" \\
-\\
-int main(void) \\
-\{ \\ \ind
- SOD_DECL(Greeter, g); \\
- \\
- Greeter_greet(g, stdout); \\
- return (0); \- \\
-\}
+ \#include "greeter.h"
+ \\+
+ int main(void) \\
+ \{ \\ \ind
+ SOD_DECL(Greeter, g);
+ \\+
+ Greeter_greet(g, stdout); \\
+ return (0); \- \\
+ \}
\end{prog}
Compare this to the traditional
\begin{prog}
\end{prog}
Compare this to the traditional
\begin{prog}
-\#include <stdio.h> \\
-\\
-int main(void) \\ \ind
- \{ fputs("Hello, world@\\n", stdout); return (0); \}
+ \#include <stdio.h>
+ \\+
+ int main(void) \\ \ind
+ \{ fputs("Hello, world@\\n", stdout); return (0); \}
\end{prog}
and I'm sure you'll appreciate the benefits of using Sod already -- mostly to
do with finger exercise. Trust me, it gets more useful.
\end{prog}
and I'm sure you'll appreciate the benefits of using Sod already -- mostly to
do with finger exercise. Trust me, it gets more useful.