| 1 |
/* |
| 2 |
* ChkTeX, utility functions -- header file. |
| 3 |
* Copyright (C) 1995-96 Jens T. Berger Thielemann |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 |
* |
| 19 |
* Contact the author at: |
| 20 |
* Jens Berger |
| 21 |
* Spektrumvn. 4 |
| 22 |
* N-0666 Oslo |
| 23 |
* Norway |
| 24 |
* E-mail: <[email protected]> |
| 25 |
* |
| 26 |
* |
| 27 |
*/ |
| 28 |
|
| 29 |
#ifndef UTILITY_H |
| 30 |
#define UTILITY_H 1 |
| 31 |
|
| 32 |
#include "ChkTeX.h" |
| 33 |
#include "OpSys.h" |
| 34 |
|
| 35 |
/* |
| 36 |
* How many indexes we'll allocate first time |
| 37 |
*/ |
| 38 |
#define MINPUDDLE 256 |
| 39 |
|
| 40 |
/* |
| 41 |
* How many bytes we want in front/end of each char buffer. > 2 |
| 42 |
*/ |
| 43 |
#define WALLBYTES 4 |
| 44 |
|
| 45 |
#ifndef HASH_SIZE |
| 46 |
# define HASH_SIZE 1009 /* A reasonably large prime */ |
| 47 |
#endif |
| 48 |
|
| 49 |
#define FORWL(ind, list) for(ind = 0; ind < (list).Stack.Used; ind++) |
| 50 |
|
| 51 |
|
| 52 |
enum Strip |
| 53 |
{ |
| 54 |
STRP_LFT = 0x01, |
| 55 |
STRP_RGT = 0x02, |
| 56 |
STRP_BTH = 0x03 |
| 57 |
}; |
| 58 |
|
| 59 |
struct HashEntry |
| 60 |
{ |
| 61 |
struct HashEntry *Next; |
| 62 |
char *Str; |
| 63 |
}; |
| 64 |
|
| 65 |
struct Hash |
| 66 |
{ |
| 67 |
struct HashEntry **Index; |
| 68 |
}; |
| 69 |
|
| 70 |
struct Stack |
| 71 |
{ |
| 72 |
void **Data; |
| 73 |
unsigned long Size, Used; |
| 74 |
}; |
| 75 |
|
| 76 |
struct WordList |
| 77 |
{ |
| 78 |
unsigned long MaxLen; |
| 79 |
int NonEmpty; |
| 80 |
struct Stack Stack; |
| 81 |
struct Hash Hash; |
| 82 |
}; |
| 83 |
#define WORDLIST_DEFINED |
| 84 |
|
| 85 |
struct FileNode |
| 86 |
{ |
| 87 |
char *Name; |
| 88 |
FILE *fh; |
| 89 |
unsigned long Line; |
| 90 |
}; |
| 91 |
|
| 92 |
/* Subtract 1 because sizeof includes the null terminator. |
| 93 |
* WARNING: To use this on a variable, the type should be char[] |
| 94 |
* rather than char*, since for some versions of gcc these give |
| 95 |
* different values. */ |
| 96 |
#define STRLEN(x) (sizeof(x)/sizeof(x[0]) - 1) |
| 97 |
|
| 98 |
int fexists(const char *Filename); |
| 99 |
|
| 100 |
void *sfmemset(void *to, int c, long n); |
| 101 |
void *saferealloc(void *old, size_t newsize); |
| 102 |
|
| 103 |
int strafter(const char *Str, const char *Cmp); |
| 104 |
void strrep(char *String, const char From, const char To); |
| 105 |
void strxrep(char *Buf, const char *Prot, const char To); |
| 106 |
char *strip(char *String, const enum Strip What); |
| 107 |
void strwrite(char *To, const char *From, unsigned long Len); |
| 108 |
int strinfront(const char *Str, const char *Cmp); |
| 109 |
char *strdupx(const char *String, int Extra); |
| 110 |
void strmove(char *a, const char *b); |
| 111 |
|
| 112 |
void ClearHash(struct Hash *h); |
| 113 |
void InsertHash(char *a, struct Hash *h); |
| 114 |
char *HasHash(const char *a, const struct Hash *h); |
| 115 |
|
| 116 |
int InsertWord(const char *Word, struct WordList *WL); |
| 117 |
char *HasWord(const char *Word, struct WordList *WL); |
| 118 |
void MakeLower(struct WordList *wl); |
| 119 |
void ListRep(struct WordList *wl, const char From, const char To); |
| 120 |
void ClearWord(struct WordList *WL); |
| 121 |
|
| 122 |
int StkPush(void *Data, struct Stack *Stack); |
| 123 |
void *StkPop(struct Stack *Stack); |
| 124 |
void *StkTop(struct Stack *Stack); |
| 125 |
|
| 126 |
FILE *CurStkFile(struct Stack *stack); |
| 127 |
const char *CurStkName(struct Stack *stack); |
| 128 |
unsigned long CurStkLine(struct Stack *stack); |
| 129 |
long CurStkMode(struct Stack *stack); |
| 130 |
long *PushMode(long mode, struct Stack *stack); |
| 131 |
char *FGetsStk(char *Dest, unsigned long len, struct Stack *stack); |
| 132 |
int PushFileName(const char *Name, struct Stack *stack); |
| 133 |
int PushFile(const char *, FILE *, struct Stack *); |
| 134 |
|
| 135 |
|
| 136 |
void FreeErrInfo(struct ErrInfo *ei); |
| 137 |
struct ErrInfo *PushChar(const char c, const unsigned long Line, |
| 138 |
const unsigned long Column, struct Stack *Stk, |
| 139 |
const char *LineCpy); |
| 140 |
struct ErrInfo *PushErr(const char *Data, const unsigned long Line, |
| 141 |
const unsigned long Column, |
| 142 |
const unsigned long ErrLen, const char *LineCpy, |
| 143 |
struct Stack *Stk); |
| 144 |
struct ErrInfo *TopChar(struct Stack *Stack); |
| 145 |
struct ErrInfo *TopErr(struct Stack *Stack); |
| 146 |
struct ErrInfo *PopErr(struct Stack *Stack); |
| 147 |
struct ErrInfo *TopMatch(struct Stack *Stack, char *String); |
| 148 |
|
| 149 |
long BrackIndex(const char c); |
| 150 |
void AddBracket(const char c); |
| 151 |
char MatchBracket(const char c); |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
short substring(const char *source, char *dest, unsigned long pos, long len); |
| 156 |
|
| 157 |
#ifndef HAVE_STRLWR |
| 158 |
# define strlwr mystrlwr |
| 159 |
char *mystrlwr(char *String); |
| 160 |
#endif |
| 161 |
|
| 162 |
#ifndef HAVE_STRDUP |
| 163 |
# define strdup mystrdup |
| 164 |
char *mystrdup(const char *String); |
| 165 |
#endif |
| 166 |
|
| 167 |
|
| 168 |
#ifndef HAVE_STRCASECMP |
| 169 |
int strcasecmp(char *a, char *b); |
| 170 |
#endif |
| 171 |
|
| 172 |
#if !(defined HAVE_DECL_STPCPY && HAVE_DECL_STPCPY) |
| 173 |
static inline char * stpcpy(char *dest, const char *src) |
| 174 |
{ |
| 175 |
return strcpy(dest, src) + strlen(src); |
| 176 |
} |
| 177 |
#endif |
| 178 |
|
| 179 |
|
| 180 |
#endif /* UTILITY_H */ |