/* STRINGFN.C String manipulation functions Copyright (c) 1995-2006 by Kent Tessman Only if ALLOW_NESTING is #defined may these calls be nested, and then only two at a time (noting that it takes another 1025 bytes of global storage to do so). */ #include #include #include char *Left(char *a, int l); char *Ltrim(char *a); char *Mid(char *a, int pos, int n); char *Right(char *a, int l); char *Rtrim(char *a); #ifdef QUICKC #define OMIT_EXTRA_STRING_FUNCTIONS #endif #ifndef OMIT_EXTRA_STRING_FUNCTIONS #define EXTRA_STRING_FUNCTIONS #endif #if defined (EXTRA_STRING_FUNCTIONS) char *itoa(int a, char *buf, int base); char *strlwr(char *s); char *strnset(char *s, int c, size_t l); char *strupr(char *s); #endif /* GETTEMPSTRING Prevents having to make sure each string-returning function has its own static char array to copy into. In other words, for five functions, we don't need 5 * 1K each of static char array. NOTE: Assumes that no more than NUM_TEMPSTRINGS nested string-manipulations will be done at once. */ #ifndef ALLOW_NESTING static char tempstring[1025]; #else #define NUM_TEMPSTRINGS 2 static char tempstring[NUM_TEMPSTRINGS][1025]; static char tempstring_count = 0; static char *GetTempString(void) { static char *r; r = &tempstring[(int)tempstring_count][0]; if (++tempstring_count >= NUM_TEMPSTRINGS) tempstring_count = 0; return r; } #endif /* The following string-manipulation functions closely mimic BASIC-language string functionality. They do not alter the provided string; instead, they return a pointer to a static (modified) copy. */ /* LEFT */ char *Left(char a[], int l) { static char *temp; int i; #ifdef ALLOW_NESTING temp = GetTempString(); #else temp = &tempstring[0]; #endif if (l > (int)strlen(a)) l = strlen(a); for (i = 0; i (int)strlen(a)) n = strlen(a)-pos; for (i = 0; i (int)strlen(a)) l = strlen(a); for (i = 0; i