gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
Added a flag variable for conditional jumps.
[mjc2wsl.git] / src / mjc2wsl.java
1 /*
2 Copyright (C) 2014 Doni Pracner
4 This file is part of mjc2wsl.
6 mjc2wsl is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 mjc2wsl is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with mjc2wsl. If not, see <http://www.gnu.org/licenses/>.
18 */
19 import java.io.*;
20 import java.util.*;
22 /**
23 * This program converts file from compiled MicroJava bytecode to WSL language
24 * which is a part of the FermaT Transformation system. MicroJava is a subset
25 * used in Compiler Construction courses by Hanspeter Moessenboeck, not
26 * "Java ME".
27 *
28 * @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
29 */
30 public class mjc2wsl{
31 public static String versionN = "0.1.7";
33 private TransMessages messages = new TransMessages();
35 private boolean genPauseAfterEachAddress=false,
36 genPrintForEachAddress = false,
37 genPrintEStackOnChange = false;
39 private boolean genPopPush=false;
41 /** Constant used for marking a regular comment from the original file */
42 public static final char C_REG = ' ';
43 /**
44 * Constant used for marking when original code is inserted in the file,
45 * next to the translations
46 */
47 public static final char C_OC = '#';
48 /** Constant used for marking special messages from the translator */
49 public static final char C_SPEC = '&';
50 /** Constant used for marking error messages from the translator */
51 public static final char C_ERR = '!';
53 /** instruction code in MicroJava bytecode. */
54 public static final int
55 load = 1,
56 load_0 = 2,
57 load_1 = 3,
58 load_2 = 4,
59 load_3 = 5,
60 store = 6,
61 store_0 = 7,
62 store_1 = 8,
63 store_2 = 9,
64 store_3 = 10,
65 getstatic = 11,
66 putstatic = 12,
67 getfield = 13,
68 putfield = 14,
69 const_0 = 15,
70 const_1 = 16,
71 const_2 = 17,
72 const_3 = 18,
73 const_4 = 19,
74 const_5 = 20,
75 const_m1 = 21,
76 const_ = 22,
77 add = 23,
78 sub = 24,
79 mul = 25,
80 div = 26,
81 rem = 27,
82 neg = 28,
83 shl = 29,
84 shr = 30,
85 inc = 31,
86 new_ = 32,
87 newarray = 33,
88 aload = 34,
89 astore = 35,
90 baload = 36,
91 bastore = 37,
92 arraylength = 38,
93 pop = 39,
94 dup = 40,
95 dup2 = 41,
96 jmp = 42,
97 jeq = 43,
98 jne = 44,
99 jlt = 45,
100 jle = 46,
101 jgt = 47,
102 jge = 48,
103 call = 49,
104 return_ = 50,
105 enter = 51,
106 exit = 52,
107 read = 53,
108 print = 54,
109 bread = 55,
110 bprint = 56,
111 trap = 57;
113 private boolean originalInComments = false;
115 private HashMap<Integer,String> opMap = null;
117 private String opCodeFile = "mj-bytecodes.properties";
119 private HashMap<Integer, String> getOpMap() {
120 if (opMap == null) {
121 opMap = new HashMap<Integer, String>(60, 0.98f);
122 try {
123 BufferedReader in = new BufferedReader(new InputStreamReader(
124 getClass().getResourceAsStream(opCodeFile)));
125 String str = in.readLine();
126 while (str != null) {
127 String[] ss = str.split("=");
128 opMap.put(Integer.parseInt(ss[0]), ss[1]);
129 str = in.readLine();
131 in.close();
132 } catch (Exception ex) {
133 ex.printStackTrace();
136 return opMap;
139 public String getOpString(int op) {
140 return getOpMap().get(op);
143 public String describeOpCode(int op) {
144 return op + " (" + getOpString(op) + ")";
147 private InputStream mainIn;
148 private PrintWriter out = null;
149 private int counter = -1;
151 private void pr(int i){
152 out.print(i);
155 private void pr(char i){
156 out.print(i);
159 private void pr(String i){
160 out.print(i);
163 private void prl(String i){
164 out.println(i);
167 private int get() {
168 int res = -1;
169 try {
170 res = mainIn.read();
171 if (res >= 0)
172 res = res << 24 >>> 24;
173 } catch (IOException ex) {
174 ex.printStackTrace();
176 counter++;
177 return res;
180 private int get2() {
181 return (get() * 256 + get()) << 16 >> 16;
184 private int get4() {
185 return (get2() << 16) + (get2() << 16 >>> 16);
188 public String createStandardStart(){
189 return createStandardStart(10);
192 public String createStandardStart(int numWords){
193 StringBuilder ret = new StringBuilder(
194 "C:\" This file automatically converted from microjava bytecode\";\n"
195 +"C:\" with mjc2wsl v "+versionN+"\";\n\n");
197 ret.append(createAsciiString());
199 ret.append("\nBEGIN");
200 ret.append("\nVAR <\n\t");
201 ret.append("mjvm_locals := ARRAY(1,0),");
202 ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0),");
203 ret.append("\n\tmjvm_arrays := < >,");
204 ret.append("\n\tmjvm_flag_jump := 0,");
205 ret.append("\n\tmjvm_objects := < >,");
206 ret.append("\n\tmjvm_estack := < >, mjvm_mstack := < > > :");
208 return ret.toString();
211 public String createAsciiString(){
212 StringBuilder ret = new StringBuilder("C:\"char array for ascii code conversions\";");
213 ret.append("\nascii := \"????????????????????????????????\"++\n");
214 ret.append("\" !\"++Quote++\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\";\n");
216 return ret.toString();
219 public String createStandardEnd(){
220 StringBuilder ret = new StringBuilder("SKIP\nENDVAR\n");
221 ret.append("\nWHERE\n");
223 ret.append("\nFUNCT CHR(num) ==:\n");
224 ret.append("\tSUBSTR(ascii,num,1)\n");
225 ret.append("END\n");
227 ret.append("\nPROC Print_MJ(val, format VAR)==\n");
228 ret.append(createComment("print spacing", C_SPEC));
229 ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
230 ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
231 ret.append("\tFI;\n\tPRINFLUSH(val)\nEND\n");
233 ret.append("\nPROC Print_MJ_CHAR(val, format VAR)==\n");
234 ret.append(createComment("print spacing", C_SPEC));
235 ret.append("\n\tIF val=10 OR val=13 THEN\n");
236 ret.append("\t\tPRINT(\"\");\n");
237 ret.append("\tELSE\n");
238 ret.append("\t\tIF format>1 THEN\n\t\t\tFOR i:=2 TO ");
239 ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
240 ret.append("\t\tFI;\n\t\tPRINFLUSH(CHR(val))\n");
241 ret.append("\tFI\n");
242 ret.append("END\n");
244 ret.append("\nEND");
245 return ret.toString();
248 private String createStartVar(String... vars){
249 StringBuilder ret = new StringBuilder("VAR < ");
250 ret.append(vars[0] + " := 0");
251 for (int i=1; i<vars.length; i++)
252 ret.append(", "+ vars[i] +" := 0");
253 ret.append(" > : ");
255 return ret.toString();
258 private String createEndVar(){
259 return "ENDVAR;";
262 private String createLocal(int i) {
263 // arrays start at 1 in WSL, so we need an offset
264 return "mjvm_locals[" + (i + 1) + "]";
267 private String createStatic(int i) {
268 return "mjvm_statics[" + (i + 1) + "]";
271 private String createArray(int i) {
272 return "mjvm_arrays[" + i + "]";
275 private String createArray(String i) {
276 return "mjvm_arrays[" + i + "]";
279 private String createObject(String i) {
280 return "mjvm_objects[" + i + "]";
283 /**
284 * Creates a WSL comment with care to quote chars.
285 */
286 public static String createComment(String str){
287 return createComment(str, C_REG);
290 /**
291 * Creates a WSL comment with care to quote chars, of the
292 * given type. Types are given as char constants. They can be
293 * default comments, comments that contain the original code
294 * in them, or additional comments regarding the translation
295 * process.
296 */
297 public static String createComment(String str, char type) {
298 return "C:\"" + type + str.replace("\"", "''") + "\";";
301 // generalised stack operations
303 private String createToStack(String stack, String var){
304 if (genPopPush)
305 return "PUSH("+stack+"," + var + ");";
306 else
307 return stack + " := <" + var + " > ++ " + stack +";";
310 private String createFromStack(String stack, String var){
311 if (genPopPush)
312 return "POP("+ var + ", "+stack+");";
313 else
314 return var + ":= HEAD("+stack+"); "+stack+" := TAIL("+stack+");";
316 //Expression stack
318 private String createToEStack(int i) {
319 return createToEStack(i+"");
322 private String createToEStack(String i) {
323 String res = createToStack("mjvm_estack", i);
324 if (genPrintEStackOnChange)
325 res += "PRINT(\"eStack\",mjvm_estack);";
326 return res;
329 private String createFromEStack(String st) {
330 String res = createFromStack("mjvm_estack",st);
331 if (genPrintEStackOnChange)
332 res += "PRINT(\"eStack\",mjvm_estack);";
333 return res;
336 private String createPopEStack() {
337 String res = "mjvm_estack := TAIL(mjvm_estack);";
338 if (genPrintEStackOnChange)
339 res += "PRINT(\"eStack\",mjvm_estack);";
340 return res;
343 private String createTopTwoEStack() {
344 return createFromEStack("tempa") + "\n" + createFromEStack("tempb");
347 private String createTopEStack() {
348 return createFromEStack("tempa");
351 //Method stack
353 private String createToMStack(int i) {
354 return createToMStack(i+"");
357 private String createToMStack(String i) {
358 return createToStack("mjvm_mstack", i);
361 private String createFromMStack(String st) {
362 return createFromStack("mjvm_mstack", st);
365 private String getRelationFor(int opcode) throws Exception {
366 switch (opcode) {
367 case jeq: return "=";
368 case jne: return "<>";
369 case jlt: return "<";
370 case jle: return "<=";
371 case jgt: return ">";
372 case jge: return ">=";
374 throw new Exception("Wrong opcode for a relation");
377 private boolean isJumpCode(int opcode) {
378 return (opcode >= jmp) && (opcode <= jge);
381 public void convertStream(InputStream ins) throws Exception{
382 mainIn = ins;
383 //process start
384 byte m = (byte) get();
385 byte j = (byte) get();
386 if (m!='M' || j !='J')
387 throw new Exception("Wrong start of bytecode file");
388 int codesize = get4();
389 int numberOfWords = get4();
390 int mainAdr = get4();
392 prl(createStandardStart(numberOfWords));
393 prl("SKIP;\n ACTIONS a" + (14 + mainAdr) + " :");
394 int op = get();
395 while (op >= 0) {
396 prl(" a" + counter + " ==");
397 if (originalInComments)
398 prl(createComment(describeOpCode(op), C_OC));
399 if (genPrintForEachAddress) {
400 prl("PRINT(\"a" + counter + "\");");
401 if (genPauseAfterEachAddress)
402 prl("debug_disposable_string := @Read_Line(Standard_Input_Port);");
404 switch (op) {
405 case load: {
406 prl(createToEStack(createLocal(get())));
407 break;
409 case load_0:
410 case load_1:
411 case load_2:
412 case load_3: {
413 prl(createStartVar("tempa"));
414 prl("tempa :="+createLocal(op - load_0)+";");
415 prl(createToEStack("tempa"));
416 prl(createEndVar());
417 break;
419 case store: {
420 prl(createFromEStack(createLocal(get())));
421 break;
423 case store_0:
424 case store_1:
425 case store_2:
426 case store_3: {
427 prl(createStartVar("tempa"));
428 prl(createFromEStack("tempa"));
429 prl(createLocal(op - store_0)+" := tempa;");
430 prl(createEndVar());
431 break;
434 case getstatic: {
435 prl(createToEStack(createStatic(get2())));
436 break;
438 case putstatic: {
439 prl(createFromEStack(createStatic(get2())));
440 break;
443 case getfield: {
444 int f = get2();
445 prl(createTopEStack());
446 prl(createToEStack(createObject("tempa") + "[" + (f + 1) + "]"));
447 break;
449 case putfield: {
450 int f = get2();
451 // we need to use a temparray as a pointer, WSL
452 // otherwise tries to access it as a list of lists and fails
453 prl(createTopTwoEStack());
454 prl("VAR < tempArray := " + createObject("tempb") + " > :");
455 prl("tempArray[" + (f + 1) + "]:=tempa ENDVAR;");
456 break;
459 case const_: {
460 prl(createToEStack(get4()));
461 break;
464 case const_0:
465 case const_1:
466 case const_2:
467 case const_3:
468 case const_4:
469 case const_5: {
470 prl(createToEStack(op - const_0));
471 break;
474 case add: {
475 prl(createStartVar("tempa", "tempb", "tempres"));
476 prl(createTopTwoEStack());
477 prl("tempres := tempb + tempa;");
478 prl(createToEStack("tempres"));
479 prl(createEndVar());
480 break;
482 case sub: {
483 prl(createStartVar("tempa", "tempb", "tempres"));
484 prl(createTopTwoEStack());
485 prl("tempres := tempb - tempa;");
486 prl(createToEStack("tempres"));
487 prl(createEndVar());
488 break;
490 case mul: {
491 prl(createStartVar("tempa", "tempb", "tempres"));
492 prl(createTopTwoEStack());
493 prl("tempres := tempb * tempa;");
494 prl(createToEStack("tempres"));
495 prl(createEndVar());
496 break;
498 case div: {
499 prl(createStartVar("tempa", "tempb", "tempres"));
500 prl(createTopTwoEStack());
501 prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
502 prl("tempres := tempb DIV tempa;");
503 prl(createToEStack("tempres"));
504 prl(createEndVar());
505 break;
507 case rem: {
508 prl(createStartVar("tempa", "tempb", "tempres"));
509 prl(createTopTwoEStack());
510 prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
511 prl("tempres := tempb MOD tempa;");
512 prl(createToEStack("tempres"));
513 prl(createEndVar());
514 break;
517 case neg: {
518 prl(createStartVar("tempa"));
519 prl(createTopEStack());
520 prl(createToEStack("-tempa"));
521 prl(createEndVar());
522 break;
525 case shl: {
526 prl(createTopTwoEStack());
527 prl("VAR <tempres :=tempb, i:=1 >:");
528 prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres * 2 OD;");
529 prl(createToEStack("tempres"));
530 prl("ENDVAR;");
531 break;
533 case shr: {
534 prl(createTopTwoEStack());
535 prl("VAR <tempres :=tempb, i:=1 >:");
536 prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres DIV 2 OD;");
537 prl(createToEStack("tempres"));
538 prl("ENDVAR;");
539 break;
542 case inc: {
543 int b1 = get(), b2 = get();
544 prl(createLocal(b1) + " := " + createLocal(b1) + " + " + b2 + ";");
545 break;
548 case new_: {
549 int size = get2();
550 // TODO maybe objects and arrays should be in the same list?
551 prl("mjvm_objects := mjvm_objects ++ < ARRAY(" + size
552 + ",0) >;");
553 prl(createToEStack("LENGTH(mjvm_objects)"));
554 break;
556 case newarray: {
557 get();// 0 - bytes, 1 - words; ignore for now
558 // TODO take into consideration 0/1
559 prl(createTopEStack());
560 prl("mjvm_arrays := mjvm_arrays ++ < ARRAY(tempa,0) >;");
561 prl(createToEStack("LENGTH(mjvm_arrays)"));
562 break;
565 case aload:
566 case baload: {
567 prl(createTopTwoEStack());
568 prl(createToEStack(createArray("tempb") + "[tempa+1]"));
569 break;
571 case astore:
572 case bastore: {
573 prl(createFromEStack("tempres"));
574 prl(createTopTwoEStack());
575 // we need to use a temparray as a pointer, WSL
576 // otherwise tries to access it as a list of lists and fails
577 prl("VAR < tempArray := " + createArray("tempb") + " > :");
578 prl("tempArray[tempa+1]:=tempres ENDVAR;");
579 break;
581 case arraylength: {
582 prl(createTopEStack());
583 prl("tempb := LENGTH("+ createArray("tempa") + ");");
584 prl(createToEStack("tempb"));
585 break;
588 case dup: {
589 prl(createTopEStack());
590 prl(createToEStack("tempa"));
591 prl(createToEStack("tempa"));
592 break;
594 case dup2: {
595 prl(createTopTwoEStack());
596 prl(createToEStack("tempb"));
597 prl(createToEStack("tempa"));
598 prl(createToEStack("tempb"));
599 prl(createToEStack("tempa"));
600 break;
603 case pop: {
604 prl(createPopEStack());
605 break;
608 case jmp: {
609 prl("CALL a" + (counter + get2()) + ";");
610 break;
613 case jeq:
614 case jne:
615 case jlt:
616 case jle:
617 case jgt:
618 case jge: {
619 prl(createStartVar("tempa", "tempb"));
620 prl(createTopTwoEStack());
621 prl("IF tempb " + getRelationFor(op)
622 + " tempa THEN mjvm_flag_jump := 1"
623 + " ELSE mjvm_flag_jump := 0"
624 + " FI;");
625 prl(createEndVar());
626 prl("IF mjvm_flag_jump = 1 THEN CALL a"
627 + (counter + get2())
628 + " ELSE CALL a" + (counter + 1)
629 + " FI;");
631 break;
634 case call: {
635 prl("CALL a" + (counter + get2()) + ";");
636 break;
639 case return_: {
640 // we let the actions return
641 // there is nothing to clean up
642 prl("SKIP\n END\n b" + counter + " ==");
643 break;
645 case enter: {
646 int parameters = get();
648 int locals = get();
649 prl(createToMStack("mjvm_locals"));
650 prl("mjvm_locals := ARRAY(" + locals + ",0);");
651 for (int i = parameters - 1; i >= 0; i--)
652 prl(createFromEStack(createLocal(i)));
653 break;
655 case exit: {
656 prl(createFromMStack("mjvm_locals"));
657 break;
660 // read, print
661 case bread: {
662 // TODO make it a char for read
663 messages.message("char is read like a number", TransMessages.M_WAR);
664 prl(createComment("char is read like a number", C_SPEC));
666 case read: {
667 prl(createStartVar("tempa"));
668 prl("tempa := @String_To_Num(@Read_Line(Standard_Input_Port));");
669 prl(createToEStack("tempa"));
670 prl(createEndVar());
671 break;
674 // the prints
675 case bprint: {
676 prl(createStartVar("tempa", "tempb"));
677 prl(createTopTwoEStack());
678 prl("Print_MJ_CHAR(tempb,tempa);");
679 prl(createEndVar());
680 break;
682 case print: {
683 // TODO printing numbers needs different lengths of spacing
684 prl(createStartVar("tempa", "tempb"));
686 prl(createTopTwoEStack());
687 prl("Print_MJ(tempb,tempa);");
688 prl(createEndVar());
689 break;
692 case trap: {
693 prl("ERROR(\"Runtime error: trap(" + get() + ")\");");
694 break;
697 default:
698 prl(createComment("unknown op error: " + op, C_ERR));
699 messages.message("unknown op error: " + op, TransMessages.M_ERR);
700 break;
703 boolean wasJump = isJumpCode(op);
704 op = get();
705 if (op >= 0)
706 if (wasJump)
707 prl("SKIP\n END");
708 else
709 prl("CALL a" + counter + "\n END");
711 prl("SKIP\n END\nENDACTIONS;\n");
712 pr(createStandardEnd());
715 public void convertFile(File f) {
716 try {
717 convertStream(new FileInputStream(f));
718 } catch (Exception ex) {
719 ex.printStackTrace();
723 public void printHelp() {
724 printVersion();
725 printUsage();
726 printHelpOutput();
727 printHelpHelp();
730 public void printLongHelp() {
731 printVersion();
732 printUsage();
733 System.out.println();
734 printHelpOutput();
735 System.out.println();
736 printHelpDirectives();
737 System.out.println();
738 printHelpGenerating();
739 System.out.println();
740 printHelpHelp();
743 public void printHelpOutput() {
744 System.out.println("Output options:");
745 System.out.println(" --screen print output to screen");
746 System.out.println(" -o --oc[+-] include original code in comments");
747 System.out.println(" -v verbose, print warning messages");
748 System.out.println(" -q quiet; don't print even the error messages");
749 System.out.println(" -d print detailed debug messages");
752 public void printHelpGenerating() {
753 System.out.println("Options for generating extra code for tracking code execution");
754 System.out.println(" --genEStackPrint generate print for all EStack changes");
755 System.out.println(" --genAddrPrint generate prints after every address of the original code ");
756 System.out.println(" --genAddrPause generate a pause after every address of the original code ");
757 System.out.println(" --genAddr short for --genAddrPrint and --genAddrPause");
758 System.out.println(" --genAll short for applying all code generation");
761 public void printHelpDirectives(){
762 System.out.println("Alternatives for code generation:");
763 System.out.println(" --genPopPush generate POP/PUSH instead of TAIL/HEAD");
766 public void printHelpHelp() {
767 System.out.println("Help and info options");
768 System.out.println(" -h basic help");
769 System.out.println(" --help print more detailed help");
770 System.out.println(" --version or -version print version and exit");
773 public void printUsage(){
774 System.out.println("usage:\n\t mjc2wsl {options} filename [outfile]");
777 public void printVersion() {
778 System.out.println("MicroJava bytecode to WSL converter. v " + versionN
779 + ", by Doni Pracner");
782 public String makeDefaultOutName(String inname){
783 String rez = inname;
784 if (inname.endsWith(".obj"))
785 rez = rez.substring(0, rez.length() - 4);
786 return rez + ".wsl";
789 public void run(String[] args) {
790 if (args.length == 0) {
791 printHelp();
792 } else {
793 int i = 0;
794 while (i < args.length && args[i].charAt(0) == '-') {
795 if (args[i].compareTo("-h") == 0) {
796 printHelp();
797 return;
798 } else if (args[i].compareTo("--help") == 0) {
799 printLongHelp();
800 return;
801 } else if (args[i].compareTo("--version") == 0
802 || args[i].compareTo("-version") == 0) {
803 printVersion();
804 return;
805 } else if (args[i].compareTo("-o") == 0
806 || args[i].startsWith("--oc")) {
807 if (args[i].length() == 2)
808 originalInComments = true;
809 else if (args[i].length() == 5)
810 originalInComments = args[i].charAt(4) == '+';
811 else
812 originalInComments = true;
813 } else if (args[i].compareTo("--screen") == 0) {
814 out = new PrintWriter(System.out);
815 } else if (args[i].compareTo("-d") == 0) {
816 messages.setPrintLevel(TransMessages.M_DEB);// print debug info
817 } else if (args[i].compareTo("-v") == 0) {
818 messages.setPrintLevel(TransMessages.M_WAR);// print warnings
819 } else if (args[i].compareTo("-q") == 0) {
820 messages.setPrintLevel(TransMessages.M_QUIET);// no printing
821 } else if (args[i].compareToIgnoreCase("--genEStackPrint") == 0) {
822 genPrintEStackOnChange = true;
823 } else if (args[i].compareToIgnoreCase("--genAddrPause") == 0) {
824 genPauseAfterEachAddress = true;
825 } else if (args[i].compareToIgnoreCase("--genAddrPrint") == 0) {
826 genPrintForEachAddress = true;
827 } else if (args[i].compareToIgnoreCase("--genAddr") == 0) {
828 genPrintForEachAddress = true;
829 genPauseAfterEachAddress = true;
830 } else if (args[i].compareToIgnoreCase("--genAll") == 0) {
831 genPrintEStackOnChange = true;
832 genPrintForEachAddress = true;
833 genPauseAfterEachAddress = true;
834 } else if (args[i].compareToIgnoreCase("--genPopPush") == 0) {
835 genPopPush = true;
837 i++;
840 if (i >= args.length) {
841 System.out.println("no filename supplied");
842 System.exit(2);
844 File f = new File(args[i]);
846 if (i + 1 < args.length) {
847 try {
848 out = new PrintWriter(args[i + 1]);
849 } catch (Exception e) {
850 System.err.println("error in opening out file:");
851 e.printStackTrace();
854 if (out == null) {
855 // if not set to screen, or a file, make a default filename
856 try {
857 out = new PrintWriter(makeDefaultOutName(args[i]));
858 } catch (Exception e) {
859 System.err.println("error in opening out file:");
860 e.printStackTrace();
863 if (f.exists()) {
864 Calendar now = Calendar.getInstance();
865 convertFile(f);
866 long mili = Calendar.getInstance().getTimeInMillis()
867 - now.getTimeInMillis();
868 System.out.println("conversion time:" + mili + " ms");
869 messages.printMessageCounters();
870 out.close();
871 } else
872 System.out.println("file does not exist");
876 public static void main(String[] args) {
877 new mjc2wsl().run(args);
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner