home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / games / spl / src / general.cpp next >
C/C++ Source or Header  |  1993-08-10  |  2KB  |  90 lines

  1. /* general.c: some useful(?) functions
  2.  
  3.     Copyright (C) 1993 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 <ctype.h>
  28. #include <stdarg.h>
  29. #include "general.hpp"
  30.  
  31. void fatal(char *fmt, ...) {
  32.     va_list ap;
  33.  
  34.     va_start(ap,fmt);
  35.     fprintf(stderr,"\nFatal Error: ");
  36.     vfprintf(stderr,fmt,ap);
  37.     fprintf(stderr,"\n");
  38.     va_end(ap);
  39.     exit(1);
  40. }
  41.  
  42. void error(char *fmt, ...) {
  43.     va_list ap;
  44.  
  45.     va_start(ap,fmt);
  46.     fprintf(stderr,"\nError: ");
  47.     vfprintf(stderr,fmt,ap);
  48.     fprintf(stderr,"\n");
  49.     va_end(ap);
  50. }
  51.  
  52. void warning(char *fmt, ...) {
  53.     va_list ap;
  54.  
  55.     va_start(ap,fmt);
  56.     fprintf(stderr,"\nWarning: ");
  57.     vfprintf(stderr,fmt,ap);
  58.     fprintf(stderr,"\n");
  59.     va_end(ap);
  60. }
  61.  
  62. void *chkcalloc(size_t nitems, size_t size) {
  63.     void *ret;
  64.  
  65.     if( (ret = calloc(nitems,size)) == NULL)
  66.         fatal("Ran out of memory");
  67.     return (ret);
  68. }
  69.  
  70. char *upstr(char *str) {
  71.     register char *s = str;
  72.  
  73.     if (str)
  74.         while( *s = toupper(*s) )
  75.             s++;
  76.  
  77.     return str;
  78. }
  79.  
  80. char *lowstr(char *str) {
  81.     register char *s = str;
  82.  
  83.     if (str)
  84.         while( *s = tolower(*s) )
  85.             s++;
  86.         
  87.     return str;
  88. }
  89.  
  90.