Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/libiberty/argv.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* Create and destroy argument vectors (argv's)
    2    Copyright (C) 1992 Free Software Foundation, Inc.
     2   Copyright (C) 1992, 2001 Free Software Foundation, Inc.
    33   Written by Fred Fish @ Cygnus Support
    44
     
    3030/*  Routines imported from standard C runtime libraries. */
    3131
    32 #ifdef __STDC__
     32#ifdef ANSI_PROTOTYPES
    3333
    3434#include <stddef.h>
     
    3636#include <stdlib.h>
    3737
    38 #else   /* !__STDC__ */
     38#else   /* !ANSI_PROTOTYPES */
    3939
    4040#if !defined _WIN32 || defined __GNUC__
     
    4747#endif
    4848
    49 #endif  /* __STDC__ */
    50 
    51 #include "alloca-conf.h"
     49#endif  /* ANSI_PROTOTYPES */
     50
    5251
    5352#ifndef NULL
     
    6463/*
    6564
    66 NAME
    67 
    68         dupargv -- duplicate an argument vector
    69 
    70 SYNOPSIS
    71 
    72         char **dupargv (vector)
    73         char **vector;
    74 
    75 DESCRIPTION
    76 
    77         Duplicate an argument vector.  Simply scans through the
    78         vector, duplicating each argument until the
    79         terminating NULL is found.
    80 
    81 RETURNS
    82 
    83         Returns a pointer to the argument vector if
    84         successful. Returns NULL if there is insufficient memory to
    85         complete building the argument vector.
     65@deftypefn Extension char** dupargv (char **@var{vector})
     66
     67Duplicate an argument vector.  Simply scans through @var{vector},
     68duplicating each argument until the terminating @code{NULL} is found.
     69Returns a pointer to the argument vector if successful.  Returns
     70@code{NULL} if there is insufficient memory to complete building the
     71argument vector.
     72
     73@end deftypefn
    8674
    8775*/
     
    121109/*
    122110
    123 NAME
    124 
    125         freeargv -- free an argument vector
    126 
    127 SYNOPSIS
    128 
    129         void freeargv (vector)
    130         char **vector;
    131 
    132 DESCRIPTION
    133 
    134         Free an argument vector that was built using buildargv.  Simply scans
    135         through the vector, freeing the memory for each argument until the
    136         terminating NULL is found, and then frees the vector itself.
    137 
    138 RETURNS
    139 
    140         No value.
     111@deftypefn Extension void freeargv (char **@var{vector})
     112
     113Free an argument vector that was built using @code{buildargv}.  Simply
     114scans through @var{vector}, freeing the memory for each argument until
     115the terminating @code{NULL} is found, and then frees @var{vector}
     116itself.
     117
     118@end deftypefn
    141119
    142120*/
     
    159137/*
    160138
    161 NAME
    162 
    163         buildargv -- build an argument vector from a string
    164 
    165 SYNOPSIS
    166 
    167         char **buildargv (sp)
    168         char *sp;
    169 
    170 DESCRIPTION
    171 
    172         Given a pointer to a string, parse the string extracting fields
    173         separated by whitespace and optionally enclosed within either single
    174         or double quotes (which are stripped off), and build a vector of
    175         pointers to copies of the string for each field.  The input string
    176         remains unchanged.
    177 
    178         All of the memory for the pointer array and copies of the string
    179         is obtained from malloc.  All of the memory can be returned to the
    180         system with the single function call freeargv, which takes the
    181         returned result of buildargv, as it's argument.
    182 
    183         The memory for the argv array is dynamically expanded as necessary.
    184 
    185 RETURNS
    186 
    187         Returns a pointer to the argument vector if successful. Returns NULL
    188         if the input string pointer is NULL or if there is insufficient
    189         memory to complete building the argument vector.
    190 
    191 NOTES
    192 
    193         In order to provide a working buffer for extracting arguments into,
    194         with appropriate stripping of quotes and translation of backslash
    195         sequences, we allocate a working buffer at least as long as the input
    196         string.  This ensures that we always have enough space in which to
    197         work, since the extracted arg is never larger than the input string.
    198 
    199         If the input is a null string (as opposed to a NULL pointer), then
    200         buildarg returns an argv that has one arg, a null string.
    201 
    202         Argv is always kept terminated with a NULL arg pointer, so it can
    203         be passed to freeargv at any time, or returned, as appropriate.
     139@deftypefn Extension char** buildargv (char *@var{sp})
     140
     141Given a pointer to a string, parse the string extracting fields
     142separated by whitespace and optionally enclosed within either single
     143or double quotes (which are stripped off), and build a vector of
     144pointers to copies of the string for each field.  The input string
     145remains unchanged.  The last element of the vector is followed by a
     146@code{NULL} element.
     147
     148All of the memory for the pointer array and copies of the string
     149is obtained from @code{malloc}.  All of the memory can be returned to the
     150system with the single function call @code{freeargv}, which takes the
     151returned result of @code{buildargv}, as it's argument.
     152
     153Returns a pointer to the argument vector if successful.  Returns
     154@code{NULL} if @var{sp} is @code{NULL} or if there is insufficient
     155memory to complete building the argument vector.
     156
     157If the input is a null string (as opposed to a @code{NULL} pointer),
     158then buildarg returns an argument vector that has one arg, a null
     159string.
     160
     161@end deftypefn
     162
     163The memory for the argv array is dynamically expanded as necessary.
     164
     165In order to provide a working buffer for extracting arguments into,
     166with appropriate stripping of quotes and translation of backslash
     167sequences, we allocate a working buffer at least as long as the input
     168string.  This ensures that we always have enough space in which to
     169work, since the extracted arg is never larger than the input string.
     170
     171The argument vector is always kept terminated with a @code{NULL} arg
     172pointer, so it can be passed to @code{freeargv} at any time, or
     173returned, as appropriate.
     174
    204175*/
    205176
    206177char **buildargv (input)
    207 char *input;
     178     const char *input;
    208179{
    209180  char *arg;
     
    338309/* Simple little test driver. */
    339310
    340 static char *tests[] =
     311static const char *const tests[] =
    341312{
    342313  "a simple command line",
     
    355326};
    356327
    357 main ()
     328int main ()
    358329{
    359330  char **argv;
    360   char **test;
     331  const char *const *test;
    361332  char **targs;
    362333
     
    379350    }
    380351
     352  return 0;
    381353}
    382354
Note: See TracChangeset for help on using the changeset viewer.