static int resolvinfo_hosts_load(nbio_t *nb) { char buf[LIBNBIO_RESOLV_MAXLINELEN]; int fd; if ((fd = open(LIBNBIO_RESOLV_HOSTSFN, O_RDONLY)) == -1) return -1; while (readln(fd, buf, sizeof(buf)) > 0) { char *s; char *addr, *name, *aliases = NULL; if ((s = strchr(buf, '#'))) *s = '\0'; /* ADDR WS NAME [WS [ALIAS[ WS ALIAS]]] */ s = buf; FIRSTCHAR(s); if (!strlen(s)) continue; /* address required */ addr = s; FIRSTWHITE(s); if (!strlen(s)) continue; /* WS before host name required */ *(s++) = '\0'; FIRSTCHAR(s); if (!strlen(s)) continue; /* host name required */ name = s; FIRSTWHITE(s); if (strlen(s)) { /* aliases optional */ *(s++) = '\0'; FIRSTCHAR(s); aliases = strlen(s) ? s : NULL; } TRIMRIGHT(addr); TRIMRIGHT(name); resolvinfo_hosts_add(nb, addr, name, aliases); } close(fd); return 0; }
static SEXP stripchars(const char * const inchar, int minlen) { /* This routine used to use strcpy with overlapping dest and src. That is not allowed by ISO C. */ int i, j, nspace = 0, upper; char *buff1 = cbuff.data; mystrcpy(buff1, inchar); upper = (int)(strlen(buff1) - 1); /* remove leading blanks */ j = 0; for (i = 0 ; i < upper ; i++) if (isspace((int)buff1[i])) j++; else break; mystrcpy(buff1, &buff1[j]); upper = (int)(strlen(buff1) - 1); if (strlen(buff1) < minlen) goto donesc; for (i = upper, j = 1; i > 0; i--) { if (isspace((int)buff1[i])) { if (j) buff1[i] = '\0' ; else nspace++; } else j = 0; /*strcpy(buff1[i],buff1[i+1]);*/ if (strlen(buff1) - nspace <= minlen) goto donesc; } upper = (int)(strlen(buff1) - 1); for (i = upper; i > 0; i--) { if (LOWVOW(i) && LASTCHAR(i)) mystrcpy(&buff1[i], &buff1[i + 1]); if (strlen(buff1) - nspace <= minlen) goto donesc; } upper = (int)(strlen(buff1) - 1); for (i = upper; i > 0; i--) { if (LOWVOW(i) && !FIRSTCHAR(i)) mystrcpy(&buff1[i], &buff1[i + 1]); if (strlen(buff1) - nspace <= minlen) goto donesc; } upper = (int)(strlen(buff1) - 1); for (i = upper; i > 0; i--) { if (islower((int)buff1[i]) && LASTCHAR(i)) mystrcpy(&buff1[i], &buff1[i + 1]); if (strlen(buff1) - nspace <= minlen) goto donesc; } upper = (int)(strlen(buff1) - 1); for (i = upper; i > 0; i--) { if (islower((int)buff1[i]) && !FIRSTCHAR(i)) mystrcpy(&buff1[i], &buff1[i + 1]); if (strlen(buff1) - nspace <= minlen) goto donesc; } /* all else has failed so we use brute force */ upper = (int)(strlen(buff1) - 1); for (i = upper; i > 0; i--) { if (!FIRSTCHAR(i) && !isspace((int)buff1[i])) mystrcpy(&buff1[i], &buff1[i + 1]); if (strlen(buff1) - nspace <= minlen) goto donesc; } donesc: upper = (int) strlen(buff1); if (upper > minlen) for (i = upper - 1; i > 0; i--) if (isspace((int)buff1[i])) mystrcpy(&buff1[i], &buff1[i + 1]); return(mkChar(buff1)); }