| 1 |
/* |
| 2 |
* $Id: routines.h 536 2007-06-02 06:09:00Z elliotth $ |
| 3 |
* |
| 4 |
* Copyright (c) 2002, Darren Hiebert |
| 5 |
* |
| 6 |
* This source code is released for free distribution under the terms of the |
| 7 |
* GNU General Public License. |
| 8 |
* |
| 9 |
* External interface to routines.c |
| 10 |
*/ |
| 11 |
#ifndef _ROUTINES_H |
| 12 |
#define _ROUTINES_H |
| 13 |
|
| 14 |
/* |
| 15 |
* INCLUDE FILES |
| 16 |
*/ |
| 17 |
#include "general.h" /* must always come first */ |
| 18 |
|
| 19 |
/* |
| 20 |
* MACROS |
| 21 |
*/ |
| 22 |
#define xMalloc(n,Type) (Type *)eMalloc((size_t)(n) * sizeof (Type)) |
| 23 |
#define xCalloc(n,Type) (Type *)eCalloc((size_t)(n), sizeof (Type)) |
| 24 |
#define xRealloc(p,n,Type) (Type *)eRealloc((p), (n) * sizeof (Type)) |
| 25 |
|
| 26 |
/* |
| 27 |
* Portability macros |
| 28 |
*/ |
| 29 |
#ifndef PATH_SEPARATOR |
| 30 |
# if defined (MSDOS_STYLE_PATH) |
| 31 |
# define PATH_SEPARATOR '\\' |
| 32 |
# elif defined (QDOS) |
| 33 |
# define PATH_SEPARATOR '_' |
| 34 |
# else |
| 35 |
# define PATH_SEPARATOR '/' |
| 36 |
# endif |
| 37 |
#endif |
| 38 |
|
| 39 |
#if defined (MSDOS_STYLE_PATH) && defined (UNIX_PATH_SEPARATOR) |
| 40 |
# define OUTPUT_PATH_SEPARATOR '/' |
| 41 |
#else |
| 42 |
# define OUTPUT_PATH_SEPARATOR PATH_SEPARATOR |
| 43 |
#endif |
| 44 |
|
| 45 |
/* |
| 46 |
* DATA DECLARATIONS |
| 47 |
*/ |
| 48 |
#if defined (MSDOS_STYLE_PATH) || defined (VMS) |
| 49 |
extern const char *const PathDelimiters; |
| 50 |
#endif |
| 51 |
extern char *CurrentDirectory; |
| 52 |
typedef int errorSelection; |
| 53 |
enum eErrorTypes { FATAL = 1, WARNING = 2, PERROR = 4 }; |
| 54 |
|
| 55 |
typedef struct { |
| 56 |
/* Name of file for which status is valid */ |
| 57 |
char* name; |
| 58 |
|
| 59 |
/* Does file exist? If not, members below do not contain valid data. */ |
| 60 |
boolean exists; |
| 61 |
|
| 62 |
/* is file path a symbolic link to another file? */ |
| 63 |
boolean isSymbolicLink; |
| 64 |
|
| 65 |
/* Is file (pointed to) a directory? */ |
| 66 |
boolean isDirectory; |
| 67 |
|
| 68 |
/* Is file (pointed to) a normal file? */ |
| 69 |
boolean isNormalFile; |
| 70 |
|
| 71 |
/* Is file (pointed to) executable? */ |
| 72 |
boolean isExecutable; |
| 73 |
|
| 74 |
/* Is file (pointed to) setuid? */ |
| 75 |
boolean isSetuid; |
| 76 |
|
| 77 |
/* Size of file (pointed to) */ |
| 78 |
unsigned long size; |
| 79 |
} fileStatus; |
| 80 |
|
| 81 |
/* |
| 82 |
* FUNCTION PROTOTYPES |
| 83 |
*/ |
| 84 |
extern void freeRoutineResources (void); |
| 85 |
extern void setExecutableName (const char *const path); |
| 86 |
extern const char *getExecutableName (void); |
| 87 |
extern const char *getExecutablePath (void); |
| 88 |
extern void error (const errorSelection selection, const char *const format, ...) __printf__ (2, 3); |
| 89 |
|
| 90 |
/* Memory allocation functions */ |
| 91 |
#ifdef NEED_PROTO_MALLOC |
| 92 |
extern void *malloc (size_t); |
| 93 |
extern void *realloc (void *ptr, size_t); |
| 94 |
#endif |
| 95 |
extern void *eMalloc (const size_t size); |
| 96 |
extern void *eCalloc (const size_t count, const size_t size); |
| 97 |
extern void *eRealloc (void *const ptr, const size_t size); |
| 98 |
extern void eFree (void *const ptr); |
| 99 |
|
| 100 |
/* String manipulation functions */ |
| 101 |
extern int struppercmp (const char *s1, const char *s2); |
| 102 |
extern int strnuppercmp (const char *s1, const char *s2, size_t n); |
| 103 |
#ifndef HAVE_STRSTR |
| 104 |
extern char* strstr (const char *str, const char *substr); |
| 105 |
#endif |
| 106 |
extern char* eStrdup (const char* str); |
| 107 |
extern void toLowerString (char* str); |
| 108 |
extern void toUpperString (char* str); |
| 109 |
extern char* newLowerString (const char* str); |
| 110 |
extern char* newUpperString (const char* str); |
| 111 |
|
| 112 |
/* File system functions */ |
| 113 |
extern void setCurrentDirectory (void); |
| 114 |
extern fileStatus *eStat (const char *const fileName); |
| 115 |
extern void eStatFree (fileStatus *status); |
| 116 |
extern boolean doesFileExist (const char *const fileName); |
| 117 |
extern boolean isRecursiveLink (const char* const dirName); |
| 118 |
extern boolean isSameFile (const char *const name1, const char *const name2); |
| 119 |
#if defined(NEED_PROTO_FGETPOS) |
| 120 |
extern int fgetpos (FILE *stream, fpos_t *pos); |
| 121 |
extern int fsetpos (FILE *stream, fpos_t *pos); |
| 122 |
#endif |
| 123 |
extern const char *baseFilename (const char *const filePath); |
| 124 |
extern const char *fileExtension (const char *const fileName); |
| 125 |
extern boolean isAbsolutePath (const char *const path); |
| 126 |
extern vString *combinePathAndFile (const char *const path, const char *const file); |
| 127 |
extern char* absoluteFilename (const char *file); |
| 128 |
extern char* absoluteDirname (char *file); |
| 129 |
extern char* relativeFilename (const char *file, const char *dir); |
| 130 |
extern FILE *tempFile (const char *const mode, char **const pName); |
| 131 |
|
| 132 |
#endif /* _ROUTINES_H */ |
| 133 |
|
| 134 |
/* vi:set tabstop=4 shiftwidth=4: */ |