Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / gattrib / src / s_misc.c
blob012bf65d2a4c6bce9157bda63685a4971d283c71
1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003-2010 Stuart D. Brorson.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 /*! \file
21 * \brief Miscellaneous STRING_LIST functions
24 #include <config.h>
26 #include <stdio.h>
27 #include <math.h>
28 #ifdef HAVE_STRING_H
29 #include <string.h>
30 #endif
32 /*------------------------------------------------------------------
33 * Gattrib specific includes
34 *------------------------------------------------------------------*/
35 #include <libgeda/libgeda.h> /* geda library fcns */
36 #include "../include/struct.h" /* typdef and struct declarations */
37 #include "../include/prototype.h" /* function prototypes */
38 #include "../include/globals.h"
40 #ifdef HAVE_LIBDMALLOC
41 #include <dmalloc.h>
42 #endif
45 /*------------------------------------------------------------------
46 * The below fcns identical to those defined in
47 * geda-gnetlist/src/s_misc.c
48 *------------------------------------------------------------------*/
49 /*!
50 * Running count of number of characters printed on current line.
52 static int char_index = 0;
54 /*! \brief Print message in verbose mode
56 * Print the supplied message in verbose mode. Line wrap if necessary.
58 * Identical to that defined in gnetlist/src/s_misc.c
59 * \param string String to be printed
61 void verbose_print(char *string)
63 if (verbose_mode) {
64 printf("%s", string);
65 char_index++;
66 if ((char_index + 1) >= 78) {
67 printf("\n");
68 char_index = 0;
73 /*! \brief Print "DONE" message in verbose mode
75 * Prints the "DONE" message in verbose mode, wrapping before printing
76 * if near the end of line.
78 * Identical to function defined in gnetlist/src/s_misc.c
80 void verbose_done(void)
82 if (verbose_mode) {
83 if (char_index >= 70) {
84 printf("\nDONE\n");
85 } else {
86 printf(" DONE\n");
89 char_index = 0;
93 /*! \brief Reset the running character count
95 * Reset the current characted count.
97 * Identical to function defined in gnetlist/src/s_misc.c
100 void verbose_reset_index(void)
102 char_index = 0;
106 /*------------------------------------------------------------------
107 * Gattrib specific utilities
108 *------------------------------------------------------------------*/
109 char *s_misc_remaining_string(gchar *string, gchar delimiter, gint count)
111 gint i;
112 gchar *remaining;
113 gchar *return_value;
115 /* find count'th delimiter */
116 remaining = string;
117 for (i = 0; i < count; i++) {
118 remaining = strchr(remaining, delimiter);
119 if (!remaining) {
120 return (NULL);
122 remaining++;
125 /* skip whitespace */
126 while (*remaining == ' ') {
127 remaining++;
129 if (!(*remaining)) {
130 return (NULL);
133 /* copy remainder into allocated return string */
134 return_value = g_strdup(remaining);
136 /* return string */
137 return (return_value);