libgeda

u_basic.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * libgeda - gEDA's library
00003  * Copyright (C) 1998, 1999, 2000 Kazu Hirata / Ales Hvezda
00004  * Copyright (C) 1998-2010 Ales Hvezda
00005  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 #include <config.h>
00022 
00023 #include <stdio.h>
00024 #ifdef HAVE_STRING_H
00025 #include <string.h>
00026 #endif
00027 #ifdef HAVE_STDLIB_H
00028 #include <stdlib.h>
00029 #endif
00030 
00031 #include "libgeda_priv.h"
00032 
00033 #ifdef HAVE_LIBDMALLOC
00034 #include <dmalloc.h>
00035 #endif
00036 
00042 /* the delimiter is what is passed in or spaces */
00043 /* count starts at zero */
00044 char *u_basic_breakup_string(char *string, char delimiter, int count)
00045 {
00046   int i=0, j=0;
00047   int internal_counter=0;
00048   int done=FALSE;
00049   char *return_value;
00050 
00051   g_return_val_if_fail ((string != NULL),
00052                         NULL);
00053 
00054   /* skip over any leading white space */
00055   while(string[i] == ' ' && !string[i]) {
00056     i++;
00057   }
00058 
00059   /* Allocate space for temp string storage (+1 for null character) */ 
00060   return_value = g_malloc(sizeof(char)*(strlen(string) + 1));
00061 
00062   while(!done) {
00063 
00064     /* oops, ran out of string before we found what we were */
00065     /* looking for */
00066     if (i > strlen(string)) {
00067       g_free(return_value);
00068       return(NULL);
00069     }
00070 
00071     /* skip over any leading white space */
00072     while(string[i] == ' ' && string[i] != '\0') {
00073       i++;
00074     }
00075 
00076     j = 0;
00077 
00078     /* Old forgiving parsing */
00079     /*      while(string[i] != ',' && string[i] != ';' && */
00080     /*            string[i] != ' ' && string[i] != '\0') {*/
00081 
00082     while(string[i] != delimiter && string[i] != '\0') {
00083       return_value[j] = string[i];
00084       i++; j++;
00085     }
00086 
00087     if (internal_counter == count)  { 
00088       done = TRUE;  
00089     } else {
00090       internal_counter++;
00091       i++; /* skip the offending character */
00092     }
00093   }
00094 
00095   return_value[j] = '\0';
00096   return(return_value);
00097 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines