Пример #1
0
/* Signal handler function. */
void MainSignalHandler (int sig) {
	last_signal = sig;
	
	/* If there is a first_bak!=NULL a filter is set. Reset first_ptr
	   so the correct list gets written on the disk when exisiting via SIGINT. */
	if (first_bak != NULL)
		first_ptr = first_bak;
	MainQuit(NULL, NULL);
}
Пример #2
0
/* Private malloc wrapper. Aborts program execution if malloc fails. */
void * s_malloc (size_t size) {
	void *newmem;
	
	newmem = malloc (size);
	
	if (newmem == NULL) {
		MainQuit ("Allocating memory", strerror(errno));
	}
	
	return newmem;
}
Пример #3
0
int main (int argc, char *argv[]) {
#ifdef SIGWINCH
	struct sigaction act;
#endif

	int autoupdate = 0;		/* Automatically update feeds on app start... or not if set to 0. */
	int numfeeds;			/* Number of feeds loaded from Config(). */
	int i = 0;	
	char *arg;
	char *foo;
	
#ifdef LOCALEPATH
	setlocale (LC_ALL, "");
	bindtextdomain ("snownews", LOCALEPATH);
	textdomain ("snownews");
#endif
	
	if (argc > 1) {
		i = 1;
		while (i < argc) {
			arg = argv[i];
			if (strcmp(arg, "--version") == 0 || strcmp(arg, "-V") == 0) {
				printf (_("Snownews version %s\n\n"), VERSION);
				return 0;
			} else if (strcmp(arg, "-u") == 0 || strcmp(arg, "--update") == 0) {
				autoupdate = 1;
				i++;
				continue;
			} else if (strcmp(arg, "-c") == 0 || strcmp(arg, "--cursor-on") == 0) {
				cursor_always_visible = 1;
				i++;
				continue;
			} else if (strcmp(arg, "-l") == 0 || strcmp(arg, "--charset") == 0) {
				foo = argv[i+1];
				if (foo) {
					forced_target_charset = foo;
					i += 2;
				} else {
					badOption(arg);
					exit(1);
				}
				continue;
			} else if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
				printHelp();
				return 0;
			} else {
				printf ("Unkown option given: \"%s\".\n", arg);
				printHelp();
				return 0;
			}
		}
	}
	
	checkPIDFile();
	
	/* Create PID file. */
	modifyPIDFile(pid_file_create);

	signal (SIGHUP, MainSignalHandler);
	signal (SIGINT, MainSignalHandler);
	signal (SIGTERM, MainSignalHandler);
	
	/* Un-broken pipify */
	signal (SIGPIPE, SIG_IGN);
	
	signal (SIGCHLD, sigChildHandler);
	
#ifdef SIGWINCH
	/* Set up SIGWINCH handler */
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	act.sa_handler = sig_winch;
	sigaction(SIGWINCH, &act, NULL);
#endif

	InitCurses();
	
	/* Check if configfiles exist and create/read them. */
	numfeeds = Config();
			
	LoadAllFeeds (numfeeds);

	if (autoupdate)
		UpdateAllFeeds();
	
	/* Init the pRNG. See about.c for usages of rand() ;) */
	srand(time(0));
	
	/* Give control to main program loop. */
	UIMainInterface();

	/* We really shouldn't be here at all... ah well. */
	MainQuit(NULL, NULL);
	return 0;
}
Пример #4
0
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam,
				   int nCmdShow)
{
	MSG msg;
	WINDOWPLACEMENT w;
	BOOL bQuit = FALSE;

	InitCommonControls();

	hInst = hInstance;

	// Find location of configuration file
	ConfigInit();

	/* Register our custom classes */
	RegisterWindowClasses();

	hMain = CreateWindow(szAppName,       /* window class name */
		szAppName,               /* window caption */
		WS_OVERLAPPEDWINDOW,     /* window style */
		0, 0, 0, 0,              /* initially zero size; changed below */
		NULL,                    /* parent window handle */
		NULL,                    /* window menu handle */
		hInstance,               /* program instance handle */
		NULL);	   	         /* creation parameters */

	if (!hMain)
	{
		char buf[256];
		DWORD err = GetLastError();
		sprintf(buf, "Error - Couldn't Create Client Window : %d", err);
		MessageBox(NULL, buf, "ERROR!", MB_OK);
		MainQuit(hMain);
		exit(1);
	}

	if (config.debug)
		CreateDebugWindow();

	if (lpszCmdParam && strlen(lpszCmdParam) > 0)
		ConfigOverride(lpszCmdParam);

	w.length = sizeof(WINDOWPLACEMENT);
	WindowSettingsLoad(&w);
	SetWindowPlacement(hMain, &w);

	D3DRenderInit(hMain);

	ModulesInit();   // Set up data structures for modules


/* attempt make a crc16 on the meridian.exe */
	GenerateCRC16();

	MainInitState(STATE_OFFLINE);

	UpdateWindow(hMain);

	while (!bQuit)
	{
		MainIdle();

		while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		{
			if (!GetMessage(&msg, NULL, 0, 0))
			{
				bQuit = TRUE;
				break;
			}

			// Forward appropriate messages for tooltips
			if (state == STATE_GAME)
				TooltipForwardMessage(&msg);

			/* Handle modeless dialog messages separately */
			if ((hCurrentDlg == NULL || !IsDialogMessage(hCurrentDlg, &msg)))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
	}

	/* Unregister our custom classes--not good to leave them around */
	UnregisterWindowClasses();

	return msg.wParam;  // Return value of PostQuitMessage
}
Пример #5
0
int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);
	QTextCodec *codec = QTextCodec::codecForName("ISO 8859-7");
	QTextCodec::setCodecForCStrings(codec);
	QTextCodec::setCodecForLocale(codec);

	bool ok;
	QString tmpStr;

	QString iniFile = "./GiDT.ini";

	qDebug() << "Main Thread id: " << QThread::currentThreadId();

	MainSignalHandler slotHandler;


	QObject::connect(&slotHandler, SIGNAL(MainQuit()), &a, SLOT(quit()),Qt::DirectConnection);


	/***************** CONFIGURATION *****************/
	//read config file
	QSettings settings(iniFile, QSettings::IniFormat);
	glb_core.inbox = settings.value("Folders/inbox").toString();
	glb_core.hbbox = settings.value("Folders/hbbox").toString();
	glb_core.logbox = settings.value("Folders/logbox").toString();

	logger = new Logger(glb_core.logbox);

	logger->AddToLog("Program started.");

    //QSqlDatabase maindbHandler = QSqlDatabase::addDatabase("QSQLITE");	//create db object

	/***************** MODULE MANAGER *****************/

	//Start module manager
	modManager = new ModuleManager(&a, iniFile);
	QObject::connect(modManager, SIGNAL(Log(QString)), logger, SLOT(AddLog(QString)), Qt::DirectConnection);
	QObject::connect(modManager, SIGNAL(Output(QString)), logger, SLOT(AddLog(QString)), Qt::DirectConnection);

	/***************** DATABASE *****************/
	//Connect to MySQL database
	glb_core.dbName = settings.value("Database/dbName").toString();
	glb_core.dbServer = settings.value("Database/dbServer").toString();
	glb_core.dbUser = settings.value("Database/dbUser").toString();
	glb_core.dbPassword = settings.value("Database/dbPassword").toString();

	db = new KnxDB(glb_core.dbUser, glb_core.dbPassword, glb_core.dbName, glb_core.dbServer);
	QObject::connect(modManager, SIGNAL(Output(QString)), db, SLOT(Input(QString)), Qt::DirectConnection);		//MOD -> DB
	QObject::connect(db, SIGNAL(OutputMod(QString)),modManager, SLOT(Input(QString)), Qt::DirectConnection);	//DB -> MOD
	QObject::connect(db, SIGNAL(Log(QString)), logger, SLOT(AddLog(QString)), Qt::DirectConnection);
	if (!db->Connect()) {
		qDebug() << "WTF?!?";	//if it can't connect to db then exit
		abort();
	}
	

    /***************** KNX/IP GATEWAYS *****************/
    //Create a new knx/ip client
    int size = settings.beginReadArray("KnxGateways");
    qDebug() << "Found " << size << " gateways.";
    if (size > 0) {
        for (int i = 0; i < size; ++i) {
            settings.setArrayIndex(i);
            qDebug() << "KnxGateways ini[" << i << "]: " << settings.value("iniFile").toString();
            gw[i] = new KnxGateway(settings.value("iniFile").toString());
        }
        settings.endArray();
    }
    //gw = new KnxGateway(settings.value("KnxGateways/iniFile").toString());
    //Use only first gateway
    QObject::connect(gw[0], SIGNAL(Output(QString)), db, SLOT(Input(QString)),Qt::DirectConnection);		//GW -> DB
    QObject::connect(db, SIGNAL(OutputKnx(QString)), gw[0], SLOT(Input(QString)), Qt::DirectConnection);	//DB -> GW
    QObject::connect(gw[0], SIGNAL(Log(QString)), logger, SLOT(AddLog(QString)), Qt::DirectConnection);
    QObject::connect(&slotHandler, SIGNAL(AllQuit()), gw[0], SLOT(AllQuit()),Qt::DirectConnection);


//	QThread gatewayThread;
//	gw[0]->moveToThread(&gatewayThread);
//	QObject::connect(&gatewayThread, SIGNAL(started()),gw[0], SLOT(UdpThread()), Qt::DirectConnection);
//	gatewayThread.start();


//	/***************** UDP SERVER *****************/
//	QString udpServerIp = settings.value("UdpServer/listenIp").toString();
//	quint16 udpServerPort = settings.value("UdpServer/listenPort").toInt();

//	udpServer = new UdpServer(udpServerIp, udpServerPort);
//	QObject::connect(udpServer, SIGNAL(Output(QString)), db, SLOT(Input(QString)), Qt::DirectConnection);		//UDP -> DB
//	QObject::connect(db, SIGNAL(OutputUdp(QString)), udpServer, SLOT(Input(QString)), Qt::DirectConnection);	//UDP <- DB
//	QObject::connect(udpServer, SIGNAL(Log(QString)), logger, SLOT(AddLog(QString)), Qt::DirectConnection);
//	QObject::connect(&slotHandler, SIGNAL(AllQuit()), udpServer, SLOT(AllQuit()),Qt::DirectConnection);
//	//QObject::connect(udpServer, SIGNAL(Output(QString, QString)), modManager, SLOT(Input(QString)), Qt::DirectConnection);


//	QThread udpServerThread;
//	udpServer->moveToThread(&udpServerThread);
//	QObject::connect(&udpServerThread, SIGNAL(started()),udpServer, SLOT(OnUdpData()), Qt::DirectConnection);
//	udpServerThread.start();







//	/***************** CONSOLE *****************/

    ConsoleCapture * console = new ConsoleCapture();
    QObject::connect(console, SIGNAL(Log(QString)), logger, SLOT(AddLog(QString)), Qt::DirectConnection);
    QObject::connect(&slotHandler, SIGNAL(AllQuit()), console, SLOT(AllQuit()),Qt::DirectConnection);
    QObject::connect(console, SIGNAL(ConsoleMsg(QString)), &slotHandler, SLOT(ConsoleMsg(QString)),Qt::DirectConnection);

    QThread captureThread;
    console->moveToThread(&captureThread);
    QObject::connect(&captureThread, SIGNAL(started()),console, SLOT(ReadLoop()), Qt::DirectConnection);
    // go!
    captureThread.start();

    //Start ModuleManager
    if (modManager->Begin() < 0) {
        logger->AddToLog("Could not start Module Manager.");
        return(-1);
    }
    QThread modThread;

    modManager->moveToThread(&modThread);
    QObject::connect(&modThread, SIGNAL(started()),modManager, SLOT(ManagerThread()), Qt::DirectConnection);
    modThread.start();

	qDebug() << "[Main] Functioning with timestamp: " << QDateTime::currentDateTime().toTime_t();
	//QTimer::singleShot(0, console, SLOT(ReadLoop()));
	
	return a.exec();
}
Пример #6
0
/*
 * MenuCommand:  A menu item has been selected.
 */
void MenuCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
   // Set last action time to now, to prevent keypress from being interpreted as a game action.
   KeySetLastNorepeatTime();

   // See if module wants to handle menu selection
   if (ModuleEvent(EVENT_MENUITEM, id) == False)
      return;
   
   /* Handle menu selections */
   switch (id)
   {
   case ID_GAME_EXIT:
      if (connection != CON_NONE && !AreYouSure(hInst, hMain, NO_BUTTON, IDS_LOGOFF))
	 break;
      MainQuit(hwnd);
      break;

   case ID_GAME_PRINTMAP:
      if (state == STATE_GAME)
	 PrintMap(FALSE);
      break;

   case ID_GAME_CONNECT:
      OfflineConnect();	 
      break;
      
   case ID_GAME_DISCONNECT:
      if (!AreYouSure(hInst, hMain, NO_BUTTON, IDS_LOGOFF))
	 break;
      Logoff();
      MainSetState(STATE_OFFLINE);
      break;

   case ID_GAME_SETTINGS:
      if (DialogBox(hInst, MAKEINTRESOURCE(IDD_SETTINGS), hMain, PreferencesDialogProc) == IDOK)
      {
         ModuleEvent(EVENT_CONFIGCHANGED);
         MenuDisplaySettings(hMain);
      }
      break;

  case ID_CONFIGMENU:
	  ConfigMenuLaunch();
      break;

   case ID_GAME_PASSWORD:
      PerformAction(A_CHANGEPASSWORD, NULL);
      break;

   case ID_OPTIONS_TIMEOUT:
      UserSetTimeout();
      break;
   case ID_OPTIONS_MUSIC:
      config.play_music = !config.play_music;
      CheckMenuItem(menu, ID_OPTIONS_MUSIC, config.play_music ? MF_CHECKED : MF_UNCHECKED);
      UserToggleMusic(config.play_music);
      break;
   case ID_OPTIONS_SOUND:
      config.play_sound = !config.play_sound;
      CheckMenuItem(menu, ID_OPTIONS_SOUND, config.play_sound ? MF_CHECKED : MF_UNCHECKED);
      if (!config.play_sound)
	 SoundStopAll();
      break;
   case ID_OPTIONS_SAVENOW:
      SaveSettings();
      break;
   case ID_OPTIONS_SAVEEXIT:
      config.save_settings = !config.save_settings;
      CheckMenuItem(menu, ID_OPTIONS_SAVEEXIT, config.save_settings ? MF_CHECKED : MF_UNCHECKED);
      break;
   case ID_OPTIONS_AREA:
	   // due to issues with certain D3D drivers, this no longer immediately updates the config
	   // it now sets a temporary variable that will update the config on shutdown
	   // this means a shutdown and restart are necessary for window size changes
	   MessageBox(hMain, "You must shutdown and restart Meridian 59 for these changes to take effect",
		   "Direct3D", MB_OK);
		   
//      config.large_area = !config.large_area;
	   gLargeArea = !gLargeArea;
      CheckMenuItem(menu, ID_OPTIONS_AREA, gLargeArea ? MF_CHECKED : MF_UNCHECKED);
/*      if (state == STATE_GAME)
	 // Send ourselves a resize message 
	 ResizeAll();
      RedrawAll();*/
      break;

   case ID_OPTIONS_FONT_MAP_TITLE: UserSelectFont(FONT_MAP_TITLE); break;
   case ID_OPTIONS_FONT_MAP_LABEL: UserSelectFont(FONT_MAP_LABEL); break;
   case ID_OPTIONS_FONT_MAP_TEXT: UserSelectFont(FONT_MAP_TEXT); break;

   case ID_FONT_GAMETEXT:
      UserSelectFont(FONT_EDIT);
      break;
   case ID_FONT_LIST:
      UserSelectFont(FONT_LIST);
      break;
   case ID_FONT_MAIL:
      UserSelectFont(FONT_MAIL);
      break;
   case ID_FONT_TITLES:
      UserSelectFont(FONT_TITLES);
      break;
   case ID_FONT_STATISTICS:
      UserSelectFont(FONT_STATS);
      break;
   case ID_FONT_INPUT:
      UserSelectFont(FONT_INPUT);
      break;
   case ID_FONT_LABELS:
      UserSelectFont(FONT_LABELS);
      break;
   case ID_FONT_DEFAULTS:
      FontsRestoreDefaults();
      break;

   case ID_COLOR_MAIN:
      UserSelectColors(COLOR_FGD, COLOR_BGD);
      break;
   case ID_COLOR_LIST:
      UserSelectColors(COLOR_LISTFGD, COLOR_LISTBGD);
      break;
   case ID_COLOR_LISTSEL:
      UserSelectColors(COLOR_LISTSELFGD, COLOR_LISTSELBGD);
      break;
   case ID_COLOR_MAGIC:
      UserSelectColor(COLOR_ITEM_MAGIC_FG);
      break;
   case ID_COLOR_HIGHLIGHT:
      UserSelectColor(COLOR_HIGHLITE);
      break;
   case ID_COLOR_MAIL:
      UserSelectColors(COLOR_MAILFGD, COLOR_MAILBGD);
      break;
   case ID_COLOR_TEXT:
      UserSelectColors(COLOR_MAINEDITFGD, COLOR_MAINEDITBGD);
      break;
   case ID_COLOR_EDIT:
      UserSelectColors(COLOR_EDITFGD, COLOR_EDITBGD);
      break;
   case ID_COLOR_SYSMSG:
      UserSelectColor(COLOR_SYSMSGFGD);
   case ID_COLOR_QUESTHEADER:
      UserSelectColor(COLOR_QUEST_HEADER);
      break;
      break;
   case ID_COLOR_STATS:
      UserSelectColors(COLOR_STATSFGD, COLOR_STATSBGD);
      break;
   case ID_COLOR_BAR1:
      UserSelectColor(COLOR_BAR1);
      break;
   case ID_COLOR_BAR2:
      UserSelectColor(COLOR_BAR2);
      break;
   case ID_COLOR_BAR3:
      UserSelectColor(COLOR_BAR3);
      break;
   case ID_COLOR_BAR4:
      UserSelectColor(COLOR_BAR4);
      break;
   case ID_COLOR_INVNUM:
      UserSelectColors(COLOR_INVNUMFGD, COLOR_INVNUMBGD);
      break;
   case ID_COLOR_DEFAULTS:
      ColorsRestoreDefaults();
      break;

   case ID_HELP_CONTENTS:
      StartHelp();
      break;
   case ID_HOMEPAGE:
      WebLaunchBrowser(GetString(hInst, IDS_HOMEPAGEURL));
      break;
   case ID_FORUM:
      WebLaunchBrowser(GetString(hInst, IDS_FORUMURL));
      break;
   case ID_WIKI:
      WebLaunchBrowser(GetString(hInst, IDS_WIKIURL));
      break;
   case ID_HELP_ABOUT:
      DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hMain, AboutDialogProc);
      break;

   }
}