1c041511dScube
2c041511dScube/* Copyright (c) Mark J. Kilgard, 1994. */
3c041511dScube
4c041511dScube/* This program is freely distributable without licensing fees
5c041511dScube   and is provided without guarantee or warrantee expressed or
6c041511dScube   implied. This program is -not- in the public domain. */
7c041511dScube
8c041511dScube#include <stdlib.h>
9c041511dScube#include <stdarg.h>
10c041511dScube#include <string.h>
11c041511dScube#include <stdio.h>
12c041511dScube
13c041511dScube#include "glutint.h"
14c041511dScube
15c041511dScube/* strdup is actually not a standard ANSI C or POSIX routine
16c041511dScube   so implement a private one for GLUT.  OpenVMS does not have a
17c041511dScube   strdup; Linux's standard libc doesn't declare strdup by default
18c041511dScube   (unless BSD or SVID interfaces are requested). */
19c041511dScubechar *
20c041511dScube__glutStrdup(const char *string)
21c041511dScube{
22c041511dScube  char *copy;
23c041511dScube
24c041511dScube  copy = (char*) malloc(strlen(string) + 1);
25c041511dScube  if (copy == NULL)
26c041511dScube    return NULL;
27c041511dScube  strcpy(copy, string);
28c041511dScube  return copy;
29c041511dScube}
30c041511dScube
31c041511dScubevoid
32c041511dScube__glutWarning(char *format,...)
33c041511dScube{
34c041511dScube  va_list args;
35c041511dScube
36c041511dScube  va_start(args, format);
37c041511dScube  fprintf(stderr, "GLUT: Warning in %s: ",
38c041511dScube    __glutProgramName ? __glutProgramName : "(unamed)");
39c041511dScube  vfprintf(stderr, format, args);
40c041511dScube  va_end(args);
41c041511dScube  putc('\n', stderr);
42c041511dScube}
43c041511dScube
44c041511dScube/* CENTRY */
45c041511dScubevoid GLUTAPIENTRY
46c041511dScubeglutReportErrors(void)
47c041511dScube{
48c041511dScube  GLenum error;
49c041511dScube
50c041511dScube  while ((error = glGetError()) != GL_NO_ERROR)
51c041511dScube    __glutWarning("GL error: %s", gluErrorString(error));
52c041511dScube}
53c041511dScube/* ENDCENTRY */
54c041511dScube
55c041511dScubevoid
56c041511dScube__glutFatalError(char *format,...)
57c041511dScube{
58c041511dScube  va_list args;
59c041511dScube
60c041511dScube  va_start(args, format);
61c041511dScube  fprintf(stderr, "GLUT: Fatal Error in %s: ",
62c041511dScube    __glutProgramName ? __glutProgramName : "(unamed)");
63c041511dScube  vfprintf(stderr, format, args);
64c041511dScube  va_end(args);
65c041511dScube  putc('\n', stderr);
66c041511dScube#ifdef _WIN32
67c041511dScube  if (__glutExitFunc) {
68c041511dScube    __glutExitFunc(1);
69c041511dScube  }
70c041511dScube#endif
71c041511dScube  exit(1);
72c041511dScube}
73c041511dScube
74c041511dScubevoid
75c041511dScube__glutFatalUsage(char *format,...)
76c041511dScube{
77c041511dScube  va_list args;
78c041511dScube
79c041511dScube  va_start(args, format);
80c041511dScube  fprintf(stderr, "GLUT: Fatal API Usage in %s: ",
81c041511dScube    __glutProgramName ? __glutProgramName : "(unamed)");
82c041511dScube  vfprintf(stderr, format, args);
83c041511dScube  va_end(args);
84c041511dScube  putc('\n', stderr);
85c041511dScube  abort();
86c041511dScube}
87