Subversion Repositories MLServ

Rev

Rev 4 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 nishi 1
/* $Id: main.c 5 2024-09-25 00:19:35Z nishi $ */
2
 
4 nishi 3
#include <stdio.h>
4
#include <string.h>
5
 
6
#include "ms_newlist.h"
7
#include "ms_server.h"
8
 
5 nishi 9
#include <cm_crypt.h>
4 nishi 10
#include <cm_version.h>
11
 
5 nishi 12
extern const char* cm_crypt_methods[];
13
 
4 nishi 14
int main(int argc, char** argv) {
15
	int i;
16
	int startsub = 0;
17
	const char* option = NULL;
18
	for(i = 1; i < argc; i++) {
19
		if(argv[i][0] == '-') {
20
			if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) {
21
				printf("MLServ version %s\n", cm_get_version());
22
				return 0;
23
			} else if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
24
				printf("Usage: %s [options] [subcommand] [subcommand options/arguments]\n", argv[0]);
25
				printf("Options:\n");
26
				printf("-V | --version   Shows the version\n");
27
				printf("-h | --help      Shows the help\n");
28
				printf("Subcommands:\n");
29
				printf("newlist          Creates a new list\n");
30
				printf("server           Starts a server\n");
31
				return 0;
32
			} else {
33
				fprintf(stderr, "Invalid flag: %s\n", argv[i]);
34
				return 1;
35
			}
36
		} else {
37
			option = argv[i];
38
			startsub = i + 1;
39
			break;
40
		}
41
	}
42
	if(option == NULL) {
43
		fprintf(stderr, "Specify subcommand\n");
44
		return 1;
45
	} else if(strcmp(option, "newlist") == 0) {
46
		return ms_handle_newlist(argc, argv, startsub);
47
	} else if(strcmp(option, "server") == 0) {
5 nishi 48
		int m;
49
		if((m = cm_crypt_init()) < 0) {
50
			fprintf(stderr, "No crypt() method available\n");
51
			return 1;
52
		}
53
		printf("Using %s as the default crypt() method\n", cm_crypt_methods[m]);
4 nishi 54
		return ms_handle_server(argc, argv, startsub);
55
	} else {
56
		fprintf(stderr, "Invalid subcommand: %s\n", option);
57
		return 1;
58
	}
59
	return 0;
60
}