Subversion Repositories Tewi

Rev

Rev 312 | Rev 319 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 312 Rev 315
Line 1... Line 1...
1
/* $Id: main.c 312 2024-10-13 18:17:37Z nishi $ */
1
/* $Id: main.c 315 2024-10-14 10:01:02Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 32... Line 32...
32
 
32
 
33
#include "tw_config.h"
33
#include "tw_config.h"
34
#include "tw_server.h"
34
#include "tw_server.h"
35
#include "tw_version.h"
35
#include "tw_version.h"
36
 
36
 
37
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && !defined(__OS2__))
37
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && !defined(__OS2__) && !defined(__NETWARE__))
38
#include <windows.h>
38
#include <windows.h>
-
 
39
#elif defined(__NETWARE__)
-
 
40
#include <nwconio.h>
-
 
41
#include <nwthread.h>
39
#endif
42
#endif
40
 
43
 
41
#ifdef _PSP
44
#ifdef _PSP
42
#include <pspkernel.h>
45
#include <pspkernel.h>
43
#include <pspdebug.h>
46
#include <pspdebug.h>
Line 90... Line 93...
90
 
93
 
91
char tw_server[2048];
94
char tw_server[2048];
92
 
95
 
93
int startup(int argc, char** argv);
96
int startup(int argc, char** argv);
94
 
97
 
95
#if defined(__MINGW32__) || defined(_MSC_VER) || (defined(__WATCOMC__) && !defined(__OS2__)) || defined(__BORLANDC__)
98
#if defined(__MINGW32__) || defined(_MSC_VER) || (defined(__WATCOMC__) && !defined(__OS2__) && !defined(__NETWARE__)) || defined(__BORLANDC__)
96
char* get_registry(const char* main, const char* sub) {
99
char* get_registry(const char* main, const char* sub) {
97
	DWORD bufsize = 512;
100
	DWORD bufsize = 512;
98
	HKEY handle;
101
	HKEY handle;
99
	char* value = malloc(513);
102
	char* value = malloc(513);
100
	int err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, main, 0, KEY_QUERY_VALUE, &handle);
103
	int err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, main, 0, KEY_QUERY_VALUE, &handle);
Line 530... Line 533...
530
}
533
}
531
 
534
 
532
#endif
535
#endif
533
 
536
 
534
#if !defined(BUILD_GUI_VALID)
537
#if !defined(BUILD_GUI_VALID)
-
 
538
void thread_stuff(void* pargs);
-
 
539
 
-
 
540
struct arg_struct {
-
 
541
	int argc;
-
 
542
	char** argv;
-
 
543
};
-
 
544
 
535
int main(int argc, char** argv) {
545
int main(int argc, char** argv) {
536
	int st;
546
	int st;
-
 
547
#ifdef __NETWARE__
-
 
548
	struct arg_struct* parg = malloc(sizeof(*parg));
-
 
549
	parg->argc = argc;
-
 
550
	parg->argv = argv;
-
 
551
	DestroyScreen(GetCurrentScreen());
-
 
552
	SetCurrentScreen(CreateScreen("Tewi Console", 0));
-
 
553
	BeginThread(thread_stuff, NULL, 0, parg);
-
 
554
	ThreadSwitch();
-
 
555
	ExitThread(EXIT_THREAD, 0);
-
 
556
	return 0;
-
 
557
}
-
 
558
 
-
 
559
void thread_stuff(void* pargs) {
-
 
560
	int st;
-
 
561
	int argc = ((struct arg_struct*)pargs)->argc;
-
 
562
	char** argv = ((struct arg_struct*)pargs)->argv;
-
 
563
#endif
537
#ifdef SERVICE
564
#ifdef SERVICE
538
	SERVICE_TABLE_ENTRY table[] = {{"Tewi HTTPd", servmain}, {NULL, NULL}};
565
	SERVICE_TABLE_ENTRY table[] = {{"Tewi HTTPd", servmain}, {NULL, NULL}};
539
	logfile = stderr;
566
	logfile = stderr;
540
	if(!StartServiceCtrlDispatcher(table)) {
567
	if(!StartServiceCtrlDispatcher(table)) {
541
		printf("Failed to start the service dispatcher\n");
568
		printf("Failed to start the service dispatcher\n");
Line 704... Line 731...
704
#ifdef __PPU__
731
#ifdef __PPU__
705
		printf("Error code %d\n", st);
732
		printf("Error code %d\n", st);
706
		while(1)
733
		while(1)
707
			;
734
			;
708
#endif
735
#endif
-
 
736
#ifdef __NETWARE__
-
 
737
		return;
-
 
738
#else
709
		return st;
739
		return st;
710
#endif
740
#endif
-
 
741
#endif
711
	}
742
	}
712
	tw_server_loop();
743
	tw_server_loop();
713
#endif
744
#endif
714
#ifdef _PSP
745
#ifdef _PSP
715
	sceKernelExitGame();
746
	sceKernelExitGame();
716
#endif
747
#endif
-
 
748
#ifdef __NETWARE__
-
 
749
	return;
-
 
750
#else
717
	return 0;
751
	return 0;
-
 
752
#endif
718
}
753
}
719
#endif
754
#endif
720
 
755
 
721
int startup(int argc, char** argv) {
756
int startup(int argc, char** argv) {
722
	int i;
757
	int i;
723
	char* r;
758
	char* r;
724
#if defined(__MINGW32__) || defined(_MSC_VER) || (defined(__WATCOMC__) && !defined(__OS2__)) || defined(__BORLANDC__)
759
#if defined(__MINGW32__) || defined(_MSC_VER) || (defined(__WATCOMC__) && !defined(__OS2__) && !defined(__NETWARE__)) || defined(__BORLANDC__)
725
	char* confpath = cm_strdup(PREFIX "/etc/tewi.conf");
760
	char* confpath = cm_strdup(PREFIX "/etc/tewi.conf");
726
	char* regpath = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir");
761
	char* regpath = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir");
727
	if(regpath != NULL) {
762
	if(regpath != NULL) {
728
		free(confpath);
763
		free(confpath);
729
		confpath = cm_strcat(regpath, "/etc/tewi.conf");
764
		confpath = cm_strcat(regpath, "/etc/tewi.conf");
Line 803... Line 838...
803
	cm_force_log(r);
838
	cm_force_log(r);
804
	free(r);
839
	free(r);
805
#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
840
#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
806
	signal(SIGCHLD, SIG_IGN);
841
	signal(SIGCHLD, SIG_IGN);
807
	signal(SIGPIPE, SIG_IGN);
842
	signal(SIGPIPE, SIG_IGN);
808
#elif !defined(BUILD_GUI) && !defined(__OS2__)
843
#elif !defined(BUILD_GUI) && !defined(__OS2__) && !defined(__NETWARE__)
809
	SetConsoleTitle(tw_server);
844
	SetConsoleTitle(tw_server);
810
#endif
845
#endif
811
	return -1;
846
	return -1;
812
}
847
}