Fix a problem that caused the new interface code to not actually be
[mesa.git] / src / glut / beos / glutDstr.cpp
1 /***********************************************************
2 * Copyright (C) 1997, Be Inc. All rights reserved.
3 *
4 * FILE: glutDstr.cpp
5 *
6 * DESCRIPTION: convert display string into a Be options variable
7 ***********************************************************/
8
9 /***********************************************************
10 * Headers
11 ***********************************************************/
12 #include <GL/glut.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include "glutint.h"
16 #include "glutState.h"
17
18 /***********************************************************
19 * FUNCTION: glutInitDisplayString
20 *
21 * DESCRIPTION: sets the display string variable
22 ***********************************************************/
23 void APIENTRY
24 glutInitDisplayString(const char *string)
25 {
26 if (gState.displayString) {
27 free(gState.displayString);
28 }
29 if (string) {
30 gState.displayString = strdup(string);
31 if (!gState.displayString)
32 __glutFatalError("out of memory.");
33 } else
34 gState.displayString = NULL;
35 }
36
37 /***********************************************************
38 * FUNCTION: __glutConvertDisplayModeFromString
39 *
40 * DESCRIPTION: converts the current display mode into a BGLView
41 * display mode, printing warnings as appropriate.
42 *
43 * PARAMETERS: if options is non-NULL, the current display mode is
44 * returned in it.
45 *
46 * RETURNS: 1 if the current display mode is possible, else 0
47 ***********************************************************/
48 int __glutConvertDisplayModeFromString(unsigned long *options) {
49 ulong newoptions = BGL_DOUBLE;
50 gState.swapHack = true; // assume single buffered
51
52 char *word = strtok(gState.displayString, " \t");
53 do {
54 char *cstr = strpbrk(word, "=><!~");
55 if(cstr)
56 *cstr = '\0';
57 // this is the most minimal possible parser. scan for
58 // options that we support, and add them to newoptions
59 // this will certainly cause it to accept things that we
60 // don't actually support, but if we don't support it, the
61 // program's probably not going to work anyway.
62 if(!strcmp(word, "alpha")) {
63 newoptions |= BGL_ALPHA;
64 } else if((!strcmp(word, "acc")) || (!strcmp(word, "acca"))) {
65 newoptions |= BGL_ACCUM;
66 } else if(!strcmp(word, "depth")) {
67 newoptions |= BGL_DEPTH;
68 } else if(!strcmp(word, "double")) {
69 gState.swapHack = false;
70 } else if(!strcmp(word, "stencil")) {
71 newoptions |= BGL_STENCIL;
72 }
73 } while((word = strtok(0, " \t")) != 0);
74
75 if (options)
76 *options = newoptions;
77
78 return 1; // assume we support it
79 }