From b5b320c4c2ee00e9ee3d348b996acade4c9068e2 Mon Sep 17 00:00:00 2001 From: Petr Kubiznak Date: Sun, 3 Apr 2011 22:17:19 +0200 Subject: [PATCH] opengl & sql: Multiplatform fixes (missing/invalid includes, conditional includes). sql_connector: String constants cannot be assigned to (char *)! runGlutMainLoop: Missing glutInit() fixed. --- opengl/runGlutMainLoop.cpp | 22 +++++++++++++++++----- sqlconn/sql_connector.cpp | 45 ++++++++++++++------------------------------- sqlconn/sql_connector.h | 19 ++++++++++++------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/opengl/runGlutMainLoop.cpp b/opengl/runGlutMainLoop.cpp index 46454a6..02810e2 100644 --- a/opengl/runGlutMainLoop.cpp +++ b/opengl/runGlutMainLoop.cpp @@ -1,17 +1,24 @@ -#include +#if defined(_WIN32) || defined(__WIN32__) +# include +#endif #include #include -#include +#include -#include +#include #include "trackball.h" #include "readtex.h" #include "runGlutMainLoop.h" #include "../core/board.h" #include "../threads/thread_controller.h" +#ifndef byte +# define byte unsigned char +#endif + + #define glut_WINDOW_SIZE 500 #define glut_WINDOW_POS_X 500 #define glut_WINDOW_POS_Y 200 @@ -102,10 +109,15 @@ void forceRedraw(void) void * runGlutMainLoop( void * args ) { - + char *argval = new char [1]; + char **argv = new char* [1]; + argv[0] = argval; + argval[0] = '\0'; + int argc = 1; + thc = (Thread_controller *)args; - + glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(glut_WINDOW_SIZE,glut_WINDOW_SIZE); glutInitWindowPosition(glut_WINDOW_POS_X,glut_WINDOW_POS_Y); diff --git a/sqlconn/sql_connector.cpp b/sqlconn/sql_connector.cpp index 018765d..19b1cea 100644 --- a/sqlconn/sql_connector.cpp +++ b/sqlconn/sql_connector.cpp @@ -1,5 +1,9 @@ #include "sql_connector.h" #include +#include +#include + +#define TABLEDATA_BUFSIZE 255 Sql_connector::Sql_connector(void) { @@ -13,25 +17,25 @@ Sql_connector::Sql_connector(void) c_data->db_port = 3306; c_data->db_cols = 4; - if (c_data->table_data = (char**)malloc((c_data->db_cols+1) * sizeof *(c_data->table_data) )) + if( (c_data->table_data = (char**)malloc((c_data->db_cols+1) * sizeof *(c_data->table_data) )) ) { for (i=0;i<=c_data->db_cols;i++) { - c_data->table_data[i] = (char *)malloc( sizeof(char) * 255 ); + c_data->table_data[i] = (char *)malloc( sizeof(char) * TABLEDATA_BUFSIZE+1 ); } - c_data->table_data[0] = "api_miny_score"; - c_data->table_data[1] = "jmeno"; - c_data->table_data[2] = "skore"; - c_data->table_data[3] = "date"; - c_data->table_data[4] = "difficulty"; + snprintf(c_data->table_data[0], TABLEDATA_BUFSIZE, "api_miny_score"); + snprintf(c_data->table_data[1], TABLEDATA_BUFSIZE, "jmeno"); + snprintf(c_data->table_data[2], TABLEDATA_BUFSIZE, "skore"); + snprintf(c_data->table_data[3], TABLEDATA_BUFSIZE, "date"); + snprintf(c_data->table_data[4], TABLEDATA_BUFSIZE, "difficulty"); - printf("malloc ok\n"); + fprintf(stderr, "malloc ok\n"); } else { - printf("malloc failed\n"); + fprintf(stderr, "malloc failed\n"); } @@ -106,7 +110,7 @@ int Sql_connector::insertScore(const char * name, int score,byte difficulty) sprintf(query,"INSERT INTO %s (%s,%s,%s,%s) VALUES ( '%s','%i:%i:%i','%i-%i-%i %i:%i:%i','%i' );", c_data->table_data[0],c_data->table_data[1],c_data->table_data[2],c_data->table_data[3],c_data->table_data[4], name,h,m,s,ptm->tm_year,ptm->tm_mon,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec,difficulty); - if (len = mysql_query(conn,query)); + if( (len = mysql_query(conn,query)) ) { printf("error: %u %s\r\n",mysql_errno(conn),mysql_error(conn)); } @@ -116,24 +120,3 @@ int Sql_connector::insertScore(const char * name, int score,byte difficulty) return len; } - - - - - - - - - - - - - - - - - - - - - diff --git a/sqlconn/sql_connector.h b/sqlconn/sql_connector.h index f17ad36..fb48a1e 100644 --- a/sqlconn/sql_connector.h +++ b/sqlconn/sql_connector.h @@ -1,21 +1,26 @@ #ifndef SQL_CONN_H #define SQL_CONN_H - -#include +#if defined(_WIN32) || defined(__WIN32__) +# include +#endif #include #include #include -#define CONN_CONFIG_FILE "conn_config" +#define CONN_CONFIG_FILE "conn_config" + +#ifndef byte +# define byte unsigned char +#endif struct conn_data { - char * server_name; - char * user_name; - char * db_name; - char * db_passwd; + const char * server_name; + const char * user_name; + const char * db_name; + const char * db_passwd; int db_port; int db_cols; char ** table_data; // name col1 col2 col3 ... -- 2.11.4.GIT