summaryrefslogtreecommitdiff
path: root/src/pdflib/pdcore/pc_file.h
blob: d1a61633a71a1d5c8b8831fab434b2ba470685ad (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*---------------------------------------------------------------------------*
 |              PDFlib - A library for generating PDF on the fly             |
 +---------------------------------------------------------------------------+
 | Copyright (c) 1997-2006 Thomas Merz and PDFlib GmbH. All rights reserved. |
 +---------------------------------------------------------------------------+
 |                                                                           |
 |    This software is subject to the PDFlib license. It is NOT in the       |
 |    public domain. Extended versions and commercial licenses are           |
 |    available, please check http://www.pdflib.com.                         |
 |                                                                           |
 *---------------------------------------------------------------------------*/

/* $Id: pc_file.h,v 1.1 2008/10/17 06:10:43 scuri Exp $
 *
 * Definitions for file routines
 *
 */

#ifndef PC_FILE_H
#define PC_FILE_H

#if (defined(MAC) || defined(MACOSX))

#include <Files.h>

#ifdef PDF_TARGET_API_MAC_CARBON

OSStatus FSMakePath(SInt16 volRefNum, SInt32 dirID, ConstStr255Param name,
           UInt8 *path, UInt32 maxPathSize);

OSStatus FSPathMakeFSSpec(const UInt8 *path, FSSpec *spec);

#else

#include <Aliases.h>

OSErr FSpGetFullPath(const FSSpec *spec, short *fullPathLength,
        Handle *fullPath);

OSErr FSpLocationFromFullPath(short fullPathLength,
		const void *fullPath, FSSpec *spec);

#endif /* !PDF_TARGET_API_MAC_CARBON */
#endif /* (defined(MAC) || defined(MACOSX)) */

#define PDC_FILENAMELEN  1024    /* maximum file name length */

#define PDC_FILE_TEXT       (1L<<0)  /* text file - whether ASCII file or not
                                      * depends on pdc->asciifile */

#define PDC_FILE_ASCII      (1L<<1)  /* treat text or binary file as ASCII file
                                      * even on EBCDIC platforms */

#define PDC_FILE_BINARY     (1L<<2)  /* open as binary file,
                                      * otherwise as text file */

#define PDC_FILE_WRITEMODE  (1L<<10) /* open file in writing mode,
                                      * otherwise in reading mode */

#define PDC_FILE_APPENDMODE (1L<<11) /* open file in appending mode */


/* flags for pdc_read_textfile() */

#define PDC_FILE_BSSUBST    (1<<0)   /* backslash substitution */
#define PDC_FILE_KEEPLF     (1<<1)   /* keep linefeed at line continuation */

#define PDC_BUFSIZE 1024

#define PDC_OK_FREAD(file, buffer, len) \
    (pdc_fread(buffer, 1, len, file) == len)

typedef struct pdc_file_s pdc_file;

/* pc_file.c */

int		pdc__fseek(FILE *fp, pdc_off_t offset, int whence);
pdc_off_t	pdc__ftell(FILE *fp);
size_t		pdc__fread(void *ptr, size_t size, size_t nmemb, FILE *fp);
size_t          pdc__fwrite(const void *ptr, size_t size, size_t nmemb,
                            FILE *fp);
int		pdc__fgetc(FILE *fp);
int		pdc__feof(FILE *fp);

FILE   *pdc_get_fileptr(pdc_file *sfp);
pdc_core   *pdc_get_pdcptr(pdc_file *sfp);
int     pdc_get_fopen_errnum(pdc_core *pdc, int errnum);
void    pdc_set_fopen_errmsg(pdc_core *pdc, int errnum, const char *qualifier,
                            const char *filename);
pdc_bool pdc_check_fopen_errmsg(pdc_core *pdc, pdc_bool requested);

void    *pdc_read_file(pdc_core *pdc, FILE *fp, pdc_off_t *o_filelen,
			    int incore);
int     pdc_read_textfile(pdc_core *pdc, pdc_file *sfp, int flags,
                          char ***linelist);
char *	pdc_temppath(pdc_core *pdc, char *outbuf, const char *inbuf,
			    size_t inlen, const char *dirname);

char *pdc_check_filename(pdc_core *pdc, char *filename);
char *pdc_get_filename(pdc_core *pdc, char *filename);
const char *pdc_convert_filename_ext(pdc_core *pdc, const char *filename,
        int len, const char *paramname, pdc_encoding enc, int codepage,
        int flags);
const char *pdc_convert_filename(pdc_core *pdc, const char *filename, int len,
        const char *paramname, pdc_bool withbom);
FILE *pdc_fopen_logg(pdc_core *pdc, const char *filename, const char *mode);

pdc_file *	pdc_fopen(pdc_core *pdc, const char *filename,
		    const char *qualifier, const pdc_byte *data,
		    size_t size, int flags);
pdc_core *	pdc_file_getpdc(pdc_file *sfp);
char   *	pdc_file_name(pdc_file *sfp);
pdc_off_t	pdc_file_size(pdc_file *sfp);
pdc_bool	pdc_file_isvirtual(pdc_file *sfp);
char   *	pdc_fgetline(char *s, int size, pdc_file *sfp);
pdc_off_t	pdc_ftell(pdc_file *sfp);
int		pdc_fseek(pdc_file *sfp, pdc_off_t offset, int whence);
size_t		pdc_fread(void *ptr, size_t size, size_t nmemb, pdc_file *sfp);
const void *	pdc_freadall(pdc_file *sfp, size_t *filelen,
		    pdc_bool *ismem);
size_t          pdc_fwrite(const void *ptr, size_t size, size_t nmemb,
                     pdc_file *sfp);
void            pdc_freset(pdc_file *sfp, size_t size);

int     pdc_ungetc(int c, pdc_file *sfp);
int     pdc_fgetc(pdc_file *sfp);
int     pdc_feof(pdc_file *sfp);
void    pdc_fclose(pdc_file *sfp);
void    pdc_fclose_logg(pdc_core *pdc, FILE *fp);
void    pdc_file_fullname(const char *dirname, const char *basename,
                          char *fullname);
char *pdc_file_fullname_mem(pdc_core *pdc, const char *dirname,
        const char *basename);
char *pdc_file_concat(pdc_core *pdc, const char *dirname, const char *basename,
        const char *extension);
const char *pdc_file_strip_dirs(const char *pathname);
char *pdc_file_strip_name(char *pathname);
char *pdc_file_strip_ext(char *pathname);

size_t pdc_fwrite_ascii(pdc_core *pdc, const char *str, size_t len, FILE *fp);
size_t pdc_write_file(pdc_core *pdc, const char *filename,
        const char *qualifier, const char *content, size_t len, int flags);


/* pc_resource.c */

pdc_file *pdc_fsearch_fopen(pdc_core *pdc, const char *filename, char *fullname,
        const char *qualifier, int flags);

#endif  /* PC_FILE_H */