1 /* 2 * Copyright (c) 2002, Darren Hiebert 3 * 4 * This source code is released for free distribution under the terms of the 5 * GNU General Public License version 2 or (at your option) any later version. 6 * 7 * External interface to routines.c 8 */ 9 #ifndef CTAGS_MAIN_ROUTINES_H 10 #define CTAGS_MAIN_ROUTINES_H 11 12 /* 13 * INCLUDE FILES 14 */ 15 #include "general.h" /* must always come first */ 16 17 #include <stdio.h> 18 19 20 /* 21 * MACROS 22 */ 23 #define xMalloc(n,Type) (Type *)eMalloc((size_t)(n) * sizeof (Type)) 24 #define xCalloc(n,Type) (Type *)eCalloc((size_t)(n), sizeof (Type)) 25 #define xRealloc(p,n,Type) (Type *)eRealloc((p), (n) * sizeof (Type)) 26 27 #define ARRAY_SIZE(X) (sizeof (X) / sizeof (X[0])) 28 #define ARRAY_AND_SIZE(X) (X), ARRAY_SIZE(X) 29 30 #define STRINGIFY(X) STRINGIFY_(X) 31 #define STRINGIFY_(X) #X 32 33 /* 34 * DATA DECLARATIONS 35 */ 36 typedef int errorSelection; 37 enum eErrorTypes { FATAL = 1, WARNING = 2, NOTICE = 4, PERROR = 8, }; 38 39 /* 40 * FUNCTION PROTOTYPES 41 */ 42 extern void error (const errorSelection selection, const char *const format, ...) CTAGS_ATTR_PRINTF (2, 3); 43 #define notice(...) error (NOTICE, __VA_ARGS__) 44 45 /* Memory allocation functions */ 46 #ifdef NEED_PROTO_MALLOC 47 extern void *malloc (size_t); 48 extern void *realloc (void *ptr, size_t); 49 #endif 50 extern void *eMalloc (const size_t size); 51 extern void *eCalloc (const size_t count, const size_t size); 52 extern void *eRealloc (void *const ptr, const size_t size); 53 extern void eFree (void *const ptr); 54 extern void eFreeNoNullCheck (void *const ptr); 55 extern void eFreeIndirect(void **ptr); 56 57 /* String manipulation functions */ 58 extern int struppercmp (const char *s1, const char *s2); 59 extern int strnuppercmp (const char *s1, const char *s2, size_t n); 60 #ifndef HAVE_STRSTR 61 extern char* strstr (const char *str, const char *substr); 62 #endif 63 extern char* strrstr (const char *str, const char *substr); 64 extern char* eStrdup (const char* str); 65 extern char* eStrndup (const char* str, size_t len); 66 extern void toLowerString (char* str); 67 extern void toUpperString (char* str); 68 extern char* newLowerString (const char* str); 69 extern char* newUpperString (const char* str); 70 extern bool strToUInt(const char *const str, int base, unsigned int *value); 71 extern bool strToULong(const char *const string, int base, unsigned long *value); 72 extern bool strToInt(const char *const str, int base, int *value); 73 extern bool strToLong(const char *const string, int base, long *value); 74 75 /* File system functions */ 76 extern const char *baseFilename (const char *const filePath); 77 extern const char *fileExtension (const char *const fileName); 78 79 extern FILE *tempFileFP (const char *const mode, char **const pName); 80 81 #endif /* CTAGS_MAIN_ROUTINES_H */ 82