Clean up function move_to_abs_word() and rename to move_to_word()

Remove the output argument, as it's the same as the function return value anyway, so
the callers should just use that.
This commit is contained in:
Kevin Easton
2017-11-14 23:15:33 +11:00
parent 5e40c1ac01
commit fea88185f8
7 changed files with 22 additions and 20 deletions

View File

@@ -1,5 +1,7 @@
[Changes 1.2.2] [Changes 1.2.2]
* Rename exported function move_to_abs_word() to move_to_word(). (caf)
* Make "You can't hide an invisible window" message respect * Make "You can't hide an invisible window" message respect
/SET WINDOW_QUIET. (caf) /SET WINDOW_QUIET. (caf)

View File

@@ -133,7 +133,7 @@ char * base64_encode (const void *data, size_t size);
#define SOS -32767 #define SOS -32767
#define EOS 32767 #define EOS 32767
char *BX_strsearch (register char *, char *, char *, int); char *BX_strsearch (register char *, char *, char *, int);
char *BX_move_to_abs_word (const register char *, char **, int); char *BX_move_to_word (const char *, int);
char *BX_move_word_rel (const char *, char **, int); char *BX_move_word_rel (const char *, char **, int);
char *BX_extract (char *, int, int); char *BX_extract (char *, int, int);
char *BX_extract2 (const char *, int, int); char *BX_extract2 (const char *, int, int);

View File

@@ -10,7 +10,7 @@
* if we change the table below, we change this module number to the * if we change the table below, we change this module number to the
* current date (YYYYMMDDxx where xx is a serial number). * current date (YYYYMMDDxx where xx is a serial number).
*/ */
#define MODULE_VERSION 2017110602UL #define MODULE_VERSION 2017111401UL
#include "struct.h" #include "struct.h"
@@ -201,7 +201,7 @@ enum FUNCTION_VALUE
/* words.c */ /* words.c */
STRSEARCH, STRSEARCH,
MOVE_TO_ABS_WORD, MOVE_TO_WORD,
MOVE_WORD_REL, MOVE_WORD_REL,
EXTRACT, EXTRACT,
EXTRACT2, EXTRACT2,

View File

@@ -200,7 +200,7 @@ extern Function_ptr *global;
/* words.c reg.c */ /* words.c reg.c */
#define strsearch (*(char *(*)(char *, char *, char *, int ))global[STRSEARCH]) #define strsearch (*(char *(*)(char *, char *, char *, int ))global[STRSEARCH])
#define move_to_abs_word (*(char *(*)(const char *, char **, int ))global[MOVE_TO_ABS_WORD]) #define move_to_word (*(char *(*)(const char *, int))global[MOVE_TO_WORD])
#define move_word_rel (*(char *(*)(const char *, char **, int ))global[MOVE_WORD_REL]) #define move_word_rel (*(char *(*)(const char *, char **, int ))global[MOVE_WORD_REL])
#define extract (*(char *(*)(char *, int , int ))global[EXTRACT]) #define extract (*(char *(*)(char *, int , int ))global[EXTRACT])
#define extract2 (*(char *(*)(const char *, int , int ))global[EXTRACT2]) #define extract2 (*(char *(*)(const char *, int , int ))global[EXTRACT2])

View File

@@ -201,7 +201,7 @@ static int already_done = 0;
/* words.c reg.c */ /* words.c reg.c */
global_table[STRSEARCH] = (Function_ptr) BX_strsearch; global_table[STRSEARCH] = (Function_ptr) BX_strsearch;
global_table[MOVE_TO_ABS_WORD] = (Function_ptr) BX_move_to_abs_word; global_table[MOVE_TO_WORD] = (Function_ptr) BX_move_to_word;
global_table[MOVE_WORD_REL] = (Function_ptr) BX_move_word_rel; global_table[MOVE_WORD_REL] = (Function_ptr) BX_move_word_rel;
global_table[EXTRACT] = (Function_ptr) BX_extract; global_table[EXTRACT] = (Function_ptr) BX_extract;
global_table[EXTRACT2] = (Function_ptr) BX_extract2; global_table[EXTRACT2] = (Function_ptr) BX_extract2;

View File

@@ -845,7 +845,7 @@ void BX_userhostbase(char *args, void (*line) (UserhostItem *, char *, char *),
{ {
UserhostEntry *new_uh = get_new_userhost_entry(); UserhostEntry *new_uh = get_new_userhost_entry();
move_to_abs_word(ptr, &next_ptr, 5); next_ptr = move_to_word(ptr, 5);
if (next_ptr && *next_ptr && next_ptr > ptr) if (next_ptr && *next_ptr && next_ptr > ptr)
next_ptr[-1] = 0; next_ptr[-1] = 0;

View File

@@ -47,12 +47,14 @@ extern char *BX_strsearch(register char *start, char *mark, char *chars, int how
return mark; return mark;
} }
/* Move to an absolute word number from start */ /* move_to_word()
/* First word is always numbered zero. */ *
extern char *BX_move_to_abs_word (const register char *start, char **mark, int word) * Return a pointer to the first character of the Nth word in a string.
* The first word is always numbered zero.
*/
extern char *BX_move_to_word(const char *start, int word)
{ {
register char *pointer = (char *)start; const char *pointer = start;
register int counter = word;
/* This fixes a bug that counted leading spaces as /* This fixes a bug that counted leading spaces as
* a word, when they're really not a word.... * a word, when they're really not a word....
@@ -64,10 +66,10 @@ extern char *BX_move_to_abs_word (const register char *start, char **mark, int w
* my foot in this one... I'm just going to go with * my foot in this one... I'm just going to go with
* what the stock client does... * what the stock client does...
*/ */
while (pointer && *pointer && my_isspace(*pointer)) while (*pointer && my_isspace(*pointer))
pointer++; pointer++;
for (;counter > 0 && *pointer;counter--) for (; word > 0 && *pointer; word--)
{ {
while (*pointer && !my_isspace(*pointer)) while (*pointer && !my_isspace(*pointer))
pointer++; pointer++;
@@ -75,9 +77,7 @@ extern char *BX_move_to_abs_word (const register char *start, char **mark, int w
pointer++; pointer++;
} }
if (mark) return (char *)pointer;
*mark = pointer;
return pointer;
} }
/* move_word_rel() /* move_word_rel()
@@ -179,7 +179,7 @@ extern char *BX_extract2(const char *start, int firstword, int lastword)
/* If the firstword is positive, move to that word */ /* If the firstword is positive, move to that word */
else if (firstword >= 0) else if (firstword >= 0)
{ {
move_to_abs_word(start, &mark, firstword); mark = move_to_word(start, firstword);
if (!*mark) if (!*mark)
return m_strdup(empty_string); return m_strdup(empty_string);
} }
@@ -221,7 +221,7 @@ extern char *BX_extract2(const char *start, int firstword, int lastword)
else else
{ {
if (lastword >= 0) if (lastword >= 0)
move_to_abs_word(start, &mark2, lastword+1); mark2 = move_to_word(start, lastword + 1);
else else
{ {
mark2 = (char *)start + strlen(start); mark2 = (char *)start + strlen(start);
@@ -297,7 +297,7 @@ extern char *BX_extract(char *start, int firstword, int lastword)
/* If the firstword is positive, move to that word */ /* If the firstword is positive, move to that word */
else if (firstword >= 0) else if (firstword >= 0)
move_to_abs_word(start, &mark, firstword); mark = move_to_word(start, firstword);
/* Its negative. Hold off right now. */ /* Its negative. Hold off right now. */
else else
@@ -314,7 +314,7 @@ extern char *BX_extract(char *start, int firstword, int lastword)
else else
{ {
if (lastword >= 0) if (lastword >= 0)
move_to_abs_word(start, &mark2, lastword+1); mark2 = move_to_word(start, lastword + 1);
else else
/* it's negative -- that's not valid */ /* it's negative -- that's not valid */
return m_strdup(empty_string); return m_strdup(empty_string);