@@ -115,24 +115,24 @@ void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */
115
115
break ;
116
116
}
117
117
}
118
-
118
+
119
119
} /* }}} */
120
120
121
121
static inline phpdbg_input_t * * phpdbg_read_argv (char * buffer , int * argc TSRMLS_DC ) /* {{{ */
122
122
{
123
- char * p , * s ;
123
+ char * p ;
124
124
char b [PHPDBG_MAX_CMD ];
125
125
int l = 0 ;
126
126
enum states {
127
127
IN_BETWEEN ,
128
- IN_WORD ,
129
- IN_STRING
128
+ IN_WORD ,
129
+ IN_STRING
130
130
} state = IN_BETWEEN ;
131
131
phpdbg_input_t * * argv = NULL ;
132
-
132
+
133
133
argv = (phpdbg_input_t * * ) emalloc (sizeof (phpdbg_input_t * * ));
134
134
(* argc ) = 0 ;
135
-
135
+
136
136
#define RESET_STATE () do {\
137
137
phpdbg_input_t *arg = emalloc(sizeof(phpdbg_input_t));\
138
138
if (arg) {\
@@ -157,11 +157,9 @@ static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_D
157
157
}
158
158
if (c == '"' ) {
159
159
state = IN_STRING ;
160
- s = p + 1 ;
161
160
continue ;
162
161
}
163
162
state = IN_WORD ;
164
- s = p ;
165
163
b [l ++ ]= c ;
166
164
continue ;
167
165
@@ -186,39 +184,39 @@ static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_D
186
184
continue ;
187
185
}
188
186
}
189
-
187
+
190
188
switch (state ) {
191
189
case IN_WORD : {
192
190
RESET_STATE ();
193
191
} break ;
194
-
192
+
195
193
case IN_STRING :
196
194
phpdbg_error (
197
- "Malformed command line (unclosed quote) @ %d: %s!" ,
195
+ "Malformed command line (unclosed quote) @ %d: %s!" ,
198
196
(p - buffer )- 1 , & buffer [(p - buffer )- 1 ]);
199
197
break ;
200
198
}
201
-
199
+
202
200
if ((* argc ) == 0 ) {
203
201
/* not needed */
204
202
efree (argv );
205
-
203
+
206
204
/* to be sure */
207
205
return NULL ;
208
206
}
209
-
207
+
210
208
return argv ;
211
209
} /* }}} */
212
210
213
- phpdbg_input_t * phpdbg_read_input (TSRMLS_D ) /* {{{ */
211
+ phpdbg_input_t * phpdbg_read_input (TSRMLS_D ) /* {{{ */
214
212
{
215
213
if (!(PHPDBG_G (flags ) & PHPDBG_IS_QUITTING )) {
216
214
phpdbg_input_t * buffer = NULL ;
217
215
size_t cmd_len = 0L ;
218
216
219
217
#ifndef HAVE_LIBREADLINE
220
218
char * cmd = NULL ;
221
- char buf [PHPDBG_MAX_CMD ];
219
+ char buf [PHPDBG_MAX_CMD ];
222
220
if (!phpdbg_write (PROMPT ) ||
223
221
!fgets (buf , PHPDBG_MAX_CMD , stdin )) {
224
222
/* the user has gone away */
@@ -227,7 +225,7 @@ phpdbg_input_t* phpdbg_read_input(TSRMLS_D) /* {{{ */
227
225
zend_bailout ();
228
226
return NULL ;
229
227
}
230
-
228
+
231
229
cmd = buf ;
232
230
#else
233
231
char * cmd = readline (PROMPT );
@@ -242,46 +240,36 @@ phpdbg_input_t* phpdbg_read_input(TSRMLS_D) /* {{{ */
242
240
add_history (cmd );
243
241
#endif
244
242
245
- /* strip whitespace */
246
- while (cmd && isspace (* cmd ))
247
- cmd ++ ;
248
- cmd_len = strlen (cmd );
249
- while (* cmd && isspace (cmd [cmd_len - 1 ]))
250
- cmd_len -- ;
251
- cmd [cmd_len ] = '\0' ;
252
-
253
243
/* allocate and sanitize buffer */
254
244
buffer = (phpdbg_input_t * ) emalloc (sizeof (phpdbg_input_t ));
255
- if (buffer ) {
256
- buffer -> length = strlen (cmd );
257
- buffer -> string = emalloc (buffer -> length + 1 );
258
- if (buffer -> string ) {
259
- memcpy (
260
- buffer -> string , cmd , buffer -> length );
261
- buffer -> string [buffer -> length ] = '\0' ;
262
- /* store constant pointer to start of buffer */
263
- buffer -> start = (char * const * ) buffer -> string ;
264
- {
265
- /* temporary, when we switch to argv/argc handling
266
- will be unnecessary */
267
- char * store = (char * ) estrdup (buffer -> string );
268
-
269
- buffer -> argv = phpdbg_read_argv (
270
- store , & buffer -> argc TSRMLS_CC );
271
-
272
- if (buffer -> argc ) {
273
- int arg = 0 ;
274
-
275
- while (arg < buffer -> argc ) {
276
- phpdbg_debug (
277
- "argv %d=%s" , arg , buffer -> argv [arg ]-> string );
278
- arg ++ ;
279
- }
280
- }
281
-
282
- efree (store );
245
+ if (!buffer ) {
246
+ return NULL ;
247
+ }
248
+
249
+ buffer -> string = phpdbg_trim (cmd , strlen (cmd ), & buffer -> length );
250
+
251
+ if (buffer -> string ) {
252
+ /* temporary, when we switch to argv/argc handling
253
+ will be unnecessary */
254
+ char * store = (char * ) estrdup (buffer -> string );
255
+
256
+ /* store constant pointer to start of buffer */
257
+ buffer -> start = (char * const * ) buffer -> string ;
258
+
259
+ buffer -> argv = phpdbg_read_argv (
260
+ store , & buffer -> argc TSRMLS_CC );
261
+
262
+ if (buffer -> argc ) {
263
+ int arg = 0 ;
264
+
265
+ while (arg < buffer -> argc ) {
266
+ phpdbg_debug (
267
+ "argv %d=%s" , arg , buffer -> argv [arg ]-> string );
268
+ arg ++ ;
283
269
}
284
270
}
271
+
272
+ efree (store );
285
273
}
286
274
287
275
#ifdef HAVE_LIBREADLINE
@@ -292,18 +280,17 @@ phpdbg_input_t* phpdbg_read_input(TSRMLS_D) /* {{{ */
292
280
293
281
return buffer ;
294
282
}
295
-
283
+
296
284
return NULL ;
297
285
} /* }}} */
298
286
299
287
void phpdbg_destroy_input (phpdbg_input_t * * input TSRMLS_DC ) /*{{{ */
300
288
{
301
289
if (* input ) {
302
-
303
290
if ((* input )-> string ) {
304
291
efree ((* input )-> string );
305
292
}
306
-
293
+
307
294
if ((* input )-> argc > 0 ) {
308
295
int arg ;
309
296
for (arg = 0 ; arg < (* input )-> argc ; arg ++ ) {
@@ -315,7 +302,7 @@ void phpdbg_destroy_input(phpdbg_input_t **input TSRMLS_DC) /*{{{ */
315
302
if ((* input )-> argv ) {
316
303
efree ((* input )-> argv );
317
304
}
318
-
305
+
319
306
efree (* input );
320
307
}
321
308
} /* }}} */
@@ -326,10 +313,10 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
326
313
327
314
if (input -> argc > 0 ) {
328
315
while (command && command -> name && command -> handler ) {
329
- if (((command -> name_len == input -> argv [0 ]-> length ) &&
316
+ if (((command -> name_len == input -> argv [0 ]-> length ) &&
330
317
(memcmp (command -> name , input -> argv [0 ]-> string , command -> name_len ) == SUCCESS )) ||
331
318
(command -> alias &&
332
- (input -> argv [0 ]-> length == 1 ) &&
319
+ (input -> argv [0 ]-> length == 1 ) &&
333
320
(command -> alias == * input -> argv [0 ]-> string ))) {
334
321
335
322
phpdbg_param_t param ;
@@ -353,18 +340,18 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
353
340
input -> argv [1 ]-> string ,
354
341
input -> argv [1 ]-> length ,
355
342
& param TSRMLS_CC );
356
- }
343
+ }
357
344
}
358
345
359
346
phpdbg_debug (
360
- "found command \"%s\" for \"%s\" have %d arguments" ,
347
+ "found command %s for %s with %d arguments" ,
361
348
command -> name , input -> argv [0 ]-> string , input -> argc - 1 );
362
349
{
363
350
int arg ;
364
351
for (arg = 1 ; arg < input -> argc ; arg ++ ) {
365
352
phpdbg_debug (
366
- "\t#%d: [%s=%d]" ,
367
- arg ,
353
+ "\t#%d: [%s=%d]" ,
354
+ arg ,
368
355
input -> argv [arg ]-> string ,
369
356
input -> argv [arg ]-> length );
370
357
}
@@ -376,7 +363,6 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
376
363
PHPDBG_G (lparam ) = param ;
377
364
378
365
rc = command -> handler (& param TSRMLS_CC );
379
-
380
366
break ;
381
367
}
382
368
command ++ ;
@@ -386,7 +372,7 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
386
372
phpdbg_error (
387
373
"No function executed !!" );
388
374
}
389
-
375
+
390
376
return rc ;
391
377
} /* }}} */
392
378
@@ -409,7 +395,7 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
409
395
expr ,
410
396
(cmd_len - expr_len ) ? (((cmd_len - expr_len ) - sizeof (" " ))+ 1 ) : 0 ,
411
397
& param TSRMLS_CC );
412
-
398
+
413
399
if (command -> subs && param .type == STR_PARAM ) {
414
400
if (phpdbg_do_cmd (command -> subs , param .str , param .len TSRMLS_CC ) == SUCCESS ) {
415
401
rc = SUCCESS ;
0 commit comments