File: TextBinary.h

package info (click to toggle)
gcvs 1.0final-12
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 12,248 kB
  • ctags: 10,631
  • sloc: ansic: 71,709; cpp: 39,780; sh: 18,434; makefile: 1,915; yacc: 1,299; tcl: 1,283; perl: 910; lex: 249; csh: 185; lisp: 7
file content (108 lines) | stat: -rwxr-xr-x 3,391 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
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
/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 1, or (at your option)
** any later version.

** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.

** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/*
 * Author : Alexandre Parenteau <aubonbeurre@hotmail.com> --- December 1997
 */

/*
 * TextBinary.h --- utilities to ckeck if files are binary or text
 */

#ifndef TEXTBINARY_H
#define TEXTBINARY_H

#include "CPStr.h"

#ifdef macintosh
#	include <Files.h>
#	if TARGET_API_MAC_OSX
#		define UFSSpec FSRef
#	else
#		define UFSSpec FSSpec
#	endif
#else /* !macintosh */
	typedef int FSSpec;
#	define UFSSpec FSSpec
#endif /* !macintosh */

#ifdef WIN32
	static const char kPathDelimiter = '\\';
#elif TARGET_RT_MAC_CFM
	static const char kPathDelimiter = ':';
#else
	static const char kPathDelimiter = '/';
#endif

//! File type enum
typedef enum
{
	// text and binary flags
	kFileIsOK,			/*!< good file */
	kFileMissing,		/*!< file is missing or unreadable */
	kFileIsAlias,		/*!< file is an alias */
	kFileInvalidName,	/*!< invalid character ('/') */
	
	// text flags
	kTextWrongLF,		/*!< for example it has Mac \r on Windows */
	kTextIsBinary,		/*!< file should be text but seems to be binary */
	kTextEscapeChar,	/*!< file has some extras characters (0x00-0x1F, 0x80-0xFF) */
	kTextWrongSig,		/*!< file has not the 'TEXT' signature (Mac only) */
	kTextIsUnicode,		/*!< file should be text but seems to be unicode file */

	// binary flags
	kBinIsText,			/*!< binary file seems to be a text file */
	kBinWrongSig,		/*!< file should not have the 'TEXT' signature in it (Mac only) */
	kBinIsUnicode,		/*!< binary file seems to be unicode file */

	// unicode flags
	kUnicodeIsText,		/*!< unicode file seems to be text file */
	kUnicodeIsBinary	/*!< unicode file seems to be binary */
} kTextBinTYPE;

//! Expected file type enum
typedef enum
{
	kFileTypeText,
	kFileTypeBin,
	kFileTypeUnicode
} kFileType;

kTextBinTYPE FileIsText(const char *arg, const char *dir, const UFSSpec * spec = 0L);
kTextBinTYPE FileIsBinary(const char *arg, const char *dir, const UFSSpec * spec = 0L);
kTextBinTYPE FileIsUnicode(const char *arg, const char *dir, const UFSSpec * spec = 0L);

bool SplitPath(const char *dir, CStr & uppath, CStr & folder);
	// split the path with the up-directory and the folder.
	// returns false if failed

bool MakeTmpFile(CStr & file, const char *prefix, const char *extension = 0L, bool create = false);
	// find a unique name for a temp file

void GetExtension(const char *file, CStr & base, CStr & ext);
	// extract the extension from the filename

bool GetEnvValue(const char *cmd, const char *key, UStr & value);
	// utility function, parse a command like 'user=who&host=cvs'

#define MAX_ARGS 40
#define MAX_CMD_LEN 2048

int StringToArgv(const char *cmdLine, char **argv);
	// convert a command line (possibly quoted) into
	// regular argc, argv arguments

#endif /* TEXTBINARY_H */