Google
Web alhem.net
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Globals.cpp

Go to the documentation of this file.
00001 00006 /* 00007 Copyright (C) 2004 Anders Hedstrom 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 00012 of the License, or (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 #include <stdincl.h> 00024 //#include <libcgi++.h> 00025 00026 #include "defaults.h" 00027 #include "util/Parse.h" 00028 #include "Globals.h" 00029 00030 using util::Parse; 00031 00032 00033 string Globals::m_host = "alhem.net"; 00034 int Globals::m_port = DEFAULT_PORT; 00035 double Globals::m_zx = -0.852693; 00036 double Globals::m_zy = 0.353394; 00037 double Globals::m_scale = 0.000596; 00038 00039 00040 Globals::Globals() 00041 { 00042 read_globals(); 00043 } 00044 00045 00046 Globals::~Globals() 00047 { 00048 write_globals(); 00049 } 00050 00051 00052 void Globals::read_globals() 00053 { 00054 FILE *fil; 00055 char slask[200]; 00056 char value[200]; 00057 00058 if ((fil = fopen("globals.dat","rt")) != NULL) 00059 { 00060 fgets(slask,200,fil); 00061 while (!feof(fil)) 00062 { 00063 slask[strlen(slask) - 1] = 0; 00064 Parse pa(slask); 00065 pa.getword(slask); 00066 pa.getrest(value); 00067 if (!strcmp(slask,"host")) 00068 { 00069 m_host = value; 00070 } 00071 else 00072 if (!strcmp(slask,"port")) 00073 { 00074 m_port = atoi(value); 00075 } 00076 else 00077 if (!strcmp(slask,"zx")) 00078 { 00079 m_zx = atof(value); 00080 } 00081 else 00082 if (!strcmp(slask,"zy")) 00083 { 00084 m_zy = atof(value); 00085 } 00086 else 00087 if (!strcmp(slask,"scale")) 00088 { 00089 m_scale = atof(value); 00090 } 00091 else 00092 { 00093 fprintf(stderr,"Unknown key '%s'\n", slask); 00094 } 00095 fgets(slask,200,fil); 00096 } 00097 fclose(fil); 00098 } 00099 } 00100 00101 00102 void Globals::write_globals() 00103 { 00104 FILE *fil; 00105 00106 if ((fil = fopen("globals.dat","wt")) != NULL) 00107 { 00108 fprintf(fil,"host %s\n",m_host.c_str()); 00109 fprintf(fil,"port %d\n",m_port); 00110 fprintf(fil,"zx %f\n",m_zx); 00111 fprintf(fil,"zy %f\n",m_zy); 00112 fprintf(fil,"scale %f\n",m_scale); 00113 fclose(fil); 00114 } 00115 } 00116

Generated for SDL C++ GUI by doxygen 1.3.6