source: rtems-schedsim/schedsim/shell/shared/shell_makeargs.c @ a2aad55

Last change on this file since a2aad55 was a2aad55, checked in by Joel Sherrill <joel.sherrill@…>, on May 1, 2013 at 12:41:56 AM

Remove CVS $

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 *  Split string into argc/argv style argument list
3 *
4 *  COPYRIGHT (c) 1989-2013.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <string.h>
17#include <ctype.h>
18
19int rtems_shell_make_args(
20  char  *commandLine,
21  int   *argc_p,
22  char **argv_p,
23  int    max_args
24)
25{
26  int   argc;
27  char *ch;
28  int   status = 0;
29 
30  argc = 0;
31  ch = commandLine;
32
33  while ( *ch ) {
34
35    while ( isspace((unsigned char)*ch) ) ch++;
36
37    if ( *ch == '\0' )
38      break;
39
40    if ( *ch == '"' ) {
41      argv_p[ argc ] = ++ch;
42      while ( ( *ch != '\0' ) && ( *ch != '"' ) ) ch++;
43    } else {
44      argv_p[ argc ] = ch;
45      while ( ( *ch != '\0' ) && ( !isspace((unsigned char)*ch) ) ) ch++;
46    }
47
48    argc++;
49
50    if ( *ch == '\0' )
51      break;
52
53    *ch++ = '\0';
54
55    if ( argc == (max_args-1) ) {
56        status = -1;
57        break;
58    }
59
60
61  }
62  argv_p[ argc ] = NULL;
63  *argc_p = argc;
64  return status;
65}
66
Note: See TracBrowser for help on using the repository browser.