-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcatdoc.c
More file actions
60 lines (48 loc) · 1.3 KB
/
catdoc.c
File metadata and controls
60 lines (48 loc) · 1.3 KB
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
/*
Copyright 1996-2003 Victor Wagner
Copyright 2003 Alex Ott
This file is released under the GPL. Details can be
found in the file COPYING accompanying this distribution.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include "catdoc.h"
const short int const *source_charset = source_charsets[CP_1251];
/**************************************************************/
/* Main program */
/* Processes options, reads charsets files and substitution */
/* maps and passes all remaining args to processfile */
/**************************************************************/
int doc2text(const char *buf, size_t size, char **buffer_out) {
FILE *f, *out;
int c;
size_t size_out;
if (!strlen(buf))
{
errno = EINVAL;
return -1;
}
if (LINE_BUF_SIZE - LONGEST_SEQUENCE <= WRAP_MARGIN) {
errno = EINVAL;
return -1;
}
c=0;
out = open_memstream(buffer_out, &size_out);
if (!out) return -1;
f = fmemopen((char*)buf, size, "rb");
if (!f) {
fclose(out);
return -1;
}
c = analyze_format(f, out);
fclose(f);
fclose(out);
return c;
}