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
RevLine 
[814d9588]1/*
[8fdadc8]2 *  Split string into argc/argv style argument list
3 *
[a3ddb08b]4 *  COPYRIGHT (c) 1989-2008.
[814d9588]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
[c499856]9 *  http://www.rtems.org/license/LICENSE.
[814d9588]10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <string.h>
[06443cf]17#include <ctype.h>
[94547d1]18#include <rtems/shell.h>
[814d9588]19
[2eeb648c]20int rtems_shell_make_args(
[814d9588]21  char  *commandLine,
[0893220]22  int   *argc_p,
23  char **argv_p,
[814d9588]24  int    max_args
25)
26{
27  int   argc;
[1fe7324]28  char *ch;
[814d9588]29  int   status = 0;
[1fe7324]30 
[814d9588]31  argc = 0;
[1fe7324]32  ch = commandLine;
33
34  while ( *ch ) {
35
[bab5c5fa]36    while ( isspace((unsigned char)*ch) ) ch++;
[814d9588]37
[1fe7324]38    if ( *ch == '\0' )
[814d9588]39      break;
[1fe7324]40
41    if ( *ch == '"' ) {
[0a973a9e]42      argv_p[ argc ] = ++ch;
43      while ( ( *ch != '\0' ) && ( *ch != '"' ) ) ch++;
[1fe7324]44    } else {
[0a973a9e]45      argv_p[ argc ] = ch;
46      while ( ( *ch != '\0' ) && ( !isspace((unsigned char)*ch) ) ) ch++;
[1fe7324]47    }
48
[0a973a9e]49    argc++;
50
[1fe7324]51    if ( *ch == '\0' )
[814d9588]52      break;
[1fe7324]53
54    *ch++ = '\0';
55
56    if ( argc == (max_args-1) ) {
57        status = -1;
58        break;
[814d9588]59    }
[1fe7324]60
61
[814d9588]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.