1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
@c -*- mode: Noweb; noweb-doc-mode: texinfo-mode; noweb-code-mode: c-mode -*-
@node File u_basic.c,,,Top
@chapter File @file{u_basic.c}
@section File header
<<u_basic.c : *>>=
<<u_basic.c : copyright and license>>
/* DO NOT read or edit this file ! Use ../noweb/u_basic.nw instead */
<<u_basic.c : include directives>>
<<u_basic.c : u_basic_breakup_string()>>
<<u_basic.c : u_basic_strip_trailing()>>
<<u_basic.c : u_basic_has_trailing()>>
<<u_basic.c : u_basic_count_char()>>
@
<<u_basic.c : copyright and license>>=
/* gEDA - GPL Electronic Design Automation
* libgeda - gEDA's library
* Copyright (C) 1998, 1999, 2000 Kazu Hirata / Ales Hvezda
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
*/
@
<<u_basic.c : include directives>>=
#include <config.h>
#include <stdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <gtk/gtk.h>
#include <libguile.h>
#include "defines.h"
#include "struct.h"
#include "globals.h"
#include "../include/prototype.h"
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
@
/* ------------------------------------------------------------ */
@section Function @code{u_basic_breakup_string()}
@defun u_basic_breakup_string string count
@end defun
<<u_basic.c : u_basic_breakup_string()>>=
/* the delimiter is what is passed in or spaces */
/* count starts at zero */
char *
u_basic_breakup_string(char *string, char delimiter, int count)
{
int i=0, j=0;
int internal_counter=0;
int done=FALSE;
char *return_value;
/* skip over any leading white space */
while(string[i] == ' ' && !string[i]) {
i++;
}
/* Allocate space for temp string storage (+1 for null character) */
return_value = malloc(sizeof(char)*(strlen(string) + 1));
while(!done) {
/* oops, ran out of string before we found what we were */
/* looking for */
if (i > strlen(string)) {
free(return_value);
return(NULL);
}
/* skip over any leading white space */
while(string[i] == ' ' && string[i] != '\0') {
i++;
}
j = 0;
/* Old forgiving parsing */
/* while(string[i] != ',' && string[i] != ';' && */
/* string[i] != ' ' && string[i] != '\0') {*/
while(string[i] != delimiter && string[i] != '\0') {
return_value[j] = string[i];
i++; j++;
}
if (internal_counter == count) {
done = TRUE;
} else {
internal_counter++;
i++; /* skip the offending character */
}
}
return_value[j] = '\0';
return(return_value);
}
@ %def u_basic_breakup_string
/* ------------------------------------------------------------ */
@section Function @code{u_basic_strip_trailing()}
@defun u_basic_strip_trailing string character
@end defun
<<u_basic.c : u_basic_strip_trailing()>>=
void
u_basic_strip_trailing(char *string, char c)
{
if (string) {
int len = strlen(string) - 1; /* point to last char */
if (string[len] == c) {
string[len] = '\0';
}
}
}
@ %def u_basic_strip_trailing
/* ------------------------------------------------------------ */
@section Function @code{u_basic_has_trailing()}
@defun u_has_strip_trailing string character
@end defun
<<u_basic.c : u_basic_has_trailing()>>=
int
u_basic_has_trailing(char *string, char c)
{
if (string) {
int len = strlen(string) - 1; /* point to last char */
if (string[len] == c) {
return TRUE;
}
}
return FALSE;
}
@ %def u_basic_has_trailing
/* ------------------------------------------------------------ */
@section Function @code{u_basic_count_char()}
@defun u_basic_count_char string character
@end defun
<<u_basic.c : u_basic_count_char()>>=
/*
* This fcn counts the number of occurances of the character
* "character" in the string "string".
* 1.23.2005 -- SDB
*/
int u_basic_count_char(const char *string, char character)
{
int count = 0;
int i=0;
#ifdef DEBUG
printf("In u_basic_count_char, looking for char \"%c\" in string \"%s\".\n",
character, string);
#endif
while (string[i] != '\0') {
if (string[i] == character) {
count++;
}
i++;
}
#ifdef DEBUG
printf(". . . . . Found it %d times.\n",
count);
#endif
return count;
}
@ %def u_basic_count_char
|