2 visor - lightweight system-independent embeddable text editor framework
3 Copyright (C) 2019 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
23 int atoi(const char *str)
25 return strtol(str, 0, 10);
28 long atol(const char *str)
30 return strtol(str, 0, 10);
33 long strtol(const char *str, char **endp, int base)
38 const char *start = str;
40 while(isspace(*str)) str++;
44 if(str[1] == 'x' || str[1] == 'X') {
56 } else if(*str == '-') {
62 long val = 0x7fffffff;
63 char c = tolower(*str);
67 } else if(c >= 'a' && c <= 'f') {
77 acc = acc * base + val;
82 *endp = (char*)(valid ? str : start);
85 return sign > 0 ? acc : -acc;
89 void *memset(void *s, int c, unsigned long n)
96 void *memcpy(void *dest, const void *src, unsigned long n)
100 while(n--) *d++ = *s++;
104 void *memmove(void *dest, const void *src, unsigned long n)
119 dptr = (char*)dest + n - 1;
120 sptr = (const char*)src + n - 1;
129 unsigned long strlen(const char *s)
131 unsigned long len = 0;
136 char *strchr(const char *s, int c)
147 int strcmp(const char *s1, const char *s2)
149 while(*s1 && *s1 == *s2) {
156 char *strcpy(char *dest, const char *src)
159 while((*dptr++ = *src++));
166 return isalpha(c) || isdigit(c);
171 return isupper(c) || islower(c);
176 return c == ' ' || c == '\t';
181 return c >= '0' && c <= '9';
186 return c >= 'A' && c <= 'Z';
191 return c >= 'a' && c <= 'z';
196 return c > ' ' && c <= '~';
201 return isgraph(c) || c == ' ';
206 return isblank(c) || c == '\f' || c == '\n' || c == '\r' || c == '\v';
211 return islower(c) ? (c + ('A' - 'a')) : c;
216 return isupper(c) ? (c - ('A' - 'a')) : c;
219 #endif /* !def HAVE_LIBC */
221 static char errstr_buf[256];
223 void vi_error(struct visor *vi, const char *fmt, ...)
228 vsnprintf(errstr_buf, sizeof errstr_buf, fmt, ap);
232 vi->tty.status(errstr_buf, vi->tty_cls);