gattrib
|
00001 /* gEDA - GPL Electronic Design Automation 00002 * gattrib -- gEDA component and net attribute manipulation using spreadsheet. 00003 * Copyright (C) 2003-2010 Stuart D. Brorson. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00024 #include <config.h> 00025 00026 #include <stdio.h> 00027 #include <math.h> 00028 #ifdef HAVE_STRING_H 00029 #include <string.h> 00030 #endif 00031 00032 /*------------------------------------------------------------------ 00033 * Gattrib specific includes 00034 *------------------------------------------------------------------*/ 00035 #include <libgeda/libgeda.h> /* geda library fcns */ 00036 #include "../include/struct.h" /* typdef and struct declarations */ 00037 #include "../include/prototype.h" /* function prototypes */ 00038 #include "../include/globals.h" 00039 00040 #ifdef HAVE_LIBDMALLOC 00041 #include <dmalloc.h> 00042 #endif 00043 00044 00045 /*------------------------------------------------------------------ 00046 * The below fcns identical to those defined in 00047 * geda-gnetlist/src/s_misc.c 00048 *------------------------------------------------------------------*/ 00052 static int char_index = 0; 00053 00061 void verbose_print(char *string) 00062 { 00063 if (verbose_mode) { 00064 printf("%s", string); 00065 char_index++; 00066 if ((char_index + 1) >= 78) { 00067 printf("\n"); 00068 char_index = 0; 00069 } 00070 } 00071 } 00072 00080 void verbose_done(void) 00081 { 00082 if (verbose_mode) { 00083 if (char_index >= 70) { 00084 printf("\nDONE\n"); 00085 } else { 00086 printf(" DONE\n"); 00087 } 00088 00089 char_index = 0; 00090 } 00091 } 00092 00100 void verbose_reset_index(void) 00101 { 00102 char_index = 0; 00103 } 00104 00105 00106 /*------------------------------------------------------------------ 00107 * Gattrib specific utilities 00108 *------------------------------------------------------------------*/ 00109 char *s_misc_remaining_string(gchar *string, gchar delimiter, gint count) 00110 { 00111 gint i; 00112 gchar *remaining; 00113 gchar *return_value; 00114 00115 /* find count'th delimiter */ 00116 remaining = string; 00117 for (i = 0; i < count; i++) { 00118 remaining = strchr(remaining, delimiter); 00119 if (!remaining) { 00120 return (NULL); 00121 } 00122 remaining++; 00123 } 00124 00125 /* skip whitespace */ 00126 while (*remaining == ' ') { 00127 remaining++; 00128 } 00129 if (!(*remaining)) { 00130 return (NULL); 00131 } 00132 00133 /* copy remainder into allocated return string */ 00134 return_value = g_strdup(remaining); 00135 00136 /* return string */ 00137 return (return_value); 00138 }