1
0
mirror of https://github.com/Wind4/vlmcsd.git synced 2024-11-25 03:21:03 +08:00
vlmcsd/vlmcsdmulti.c

100 lines
2.1 KiB
C
Raw Permalink Normal View History

2015-11-29 17:30:52 +08:00
/* Multi-Call Binary for vlmcs and vlmcsd */
2016-10-08 13:35:48 +08:00
#define _CRT_SECURE_NO_WARNINGS
2015-11-29 17:30:52 +08:00
#ifndef CONFIG
#define CONFIG "config.h"
#endif // CONFIG
#include CONFIG
#if MULTI_CALL_BINARY < 1
#error "Please define MULTI_CALL_BINARY=1 when compiling this file."
#endif
#include <stdio.h>
2016-10-08 13:35:48 +08:00
#if !_MSC_VER
#include <libgen.h>
#else // _MSC_VER
#include <stdlib.h>
#include "helpers.h"
#endif // _MSC_VER
2015-11-29 17:30:52 +08:00
#include "vlmcs.h"
#include "vlmcsd.h"
#include "types.h"
#include "shared_globals.h"
#include "output.h"
#if (defined(_WIN32) || defined(__CYGWIN__))
#define compare strcasecmp // Best for case-preserving (but otherwise case-insensitive) filesystems
#else // native Unix
#define compare strcmp // for case-sensitive filesystems
#endif // native Unix
2016-10-08 13:35:48 +08:00
#if _MSC_VER
static char* basename(const char* fullname)
{
size_t len = strlen(fullname);
char* filename = (char*)vlmcsd_malloc(len + 1);
char* extension = (char*)vlmcsd_malloc(len + 1);
static char result[64];
_splitpath(fullname, NULL, NULL, filename, extension);
if (strlen(filename) + strlen(extension) > 63)
{
*result = 0;
goto finally;
}
strcpy(result, filename);
strcat(result, extension);
finally:
free(filename);
free(extension);
return result;
}
#endif // _MSC_VER
2015-11-29 17:30:52 +08:00
int main(int argc, CARGV argv)
{
multi_argv = argv;
multi_argc = argc;
if (!compare(basename((char*)*argv), "vlmcsd"))
return server_main(argc, argv);
if (!compare(basename((char*)*argv), "vlmcs"))
return client_main(argc, argv);
2016-10-08 13:35:48 +08:00
#ifdef _WIN32
2015-11-29 17:30:52 +08:00
if (!compare(basename((char*)*argv), "vlmcsd.exe"))
return server_main(argc, argv);
if (!compare(basename((char*)*argv), "vlmcs.exe"))
return client_main(argc, argv);
2016-10-08 13:35:48 +08:00
#endif // _WIN32
2015-11-29 17:30:52 +08:00
if (argc > 1)
{
2016-10-08 13:35:48 +08:00
if (!strcmp((char*)argv[1], "vlmcsd"))
2015-11-29 17:30:52 +08:00
return server_main(argc - 1, argv + 1);
2016-10-08 13:35:48 +08:00
if (!strcmp((char*)argv[1], "vlmcs"))
2015-11-29 17:30:52 +08:00
return client_main(argc - 1, argv + 1);
}
errorout(
2016-10-08 13:35:48 +08:00
"vlmcsdmulti %s\n\n"
"Usage:\n"
"\t%s vlmcsd [<vlmcsd command line>]\n"
"\t%s vlmcs [<vlmcs command line>]\n\n",
Version, *argv, *argv
2015-11-29 17:30:52 +08:00
);
return !0;
}