Skip to content

Commit fa796d6

Browse files
Get some basic function signatures right for new instanced parser
1 parent e4ee4ec commit fa796d6

14 files changed

+280
-262
lines changed

builtin.cpp

+190-191
Large diffs are not rendered by default.

builtin.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "util.h"
1111
#include "io.h"
1212

13+
class parser_t;
14+
1315
enum
1416
{
1517
COMMAND_NOT_BUILTIN,
@@ -125,6 +127,7 @@ int builtin_exists( wchar_t *cmd );
125127
/**
126128
Execute a builtin command
127129
130+
\param parser The parser being used
128131
\param argv Array containing the command and parameters
129132
of the builtin. The list is terminated by a
130133
null pointer. This syntax resembles the syntax
@@ -133,7 +136,7 @@ int builtin_exists( wchar_t *cmd );
133136
134137
\return the exit status of the builtin command
135138
*/
136-
int builtin_run( wchar_t **argv, io_data_t *io );
139+
int builtin_run( parser_t &parser, wchar_t **argv, io_data_t *io );
137140

138141
/**
139142
Insert all builtin names into l. These are not copies of the strings and should not be freed after use.
@@ -143,26 +146,26 @@ void builtin_get_names( array_list_t *list );
143146
/**
144147
Pushes a new set of input/output to the stack. The new stdin is supplied, a new set of output string_buffer_ts is created.
145148
*/
146-
void builtin_push_io( int stdin_fd );
149+
void builtin_push_io( parser_t &parser, int stdin_fd );
147150

148151
/**
149152
Pops a set of input/output from the stack. The output string_buffer_ts are destroued, but the input file is not closed.
150153
*/
151-
void builtin_pop_io();
154+
void builtin_pop_io(parser_t &parser);
152155

153156

154157
/**
155158
Return a one-line description of the specified builtin
156159
*/
157-
const wchar_t *builtin_get_desc( const wchar_t *b );
160+
const wchar_t *builtin_get_desc( parser_t &parser, const wchar_t *b );
158161

159162

160163
/**
161164
Slightly kludgy function used with 'complete -C' in order to make
162165
the commandline builtin operate on the string to complete instead
163166
of operating on whatever is to be completed.
164167
*/
165-
const wchar_t *builtin_complete_get_temporary_buffer();
168+
const wchar_t *builtin_complete_get_temporary_buffer(parser_t &parser);
166169

167170

168171
/**
@@ -171,6 +174,6 @@ const wchar_t *builtin_complete_get_temporary_buffer();
171174
the next time this function is called, and must never be free'd manually.
172175
*/
173176

174-
wchar_t *builtin_help_get( const wchar_t *cmd );
177+
wchar_t *builtin_help_get( parser_t &parser, const wchar_t *cmd );
175178

176179
#endif

builtin_commandline.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static void write_part( const wchar_t *begin,
214214
The commandline builtin. It is used for specifying a new value for
215215
the commandline.
216216
*/
217-
static int builtin_commandline( wchar_t **argv )
217+
static int builtin_commandline( parser_t &parser, wchar_t **argv )
218218
{
219219

220220
int buffer_part=0;
@@ -259,7 +259,7 @@ static int builtin_commandline( wchar_t **argv )
259259
argv[0],
260260
L": Can not set commandline in non-interactive mode\n",
261261
NULL );
262-
builtin_print_help( argv[0], sb_err );
262+
builtin_print_help( parser, argv[0], sb_err );
263263
return 1;
264264
}
265265

@@ -355,7 +355,7 @@ static int builtin_commandline( wchar_t **argv )
355355
BUILTIN_ERR_UNKNOWN,
356356
argv[0],
357357
long_options[opt_index].name );
358-
builtin_print_help( argv[0], sb_err );
358+
builtin_print_help( parser, argv[0], sb_err );
359359

360360
return 1;
361361

@@ -418,11 +418,11 @@ static int builtin_commandline( wchar_t **argv )
418418
break;
419419

420420
case 'h':
421-
builtin_print_help( argv[0], sb_out );
421+
builtin_print_help( parser, argv[0], sb_out );
422422
return 0;
423423

424424
case L'?':
425-
builtin_unknown_option( argv[0], argv[woptind-1] );
425+
builtin_unknown_option( parser, argv[0], argv[woptind-1] );
426426
return 1;
427427
}
428428
}
@@ -440,7 +440,7 @@ static int builtin_commandline( wchar_t **argv )
440440
BUILTIN_ERR_COMBO,
441441
argv[0] );
442442

443-
builtin_print_help( argv[0], sb_err );
443+
builtin_print_help( parser, argv[0], sb_err );
444444
return 1;
445445
}
446446

@@ -451,7 +451,7 @@ static int builtin_commandline( wchar_t **argv )
451451
BUILTIN_ERR_MISSING,
452452
argv[0] );
453453

454-
builtin_print_help( argv[0], sb_err );
454+
builtin_print_help( parser, argv[0], sb_err );
455455
return 1;
456456
}
457457
for( i=woptind; i<argc; i++ )
@@ -472,7 +472,7 @@ static int builtin_commandline( wchar_t **argv )
472472
_(L"%ls: Unknown input function '%ls'\n"),
473473
argv[0],
474474
argv[i] );
475-
builtin_print_help( argv[0], sb_err );
475+
builtin_print_help( parser, argv[0], sb_err );
476476
return 1;
477477
}
478478
}
@@ -490,7 +490,7 @@ static int builtin_commandline( wchar_t **argv )
490490
argv[0],
491491
L": Too many arguments\n",
492492
NULL );
493-
builtin_print_help( argv[0], sb_err );
493+
builtin_print_help( parser, argv[0], sb_err );
494494
return 1;
495495
}
496496

@@ -500,7 +500,7 @@ static int builtin_commandline( wchar_t **argv )
500500
BUILTIN_ERR_COMBO,
501501
argv[0] );
502502

503-
builtin_print_help( argv[0], sb_err );
503+
builtin_print_help( parser, argv[0], sb_err );
504504
return 1;
505505
}
506506

@@ -513,7 +513,7 @@ static int builtin_commandline( wchar_t **argv )
513513
L"--cut-at-cursor and --tokenize can not be used when setting the commandline" );
514514

515515

516-
builtin_print_help( argv[0], sb_err );
516+
builtin_print_help( parser, argv[0], sb_err );
517517
return 1;
518518
}
519519

@@ -524,7 +524,7 @@ static int builtin_commandline( wchar_t **argv )
524524
argv[0],
525525
L"insertion mode switches can not be used when not in insertion mode" );
526526

527-
builtin_print_help( argv[0], sb_err );
527+
builtin_print_help( parser, argv[0], sb_err );
528528
return 1;
529529
}
530530

@@ -556,7 +556,7 @@ static int builtin_commandline( wchar_t **argv )
556556
BUILTIN_ERR_NOT_NUMBER,
557557
argv[0],
558558
argv[woptind] );
559-
builtin_print_help( argv[0], sb_err );
559+
builtin_print_help( parser, argv[0], sb_err );
560560
}
561561

562562
current_buffer = reader_get_buffer();

builtin_complete.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ const wchar_t *builtin_complete_get_temporary_buffer()
289289
tab-completions. Calls the functions in complete.c for any heavy
290290
lifting. Defined in builtin_complete.c
291291
*/
292-
static int builtin_complete( wchar_t **argv )
292+
static int builtin_complete( parser_t &parser, wchar_t **argv )
293293
{
294294
ASSERT_IS_MAIN_THREAD();
295295
int res=0;
@@ -414,7 +414,7 @@ static int builtin_complete( wchar_t **argv )
414414
BUILTIN_ERR_UNKNOWN,
415415
argv[0],
416416
long_options[opt_index].name );
417-
builtin_print_help( argv[0], sb_err );
417+
builtin_print_help( parser, argv[0], sb_err );
418418

419419

420420
res = 1;
@@ -489,11 +489,11 @@ static int builtin_complete( wchar_t **argv )
489489
break;
490490

491491
case 'h':
492-
builtin_print_help( argv[0], sb_out );
492+
builtin_print_help( parser, argv[0], sb_out );
493493
return 0;
494494

495495
case '?':
496-
builtin_unknown_option( argv[0], argv[woptind-1] );
496+
builtin_unknown_option( parser, argv[0], argv[woptind-1] );
497497
res = 1;
498498
break;
499499

@@ -505,14 +505,14 @@ static int builtin_complete( wchar_t **argv )
505505
{
506506
if( condition && wcslen( condition ) )
507507
{
508-
if( parser_test( condition, 0, 0, 0 ) )
508+
if( parser.test( condition, 0, 0, 0 ) )
509509
{
510510
sb_printf( sb_err,
511511
L"%ls: Condition '%ls' contained a syntax error\n",
512512
argv[0],
513513
condition );
514514

515-
parser_test( condition, 0, sb_err, argv[0] );
515+
parser.test( condition, 0, sb_err, argv[0] );
516516

517517
res = 1;
518518
}
@@ -523,14 +523,14 @@ static int builtin_complete( wchar_t **argv )
523523
{
524524
if( comp && wcslen( comp ) )
525525
{
526-
if( parser_test_args( comp, 0, 0 ) )
526+
if( parser.test_args( comp, 0, 0 ) )
527527
{
528528
sb_printf( sb_err,
529529
L"%ls: Completion '%ls' contained a syntax error\n",
530530
argv[0],
531531
comp );
532532

533-
parser_test_args( comp, sb_err, argv[0] );
533+
parser.test_args( comp, sb_err, argv[0] );
534534

535535
res = 1;
536536
}
@@ -597,7 +597,7 @@ static int builtin_complete( wchar_t **argv )
597597
sb_printf( sb_err,
598598
_( L"%ls: Too many arguments\n" ),
599599
argv[0] );
600-
builtin_print_help( argv[0], sb_err );
600+
builtin_print_help( parser, argv[0], sb_err );
601601

602602
res = 1;
603603
}

builtin_jobs.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static void builtin_jobs_print( job_t *j, int mode, int header )
160160
/**
161161
The jobs builtin. Used fopr printing running jobs. Defined in builtin_jobs.c.
162162
*/
163-
static int builtin_jobs( wchar_t **argv )
163+
static int builtin_jobs( parser_t &parser, wchar_t **argv )
164164
{
165165
int argc=0;
166166
int found=0;
@@ -222,7 +222,7 @@ static int builtin_jobs( wchar_t **argv )
222222
argv[0],
223223
long_options[opt_index].name );
224224

225-
builtin_print_help( argv[0], sb_err );
225+
builtin_print_help( parser, argv[0], sb_err );
226226

227227

228228
return 1;
@@ -247,11 +247,11 @@ static int builtin_jobs( wchar_t **argv )
247247
}
248248

249249
case 'h':
250-
builtin_print_help( argv[0], sb_out );
250+
builtin_print_help( parser, argv[0], sb_out );
251251
return 0;
252252

253253
case '?':
254-
builtin_unknown_option( argv[0], argv[woptind-1] );
254+
builtin_unknown_option( parser, argv[0], argv[woptind-1] );
255255
return 1;
256256

257257
}

0 commit comments

Comments
 (0)