| 1 | <HTML> |
| 2 | <HEAD> |
| 3 | <TITLE>How do I use push_output?</TITLE> |
| 4 | </HEAD> |
| 5 | <BODY> |
| 6 | |
| 7 | <P><B>Links</B>: <A HREF=popoutput.html>Next</A> <A HREF=output.html>Previous</A> <A HREF=sgmlspl.html>Up</A> <A HREF=sgmlspl.html>Top</A></P> |
| 8 | |
| 9 | <H1>How do I use <TT>push_output</TT>?</H1> |
| 10 | |
| 11 | <P>The subroutine |
| 12 | <TT>push_output(<IT>type</IT>[,<IT>data</IT>])</TT> |
| 13 | takes two arguments: the <IT>type</IT>, which is always |
| 14 | required, and the <IT>data</IT>, which is needed for |
| 15 | certain types of output. Table 3 lists the different types which you |
| 16 | can push onto the output stack.</P> |
| 17 | |
| 18 | |
| 19 | <H3>Table 3: Types for <TT>push_output</TT></H3> |
| 20 | |
| 21 | <HR> |
| 22 | <DL> |
| 23 | <DT><B>Type</B></DT> |
| 24 | <DD><TT>'handle'</TT></DD> |
| 25 | <DT><B>Data</B></DT> |
| 26 | <DD>a filehandle</DD> |
| 27 | <DT><B>Description</B></DT> |
| 28 | <DD>Send all output to the supplied filehandle.</DD> |
| 29 | |
| 30 | </DL> |
| 31 | <HR> |
| 32 | |
| 33 | |
| 34 | <DL> |
| 35 | <DT><B>Type</B></DT> |
| 36 | <DD><TT>'file'</TT></DD> |
| 37 | <DT><B>Data</B></DT> |
| 38 | <DD>a filename</DD> |
| 39 | <DT><B>Description</B></DT> |
| 40 | <DD>Open the supplied file for writing, erasing its current |
| 41 | contents (if any), and send all output to it.</DD> |
| 42 | |
| 43 | </DL> |
| 44 | <HR> |
| 45 | |
| 46 | |
| 47 | <DL> |
| 48 | <DT><B>Type</B></DT> |
| 49 | <DD><TT>'append'</TT></DD> |
| 50 | <DT><B>Data</B></DT> |
| 51 | <DD>a filename</DD> |
| 52 | <DT><B>Description</B></DT> |
| 53 | <DD>Open the supplied file for writing and append all output to its |
| 54 | current contents.</DD> |
| 55 | |
| 56 | </DL> |
| 57 | <HR> |
| 58 | |
| 59 | |
| 60 | <DL> |
| 61 | <DT><B>Type</B></DT> |
| 62 | <DD><TT>'pipe'</TT></DD> |
| 63 | <DT><B>Data</B></DT> |
| 64 | <DD>a shell command</DD> |
| 65 | <DT><B>Description</B></DT> |
| 66 | <DD>Pipe all output to the supplied shell command.</DD> |
| 67 | |
| 68 | </DL> |
| 69 | <HR> |
| 70 | |
| 71 | |
| 72 | <DL> |
| 73 | <DT><B>Type</B></DT> |
| 74 | <DD><TT>'string'</TT></DD> |
| 75 | <DT><B>Data</B></DT> |
| 76 | <DD>a string [optional]</DD> |
| 77 | <DT><B>Description</B></DT> |
| 78 | <DD>Append all output to the supplied string, which will be |
| 79 | returned by <TT>pop_output</TT>.</DD> |
| 80 | |
| 81 | </DL> |
| 82 | <HR> |
| 83 | |
| 84 | |
| 85 | <DL> |
| 86 | <DT><B>Type</B></DT> |
| 87 | <DD><TT>'nul'</TT></DD> |
| 88 | <DT><B>Data</B></DT> |
| 89 | <DD>[none]</DD> |
| 90 | <DT><B>Description</B></DT> |
| 91 | <DD>Ignore all output.</DD> |
| 92 | |
| 93 | </DL> |
| 94 | <HR> |
| 95 | |
| 96 | |
| 97 | <P>Because the output is stack-based, you do not lose the previous |
| 98 | output destination when you push a new one. This is especially |
| 99 | convenient for dealing with data in tree-structures, like <A HREF="http://www.sil.org/sgml/sgml.html"><B>SGML</B></A> data |
| 100 | -- for example, you can capture the contents of sub-elements as |
| 101 | strings, ignore certain types of elements, and split the output from |
| 102 | one <A HREF="http://www.sil.org/sgml/sgml.html"><B>SGML</B></A> parse into a series of sub-files. Here are some examples:</P> |
| 103 | |
| 104 | <P> |
| 105 | <PRE>push_output('string'); # append output to an empty string |
| 106 | push_output('file','/tmp/foo'); # send output to this file |
| 107 | push_output('pipe','mail webmaster'); # mail output to 'webmaster' (!!) |
| 108 | push_output('nul'); # just ignore all output</PRE> |
| 109 | </P> |
| 110 | |
| 111 | <P><B>Links</B>: <A HREF=popoutput.html>Next</A> <A HREF=output.html>Previous</A> <A HREF=sgmlspl.html>Up</A> <A HREF=sgmlspl.html>Top</A></P> |
| 112 | |
| 113 | |
| 114 | <ADDRESS>David Megginson <A HREF="mailto:[email protected]"><[email protected]></A></ADDRESS> |
| 115 | </BODY> |
| 116 | </HTML> |