home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games / INFESPGAMES.mdf / os2 / spl / src / general.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  2.1 KB  |  98 lines

  1. /* general.cpp: some useful(?) functions
  2.  
  3.     Copyright (C) 1993, 1994 John-Marc Chandonia
  4.  
  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.
  9.  
  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.
  14.  
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include <stdlib.h>
  21. #ifdef __MSDOS__
  22. #include <alloc.h>
  23. #else
  24. /*#include <malloc.h> */
  25. #endif
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include <stdarg.h>
  30. #include "general.hpp"
  31.  
  32. void fatal(char *fmt, ...) {
  33.     va_list ap;
  34.  
  35.     va_start(ap,fmt);
  36.     fprintf(stderr,"\nFatal Error: ");
  37.     vfprintf(stderr,fmt,ap);
  38.     fprintf(stderr,"\n");
  39.     va_end(ap);
  40.     exit(1);
  41. }
  42.  
  43. void error(char *fmt, ...) {
  44.     va_list ap;
  45.  
  46.     va_start(ap,fmt);
  47.     fprintf(stderr,"\nError: ");
  48.     vfprintf(stderr,fmt,ap);
  49.     fprintf(stderr,"\n");
  50.     va_end(ap);
  51. }
  52.  
  53. void warning(char *fmt, ...) {
  54.     va_list ap;
  55.  
  56.     va_start(ap,fmt);
  57.     fprintf(stderr,"\nWarning: ");
  58.     vfprintf(stderr,fmt,ap);
  59.     fprintf(stderr,"\n");
  60.     va_end(ap);
  61. }
  62.  
  63. void *chkcalloc(size_t nitems, size_t size) {
  64.     void *ret;
  65.  
  66.     if( (ret = calloc(nitems,size)) == NULL)
  67.         fatal("Ran out of memory");
  68.     return (ret);
  69. }
  70.  
  71. char *upstr(char *str) {
  72.     register char *s = str;
  73.  
  74.     if (str)
  75.         while( *s = toupper(*s) )
  76.             s++;
  77.  
  78.     return str;
  79. }
  80.  
  81. char *lowstr(char *str) {
  82.     register char *s = str;
  83.  
  84.     if (str)
  85.         while( *s = tolower(*s) )
  86.             s++;
  87.         
  88.     return str;
  89. }
  90.  
  91. void fgets_no_cr(char *buffer, int n, FILE *infile) {
  92.     char *s;
  93.  
  94.     fgets(buffer,n,infile);
  95.     s=strchr(buffer,(char)10);
  96.     if (s!=NULL) s[0]=(char)0;
  97. }
  98.