Subversion Repositories Tewi

Rev

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

Rev 209 Rev 212
Line 1... Line 1...
1
/* $Id: main.c 209 2024-10-02 03:01:30Z nishi $ */
1
/* $Id: main.c 212 2024-10-02 17:44:55Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
-
 
7
#ifndef _MSC_VER
7
#include <unistd.h>
8
#include <unistd.h>
-
 
9
#endif
8
#include <stdio.h>
10
#include <stdio.h>
9
#include <stdbool.h>
11
#include <stdbool.h>
10
#include <string.h>
12
#include <string.h>
11
#include <signal.h>
13
#include <signal.h>
12
#include <stdlib.h>
14
#include <stdlib.h>
Line 20... Line 22...
20
 
22
 
21
#include "tw_config.h"
23
#include "tw_config.h"
22
#include "tw_server.h"
24
#include "tw_server.h"
23
#include "tw_version.h"
25
#include "tw_version.h"
24
 
26
 
25
#ifdef __MINGW32__
27
#if defined(__MINGW32__) || defined(_MSC_VER)
26
#include <windows.h>
28
#include <windows.h>
27
#endif
29
#endif
28
 
30
 
29
#ifdef _PSP
31
#ifdef _PSP
30
#include <pspkernel.h>
32
#include <pspkernel.h>
Line 57... Line 59...
57
#include <stdarg.h>
59
#include <stdarg.h>
58
#include <png.h>
60
#include <png.h>
59
 
61
 
60
#define printf(...) tt_printf(__VA_ARGS__)
62
#define printf(...) tt_printf(__VA_ARGS__)
61
#define STDERR_LOG(...) tt_printf(__VA_ARGS__)
63
#define STDERR_LOG(...) tt_printf(__VA_ARGS__)
-
 
64
#elif defined(_MSC_VER)
-
 
65
void STDERR_LOG(const char* format, ...){
-
 
66
	va_list args;
-
 
67
	va_start(args, format);
-
 
68
	vfprintf(stderr, format, args);
-
 
69
	va_end(args);
-
 
70
}
62
#else
71
#else
63
#define STDERR_LOG(...) fprintf(stderr, __VA_ARGS__)
72
#define STDERR_LOG(...) fprintf(stderr, __VA_ARGS__)
64
#endif
73
#endif
65
 
74
 
66
extern bool cm_do_log;
75
extern bool cm_do_log;
Line 69... Line 78...
69
 
78
 
70
char tw_server[2048];
79
char tw_server[2048];
71
 
80
 
72
int startup(int argc, char** argv);
81
int startup(int argc, char** argv);
73
 
82
 
74
#ifdef __MINGW32__
83
#if defined(__MINGW32__) || defined(_MSC_VER)
75
char* get_registry(const char* main, const char* sub) {
84
char* get_registry(const char* main, const char* sub) {
76
	DWORD bufsize = 512;
85
	DWORD bufsize = 512;
77
	HKEY handle;
86
	HKEY handle;
78
	char* value = malloc(513);
87
	char* value = malloc(513);
79
	int err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, main, 0, KEY_QUERY_VALUE, &handle);
88
	int err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, main, 0, KEY_QUERY_VALUE, &handle);
Line 508... Line 517...
508
}
517
}
509
 
518
 
510
#endif
519
#endif
511
 
520
 
512
int main(int argc, char** argv) {
521
int main(int argc, char** argv) {
-
 
522
	int st;
513
	logfile = stderr;
523
	logfile = stderr;
514
#ifdef SERVICE
524
#ifdef SERVICE
515
	SERVICE_TABLE_ENTRY table[] = {{"Tewi HTTPd", servmain}, {NULL, NULL}};
525
	SERVICE_TABLE_ENTRY table[] = {{"Tewi HTTPd", servmain}, {NULL, NULL}};
516
	StartServiceCtrlDispatcher(table);
526
	StartServiceCtrlDispatcher(table);
517
#else
527
#else
Line 664... Line 674...
664
		;
674
		;
665
	init_scr();
675
	init_scr();
666
	scr_printf("PS2 Bootstrap, Tewi/%s\n", tw_get_version());
676
	scr_printf("PS2 Bootstrap, Tewi/%s\n", tw_get_version());
667
	SleepThread();
677
	SleepThread();
668
#endif
678
#endif
669
	int st = startup(argc, argv);
679
	st = startup(argc, argv);
670
	if(st != -1) {
680
	if(st != -1) {
671
#ifdef _PSP
681
#ifdef _PSP
672
		printf("Error code %d\n", st);
682
		printf("Error code %d\n", st);
673
		while(running) sceKernelDelayThread(50 * 1000);
683
		while(running) sceKernelDelayThread(50 * 1000);
674
		sceKernelExitGame();
684
		sceKernelExitGame();
Line 689... Line 699...
689
	return 0;
699
	return 0;
690
}
700
}
691
 
701
 
692
int startup(int argc, char** argv) {
702
int startup(int argc, char** argv) {
693
	int i;
703
	int i;
-
 
704
	char* r;
694
#ifdef __MINGW32__
705
#if defined(__MINGW32__) || defined(_MSC_VER)
695
	char* confpath = cm_strdup(PREFIX "/etc/tewi.conf");
706
	char* confpath = cm_strdup(PREFIX "/etc/tewi.conf");
696
	char* regpath = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir");
707
	char* regpath = get_registry("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tewi HTTPd", "InstallDir");
697
	if(regpath != NULL) {
708
	if(regpath != NULL) {
698
		free(confpath);
709
		free(confpath);
699
		confpath = cm_strcat(regpath, "/etc/tewi.conf");
710
		confpath = cm_strcat(regpath, "/etc/tewi.conf");
Line 767... Line 778...
767
	if(tw_server_init() != 0) {
778
	if(tw_server_init() != 0) {
768
		STDERR_LOG("Could not initialize the server\n");
779
		STDERR_LOG("Could not initialize the server\n");
769
		return 1;
780
		return 1;
770
	}
781
	}
771
	sprintf(tw_server, "Tewi/%s (%s)%s", tw_get_version(), tw_get_platform(), config.extension == NULL ? "" : config.extension);
782
	sprintf(tw_server, "Tewi/%s (%s)%s", tw_get_version(), tw_get_platform(), config.extension == NULL ? "" : config.extension);
772
	char* r = cm_strcat(tw_server, " running...");
783
	r = cm_strcat(tw_server, " running...");
773
	cm_force_log(r);
784
	cm_force_log(r);
774
	free(r);
785
	free(r);
775
#ifndef __MINGW32__
786
#if !defined(__MINGW32__) && !defined(_MSC_VER)
776
	signal(SIGCHLD, SIG_IGN);
787
	signal(SIGCHLD, SIG_IGN);
777
	signal(SIGPIPE, SIG_IGN);
788
	signal(SIGPIPE, SIG_IGN);
778
#else
789
#else
779
	SetConsoleTitle(tw_server);
790
	SetConsoleTitle(tw_server);
780
#endif
791
#endif