1 /*
2 linphone
3 Copyright (C) 2012 Belledonne Communications SARL
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 */
19 
20 #include <stdio.h>
21 #include "lpc2xml.h"
22 
cb_function(void * ctx,lpc2xml_log_level level,const char * msg,va_list list)23 void cb_function(void *ctx, lpc2xml_log_level level, const char *msg, va_list list) {
24 	const char *header = "";
25 	switch(level) {
26 		case LPC2XML_DEBUG:
27 			header = "DEBUG";
28 			break;
29 		case LPC2XML_MESSAGE:
30 			header = "MESSAGE";
31 			break;
32 		case LPC2XML_WARNING:
33 			header = "WARNING";
34 			break;
35 		case LPC2XML_ERROR:
36 			header = "ERROR";
37 			break;
38 	}
39 	fprintf(stdout, "%s - ", header);
40 	vfprintf(stdout, msg, list);
41 	fprintf(stdout, "\n");
42 }
43 
show_usage(int argc,char * argv[])44 void show_usage(int argc, char *argv[]) {
45 	fprintf(stderr, "usage:\n%s convert <lpc_file> <xml_file>\n%s dump <lpc_file>\n", argv[0], argv[0]);
46 }
47 
main(int argc,char * argv[])48 int main(int argc, char *argv[]) {
49 	lpc2xml_context *ctx;
50 	LpConfig *lpc;
51 	if(argc > 4 || argc < 3) {
52 		show_usage(argc, argv);
53 		return -1;
54 	}
55 
56 	lpc = lp_config_new(argv[2]);
57 	if(strcmp("convert", argv[1]) == 0 && argc == 4) {
58 		ctx = lpc2xml_context_new(cb_function, NULL);
59 		lpc2xml_set_lpc(ctx, lpc);
60 		lpc2xml_convert_file(ctx, argv[3]);
61 		lpc2xml_context_destroy(ctx);
62 	} else if (strcmp("dump", argv[1]) == 0 && argc == 3) {
63 		char *dump = lp_config_dump_as_xml(lpc);
64 		fprintf(stdout, "%s", dump);
65 	} else {
66 		show_usage(argc, argv);
67 	}
68 	lp_config_destroy(lpc);
69 	return 0;
70 }
71 
72