/* Copyright (C) 1992-1998 The Geometry Center * Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips * * This file is part of Geomview. * * Geomview is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) * any later version. * * Geomview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with Geomview; see the file COPYING. If not, write * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, * USA, or visit http://www.gnu.org. */ #if defined(HAVE_CONFIG_H) && !defined(CONFIG_H_INCLUDED) #include "config.h" #endif static char copyright[] = "Copyright (C) 1992-1998 The Geometry Center\n\ Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips"; /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */ #include #include #include "ooglutil.h" char *_GFILE; /* Name of file where error is found */ int _GLINE; /* Line number in file where error is found */ int OOGL_Errorcode; /* Unique integer error code */ int _OOGLError(int errorcode,char* fmt,...) { va_list args; va_start(args, fmt); if(errorcode & OE_VERBOSE) fprintf(stderr, "Error <%d>: ",errorcode); if (fmt != NULL) vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); if(errorcode & OE_VERBOSE) fprintf(stderr, "File: %s, Line: %d\n\n",_GFILE,_GLINE); OOGL_Errorcode = errorcode; va_end(args); return 0; } /* * Report syntax error */ void OOGLSyntax(FILE *f, char *fmt, ...) { static FILE *oldf; static FILE oldfile; static char oldtext[32]; char *context; va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); context = fcontext(f); if(f == oldf && memcmp(f, &oldfile, sizeof(FILE)) == 0 && strcmp(context, oldtext) == 0) { fprintf(stderr, " [ditto]\n"); } else { fprintf(stderr, context[0] != '\0' ? ":\n%s" : " [no text available]\n", context); oldf = f; oldfile = *f; memcpy(oldtext, context, sizeof(oldtext)); oldtext[sizeof(oldtext)-1] = '\0'; } va_end(args); } void OOGLWarn(char *fmt, ...) { int level = 2; va_list args; if(fmt[0] < ' ' && fmt[0] != '\0') level = *fmt++; /* Maybe we have a current warning level below which we don't print */ va_start (args, fmt); vfprintf (stderr, fmt, args); fputc('\n', stderr); fflush(stderr); va_end (args); } const char * sperrno(unsigned int err) { #if !defined(__FreeBSD__) && !defined(__GLIBC__) extern int sys_nerr; extern char *sys_errlist[]; #endif static char errstr[16]; if(err < sys_nerr) return(sys_errlist[err]); sprintf(errstr, "Error %d", err & 0xffff); return(errstr); } const char * sperror(void) { extern int errno; return sperrno(errno); }