home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / glass / glass.lha / GLASS / libtmc / newstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-06  |  1.9 KB  |  74 lines

  1. /* 
  2.    Copyright (C) 1990 C van Reewijk, email: dutentb.uucp!reeuwijk
  3.  
  4. This file is part of GLASS.
  5.  
  6. GLASS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GLASS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GLASS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* file: newstr.c
  21.    String manipulation routines.
  22.  */
  23.  
  24. /* other standard UNIX functions */
  25. #include <stdio.h>
  26. #include <ctype.h>
  27. #include "config.h"
  28. #include "tmc.h"
  29.  
  30. #define PRSTAT(f,nm,new,fre) fprintf(f,"%-15s: %6ld allocated, %6ld freed.%s\n", nm, new, fre, ((new==fre)? "": "<-") );
  31.  
  32. static long newcnt_string = 0;
  33. static long frecnt_string = 0;
  34.  
  35. /* Allocate space for string 's' and copy the text into it. */
  36. string new_string( s )
  37.  char *s;
  38. {
  39.     register unsigned int len;
  40.     register char *adr;
  41.  
  42.     if( s == NULL ){
  43.     return NULL;
  44.     }
  45.     len = ((unsigned) strlen( s )) + 1;
  46.     adr = malloc( len );
  47.     if( adr == NULL ){
  48.     tmfatal( __FILE__, __LINE__, "no room" );
  49.     }
  50.     (void) strcpy( adr, s );
  51.     newcnt_string++;
  52.     return( adr );
  53. }
  54.  
  55. /* de-allocate space for string 's'. */
  56. void fre_string( s )
  57.  char *s;
  58. {
  59.     if( s==NULL ) return;
  60.     frecnt_string++;
  61.     TMFREE( s );
  62. }
  63.  
  64. /***********************************************************
  65.  *   initalizing and statistics                            *
  66.  ***********************************************************/
  67.  
  68. /* Give statistics */
  69. void stat_string( f )
  70.  FILE *f;
  71. {
  72.     PRSTAT( f, "string", newcnt_string, frecnt_string );
  73. }
  74.