source: rtems/cpukit/libmisc/shell/shell_makeargs.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • 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-2008.
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.org/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#include <rtems/shell.h>
19
20int rtems_shell_make_args(
21  char  *commandLine,
22  int   *argc_p,
23  char **argv_p,
24  int    max_args
25)
26{
27  int   argc;
28  char *ch;
29  int   status = 0;
30 
31  argc = 0;
32  ch = commandLine;
33
34  while ( *ch ) {
35
36    while ( isspace((unsigned char)*ch) ) ch++;
37
38    if ( *ch == '\0' )
39      break;
40
41    if ( *ch == '"' ) {
42      argv_p[ argc ] = ++ch;
43      while ( ( *ch != '\0' ) && ( *ch != '"' ) ) ch++;
44    } else {
45      argv_p[ argc ] = ch;
46      while ( ( *ch != '\0' ) && ( !isspace((unsigned char)*ch) ) ) ch++;
47    }
48
49    argc++;
50
51    if ( *ch == '\0' )
52      break;
53
54    *ch++ = '\0';
55
56    if ( argc == (max_args-1) ) {
57        status = -1;
58        break;
59    }
60
61
62  }
63  argv_p[ argc ] = NULL;
64  *argc_p = argc;
65  return status;
66}
67
Note: See TracBrowser for help on using the repository browser.