Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > a74ec78bdb789d910d054e3918f3f007 > files > 299

libsword1-devel-1.5.5-2mdk.ppc.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>rawtxt2z.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>rawtxt2z.cpp</h1><div class="fragment"><pre>00001 <font class="preprocessor">#include &lt;ctype.h&gt;</font>
00002 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00003 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00004 <font class="preprocessor">#include &lt;errno.h&gt;</font>
00005 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00006 
00007 <font class="preprocessor">#ifndef __GNUC__</font>
00008 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00009 <font class="preprocessor">#else</font>
00010 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00011 <font class="preprocessor">#endif</font>
00012 <font class="preprocessor"></font>
00013 <font class="preprocessor">#include &lt;swcomprs.h&gt;</font>
00014 
00015 
00016 main(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00017 {
00018         SWCompress *zobj;
00019         <font class="keywordtype">int</font> ifd, ofd, ixfd, oxfd;
00020         <font class="keywordtype">long</font> offset, loffset, lzoffset;
00021         <font class="keywordtype">short</font> size, lsize, lzsize;
00022         <font class="keywordtype">char</font> *tmpbuf;
00023         
00024         <font class="keywordflow">if</font> (argc != 2) {
00025                 fprintf(stderr, <font class="stringliteral">"usage: %s &lt;datafilename&gt;\n"</font>, argv[0]);
00026                 exit(1);
00027         }
00028 
00029         zobj = <font class="keyword">new</font> SWCompress();
00030 
00031 <font class="preprocessor">#ifndef O_BINARY</font>
00032 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0</font>
00033 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00034 <font class="preprocessor"></font>
00035         tmpbuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen(argv[1]) + 9 ];
00036         ifd = open(argv[1], O_RDONLY|O_BINARY);
00037         sprintf(tmpbuf, <font class="stringliteral">"%s.vss"</font>, argv[1]);
00038         ixfd = open(tmpbuf, O_RDONLY|O_BINARY);
00039         sprintf(tmpbuf, <font class="stringliteral">"%s.zzz"</font>, argv[1]);
00040         ofd = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
00041         sprintf(tmpbuf, <font class="stringliteral">"%s.zzz.vss"</font>, argv[1]);
00042         oxfd = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
00043 
00044         <font class="keyword">delete</font> [] tmpbuf;
00045 
00046         printf(<font class="stringliteral">"\n"</font>);
00047 
00048         <font class="keywordflow">while</font> (1) {
00049                 <font class="keywordflow">if</font> (read(ixfd, &amp;offset, 4) != 4)
00050                         <font class="keywordflow">break</font>;
00051                 <font class="keywordflow">if</font> (read(ixfd, &amp;size, 2) != 2)
00052                         <font class="keywordflow">break</font>;
00053 
00054                 <font class="keywordflow">if</font> ((offset == loffset) &amp;&amp; (size == lsize)) {
00055                         printf(<font class="stringliteral">"using previous offset,size\n"</font>, size);
00056                         write(oxfd, &amp;lzoffset, 4);
00057                         write(oxfd, &amp;lzsize, 2);
00058                 }
00059                 <font class="keywordflow">else</font> {
00060                         printf(<font class="stringliteral">"%d -&gt; "</font>, size);
00061                         lsize   = size;
00062                         loffset = offset;
00063 
00064                         <font class="keywordflow">if</font> (size) {
00065                                 tmpbuf = (<font class="keywordtype">char</font> *) calloc(size + 1, 1);
00066                                 lseek(ifd, offset, SEEK_SET);
00067                                 read(ifd, tmpbuf, size);
00068                                 zobj-&gt;Buf(tmpbuf);
00069                                 zobj-&gt;zBuf(&amp;size);
00070                                 free(tmpbuf);
00071                         }
00072                         offset = lseek(ofd, 0, SEEK_END);
00073                         write(oxfd, &amp;offset, 4);
00074                         <font class="keywordflow">if</font> (size) 
00075                                 write(ofd, zobj-&gt;zBuf(&amp;size), size);
00076                         lzoffset = offset;
00077                         write(oxfd, &amp;size, 2);
00078                         lzsize = size;
00079                         printf(<font class="stringliteral">"%d \n"</font>, size);
00080                 }
00081         }
00082         <font class="keyword">delete</font> zobj;
00083 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>