Aggressive use of whitespace() and whiteness() macros.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-12-11 21:31:22 +03:00
parent e0c02c9c77
commit 28ca14d73a
15 changed files with 48 additions and 50 deletions

View File

@ -36,6 +36,8 @@
#include "lib/global.h"
#include "lib/strutil.h" /* utf-8 functions */
#include "lib/fileloc.h"
#include "lib/util.h" /* whitespace() */
#include "lib/charsets.h"
/*** global variables ****************************************************************************/
@ -111,7 +113,7 @@ load_codepages_list_from_file (GPtrArray ** list, const char *fname)
if (buflen > 0 && buf[buflen - 1] == '\n')
buf[buflen - 1] = '\0';
while (*p != '\t' && *p != ' ' && *p != '\0')
while (*p != '\0' && !whitespace (*p))
++p;
if (*p == '\0')
goto fail;

View File

@ -36,6 +36,7 @@
#include <sys/types.h> /* size_t */
#include "lib/global.h"
#include "lib/util.h" /* whitespace() */
#include "tty-slang.h"
#include "color.h" /* variables */
@ -72,7 +73,7 @@ has_colors (gboolean disable, gboolean force)
char *s;
size_t i = 0;
while (*cts == ' ' || *cts == '\t')
while (whitespace (*cts))
cts++;
s = cts;

View File

@ -695,8 +695,8 @@ skip_separators (const char *s)
{
const char *su = s;
for (; *su; str_cnext_char (&su))
if (*su != ' ' && *su != '\t' && *su != ',')
for (; *su != '\0'; str_cnext_char (&su))
if (!whitespace (*su) && *su != ',')
break;
return su;
@ -709,7 +709,7 @@ skip_numbers (const char *s)
{
const char *su = s;
for (; *su; str_cnext_char (&su))
for (; *su != '\0'; str_cnext_char (&su))
if (!str_isdigit (su))
break;

View File

@ -27,6 +27,9 @@
#define mc_return_if_error(mcerror) do { if (mcerror != NULL && *mcerror != NULL) return; } while (0)
#define mc_return_val_if_error(mcerror, mcvalue) do { if (mcerror != NULL && *mcerror != NULL) return mcvalue; } while (0)
#define whitespace(c) ((c) == ' ' || (c) == '\t')
#define whiteness(c) (whitespace (c) || (c) == '\n')
#define MC_PIPE_BUFSIZE BUF_8K
#define MC_PIPE_STREAM_EOF 0
#define MC_PIPE_STREAM_UNREAD -1

View File

@ -70,8 +70,6 @@ extern char **environ;
#define SHOW_C_CTX(func)
#endif /* DO_CMPLETION_DEBUG */
#define whitespace(c) ((c) == ' ' || (c) == '\t')
#define DO_INSERTION 1
#define DO_QUERY 2
@ -847,7 +845,7 @@ try_complete_commands_prepare (try_complete_automation_state_t * state, char *te
else
{
ti = str_get_prev_char (&text[*lc_start]);
while (ti > text && (ti[0] == ' ' || ti[0] == '\t'))
while (ti > text && whitespace (ti[0]))
str_prev_char (&ti);
}
@ -933,14 +931,12 @@ try_complete_all_possible (try_complete_automation_state_t * state, char *text,
{
state->q = text + *lc_start;
for (state->p = text;
*state->p != '\0' && state->p < state->q && (*state->p == ' '
|| *state->p == '\t');
*state->p != '\0' && state->p < state->q && whitespace (*state->p);
str_next_char (&state->p))
;
if (strncmp (state->p, "cd", 2) == 0)
for (state->p += 2;
*state->p != '\0' && state->p < state->q && (*state->p == ' '
|| *state->p == '\t');
*state->p != '\0' && state->p < state->q && whitespace (*state->p);
str_next_char (&state->p))
;
if (state->p == state->q)

View File

@ -1399,7 +1399,7 @@ edit_auto_indent (WEdit * edit)
char c;
c = edit_buffer_get_byte (&edit->buffer, p++);
if (c != ' ' && c != '\t')
if (!whitespace (c))
break;
edit_insert (edit, c);
}
@ -1491,7 +1491,7 @@ check_and_wrap_line (WEdit * edit)
edit_insert (edit, '\n');
return;
}
if (c == ' ' || c == '\t')
if (whitespace (c))
{
off_t current = edit->buffer.curs1;
edit_cursor_move (edit, curs - edit->buffer.curs1 + 1);

View File

@ -575,14 +575,19 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
if (row <= edit->buffer.lines - edit->start_line)
{
off_t tws = 0;
if (tty_use_colors () && visible_tws)
{
unsigned int c;
tws = edit_buffer_get_eol (&edit->buffer, b);
while (tws > b
&& ((c = edit_buffer_get_byte (&edit->buffer, tws - 1)) == ' ' || c == '\t'))
while (tws > b)
{
unsigned int c;
c = edit_buffer_get_byte (&edit->buffer, tws - 1);
if (!whitespace (c))
break;
tws--;
}
}
while (col <= end_col - edit->start_col)

View File

@ -303,7 +303,7 @@ word_start (unsigned char *t, off_t q, off_t size)
{
off_t i;
if (t[q] == ' ' || t[q] == '\t')
if (whitespace (t[q]))
return next_word_start (t, q, size);
for (i = q;; i--)
@ -315,7 +315,7 @@ word_start (unsigned char *t, off_t q, off_t size)
c = t[i - 1];
if (c == '\n')
return (-1);
if (c == ' ' || c == '\t')
if (whitespace (c))
return i;
}
}

View File

@ -82,8 +82,6 @@ gboolean option_auto_syntax = TRUE;
#define SYNTAX_TOKEN_BRACKET '\003'
#define SYNTAX_TOKEN_BRACE '\004'
#define whiteness(x) ((x) == '\t' || (x) == '\n' || (x) == ' ')
#define free_args(x)
#define break_a {result=line;break;}
#define check_a {if(!*a){result=line;break;}}
@ -291,8 +289,7 @@ compare_word_to_right (const WEdit * edit, off_t i, const char *text,
}
if (j != 0 && strchr ((const char *) p + 1, c) != NULL) /* c exists further down, so it will get matched later */
break;
if (c == '\n' || c == '\t' || c == ' ' ||
(whole_right != NULL && strchr (whole_right, c) == NULL))
if (whiteness (c) || (whole_right != NULL && strchr (whole_right, c) == NULL))
{
if (*p == '\0')
{

View File

@ -254,10 +254,10 @@ enter (WInput * lc_cmdline)
return MSG_HANDLED;
/* Any initial whitespace should be removed at this point */
while (*cmd == ' ' || *cmd == '\t' || *cmd == '\n')
while (whiteness (*cmd))
cmd++;
if (!*cmd)
if (*cmd == '\0')
return MSG_HANDLED;
if (strncmp (cmd, "cd ", 3) == 0 || strcmp (cmd, "cd") == 0)
@ -381,18 +381,18 @@ do_cd_command (char *orig_cmd)
/* FIXME: what about interpreting quoted strings like the shell.
so one could type "cd <tab> M-a <enter>" and it would work. */
len = strlen (orig_cmd) - 1;
while (len >= 0 && (orig_cmd[len] == ' ' || orig_cmd[len] == '\t' || orig_cmd[len] == '\n'))
while (len >= 0 && whiteness (orig_cmd[len]))
{
orig_cmd[len] = 0;
orig_cmd[len] = '\0';
len--;
}
cmd = orig_cmd;
if (cmd[CD_OPERAND_OFFSET - 1] == 0)
if (cmd[CD_OPERAND_OFFSET - 1] == '\0')
cmd = "cd "; /* 0..2 => given text, 3 => \0 */
/* allow any amount of white space in front of the path operand */
while (cmd[operand_pos] == ' ' || cmd[operand_pos] == '\t')
while (whitespace (cmd[operand_pos]))
operand_pos++;
if (get_current_type () == view_tree)

View File

@ -337,7 +337,7 @@ exec_make_shell_string (const char *lc_data, const vfs_path_t * filename_vpath)
expand_prefix_found = TRUE;
else
{
if (*lc_data != ' ' && *lc_data != '\t')
if (!whitespace (*lc_data))
written_nonspace = TRUE;
if (is_cd)
*(pbuffer++) = *lc_data;
@ -386,13 +386,10 @@ exec_extension_cd (void)
*pbuffer = '\0';
pbuffer = buffer;
/* while (*p == ' ' && *p == '\t')
* p++;
*/
/* Search last non-space character. Start search at the end in order
not to short filenames containing spaces. */
q = pbuffer + strlen (pbuffer) - 1;
while (q >= pbuffer && (*q == ' ' || *q == '\t'))
while (q >= pbuffer && whitespace (*q))
q--;
q[1] = 0;
@ -698,9 +695,8 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
if (content_string[content_shift] == ':')
{
/* Solaris' file prints tab(s) after ':' */
for (content_shift++;
content_string[content_shift] == ' '
|| content_string[content_shift] == '\t'; content_shift++)
for (content_shift++; whitespace (content_string[content_shift]);
content_shift++)
;
}
}
@ -872,7 +868,7 @@ regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *
for (p = data; *p != '\0'; p++)
{
for (q = p; *q == ' ' || *q == '\t'; q++)
for (q = p; whitespace (*q); q++)
;
if (*q == '\n' || *q == '\0')
p = q; /* empty line */
@ -1007,7 +1003,7 @@ regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *
{
*r = c;
for (p = r + 1; *p == ' ' || *p == '\t'; p++)
for (p = r + 1; whitespace (*p); p++)
;
/* Empty commands just stop searching

View File

@ -1471,8 +1471,7 @@ midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
if (current_panel->active == 0 && get_other_type () == view_quick)
return MSG_NOT_HANDLED;
for (i = 0; cmdline->buffer[i] != '\0' &&
(cmdline->buffer[i] == ' ' || cmdline->buffer[i] == '\t'); i++)
for (i = 0; cmdline->buffer[i] != '\0' && whitespace (cmdline->buffer[i]); i++)
;
if (cmdline->buffer[i] != '\0')

View File

@ -123,7 +123,7 @@ check_patterns (char *p)
/* Skip spaces */
p++;
while (*p == '\n' || *p == '\t' || *p == ' ')
while (whiteness (*p))
p++;
return p;
}
@ -135,7 +135,7 @@ check_patterns (char *p)
static char *
extract_arg (char *p, char *arg, int size)
{
while (*p != '\0' && (*p == ' ' || *p == '\t' || *p == '\n'))
while (*p != '\0' && whiteness (*p))
p++;
/* support quote space .mnu */
@ -456,9 +456,9 @@ execute_menu_command (const WEdit * edit_widget, const char *commands, gboolean
{
if (col == 0)
{
if (*commands != ' ' && *commands != '\t')
if (!whitespace (*commands))
break;
while (*commands == ' ' || *commands == '\t')
while (whitespace (*commands))
commands++;
if (*commands == '\0')
break;
@ -1054,7 +1054,7 @@ user_menu_cmd (const WEdit * edit_widget, const char *menu_file, int selected_en
selected = menu_lines;
}
}
else if (*p != ' ' && *p != '\t' && str_isprint (p))
else if (!whitespace (*p) && str_isprint (p))
{
/* A menu entry title line */
if (accept_entry)

View File

@ -2367,8 +2367,7 @@ ftpfs_netrc_next (void)
}
else
{
for (; *netrcp != '\n' && *netrcp != '\t' && *netrcp != ' ' &&
*netrcp != ',' && *netrcp; netrcp++)
for (; *netrcp != '\0' && !whiteness (*netrcp) && *netrcp != ','; netrcp++)
{
if (*netrcp == '\\')
netrcp++;

View File

@ -466,7 +466,7 @@ sfs_init (struct vfs_class *me)
}
c = semi + 1;
while (*c && (*c != ' ') && (*c != '\t'))
while (*c != '\0' && !whitespace (*c))
{
switch (*c)
{