Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

utils.c

Go to the documentation of this file.
00001 
00005 /* GtkSQL -- an interactive graphical query tool for PostgreSQL
00006  * Copyright (C) 2003 Darryl Luff
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #include <ctype.h>
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <string.h>
00027 
00031 void add_space(FILE * f, const int exists, const int todo)
00032 {
00033     int i;
00034 
00035     for (i = exists; i < todo; i++)
00036         fputc(' ', f);
00037 }
00038 
00039 static char *ttBuf = NULL;
00040 static int ttBuflen = 0;
00046 char *trimtext(const char *s) {
00047     char *dp;
00048     const char *sp;
00049 
00050     if (! s)
00051         return "";
00052 
00053     if (ttBuflen < (strlen(s) + 1)) {
00054         if (ttBuf)
00055             free(ttBuf);
00056 
00057         ttBuflen = strlen(s)+1;
00058         ttBuf = malloc(ttBuflen);
00059     }
00060     sp = s;
00061     dp = ttBuf;
00062 
00063     /* skip leading spaces  */
00064     while ((*sp) && (isspace(*sp)))
00065         sp++;
00066 
00067     /* now just copy to end of string   */
00068     while (*sp) {
00069         *dp = *sp;
00070         dp++;
00071         sp++;
00072     }
00073 
00074     *dp = '\0';
00075     return ttBuf;
00076 }
00077 
00082 char *get_short_filename(char *fn) {
00083     char *sfn;
00084     char *p;
00085     if (fn == NULL)
00086         return NULL;
00087 
00088     sfn = fn;
00089     p = strchr(sfn, '/');
00090     while (p != NULL) {
00091         sfn = p;
00092         sfn++;
00093         p = strchr(sfn, '/');
00094     }
00095 
00096     /* Now, p should be null, meaning that there are no more '/'s, and
00097      * 'sfn' should point to the short name.    */
00098     return sfn;
00099 }

Generated on Sun May 9 19:19:17 2004 for GtkSQL by doxygen1.2.18