1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-09-01 17:14:15 -04:00

Move chstrdup() to utils.c and rename it to xchstrdup()

The new name is for consistency with other XXXdup() functions used in
this program.
This commit is contained in:
John Zaitseff 2011-08-20 15:17:09 +10:00
parent bc8dc76f00
commit b5b211313e
6 changed files with 40 additions and 40 deletions

View File

@ -412,7 +412,7 @@ void visit_bank (void)
mkchstr(chbuf, BUFSIZE, attr_normal, attr_normal | A_BOLD, 0, 1,
getmaxx(curwin) / 2, &width_cursym, 1, "^{%s^}",
lconvinfo.currency_symbol);
chbuf_cursym = chstrdup(chbuf);
chbuf_cursym = xchstrdup(chbuf);
mkchstr(chbuf, BUFSIZE, attr_normal, 0, 0, 1, getmaxx(curwin)
- BANK_INPUT_COLS - width_cursym - 6, &width, 1,
@ -470,7 +470,7 @@ void visit_bank (void)
mkchstr(chbuf, BUFSIZE, attr_normal, attr_normal | A_BOLD, 0, 1,
getmaxx(curwin) / 2, &width_cursym, 1, "^{%s^}",
lconvinfo.currency_symbol);
chbuf_cursym = chstrdup(chbuf);
chbuf_cursym = xchstrdup(chbuf);
mkchstr(chbuf, BUFSIZE, attr_normal, 0, 0, 1, getmaxx(curwin)
- BANK_INPUT_COLS - width_cursym - 6, &width, 1,

View File

@ -1391,28 +1391,6 @@ error:
}
/***********************************************************************/
// chstrdup: Duplicate a chtype buffer
chtype *chstrdup (const chtype *restrict chstr)
{
const chtype *p;
int len;
chtype *ret;
// Determine chstr length, including ending NUL
for (len = 1, p = chstr; *p != '\0'; p++, len++)
;
ret = xmalloc(len * sizeof(chtype));
memcpy(ret, chstr, len * sizeof(chtype));
ret[len - 1] = '\0'; // Terminating NUL, just in case not present
return ret;
}
/***********************************************************************/
// leftch: Print strings in chstr left-aligned

View File

@ -408,19 +408,6 @@ extern int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
const char *restrict format, va_list args);
/*
Function: chstrdup - Duplicate a chtype string
Parameters: chstr - String to duplicate
Returns: chtype * - Pointer to new (duplicated) string
This function returns a new string of type chtype * that contains a
copy of the string in chstr. No errors are returned: if sufficient
memory is not available, the program terminates with an "Out of memory"
message.
*/
extern chtype *chstrdup (const chtype *restrict chstr);
/*
Function: leftch - Print strings in chstr left-aligned
Parameters: win - Window to use (should be curwin)

View File

@ -788,11 +788,11 @@ void merge_companies (map_val_t a, map_val_t b)
mkchstr(chbuf, BUFSIZE, attr_highlight, 0, 0, 1, getmaxx(curwin) / 2,
&width_aa, 1, "%s", company[aa].name);
chbuf_aa = chstrdup(chbuf);
chbuf_aa = xchstrdup(chbuf);
mkchstr(chbuf, BUFSIZE, attr_highlight, 0, 0, 1, getmaxx(curwin) / 2,
&width_bb, 1, "%s", company[bb].name);
chbuf_bb = chstrdup(chbuf);
chbuf_bb = xchstrdup(chbuf);
mkchstr(chbuf, BUFSIZE, attr_normal, 0, 0, 1, getmaxx(curwin) / 2,
&width, 1,
@ -1032,7 +1032,7 @@ void adjust_values (void)
mkchstr(chbuf, BUFSIZE, attr_error_highlight, 0, 0, 1, w / 2,
&width_amt, 1, "%N", company[which].share_price);
chbuf_amt = chstrdup(chbuf);
chbuf_amt = xchstrdup(chbuf);
mkchstr(chbuf, BUFSIZE, attr_error_normal, 0, 0, 1, w / 2,
&width, 1,

View File

@ -487,6 +487,28 @@ char *xstrdup (const char *str)
}
/***********************************************************************/
// chstrdup: Duplicate a chtype buffer
chtype *xchstrdup (const chtype *restrict chstr)
{
const chtype *p;
int len;
chtype *ret;
// Determine chstr length, including ending NUL
for (len = 1, p = chstr; *p != '\0'; p++, len++)
;
ret = xmalloc(len * sizeof(chtype));
memcpy(ret, chstr, len * sizeof(chtype));
ret[len - 1] = '\0'; // Terminating NUL, just in case not present
return ret;
}
/***********************************************************************/
// xwcsdup: Duplicate a wide-character string, with checking

View File

@ -331,6 +331,19 @@ extern void *xmalloc (size_t size);
extern char *xstrdup (const char *str);
/*
Function: xchstrdup - Duplicate a chtype string
Parameters: chstr - String to duplicate
Returns: chtype * - Pointer to new (duplicated) string
This function returns a new string of type chtype * that contains a
copy of the string in chstr. No errors are returned: if sufficient
memory is not available, the program terminates with an "Out of memory"
message.
*/
extern chtype *xchstrdup (const chtype *restrict chstr);
/*
Function: xwcsdup - Duplicate a wide-character string, with checking
Parameters: str - String to duplicate