openbsd-ports/textproc/pinfo/patches/patch-src_utils_c
mgrimm 75f3498214 Update to pinfo 0.6.9; many bugfixes.
With feedback, help and fixes from both kili@ and espie@.

ok kili@, "go ahead" espie@ (MAINTAINER)
2007-11-19 18:31:03 +00:00

80 lines
2.4 KiB
Plaintext

$OpenBSD: patch-src_utils_c,v 1.2 2007/11/19 18:31:03 mgrimm Exp $
--- src/utils.c.orig Sun Jul 8 17:12:56 2007
+++ src/utils.c Sun Jul 8 17:19:18 2007
@@ -553,6 +553,10 @@ handlewinch()
int
check_node_name( const char * const node_name, const char * const node_header)
{
+ size_t header_len;
+ char *header, *str_start, *c;
+ int res;
+
/* if either one of node_name or node_header is NULL or a zero
* sized string, we have nothing to check, so return success */
if ( (node_name==NULL) || (node_header==NULL)
@@ -561,15 +565,15 @@ check_node_name( const char * const node_name, const c
return 1;
}
- size_t header_len = strlen(node_header);
+ header_len = strlen(node_header);
/* copy node_header to a local string which can be mutilated */
/* don't use strdup here, as xmalloc handles all errors */
- char *header = xmalloc( header_len + 1 );
+ header = xmalloc( header_len + 1 );
strcpy(header, node_header);
/* search for "Node: foobar," in node_header */
- char *str_start = strstr(header, "Node: ");
+ str_start = strstr(header, "Node: ");
if (str_start==NULL) /* no match */
{
return 0;
@@ -577,14 +581,14 @@ check_node_name( const char * const node_name, const c
/* advance str_start to the start of the node name */
str_start += strlen("Node: ");
/* and search for the next comma, tab, or newline */
- char *c = str_start;
+ c = str_start;
while ( (*c!=',') && (*c!='\t') && (*c!='\n') && (*c!='\0') ) c++;
*c = '\0';
/* so, now str_start point to a \0-terminated string containing the
* node name from the header.
* Let's compare it with the node_name we're looking for */
- int res = strcmp(str_start, node_name);
+ res = strcmp(str_start, node_name);
/* we're done, so free alloc'ed vars */
xfree(header);
@@ -637,20 +641,24 @@ wcswidth(const wchar_t *wstr, size_t max_len)
int
width_of_string( const char * const mbs, const int len)
{
+ int width;
+ char *str;
+#ifdef USE_WCHAR
+ wchar_t *wstr;
+#endif /* USE_WCHAR */
+
if (len<0) return -1;
if (len==0) return 0;
- int width;
-
/* copy the string to a local buffer, because we only want to
* compare the first len bytes */
- char *str = xmalloc(len+1);
+ str = xmalloc(len+1);
memcpy(str, mbs, len);
#ifdef USE_WCHAR
/* allocate a widestring */
- wchar_t *wstr = xmalloc( (len+1)*sizeof(wchar_t) );
+ wstr = xmalloc( (len+1)*sizeof(wchar_t) );
mbstowcs(wstr, str, len);
width = wcswidth(wstr, len);