Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members  

util.c

Go to the documentation of this file.
00001 /*  $Id: util.c,v 1.5 2000/12/06 18:42:30 dbryson Exp $
00002 **
00003 **  Copyright (c) 2000 Derry Bryson <derry@techass.com>
00004 **
00005 **  Description:
00006 **  
00007 **    Postscript Library
00008 **
00009 **
00010 **  License:
00011 **
00012 **    This library is free software; you can redistribute it and/or
00013 **    modify it under the terms of the GNU Lesser General Public
00014 **    License as published by the Free Software Foundation; either
00015 **    version 2.1 of the License, or (at your option) any later version.
00016 **
00017 **    This library is distributed in the hope that it will be useful,
00018 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 **    Lesser General Public License for more details.
00021 **
00022 **    You should have received a copy of the GNU Lesser General Public
00023 **    License along with this library; if not, write to the Free Software
00024 **    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 **
00026 **
00027 **  Contact:
00028 **
00029 **      Mail:
00030 **
00031 **        Technology Associates, Inc.
00032 **        LIBPS Project
00033 **        1455 Deming Way #11
00034 **        Sparks, NV  89431
00035 **        USA
00036 **
00037 **      Email:
00038 **
00039 **        libps@techass.com
00040 **
00041 **      See our website at:
00042 **
00043 **        libps.sourceforge.net
00044 **
00045 */
00046 
00050 #ifdef HAVE_CONFIG_H
00051 # include "psconfig.h"
00052 #endif
00053 
00054 #include <stdio.h>
00055 #include <stdlib.h>
00056 #include <string.h>
00057 #include <ctype.h>
00058 
00072 char*
00073 psStrncpy(char* dest, char* src, size_t n)
00074 {
00075   int
00076     i;
00077     
00078   for(i = 0; i < n && *src; i++, src++, dest++)
00079     *dest = *src;
00080   *dest = 0;
00081   
00082   return dest;
00083 }
00084 
00097 char*
00098 psStrndup(char* s, size_t n)
00099 {
00100   char
00101     *p;
00102     
00103   p = calloc(1, n + 1);
00104   if(p)
00105     psStrncpy(p, s, n);
00106   
00107   return p;
00108 }
00109 
00125 char *
00126 psUStrncpy(char *dst, char *str, size_t n)
00127 {
00128   int 
00129     i;
00130     
00131   char
00132     *p;
00133 
00134   for(i = 0, p = dst; i < n; i += 2)
00135     if(!str[i])
00136       *p++ = str[i + 1];
00137   *p = 0;
00138   
00139   return dst;
00140 }
00141 
00157 char* 
00158 psUStrndup(char* s, size_t n)
00159 {
00160   char
00161     *p;
00162     
00163   p = malloc(n / 2 + 1);
00164   if(p)
00165     psUStrncpy(p, s, n);
00166     
00167   return p;
00168 }
00169 
00180 char* 
00181 psEraseWhiteBegin(char* str)
00182 {
00183   char
00184     *p,
00185     *q;
00186     
00187   for(p = str; *p && isspace(*p); p++)
00188     ;
00189   for(q = str; *p; p++, q++)
00190     *q = *p;
00191   *q = 0;
00192   
00193   return str;
00194 }
00195 
00206 char* 
00207 psEraseWhiteEnd(char* str)
00208 {
00209   char
00210     *p;
00211     
00212   for(p = str + strlen(str) - 1; p >= str && isspace(*p); p--)
00213     *p = 0;
00214     
00215   return str;
00216 }
00217 
00228 char* 
00229 psEraseWhite(char* str)
00230 {
00231   psEraseWhiteBegin(str);
00232   return psEraseWhiteEnd(str);
00233 }

Generated at Mon Dec 11 22:46:28 2000 for Postscript Utility Library by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000