static char *skip_non_spaces __P((char *));
static char *savenstr __P((char *, int));
static char *savestr __P((char *));
-static char *etags_strchr __P((const char *, int));
-static char *etags_strrchr __P((const char *, int));
-static int etags_strcasecmp __P((const char *, const char *));
-static int etags_strncasecmp __P((const char *, const char *, int));
static char *etags_getcwd __P((void));
static char *relative_filename __P((char *, char *));
static char *absolute_filename __P((char *, char *));
static PTR xmalloc __P((unsigned int));
static PTR xrealloc __P((char *, unsigned int));
+
+\f
+#if HAVE_STRRCHR
+#define etags_strrchr strrchr
+#else
+/*
+ * Return the ptr in sp at which the character c last
+ * appears; NULL if not found
+ *
+ * Identical to POSIX strrchr, included for portability.
+ */
+static char *
+etags_strrchr (sp, c)
+register const char *sp;
+register int c;
+{
+ register const char *r;
+
+ r = NULL;
+ do
+ {
+ if (*sp == c)
+ r = sp;
+ } while (*sp++);
+ return (char *)r;
+}
+#endif
+
+#if HAVE_STRCHR
+#define etags_strchr strchr
+#else
+/*
+ * Return the ptr in sp at which the character c first
+ * appears; NULL if not found
+ *
+ * Identical to POSIX strchr, included for portability.
+ */
+static char *
+etags_strchr (sp, c)
+register const char *sp;
+register int c;
+{
+ do
+ {
+ if (*sp == c)
+ return (char *)sp;
+ } while (*sp++);
+ return NULL;
+}
+#endif
+
+#if HAVE_STRCASECMP
+#define etags_strcasecmp strcasecmp
+#else
+/*
+ * Compare two strings, ignoring case for alphabetic characters.
+ *
+ * Same as BSD's strcasecmp, included for portability.
+ */
+static int
+etags_strcasecmp (s1, s2)
+register const char *s1;
+register const char *s2;
+{
+ while (*s1 != '\0'
+ && (ISALPHA (*s1) && ISALPHA (*s2)
+ ? lowcase (*s1) == lowcase (*s2)
+ : *s1 == *s2))
+ s1++, s2++;
+
+ return (ISALPHA (*s1) && ISALPHA (*s2)
+ ? lowcase (*s1) - lowcase (*s2)
+ : *s1 - *s2);
+}
+#endif
+
+#if HAVE_STRCASECMP
+#define etags_strncasecmp strncasecmp
+#else
+/*
+ * Compare two strings, ignoring case for alphabetic characters.
+ * Stop after a given number of characters
+ *
+ * Same as BSD's strncasecmp, included for portability.
+ */
+static int
+etags_strncasecmp (s1, s2, n)
+register const char *s1;
+register const char *s2;
+register int n;
+{
+ while (*s1 != '\0' && n-- > 0
+ && (ISALPHA (*s1) && ISALPHA (*s2)
+ ? lowcase (*s1) == lowcase (*s2)
+ : *s1 == *s2))
+ s1++, s2++;
+
+ if (n < 0)
+ return 0;
+ else
+ return (ISALPHA (*s1) && ISALPHA (*s2)
+ ? lowcase (*s1) - lowcase (*s2)
+ : *s1 - *s2);
+}
+#endif
+
\f
static char searchar = '/'; /* use /.../ searches */
{
fvdef = fvnone;
objdef = omethodtag;
- linebuffer_setlen (&token_name, len);
- xstrncpy (token_name.buffer, str, len);
+ linebuffer_setlen (&token_name, len+1);
+ xstrncpy (token_name.buffer, str, len+1);
token_name.buffer[len] = '\0';
return TRUE;
}
off += 1;
len -= 1;
}
- linebuffer_setlen (&token_name, len);
+ linebuffer_setlen (&token_name, len+1);
xstrncpy (token_name.buffer,
- newlb.buffer + off, len);
- token_name.buffer[len] = '\0';
+ newlb.buffer + off, len+1);
if (defun)
while (--len >= 0)
if (token_name.buffer[len] == '_')
}
else
{
- linebuffer_setlen (&token_name, toklen);
+ linebuffer_setlen (&token_name, toklen+1);
xstrncpy (token_name.buffer,
- newlb.buffer + tokoff, toklen);
+ newlb.buffer + tokoff, toklen+1);
token_name.buffer[toklen] = '\0';
/* Name macros and members. */
token.named = (structdef == stagseen
continue;
/* Save all values for later tagging. */
- linebuffer_setlen (&tline, lb.len);
- xstrncpy(tline.buffer, lb.buffer, lb.len-1);
+ linebuffer_setlen (&tline, lb.len+1);
+ xstrncpy(tline.buffer, lb.buffer, lb.len+1);
save_lineno = lineno;
save_lcno = linecharno;
name = tline.buffer + (dbp - lb.buffer);
else
for (end = dbp; *end != '\0' && intoken (*end); end++)
continue;
- linebuffer_setlen (&token_name, end - dbp);
- xstrncpy (token_name.buffer, dbp, end - dbp);
+ linebuffer_setlen (&token_name, end - dbp+1);
+ xstrncpy (token_name.buffer, dbp, end - dbp+1);
token_name.buffer[end - dbp] = '\0';
dbp = end;
else if (len + 1 > allocated)
xrnew (last, len + 1, char);
allocated = len + 1;
- xstrncpy (last, cp, len);
- last[len] = '\0';
+ xstrncpy (last, cp, len+1);
}
}
free (last);
else if (len + 1 > allocated)
xrnew (last, len + 1, char);
allocated = len + 1;
- xstrncpy (last, cp, len);
- last[len] = '\0';
+ xstrncpy (last, cp, allocated);
}
}
free (last);
/* Allocate space and do the substitutions. */
assert (size >= 0);
- result = xnew (size + 1, char);
+ size_t avail = size + 1;
+ result = xnew (avail, char);
for (t = result; *out != '\0'; out++)
if (*out == '\\' && ISDIGIT (*++out))
{
dig = *out - '0';
diglen = regs->end[dig] - regs->start[dig];
- xstrncpy (t, in + regs->start[dig], diglen);
+ xstrncpy (t, in + regs->start[dig], avail);
t += diglen;
+ avail -= diglen;
}
- else
+ else {
*t++ = *out;
+ avail --;
+ }
*t = '\0';
assert (t <= result + size);
if (need_filebuf /* we need filebuf for multi-line regexps */
&& chars_deleted > 0) /* not at EOF */
{
- while (filebuf.size <= filebuf.len + lbp->len + 1) /* +1 for \n */
- {
- /* Expand filebuf. */
+ size_t need = filebuf.len + lbp->len + 1; /* +1 for \n */
+ while (filebuf.size <= need )
filebuf.size *= 2;
- xrnew (filebuf.buffer, filebuf.size, char);
- }
- xstrncpy (filebuf.buffer + filebuf.len, lbp->buffer, lbp->len);
+ /* Expand filebuf. */
+ xrnew (filebuf.buffer, filebuf.size, char);
+ xstrncpy (filebuf.buffer + filebuf.len, lbp->buffer, filebuf.size - filebuf.len);
filebuf.len += lbp->len;
filebuf.buffer[filebuf.len++] = '\n';
filebuf.buffer[filebuf.len] = '\0';
register char *dp;
dp = xnew (len + 1, char);
- xstrncpy (dp, cp, len);
+ xstrncpy (dp, cp, len+1);
dp[len] = '\0';
return dp;
}
-/*
- * Return the ptr in sp at which the character c last
- * appears; NULL if not found
- *
- * Identical to POSIX strrchr, included for portability.
- */
-static char *
-etags_strrchr (sp, c)
-register const char *sp;
-register int c;
-{
- register const char *r;
-
- r = NULL;
- do
- {
- if (*sp == c)
- r = sp;
- } while (*sp++);
- return (char *)r;
-}
-
-/*
- * Return the ptr in sp at which the character c first
- * appears; NULL if not found
- *
- * Identical to POSIX strchr, included for portability.
- */
-static char *
-etags_strchr (sp, c)
-register const char *sp;
-register int c;
-{
- do
- {
- if (*sp == c)
- return (char *)sp;
- } while (*sp++);
- return NULL;
-}
-
-/*
- * Compare two strings, ignoring case for alphabetic characters.
- *
- * Same as BSD's strcasecmp, included for portability.
- */
-static int
-etags_strcasecmp (s1, s2)
-register const char *s1;
-register const char *s2;
-{
- while (*s1 != '\0'
- && (ISALPHA (*s1) && ISALPHA (*s2)
- ? lowcase (*s1) == lowcase (*s2)
- : *s1 == *s2))
- s1++, s2++;
-
- return (ISALPHA (*s1) && ISALPHA (*s2)
- ? lowcase (*s1) - lowcase (*s2)
- : *s1 - *s2);
-}
-
-/*
- * Compare two strings, ignoring case for alphabetic characters.
- * Stop after a given number of characters
- *
- * Same as BSD's strncasecmp, included for portability.
- */
-static int
-etags_strncasecmp (s1, s2, n)
-register const char *s1;
-register const char *s2;
-register int n;
-{
- while (*s1 != '\0' && n-- > 0
- && (ISALPHA (*s1) && ISALPHA (*s2)
- ? lowcase (*s1) == lowcase (*s2)
- : *s1 == *s2))
- s1++, s2++;
-
- if (n < 0)
- return 0;
- else
- return (ISALPHA (*s1) && ISALPHA (*s2)
- ? lowcase (*s1) - lowcase (*s2)
- : *s1 - *s2);
-}
/* Skip spaces (end of string is not space), return new pointer. */
static char *
int toksize;
{
while (lbp->size <= toksize)
- {
lbp->size *= 2;
- xrnew (lbp->buffer, lbp->size, char);
- }
+ xrnew (lbp->buffer, lbp->size, char);
lbp->len = toksize;
}
temp = cuserid((char *)NULL);
/* the_user */
the_user_len = strlen(temp);
- the_user = alloc_string(the_user_len + 1);
- xstrncpy(the_user, the_user_len, temp);
+ the_user = alloc_string(the_user_len);
+ xstrncpy(the_user, temp, the_user_len+1);
/* alloc the_string */
the_string_len = 3 + prefix_length + the_user_len + date_length;
the_string = alloc_string(the_string_len);
- temp_len = the_string_len;
+ temp_len = the_string_len+1;
temp = the_string;
- xstrncpy(temp, temp_len, FROM_PREFIX);
+ xstrncpy(temp, FROM_PREFIX, temp_len);
temp = &temp[prefix_length];
*temp++ = ' ';
temp_len -= prefix_length + 1;
- xstrncpy(temp, temp_len, the_user);
+ xstrncpy(temp, the_user, temp_len);
temp = &temp[the_user_len];
*temp++ = ' ';
temp_len -= the_user_len + 1;
- xstrncpy(temp, temp_len, the_date);
+ xstrncpy(temp, the_date, temp_len);
result = new_list();
result->string = the_string;
}
/* if */
msgctl(ipc_qid, IPC_STAT, &msg_st);
- xstrncpy(buf, msgp->mtext, len);
- /* terminate buf */
- buf[len] = '\0';
+ xstrncpy(buf, msgp->mtext, sizeof(buf));
printf("%d %s", ipc_qid, buf);
fflush(stdout);
char *skip_non_spaces PP((char *cp));
char *savenstr PP((char *cp, int len));
char *savestr PP((char *cp));
-char *etags_strchr PP((char *sp, int c));
-char *etags_strrchr PP((char *sp, int c));
char *etags_getcwd PP((void));
char *relative_filename PP((char *file, char *dir));
char *absolute_filename PP((char *file, char *dir));
long *xmalloc PP((unsigned int size));
long *xrealloc PP((char *ptr, unsigned int size));
\f
+#if HAVE_STRRCHR
+#define etags_strrchr strrchr
+#else
+/*
+ * Return the ptr in sp at which the character c last
+ * appears; NULL if not found
+ *
+ * Identical to POSIX strrchr, included for portability.
+ */
+static char *
+etags_strrchr (sp, c)
+register const char *sp;
+register int c;
+{
+ register const char *r;
+
+ r = NULL;
+ do
+ {
+ if (*sp == c)
+ r = sp;
+ } while (*sp++);
+ return (char *)r;
+}
+#endif
+
+#if HAVE_STRCHR
+#define etags_strchr strchr
+#else
+/*
+ * Return the ptr in sp at which the character c first
+ * appears; NULL if not found
+ *
+ * Identical to POSIX strchr, included for portability.
+ */
+static char *
+etags_strchr (sp, c)
+register const char *sp;
+register int c;
+{
+ do
+ {
+ if (*sp == c)
+ return (char *)sp;
+ } while (*sp++);
+ return NULL;
+}
+#endif
+\f
char searchar = '/'; /* use /.../ searches */
char *tagfile; /* output file */
objdef = omethodtag;
methodlen = len;
grow_linebuffer(&token_name, methodlen + 1);
- xstrncpy(token_name.buffer, str, len);
+ xstrncpy(token_name.buffer, str, methodlen+1);
token_name.buffer[methodlen] = '\0';
token_name.len = methodlen;
return TRUE;
newlb.
buffer +
tokoff,
- toklen);
- token_name.
- buffer
- [toklen] =
- '\0';
+ toklen + 1);
token_name.len =
toklen;
/* Name macros. */
/* save all values for later tagging */
grow_linebuffer(&tline, lb.len + 1);
- xstrncpy(tline.buffer, lb.buffer, lb.len);
+ xstrncpy(tline.buffer, lb.buffer, lb.len + 1);
save_lineno = lineno;
save_lcno = linecharno;
else if (len + 1 > allocated)
last = xrnew(last, len + 1, char);
allocated = len + 1;
- xstrncpy(last, cp, len);
- last[len] = '\0';
+ xstrncpy(last, cp, allocated);
}
}
free(last);
else if (len + 1 > allocated)
last = xrnew(last, len + 1, char);
allocated = len + 1;
- xstrncpy(last, cp, len);
- last[len] = '\0';
+ xstrncpy(last, cp, allocated);
}
}
free(last);
size -= 1;
/* Allocate space and do the substitutions. */
- result = xnew(size + 1, char);
+ size_t avail = size + 1;
+ result = xnew(avail, char);
for (t = result; *out != '\0'; out++)
if (*out == '\\' && isdigit(*++out)) {
/* Using "dig2" satisfies my debugger. Bleah. */
dig = *out - '0';
diglen = regs->end[dig] - regs->start[dig];
- xstrncpy(t, in + regs->start[dig], diglen);
+ xstrncpy(t, in + regs->start[dig], avail);
t += diglen;
- } else
+ avail -= diglen;
+ } else {
*t++ = *out;
+ avail --;
+ }
*t = '\0';
if (DEBUG && (t > result + size || t - result != strlen(result)))
register char *dp;
dp = xnew(len + 1, char);
- xstrncpy(dp, cp, len);
+ xstrncpy(dp, cp, len+1);
dp[len] = '\0';
return dp;
}
-/*
- * Return the ptr in sp at which the character c last
- * appears; NULL if not found
- *
- * Identical to System V strrchr, included for portability.
- */
-char *etags_strrchr(sp, c)
-register char *sp;
-register int c;
-{
- register char *r;
-
- r = NULL;
- do {
- if (*sp == c)
- r = sp;
- } while (*sp++);
- return r;
-}
-
-/*
- * Return the ptr in sp at which the character c first
- * appears; NULL if not found
- *
- * Identical to System V strchr, included for portability.
- */
-char *etags_strchr(sp, c)
-register char *sp;
-register int c;
-{
- do {
- if (*sp == c)
- return sp;
- } while (*sp++);
- return NULL;
-}
-
/* Skip spaces, return new pointer. */
char *skip_spaces(cp)
char *cp;
if (0 == strncmp (fromserver, "-ERR", 4)) {
xstrncpy (pop_error, fromserver, ERROR_MAX);
} else {
- strcpy (pop_error,
+ xstrncpy (pop_error,
"Unexpected response from POP "
- "server in pop_stat");
+ "server in pop_stat", ERROR_MAX);
pop_trash (server);
}
return (-1);
}
if (remain > 0) {
xstrncpy(w, name, remain);
- w[remain]='\0';
}
/* Check that exe_path is executable and not a
/* set up the program call */
xstrncpy(mdocfile,
(char*)XSTRING_DATA(Vexec_directory),
- XSTRING_LENGTH(Vexec_directory));
- xstrncpy(mdocfile+XSTRING_LENGTH(Vexec_directory),
- make_docfile_prog, countof(make_docfile_prog));
+ sizeof(mdocfile));
+ xstrncpy(mdocfile+edlen,
+ make_docfile_prog, sizeof(mdocfile)-edlen);
/* find the --make-docfile option */
for (p = v; *p; p++) {
struct {
Lisp_Object face;
- /* These flags are simply an optimization for common boolean properties
- which go onto the extent's property list. Any of them would work if
- done in the normal way, but the space savings of doing these in this
- way is significant. Note that if you add a flag, there are numerous
- places in extents.c that need to know about it.
-
- Another consideration is that some of these properties are accessed
- during redisplay, so it's good for access to them to be fast (a bit
- reference instead of a search down a plist).
-
- `begin_glyph_layout' and `end_glyph_layout' are unusual in that
- they have 4 states instead of 2.
-
- Other special extent properties are stored in an auxiliary
- structure that sits at the beginning of the plist. The has_aux
- flag indicates whether this structure exists. The has_parent
- flag is an optimization indicating whether the extent has a parent
- (this could also be determined by looking in the aux structure). */
+ /* These flags are simply an optimization for common
+ boolean properties which go onto the extent's
+ property list. Any of them would work if done in
+ the normal way, but the space savings of doing
+ these in this way is significant. Note that if you
+ add a flag, there are numerous places in extents.c
+ that need to know about it.
+
+ Another consideration is that some of these
+ properties are accessed during redisplay, so it's
+ good for access to them to be fast (a bit reference
+ instead of a search down a plist).
+
+ `begin_glyph_layout' and `end_glyph_layout' are
+ unusual in that they have 4 states instead of 2.
+
+ Other special extent properties are stored in an
+ auxiliary structure that sits at the beginning of
+ the plist. The has_aux flag indicates whether this
+ structure exists. The has_parent flag is an
+ optimization indicating whether the extent has a
+ parent (this could also be determined by looking in
+ the aux structure). */
enum_field(glyph_layout) begin_glyph_layout:2;
/* 2 text, margins, or whitespace */
xstrncpy(res, file, len);
/* if we were using side effects we woulda matched the above cond */
result = dirname(res);
- xstrncpy(res, result, xmin_size_t(len, xstrlen(result)));
+ xstrncpy(res, result, len);
return;
}
#elif defined(HAVE_DIRNAME)
{
/* assumes res is malloc'd of size LEN */
char *result = dirname(res);
- xstrncpy(res, result, xmin_size_t(len, xstrlen(result)));
+ xstrncpy(res, result, len);
return;
}
#endif
extern_inline char*
xdirname(const char *file)
{
- size_t len = xstrlen(file);
+ size_t len = xstrlen(file)+1;
char *res = xmalloc_atomic(len);
x__dirname(res, file, len);
pb.type = PROP_STRING;
pb.data.p_string.str =
- xnew_atomic_array(Bufbyte, len);
+ xnew_atomic_array(Bufbyte, len+1);
xstrncpy((char *)pb.data.p_string.str,
- (char *)pos, len);
+ (char *)pos, len+1);
pb.data.p_string.len = len;
Dynarr_add(prop, pb);