summaryrefslogtreecommitdiffstats
path: root/contrib/bind/bin/nslookup/subr.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind/bin/nslookup/subr.c')
-rw-r--r--contrib/bind/bin/nslookup/subr.c136
1 files changed, 126 insertions, 10 deletions
diff --git a/contrib/bind/bin/nslookup/subr.c b/contrib/bind/bin/nslookup/subr.c
index cefc2eb..a3b9f96 100644
--- a/contrib/bind/bin/nslookup/subr.c
+++ b/contrib/bind/bin/nslookup/subr.c
@@ -52,8 +52,8 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)subr.c 5.24 (Berkeley) 3/2/91";
-static char rcsid[] = "$Id: subr.c,v 8.9 1997/04/25 00:27:19 vixie Exp $";
+static const char sccsid[] = "@(#)subr.c 5.24 (Berkeley) 3/2/91";
+static const char rcsid[] = "$Id: subr.c,v 8.13 1999/10/13 16:39:20 vixie Exp $";
#endif /* not lint */
/*
@@ -126,6 +126,7 @@ IntrHandler()
extern FILE *yyin; /* scanner input file */
extern void yyrestart(); /* routine to restart scanner after interrupt */
#endif
+ extern void ListHost_close(void);
SendRequest_close();
ListHost_close();
@@ -204,9 +205,8 @@ Malloc(size)
fflush(stderr);
abort();
/*NOTREACHED*/
- } else {
- return(ptr);
}
+ return (ptr);
}
char *
@@ -324,7 +324,8 @@ PrintHostInfo(file, title, hp)
* OpenFile --
*
* Parses a command string for a file name and opens
- * the file.
+ * the file. The file name is copued to the argument FILE. The
+ * parameter SIZE parameter includes space for a null byte.
*
* Results:
* file pointer - the open was successful.
@@ -335,12 +336,14 @@ PrintHostInfo(file, title, hp)
*/
FILE *
-OpenFile(string, file)
+OpenFile(string, file, size)
char *string;
char *file;
+ size_t size;
{
char *redirect;
FILE *tmpPtr;
+ int i;
/*
* Open an output file if we see '>' or >>'.
@@ -351,12 +354,18 @@ OpenFile(string, file)
if (redirect == NULL) {
return(NULL);
}
+
+ tmpPtr = NULL;
if (redirect[1] == '>') {
- sscanf(redirect, ">> %s", file);
- tmpPtr = fopen(file, "a+");
+ i = pickString(redirect + 2, file, size);
+ if (i > 0) {
+ tmpPtr = fopen(file, "a+");
+ }
} else {
- sscanf(redirect, "> %s", file);
- tmpPtr = fopen(file, "w");
+ i = pickString(redirect + 1, file, size);
+ if (i > 0) {
+ tmpPtr = fopen(file, "w");
+ }
}
if (tmpPtr != NULL) {
@@ -473,3 +482,110 @@ DecodeType(type)
return (sym_ntop(__p_type_syms, type, (int *)0));
}
+
+
+
+
+/*
+ * Skip over leading white space in SRC and then copy the next sequence of
+ * non-whitespace characters into DEST. No more than (DEST_SIZE - 1)
+ * characters are copied. DEST is always null-terminated. Returns 0 if no
+ * characters could be copied into DEST. Returns the number of characters
+ * in SRC that were processed (i.e. the count of characters in the leading
+ * white space and the first non-whitespace sequence).
+ *
+ * int i;
+ * char *p = " foo bar ", *q;
+ * char buf[100];
+ *
+ * q = p + pickString(p, buf, sizeof buff);
+ * assert (strcmp (q, " bar ") == 0) ;
+ *
+ */
+
+int
+pickString(const char *src, char *dest, size_t dest_size) {
+ const char *start;
+ const char *end ;
+ size_t sublen ;
+
+ if (dest_size == 0 || dest == NULL || src == NULL)
+ return 0;
+
+ for (start = src ; isspace(*start) ; start++)
+ /* nada */ ;
+
+ for (end = start ; *end != '\0' && !isspace(*end) ; end++)
+ /* nada */ ;
+
+ sublen = end - start ;
+
+ if (sublen == 0 || sublen > (dest_size - 1))
+ return 0;
+
+ strncpy (dest, start, sublen);
+
+ dest[sublen] = '\0' ;
+
+ return (end - src);
+}
+
+
+
+
+/*
+ * match the string FORMAT against the string SRC. Leading whitespace in
+ * FORMAT will match any amount of (including no) leading whitespace in
+ * SRC. Any amount of whitespace inside FORMAT matches any non-zero amount
+ * of whitespace in SRC. Value returned is 0 if match didn't occur, or the
+ * amount of characters in SRC that did match
+ *
+ * int i ;
+ *
+ * i = matchString(" a b c", "a b c") ;
+ * assert (i == 5) ;
+ * i = matchString("a b c", " a b c");
+ * assert (i == 0) ; becasue no leading white space in format
+ * i = matchString(" a b c", " a b c");
+ * assert(i == 12);
+ * i = matchString("aa bb ", "aa bb ddd sd");
+ * assert(i == 16);
+ */
+int
+matchString (const char *format, const char *src) {
+ const char *f = format;
+ const char *s = src;
+
+ if (f == NULL || s == NULL)
+ goto notfound;
+
+ if (isspace(*f)) {
+ while (isspace(*f))
+ f++ ;
+ while (isspace(*s))
+ s++ ;
+ }
+
+ while (1) {
+ if (isspace(*f)) {
+ if (!isspace(*s))
+ goto notfound;
+ while(isspace(*s))
+ s++;
+ /* any amount of whitespace in the format string
+ will match any amount of space in the source
+ string. */
+ while (isspace(*f))
+ f++;
+ } else if (*f == '\0') {
+ return (s - src);
+ } else if (*f != *s) {
+ goto notfound;
+ } else {
+ s++ ;
+ f++ ;
+ }
+ }
+ notfound:
+ return 0 ;
+}
OpenPOWER on IntegriCloud