Atlas - UTIL.C
Home / systems / IBM-PC / DataWorks / src Lines: 2 | Size: 1494 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* C89 Standard only */ 2 3#include <string.h> 4#include <ctype.h> 5#include <stdlib.h> 6 7#include "DW.H" 8 9void dw_trim(char *s) 10{ 11 int len; 12 int i; 13 int start; 14 15 len = (int)strlen(s); 16 while (len > 0 && (s[len - 1] == '\n' || s[len - 1] == '\r' || isspace((unsigned char)s[len - 1]))) { 17 s[len - 1] = '\0'; 18 --len; 19 } 20 21 start = 0; 22 while (s[start] != '\0' && isspace((unsigned char)s[start])) { 23 ++start; 24 } 25 26 if (start > 0) { 27 i = 0; 28 while (s[start + i] != '\0') { 29 s[i] = s[start + i]; 30 ++i; 31 } 32 s[i] = '\0'; 33 } 34} 35 36int dw_stricmp(const char *a, const char *b) 37{ 38 unsigned char ca; 39 unsigned char cb; 40 41 while (*a != '\0' && *b != '\0') { 42 ca = (unsigned char)tolower((unsigned char)*a); 43 cb = (unsigned char)tolower((unsigned char)*b); 44 if (ca != cb) { 45 return (int)ca - (int)cb; 46 } 47 ++a; 48 ++b; 49 } 50 return (int)(unsigned char)*a - (int)(unsigned char)*b; 51} 52 53void dw_copy_cell(char *dst, const char *src) 54{ 55 if (src == NULL) { 56 dst[0] = '\0'; 57 return; 58 } 59 strncpy(dst, src, DW_MAX_CELL - 1); 60 dst[DW_MAX_CELL - 1] = '\0'; 61} 62 63int dw_parse_cell_ref(const char *text, int *row, int *col) 64{ 65 char *endptr; 66 long r; 67 long c; 68 69 if (text == NULL || text[0] != '$') { 70 return 0; 71 } 72 73 r = strtol(text + 1, &endptr, 10); 74 if (*endptr != ',' || r < 0) { 75 return 0; 76 } 77 c = strtol(endptr + 1, &endptr, 10); 78 if (*endptr != '\0' || c < 0) { 79 return 0; 80 } 81 82 *row = (int)r; 83 *col = (int)c; 84 return 1; 85} 86[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.