Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_prsargv_split - malloc and create an argv-style char ** from words in a string
librock_prsargv_free - Free an argv-style char **, previously returned from librock_prsargv_split
librock_prsargv_glom - Create a string from an argv-style char **
#License - #Source code - #Example Use -

SYNOPSIS

#include <librock/exec.h>

int
librock_prsargv_split(const char *line, char ***argvp);

void
librock_prsargv_free(char ***argvp);

char *
librock_prsargv_glom(const char **av);


DESCRIPTION

librock_prsargv_split parses a string into words separated by tabs and spaces, creating a NULL-terminated array of pointers to each word. This mallocs space for a copy of the string and the argv array, which should be free'd by eventually calling librock_prsargv_free. This does not change the original string. If *argvp isn't NULL, it will first call librock_prsarg_free. On success, the return value is the number of non-NULL points at *argvp. Otherwise the return is -1 on malloc() failure.

There is no recognition of quote, escape, or other special characters. It considers newlines and other characters to be non-spaces. librock_decbe could be helpful to the caller.

librock_prsargv_glom mallocs and creates a string by contatenating all strings in a array terminated by NULL, inserting a single space between elements. The return value is NULL on error. Return value on success should eventually be given to free().

Typical use is to break lines read from files, such as configuration files, into a list for making function calls.

#ifdef librock_TYPICAL_USE_prsargv_split
    #include <librock/exec.h>
    char **testargv = 0; /* Be sure to initialize to 0! */
    int cnt;
    cnt = librock_prsargv_split("This is  a test",&testargv);
    if (cnt < 0) { /* Error handling */
    } else {
        /* Process */
        int i = 0;
        while(i < cnt) {
            printf("%d: '%s'\n",i,testargv[i]);
            i++;
        }
    }
    /* . . . */
    librock_prsargv_free(&testargv);
#endif

USES

  malloc
  free
  strlen
  strcpy
  librock_countbl();
 


LICENSE

  Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com
  Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block.
  License text in <librock/license/librock.txt> librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45

Source Code

./exec/process/vararg/prsargv.c (implementation, plus source of this manual page)

This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)

Want to help? We welcome comments, patches. -- Need help? Request paid support.