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