fix a horrible memleak in ipkg (#2702)
[openwrt.git] / package / ifxmips_adsl / src / translate.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15 */
16 //-----------------------------------------------------------------------
17 //Description:
18 // winhost script translation tool under Linux for Danube
19 //-----------------------------------------------------------------------
20 //Author: Qi-Ming.Wu@infineon.com
21 //Created: 29-October-2004
22 //-----------------------------------------------------------------------
23 /* History
24 * Last changed on:
25 * Last changed by:
26 *
27 */
28
29 #define _IFXMIPS_ADSL_APP
30 //#define DEBUG
31 #define u32 unsigned int
32 #define u16 unsigned short
33 #define u8 unsigned char
34 #define IFXMIPS_MEI_DEV "/dev/ifxmips/mei"
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <fcntl.h>
39 #include <errno.h>
40 #include <string.h>
41 #include <time.h>
42 #include <getopt.h>
43 #include <sys/types.h>
44 #include <sys/ioctl.h>
45 #include <sys/stat.h>
46 #include <sys/time.h>
47 #include <sys/mman.h>
48
49 #include <asm/ifxmips/ifxmips.h>
50 #include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
51 #include <asm/ifxmips/ifxmips_mei_app.h>
52 #include <asm/ifxmips/ifxmips_mei_ioctl.h>
53 #include <asm/ifxmips/ifxmips_mei.h>
54
55
56 /*============================definitions======================*/
57 #define OPTN 5
58 #define CNFG 8
59 #define CNTL 1
60 #define STAT 2
61 #define RATE 6
62 #define PLAM 7
63 #define INFO 3
64 #define TEST 4
65
66 typedef unsigned short UINT16;
67 typedef unsigned long UINT32;
68
69
70
71 /*=============================================================*/
72
73
74 /*=============================global variables================*/
75 int c=0;
76 int input_flag=0;
77 int digit_optind=0;
78 FILE* script_file;
79 void (*func)()=NULL;
80 int fd;
81
82 UINT16 var16[8];
83 UINT32 var32[8];
84 UINT16 Message[16];
85
86 /*=============================================================*/
87
88
89
90
91 void display_version()
92 {
93 printf("translate version1.0\nby Wu Qi Ming\nQi-Ming.Wu@infineon.com\n");
94 return;
95 }
96
97
98 void translate_help()
99 {
100 printf("Usage:translate [options] [parameter] ...\n");
101 printf("options:\n");
102 printf("-h --help Display help information\n");
103 printf("-v --version Display version information\n");
104 printf("-f --file Specify the script file\n");
105 printf("-e --execute Execute the specified script file\n");
106 //printf("-c --check Check the script file\n");
107 return;
108 }
109
110 /*
111 print the content in buf excluding the command "echo" itself.
112 */
113
114 void echo(char* buf)
115 {
116 int i;
117 char msg[128];
118 for(i=0;i<128;i++)
119 {
120 if((buf[i]!=0)&&(buf[i]!=32))
121 {
122 sscanf(buf+i,"%s",&msg);
123 if(strcmp(msg,"echo")==0)
124 i+=4;
125 else break;
126 }
127
128 }
129 for(i;i<128;i++)
130 {
131 if(buf[i]!=0&&(buf[i]!=10))
132 {
133 printf("%c",buf[i]);
134 }
135 }
136
137
138 printf("\n");
139 return;
140
141 }
142
143 static void makeCMV(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data)
144 {
145
146 memset(Message, 0, 16*2);
147 Message[0]= (opcode<<4) + (size&0xf);
148 if(opcode == H2D_DEBUG_WRITE_DM)
149 Message[1]= (group&0x7f);
150 else
151 Message[1]= (((index==0)?0:1)<<7) + (group&0x7f);
152 Message[2]= address;
153 Message[3]= index;
154 if((opcode == H2D_CMV_WRITE)||(opcode == H2D_DEBUG_WRITE_DM))
155 memcpy(Message+4, data, size*2);
156
157 return;
158 }
159
160
161
162 UINT16 CMV_read(char* str_group,int address,int index)
163 {
164 int group=0;
165 if(strcmp(str_group,"optn")==0)
166 group=OPTN;
167 else if(strcmp(str_group,"cnfg")==0)
168 group=CNFG;
169 else if(strcmp(str_group,"cntl")==0)
170 group=CNTL;
171 else if(strcmp(str_group,"stat")==0)
172 group=STAT;
173 else if(strcmp(str_group,"rate")==0)
174 group=RATE;
175 else if(strcmp(str_group,"plam")==0)
176 group=PLAM;
177 else if(strcmp(str_group,"info")==0)
178 group=INFO;
179 else if(strcmp(str_group,"test")==0)
180 group=TEST;
181 else
182 {
183 printf("wrong group type!\ncheck script file please!\n");
184 exit(0);
185 }
186
187 #ifndef DEBUG
188 makeCMV(H2D_CMV_READ, group, address, index, 1, NULL);
189 if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
190 printf("cr read %d %d %d fail",group,address,index);
191 exit(0);
192 }
193 #endif
194
195 return Message[4];
196
197
198 }
199
200
201 int CMV_write(char* str_group,int address,int index,UINT16 value)
202 {
203 int group=0;
204 if(strcmp(str_group,"optn")==0)
205 group=OPTN;
206 else if(strcmp(str_group,"cnfg")==0)
207 group=CNFG;
208 else if(strcmp(str_group,"cntl")==0)
209 group=CNTL;
210 else if(strcmp(str_group,"stat")==0)
211 group=STAT;
212 else if(strcmp(str_group,"rate")==0)
213 group=RATE;
214 else if(strcmp(str_group,"plam")==0)
215 group=PLAM;
216 else if(strcmp(str_group,"info")==0)
217 group=INFO;
218 else if(strcmp(str_group,"test")==0)
219 group=TEST;
220 else
221 {
222 printf("wrong group type!\ncheck script file please!\n");
223 exit(0);
224 }
225
226 #ifndef DEBUG
227 makeCMV(H2D_CMV_WRITE, group, address, index, 1, &value);
228 if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
229 printf("cw %d %d %d fail",group,address,index);
230 return -1;
231 }
232 #endif
233
234 return 0;
235
236
237 }
238
239 void execute_script()
240 {
241 char buf[128];
242 char str_command[20]={0};
243 char str_group[20]={0};
244 char str_value[128]={0};
245 char op1[40],op2[40];
246 int address,index;
247 int n=0;
248 UINT16 value=0;
249 if(!script_file) return;
250
251 while(fgets(buf,128,script_file))/*scan one line into buffer, 128 bytes at most*/
252 {
253 if(sscanf(buf,"%s",&str_command)==0) continue;
254 /*if the line is empty, then go on to the next*/
255 if(strcmp(str_command,"cr")==0)/*cr command*/
256 {
257 sscanf(buf,"%s %s %d %d %s",&str_command,\
258 &str_group,\
259 &address,\
260 &index,\
261 &str_value);
262 if(strncmp(str_value,"$",1)!=0)
263 {
264 printf("error:cr parameter type mismatch!\n");
265 break;
266 }
267 n=strtoul(str_value+1,NULL,0);
268 var16[n]=CMV_read(str_group,address,index);
269 printf("read %s %d %d, value=%04x\n",str_group, address, index,var16[n]);
270 }
271 else if(strcmp(str_command,"cw")==0)/*cw command*/
272 {
273 sscanf(buf,"%s %s %d %d %s",&str_command,\
274 &str_group,\
275 &address,\
276 &index,\
277 &str_value);
278 n=strtoul(str_value+1,NULL,0);
279 if(strncmp(str_value,"$",1)==0)
280 {
281 value=var16[n];
282 }
283 else if(strncmp(str_value,"#",1)==0)
284 {
285 value=strtoul(str_value+1,NULL,0);
286 }
287 else
288 {
289 value=strtoul(str_value,NULL,0);
290 }
291 if(CMV_write(str_group,address,index,value)<0)
292 {
293 break;
294 }
295 }
296
297 else if(strcmp(str_command,"mw")==0)/*mr command*/
298 {
299
300 sscanf(buf,"%s %s %s",&str_command,\
301 &op1,\
302 &str_value);
303
304 n=strtoul(str_value+1,NULL,0);
305 address=strtoul(op1,NULL,0);
306 if(strncmp(str_value,"$",1)==0)
307 {
308 value=var16[n];
309 }
310 else if(strncmp(str_value,"#",1)==0)
311 {
312 value=strtoul(str_value+1,NULL,0);
313 }
314 else
315 {
316 value=strtoul(str_value,NULL,0);
317
318 }
319
320 makeCMV(H2D_DEBUG_WRITE_DM, 0x0, address>>16, (address)&(0xffff), 1, &value);
321 if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
322 printf("mw %08x fail",address);
323 break;
324
325 }
326
327 }
328
329 else if(strcmp(str_command,"mr")==0)/*mr command*/
330 {
331
332 sscanf(buf,"%s %s %s",&str_command,\
333 &op1,\
334 &str_value);
335 address=strtoul(op1,NULL,0);
336 n=strtoul(str_value+1,NULL,0);
337 if(strncmp(str_value,"$",1)!=0)
338 {
339 printf("error:mr parameter type mismatch!\n");
340 break;
341 }
342 makeCMV(H2D_DEBUG_READ_DM, 0x0, address>>16, (address)&(0xffff), 1, NULL);
343 if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
344 printf("mw %08x fail",address);
345 break;
346 }
347 value=Message[4];
348 var16[n]=value;
349 }
350
351
352
353 else if(strcmp(str_command,"meiw")==0)/*meiw command*/
354 {
355 meireg regrdwr;
356 sscanf(buf,"%s %s %s",&str_command,\
357 &op1,\
358 &op2);
359 regrdwr.iAddress=strtoul(op1,NULL,0)+IFXMIPS_MEI_BASE_ADDR;
360
361
362 if(strncmp(op2,"#",1)==0) regrdwr.iData=strtoul(op1+1,NULL,0);
363 else if(strncmp(op2,"$",1)==0) regrdwr.iData=var16[strtoul(op2+1,NULL,0)];
364 else if(strncmp(op2,"@",1)==0) regrdwr.iData=var32[strtoul(op2+1,NULL,0)];
365 else regrdwr.iData=strtoul(op1,NULL,0);
366 //printf("address=%08x\n", regrdwr.iAddress);
367 if(ioctl(fd, IFXMIPS_MEI_CMV_WRITE, &regrdwr)<0){
368 printf("meiw fail\n");
369 break;;
370 }
371
372 }
373
374 else if(strcmp(str_command,"meir")==0)/*meir command*/
375 {
376 meireg regrdwr;
377 sscanf(buf,"%s %s %s",&str_command,\
378 &op1,\
379 &op2);
380 regrdwr.iAddress=strtoul(op1,NULL,0)+IFXMIPS_MEI_BASE_ADDR;
381 if(ioctl(fd, IFXMIPS_MEI_CMV_READ, &regrdwr)<0){
382 printf("meir fail\n");
383 break;
384 }
385 if(strncmp(op2,"$",1)==0) var16[strtoul(op2+1,NULL,0)]=regrdwr.iData;
386 else if(strncmp(op2,"@",1)==0) var32[strtoul(op2+1,NULL,0)]=regrdwr.iData;
387 else
388 {
389 printf("meir grammar error!\n");
390 break;
391 }
392
393 }
394
395
396 else if(strcmp(str_command,"lst")==0)/*lst command*/
397 {
398
399 sscanf(buf,"%s %s",&str_command,\
400 &str_value);
401
402 if(strncmp(str_value,"$",1)==0)
403 {
404 n=strtoul(str_value+1,NULL,0);
405 printf("$%d=0x%04x\n",n,var16[n]);
406
407 }
408 else if(strncmp(str_value,"@",1)==0)
409 {
410 n=strtoul(str_value+1,NULL,0);
411 printf("$%d=0x%08x\n",n,var32[n]);
412
413 }
414 else
415 {
416 printf("lst grammar error!\n");
417 break;
418 }
419 }
420
421 else if(strcmp(str_command,"echo")==0)/*echo command*/
422 {
423 echo(buf);
424 }
425 else if(strcmp(str_command,"mov")==0)/*mov command*/
426 {
427 sscanf(buf,"%s %s %s",&str_command,\
428 &op1,\
429 &op2);
430 if(strncmp(op1,"$",1)==0)
431 {
432 if(strncmp(op2,"$",1)==0)
433 {
434 var16[strtoul(op1+1,NULL,0)]=var16[strtoul(op2+1,NULL,0)];
435 }
436 else if(strncmp(op2,"@",1)==0)
437 {
438 var16[strtoul(op1+1,NULL,0)]= var32[strtoul(op2+1,NULL,0)];
439
440 }
441 else if(strncmp(op2,"#",1)==0)
442 {
443 var16[strtoul(op1+1,NULL,0)]=strtoul(op2+1,NULL,0);
444 }
445 else
446 {
447 var16[strtoul(op1+1,NULL,0)]=strtoul(op2,NULL,0);
448
449 }
450 }
451 else if(strncmp(op1,"@",1)==0)
452 {
453 if(strncmp(op2,"$",1)==0)
454 {
455 var32[strtoul(op1+1,NULL,0)]=var16[strtoul(op2+1,NULL,0)];
456 }
457 else if(strncmp(op2,"@",1)==0)
458 {
459 var32[strtoul(op1+1,NULL,0)]= var32[strtoul(op2+1,NULL,0)];
460
461 }
462 else if(strncmp(op2,"#",1)==0)
463 {
464 var32[strtoul(op1+1,NULL,0)]=strtoul(op2+1,NULL,0);
465 }
466 }
467 else
468 {
469 printf("grammar error!\n");
470 break;
471 }
472
473
474 }
475
476
477 else if(strcmp(str_command,"or")==0)/*or command*/
478 {
479 sscanf(buf,"%s %s %s",&str_command,\
480 &op1,\
481 &op2);
482 if(strncmp(op1,"$",1)==0)
483 {
484 if(strncmp(op2,"$",1)==0)
485 {
486 var16[strtoul(op1+1,NULL,0)]|=var16[strtoul(op2+1,NULL,0)];
487 }
488 else if(strncmp(op2,"@",1)==0)
489 {
490 var16[strtoul(op1+1,NULL,0)]|= var32[strtoul(op2+1,NULL,0)];
491
492 }
493 else if(strncmp(op2,"#",1)==0)
494 {
495 var16[strtoul(op1+1,NULL,0)]|=strtoul(op2+1,NULL,0);
496 }
497 }
498 else if(strncmp(op1,"@",1)==0)
499 {
500 if(strncmp(op2,"$",1)==0)
501 {
502 var32[strtoul(op1+1,NULL,0)]|=var16[strtoul(op2+1,NULL,0)];
503 }
504 else if(strncmp(op2,"@",1)==0)
505 {
506 var32[strtoul(op1+1,NULL,0)]|= var32[strtoul(op2+1,NULL,0)];
507
508 }
509 else if(strncmp(op2,"#",1)==0)
510 {
511 var32[strtoul(op1+1,NULL,0)]|=strtoul(op2+1,NULL,0);
512 }
513 }
514 else
515 {
516 printf("grammar error!\n");
517 break;
518 }
519 }
520
521 else if(strcmp(str_command,"and")==0)/*and command*/
522 {
523 sscanf(buf,"%s %s %s",&str_command,\
524 &op1,\
525 &op2);
526 if(strncmp(op1,"$",1)==0)
527 {
528 if(strncmp(op2,"$",1)==0)
529 {
530 var16[strtoul(op1+1,NULL,0)]&=var16[strtoul(op2+1,NULL,0)];
531 }
532 else if(strncmp(op2,"@",1)==0)
533 {
534 var16[strtoul(op1+1,NULL,0)]&= var32[strtoul(op2+1,NULL,0)];
535
536 }
537 else if(strncmp(op2,"#",1)==0)
538 {
539 var16[strtoul(op1+1,NULL,0)]&=strtoul(op2+1,NULL,0);
540 }
541 }
542 else if(strncmp(op1,"@",1)==0)
543 {
544 if(strncmp(op2,"$",1)==0)
545 {
546 var32[strtoul(op1+1,NULL,0)]&=var16[strtoul(op2+1,NULL,0)];
547 }
548 else if(strncmp(op2,"@",1)==0)
549 {
550 var32[strtoul(op1+1,NULL,0)]&= var32[strtoul(op2+1,NULL,0)];
551
552 }
553 else if(strncmp(op2,"#",1)==0)
554 {
555 var32[strtoul(op1+1,NULL,0)]&=strtoul(op2+1,NULL,0);
556 }
557 }
558 else
559 {
560 printf("grammar error!\n");
561 break;
562 }
563 }
564 else if(strcmp(str_command,"not")==0)/*not command*/
565 {
566 sscanf(buf,"%s %s",&str_command,\
567 &op1);
568 if(strncmp(op1,"$",1)==0)
569 {
570 var16[strtoul(op1+1,NULL,0)]=~var16[strtoul(op1+1,NULL,0)];
571 }
572 else if(strncmp(op1,"@",1)==0)
573 {
574 var32[strtoul(op1+1,NULL,0)]=~var32[strtoul(op1+1,NULL,0)];
575 }
576 else
577 {
578 printf("grammar error!\n");
579 break;
580 }
581 }
582 else if(strcmp(str_command,"shl")==0)/*shl command*/
583 {
584 sscanf(buf,"%s %s %s",&str_command,\
585 &op1,\
586 &op2);
587 if(strncmp(op1,"$",1)==0)
588 {
589 if(strncmp(op2,"$",1)==0)
590 {
591 var16[strtoul(op1+1,NULL,0)]<<=var16[strtoul(op2+1,NULL,0)];
592 }
593 else if(strncmp(op2,"@",1)==0)
594 {
595 var16[strtoul(op1+1,NULL,0)]<<= var32[strtoul(op2+1,NULL,0)];
596
597 }
598 else if(strncmp(op2,"#",1)==0)
599 {
600 var16[strtoul(op1+1,NULL,0)]<<=strtoul(op2+1,NULL,0);
601 }
602 }
603 else if(strncmp(op1,"@",1)==0)
604 {
605 if(strncmp(op2,"$",1)==0)
606 {
607 var32[strtoul(op1+1,NULL,0)]<<=var16[strtoul(op2+1,NULL,0)];
608 }
609 else if(strncmp(op2,"@",1)==0)
610 {
611 var32[strtoul(op1+1,NULL,0)]<<= var32[strtoul(op2+1,NULL,0)];
612
613 }
614 else if(strncmp(op2,"#",1)==0)
615 {
616 var32[strtoul(op1+1,NULL,0)]<<=strtoul(op2+1,NULL,0);
617 }
618 }
619 else
620 {
621 printf("grammar error!\n");
622 break;
623 }
624 }
625
626 else if(strcmp(str_command,"shr")==0)/*shr command*/
627 {
628 sscanf(buf,"%s %s %s",&str_command,\
629 &op1,\
630 &op2);
631 if(strncmp(op1,"$",1)==0)
632 {
633 if(strncmp(op2,"$",1)==0)
634 {
635 var16[strtoul(op1+1,NULL,0)]>>=var16[strtoul(op2+1,NULL,0)];
636 }
637 else if(strncmp(op2,"@",1)==0)
638 {
639 var16[strtoul(op1+1,NULL,0)]>>= var32[strtoul(op2+1,NULL,0)];
640
641 }
642 else if(strncmp(op2,"#",1)==0)
643 {
644 var16[strtoul(op1+1,NULL,0)]>>=strtoul(op2+1,NULL,0);
645 }
646 }
647 else if(strncmp(op1,"@",1)==0)
648 {
649 if(strncmp(op2,"$",1)==0)
650 {
651 var32[strtoul(op1+1,NULL,0)]>>=var16[strtoul(op2+1,NULL,0)];
652 }
653 else if(strncmp(op2,"@",1)==0)
654 {
655 var32[strtoul(op1+1,NULL,0)]>>= var32[strtoul(op2+1,NULL,0)];
656
657 }
658 else if(strncmp(op2,"#",1)==0)
659 {
660 var32[strtoul(op1+1,NULL,0)]>>=strtoul(op2+1,NULL,0);
661 }
662 }
663 else
664 {
665 printf("grammar error!\n");
666 break;
667 }
668 }
669
670 else if(strcmp(str_command,"add")==0)/*add command*/
671 {
672 sscanf(buf,"%s %s %s",&str_command,\
673 &op1,\
674 &op2);
675 if(strncmp(op1,"$",1)==0)
676 {
677 if(strncmp(op2,"$",1)==0)
678 {
679 var16[strtoul(op1+1,NULL,0)]+=var16[strtoul(op2+1,NULL,0)];
680 }
681 else if(strncmp(op2,"@",1)==0)
682 {
683 var16[strtoul(op1+1,NULL,0)]+= var32[strtoul(op2+1,NULL,0)];
684
685 }
686 else if(strncmp(op2,"#",1)==0)
687 {
688 var16[strtoul(op1+1,NULL,0)]+=strtoul(op2+1,NULL,0);
689 }
690 }
691 else if(strncmp(op1,"@",1)==0)
692 {
693 if(strncmp(op2,"$",1)==0)
694 {
695 var32[strtoul(op1+1,NULL,0)]+=var16[strtoul(op2+1,NULL,0)];
696 }
697 else if(strncmp(op2,"@",1)==0)
698 {
699 var32[strtoul(op1+1,NULL,0)]+= var32[strtoul(op2+1,NULL,0)];
700
701 }
702 else if(strncmp(op2,"#",1)==0)
703 {
704 var32[strtoul(op1+1,NULL,0)]+=strtoul(op2+1,NULL,0);
705 }
706 }
707 else
708 {
709 printf("grammar error!\n");
710 break;
711 }
712 }
713 else if(strcmp(str_command,"sub")==0)/*sub command*/
714 {
715 sscanf(buf,"%s %s %s",&str_command,\
716 &op1,\
717 &op2);
718 if(strncmp(op1,"$",1)==0)
719 {
720 if(strncmp(op2,"$",1)==0)
721 {
722 var16[strtoul(op1+1,NULL,0)]-=var16[strtoul(op2+1,NULL,0)];
723 }
724 else if(strncmp(op2,"@",1)==0)
725 {
726 var16[strtoul(op1+1,NULL,0)]-= var32[strtoul(op2+1,NULL,0)];
727
728 }
729 else if(strncmp(op2,"#",1)==0)
730 {
731 var16[strtoul(op1+1,NULL,0)]-=strtoul(op2+1,NULL,0);
732 }
733 }
734 else if(strncmp(op1,"@",1)==0)
735 {
736 if(strncmp(op2,"$",1)==0)
737 {
738 var32[strtoul(op1+1,NULL,0)]-=var16[strtoul(op2+1,NULL,0)];
739 }
740 else if(strncmp(op2,"@",1)==0)
741 {
742 var32[strtoul(op1+1,NULL,0)]-= var32[strtoul(op2+1,NULL,0)];
743
744 }
745 else if(strncmp(op2,"#",1)==0)
746 {
747 var32[strtoul(op1+1,NULL,0)]-=strtoul(op2+1,NULL,0);
748 }
749 }
750 else
751 {
752 printf("grammar error!\n");
753 break;
754 }
755 }
756
757 memset(str_command,0,20);
758 memset(buf,0,128);
759 }
760 return;
761 }
762
763 int main (int argc, char** argv) {
764
765 #ifndef DEBUG
766 fd=open(IFXMIPS_MEI_DEV, O_RDWR);
767 if(fd<0){
768 printf("\n\n autoboot open device fail\n");
769 return -1;
770 }
771 #endif
772 while(1) {
773 int option_index=0;
774 static struct option long_options[] ={
775 {"help",0,0,0},
776 {"version",0,0,0},
777 {"file",1,0,0},
778 {"execute",0,0,0}
779 };
780
781 c = getopt_long(argc,argv, "hvf:e",
782 long_options, &option_index);
783
784 //printf("c=%d option_index=%d\n",c,option_index);
785 if(c==-1)
786 {
787 if(input_flag==0)
788 {
789 printf("translate:please specify parameters\n");
790 func=&translate_help;
791 }
792 if(func)
793 (*func)();
794 else
795 {
796 ERROR: translate_help();
797 }
798 break;
799 }
800 input_flag=1;
801 switch (c) {
802 case 0:
803 if(option_index==0)
804 {
805 func=&translate_help;
806 break;
807 }
808 if(option_index==1)
809 {
810 func=&display_version;
811 break;
812 }
813 if(option_index==2)
814 {
815 goto FILE;
816 break;
817 }
818 if(option_index==3)
819 {
820 goto EXECUTE;
821 break;
822 }
823 case 'h':
824 func=&translate_help;
825 break;
826 case 'v':
827 func=&display_version;
828 break;
829 case 'f':
830 FILE: if(!optarg) goto ERROR;
831 script_file=fopen((char*)optarg,"r");
832 if(!script_file) perror("fopen");
833 break;
834 case 'e':
835 EXECUTE: func=&execute_script;
836 break;
837 }
838
839
840 }
841 if(script_file) fclose(script_file);
842 #ifndef DEBUG
843 close(fd);
844 #endif
845 }
846
847
848
This page took 0.107529 seconds and 5 git commands to generate.