inspircd/win/configure.cpp

1 line
20 KiB
C++
Raw Normal View History

/* +------------------------------------+ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * * InspIRCd: (C) 2002-2007 InspIRCd Development Team * See: http://www.inspircd.org/wiki/index.php/Credits * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ #define _CRT_SECURE_NO_DEPRECATE #include <windows.h> #include <stdio.h> #include <string> #include <time.h> #include "colours.h" using namespace std; void Run(); void Banner(); void WriteCompileModules(); void WriteCompileCommands(); /* detects if we are running windows xp or higher (5.1) */ bool iswinxp() { OSVERSIONINFO vi; vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&vi); if(vi.dwMajorVersion >= 5) return true; return false; } int get_int_option(const char * text, int def) { static char buffer[500]; int ret; printf_c("%s\n[\033[1;32m%u\033[0m] -> ", text, def); fgets(buffer, 500, stdin); if(sscanf(buffer, "%u", &ret) != 1) ret = def; printf("\n"); return ret; } bool get_bool_option(const char * text, bool def) { static char buffer[500]; char ret[100]; printf_c("%s [\033[1;32m%c\033[0m] -> ", text, def ? 'y' : 'n'); fgets(buffer, 500, stdin); if(sscanf(buffer, "%s", ret) != 1) strcpy(ret, def ? "y" : "n"); printf("\n"); return !strncmp(ret, "y", 1); } void get_string_option(const char * text, char * def, char * buf) { static char buffer[500]; printf_c("%s\n[\033[1;32m%s\033[0m] -> ", text, def); fgets(buffer, 500, stdin); if(sscanf(buffer, "%s", buf) != 1) strcpy(buf, def); printf("\n"); } // escapes a string for use in a c++ file bool escape_string(char * str, size_t size) { size_t len = strlen(str); char * d_str = (char*)malloc(len * 2); size_t i = 0; size_t j = 0; for(; i < len; ++i) { if(str[i] == '\\') { d_str[j++] = '\\'; d_str[j++] = '\\'; } else { d_str[j++] = str[i]; } } d_str[j++] = 0; if(j > size) { free(d_str); return false; } strcpy(str, d_str); free(d_str); return true; } /* gets the svn revision */ int get_svn_revision(char * buffer, size_t len) { /* again.. I am lazy :p cbf to pipe output of svn info to us, so i'll just read the file */ /* 8 dir 7033 */ char buf[1000]; FILE * f = fopen("..\\.svn\\entries", "r"); if(!f) goto bad_rev; if(!fgets(buf, 1000, f)) goto bad_rev; if(!fgets(buf, 1000, f)) goto bad_rev; if(!fgets(buf, 1000, f)) goto bad_rev; if(!fgets(buf, 1000, f)) goto bad_rev; int rev = atoi(buf); if(rev == 0) goto bad_rev; sprintf(buffer, "%u", rev); fclose(f); return rev; bad_rev: strcpy(buffer, "non-svn"); if(f) fclose(f); return 0; } int __stdcall WinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd ) { FILE * j = fopen("inspircd_config.h", "r"); if (j) { if (MessageBox(0, "inspircd_config.h already exists. Remove it and build from clean?", "Configure program", MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES) { fclose(j); exit(0); } } AllocConsole(); // pipe standard handles to this console freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); Banner(); Run(); WriteCompileCommands(); WriteCompileModules(); FreeConsole(); return 0; } void Banner() { printf_c("\nWelcome to the \033[1mInspIRCd\033[0m Configuration program! (\033[1minteractive mode\033[0m)\n" "\033[1mPackage maintainers: Type ./configure --help for non-interactive help\033[0m\n\n"); printf_c("*** If you are unsure of any of these values, leave it blank for ***\n" "*** standard settings that will work, and your server will run ***\n" "*** using them. Please consult your IRC network admin if in doubt. ***\n\n" "Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter\n" "a new value. Please note: You will \033[1mHAVE\033[0m to read the docs\n" "dir, otherwise you won't have a config file!\n\n"); } void Ru