Fix indentation of switch statements

This commit is contained in:
ridiculousfish 2012-11-19 00:31:03 -08:00
parent 7d63900fb8
commit 26678682ca
40 changed files with 7015 additions and 7014 deletions

File diff suppressed because it is too large Load diff

View file

@ -102,29 +102,29 @@ static void replace_part(const wchar_t *begin,
switch (append_mode)
{
case REPLACE_MODE:
{
case REPLACE_MODE:
{
out.append(insert);
out_pos = wcslen(insert) + (begin-buff);
break;
out.append(insert);
out_pos = wcslen(insert) + (begin-buff);
break;
}
case APPEND_MODE:
{
out.append(begin, end-begin);
out.append(insert);
break;
}
case INSERT_MODE:
{
long cursor = get_cursor_pos() -(begin-buff);
out.append(begin, cursor);
out.append(insert);
out.append(begin+cursor, end-begin-cursor);
out_pos += wcslen(insert);
break;
}
}
case APPEND_MODE:
{
out.append(begin, end-begin);
out.append(insert);
break;
}
case INSERT_MODE:
{
long cursor = get_cursor_pos() -(begin-buff);
out.append(begin, cursor);
out.append(insert);
out.append(begin+cursor, end-begin-cursor);
out_pos += wcslen(insert);
break;
}
}
out.append(end);
reader_set_buffer(out, out_pos);
@ -166,12 +166,12 @@ static void write_part(const wchar_t *begin,
switch (tok_last_type(&tok))
{
case TOK_STRING:
{
out.append(escape_string(tok_last(&tok), UNESCAPE_INCOMPLETE));
out.push_back(L'\n');
break;
}
case TOK_STRING:
{
out.append(escape_string(tok_last(&tok), UNESCAPE_INCOMPLETE));
out.push_back(L'\n');
break;
}
}
}
@ -333,82 +333,82 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
switch (opt)
{
case 0:
if (long_options[opt_index].flag != 0)
case 0:
if (long_options[opt_index].flag != 0)
break;
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name);
builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
case L'a':
append_mode = APPEND_MODE;
break;
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name);
builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
case L'a':
append_mode = APPEND_MODE;
break;
case L'b':
buffer_part = STRING_MODE;
break;
case L'b':
buffer_part = STRING_MODE;
break;
case L'i':
append_mode = INSERT_MODE;
break;
case L'i':
append_mode = INSERT_MODE;
break;
case L'r':
append_mode = REPLACE_MODE;
break;
case L'r':
append_mode = REPLACE_MODE;
break;
case 'c':
cut_at_cursor=1;
break;
case 'c':
cut_at_cursor=1;
break;
case 't':
buffer_part = TOKEN_MODE;
break;
case 't':
buffer_part = TOKEN_MODE;
break;
case 'j':
buffer_part = JOB_MODE;
break;
case 'j':
buffer_part = JOB_MODE;
break;
case 'p':
buffer_part = PROCESS_MODE;
break;
case 'p':
buffer_part = PROCESS_MODE;
break;
case 'f':
function_mode=1;
break;
case 'f':
function_mode=1;
break;
case 'o':
tokenize=1;
break;
case 'o':
tokenize=1;
break;
case 'I':
current_buffer = woptarg;
current_cursor_pos = wcslen(woptarg);
break;
case 'I':
current_buffer = woptarg;
current_cursor_pos = wcslen(woptarg);
break;
case 'C':
cursor_mode = 1;
break;
case 'C':
cursor_mode = 1;
break;
case 'L':
line_mode = 1;
break;
case 'L':
line_mode = 1;
break;
case 'S':
search_mode = 1;
break;
case 'S':
search_mode = 1;
break;
case 'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case 'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case L'?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
return 1;
case L'?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
return 1;
}
}
@ -574,72 +574,72 @@ static int builtin_commandline(parser_t &parser, wchar_t **argv)
switch (buffer_part)
{
case STRING_MODE:
{
begin = get_buffer();
end = begin+wcslen(begin);
break;
}
case STRING_MODE:
{
begin = get_buffer();
end = begin+wcslen(begin);
break;
}
case PROCESS_MODE:
{
parse_util_process_extent(get_buffer(),
case PROCESS_MODE:
{
parse_util_process_extent(get_buffer(),
get_cursor_pos(),
&begin,
&end);
break;
}
case JOB_MODE:
{
parse_util_job_extent(get_buffer(),
get_cursor_pos(),
&begin,
&end);
break;
}
break;
}
case JOB_MODE:
{
parse_util_job_extent(get_buffer(),
get_cursor_pos(),
&begin,
&end);
break;
}
case TOKEN_MODE:
{
parse_util_token_extent(get_buffer(),
get_cursor_pos(),
&begin,
&end,
0, 0);
break;
}
case TOKEN_MODE:
{
parse_util_token_extent(get_buffer(),
get_cursor_pos(),
&begin,
&end,
0, 0);
break;
}
}
switch (argc-woptind)
{
case 0:
{
write_part(begin, end, cut_at_cursor, tokenize);
break;
}
case 1:
{
replace_part(begin, end, argv[woptind], append_mode);
break;
}
default:
{
wcstring sb = argv[woptind];
int i;
for (i=woptind+1; i<argc; i++)
case 0:
{
sb.push_back(L'\n');
sb.append(argv[i]);
write_part(begin, end, cut_at_cursor, tokenize);
break;
}
replace_part(begin, end, sb.c_str(), append_mode);
case 1:
{
replace_part(begin, end, argv[woptind], append_mode);
break;
}
break;
}
default:
{
wcstring sb = argv[woptind];
int i;
for (i=woptind+1; i<argc; i++)
{
sb.push_back(L'\n');
sb.append(argv[i]);
}
replace_part(begin, end, sb.c_str(), append_mode);
break;
}
}
return 0;

View file

@ -395,99 +395,99 @@ static int builtin_complete(parser_t &parser, wchar_t **argv)
switch (opt)
{
case 0:
if (long_options[opt_index].flag != 0)
break;
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name);
builtin_print_help(parser, argv[0], stderr_buffer);
case 0:
if (long_options[opt_index].flag != 0)
break;
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name);
builtin_print_help(parser, argv[0], stderr_buffer);
res = true;
break;
case 'x':
result_mode |= EXCLUSIVE;
break;
case 'f':
result_mode |= NO_FILES;
break;
case 'r':
result_mode |= NO_COMMON;
break;
case 'p':
case 'c':
{
wcstring tmp = woptarg;
if (unescape_string(tmp, 1))
{
if (opt=='p')
path.push_back(tmp);
else
cmd.push_back(tmp);
}
else
{
append_format(stderr_buffer, L"%ls: Invalid token '%ls'\n", argv[0], woptarg);
res = true;
break;
case 'x':
result_mode |= EXCLUSIVE;
break;
case 'f':
result_mode |= NO_FILES;
break;
case 'r':
result_mode |= NO_COMMON;
break;
case 'p':
case 'c':
{
wcstring tmp = woptarg;
if (unescape_string(tmp, 1))
{
if (opt=='p')
path.push_back(tmp);
else
cmd.push_back(tmp);
}
else
{
append_format(stderr_buffer, L"%ls: Invalid token '%ls'\n", argv[0], woptarg);
res = true;
}
break;
}
break;
}
case 'd':
desc = woptarg;
break;
case 'd':
desc = woptarg;
break;
case 'u':
authoritative=0;
break;
case 'u':
authoritative=0;
break;
case 'A':
authoritative=1;
break;
case 'A':
authoritative=1;
break;
case 's':
short_opt.append(woptarg);
break;
case 's':
short_opt.append(woptarg);
break;
case 'l':
gnu_opt.push_back(woptarg);
break;
case 'l':
gnu_opt.push_back(woptarg);
break;
case 'o':
old_opt.push_back(woptarg);
break;
case 'o':
old_opt.push_back(woptarg);
break;
case 'a':
comp = woptarg;
break;
case 'a':
comp = woptarg;
break;
case 'e':
remove = 1;
break;
case 'e':
remove = 1;
break;
case 'n':
condition = woptarg;
break;
case 'n':
condition = woptarg;
break;
case 'C':
do_complete = true;
do_complete_param = woptarg ? woptarg : reader_get_buffer();
break;
case 'C':
do_complete = true;
do_complete_param = woptarg ? woptarg : reader_get_buffer();
break;
case 'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case 'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case '?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
res = true;
break;
case '?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
res = true;
break;
}

View file

@ -76,79 +76,79 @@ static void builtin_jobs_print(const job_t *j, int mode, int header)
process_t *p;
switch (mode)
{
case JOBS_DEFAULT:
{
if (header)
case JOBS_DEFAULT:
{
/*
Print table header before first job
*/
stdout_buffer.append(_(L"Job\tGroup\t"));
#ifdef HAVE__PROC_SELF_STAT
stdout_buffer.append(_(L"CPU\t"));
#endif
stdout_buffer.append(_(L"State\tCommand\n"));
}
append_format(stdout_buffer, L"%d\t%d\t", j->job_id, j->pgid);
if (header)
{
/*
Print table header before first job
*/
stdout_buffer.append(_(L"Job\tGroup\t"));
#ifdef HAVE__PROC_SELF_STAT
stdout_buffer.append(_(L"CPU\t"));
#endif
stdout_buffer.append(_(L"State\tCommand\n"));
}
append_format(stdout_buffer, L"%d\t%d\t", j->job_id, j->pgid);
#ifdef HAVE__PROC_SELF_STAT
append_format(stdout_buffer, L"%d%%\t", cpu_use(j));
append_format(stdout_buffer, L"%d%%\t", cpu_use(j));
#endif
stdout_buffer.append(job_is_stopped(j)?_(L"stopped"):_(L"running"));
stdout_buffer.append(L"\t");
stdout_buffer.append(j->command_wcstr());
stdout_buffer.append(L"\n");
break;
}
case JOBS_PRINT_GROUP:
{
if (header)
{
/*
Print table header before first job
*/
stdout_buffer.append(_(L"Group\n"));
}
append_format(stdout_buffer, L"%d\n", j->pgid);
break;
}
case JOBS_PRINT_PID:
{
if (header)
{
/*
Print table header before first job
*/
stdout_buffer.append(_(L"Procces\n"));
stdout_buffer.append(job_is_stopped(j)?_(L"stopped"):_(L"running"));
stdout_buffer.append(L"\t");
stdout_buffer.append(j->command_wcstr());
stdout_buffer.append(L"\n");
break;
}
for (p=j->first_process; p; p=p->next)
case JOBS_PRINT_GROUP:
{
append_format(stdout_buffer, L"%d\n", p->pid);
}
break;
}
case JOBS_PRINT_COMMAND:
{
if (header)
{
/*
Print table header before first job
*/
stdout_buffer.append(_(L"Command\n"));
if (header)
{
/*
Print table header before first job
*/
stdout_buffer.append(_(L"Group\n"));
}
append_format(stdout_buffer, L"%d\n", j->pgid);
break;
}
for (p=j->first_process; p; p=p->next)
case JOBS_PRINT_PID:
{
append_format(stdout_buffer, L"%ls\n", p->argv0());
if (header)
{
/*
Print table header before first job
*/
stdout_buffer.append(_(L"Procces\n"));
}
for (p=j->first_process; p; p=p->next)
{
append_format(stdout_buffer, L"%d\n", p->pid);
}
break;
}
case JOBS_PRINT_COMMAND:
{
if (header)
{
/*
Print table header before first job
*/
stdout_buffer.append(_(L"Command\n"));
}
for (p=j->first_process; p; p=p->next)
{
append_format(stdout_buffer, L"%ls\n", p->argv0());
}
break;
}
break;
}
}
}
@ -212,45 +212,45 @@ static int builtin_jobs(parser_t &parser, wchar_t **argv)
switch (opt)
{
case 0:
if (long_options[opt_index].flag != 0)
case 0:
if (long_options[opt_index].flag != 0)
break;
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name);
builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
case 'p':
mode=JOBS_PRINT_PID;
break;
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name);
builtin_print_help(parser, argv[0], stderr_buffer);
case 'c':
mode=JOBS_PRINT_COMMAND;
break;
case 'g':
mode=JOBS_PRINT_GROUP;
break;
return 1;
case 'l':
{
print_last = 1;
break;
}
case 'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case 'p':
mode=JOBS_PRINT_PID;
break;
case 'c':
mode=JOBS_PRINT_COMMAND;
break;
case 'g':
mode=JOBS_PRINT_GROUP;
break;
case 'l':
{
print_last = 1;
break;
}
case 'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case '?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
return 1;
case '?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
return 1;
}
}

View file

@ -141,19 +141,19 @@ static int my_env_set(const wchar_t *key, const wcstring_list_t &val, int scope)
switch (env_set(key, val_str, scope | ENV_USER))
{
case ENV_PERM:
{
append_format(stderr_buffer, _(L"%ls: Tried to change the read-only variable '%ls'\n"), L"set", key);
retcode=1;
break;
}
case ENV_PERM:
{
append_format(stderr_buffer, _(L"%ls: Tried to change the read-only variable '%ls'\n"), L"set", key);
retcode=1;
break;
}
case ENV_INVALID:
{
append_format(stderr_buffer, _(L"%ls: Unknown error"), L"set");
retcode=1;
break;
}
case ENV_INVALID:
{
append_format(stderr_buffer, _(L"%ls: Unknown error"), L"set");
retcode=1;
break;
}
}
return retcode;
@ -470,55 +470,55 @@ static int builtin_set(parser_t &parser, wchar_t **argv)
switch (c)
{
case 0:
break;
case 0:
break;
case 'e':
erase = 1;
break;
case 'e':
erase = 1;
break;
case 'n':
list = 1;
break;
case 'n':
list = 1;
break;
case 'x':
exportv = 1;
break;
case 'x':
exportv = 1;
break;
case 'l':
local = 1;
break;
case 'l':
local = 1;
break;
case 'g':
global = 1;
break;
case 'g':
global = 1;
break;
case 'u':
unexport = 1;
break;
case 'u':
unexport = 1;
break;
case 'U':
universal = 1;
break;
case 'U':
universal = 1;
break;
case 'L':
shorten_ok = false;
break;
case 'L':
shorten_ok = false;
break;
case 'q':
query = 1;
break;
case 'q':
query = 1;
break;
case 'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case 'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case '?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
return 1;
case '?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
return 1;
default:
break;
default:
break;
}
}

View file

@ -592,12 +592,12 @@ bool unary_operator::evaluate(wcstring_list_t &errors)
{
switch (token)
{
case test_bang:
assert(subject.get());
return ! subject->evaluate(errors);
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return false;
case test_bang:
assert(subject.get());
return ! subject->evaluate(errors);
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return false;
}
}
@ -606,51 +606,51 @@ bool combining_expression::evaluate(wcstring_list_t &errors)
{
switch (token)
{
case test_combine_and:
case test_combine_or:
{
/* One-element case */
if (subjects.size() == 1)
return subjects.at(0)->evaluate(errors);
/* Evaluate our lists, remembering that AND has higher precedence than OR. We can visualize this as a sequence of OR expressions of AND expressions. */
assert(combiners.size() + 1 == subjects.size());
assert(! subjects.empty());
size_t idx = 0, max = subjects.size();
bool or_result = false;
while (idx < max)
case test_combine_and:
case test_combine_or:
{
if (or_result)
{
/* Short circuit */
break;
}
/* One-element case */
if (subjects.size() == 1)
return subjects.at(0)->evaluate(errors);
/* Evaluate a stream of AND starting at given subject index. It may only have one element. */
bool and_result = true;
for (; idx < max; idx++)
{
/* Evaluate it, short-circuiting */
and_result = and_result && subjects.at(idx)->evaluate(errors);
/* Evaluate our lists, remembering that AND has higher precedence than OR. We can visualize this as a sequence of OR expressions of AND expressions. */
assert(combiners.size() + 1 == subjects.size());
assert(! subjects.empty());
/* If the combiner at this index (which corresponding to how we combine with the next subject) is not AND, then exit the loop */
if (idx + 1 < max && combiners.at(idx) != test_combine_and)
size_t idx = 0, max = subjects.size();
bool or_result = false;
while (idx < max)
{
if (or_result)
{
idx++;
/* Short circuit */
break;
}
/* Evaluate a stream of AND starting at given subject index. It may only have one element. */
bool and_result = true;
for (; idx < max; idx++)
{
/* Evaluate it, short-circuiting */
and_result = and_result && subjects.at(idx)->evaluate(errors);
/* If the combiner at this index (which corresponding to how we combine with the next subject) is not AND, then exit the loop */
if (idx + 1 < max && combiners.at(idx) != test_combine_and)
{
idx++;
break;
}
}
/* OR it in */
or_result = or_result || and_result;
}
/* OR it in */
or_result = or_result || and_result;
return or_result;
}
return or_result;
}
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return BUILTIN_TEST_FAIL;
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return BUILTIN_TEST_FAIL;
}
}
@ -675,33 +675,33 @@ static bool binary_primary_evaluate(test_expressions::token_t token, const wcstr
long long left_num, right_num;
switch (token)
{
case test_string_equal:
return left == right;
case test_string_equal:
return left == right;
case test_string_not_equal:
return left != right;
case test_string_not_equal:
return left != right;
case test_number_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num == right_num;
case test_number_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num == right_num;
case test_number_not_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num != right_num;
case test_number_not_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num != right_num;
case test_number_greater:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num > right_num;
case test_number_greater:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num > right_num;
case test_number_greater_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num >= right_num;
case test_number_greater_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num >= right_num;
case test_number_lesser:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num < right_num;
case test_number_lesser:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num < right_num;
case test_number_lesser_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num <= right_num;
case test_number_lesser_equal:
return parse_number(left, &left_num) && parse_number(right, &right_num) && left_num <= right_num;
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return false;
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return false;
}
}
@ -713,61 +713,61 @@ static bool unary_primary_evaluate(test_expressions::token_t token, const wcstri
long long num;
switch (token)
{
case test_filetype_b: // "-b", for block special files
return !wstat(arg, &buf) && S_ISBLK(buf.st_mode);
case test_filetype_b: // "-b", for block special files
return !wstat(arg, &buf) && S_ISBLK(buf.st_mode);
case test_filetype_c: // "-c" for character special files
return !wstat(arg, &buf) && S_ISCHR(buf.st_mode);
case test_filetype_c: // "-c" for character special files
return !wstat(arg, &buf) && S_ISCHR(buf.st_mode);
case test_filetype_d: // "-d" for directories
return !wstat(arg, &buf) && S_ISDIR(buf.st_mode);
case test_filetype_d: // "-d" for directories
return !wstat(arg, &buf) && S_ISDIR(buf.st_mode);
case test_filetype_e: // "-e" for files that exist
return !wstat(arg, &buf);
case test_filetype_e: // "-e" for files that exist
return !wstat(arg, &buf);
case test_filetype_f: // "-f" for for regular files
return !wstat(arg, &buf) && S_ISREG(buf.st_mode);
case test_filetype_f: // "-f" for for regular files
return !wstat(arg, &buf) && S_ISREG(buf.st_mode);
case test_filetype_g: // "-g" for set-group-id
return !wstat(arg, &buf) && (S_ISGID & buf.st_mode);
case test_filetype_g: // "-g" for set-group-id
return !wstat(arg, &buf) && (S_ISGID & buf.st_mode);
case test_filetype_h: // "-h" for symbolic links
case test_filetype_L: // "-L", same as -h
return !lwstat(arg, &buf) && S_ISLNK(buf.st_mode);
case test_filetype_h: // "-h" for symbolic links
case test_filetype_L: // "-L", same as -h
return !lwstat(arg, &buf) && S_ISLNK(buf.st_mode);
case test_filetype_p: // "-p", for FIFO
return !wstat(arg, &buf) && S_ISFIFO(buf.st_mode);
case test_filetype_p: // "-p", for FIFO
return !wstat(arg, &buf) && S_ISFIFO(buf.st_mode);
case test_filetype_S: // "-S", socket
return !wstat(arg, &buf) && S_ISSOCK(buf.st_mode);
case test_filetype_S: // "-S", socket
return !wstat(arg, &buf) && S_ISSOCK(buf.st_mode);
case test_filesize_s: // "-s", size greater than zero
return !wstat(arg, &buf) && buf.st_size > 0;
case test_filesize_s: // "-s", size greater than zero
return !wstat(arg, &buf) && buf.st_size > 0;
case test_filedesc_t: // "-t", whether the fd is associated with a terminal
return parse_number(arg, &num) && num == (int)num && isatty((int)num);
case test_filedesc_t: // "-t", whether the fd is associated with a terminal
return parse_number(arg, &num) && num == (int)num && isatty((int)num);
case test_fileperm_r: // "-r", read permission
return !waccess(arg, R_OK);
case test_fileperm_r: // "-r", read permission
return !waccess(arg, R_OK);
case test_fileperm_u: // "-u", whether file is setuid
return !wstat(arg, &buf) && (S_ISUID & buf.st_mode);
case test_fileperm_u: // "-u", whether file is setuid
return !wstat(arg, &buf) && (S_ISUID & buf.st_mode);
case test_fileperm_w: // "-w", whether file write permission is allowed
return !waccess(arg, W_OK);
case test_fileperm_w: // "-w", whether file write permission is allowed
return !waccess(arg, W_OK);
case test_fileperm_x: // "-x", whether file execute/search is allowed
return !waccess(arg, X_OK);
case test_fileperm_x: // "-x", whether file execute/search is allowed
return !waccess(arg, X_OK);
case test_string_n: // "-n", non-empty string
return ! arg.empty();
case test_string_n: // "-n", non-empty string
return ! arg.empty();
case test_string_z: // "-z", true if length of string is 0
return arg.empty();
case test_string_z: // "-z", true if length of string is 0
return arg.empty();
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return false;
default:
errors.push_back(format_string(L"Unknown token type in %s", __func__));
return false;
}
}

View file

@ -344,83 +344,83 @@ static int builtin_ulimit(parser_t &parser, wchar_t ** argv)
switch (opt)
{
case 0:
if (long_options[opt_index].flag != 0)
case 0:
if (long_options[opt_index].flag != 0)
break;
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name);
builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
case L'a':
report_all=1;
break;
append_format(stderr_buffer,
BUILTIN_ERR_UNKNOWN,
argv[0],
long_options[opt_index].name);
builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
case L'H':
hard=1;
break;
case L'a':
report_all=1;
break;
case L'S':
soft=1;
break;
case L'H':
hard=1;
break;
case L'c':
what=RLIMIT_CORE;
break;
case L'S':
soft=1;
break;
case L'd':
what=RLIMIT_DATA;
break;
case L'c':
what=RLIMIT_CORE;
break;
case L'd':
what=RLIMIT_DATA;
break;
case L'f':
what=RLIMIT_FSIZE;
break;
case L'f':
what=RLIMIT_FSIZE;
break;
#ifdef RLIMIT_MEMLOCK
case L'l':
what=RLIMIT_MEMLOCK;
break;
case L'l':
what=RLIMIT_MEMLOCK;
break;
#endif
#ifdef RLIMIT_RSS
case L'm':
what=RLIMIT_RSS;
break;
case L'm':
what=RLIMIT_RSS;
break;
#endif
case L'n':
what=RLIMIT_NOFILE;
break;
case L'n':
what=RLIMIT_NOFILE;
break;
case L's':
what=RLIMIT_STACK;
break;
case L's':
what=RLIMIT_STACK;
break;
case L't':
what=RLIMIT_CPU;
break;
case L't':
what=RLIMIT_CPU;
break;
#ifdef RLIMIT_NPROC
case L'u':
what=RLIMIT_NPROC;
break;
case L'u':
what=RLIMIT_NPROC;
break;
#endif
#ifdef RLIMIT_AS
case L'v':
what=RLIMIT_AS;
break;
case L'v':
what=RLIMIT_AS;
break;
#endif
case L'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case L'h':
builtin_print_help(parser, argv[0], stdout_buffer);
return 0;
case L'?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
return 1;
case L'?':
builtin_unknown_option(parser, argv[0], argv[woptind-1]);
return 1;
}
}
@ -443,69 +443,69 @@ static int builtin_ulimit(parser_t &parser, wchar_t ** argv)
switch (argc - woptind)
{
case 0:
{
/*
Show current limit value
*/
print(what, hard);
break;
}
case 1:
{
/*
Change current limit value
*/
rlim_t new_limit;
wchar_t *end;
/*
Set both hard and soft limits if nothing else was specified
*/
if (!(hard+soft))
case 0:
{
hard=soft=1;
/*
Show current limit value
*/
print(what, hard);
break;
}
if (wcscasecmp(argv[woptind], L"unlimited")==0)
case 1:
{
new_limit = RLIM_INFINITY;
}
else if (wcscasecmp(argv[woptind], L"hard")==0)
{
new_limit = get(what, 1);
}
else if (wcscasecmp(argv[woptind], L"soft")==0)
{
new_limit = get(what, soft);
}
else
{
errno=0;
new_limit = wcstol(argv[woptind], &end, 10);
if (errno || *end)
/*
Change current limit value
*/
rlim_t new_limit;
wchar_t *end;
/*
Set both hard and soft limits if nothing else was specified
*/
if (!(hard+soft))
{
append_format(stderr_buffer,
L"%ls: Invalid limit '%ls'\n",
argv[0],
argv[woptind]);
builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
hard=soft=1;
}
new_limit *= get_multiplier(what);
if (wcscasecmp(argv[woptind], L"unlimited")==0)
{
new_limit = RLIM_INFINITY;
}
else if (wcscasecmp(argv[woptind], L"hard")==0)
{
new_limit = get(what, 1);
}
else if (wcscasecmp(argv[woptind], L"soft")==0)
{
new_limit = get(what, soft);
}
else
{
errno=0;
new_limit = wcstol(argv[woptind], &end, 10);
if (errno || *end)
{
append_format(stderr_buffer,
L"%ls: Invalid limit '%ls'\n",
argv[0],
argv[woptind]);
builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
}
new_limit *= get_multiplier(what);
}
return set(what, hard, soft, new_limit);
}
return set(what, hard, soft, new_limit);
}
default:
{
stderr_buffer.append(argv[0]);
stderr_buffer.append(L": Too many arguments\n");
builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
}
default:
{
stderr_buffer.append(argv[0]);
stderr_buffer.append(L": Too many arguments\n");
builtin_print_help(parser, argv[0], stderr_buffer);
return 1;
}
}
return 0;

110
color.cpp
View file

@ -31,46 +31,46 @@ static int parse_hex_digit(wchar_t x)
{
switch (x)
{
case L'0':
return 0x0;
case L'1':
return 0x1;
case L'2':
return 0x2;
case L'3':
return 0x3;
case L'4':
return 0x4;
case L'5':
return 0x5;
case L'6':
return 0x6;
case L'7':
return 0x7;
case L'8':
return 0x8;
case L'9':
return 0x9;
case L'a':
case L'A':
return 0xA;
case L'b':
case L'B':
return 0xB;
case L'c':
case L'C':
return 0xC;
case L'd':
case L'D':
return 0xD;
case L'e':
case L'E':
return 0xE;
case L'f':
case L'F':
return 0xF;
default:
return -1;
case L'0':
return 0x0;
case L'1':
return 0x1;
case L'2':
return 0x2;
case L'3':
return 0x3;
case L'4':
return 0x4;
case L'5':
return 0x5;
case L'6':
return 0x6;
case L'7':
return 0x7;
case L'8':
return 0x8;
case L'9':
return 0x9;
case L'a':
case L'A':
return 0xA;
case L'b':
case L'B':
return 0xB;
case L'c':
case L'C':
return 0xC;
case L'd':
case L'D':
return 0xD;
case L'e':
case L'E':
return 0xE;
case L'f':
case L'F':
return 0xF;
default:
return -1;
}
}
@ -334,20 +334,20 @@ wcstring rgb_color_t::description() const
{
switch (type)
{
case type_none:
return L"none";
case type_named:
return format_string(L"named(%d: %ls)", (int)data.name_idx, name_for_color_idx(data.name_idx));
case type_rgb:
return format_string(L"rgb(0x%02x%02x%02x)", data.rgb[0], data.rgb[1], data.rgb[2]);
case type_reset:
return L"reset";
case type_normal:
return L"normal";
case type_ignore:
return L"ignore";
default:
abort();
return L"";
case type_none:
return L"none";
case type_named:
return format_string(L"named(%d: %ls)", (int)data.name_idx, name_for_color_idx(data.name_idx));
case type_rgb:
return format_string(L"rgb(0x%02x%02x%02x)", data.rgb[0], data.rgb[1], data.rgb[2]);
case type_reset:
return L"reset";
case type_normal:
return L"normal";
case type_ignore:
return L"ignore";
default:
abort();
return L"";
}
}

1176
common.cpp

File diff suppressed because it is too large Load diff

View file

@ -702,20 +702,20 @@ int complete_is_valid_option(const wcstring &str,
switch (opt.size())
{
case 0:
case 1:
{
return true;
}
case 2:
{
if (opt == L"--")
case 0:
case 1:
{
return true;
}
break;
}
case 2:
{
if (opt == L"--")
{
return true;
}
break;
}
}
if (opt.at(0) != L'-')
@ -1816,73 +1816,73 @@ void complete(const wcstring &cmd, std::vector<completion_t> &comps, complete_ty
switch (tok_last_type(&tok))
{
case TOK_STRING:
{
const wcstring ncmd = tok_last(&tok);
int is_ddash = (ncmd == L"--") && ((tok_get_pos(&tok)+2) < (long)pos);
if (!had_cmd)
case TOK_STRING:
{
if (parser_keywords_is_subcommand(ncmd))
const wcstring ncmd = tok_last(&tok);
int is_ddash = (ncmd == L"--") && ((tok_get_pos(&tok)+2) < (long)pos);
if (!had_cmd)
{
if (ncmd == L"builtin")
if (parser_keywords_is_subcommand(ncmd))
{
use_function = 0;
use_command = 0;
use_builtin = 1;
if (ncmd == L"builtin")
{
use_function = 0;
use_command = 0;
use_builtin = 1;
}
else if (ncmd == L"command")
{
use_command = 1;
use_function = 0;
use_builtin = 0;
}
break;
}
else if (ncmd == L"command")
if (!is_ddash ||
((use_command && use_function && use_builtin)))
{
use_command = 1;
use_function = 0;
use_builtin = 0;
current_command = ncmd;
size_t token_end = tok_get_pos(&tok) + ncmd.size();
on_command = (pos <= token_end);
had_cmd=1;
}
}
else
{
if (is_ddash)
{
had_ddash = 1;
}
break;
}
if (!is_ddash ||
((use_command && use_function && use_builtin)))
{
current_command = ncmd;
size_t token_end = tok_get_pos(&tok) + ncmd.size();
on_command = (pos <= token_end);
had_cmd=1;
}
break;
}
else
case TOK_END:
case TOK_PIPE:
case TOK_BACKGROUND:
{
if (is_ddash)
{
had_ddash = 1;
}
had_cmd=0;
had_ddash = 0;
use_command = 1;
use_function = 1;
use_builtin = 1;
break;
}
break;
}
case TOK_END:
case TOK_PIPE:
case TOK_BACKGROUND:
{
had_cmd=0;
had_ddash = 0;
use_command = 1;
use_function = 1;
use_builtin = 1;
break;
}
case TOK_ERROR:
{
end_loop=1;
break;
}
case TOK_ERROR:
{
end_loop=1;
break;
}
}

26
env.cpp
View file

@ -393,21 +393,21 @@ static void universal_callback(fish_message_type_t type,
switch (type)
{
case SET:
case SET_EXPORT:
{
str=L"SET";
break;
}
case SET:
case SET_EXPORT:
{
str=L"SET";
break;
}
case ERASE:
{
str=L"ERASE";
break;
}
case ERASE:
{
str=L"ERASE";
break;
}
default:
break;
default:
break;
}
if (str)

View file

@ -215,17 +215,17 @@ static wchar_t *utf2wcs(const char *in)
switch (sizeof(wchar_t))
{
case 2:
to_name = iconv_wide_names_2;
break;
case 2:
to_name = iconv_wide_names_2;
break;
case 4:
to_name = iconv_wide_names_4;
break;
case 4:
to_name = iconv_wide_names_4;
break;
default:
to_name = iconv_wide_names_unknown;
break;
default:
to_name = iconv_wide_names_unknown;
break;
}
@ -336,17 +336,17 @@ static char *wcs2utf(const wchar_t *in)
switch (sizeof(wchar_t))
{
case 2:
from_name = iconv_wide_names_2;
break;
case 2:
from_name = iconv_wide_names_2;
break;
case 4:
from_name = iconv_wide_names_4;
break;
case 4:
from_name = iconv_wide_names_4;
break;
default:
from_name = iconv_wide_names_unknown;
break;
default:
from_name = iconv_wide_names_unknown;
break;
}
const char **to_name = iconv_utf8_names;
@ -478,34 +478,34 @@ void read_message(connection_t *src)
switch (ib)
{
case ENV_UNIVERSAL_AGAIN:
{
return;
}
case ENV_UNIVERSAL_ERROR:
{
debug(2, L"Read error on fd %d, set killme flag", src->fd);
if (debug_level > 2)
wperror(L"read");
src->killme = 1;
return;
}
case ENV_UNIVERSAL_EOF:
{
src->killme = 1;
debug(3, L"Fd %d has reached eof, set killme flag", src->fd);
if (src->input.size() > 0)
case ENV_UNIVERSAL_AGAIN:
{
char c = 0;
src->input.push_back(c);
debug(1,
L"Universal variable connection closed while reading command. Partial command recieved: '%s'",
&src->input.at(0));
return;
}
case ENV_UNIVERSAL_ERROR:
{
debug(2, L"Read error on fd %d, set killme flag", src->fd);
if (debug_level > 2)
wperror(L"read");
src->killme = 1;
return;
}
case ENV_UNIVERSAL_EOF:
{
src->killme = 1;
debug(3, L"Fd %d has reached eof, set killme flag", src->fd);
if (src->input.size() > 0)
{
char c = 0;
src->input.push_back(c);
debug(1,
L"Universal variable connection closed while reading command. Partial command recieved: '%s'",
&src->input.at(0));
}
return;
}
return;
}
}
b = (char)ib;
@ -712,17 +712,17 @@ static int try_send(message_t *msg,
{
switch (errno)
{
case EAGAIN:
return 0;
case EAGAIN:
return 0;
default:
debug(2,
L"Error while sending universal variable message to fd %d. Closing connection",
fd);
if (debug_level > 2)
wperror(L"write");
default:
debug(2,
L"Error while sending universal variable message to fd %d. Closing connection",
fd);
if (debug_level > 2)
wperror(L"write");
return -1;
return -1;
}
}
msg->count--;
@ -743,18 +743,18 @@ void try_send_all(connection_t *c)
{
switch (try_send(c->unsent->front(), c->fd))
{
case 1:
c->unsent->pop();
break;
case 1:
c->unsent->pop();
break;
case 0:
debug(4,
L"Socket full, send rest later");
return;
case 0:
debug(4,
L"Socket full, send rest later");
return;
case -1:
c->killme = 1;
return;
case -1:
c->killme = 1;
return;
}
}
}
@ -852,44 +852,44 @@ message_t *create_message(fish_message_type_t type,
switch (type)
{
case SET:
case SET_EXPORT:
{
if (!val_in)
case SET:
case SET_EXPORT:
{
val_in=L"";
if (!val_in)
{
val_in=L"";
}
wcstring esc = full_escape(val_in);
char *val = wcs2utf(esc.c_str());
set_body(msg, (type==SET?SET_MBS:SET_EXPORT_MBS), " ", key, ":", val, "\n", NULL);
free(val);
break;
}
wcstring esc = full_escape(val_in);
char *val = wcs2utf(esc.c_str());
set_body(msg, (type==SET?SET_MBS:SET_EXPORT_MBS), " ", key, ":", val, "\n", NULL);
free(val);
case ERASE:
{
set_body(msg, ERASE_MBS, " ", key, "\n", NULL);
break;
}
break;
}
case BARRIER:
{
set_body(msg, BARRIER_MBS, "\n", NULL);
break;
}
case ERASE:
{
set_body(msg, ERASE_MBS, " ", key, "\n", NULL);
break;
}
case BARRIER_REPLY:
{
set_body(msg, BARRIER_REPLY_MBS, "\n", NULL);
break;
}
case BARRIER:
{
set_body(msg, BARRIER_MBS, "\n", NULL);
break;
}
case BARRIER_REPLY:
{
set_body(msg, BARRIER_REPLY_MBS, "\n", NULL);
break;
}
default:
{
debug(0, L"create_message: Unknown message type");
}
default:
{
debug(0, L"create_message: Unknown message type");
}
}
free(key);

View file

@ -107,24 +107,24 @@ static int event_match(const event_t *classv, const event_t *instance)
switch (classv->type)
{
case EVENT_SIGNAL:
if (classv->param1.signal == EVENT_ANY_SIGNAL)
return 1;
return classv->param1.signal == instance->param1.signal;
case EVENT_SIGNAL:
if (classv->param1.signal == EVENT_ANY_SIGNAL)
return 1;
return classv->param1.signal == instance->param1.signal;
case EVENT_VARIABLE:
return instance->str_param1 == classv->str_param1;
case EVENT_VARIABLE:
return instance->str_param1 == classv->str_param1;
case EVENT_EXIT:
if (classv->param1.pid == EVENT_ANY_PID)
return 1;
return classv->param1.pid == instance->param1.pid;
case EVENT_EXIT:
if (classv->param1.pid == EVENT_ANY_PID)
return 1;
return classv->param1.pid == instance->param1.pid;
case EVENT_JOB_ID:
return classv->param1.job_id == instance->param1.job_id;
case EVENT_JOB_ID:
return classv->param1.job_id == instance->param1.job_id;
case EVENT_GENERIC:
return instance->str_param1 == classv->str_param1;
case EVENT_GENERIC:
return instance->str_param1 == classv->str_param1;
}
@ -176,48 +176,48 @@ wcstring event_get_desc(const event_t *e)
switch (e->type)
{
case EVENT_SIGNAL:
result = format_string(_(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal), signal_get_desc(e->param1.signal));
break;
case EVENT_SIGNAL:
result = format_string(_(L"signal handler for %ls (%ls)"), sig2wcs(e->param1.signal), signal_get_desc(e->param1.signal));
break;
case EVENT_VARIABLE:
result = format_string(_(L"handler for variable '%ls'"), e->str_param1.c_str());
break;
case EVENT_VARIABLE:
result = format_string(_(L"handler for variable '%ls'"), e->str_param1.c_str());
break;
case EVENT_EXIT:
if (e->param1.pid > 0)
case EVENT_EXIT:
if (e->param1.pid > 0)
{
result = format_string(_(L"exit handler for process %d"), e->param1.pid);
}
else
{
job_t *j = job_get_from_pid(-e->param1.pid);
if (j)
result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, j->command_wcstr());
else
result = format_string(_(L"exit handler for job with process group %d"), -e->param1.pid);
}
break;
case EVENT_JOB_ID:
{
result = format_string(_(L"exit handler for process %d"), e->param1.pid);
}
else
{
job_t *j = job_get_from_pid(-e->param1.pid);
job_t *j = job_get(e->param1.job_id);
if (j)
result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, j->command_wcstr());
else
result = format_string(_(L"exit handler for job with process group %d"), -e->param1.pid);
result = format_string(_(L"exit handler for job with job id %d"), e->param1.job_id);
break;
}
break;
case EVENT_GENERIC:
result = format_string(_(L"handler for generic event '%ls'"), e->str_param1.c_str());
break;
case EVENT_JOB_ID:
{
job_t *j = job_get(e->param1.job_id);
if (j)
result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, j->command_wcstr());
else
result = format_string(_(L"exit handler for job with job id %d"), e->param1.job_id);
break;
}
case EVENT_GENERIC:
result = format_string(_(L"handler for generic event '%ls'"), e->str_param1.c_str());
break;
default:
result = format_string(_(L"Unknown event type"));
break;
default:
result = format_string(_(L"Unknown event type"));
break;
}

1064
exec.cpp

File diff suppressed because it is too large Load diff

View file

@ -169,18 +169,18 @@ static int is_quotable(const wchar_t *str)
{
switch (*str)
{
case 0:
return 1;
case 0:
return 1;
case L'\n':
case L'\t':
case L'\r':
case L'\b':
case L'\x1b':
return 0;
case L'\n':
case L'\t':
case L'\r':
case L'\b':
case L'\x1b':
return 0;
default:
return is_quotable(str+1);
default:
return is_quotable(str+1);
}
return 0;
@ -201,35 +201,15 @@ wcstring expand_escape_variable(const wcstring &in)
switch (lst.size())
{
case 0:
buff.append(L"''");
break;
case 0:
buff.append(L"''");
break;
case 1:
{
const wcstring &el = lst.at(0);
case 1:
{
const wcstring &el = lst.at(0);
if (el.find(L' ') != wcstring::npos && is_quotable(el))
{
buff.append(L"'");
buff.append(el);
buff.append(L"'");
}
else
{
buff.append(escape_string(el, 1));
}
break;
}
default:
{
for (size_t j=0; j<lst.size(); j++)
{
const wcstring &el = lst.at(j);
if (j)
buff.append(L" ");
if (is_quotable(el))
if (el.find(L' ') != wcstring::npos && is_quotable(el))
{
buff.append(L"'");
buff.append(el);
@ -239,8 +219,28 @@ wcstring expand_escape_variable(const wcstring &in)
{
buff.append(escape_string(el, 1));
}
break;
}
default:
{
for (size_t j=0; j<lst.size(); j++)
{
const wcstring &el = lst.at(j);
if (j)
buff.append(L" ");
if (is_quotable(el))
{
buff.append(L"'");
buff.append(el);
buff.append(L"'");
}
else
{
buff.append(escape_string(el, 1));
}
}
}
}
}
return buff;
}
@ -814,79 +814,79 @@ void expand_variable_error(parser_t &parser, const wchar_t *token, size_t token_
switch (token[stop_pos])
{
case BRACKET_BEGIN:
{
wchar_t *cpy = wcsdup(token);
*(cpy+token_pos)=0;
wchar_t *name = &cpy[stop_pos+1];
wchar_t *end = wcschr(name, BRACKET_END);
wchar_t *post;
int is_var=0;
if (end)
case BRACKET_BEGIN:
{
post = end+1;
*end = 0;
if (!wcsvarname(name))
wchar_t *cpy = wcsdup(token);
*(cpy+token_pos)=0;
wchar_t *name = &cpy[stop_pos+1];
wchar_t *end = wcschr(name, BRACKET_END);
wchar_t *post;
int is_var=0;
if (end)
{
is_var = 1;
post = end+1;
*end = 0;
if (!wcsvarname(name))
{
is_var = 1;
}
}
if (is_var)
{
parser.error(SYNTAX_ERROR,
error_pos,
COMPLETE_VAR_BRACKET_DESC,
cpy,
name,
post);
}
else
{
parser.error(SYNTAX_ERROR,
error_pos,
COMPLETE_VAR_BRACKET_DESC,
L"",
L"VARIABLE",
L"");
}
free(cpy);
break;
}
if (is_var)
case INTERNAL_SEPARATOR:
{
parser.error(SYNTAX_ERROR,
error_pos,
COMPLETE_VAR_BRACKET_DESC,
cpy,
name,
post);
COMPLETE_VAR_PARAN_DESC);
break;
}
else
case 0:
{
parser.error(SYNTAX_ERROR,
error_pos,
COMPLETE_VAR_BRACKET_DESC,
L"",
L"VARIABLE",
L"");
COMPLETE_VAR_NULL_DESC);
break;
}
free(cpy);
break;
}
default:
{
wchar_t token_stop_char = token[stop_pos];
// Unescape (see http://github.com/fish-shell/fish-shell/issues/50)
if (token_stop_char == ANY_CHAR)
token_stop_char = L'?';
else if (token_stop_char == ANY_STRING || token_stop_char == ANY_STRING_RECURSIVE)
token_stop_char = L'*';
case INTERNAL_SEPARATOR:
{
parser.error(SYNTAX_ERROR,
error_pos,
COMPLETE_VAR_PARAN_DESC);
break;
}
case 0:
{
parser.error(SYNTAX_ERROR,
error_pos,
COMPLETE_VAR_NULL_DESC);
break;
}
default:
{
wchar_t token_stop_char = token[stop_pos];
// Unescape (see http://github.com/fish-shell/fish-shell/issues/50)
if (token_stop_char == ANY_CHAR)
token_stop_char = L'?';
else if (token_stop_char == ANY_STRING || token_stop_char == ANY_STRING_RECURSIVE)
token_stop_char = L'*';
parser.error(SYNTAX_ERROR,
error_pos,
(token_stop_char == L'?' ? COMPLETE_YOU_WANT_STATUS : COMPLETE_VAR_DESC),
token_stop_char);
break;
}
parser.error(SYNTAX_ERROR,
error_pos,
(token_stop_char == L'?' ? COMPLETE_YOU_WANT_STATUS : COMPLETE_VAR_DESC),
token_stop_char);
break;
}
}
}
@ -1219,33 +1219,33 @@ static int expand_brackets(parser_t &parser, const wcstring &instr, int flags, s
{
switch (*pos)
{
case BRACKET_BEGIN:
{
bracket_begin = pos;
bracket_count++;
break;
}
case BRACKET_END:
{
bracket_count--;
if (bracket_end < bracket_begin)
case BRACKET_BEGIN:
{
bracket_end = pos;
}
bracket_begin = pos;
bracket_count++;
break;
if (bracket_count < 0)
{
syntax_error = true;
}
break;
}
case BRACKET_SEP:
{
if (bracket_count == 1)
last_sep = pos;
}
case BRACKET_END:
{
bracket_count--;
if (bracket_end < bracket_begin)
{
bracket_end = pos;
}
if (bracket_count < 0)
{
syntax_error = true;
}
break;
}
case BRACKET_SEP:
{
if (bracket_count == 1)
last_sep = pos;
}
}
}
@ -1345,17 +1345,17 @@ static int expand_cmdsubst(parser_t &parser, const wcstring &input, std::vector<
&paran_end,
0))
{
case -1:
parser.error(SYNTAX_ERROR,
-1,
L"Mismatched parenthesis");
return 0;
case 0:
outList.push_back(completion_t(input));
return 1;
case 1:
case -1:
parser.error(SYNTAX_ERROR,
-1,
L"Mismatched parenthesis");
return 0;
case 0:
outList.push_back(completion_t(input));
return 1;
case 1:
break;
break;
}
const wcstring subcmd(paran_begin + 1, paran_end-paran_begin - 1);
@ -1547,13 +1547,13 @@ static void remove_internal_separator(wcstring &str, bool conv)
{
switch (str.at(idx))
{
case ANY_CHAR:
str.at(idx) = L'?';
break;
case ANY_STRING:
case ANY_STRING_RECURSIVE:
str.at(idx) = L'*';
break;
case ANY_CHAR:
str.at(idx) = L'?';
break;
case ANY_STRING:
case ANY_STRING_RECURSIVE:
str.at(idx) = L'*';
break;
}
}
}
@ -1724,34 +1724,34 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
switch (wc_res)
{
case 0:
{
if (!(flags & ACCEPT_INCOMPLETE))
case 0:
{
if (res == EXPAND_OK)
res = EXPAND_WILDCARD_NO_MATCH;
if (!(flags & ACCEPT_INCOMPLETE))
{
if (res == EXPAND_OK)
res = EXPAND_WILDCARD_NO_MATCH;
break;
}
}
case 1:
{
size_t j;
res = EXPAND_WILDCARD_MATCH;
sort_completions(*out);
for (j=0; j< out->size(); j++)
{
output.push_back(out->at(j));
}
out->clear();
break;
}
}
case 1:
{
size_t j;
res = EXPAND_WILDCARD_MATCH;
sort_completions(*out);
for (j=0; j< out->size(); j++)
case -1:
{
output.push_back(out->at(j));
return EXPAND_ERROR;
}
out->clear();
break;
}
case -1:
{
return EXPAND_ERROR;
}
}
}

View file

@ -203,338 +203,338 @@ static int vgwprintf(void (*writer)(wchar_t),
switch (*filter)
{
case L'l':
/* Long variable */
is_long++;
filter++;
break;
case L'l':
/* Long variable */
is_long++;
filter++;
break;
case L'*':
/* Set minimum field width */
width = va_arg(va, int);
filter++;
break;
case L'*':
/* Set minimum field width */
width = va_arg(va, int);
filter++;
break;
case L'-':
filter++;
pad_left=0;
break;
case L'-':
filter++;
pad_left=0;
break;
case L'.':
/*
Set precision.
*/
filter++;
if (*filter == L'*')
{
precision = va_arg(va, int);
}
else
{
precision=0;
while ((*filter >= L'0') && (*filter <= L'9'))
case L'.':
/*
Set precision.
*/
filter++;
if (*filter == L'*')
{
precision=10*precision+(*filter++ - L'0');
precision = va_arg(va, int);
}
}
break;
else
{
precision=0;
while ((*filter >= L'0') && (*filter <= L'9'))
{
precision=10*precision+(*filter++ - L'0');
}
}
break;
default:
loop=0;
break;
default:
loop=0;
break;
}
}
switch (*filter)
{
case L'c':
{
wchar_t c;
if ((width >= 0) && pad_left)
case L'c':
{
pad(writer, width-1);
count += maxi(width-1, 0);
}
wchar_t c;
c = is_long?va_arg(va, wint_t):btowc(va_arg(va, int));
if (precision != 0)
writer(c);
if ((width >= 0) && !pad_left)
{
pad(writer, width-1);
count += maxi(width-1, 0);
}
count++;
break;
}
case L's':
{
wchar_t *ss=0;
if (is_long)
{
ss = va_arg(va, wchar_t *);
}
else
{
char *ns = va_arg(va, char*);
if (ns)
if ((width >= 0) && pad_left)
{
ss = str2wcs(ns);
pad(writer, width-1);
count += maxi(width-1, 0);
}
}
if (!ss)
{
return -1;
}
c = is_long?va_arg(va, wint_t):btowc(va_arg(va, int));
if (precision != 0)
writer(c);
if ((width >= 0) && pad_left)
{
pad(writer, width-wcslen(ss));
count += maxi(width-wcslen(ss), 0);
}
wchar_t *s=ss;
int precount = count;
if ((width >= 0) && !pad_left)
{
pad(writer, width-1);
count += maxi(width-1, 0);
}
while (*s)
{
if ((precision > 0) && (precision <= (count-precount)))
break;
writer(*(s++));
count++;
}
if ((width >= 0) && !pad_left)
{
pad(writer, width-wcslen(ss));
count += maxi(width-wcslen(ss), 0);
}
if (!is_long)
free(ss);
break;
}
case L'd':
case L'i':
case L'o':
case L'u':
case L'x':
case L'X':
{
char str[33];
char *pos;
char format[16];
int len;
format[0]=0;
strcat(format, "%");
if (precision >= 0)
strcat(format, ".*");
switch (is_long)
{
case 2:
strcat(format, "ll");
break;
case 1:
strcat(format, "l");
break;
}
len = strlen(format);
format[len++]=(char)*filter;
format[len]=0;
switch (*filter)
{
case L'd':
case L'i':
case L's':
{
switch (is_long)
wchar_t *ss=0;
if (is_long)
{
case 0:
ss = va_arg(va, wchar_t *);
}
else
{
int d = va_arg(va, int);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
char *ns = va_arg(va, char*);
break;
if (ns)
{
ss = str2wcs(ns);
}
}
case 1:
if (!ss)
{
long d = va_arg(va, long);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
}
case 2:
{
long long d = va_arg(va, long long);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
}
default:
debug(0, L"Invalid length modifier in string %ls\n", filter_org);
return -1;
}
break;
if ((width >= 0) && pad_left)
{
pad(writer, width-wcslen(ss));
count += maxi(width-wcslen(ss), 0);
}
wchar_t *s=ss;
int precount = count;
while (*s)
{
if ((precision > 0) && (precision <= (count-precount)))
break;
writer(*(s++));
count++;
}
if ((width >= 0) && !pad_left)
{
pad(writer, width-wcslen(ss));
count += maxi(width-wcslen(ss), 0);
}
if (!is_long)
free(ss);
break;
}
case L'u':
case L'd':
case L'i':
case L'o':
case L'u':
case L'x':
case L'X':
{
char str[33];
char *pos;
char format[16];
int len;
format[0]=0;
strcat(format, "%");
if (precision >= 0)
strcat(format, ".*");
switch (is_long)
{
case 0:
{
unsigned d = va_arg(va, unsigned);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
case 2:
strcat(format, "ll");
break;
case 1:
strcat(format, "l");
break;
}
case 1:
len = strlen(format);
format[len++]=(char)*filter;
format[len]=0;
switch (*filter)
{
unsigned long d = va_arg(va, unsigned long);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
case L'd':
case L'i':
{
switch (is_long)
{
case 0:
{
int d = va_arg(va, int);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
}
case 1:
{
long d = va_arg(va, long);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
}
case 2:
{
long long d = va_arg(va, long long);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
}
default:
debug(0, L"Invalid length modifier in string %ls\n", filter_org);
return -1;
}
break;
}
case L'u':
case L'o':
case L'x':
case L'X':
{
switch (is_long)
{
case 0:
{
unsigned d = va_arg(va, unsigned);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
}
case 1:
{
unsigned long d = va_arg(va, unsigned long);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
}
case 2:
{
unsigned long long d = va_arg(va, unsigned long long);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
}
default:
debug(0, L"Invalid length modifier in string %ls\n", filter_org);
return -1;
}
break;
}
default:
debug(0, L"Invalid filter %ls in string %ls\n", *filter, filter_org);
return -1;
}
case 2:
if ((width >= 0) && pad_left)
{
unsigned long long d = va_arg(va, unsigned long long);
if (precision >= 0)
snprintf(str, 32, format, precision, d);
else
snprintf(str, 32, format, d);
break;
int l = maxi(width-strlen(str), 0);
pad(writer, l);
count += l;
}
default:
debug(0, L"Invalid length modifier in string %ls\n", filter_org);
return -1;
pos = str;
while (*pos)
{
writer(*(pos++));
count++;
}
if ((width >= 0) && !pad_left)
{
int l = maxi(width-strlen(str), 0);
pad(writer, l);
count += l;
}
break;
}
case L'f':
{
char str[32];
char *pos;
double val = va_arg(va, double);
if (precision>= 0)
{
if (width>= 0)
{
snprintf(str, 32, "%*.*f", width, precision, val);
}
else
{
snprintf(str, 32, "%.*f", precision, val);
}
}
else
{
if (width>= 0)
{
snprintf(str, 32, "%*f", width, val);
}
else
{
snprintf(str, 32, "%f", val);
}
}
pos = str;
while (*pos)
{
writer(*(pos++));
count++;
}
break;
}
case L'n':
{
int *n = va_arg(va, int *);
*n = count;
break;
}
case L'%':
{
writer('%');
count++;
break;
}
default:
debug(0, L"Invalid filter %ls in string %ls\n", *filter, filter_org);
debug(0, L"Unknown switch %lc in string %ls\n", *filter, filter_org);
return -1;
}
if ((width >= 0) && pad_left)
{
int l = maxi(width-strlen(str), 0);
pad(writer, l);
count += l;
}
pos = str;
while (*pos)
{
writer(*(pos++));
count++;
}
if ((width >= 0) && !pad_left)
{
int l = maxi(width-strlen(str), 0);
pad(writer, l);
count += l;
}
break;
}
case L'f':
{
char str[32];
char *pos;
double val = va_arg(va, double);
if (precision>= 0)
{
if (width>= 0)
{
snprintf(str, 32, "%*.*f", width, precision, val);
}
else
{
snprintf(str, 32, "%.*f", precision, val);
}
}
else
{
if (width>= 0)
{
snprintf(str, 32, "%*f", width, val);
}
else
{
snprintf(str, 32, "%f", val);
}
}
pos = str;
while (*pos)
{
writer(*(pos++));
count++;
}
break;
}
case L'n':
{
int *n = va_arg(va, int *);
*n = count;
break;
}
case L'%':
{
writer('%');
count++;
break;
}
default:
debug(0, L"Unknown switch %lc in string %ls\n", *filter, filter_org);
return -1;
}
}
else
@ -673,16 +673,16 @@ wint_t fgetwc(FILE *stream)
switch (sz)
{
case -1:
memset(&state, '\0', sizeof(state));
return WEOF;
case -1:
memset(&state, '\0', sizeof(state));
return WEOF;
case -2:
break;
case 0:
return 0;
default:
return res;
case -2:
break;
case 0:
return 0;
default:
return res;
}
}

140
fish.cpp
View file

@ -306,81 +306,81 @@ static int fish_parse_opt(int argc, char **argv, const char **cmd_ptr)
switch (opt)
{
case 0:
{
break;
}
case 'c':
{
*cmd_ptr = optarg;
is_interactive_session = 0;
break;
}
case 'd':
{
char *end;
long tmp;
errno = 0;
tmp = strtol(optarg, &end, 10);
if (tmp >= 0 && tmp <=10 && !*end && !errno)
case 0:
{
debug_level = (int)tmp;
break;
}
else
case 'c':
{
*cmd_ptr = optarg;
is_interactive_session = 0;
break;
}
case 'd':
{
char *end;
long tmp;
errno = 0;
tmp = strtol(optarg, &end, 10);
if (tmp >= 0 && tmp <=10 && !*end && !errno)
{
debug_level = (int)tmp;
}
else
{
debug(0, _(L"Invalid value '%s' for debug level switch"), optarg);
exit_without_destructors(1);
}
break;
}
case 'h':
{
*cmd_ptr = "__fish_print_help fish";
break;
}
case 'i':
{
force_interactive = 1;
break;
}
case 'l':
{
is_login=1;
break;
}
case 'n':
{
no_exec=1;
break;
}
case 'p':
{
profile = optarg;
break;
}
case 'v':
{
fwprintf(stderr,
_(L"%s, version %s\n"),
PACKAGE_NAME,
PACKAGE_VERSION);
exit_without_destructors(0);
}
case '?':
{
debug(0, _(L"Invalid value '%s' for debug level switch"), optarg);
exit_without_destructors(1);
}
break;
}
case 'h':
{
*cmd_ptr = "__fish_print_help fish";
break;
}
case 'i':
{
force_interactive = 1;
break;
}
case 'l':
{
is_login=1;
break;
}
case 'n':
{
no_exec=1;
break;
}
case 'p':
{
profile = optarg;
break;
}
case 'v':
{
fwprintf(stderr,
_(L"%s, version %s\n"),
PACKAGE_NAME,
PACKAGE_VERSION);
exit_without_destructors(0);
}
case '?':
{
exit_without_destructors(1);
}
}
}

View file

@ -101,157 +101,157 @@ static int indent(wcstring &out, const wcstring &in, int flags)
switch (type)
{
case TOK_STRING:
{
if (is_command)
case TOK_STRING:
{
int next_indent = indent;
is_command = 0;
if (is_command)
{
int next_indent = indent;
is_command = 0;
wcstring unesc = last;
unescape_string(unesc, UNESCAPE_SPECIAL);
wcstring unesc = last;
unescape_string(unesc, UNESCAPE_SPECIAL);
if (parser_keywords_is_block(unesc))
{
next_indent++;
}
else if (unesc == L"else")
{
indent--;
}
/* case should have the same indent level as switch*/
else if (unesc == L"case")
{
indent--;
}
else if (unesc == L"end")
{
indent--;
next_indent--;
}
if (parser_keywords_is_block(unesc))
{
next_indent++;
}
else if (unesc == L"else")
{
indent--;
}
/* case should have the same indent level as switch*/
else if (unesc == L"case")
{
indent--;
}
else if (unesc == L"end")
{
indent--;
next_indent--;
}
if (do_indent && flags && prev_type != TOK_PIPE)
if (do_indent && flags && prev_type != TOK_PIPE)
{
insert_tabs(out, indent);
}
append_format(out, L"%ls", last);
indent = next_indent;
}
else
{
if (prev_type != TOK_REDIRECT_FD)
out.append(L" ");
out.append(last);
}
break;
}
case TOK_END:
{
if (prev_type != TOK_END || prev_prev_type != TOK_END)
out.append(L"\n");
do_indent = 1;
is_command = 1;
break;
}
case TOK_PIPE:
{
out.append(L" ");
if (last[0] == '2' && !last[1])
{
out.append(L"^");
}
else if (last[0] != '1' || last[1])
{
out.append(last);
out.append(L">");
}
out.append(L" | ");
is_command = 1;
break;
}
case TOK_REDIRECT_OUT:
{
out.append(L" ");
if (wcscmp(last, L"2") == 0)
{
out.append(L"^");
}
else
{
if (wcscmp(last, L"1") != 0)
out.append(last);
out.append(L"> ");
}
break;
}
case TOK_REDIRECT_APPEND:
{
out.append(L" ");
if (wcscmp(last, L"2") == 0)
{
out.append(L"^^");
}
else
{
if (wcscmp(last, L"1") != 0)
out.append(last);
out.append(L">> ");
}
break;
}
case TOK_REDIRECT_IN:
{
out.append(L" ");
if (wcscmp(last, L"0") != 0)
out.append(last);
out.append(L"< ");
break;
}
case TOK_REDIRECT_FD:
{
out.append(L" ");
if (wcscmp(last, L"1") != 0)
out.append(last);
out.append(L">& ");
break;
}
case TOK_BACKGROUND:
{
out.append(L"&\n");
do_indent = 1;
is_command = 1;
break;
}
case TOK_COMMENT:
{
if (do_indent && flags)
{
insert_tabs(out, indent);
}
append_format(out, L"%ls", last);
indent = next_indent;
do_indent = 1;
break;
}
else
default:
{
if (prev_type != TOK_REDIRECT_FD)
out.append(L" ");
out.append(last);
debug(0, L"Unknown token '%ls'", last);
exit(1);
}
break;
}
case TOK_END:
{
if (prev_type != TOK_END || prev_prev_type != TOK_END)
out.append(L"\n");
do_indent = 1;
is_command = 1;
break;
}
case TOK_PIPE:
{
out.append(L" ");
if (last[0] == '2' && !last[1])
{
out.append(L"^");
}
else if (last[0] != '1' || last[1])
{
out.append(last);
out.append(L">");
}
out.append(L" | ");
is_command = 1;
break;
}
case TOK_REDIRECT_OUT:
{
out.append(L" ");
if (wcscmp(last, L"2") == 0)
{
out.append(L"^");
}
else
{
if (wcscmp(last, L"1") != 0)
out.append(last);
out.append(L"> ");
}
break;
}
case TOK_REDIRECT_APPEND:
{
out.append(L" ");
if (wcscmp(last, L"2") == 0)
{
out.append(L"^^");
}
else
{
if (wcscmp(last, L"1") != 0)
out.append(last);
out.append(L">> ");
}
break;
}
case TOK_REDIRECT_IN:
{
out.append(L" ");
if (wcscmp(last, L"0") != 0)
out.append(last);
out.append(L"< ");
break;
}
case TOK_REDIRECT_FD:
{
out.append(L" ");
if (wcscmp(last, L"1") != 0)
out.append(last);
out.append(L">& ");
break;
}
case TOK_BACKGROUND:
{
out.append(L"&\n");
do_indent = 1;
is_command = 1;
break;
}
case TOK_COMMENT:
{
if (do_indent && flags)
{
insert_tabs(out, indent);
}
append_format(out, L"%ls", last);
do_indent = 1;
break;
}
default:
{
debug(0, L"Unknown token '%ls'", last);
exit(1);
}
}
prev_prev_type = prev_type;
@ -331,38 +331,38 @@ int main(int argc, char **argv)
switch (opt)
{
case 0:
{
break;
}
case 0:
{
break;
}
case 'h':
{
print_help("fish_indent", 1);
exit(0);
break;
}
case 'h':
{
print_help("fish_indent", 1);
exit(0);
break;
}
case 'v':
{
fwprintf(stderr,
_(L"%ls, version %s\n"),
program_name,
PACKAGE_VERSION);
exit(0);
}
case 'v':
{
fwprintf(stderr,
_(L"%ls, version %s\n"),
program_name,
PACKAGE_VERSION);
exit(0);
}
case 'i':
{
do_indent = 0;
break;
}
case 'i':
{
do_indent = 0;
break;
}
case '?':
{
exit(1);
}
case '?':
{
exit(1);
}
}
}

View file

@ -717,107 +717,107 @@ static int completion_try_print(int cols,
switch (c)
{
case LINE_UP:
{
if (pos > 0)
case LINE_UP:
{
pos--;
writembs(tparm(cursor_address, 0, 0));
writembs(scroll_reverse);
completion_print(cols,
width,
pos,
pos+1,
prefix,
is_quoted,
lst);
writembs(tparm(cursor_address,
termsize.ws_row-1, 0));
writembs(clr_eol);
if (pos > 0)
{
pos--;
writembs(tparm(cursor_address, 0, 0));
writembs(scroll_reverse);
completion_print(cols,
width,
pos,
pos+1,
prefix,
is_quoted,
lst);
writembs(tparm(cursor_address,
termsize.ws_row-1, 0));
writembs(clr_eol);
}
break;
}
case LINE_DOWN:
{
if (pos <= (rows - termsize.ws_row))
{
pos++;
completion_print(cols,
width,
pos+termsize.ws_row-2,
pos+termsize.ws_row-1,
prefix,
is_quoted,
lst);
}
break;
}
case PAGE_DOWN:
{
npos = mini((int)(rows - termsize.ws_row+1), (int)(pos + termsize.ws_row-1));
if (npos != pos)
{
pos = npos;
completion_print(cols,
width,
pos,
pos+termsize.ws_row-1,
prefix,
is_quoted,
lst);
}
else
{
if (flash_screen)
writembs(flash_screen);
}
break;
}
case PAGE_UP:
{
npos = maxi(0,
pos - termsize.ws_row+1);
if (npos != pos)
{
pos = npos;
completion_print(cols,
width,
pos,
pos+termsize.ws_row-1,
prefix,
is_quoted,
lst);
}
else
{
if (flash_screen)
writembs(flash_screen);
}
break;
}
case R_NULL:
{
do_loop=0;
res=PAGER_RESIZE;
break;
}
break;
}
case LINE_DOWN:
{
if (pos <= (rows - termsize.ws_row))
default:
{
pos++;
completion_print(cols,
width,
pos+termsize.ws_row-2,
pos+termsize.ws_row-1,
prefix,
is_quoted,
lst);
out_buff.push_back(c);
do_loop = 0;
break;
}
break;
}
case PAGE_DOWN:
{
npos = mini((int)(rows - termsize.ws_row+1), (int)(pos + termsize.ws_row-1));
if (npos != pos)
{
pos = npos;
completion_print(cols,
width,
pos,
pos+termsize.ws_row-1,
prefix,
is_quoted,
lst);
}
else
{
if (flash_screen)
writembs(flash_screen);
}
break;
}
case PAGE_UP:
{
npos = maxi(0,
pos - termsize.ws_row+1);
if (npos != pos)
{
pos = npos;
completion_print(cols,
width,
pos,
pos+termsize.ws_row-1,
prefix,
is_quoted,
lst);
}
else
{
if (flash_screen)
writembs(flash_screen);
}
break;
}
case R_NULL:
{
do_loop=0;
res=PAGER_RESIZE;
break;
}
default:
{
out_buff.push_back(c);
do_loop = 0;
break;
}
}
}
writembs(clr_eol);
@ -1273,45 +1273,45 @@ int main(int argc, char **argv)
switch (opt)
{
case 0:
{
break;
}
case 0:
{
break;
}
case 'r':
{
result_fd = get_fd(optarg);
break;
}
case 'r':
{
result_fd = get_fd(optarg);
break;
}
case 'c':
{
completion_fd = get_fd(optarg);
break;
}
case 'c':
{
completion_fd = get_fd(optarg);
break;
}
case 'p':
{
prefix = str2wcs(optarg);
break;
}
case 'p':
{
prefix = str2wcs(optarg);
break;
}
case 'h':
{
print_help(argv[0], 1);
exit(0);
}
case 'h':
{
print_help(argv[0], 1);
exit(0);
}
case 'v':
{
debug(0, L"%ls, version %s\n", program_name, PACKAGE_VERSION);
exit(0);
}
case 'v':
{
debug(0, L"%ls, version %s\n", program_name, PACKAGE_VERSION);
exit(0);
}
case 'q':
{
is_quoted = 1;
}
case 'q':
{
is_quoted = 1;
}
}
}
@ -1411,22 +1411,22 @@ int main(int argc, char **argv)
switch (completion_try_print(i, prefix, is_quoted, completions))
{
case PAGER_RETRY:
break;
case PAGER_RETRY:
break;
case PAGER_DONE:
i=0;
break;
case PAGER_DONE:
i=0;
break;
case PAGER_RESIZE:
/*
This means we got a resize event, so we start
over from the beginning. Since it the screen got
bigger, we might be able to fit all completions
on-screen.
*/
i=PAGER_MAX_COLS+1;
break;
case PAGER_RESIZE:
/*
This means we got a resize event, so we start
over from the beginning. Since it the screen got
bigger, we might be able to fit all completions
on-screen.
*/
i=PAGER_MAX_COLS+1;
break;
}
}

View file

@ -535,41 +535,41 @@ static void daemonize()
*/
switch (fork())
{
case -1:
debug(0, L"Could not put fishd in background. Quitting");
wperror(L"fork");
exit(1);
case -1:
debug(0, L"Could not put fishd in background. Quitting");
wperror(L"fork");
exit(1);
case 0:
{
/* Ordinarily there's very limited things we will do after fork, due to multithreading. But fishd is safe because it's single threaded. So don't die in is_forked_child. */
setup_fork_guards();
case 0:
{
/* Ordinarily there's very limited things we will do after fork, due to multithreading. But fishd is safe because it's single threaded. So don't die in is_forked_child. */
setup_fork_guards();
/*
Make fishd ignore the HUP signal.
*/
struct sigaction act;
sigemptyset(& act.sa_mask);
act.sa_flags=0;
act.sa_handler=SIG_IGN;
sigaction(SIGHUP, &act, 0);
/*
Make fishd ignore the HUP signal.
*/
struct sigaction act;
sigemptyset(& act.sa_mask);
act.sa_flags=0;
act.sa_handler=SIG_IGN;
sigaction(SIGHUP, &act, 0);
/*
Make fishd save and exit on the TERM signal.
*/
sigfillset(& act.sa_mask);
act.sa_flags=0;
act.sa_handler=&handle_term;
sigaction(SIGTERM, &act, 0);
break;
/*
Make fishd save and exit on the TERM signal.
*/
sigfillset(& act.sa_mask);
act.sa_flags=0;
act.sa_handler=&handle_term;
sigaction(SIGTERM, &act, 0);
break;
}
}
default:
{
debug(0, L"Parent process exiting (This is normal)");
exit(0);
}
default:
{
debug(0, L"Parent process exiting (This is normal)");
exit(0);
}
}
/*
@ -792,19 +792,19 @@ int main(int argc, char ** argv)
switch (opt)
{
case 0:
break;
case 0:
break;
case 'h':
print_help(argv[0], 1);
exit(0);
case 'h':
print_help(argv[0], 1);
exit(0);
case 'v':
debug(0, L"%ls, version %s\n", program_name, PACKAGE_VERSION);
exit(0);
case 'v':
debug(0, L"%ls, version %s\n", program_name, PACKAGE_VERSION);
exit(0);
case '?':
return 1;
case '?':
return 1;
}
}

File diff suppressed because it is too large Load diff

View file

@ -176,17 +176,17 @@ bool history_item_t::matches_search(const wcstring &term, enum history_search_ty
switch (type)
{
case HISTORY_SEARCH_TYPE_CONTAINS:
/* We consider equal strings to NOT match a contains search (so that you don't have to see history equal to what you typed). The length check ensures that. */
return contents.size() > term.size() && contents.find(term) != wcstring::npos;
case HISTORY_SEARCH_TYPE_CONTAINS:
/* We consider equal strings to NOT match a contains search (so that you don't have to see history equal to what you typed). The length check ensures that. */
return contents.size() > term.size() && contents.find(term) != wcstring::npos;
case HISTORY_SEARCH_TYPE_PREFIX:
/* We consider equal strings to match a prefix search, so that autosuggest will allow suggesting what you've typed */
return string_prefixes_string(term, contents);
case HISTORY_SEARCH_TYPE_PREFIX:
/* We consider equal strings to match a prefix search, so that autosuggest will allow suggesting what you've typed */
return string_prefixes_string(term, contents);
default:
sanity_lose();
return false;
default:
sanity_lose();
return false;
}
}
@ -388,25 +388,25 @@ static size_t offset_of_next_item_fish_1_x(const char *begin, size_t mmap_length
switch (*pos)
{
case '\\':
{
pos++;
break;
}
case '\\':
{
pos++;
break;
}
case '\n':
{
if (ignore_newline)
case '\n':
{
ignore_newline = false;
if (ignore_newline)
{
ignore_newline = false;
}
else
{
/* Note: pos will be left pointing just after this newline, because of the ++ in the loop */
all_done = true;
}
break;
}
else
{
/* Note: pos will be left pointing just after this newline, because of the ++ in the loop */
all_done = true;
}
break;
}
}
}
*inout_cursor = (pos - begin);
@ -419,19 +419,19 @@ static size_t offset_of_next_item(const char *begin, size_t mmap_length, history
size_t result;
switch (mmap_type)
{
case history_type_fish_2_0:
result = offset_of_next_item_fish_2_0(begin, mmap_length, inout_cursor, cutoff_timestamp);
break;
case history_type_fish_2_0:
result = offset_of_next_item_fish_2_0(begin, mmap_length, inout_cursor, cutoff_timestamp);
break;
case history_type_fish_1_x:
result = offset_of_next_item_fish_1_x(begin, mmap_length, inout_cursor, cutoff_timestamp);
break;
case history_type_fish_1_x:
result = offset_of_next_item_fish_1_x(begin, mmap_length, inout_cursor, cutoff_timestamp);
break;
default:
case history_type_unknown:
// Oh well
result = (size_t)(-1);
break;
default:
case history_type_unknown:
// Oh well
result = (size_t)(-1);
break;
}
return result;
}
@ -706,12 +706,12 @@ history_item_t history_t::decode_item(const char *base, size_t len, history_file
{
switch (type)
{
case history_type_fish_1_x:
return history_t::decode_item_fish_1_x(base, len);
case history_type_fish_2_0:
return history_t::decode_item_fish_2_0(base, len);
default:
return history_item_t(L"");
case history_type_fish_1_x:
return history_t::decode_item_fish_1_x(base, len);
case history_type_fish_2_0:
return history_t::decode_item_fish_2_0(base, len);
default:
return history_item_t(L"");
}
}

View file

@ -400,15 +400,15 @@ static wint_t input_exec_binding(const input_mapping_t &m, const wcstring &seq)
switch (code)
{
case R_SELF_INSERT:
{
return seq[0];
}
case R_SELF_INSERT:
{
return seq[0];
}
default:
{
return code;
}
default:
{
return code;
}
}
}

View file

@ -105,34 +105,34 @@ static wint_t readb()
{
switch (errno)
{
case EINTR:
case EAGAIN:
{
if (interrupt_handler)
case EINTR:
case EAGAIN:
{
int res = interrupt_handler();
if (res)
if (interrupt_handler)
{
return res;
}
if (lookahead_count)
{
return lookahead_arr[--lookahead_count];
int res = interrupt_handler();
if (res)
{
return res;
}
if (lookahead_count)
{
return lookahead_arr[--lookahead_count];
}
}
do_loop = true;
break;
}
default:
{
/*
The terminal has been closed. Save and exit.
*/
return R_EOF;
}
do_loop = true;
break;
}
default:
{
/*
The terminal has been closed. Save and exit.
*/
return R_EOF;
}
}
}
else
@ -198,14 +198,14 @@ wchar_t input_common_readch(int timed)
switch (count)
{
case 0:
return WEOF;
case 0:
return WEOF;
case -1:
return WEOF;
break;
default:
break;
case -1:
return WEOF;
break;
default:
break;
}
}
@ -229,17 +229,17 @@ wchar_t input_common_readch(int timed)
switch (sz)
{
case (size_t)(-1):
memset(&state, '\0', sizeof(state));
debug(2, L"Illegal input");
return R_NULL;
case (size_t)(-2):
break;
case 0:
return 0;
default:
case (size_t)(-1):
memset(&state, '\0', sizeof(state));
debug(2, L"Illegal input");
return R_NULL;
case (size_t)(-2):
break;
case 0:
return 0;
default:
return res;
return res;
}
}
}

30
io.cpp
View file

@ -224,21 +224,21 @@ void io_print(const io_chain_t &chain)
fprintf(stderr, "\t%lu: fd:%d, input:%s, ", (unsigned long)i, io->fd, io->is_input ? "yes" : "no");
switch (io->io_mode)
{
case IO_FILE:
fprintf(stderr, "file (%s)\n", io->filename_cstr);
break;
case IO_PIPE:
fprintf(stderr, "pipe {%d, %d}\n", io->param1.pipe_fd[0], io->param1.pipe_fd[1]);
break;
case IO_FD:
fprintf(stderr, "FD map %d -> %d\n", io->param1.old_fd, io->fd);
break;
case IO_BUFFER:
fprintf(stderr, "buffer %p (size %lu)\n", io->out_buffer_ptr(), io->out_buffer_size());
break;
case IO_CLOSE:
fprintf(stderr, "close %d\n", io->fd);
break;
case IO_FILE:
fprintf(stderr, "file (%s)\n", io->filename_cstr);
break;
case IO_PIPE:
fprintf(stderr, "pipe {%d, %d}\n", io->param1.pipe_fd[0], io->param1.pipe_fd[1]);
break;
case IO_FD:
fprintf(stderr, "FD map %d -> %d\n", io->param1.old_fd, io->fd);
break;
case IO_BUFFER:
fprintf(stderr, "buffer %p (size %lu)\n", io->out_buffer_ptr(), io->out_buffer_size());
break;
case IO_CLOSE:
fprintf(stderr, "close %d\n", io->fd);
break;
}
}
}

View file

@ -434,28 +434,28 @@ static char *munge(char *in)
switch (*in)
{
case ' ':
case '\n':
case '\t':
case '\r':
{
had_whitespace = 1;
break;
}
case '\0':
*p = '\0';
return out;
default:
{
if (printed && had_whitespace)
case ' ':
case '\n':
case '\t':
case '\r':
{
*(p++)=' ';
had_whitespace = 1;
break;
}
case '\0':
*p = '\0';
return out;
default:
{
if (printed && had_whitespace)
{
*(p++)=' ';
}
printed=1;
had_whitespace=0;
*(p++)=*in;
break;
}
printed=1;
had_whitespace=0;
*(p++)=*in;
break;
}
}
in++;
}
@ -486,22 +486,22 @@ static char *get_lang_re()
{
switch (*lang)
{
case '@':
case '.':
case '_':
if (close)
{
*out++ = ')';
*out++ = '?';
}
case '@':
case '.':
case '_':
if (close)
{
*out++ = ')';
*out++ = '?';
}
close=1;
*out++ = '(';
*out++ = *lang;
break;
close=1;
*out++ = '(';
*out++ = *lang;
break;
default:
*out++ = *lang;
default:
*out++ = *lang;
}
}
@ -969,59 +969,59 @@ static void write_file(const char *file, int print_path)
{
switch (*str)
{
case ')':
case '(':
case '-':
case '#':
case '$':
case '}':
case '{':
case ']':
case '[':
case '*':
case '?':
case ' ':
case '|':
case '<':
case '>':
case '^':
case '&':
case '\\':
case '`':
case '\'':
case '\"':
writer('\\');
writer(*str);
break;
case ')':
case '(':
case '-':
case '#':
case '$':
case '}':
case '{':
case ']':
case '[':
case '*':
case '?':
case ' ':
case '|':
case '<':
case '>':
case '^':
case '&':
case '\\':
case '`':
case '\'':
case '\"':
writer('\\');
writer(*str);
break;
case '\n':
writer('\\');
writer('n');
break;
case '\n':
writer('\\');
writer('n');
break;
case '\r':
writer('\\');
writer('r');
break;
case '\r':
writer('\\');
writer('r');
break;
case '\t':
writer('\\');
writer('t');
break;
case '\t':
writer('\\');
writer('t');
break;
case '\b':
writer('\\');
writer('b');
break;
case '\b':
writer('\\');
writer('b');
break;
case '\v':
writer('\\');
writer('v');
break;
case '\v':
writer('\\');
writer('v');
break;
default:
writer(*str);
break;
default:
writer(*str);
break;
}
str++;
}
@ -1056,106 +1056,106 @@ static void launch(char *filter, const string_list_t &files, size_t fileno)
filter++;
switch (*filter)
{
case 'u':
{
launch_again = 1;
write_url(files.at(fileno).c_str());
break;
}
case 'U':
{
for (size_t i=0; i<files.size(); i++)
case 'u':
{
if (i != 0)
writer(' ');
write_url(files.at(i).c_str());
if (error)
break;
launch_again = 1;
write_url(files.at(fileno).c_str());
break;
}
break;
}
case 'f':
case 'n':
{
launch_again = 1;
write_file(files.at(fileno).c_str(), *filter == 'f');
break;
}
case 'F':
case 'N':
{
for (size_t i=0; i<files.size(); i++)
case 'U':
{
if (i != 0)
writer(' ');
write_file(files.at(i).c_str(), *filter == 'F');
if (error)
break;
}
break;
}
for (size_t i=0; i<files.size(); i++)
{
if (i != 0)
writer(' ');
write_url(files.at(i).c_str());
if (error)
break;
}
case 'd':
{
const char *cpy = get_fullfile(files.at(fileno).c_str());
char *dir;
launch_again=1;
/*
We wish to modify this string, make sure it is only a copy
*/
if (cpy == files.at(fileno).c_str())
cpy = my_strdup(cpy);
if (cpy == 0)
{
break;
}
dir=dirname((char *)cpy);
write_file(dir, 1);
free((void *)cpy);
break;
}
case 'D':
{
for (size_t i=0; i<files.size(); i++)
case 'f':
case 'n':
{
const char *cpy = get_fullfile(files.at(i).c_str());
launch_again = 1;
write_file(files.at(fileno).c_str(), *filter == 'f');
break;
}
case 'F':
case 'N':
{
for (size_t i=0; i<files.size(); i++)
{
if (i != 0)
writer(' ');
write_file(files.at(i).c_str(), *filter == 'F');
if (error)
break;
}
break;
}
case 'd':
{
const char *cpy = get_fullfile(files.at(fileno).c_str());
char *dir;
launch_again=1;
/*
We wish to modify this string, make sure it is only a copy
*/
if (cpy == files.at(i).c_str())
if (cpy == files.at(fileno).c_str())
cpy = my_strdup(cpy);
if (cpy == 0)
{
break;
}
dir=dirname((char *)cpy);
if (i != 0)
writer(' ');
write_file(dir, 1);
free((void *)cpy);
break;
}
break;
}
default:
fprintf(stderr, _("%s: Unsupported switch '%c' in launch string '%s'\n"), MIMEDB, *filter, filter_org);
launch_len=0;
break;
case 'D':
{
for (size_t i=0; i<files.size(); i++)
{
const char *cpy = get_fullfile(files.at(i).c_str());
char *dir;
/*
We wish to modify this string, make sure it is only a copy
*/
if (cpy == files.at(i).c_str())
cpy = my_strdup(cpy);
if (cpy == 0)
{
break;
}
dir=dirname((char *)cpy);
if (i != 0)
writer(' ');
write_file(dir, 1);
free((void *)cpy);
}
break;
}
default:
fprintf(stderr, _("%s: Unsupported switch '%c' in launch string '%s'\n"), MIMEDB, *filter, filter_org);
launch_len=0;
break;
}
}
@ -1171,31 +1171,31 @@ static void launch(char *filter, const string_list_t &files, size_t fileno)
switch (launch_len)
{
case -1:
{
launch_len = 0;
fprintf(stderr, _("%s: Out of memory\n"), MIMEDB);
return;
}
case 0:
{
return;
}
default:
{
writer(' ');
writer('&');
writer('\0');
if (system(launch_buff) == -1)
case -1:
{
fprintf(stderr, _(ERROR_SYSTEM), MIMEDB, launch_buff);
exit(STATUS_ERROR_SYSTEM);
launch_len = 0;
fprintf(stderr, _("%s: Out of memory\n"), MIMEDB);
return;
}
case 0:
{
return;
}
default:
{
break;
}
writer(' ');
writer('&');
writer('\0');
if (system(launch_buff) == -1)
{
fprintf(stderr, _(ERROR_SYSTEM), MIMEDB, launch_buff);
exit(STATUS_ERROR_SYSTEM);
}
break;
}
}
if (launch_again)
{
@ -1296,47 +1296,47 @@ int main(int argc, char *argv[])
switch (opt)
{
case 0:
break;
case 0:
break;
case 't':
input_type=FILEDATA;
break;
case 't':
input_type=FILEDATA;
break;
case 'f':
input_type=FILENAME;
break;
case 'f':
input_type=FILENAME;
break;
case 'i':
input_type=MIMETYPE;
break;
case 'i':
input_type=MIMETYPE;
break;
case 'm':
output_type=MIMETYPE;
break;
case 'm':
output_type=MIMETYPE;
break;
case 'd':
output_type=DESCRIPTION;
break;
case 'd':
output_type=DESCRIPTION;
break;
case 'a':
output_type=ACTION;
break;
case 'a':
output_type=ACTION;
break;
case 'l':
output_type=LAUNCH;
break;
case 'l':
output_type=LAUNCH;
break;
case 'h':
print_help(argv[0], 1);
exit(0);
case 'h':
print_help(argv[0], 1);
exit(0);
case 'v':
printf(_("%s, version %s\n"), MIMEDB, PACKAGE_VERSION);
exit(0);
case 'v':
printf(_("%s, version %s\n"), MIMEDB, PACKAGE_VERSION);
exit(0);
case '?':
return 1;
case '?':
return 1;
}
}
@ -1381,37 +1381,37 @@ int main(int argc, char *argv[])
*/
switch (output_type)
{
case MIMETYPE:
{
output = (char *)mimetype;
break;
case MIMETYPE:
{
output = (char *)mimetype;
break;
}
case DESCRIPTION:
{
output = get_description(mimetype);
if (!output)
output = strdup(_("Unknown"));
}
case DESCRIPTION:
{
output = get_description(mimetype);
if (!output)
output = strdup(_("Unknown"));
break;
}
case ACTION:
{
output = get_action(mimetype);
break;
}
case LAUNCH:
{
/*
There may be more files using the same launcher, we
add them all up in little array_list_ts and launched
them together after all the arguments have been
parsed.
*/
output = 0;
string_list_t &l = launch_hash[mimetype];
l.push_back(argv[i]);
}
break;
}
case ACTION:
{
output = get_action(mimetype);
break;
}
case LAUNCH:
{
/*
There may be more files using the same launcher, we
add them all up in little array_list_ts and launched
them together after all the arguments have been
parsed.
*/
output = 0;
string_list_t &l = launch_hash[mimetype];
l.push_back(argv[i]);
}
}
/*

View file

@ -453,10 +453,10 @@ int writech(wint_t ch)
switch (bytes)
{
case (size_t)(-1):
{
return 1;
}
case (size_t)(-1):
{
return 1;
}
}
}

View file

@ -373,37 +373,37 @@ static void job_or_process_extent(const wchar_t *buff,
switch (tok_last_type(&tok))
{
case TOK_PIPE:
{
if (!process)
case TOK_PIPE:
{
if (!process)
{
break;
}
}
case TOK_END:
case TOK_BACKGROUND:
{
if (tok_begin >= pos)
{
finished=1;
if (b)
{
*b = (wchar_t *)buff + tok_begin;
}
}
else
{
if (a)
{
*a = (wchar_t *)buff + tok_begin+1;
}
}
break;
}
}
case TOK_END:
case TOK_BACKGROUND:
{
if (tok_begin >= pos)
{
finished=1;
if (b)
{
*b = (wchar_t *)buff + tok_begin;
}
}
else
{
if (a)
{
*a = (wchar_t *)buff + tok_begin+1;
}
}
break;
}
}
}
free(buffcpy);
@ -611,50 +611,50 @@ wchar_t *parse_util_unescape_wildcards(const wchar_t *str)
{
switch (*in)
{
case L'\\':
{
switch (*(in + 1))
{
case L'*':
case L'?':
{
in++;
*(out++)=*in;
break;
}
case L'\\':
{
in++;
*(out++)=L'\\';
*(out++)=L'\\';
switch (*(in + 1))
{
case L'*':
case L'?':
{
in++;
*(out++)=*in;
break;
}
case L'\\':
{
in++;
*(out++)=L'\\';
*(out++)=L'\\';
break;
}
default:
{
*(out++)=*in;
break;
}
}
break;
}
case L'*':
{
*(out++)=ANY_STRING;
break;
}
case L'?':
{
*(out++)=ANY_CHAR;
break;
}
default:
{
*(out++)=*in;
break;
}
}
break;
}
case L'*':
{
*(out++)=ANY_STRING;
break;
}
case L'?':
{
*(out++)=ANY_CHAR;
break;
}
default:
{
*(out++)=*in;
break;
}
}
}
*out = *in;
@ -786,17 +786,17 @@ wcstring parse_util_escape_string_with_quote(const wcstring &cmd, wchar_t quote)
wchar_t c = cmd.at(i);
switch (c)
{
case L'\n':
case L'\t':
case L'\b':
case L'\r':
unescapable = true;
break;
default:
if (c == quote)
result.push_back(L'\\');
result.push_back(c);
break;
case L'\n':
case L'\t':
case L'\b':
case L'\r':
unescapable = true;
break;
default:
if (c == quote)
result.push_back(L'\\');
result.push_back(c);
break;
}
}

2314
parser.cpp

File diff suppressed because it is too large Load diff

View file

@ -110,18 +110,18 @@ static bool path_get_path_core(const wcstring &cmd, wcstring *out_path, const en
{
switch (errno)
{
case ENOENT:
case ENAMETOOLONG:
case EACCES:
case ENOTDIR:
break;
default:
{
debug(1,
MISSING_COMMAND_ERR_MSG,
nxt_path.c_str());
wperror(L"access");
}
case ENOENT:
case ENAMETOOLONG:
case EACCES:
case ENOTDIR:
break;
default:
{
debug(1,
MISSING_COMMAND_ERR_MSG,
nxt_path.c_str());
wperror(L"access");
}
}
}
}

View file

@ -176,36 +176,55 @@ static int handle_child_io(io_chain_t &io_chain)
switch (io->io_mode)
{
case IO_CLOSE:
{
if (close(io->fd))
case IO_CLOSE:
{
debug_safe_int(0, "Failed to close file descriptor %s", io->fd);
wperror(L"close");
if (close(io->fd))
{
debug_safe_int(0, "Failed to close file descriptor %s", io->fd);
wperror(L"close");
}
break;
}
break;
}
case IO_FILE:
{
// Here we definitely do not want to set CLO_EXEC because our child needs access
if ((tmp=open(io->filename_cstr,
io->param2.flags, OPEN_MASK))==-1)
case IO_FILE:
{
if ((io->param2.flags & O_EXCL) &&
(errno ==EEXIST))
// Here we definitely do not want to set CLO_EXEC because our child needs access
if ((tmp=open(io->filename_cstr,
io->param2.flags, OPEN_MASK))==-1)
{
debug_safe(1, NOCLOB_ERROR, io->filename_cstr);
}
else
{
debug_safe(1, FILE_ERROR, io->filename_cstr);
perror("open");
}
if ((io->param2.flags & O_EXCL) &&
(errno ==EEXIST))
{
debug_safe(1, NOCLOB_ERROR, io->filename_cstr);
}
else
{
debug_safe(1, FILE_ERROR, io->filename_cstr);
perror("open");
}
return -1;
return -1;
}
else if (tmp != io->fd)
{
/*
This call will sometimes fail, but that is ok,
this is just a precausion.
*/
close(io->fd);
if (dup2(tmp, io->fd) == -1)
{
debug_safe_int(1, FD_ERROR, io->fd);
perror("dup2");
return -1;
}
exec_close(tmp);
}
break;
}
else if (tmp != io->fd)
case IO_FD:
{
/*
This call will sometimes fail, but that is ok,
@ -213,61 +232,42 @@ static int handle_child_io(io_chain_t &io_chain)
*/
close(io->fd);
if (dup2(tmp, io->fd) == -1)
if (dup2(io->param1.old_fd, io->fd) == -1)
{
debug_safe_int(1, FD_ERROR, io->fd);
debug_safe_int(1, FD_ERROR, io->fd);
wperror(L"dup2");
return -1;
}
break;
}
case IO_BUFFER:
case IO_PIPE:
{
/* If write_pipe_idx is 0, it means we're connecting to the read end (first pipe fd). If it's 1, we're connecting to the write end (second pipe fd). */
unsigned int write_pipe_idx = (io->is_input ? 0 : 1);
/*
debug( 0,
L"%ls %ls on fd %d (%d %d)",
write_pipe?L"write":L"read",
(io->io_mode == IO_BUFFER)?L"buffer":L"pipe",
io->fd,
io->param1.pipe_fd[0],
io->param1.pipe_fd[1]);
*/
if (dup2(io->param1.pipe_fd[write_pipe_idx], io->fd) != io->fd)
{
debug_safe(1, LOCAL_PIPE_ERROR);
perror("dup2");
return -1;
}
exec_close(tmp);
if (io->param1.pipe_fd[0] >= 0)
exec_close(io->param1.pipe_fd[0]);
if (io->param1.pipe_fd[1] >= 0)
exec_close(io->param1.pipe_fd[1]);
break;
}
break;
}
case IO_FD:
{
/*
This call will sometimes fail, but that is ok,
this is just a precausion.
*/
close(io->fd);
if (dup2(io->param1.old_fd, io->fd) == -1)
{
debug_safe_int(1, FD_ERROR, io->fd);
wperror(L"dup2");
return -1;
}
break;
}
case IO_BUFFER:
case IO_PIPE:
{
/* If write_pipe_idx is 0, it means we're connecting to the read end (first pipe fd). If it's 1, we're connecting to the write end (second pipe fd). */
unsigned int write_pipe_idx = (io->is_input ? 0 : 1);
/*
debug( 0,
L"%ls %ls on fd %d (%d %d)",
write_pipe?L"write":L"read",
(io->io_mode == IO_BUFFER)?L"buffer":L"pipe",
io->fd,
io->param1.pipe_fd[0],
io->param1.pipe_fd[1]);
*/
if (dup2(io->param1.pipe_fd[write_pipe_idx], io->fd) != io->fd)
{
debug_safe(1, LOCAL_PIPE_ERROR);
perror("dup2");
return -1;
}
if (io->param1.pipe_fd[0] >= 0)
exec_close(io->param1.pipe_fd[0]);
if (io->param1.pipe_fd[1] >= 0)
exec_close(io->param1.pipe_fd[1]);
break;
}
}
}
@ -456,52 +456,52 @@ bool fork_actions_make_spawn_properties(posix_spawnattr_t *attr, posix_spawn_fil
}
switch (io->io_mode)
{
case IO_CLOSE:
{
if (! err)
err = posix_spawn_file_actions_addclose(actions, io->fd);
break;
}
case IO_FILE:
{
if (! err)
err = posix_spawn_file_actions_addopen(actions, io->fd, io->filename_cstr, io->param2.flags /* mode */, OPEN_MASK);
break;
}
case IO_FD:
{
if (! err)
err = posix_spawn_file_actions_adddup2(actions, io->param1.old_fd /* from */, io->fd /* to */);
break;
}
case IO_BUFFER:
case IO_PIPE:
{
unsigned int write_pipe_idx = (io->is_input ? 0 : 1);
int from_fd = io->param1.pipe_fd[write_pipe_idx];
int to_fd = io->fd;
if (! err)
err = posix_spawn_file_actions_adddup2(actions, from_fd, to_fd);
if (write_pipe_idx > 0)
case IO_CLOSE:
{
if (! err)
err = posix_spawn_file_actions_addclose(actions, io->param1.pipe_fd[0]);
if (! err)
err = posix_spawn_file_actions_addclose(actions, io->param1.pipe_fd[1]);
err = posix_spawn_file_actions_addclose(actions, io->fd);
break;
}
else
case IO_FILE:
{
if (! err)
err = posix_spawn_file_actions_addclose(actions, io->param1.pipe_fd[0]);
err = posix_spawn_file_actions_addopen(actions, io->fd, io->filename_cstr, io->param2.flags /* mode */, OPEN_MASK);
break;
}
case IO_FD:
{
if (! err)
err = posix_spawn_file_actions_adddup2(actions, io->param1.old_fd /* from */, io->fd /* to */);
break;
}
case IO_BUFFER:
case IO_PIPE:
{
unsigned int write_pipe_idx = (io->is_input ? 0 : 1);
int from_fd = io->param1.pipe_fd[write_pipe_idx];
int to_fd = io->fd;
if (! err)
err = posix_spawn_file_actions_adddup2(actions, from_fd, to_fd);
if (write_pipe_idx > 0)
{
if (! err)
err = posix_spawn_file_actions_addclose(actions, io->param1.pipe_fd[0]);
if (! err)
err = posix_spawn_file_actions_addclose(actions, io->param1.pipe_fd[1]);
}
else
{
if (! err)
err = posix_spawn_file_actions_addclose(actions, io->param1.pipe_fd[0]);
}
break;
}
break;
}
}
}
@ -523,81 +523,81 @@ void safe_report_exec_error(int err, const char *actual_cmd, char **argv, char *
switch (err)
{
case E2BIG:
{
char sz1[128], sz2[128];
long arg_max = -1;
size_t sz = 0;
char **p;
for (p=argv; *p; p++)
case E2BIG:
{
sz += strlen(*p)+1;
char sz1[128], sz2[128];
long arg_max = -1;
size_t sz = 0;
char **p;
for (p=argv; *p; p++)
{
sz += strlen(*p)+1;
}
for (p=envv; *p; p++)
{
sz += strlen(*p)+1;
}
format_size_safe(sz1, sz);
arg_max = sysconf(_SC_ARG_MAX);
if (arg_max > 0)
{
format_size_safe(sz2, sz);
debug_safe(0, "The total size of the argument and environment lists %s exceeds the operating system limit of %s.", sz1, sz2);
}
else
{
debug_safe(0, "The total size of the argument and environment lists (%s) exceeds the operating system limit.", sz1);
}
debug_safe(0, "Try running the command again with fewer arguments.");
break;
}
for (p=envv; *p; p++)
case ENOEXEC:
{
sz += strlen(*p)+1;
/* Hope strerror doesn't allocate... */
const char *err = strerror(errno);
debug_safe(0, "exec: %s", err);
debug_safe(0, "The file '%s' is marked as an executable but could not be run by the operating system.", actual_cmd);
break;
}
format_size_safe(sz1, sz);
arg_max = sysconf(_SC_ARG_MAX);
if (arg_max > 0)
case ENOENT:
{
format_size_safe(sz2, sz);
debug_safe(0, "The total size of the argument and environment lists %s exceeds the operating system limit of %s.", sz1, sz2);
}
else
{
debug_safe(0, "The total size of the argument and environment lists (%s) exceeds the operating system limit.", sz1);
/* ENOENT is returned by exec() when the path fails, but also returned by posix_spawn if an open file action fails. These cases appear to be impossible to distinguish. We address this by not using posix_spawn for file redirections, so all the ENOENTs we find must be errors from exec(). */
char interpreter_buff[128] = {}, *interpreter;
interpreter = get_interpreter(actual_cmd, interpreter_buff, sizeof interpreter_buff);
if (interpreter && 0 != access(interpreter, X_OK))
{
debug_safe(0, "The file '%s' specified the interpreter '%s', which is not an executable command.", actual_cmd, interpreter);
}
else
{
debug_safe(0, "The file '%s' does not exist or could not be executed.", actual_cmd);
}
break;
}
debug_safe(0, "Try running the command again with fewer arguments.");
break;
}
case ENOEXEC:
{
/* Hope strerror doesn't allocate... */
const char *err = strerror(errno);
debug_safe(0, "exec: %s", err);
debug_safe(0, "The file '%s' is marked as an executable but could not be run by the operating system.", actual_cmd);
break;
}
case ENOENT:
{
/* ENOENT is returned by exec() when the path fails, but also returned by posix_spawn if an open file action fails. These cases appear to be impossible to distinguish. We address this by not using posix_spawn for file redirections, so all the ENOENTs we find must be errors from exec(). */
char interpreter_buff[128] = {}, *interpreter;
interpreter = get_interpreter(actual_cmd, interpreter_buff, sizeof interpreter_buff);
if (interpreter && 0 != access(interpreter, X_OK))
case ENOMEM:
{
debug_safe(0, "The file '%s' specified the interpreter '%s', which is not an executable command.", actual_cmd, interpreter);
debug_safe(0, "Out of memory");
break;
}
else
default:
{
debug_safe(0, "The file '%s' does not exist or could not be executed.", actual_cmd);
/* Hope strerror doesn't allocate... */
const char *err = strerror(errno);
debug_safe(0, "exec: %s", err);
// debug(0, L"The file '%ls' is marked as an executable but could not be run by the operating system.", p->actual_cmd);
break;
}
break;
}
case ENOMEM:
{
debug_safe(0, "Out of memory");
break;
}
default:
{
/* Hope strerror doesn't allocate... */
const char *err = strerror(errno);
debug_safe(0, "exec: %s", err);
// debug(0, L"The file '%ls' is marked as an executable but could not be run by the operating system.", p->actual_cmd);
break;
}
}
}

View file

@ -566,16 +566,16 @@ void job_handle_signal(int signal, siginfo_t *info, void *con)
{
switch (pid=waitpid(-1,&status,WUNTRACED|WNOHANG))
{
case 0:
case -1:
{
errno=errno_old;
return;
}
default:
case 0:
case -1:
{
errno=errno_old;
return;
}
default:
handle_child_status(pid, status);
break;
handle_child_status(pid, status);
break;
}
}
kill(0, SIGIO);
@ -1123,45 +1123,45 @@ void job_continue(job_t *j, int cont)
// debug( 1, L"select_try()" );
switch (select_try(j))
{
case 1:
{
read_try(j);
break;
}
case -1:
{
/*
If there is no funky IO magic, we can use
waitpid instead of handling child deaths
through signals. This gives a rather large
speed boost (A factor 3 startup time
improvement on my 300 MHz machine) on
short-lived jobs.
*/
int status;
pid_t pid = waitpid(-1, &status, WUNTRACED);
if (pid > 0)
case 1:
{
handle_child_status(pid, status);
read_try(j);
break;
}
else
case -1:
{
/*
This probably means we got a
signal. A signal might mean that the
terminal emulator sent us a hup
signal to tell is to close. If so,
we should exit.
If there is no funky IO magic, we can use
waitpid instead of handling child deaths
through signals. This gives a rather large
speed boost (A factor 3 startup time
improvement on my 300 MHz machine) on
short-lived jobs.
*/
if (reader_exit_forced())
int status;
pid_t pid = waitpid(-1, &status, WUNTRACED);
if (pid > 0)
{
quit = 1;
handle_child_status(pid, status);
}
else
{
/*
This probably means we got a
signal. A signal might mean that the
terminal emulator sent us a hup
signal to tell is to close. If so,
we should exit.
*/
if (reader_exit_forced())
{
quit = 1;
}
}
break;
}
break;
}
}
}

1139
reader.cpp

File diff suppressed because it is too large Load diff

View file

@ -457,68 +457,68 @@ static void s_desired_append_char(screen_t *s,
switch (b)
{
case L'\n':
{
int i;
/* Current line is definitely hard wrapped */
s->desired.line(s->desired.cursor.y).is_soft_wrapped = false;
s->desired.create_line(s->desired.line_count());
s->desired.cursor.y++;
s->desired.cursor.x=0;
for (i=0; i < prompt_width+indent*INDENT_STEP; i++)
case L'\n':
{
s_desired_append_char(s, L' ', 0, indent, prompt_width);
}
break;
}
case L'\r':
{
line_t &current = s->desired.line(line_no);
current.clear();
s->desired.cursor.x = 0;
break;
}
default:
{
int screen_width = common_get_width();
int cw = fish_wcwidth(b);
s->desired.create_line(line_no);
/*
Check if we are at the end of the line. If so, continue on the next line.
*/
if ((s->desired.cursor.x + cw) > screen_width)
{
/* Current line is soft wrapped (assuming we support it) */
s->desired.line(s->desired.cursor.y).is_soft_wrapped = true;
//fprintf(stderr, "\n\n1 Soft wrapping %d\n\n", s->desired.cursor.y);
line_no = (int)s->desired.line_count();
s->desired.add_line();
int i;
/* Current line is definitely hard wrapped */
s->desired.line(s->desired.cursor.y).is_soft_wrapped = false;
s->desired.create_line(s->desired.line_count());
s->desired.cursor.y++;
s->desired.cursor.x=0;
for (size_t i=0; i < prompt_width; i++)
for (i=0; i < prompt_width+indent*INDENT_STEP; i++)
{
s_desired_append_char(s, L' ', 0, indent, prompt_width);
}
break;
}
line_t &line = s->desired.line(line_no);
line.append(b, c);
s->desired.cursor.x+= cw;
/* Maybe wrap the cursor to the next line, even if the line itself did not wrap. This avoids wonkiness in the last column. */
if (s->desired.cursor.x >= screen_width)
case L'\r':
{
line.is_soft_wrapped = true;
line_t &current = s->desired.line(line_no);
current.clear();
s->desired.cursor.x = 0;
s->desired.cursor.y++;
break;
}
default:
{
int screen_width = common_get_width();
int cw = fish_wcwidth(b);
s->desired.create_line(line_no);
/*
Check if we are at the end of the line. If so, continue on the next line.
*/
if ((s->desired.cursor.x + cw) > screen_width)
{
/* Current line is soft wrapped (assuming we support it) */
s->desired.line(s->desired.cursor.y).is_soft_wrapped = true;
//fprintf(stderr, "\n\n1 Soft wrapping %d\n\n", s->desired.cursor.y);
line_no = (int)s->desired.line_count();
s->desired.add_line();
s->desired.cursor.y++;
s->desired.cursor.x=0;
for (size_t i=0; i < prompt_width; i++)
{
s_desired_append_char(s, L' ', 0, indent, prompt_width);
}
}
line_t &line = s->desired.line(line_no);
line.append(b, c);
s->desired.cursor.x+= cw;
/* Maybe wrap the cursor to the next line, even if the line itself did not wrap. This avoids wonkiness in the last column. */
if (s->desired.cursor.x >= screen_width)
{
line.is_soft_wrapped = true;
s->desired.cursor.x = 0;
s->desired.cursor.y++;
}
break;
}
break;
}
}
}

View file

@ -261,35 +261,35 @@ int main(int argc, char **argv)
switch (opt)
{
case 0:
break;
case 0:
break;
case 'b':
bgcolor = optarg;
break;
case 'h':
print_help(argv[0], 1);
exit(0);
case 'b':
bgcolor = optarg;
break;
case 'h':
print_help(argv[0], 1);
exit(0);
case 'o':
bold=true;
break;
case 'o':
bold=true;
break;
case 'u':
underline=true;
break;
case 'u':
underline=true;
break;
case 'v':
check_locale_init();
fprintf(stderr, _("%s, version %s\n"), SET_COLOR, PACKAGE_VERSION);
exit(0);
case 'v':
check_locale_init();
fprintf(stderr, _("%s, version %s\n"), SET_COLOR, PACKAGE_VERSION);
exit(0);
case 'c':
print_colors();
exit(0);
case 'c':
print_colors();
exit(0);
case '?':
return 1;
case '?':
return 1;
}
@ -297,19 +297,19 @@ int main(int argc, char **argv)
switch (argc-optind)
{
case 0:
case 0:
// printf( "no fg\n" );
break;
break;
case 1:
fgcolor=argv[optind];
case 1:
fgcolor=argv[optind];
// printf( "fg %s\n", fgcolor );
break;
break;
default:
check_locale_init();
printf(_("%s: Too many arguments\n"), SET_COLOR);
return 1;
default:
check_locale_init();
printf(_("%s: Too many arguments\n"), SET_COLOR);
return 1;
}
/* Infer term256 support */

View file

@ -228,26 +228,26 @@ static bool is_string_char(wchar_t c, bool is_first)
{
switch (c)
{
/* Unconditional separators */
case L'\0':
case L' ':
case L'\n':
case L'|':
case L'\t':
case L';':
case L'#':
case L'\r':
case L'<':
case L'>':
case L'&':
return false;
/* Unconditional separators */
case L'\0':
case L' ':
case L'\n':
case L'|':
case L'\t':
case L';':
case L'#':
case L'\r':
case L'<':
case L'>':
case L'&':
return false;
/* Conditional separator */
case L'^':
return ! is_first;
/* Conditional separator */
case L'^':
return ! is_first;
default:
return true;
default:
return true;
}
}
@ -323,118 +323,118 @@ static void read_string(tokenizer *tok)
*/
switch (mode)
{
case 0:
{
switch (*tok->buff)
case 0:
{
case L'(':
{
paran_count=1;
mode = 1;
break;
}
case L'[':
{
if (tok->buff != start)
mode=2;
break;
}
case L'\'':
case L'"':
{
const wchar_t *end = quote_end(tok->buff);
tok->last_quote = *tok->buff;
if (end)
switch (*tok->buff)
{
tok->buff=(wchar_t *)end;
}
else
{
tok->buff += wcslen(tok->buff);
if ((!tok->accept_unfinished))
case L'(':
{
TOK_CALL_ERROR(tok, TOK_UNTERMINATED_QUOTE, QUOTE_ERROR);
return;
paran_count=1;
mode = 1;
break;
}
do_loop = 0;
}
break;
}
default:
{
if (!is_string_char(*(tok->buff), is_first))
{
do_loop=0;
}
}
}
break;
}
case 3:
case 1:
switch (*tok->buff)
{
case L'\'':
case L'\"':
{
const wchar_t *end = quote_end(tok->buff);
if (end)
{
tok->buff=(wchar_t *)end;
}
else
{
tok->buff += wcslen(tok->buff);
if ((!tok->accept_unfinished))
case L'[':
{
TOK_CALL_ERROR(tok, TOK_UNTERMINATED_QUOTE, QUOTE_ERROR);
return;
if (tok->buff != start)
mode=2;
break;
}
do_loop = 0;
}
case L'\'':
case L'"':
{
const wchar_t *end = quote_end(tok->buff);
tok->last_quote = *tok->buff;
if (end)
{
tok->buff=(wchar_t *)end;
}
else
{
tok->buff += wcslen(tok->buff);
if ((!tok->accept_unfinished))
{
TOK_CALL_ERROR(tok, TOK_UNTERMINATED_QUOTE, QUOTE_ERROR);
return;
}
do_loop = 0;
}
break;
}
default:
{
if (!is_string_char(*(tok->buff), is_first))
{
do_loop=0;
}
}
}
break;
}
case L'(':
paran_count++;
break;
case L')':
paran_count--;
if (paran_count == 0)
case 3:
case 1:
switch (*tok->buff)
{
mode--;
case L'\'':
case L'\"':
{
const wchar_t *end = quote_end(tok->buff);
if (end)
{
tok->buff=(wchar_t *)end;
}
else
{
tok->buff += wcslen(tok->buff);
if ((!tok->accept_unfinished))
{
TOK_CALL_ERROR(tok, TOK_UNTERMINATED_QUOTE, QUOTE_ERROR);
return;
}
do_loop = 0;
}
break;
}
case L'(':
paran_count++;
break;
case L')':
paran_count--;
if (paran_count == 0)
{
mode--;
}
break;
case L'\0':
do_loop = 0;
break;
}
break;
case L'\0':
do_loop = 0;
break;
}
break;
case 2:
switch (*tok->buff)
{
case L'(':
paran_count=1;
mode = 3;
break;
case 2:
switch (*tok->buff)
{
case L'(':
paran_count=1;
mode = 3;
break;
case L']':
mode=0;
break;
case L']':
mode=0;
break;
case L'\0':
do_loop = 0;
case L'\0':
do_loop = 0;
break;
}
break;
}
break;
}
}
@ -643,62 +643,62 @@ void tok_next(tokenizer *tok)
switch (*tok->buff)
{
case L'\0':
tok->last_type = TOK_END;
/*fwprintf( stderr, L"End of string\n" );*/
tok->has_next = false;
break;
case 13:
case L'\n':
case L';':
tok->last_type = TOK_END;
tok->buff++;
break;
case L'&':
tok->last_type = TOK_BACKGROUND;
tok->buff++;
break;
case L'\0':
tok->last_type = TOK_END;
/*fwprintf( stderr, L"End of string\n" );*/
tok->has_next = false;
break;
case 13:
case L'\n':
case L';':
tok->last_type = TOK_END;
tok->buff++;
break;
case L'&':
tok->last_type = TOK_BACKGROUND;
tok->buff++;
break;
case L'|':
check_size(tok, 2);
case L'|':
check_size(tok, 2);
tok->last[0]=L'1';
tok->last[1]=L'\0';
tok->last_type = TOK_PIPE;
tok->buff++;
break;
tok->last[0]=L'1';
tok->last[1]=L'\0';
tok->last_type = TOK_PIPE;
tok->buff++;
break;
case L'>':
read_redirect(tok, 1);
return;
case L'<':
read_redirect(tok, 0);
return;
case L'^':
read_redirect(tok, 2);
return;
case L'>':
read_redirect(tok, 1);
return;
case L'<':
read_redirect(tok, 0);
return;
case L'^':
read_redirect(tok, 2);
return;
default:
{
if (iswdigit(*tok->buff))
default:
{
const wchar_t *orig = tok->buff;
int fd = 0;
while (iswdigit(*tok->buff))
fd = (fd*10) + (*(tok->buff++) - L'0');
switch (*(tok->buff))
if (iswdigit(*tok->buff))
{
case L'^':
case L'>':
case L'<':
read_redirect(tok, fd);
return;
const wchar_t *orig = tok->buff;
int fd = 0;
while (iswdigit(*tok->buff))
fd = (fd*10) + (*(tok->buff++) - L'0');
switch (*(tok->buff))
{
case L'^':
case L'>':
case L'<':
read_redirect(tok, fd);
return;
}
tok->buff = orig;
}
tok->buff = orig;
read_string(tok);
}
read_string(tok);
}
}
@ -720,12 +720,12 @@ wchar_t *tok_first(const wchar_t *str)
switch (tok_last_type(&t))
{
case TOK_STRING:
case TOK_STRING:
// fwprintf( stderr, L"Got token %ls\n", tok_last( &t ));
res = wcsdup(tok_last(&t));
break;
default:
break;
res = wcsdup(tok_last(&t));
break;
default:
break;
}
tok_destroy(&t);
@ -766,24 +766,24 @@ int main(int argc, char **argv)
{
switch (tok_last_type(&tok))
{
case TOK_INVALID:
wprintf(L"Type: INVALID\n");
break;
case TOK_STRING:
wprintf(L"Type: STRING\t Value: %ls\n", tok_last(&tok));
break;
case TOK_PIPE:
wprintf(L"Type: PIPE\n");
break;
case TOK_END:
wprintf(L"Type: END\n");
break;
case TOK_ERROR:
wprintf(L"Type: ERROR\n");
break;
default:
wprintf(L"Type: Unknown\n");
break;
case TOK_INVALID:
wprintf(L"Type: INVALID\n");
break;
case TOK_STRING:
wprintf(L"Type: STRING\t Value: %ls\n", tok_last(&tok));
break;
case TOK_PIPE:
wprintf(L"Type: PIPE\n");
break;
case TOK_END:
wprintf(L"Type: END\n");
break;
case TOK_ERROR:
wprintf(L"Type: ERROR\n");
break;
default:
wprintf(L"Type: Unknown\n");
break;
}
}
tok_destroy(&tok);

View file

@ -477,15 +477,15 @@ static wcstring file_get_desc(const wcstring &filename,
{
switch (err)
{
case ENOENT:
{
return COMPLETE_ROTTEN_SYMLINK_DESC;
}
case ENOENT:
{
return COMPLETE_ROTTEN_SYMLINK_DESC;
}
case ELOOP:
{
return COMPLETE_LOOP_SYMLINK_DESC;
}
case ELOOP:
{
return COMPLETE_LOOP_SYMLINK_DESC;
}
}
/*
On unknown errors we do nothing. The file will be

View file

@ -153,21 +153,21 @@ FILE *wfopen(const wcstring &path, const char *mode)
size_t idx = 0;
switch (mode[idx++])
{
case 'r':
permissions = O_RDONLY;
break;
case 'w':
permissions = O_WRONLY;
options = O_CREAT | O_TRUNC;
break;
case 'a':
permissions = O_WRONLY;
options = O_CREAT | O_APPEND;
break;
default:
errno = EINVAL;
return NULL;
break;
case 'r':
permissions = O_RDONLY;
break;
case 'w':
permissions = O_WRONLY;
options = O_CREAT | O_TRUNC;
break;
case 'a':
permissions = O_WRONLY;
options = O_CREAT | O_APPEND;
break;
default:
errno = EINVAL;
return NULL;
break;
}
/* Skip binary */
if (mode[idx] == 'b')

View file

@ -398,15 +398,15 @@ _xdg_glob_hash_append_glob(XdgGlobHash *glob_hash,
switch (type)
{
case XDG_GLOB_LITERAL:
glob_hash->literal_list = _xdg_glob_list_append(glob_hash->literal_list, strdup(glob), strdup(mime_type));
break;
case XDG_GLOB_SIMPLE:
glob_hash->simple_node = _xdg_glob_hash_insert_text(glob_hash->simple_node, glob + 1, strdup(mime_type));
break;
case XDG_GLOB_FULL:
glob_hash->full_list = _xdg_glob_list_append(glob_hash->full_list, strdup(glob), strdup(mime_type));
break;
case XDG_GLOB_LITERAL:
glob_hash->literal_list = _xdg_glob_list_append(glob_hash->literal_list, strdup(glob), strdup(mime_type));
break;
case XDG_GLOB_SIMPLE:
glob_hash->simple_node = _xdg_glob_hash_insert_text(glob_hash->simple_node, glob + 1, strdup(mime_type));
break;
case XDG_GLOB_FULL:
glob_hash->full_list = _xdg_glob_list_append(glob_hash->full_list, strdup(glob), strdup(mime_type));
break;
}
}

View file

@ -731,30 +731,30 @@ _xdg_mime_magic_read_magic_file(XdgMimeMagic *mime_magic,
{
switch (state)
{
case XDG_MIME_MAGIC_SECTION:
match = _xdg_mime_magic_match_new();
state = _xdg_mime_magic_parse_header(magic_file, match);
if (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_ERROR)
_xdg_mime_magic_match_free(match);
break;
case XDG_MIME_MAGIC_MAGIC:
state = _xdg_mime_magic_parse_magic_line(magic_file, match);
if (state == XDG_MIME_MAGIC_SECTION ||
(state == XDG_MIME_MAGIC_EOF && match->mime_type))
{
match->matchlet = _xdg_mime_magic_matchlet_mirror(match->matchlet);
_xdg_mime_magic_insert_match(mime_magic, match);
}
else if (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_ERROR)
_xdg_mime_magic_match_free(match);
break;
case XDG_MIME_MAGIC_ERROR:
state = _xdg_mime_magic_parse_error(magic_file);
break;
case XDG_MIME_MAGIC_EOF:
default:
/* Make the compiler happy */
assert(0);
case XDG_MIME_MAGIC_SECTION:
match = _xdg_mime_magic_match_new();
state = _xdg_mime_magic_parse_header(magic_file, match);
if (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_ERROR)
_xdg_mime_magic_match_free(match);
break;
case XDG_MIME_MAGIC_MAGIC:
state = _xdg_mime_magic_parse_magic_line(magic_file, match);
if (state == XDG_MIME_MAGIC_SECTION ||
(state == XDG_MIME_MAGIC_EOF && match->mime_type))
{
match->matchlet = _xdg_mime_magic_matchlet_mirror(match->matchlet);
_xdg_mime_magic_insert_match(mime_magic, match);
}
else if (state == XDG_MIME_MAGIC_EOF || state == XDG_MIME_MAGIC_ERROR)
_xdg_mime_magic_match_free(match);
break;
case XDG_MIME_MAGIC_ERROR:
state = _xdg_mime_magic_parse_error(magic_file);
break;
case XDG_MIME_MAGIC_EOF:
default:
/* Make the compiler happy */
assert(0);
}
}
_xdg_mime_update_mime_magic_extents(mime_magic);