1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/* LzmaUtil.c -- Test application for LZMA compression
2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync2010-09-20 : Igor Pavlov : Public domain */
3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define _CRT_SECURE_NO_WARNINGS
5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <stdio.h>
7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <stdlib.h>
8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <string.h>
9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../Alloc.h"
11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../7zFile.h"
12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../7zVersion.h"
13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../LzmaDec.h"
14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../LzmaEnc.h"
15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
16baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst char *kCantReadMessage = "Can not read input file";
17baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst char *kCantWriteMessage = "Can not write output file";
18baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst char *kCantAllocateMessage = "Can not allocate memory";
19baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst char *kDataErrorMessage = "Data error";
20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
21baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
22baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }
23baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };
24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
25baa3858d3f5d128a5c8466b700098109edcad5f2repo syncvoid PrintHelp(char *buffer)
26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  strcat(buffer, "\nLZMA Utility " MY_VERSION_COPYRIGHT_DATE "\n"
28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      "\nUsage:  lzma <e|d> inputFile outputFile\n"
29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync             "  e: encode file\n"
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync             "  d: decode file\n");
31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
33baa3858d3f5d128a5c8466b700098109edcad5f2repo syncint PrintError(char *buffer, const char *message)
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  strcat(buffer, "\nError: ");
36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  strcat(buffer, message);
37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  strcat(buffer, "\n");
38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return 1;
39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
41baa3858d3f5d128a5c8466b700098109edcad5f2repo syncint PrintErrorNumber(char *buffer, SRes val)
42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  sprintf(buffer + strlen(buffer), "\nError code: %x\n", (unsigned)val);
44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return 1;
45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
47baa3858d3f5d128a5c8466b700098109edcad5f2repo syncint PrintUserError(char *buffer)
48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return PrintError(buffer, "Incorrect command");
50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define IN_BUF_SIZE (1 << 16)
53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define OUT_BUF_SIZE (1 << 16)
54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
55baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,
56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UInt64 unpackSize)
57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  Byte inBuf[IN_BUF_SIZE];
60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  Byte outBuf[OUT_BUF_SIZE];
61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  size_t inPos = 0, inSize = 0, outPos = 0;
62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  LzmaDec_Init(state);
63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (;;)
64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (inPos == inSize)
66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      inSize = IN_BUF_SIZE;
68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      RINOK(inStream->Read(inStream, inBuf, &inSize));
69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      inPos = 0;
70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      SRes res;
73baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      SizeT inProcessed = inSize - inPos;
74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      SizeT outProcessed = OUT_BUF_SIZE - outPos;
75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ELzmaStatus status;
77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (thereIsSize && outProcessed > unpackSize)
78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
79baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        outProcessed = (SizeT)unpackSize;
80baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        finishMode = LZMA_FINISH_END;
81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,
84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        inBuf + inPos, &inProcessed, finishMode, &status);
85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      inPos += inProcessed;
86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      outPos += outProcessed;
87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      unpackSize -= outProcessed;
88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (outStream)
90baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (outStream->Write(outStream, outBuf, outPos) != outPos)
91baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          return SZ_ERROR_WRITE;
92baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
93baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      outPos = 0;
94baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
95baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (res != SZ_OK || thereIsSize && unpackSize == 0)
96baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return res;
97baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
98baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (inProcessed == 0 && outProcessed == 0)
99baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
100baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
101baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          return SZ_ERROR_DATA;
102baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return res;
103baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
104baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
105baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
106baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
107baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
108baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)
109baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
110baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 unpackSize;
111baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int i;
112baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  SRes res = 0;
113baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
114baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CLzmaDec state;
115baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
116baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
117baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  unsigned char header[LZMA_PROPS_SIZE + 8];
118baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
119baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  /* Read and parse header */
120baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
121baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  RINOK(SeqInStream_Read(inStream, header, sizeof(header)));
122baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
123baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  unpackSize = 0;
124baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (i = 0; i < 8; i++)
125baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);
126baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
127baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  LzmaDec_Construct(&state);
128baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));
129baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  res = Decode2(&state, outStream, inStream, unpackSize);
130baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  LzmaDec_Free(&state, &g_Alloc);
131baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return res;
132baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
133baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
134baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)
135baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
136baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CLzmaEncHandle enc;
137baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  SRes res;
138baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CLzmaEncProps props;
139baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
140baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  rs = rs;
141baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
142baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  enc = LzmaEnc_Create(&g_Alloc);
143baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (enc == 0)
144baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return SZ_ERROR_MEM;
145baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
146baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  LzmaEncProps_Init(&props);
147baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  res = LzmaEnc_SetProps(enc, &props);
148baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
149baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (res == SZ_OK)
150baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
151baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Byte header[LZMA_PROPS_SIZE + 8];
152baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    size_t headerSize = LZMA_PROPS_SIZE;
153baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int i;
154baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
155baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    res = LzmaEnc_WriteProperties(enc, header, &headerSize);
156baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (i = 0; i < 8; i++)
157baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      header[headerSize++] = (Byte)(fileSize >> (8 * i));
158baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (outStream->Write(outStream, header, headerSize) != headerSize)
159baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      res = SZ_ERROR_WRITE;
160baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else
161baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
162baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (res == SZ_OK)
163baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);
164baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
165baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
166baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
167baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return res;
168baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
169baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
170baa3858d3f5d128a5c8466b700098109edcad5f2repo syncint main2(int numArgs, const char *args[], char *rs)
171baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
172baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CFileSeqInStream inStream;
173baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CFileOutStream outStream;
174baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  char c;
175baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int res;
176baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int encodeMode;
177baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  Bool useOutFile = False;
178baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
179baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  FileSeqInStream_CreateVTable(&inStream);
180baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  File_Construct(&inStream.file);
181baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
182baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  FileOutStream_CreateVTable(&outStream);
183baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  File_Construct(&outStream.file);
184baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
185baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (numArgs == 1)
186baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
187baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PrintHelp(rs);
188baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return 0;
189baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
190baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
191baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1)
192baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return PrintUserError(rs);
193baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
194baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  c = args[1][0];
195baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  encodeMode = (c == 'e' || c == 'E');
196baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (!encodeMode && c != 'd' && c != 'D')
197baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return PrintUserError(rs);
198baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
199baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
200baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    size_t t4 = sizeof(UInt32);
201baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    size_t t8 = sizeof(UInt64);
202baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (t4 != 4 || t8 != 8)
203baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return PrintError(rs, "Incorrect UInt32 or UInt64");
204baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
205baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
206baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (InFile_Open(&inStream.file, args[2]) != 0)
207baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return PrintError(rs, "Can not open input file");
208baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
209baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (numArgs > 3)
210baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
211baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    useOutFile = True;
212baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (OutFile_Open(&outStream.file, args[3]) != 0)
213baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return PrintError(rs, "Can not open output file");
214baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
215baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  else if (encodeMode)
216baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    PrintUserError(rs);
217baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
218baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (encodeMode)
219baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
220baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UInt64 fileSize;
221baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    File_GetLength(&inStream.file, &fileSize);
222baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    res = Encode(&outStream.s, &inStream.s, fileSize, rs);
223baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
224baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  else
225baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
226baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL);
227baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
228baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
229baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (useOutFile)
230baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    File_Close(&outStream.file);
231baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  File_Close(&inStream.file);
232baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
233baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (res != SZ_OK)
234baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
235baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (res == SZ_ERROR_MEM)
236baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return PrintError(rs, kCantAllocateMessage);
237baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else if (res == SZ_ERROR_DATA)
238baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return PrintError(rs, kDataErrorMessage);
239baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else if (res == SZ_ERROR_WRITE)
240baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return PrintError(rs, kCantWriteMessage);
241baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else if (res == SZ_ERROR_READ)
242baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return PrintError(rs, kCantReadMessage);
243baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return PrintErrorNumber(rs, res);
244baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
245baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return 0;
246baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
247baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
248baa3858d3f5d128a5c8466b700098109edcad5f2repo syncint MY_CDECL main(int numArgs, const char *args[])
249baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
250baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  char rs[800] = { 0 };
251baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int res = main2(numArgs, args, rs);
252baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  fputs(rs, stdout);
253baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return res;
254baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
255