summaryrefslogtreecommitdiff
path: root/src/bin/e_imc_main.c
blob: 67ffe4d9bd85178d6b060d42d3e26043035261ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

//extern int errno;
static void _e_help(void);

/* externally accessible functions */

int
main(int argc, char **argv)
{
   int i = 0;
   int valid_args = 0;
   int write_ops = 0;
   Eet_File *ef = NULL;
   E_Input_Method_Config *write_imc = NULL;
   E_Input_Method_Config *read_imc = NULL;
   
   int del_name = 0;
   int del_exe = 0;
   char *file = NULL;
   char *set_name = NULL;
   char *set_exe = NULL;
   char *set_gtk_im_module = NULL;
   char *set_qt_im_module = NULL;
   char *set_xmodifiers = NULL;
   int list = 0;

   /* handle some command-line parameters */
   for (i = 1; i < argc; i++)
     {
	if ((!strcmp(argv[i], "-set-name")) && (i < (argc - 1)))
	  {
	     i++;
	     set_name = argv[i];
             valid_args++;
             write_ops++;
	  }
	else if ((!strcmp(argv[i], "-set-exe")) && (i < (argc - 1)))
	  {
	     i++;
	     set_exe = argv[i];
             valid_args++;
             write_ops++;
	  }
	else if ((!strcmp(argv[i], "-set-gtk-im-module")) && (i < (argc - 1)))
	  {
	     i++;
	     set_gtk_im_module = argv[i];
             valid_args++;
             write_ops++;
	  }
	else if ((!strcmp(argv[i], "-set-qt-im-module")) && (i < (argc - 1)))
	  {
	     i++;
	     set_qt_im_module = argv[i];
             valid_args++;
             write_ops++;
	  }
	else if ((!strcmp(argv[i], "-set-xmodifiers")) && (i < (argc - 1)))
	  {
	     i++;
	     set_xmodifiers = argv[i];
             valid_args++;
             write_ops++;
	  }
	else if ((!strcmp(argv[i], "-del-all")))
	  {
	     del_name = 1;
	     del_exe = 1;
             valid_args++;
             write_ops++;
	  }
	else if ((!strcmp(argv[i], "-del-name")))
	  {
	     del_name = 1;
             valid_args++;
             write_ops++;
	  }
	else if ((!strcmp(argv[i], "-del-exe")))
	  {
	     del_exe = 1;
             valid_args++;
             write_ops++;
	  }
	else if ((!strcmp(argv[i], "-h")) ||
		 (!strcmp(argv[i], "-help")) ||
		 (!strcmp(argv[i], "--h")) ||
		 (!strcmp(argv[i], "--help")))
	  {
	     _e_help();
	     exit(0);
	  }
	else if ((!strcmp(argv[i], "-list")))
	  {
	     list = 1;
	     valid_args++;
	  }
	else
	  file = argv[i];
     }
   if (!file)
     {
	printf("ERROR: no file specified!\n");
	_e_help();
	exit(0);
     }

    if (valid_args == 0) {
        printf("ERROR: no valid arguments!\n");
        _e_help();
        exit(0);
    }

   eet_init();
   e_intl_init();
   
   if (write_ops != 0 && ecore_file_exists(file))
     {
	ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
     }
   else if (write_ops != 0)
     {
	ef = eet_open(file, EET_FILE_MODE_WRITE);
     }
   else
     {
        ef = eet_open(file, EET_FILE_MODE_READ);
     }
   
   if (!ef)
     {
	printf("ERROR: cannot open file %s for READ/WRITE (%d:%s)\n", file, errno, strerror(errno));
	return -1;
     }

   /* If File Exists, Try to read imc */
   read_imc = e_intl_input_method_config_read (ef);
   
   /* else create new imc */
   if (write_ops != 0)
     {
	int write_ok;
	
	write_imc = malloc(sizeof(E_Input_Method_Config));
	write_imc->version = E_INTL_INPUT_METHOD_CONFIG_VERSION;
	if (read_imc == NULL)
	  {
	     write_imc->e_im_name = NULL;
	     write_imc->gtk_im_module = NULL;
	     write_imc->qt_im_module = NULL;
	     write_imc->xmodifiers = NULL;
	     write_imc->e_im_exec = NULL;
	  }
	else
	  {
	     write_imc->e_im_name = read_imc->e_im_name;
	     write_imc->gtk_im_module = read_imc->gtk_im_module;
	     write_imc->qt_im_module = read_imc->qt_im_module;
	     write_imc->xmodifiers = read_imc->xmodifiers;
	     write_imc->e_im_exec = read_imc->e_im_exec;
	  }
	     
	if (set_name != NULL)	
	  write_imc->e_im_name = set_name;     
	if (set_gtk_im_module != NULL)     
	  write_imc->gtk_im_module = set_gtk_im_module;     
	if (set_qt_im_module != NULL)     
	  write_imc->qt_im_module = set_qt_im_module;
	if (set_xmodifiers != NULL)     
	  write_imc->xmodifiers = set_xmodifiers;
	if (set_exe != NULL)
	  write_imc->e_im_exec = set_exe;
	
	
	/* write imc to file */
	write_ok = e_intl_input_method_config_write (ef, write_imc);
     }


   if (list)
     {
	printf("Config File List:\n");
	printf("Config Version:\t%d\n", read_imc->version);
	printf("Config Name:\t%s\n", read_imc->e_im_name);
	printf("Command Line:\t%s\n", read_imc->e_im_exec);
	printf("gtk_im_module:\t%s\n", read_imc->gtk_im_module);
	printf("qt_im_module:\t%s\n", read_imc->qt_im_module);
	printf("xmodifiers:\t%s\n", read_imc->xmodifiers);
     }
   
   e_intl_input_method_config_free(read_imc);
   E_FREE(write_imc); 
   eet_close(ef);
   e_intl_shutdown();
   eet_shutdown();
   /* just return 0 to keep the compiler quiet */
   return 0;
}

static void
_e_help(void)
{
   printf("OPTIONS:\n"
	  "  -set-name NAME             Set the application name\n"
	  "  -set-exe EXE               Set the application execute line\n"
	  "  -set-gtk-im-module		Set the gtk_im_module env var\n"
	  "  -set-qt-im-module		Set the qt_im_module env var\n"
	  "  -set-xmodifiers		Set the xmodifiers env var\n"
	  "  -del-name                  Delete the application name\n"
	  "  -del-exe                   Delete the application execute line\n"
	  "  -list			List Contents of Input Method Config file\n"
	  );
}