File: fromrtf.c

package info (click to toggle)
librtfcomp 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,540 kB
  • ctags: 120
  • sloc: sh: 8,867; ansic: 1,108; makefile: 99
file content (74 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
///////////////////////////////////////////////////////////////////////////////
// FROMRTF.C
//
// Copies from a UTF8 file to an RTF file, either compressed or uncompressed
//
// ./fromrtf <infile> <outfile> isCompressed
//
// isCompressed = 1 for compressed, 0 for uncompressed
//
// Dr J A Gow : 2/2007
//
// This file is distributed under the terms and conditions of the LGPL - please
// see the file LICENCE in the package root directory.
//
///////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rtfcomp/rtfcomp.h>


unsigned char inbuf[8192];

int main(int argc, char * argv[])
{

	FILE *fpin, *fpmiddle;
	unsigned int inlen;
	unsigned char * out;
	unsigned int outlen;
	int rc=0;
	RTFOPTS options = { sizeof(RTFOPTS), 0 };

	if(argc>3) {
		if(!strcmp(argv[3],"1")) {
			options.isCompressed=1;
		}
	}

	if((fpin=fopen(argv[1],"rb"))!=NULL) {
		inlen = fread(inbuf,1,8192,fpin);
		if(inlen>0) {

			// First phase: decompress

			printf("\nhave %d bytes at input - converting to UTF8 \n", inlen);

			if((rc=LZRTFConvertRTFToUTF8(&out,&outlen,inbuf,inlen,&options))==0) {

				printf("conversion done, outlen %d\n",outlen);
		
				printf("saving converted data\n");

				if((fpmiddle=fopen(argv[2],"wb"))!=NULL) {
					fwrite(out,1,outlen,fpmiddle);
					fclose(fpmiddle);
				} else {
					printf("failed to open middle file\n");
				}

				free(out);
			} else {
				printf("failed to convert rc=%d\n",rc);
			}
		} else {
			printf("no bytes to convert\n");
		}
		fclose(fpin);
	} else {
		printf("unable to open input file\n");
	}
	return 0;
}