Added some of the doc support files to EXTRA_DIST
[geda-gaf/whiteaudio.git] / libgeda / src / u_basic.c
blobe2ca03273ce716fb31e3b4556e6d738aa814d93e
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998, 1999, 2000 Kazu Hirata / Ales Hvezda
4 * Copyright (C) 1998-2008 Ales Hvezda
5 * Copyright (C) 1998-2008 gEDA Contributors (see ChangeLog for details)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
21 #include <config.h>
23 #include <stdio.h>
24 #ifdef HAVE_STRING_H
25 #include <string.h>
26 #endif
27 #ifdef HAVE_STDLIB_H
28 #include <stdlib.h>
29 #endif
31 #include "libgeda_priv.h"
33 #ifdef HAVE_LIBDMALLOC
34 #include <dmalloc.h>
35 #endif
37 /*! \todo Finish function documentation!!!
38 * \brief
39 * \par Function Description
42 /* the delimiter is what is passed in or spaces */
43 /* count starts at zero */
44 char *u_basic_breakup_string(char *string, char delimiter, int count)
46 int i=0, j=0;
47 int internal_counter=0;
48 int done=FALSE;
49 char *return_value;
51 g_return_val_if_fail ((string != NULL),
52 NULL);
54 /* skip over any leading white space */
55 while(string[i] == ' ' && !string[i]) {
56 i++;
59 /* Allocate space for temp string storage (+1 for null character) */
60 return_value = g_malloc(sizeof(char)*(strlen(string) + 1));
62 while(!done) {
64 /* oops, ran out of string before we found what we were */
65 /* looking for */
66 if (i > strlen(string)) {
67 g_free(return_value);
68 return(NULL);
71 /* skip over any leading white space */
72 while(string[i] == ' ' && string[i] != '\0') {
73 i++;
76 j = 0;
78 /* Old forgiving parsing */
79 /* while(string[i] != ',' && string[i] != ';' && */
80 /* string[i] != ' ' && string[i] != '\0') {*/
82 while(string[i] != delimiter && string[i] != '\0') {
83 return_value[j] = string[i];
84 i++; j++;
87 if (internal_counter == count) {
88 done = TRUE;
89 } else {
90 internal_counter++;
91 i++; /* skip the offending character */
95 return_value[j] = '\0';
96 return(return_value);