Annotation of OpenXM/src/OpenMath/OM2OXM.java, Revision 1.10
1.1 tam 1: /**
1.10 ! tam 2: * $OpenXM: OpenXM/src/OpenMath/OM2OXM.java,v 1.9 1999/11/16 13:16:22 tam Exp $
1.1 tam 3: *
4: * $B$3$N%/%i%9$G$O0J2<$N(B BNF $B$GI=$5$l$k9=J82r@O$r<BAu$7$F$$$k(B
5: * expr -> stag [expr | immediate]* etag
6: * immediate -> INTEGER
7: * | SYMBOL
8: * stag -> '<' SYMBOL '>'
9: * etag -> '<' '/' SYMBOL '>'
10: * $B=*C<5-9f(B: INTEGER, SYMBOL, '<', '/', '>'
11: * $BHs=*C<5-9f(B: expr, stag, etag, immediate
12: * $B3+;O5-9f(B: expr
13: *
14: * $B0J2<$N4X?t$r;HMQ(B:
15: * public void send(OutputStream os); - buffer $B$K$"$k(B OX message $B$rAw?.$9$k(B.
16: * public int parse(); - $B9=J82r@O$r3+;O$9$k(B.
17: * private int parse_expr(); - parser $B$N(B expr $BItJ,(B
18: * private Attribute parse_stag(); - parser $B$N(B stag $BItJ,(B
19: * private void parse_etag(Attribute tag,int argnum); - parser $B$N(B etag $BItJ,(B
20: * private int parse_immediate(); - parser $B$N(B immediate $BItJ,(B
21: * private void parse_error(String mesg); - parser $B$N(B error $B$rI=<($7$F=*N;$9$k(B
22: * public static void main(String[] args); - main $B4X?t(B.
23: *
24: * $B0J2<$NJQ?t$r;HMQ(B:
25: * Attribute Attribute; - $B;z6g2r@O4o$r8F$S=P$7(B, $B$=$NB0@-CM$rJ]B8$7$F$*$/(B
26: * int token; - $B8=:_FI$_9~$s$G$$$k(B token $B$rJ]B8$7$F$*$/$N$K;HMQ(B.
27: * CellStack stack; - $B%;%^%s%F%#%C%/%9$N%A%'%C%/$K;H$&FbIt%9%?%C%/(B.
28: * ByteArrayOutputStream buffer; - oxasir $B$KAw?.$9$k$^$($K%G!<%?$rN/$a$F$*$/(B
29: */
30:
31: import java.io.*;
32: import java.net.*;
33: import java.util.Vector;
34: import JP.ac.kobe_u.math.tam.OpenXM.*;
35:
36: final class OM2OXM implements Runnable{
37: private PushbackInputStream is;
38: private String attribute;
39: private int token = TT_NULL;
40: private boolean lexPushbackFlag = false;
41: private OpenXM asir; // for debug
1.7 tam 42: private boolean debug = false;
1.1 tam 43:
44: // Token Type for lexical analyzer
45: final static int TT_NULL = 0;
46: final static int TT_String = -1;
47: final static int TT_StartTag = -2;
48: final static int TT_EndTag = -3;
49: final static int TT_SingleTag = -4;
50:
51: public void run(){ // for debug
52: //$B%5!<%PB&$+$iAw?.$5$l$?J8;zNs$r<u?.$7$^$9!#(B
53: try{
54: while(true){
55: CMO tmp;
56:
57: switch(asir.receiveOXtag()){
58: case OpenXM.OX_COMMAND:
59: asir.receiveSM();
60: break;
61:
62: case OpenXM.OX_DATA:
63: tmp = asir.receiveCMO();
1.2 tam 64: System.out.println("=> "+ CMO2OM(tmp));
1.1 tam 65: break;
66: }
67:
68: }
69: }catch(IOException e){}
70: }
71:
72: public static String CMO2OM(CMO cmo){
1.2 tam 73: return "<OMOBJ>"+ CMO2OM_sub(cmo) +"</OMOBJ>";
74: }
75:
1.9 tam 76: private static String CMO2OM_sub(CMO cmo) throws NumberFormatException{
1.1 tam 77: String ret = "";
78:
79: switch(cmo.getDISCRIMINATOR()){
80: case CMO.CMO_NULL:
81: return "<OMI>0</OMI>";
82:
83: case CMO.CMO_INT32:
84: return "<OMI>"+ ((CMO_INT32)cmo).intValue() +"</OMI>";
85:
86: // case CMO.CMO_DATUM:
87:
88: case CMO.CMO_STRING:
89: return "<OMSTR>"+ ((CMO_STRING)cmo).getString() +"</OMSTR>";
90:
91: // case CMO.CMO_LIST:
92:
93: case CMO.CMO_MONOMIAL32:
94: ret += "<OMA><OMS name=\"Monom\" cd=\"poly\"/>";
1.2 tam 95: ret += CMO2OM_sub(((CMO_MONOMIAL32)cmo).getCoefficient());
1.1 tam 96: for(int i=0;i<((CMO_MONOMIAL32)cmo).getDegree().length;i++){
97: ret += "<OMI>"+ ((CMO_MONOMIAL32)cmo).getDegree()[i] +"</OMI>";
98: }
99: ret += "</OMA>";
100: return ret;
101:
102: case CMO.CMO_ZZ:
103: return "<OMI>"+ ((CMO_ZZ)cmo).BigIntValue() +"</OMI>";
104:
105: case CMO.CMO_QQ:
106: return "<OMA><OMS name=\"over\" cd=\"basic\"/>"+
1.2 tam 107: CMO2OM_sub(((CMO_QQ)cmo).getBunshi())+
108: CMO2OM_sub(((CMO_QQ)cmo).getBunbo())+
109: "</OMA>";
1.1 tam 110:
111: case CMO.CMO_ZERO:
112: return "<OMI> 0 </OMI>";
113:
114: // case CMO.CMO_DMS:
115:
116: case CMO.CMO_DMS_GENERIC:
117: ret += "<OMA><OMS name=\"PolyRing\" cd=\"poly\"/>";
1.4 tam 118: ret += "<OMI>2</OMI></OMA>";
1.1 tam 119: return ret;
120:
121: case CMO.CMO_DISTRIBUTED_POLYNOMIAL:
122: ret += "<OMA><OMS name=\"DMP\" cd=\"poly\"/>";
1.2 tam 123: ret += CMO2OM_sub(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getRing());
1.1 tam 124: ret += "<OMA><OMS name=\"SDMP\" cd=\"poly\"/>";
1.2 tam 125: for(int i=0;i<((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials().length;
126: i++){
127: ret += CMO2OM_sub(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials()[i]);
1.1 tam 128: }
129: ret += "</OMA></OMA>";
130: return ret;
131:
1.7 tam 132: case CMO.CMO_BIGFLOAT:
133: ret += "<OMA><OMS name=\"times\" cd=\"basic\"/>";
134: ret += CMO2OM_sub(((CMO_BIGFLOAT)cmo).getSyosubu());
135: ret += "<OMA><OMS name=\"power\" cd=\"basic\"/>";
136: ret += "<OMI>2</OMI>";
137: ret += CMO2OM_sub(((CMO_BIGFLOAT)cmo).getShisubu());
138: ret += "</OMA></OMA>";
139: return ret;
140:
1.1 tam 141: case CMO.CMO_INDETERMINATE:
142: return "<OMV name=\""+ ((CMO_INDETERMINATE)cmo).getString() +"\"/>";
143:
1.10 ! tam 144: case CMO.CMO_TREE:
! 145: ret += "<OMA><OMS name=\""+ ((CMO_TREE)cmo).getName() +"\" cdname=\""+
! 146: ((CMO_TREE)cmo).getCDName() +"\"/>";
! 147: for(int i=0;i<((CMO_TREE)cmo).getLeaves().getElement().length;i++){
! 148: ret += CMO2OM_sub(((CMO_TREE)cmo).getLeaves().getElement()[i]);
! 149: }
! 150: ret += "</OMA>";
! 151: return ret;
1.1 tam 152:
153: default:
1.9 tam 154: //return "<OMSTR>"+ cmo.toCMOexpression() +"</OMSTR>";
1.1 tam 155: }
1.9 tam 156:
1.10 ! tam 157: throw new NumberFormatException("unknown convert way:"+
! 158: cmo.toCMOexpression());
1.1 tam 159: }
160:
161: private boolean isSpace(int ch){ // use from lex
162: return (ch==' ' || ch=='\t' || ch=='\n' || ch=='\r');
163: }
164:
165: private int skipSpace() throws IOException{ // use from lex
166: int ch;
167:
168: do{
169: ch = is.read();
170: }while(isSpace(ch));
171: is.unread(ch);
172:
173: return ch;
174: }
175:
176: private void pushbackLex(){
177: if(lexPushbackFlag){
178: System.err.println("lex pushback error!");
179: }
180: lexPushbackFlag = true;
181: }
182:
183: private int readNextToken() throws IOException{ // lexical analyzer
184: String buf = "";
185: int ch;
186:
187: if(lexPushbackFlag){
188: lexPushbackFlag = false;
189: return token;
190: }
191:
192: token = TT_NULL;
193: attribute = "";
194: skipSpace();
195: ch = is.read();
196:
197: if(ch == '<'){ // for tag
198: ch = skipSpace();
199: if(ch == '/'){
200: is.read();
201: token = TT_EndTag;
202: skipSpace();
203: }else{
204: token = TT_StartTag;
205: }
206: while((ch = is.read()) != '>' && ch != '/' && ch != -1){
207: if(isSpace(ch)){
208: if((ch = skipSpace()) != '>' && ch != '/'){
209: buf += " ";
210: }
211: continue;
212: }
213:
214: buf += Character.toUpperCase((char)ch);
215:
216: if(ch == '"'){
217: do{
218: ch = is.read();
219: buf += (char)ch;
220: }while(ch != '"' && ch != -1);
221: }
222: }
223: if(ch == '>'){ // for StartTag and EndTag
224: attribute = buf;
225: return token;
226: }else if(ch == '/'){
227: skipSpace();
228: if((ch = is.read()) == '>'){ // for SingleTag
229: attribute = buf;
230: return token = TT_SingleTag;
231: }
232: }
233: return token = TT_NULL;
234: }else if(ch != -1){
235: is.unread(ch);
236: while((ch = is.read()) != '<' && ch != -1){
1.3 tam 237: debug("debug: "+ch);
1.1 tam 238: if(isSpace(ch)){
1.5 tam 239: String spaces = String.valueOf((char)ch);
1.1 tam 240:
241: while(isSpace(ch = is.read())){
242: spaces += (char)ch;
243: }
244: if(ch != '<' && ch != -1){
245: buf += spaces;
246: }
247: is.unread(ch);
248: }else{
249: buf += (char)ch;
250: }
251: }
252: is.unread(ch);
253:
254: attribute = buf;
255: return token = TT_String;
256: }
257:
258: return token = TT_NULL;
259: }
260:
261: private boolean exceptTokenTypeInParse(int type) throws IOException{
262: // use from parse
263: if(readNextToken() != type){
264: parse_error("We expect type :'"+ type
265: +"', but we got type :'"+ token +"'("+ attribute +").");
266: }
1.3 tam 267: //debug(":"+token+":"+attribute+":"+type);
1.1 tam 268: return true;
269: }
270:
271: public CMO parse(InputStream stream) throws IOException{
272: // start -> '<OMOBJ>' object '</OMOBJ>'
273: CMO ret;
274:
275: is = new PushbackInputStream(stream);
276:
277: exceptTokenTypeInParse(TT_StartTag);
278: if(!attribute.equals("OMOBJ")){
279: parse_error("We expect '<OMOBJ>'.");
280: }
281:
282: ret = parse_object();
1.3 tam 283:
1.1 tam 284: exceptTokenTypeInParse(TT_EndTag);
285: if(!attribute.equals("OMOBJ")){
286: parse_error("We expect '</OMOBJ>'.");
287: }
288:
289: return ret;
290: }
291:
292: private CMO parse_object() throws IOException{
293: // object -> variable
294: // | '<OMI>' S? integer S? '</OMI>'
1.3 tam 295: // | '<OMSTR>' S? utf7 S? '</OMSTR>'
1.1 tam 296: // | '<OMA>' S? symbol S? objects S? '</OMA>'
297: CMO ret;
298:
299: if(readNextToken() != TT_StartTag && token != TT_SingleTag){
300: parse_error("We expect '<OMI> or '<OMA>' or '<OMV>'.");
301: }
302:
303: if(attribute.startsWith("OMV")){
304: pushbackLex();
305: ret = parse_variable();
306: }else if(attribute.equals("OMI")){
307: pushbackLex();
308: ret = parse_OMI();
1.3 tam 309: }else if(attribute.equals("OMSTR")){
310: pushbackLex();
311: ret = parse_OMSTR();
1.1 tam 312: }else if(attribute.equals("OMA")){
313: String name,cdname;
314: int argnum = 0;
315:
316: name = parse_symbol();
317:
318: if(name.equals("DMP")){
319: ret = parse_symb_DMP();
1.6 tam 320: debug("poly: "+ret);
1.1 tam 321: }else{
322: ret = new CMO_TREE(name,"Basic",parse_objects());
323: }
324:
325: exceptTokenTypeInParse(TT_EndTag);
326: if(!attribute.equals("OMA")){
327: parse_error("We expect '</OMA>'.");
328: }
329: }else{
330: parse_error("???");
331: ret = null;
332: }
333:
334: return ret;
335: }
336:
337: private CMO_ZZ parse_OMI() throws IOException{
338: CMO_ZZ ret;
339:
340: exceptTokenTypeInParse(TT_StartTag);
341: if(!attribute.equals("OMI")){
342: parse_error("We expect '<OMI>'.");
343: }
344:
345: ret = (CMO_ZZ)parse_integer();
346:
347: exceptTokenTypeInParse(TT_EndTag);
348: if(!attribute.equals("OMI")){
349: parse_error("We expect '</OMI>'.");
350: }
351:
352: return ret;
353: }
354:
1.3 tam 355: private CMO_STRING parse_OMSTR() throws IOException{
356: CMO_STRING ret;
357:
358: exceptTokenTypeInParse(TT_StartTag);
359: if(!attribute.equals("OMSTR")){
360: parse_error("We expect '<OMSTR>'.");
361: }
362:
363: if(readNextToken() == TT_String){
364: //ret = (CMO_STRING)parse_utf7();
365: ret = new CMO_STRING(attribute);
366: }else{
367: ret = new CMO_STRING("");
368: pushbackLex();
369: }
370:
371: exceptTokenTypeInParse(TT_EndTag);
372: if(!attribute.equals("OMSTR")){
373: parse_error("We expect '</OMSTR>'.");
374: }
375:
376: return ret;
377: }
378:
1.1 tam 379: private CMO parse_symb_DMP() throws IOException{
380: parse_object();
381: return new CMO_DISTRIBUTED_POLYNOMIAL(new CMO_DMS_GENERIC(),
382: parse_symb_SDMP());
383: }
384:
385: private CMO_MONOMIAL32[] parse_symb_SDMP() throws IOException{
386: Vector mono = new Vector();
387: CMO_MONOMIAL32[] ret;
388:
389: exceptTokenTypeInParse(TT_StartTag);
390: if(!attribute.equals("OMA")){
391: parse_error("We expect '<OMA>'.");
392: }
393:
394: if(!parse_symbol().equals("SDMP")){
395: parse_error("We expect '<SDMP>'");
396: }
397:
398: while(readNextToken() != TT_EndTag){
399: pushbackLex();
400: mono.addElement(parse_symb_Monom());
401: }
402:
403: if(!attribute.equals("OMA")){
404: parse_error("We expect '</OMA>'.");
405: }
406:
407: ret = new CMO_MONOMIAL32[mono.size()];
408: mono.copyInto((Object[])ret);
409:
410: return ret;
411: }
412:
413: private CMO_MONOMIAL32 parse_symb_Monom() throws IOException{
414: Vector degree = new Vector();
415: int[] array;
416:
417: exceptTokenTypeInParse(TT_StartTag);
418: if(!attribute.equals("OMA")){
419: parse_error("We expect '<OMA>'.");
420: }
421:
422: if(!parse_symbol().equals("Monom")){
423: parse_error("We expect '<Monom>'");
424: }
425:
426: while(readNextToken() != TT_EndTag){
427: pushbackLex();
428: degree.addElement(parse_OMI());
429: }
430:
431: if(!attribute.equals("OMA")){
432: parse_error("We expect '<OMA>'.");
433: }
434:
435: array = new int[degree.size()-1];
436: for(int i=0;i<array.length;i++){
437: array[i] = ((CMO_ZZ)degree.elementAt(i+1)).intValue();
438: }
439:
1.6 tam 440: //debug("monom: "+ new CMO_MONOMIAL32(array,(CMO_ZZ)degree.elementAt(0)));
1.1 tam 441: return new CMO_MONOMIAL32(array,(CMO_ZZ)degree.elementAt(0));
442: }
443:
1.8 tam 444: private CMO_LIST parse_objects() throws IOException{
1.1 tam 445: // $B2r@O$5$l$?(B object $B$r(B LIST $B$GJV$9(B
446: Vector objects = new Vector();
447: CMO[] array;
448:
449: while(readNextToken() != TT_EndTag){
450: pushbackLex();
451: objects.addElement(parse_object());
452: }
453: pushbackLex();
454:
455: objects.trimToSize();
456: array = new CMO[objects.size()];
457: objects.copyInto((Object[])array);
458:
1.7 tam 459: debug("debug :"+ new CMO_LIST(array));
1.1 tam 460: return new CMO_LIST(array);
461: }
462:
463: private String parse_symbol() throws IOException{
464: // symbname $B$rJV$9(B
465: String ret = "";
466: StreamTokenizer para;
467:
468: exceptTokenTypeInParse(TT_SingleTag);
469:
470: para = new StreamTokenizer(new StringReader(attribute));
471: para.resetSyntax();
472: para.wordChars('A','Z');
473: para.wordChars('a','z');
474: para.wordChars('0','9');
475: para.wordChars('\u00A0','\u00FF');
476: para.whitespaceChars('\u0000','\u0020');
477: para.quoteChar('"');
478: para.eolIsSignificant(false);
479: para.lowerCaseMode(true);
480: para.slashStarComments(false);
481: para.slashSlashComments(false);
482: para.ordinaryChar('=');
483:
484: if(para.nextToken() != StreamTokenizer.TT_WORD
485: || !para.sval.equalsIgnoreCase("OMS")){
486: parse_error("We expect '<OMS>', but '"+ para.sval +"'.");
487: }
488:
489: if(para.nextToken() != StreamTokenizer.TT_WORD){
490: parse_error("We expect 'name' or 'cd'.");
491: }
492: if(para.sval.equals("name")){
493: if(para.nextToken() != '='){
494: parse_error("We expect '='.");
495: }
496: if(para.nextToken() != '"'){
497: parse_error("We expect '\"'.");
498: }
499: ret = parse_symbname(para.sval);
500:
501: if(para.nextToken() != StreamTokenizer.TT_WORD
502: || !para.sval.equals("cd")){
503: parse_error("We expect 'cd'.");
504: }
505: if(para.nextToken() != '='){
506: parse_error("We expect '='.");
507: }
508: if(para.nextToken() != '"'){
509: parse_error("We expect '\"'.");
510: }
511: parse_cdname(para.sval);
512:
513: }else if(para.sval.equals("cd")){
514: if(para.nextToken() != '='){
515: parse_error("We expect '='.");
516: }
517: if(para.nextToken() != '"'){
518: parse_error("We expect '\"'.");
519: }
520: parse_cdname(para.sval);
521:
522: if(para.nextToken() != StreamTokenizer.TT_WORD
523: || !para.sval.equals("name")){
524: parse_error("We expect 'cd'.");
525: }
526: if(para.nextToken() != '='){
527: parse_error("We expect '='.");
528: }
529: if(para.nextToken() != '"'){
530: parse_error("We expect '\"'.");
531: }
532: ret = parse_symbname(para.sval);
533:
534: }else{
535: parse_error("We expect 'name' or 'cd'.");
536: }
537:
538: if(para.nextToken() != StreamTokenizer.TT_EOF){
539: parse_error("We expect '/>'.");
540: }
541:
542: return ret;
543: }
544:
545: private CMO parse_integer() throws IOException{
546: //Attribute integer = new Attribute(value);
547: String str;
548: int i=0;
549:
550: exceptTokenTypeInParse(TT_String);
551: str = attribute;
552:
553: if(str.charAt(i)=='-'){
554: i++;
555: }
556: if(str.length()>=i+2 && str.charAt(i)=='x'){ // for HEX
557: String strhex = str.substring(0,i) + str.substring(i+1);
558: for(i++;i<str.length();i++){
559: if("0123456789ABCDEF".indexOf((int)str.charAt(i)) == -1){
560: parse_error("We expect integer.");
561: }
562: }
563: // 10 $B?J?t$KJQ49(B
564: str = (new java.math.BigInteger(strhex,16)).toString();
565: }else if(str.length()>=i+1){ // for DEC
566: for(;i<str.length();i++){
567: if("0123456789".indexOf((int)str.charAt(i)) == -1){
568: parse_error("We expect integer.");
569: }
570: }
571: }else{
572: parse_error("We expect integer.");
573: }
574:
575: return new CMO_ZZ(str);
576: }
577:
578: private CMO parse_variable() throws IOException{
579: StreamTokenizer para;
580: CMO ret;
581:
582: exceptTokenTypeInParse(TT_SingleTag);
583:
584: para = new StreamTokenizer(new StringReader(attribute));
585: para.resetSyntax();
586: para.wordChars('A','Z');
587: para.wordChars('a','z');
588: para.wordChars('0','9');
589: para.wordChars('\u00A0','\u00FF');
590: para.whitespaceChars('\u0000','\u0020');
591: para.quoteChar('"');
592: para.eolIsSignificant(false);
593: para.lowerCaseMode(true);
594: para.slashStarComments(false);
595: para.slashSlashComments(false);
596: para.ordinaryChar('=');
597:
598: if(para.nextToken() != StreamTokenizer.TT_WORD
599: || !para.sval.equalsIgnoreCase("OMV")){
600: parse_error("We expect '<OMV>'.");
601: }
602:
603: if(para.nextToken() != StreamTokenizer.TT_WORD
604: || !para.sval.equals("name")){
605: parse_error("We expect 'name', but obtain '"+ para.sval +"'.");
606: }
607: if(para.nextToken() != '='){
608: parse_error("We expect '='.");
609: }
610: if(para.nextToken() != '"'){
611: parse_error("We expect '\"'.");
612: }
613: ret = new CMO_INDETERMINATE(parse_varname(para.sval));
614:
615: if(para.nextToken() != StreamTokenizer.TT_EOF){
616: parse_error("We expect '/>'.");
617: }
618:
619: return ret;
620: }
621:
622: private String parse_varname(String str){
623: String words = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
624: + "0123456789+='(),-./:?!#$%*;@[]^_`{|}";
625:
626: for(int i=0;i<str.length();i++){
627: if(words.indexOf((int)str.charAt(i))==-1){
628: parse_error("string \""+ str +"\" is not varname.");
629: }
630: }
631:
632: return str;
633: }
634:
635: private String parse_cdname(String str){
636: String alphabet = "abcdefghijklmnopqrstuvwxyz";
637: int i=0;
638:
639: if(alphabet.indexOf((int)str.charAt(i))==-1){
640: parse_error("cdname \""+ str +"\" must begin small alphabet.");
641: }
642: for(i++;i<str.length();i++){
643: if((alphabet + "0123456789_").indexOf((int)str.charAt(i))==-1){
644: parse_error("string \""+ str +"\" is not cdname.");
645: }
646: }
647:
648: return str;
649: }
650:
651: private String parse_symbname(String str) throws IOException{
652: String Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
653: int i=0;
654:
655: if(Alphabet.indexOf((int)str.charAt(i))==-1){
656: parse_error("symbname \""+ str +"\" must begin alphabet.");
657: }
658: for(i++;i<str.length();i++){
659: if((Alphabet + "0123456789_").indexOf((int)str.charAt(i))==-1){
660: parse_error("string \""+ str +"\" is not symbname.");
661: }
662: }
663:
664: return str;
665: }
666:
1.9 tam 667: private void parse_error(String mesg) throws NumberFormatException{
668: String ret;
669:
670: ret = mesg +"\n";
671: ret += "error occuered near :";
1.1 tam 672: try{
673: for(int i=0;i<10;i++){
1.9 tam 674: ret += (char)is.read();
1.1 tam 675: }
676: }catch(IOException e){}
1.9 tam 677: ret += "\n";
678:
679: throw new NumberFormatException(ret);
1.3 tam 680: }
681:
682: private void debug(String str){
683: if(debug){
684: System.err.println(str);
685: }
1.1 tam 686: }
687:
688: public static void main(String[] argv) throws IOException{
689: OM2OXM P = new OM2OXM();
690: OpenXM asir;
691: String host = "localhost";
692: int CtrlPort = 1200,StreamPort = 1300;
693:
694: for(int i=0;i<argv.length;i++){
695: if(argv[i].equals("-h")){
696: System.out.println("");
697: System.exit(0);
698: }else if(argv[i].equals("-host")){
699: host = argv[++i];
700: }else if(argv[i].equals("-data")){
701: StreamPort = Integer.valueOf(argv[++i]).intValue();
702: }else if(argv[i].equals("-control")){
703: CtrlPort = Integer.valueOf(argv[++i]).intValue();
704: }else{
705: System.err.println("unknown option :"+ argv[i]);
706: System.exit(1);
707: }
708: }
709:
710: try{
711: asir = new OpenXM(host,CtrlPort,StreamPort);
712: asir.sendSM(new SM(SM.SM_mathcap));
713: }catch(UnknownHostException e){
714: System.err.println("host unknown.");
715: System.err.println(e.getMessage());
716: return;
717: }catch(IOException e){
718: System.err.println("connection failed.");
719: System.err.println("IOException occuer !!");
720: System.err.println(e.getMessage());
721: return;
722: }
723:
724: P.asir = asir;
725: new Thread(P).start();
726: System.out.println("start");
727:
728: try{
729: //P.value = new Attribute(System.in);
730:
731: //$B%5!<%PB&$+$iAw?.$5$l$?J8;zNs$r<u?.$7$^$9!#(B
732: while(true){
1.9 tam 733: try{
734: CMO obj = P.parse(System.in);
735: asir.send(obj);
736: asir.sendSM(new SM(SM.SM_popCMO));
737: }catch(NumberFormatException e){
738: System.err.println(e.getMessage());
739: }
1.1 tam 740: }
741:
742: }catch(IOException e){
743: e.printStackTrace();
1.9 tam 744: }finally{
745: System.out.println("breaking...");
1.1 tam 746: }
747: }
748: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>