/* * Linux Desktop Testing Project http://www.gnomebangalore.org/ldtp * * Author: * Nagappan A * * Copyright 2004 Novell, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include "appmap-gen.h" #include "utils.h" char *strip_white_space (char *data) { int i; int j = 0; char *stripped_data = NULL; stripped_data = (char *) malloc (sizeof (char) * strlen (data) + 1); for (i = 0; i < strlen (data); i++) { if (data[i] != ' ') stripped_data[j++] = data[i]; } stripped_data[j] = '\0'; return stripped_data; } char *strip_delim (char *data, char delim) { int i; int j = 0; char *stripped_data = NULL; stripped_data = (char *) malloc (sizeof (char) * strlen (data) + 1); for (i = 0; i < strlen (data); i++) { if (data[i] == delim) { break; } stripped_data[j++] = data[i]; } stripped_data[j] = '\0'; return stripped_data; } char *read_line (int fd ) { int len = 128; int size = 0; char ch; char *data = NULL; while (read (fd, &ch, 1) > 0) { if (!data) { data = (char *) malloc (sizeof (char)*len); } if (size%len == 0) { data = (char *) realloc (data, sizeof (char)*len+size+1); } data[size++] = ch; if (ch == '\n') { if (size%len == 0) { data = (char *) realloc (data, sizeof (char)+size+1); } data[size] = '\0'; return data; } } return NULL; } gchar *remove_char (const gchar *text, gchar delimiter) { gint length; GString *str; const gchar *p; const gchar *end; g_return_val_if_fail (text != NULL, NULL); length = strlen (text); str = g_string_sized_new (length); p = text; end = text + length; while (p != end) { const gchar *next; next = g_utf8_next_char (p); if (*p != delimiter) g_string_append_len (str, p, next - p); p = next; } return g_string_free (str, FALSE); } gchar *search_forward (const gchar *text, gchar delimiter) { gint length; GString *str; const gchar *p; const gchar *end; g_return_val_if_fail (text != NULL, NULL); length = strlen (text); str = g_string_sized_new (length); p = text; end = text + length; while (p != end) { const gchar *next; next = g_utf8_next_char (p); if (*p == delimiter) break; else g_string_append_len (str, p, next - p); p = next; } return g_string_free (str, FALSE); } gchar *search_reverse (const gchar *text, gchar delimiter) { gint length; GString *str; const gchar *p; const gchar *end; gboolean flag = FALSE; g_return_val_if_fail (text != NULL, NULL); length = strlen (text); str = g_string_sized_new (length); p = text; end = text + length; while (p != end) { const gchar *next; next = g_utf8_next_char (p); if (!flag && *p != delimiter) { p = next; continue; } else if (!flag) { flag = TRUE; p = next; continue; } g_string_append_len (str, p, next - p); p = next; } return g_string_free (str, FALSE); }