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