version 1.11, 2003/11/18 11:08:27 |
version 1.17, 2013/11/06 06:23:24 |
|
|
/* $OpenXM: OpenXM/src/kxx/oxserver00.c,v 1.10 2003/08/22 16:08:23 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/kxx/oxserver00.c,v 1.16 2004/09/17 02:42:58 takayama Exp $ */ |
/* nullserver01 */ |
/* nullserver01 */ |
#include <stdio.h> |
#include <stdio.h> |
#include <sys/types.h> |
#include <sys/types.h> |
|
|
int OxCritical = 0; |
int OxCritical = 0; |
int OxInterruptFlag = 0; |
int OxInterruptFlag = 0; |
int PacketMonitor = 0; |
int PacketMonitor = 0; |
|
int NoExecution = 0; |
|
|
extern int SerialOX; /* Serial number of the packets sent. */ |
extern int SerialOX; /* Serial number of the packets sent. */ |
extern int SerialCurrent; /* Current Serial number of the recieved packet. */ |
extern int SerialCurrent; /* Current Serial number of the recieved packet. */ |
extern int OXprintMessage; /* print oxmessages? */ |
extern int OXprintMessage; /* print oxmessages? */ |
|
extern int Calling_ctrlC_hook; |
|
extern int RestrictedMode, RestrictedMode_saved; |
|
|
#if defined(__CYGWIN__) |
#if defined(__CYGWIN__) |
sigjmp_buf EnvOfChildServer; |
sigjmp_buf EnvOfChildServer; |
Line 27 jmp_buf EnvOfChildServer; |
|
Line 30 jmp_buf EnvOfChildServer; |
|
#endif |
#endif |
|
|
int JmpMessage = 0; |
int JmpMessage = 0; |
|
extern int Lisplike; |
|
|
static char *getSuffix(char *s); |
static char *getSuffix(char *s); |
main(int argc, char *argv[]) { |
main(int argc, char *argv[]) { |
Line 43 main(int argc, char *argv[]) { |
|
Line 47 main(int argc, char *argv[]) { |
|
if (strcmp(argv[1],"-monitor")==0) { |
if (strcmp(argv[1],"-monitor")==0) { |
fprintf(stderr,"Taking the packet monitor.\n"); |
fprintf(stderr,"Taking the packet monitor.\n"); |
PacketMonitor = 1; |
PacketMonitor = 1; |
|
}else if (strcmp(argv[1],"-lispLike")==0) { |
|
fprintf(stderr,"Output lispLike expression.\n"); |
|
Lisplike = 1; |
|
}else if (strcmp(argv[1],"-noexec")==0) { |
|
fprintf(stderr,"I do not execute commands.\n"); |
|
NoExecution = 1; |
}else{ |
}else{ |
fprintf(stderr,"Unknown option. Possible options are -monitor\n"); |
fprintf(stderr,"Unknown option. Possible options are -monitor\n"); |
} |
} |
Line 96 nullserver(int fdStreamIn,int fdStreamOut) { |
|
Line 106 nullserver(int fdStreamIn,int fdStreamOut) { |
|
#endif |
#endif |
int engineByteOrder; |
int engineByteOrder; |
|
|
/* for debug */ |
/* for debug, use -monitor |
PacketMonitor = 1; |
PacketMonitor = 1; */ |
|
|
fflush(NULL); |
fflush(NULL); |
engineByteOrder = oxTellMyByteOrder(fdStreamOut,fdStreamIn); |
engineByteOrder = oxTellMyByteOrder(fdStreamOut,fdStreamIn); |
Line 131 nullserver(int fdStreamIn,int fdStreamOut) { |
|
Line 141 nullserver(int fdStreamIn,int fdStreamOut) { |
|
if (OxInterruptFlag == 0) { |
if (OxInterruptFlag == 0) { |
fprintf(stderr," ?! \n"); fflush(NULL); |
fprintf(stderr," ?! \n"); fflush(NULL); |
} |
} |
KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ |
if (!Calling_ctrlC_hook) { |
|
Calling_ctrlC_hook = 1; RestrictedMode = 0; |
|
KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ |
|
RestrictedMode = RestrictedMode_saved; |
|
} |
|
Calling_ctrlC_hook = 0; |
KSexecuteString(" (Computation is interrupted.) "); |
KSexecuteString(" (Computation is interrupted.) "); |
signal(SIGUSR1,controlResetHandler); goto aaa; |
signal(SIGUSR1,controlResetHandler); goto aaa; |
} else { |
} else { |
Line 157 nullserver(int fdStreamIn,int fdStreamOut) { |
|
Line 172 nullserver(int fdStreamIn,int fdStreamOut) { |
|
*/ |
*/ |
Sm1_pushError2(SerialCurrent,-1,"Global jump by sm1 error"); |
Sm1_pushError2(SerialCurrent,-1,"Global jump by sm1 error"); |
|
|
KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ |
if (!Calling_ctrlC_hook) { |
|
Calling_ctrlC_hook = 1; RestrictedMode = 0; |
|
KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ |
|
RestrictedMode = RestrictedMode_saved; |
|
} |
|
Calling_ctrlC_hook = 0; |
signal(SIGUSR1,controlResetHandler); goto aaa ; |
signal(SIGUSR1,controlResetHandler); goto aaa ; |
} else { |
} else { |
if (JmpMessage) fprintf(stderr,"Set EnvOfStackMachine.\n"); |
if (JmpMessage) fprintf(stderr,"Set EnvOfStackMachine.\n"); |
Line 237 nullserverCommand(ox_stream ostreamIn,ox_stream ostrea |
|
Line 257 nullserverCommand(ox_stream ostreamIn,ox_stream ostrea |
|
message = OXprintMessage; |
message = OXprintMessage; |
/* message_body */ |
/* message_body */ |
id = oxGetInt32(ostreamIn); /* get the function_id */ |
id = oxGetInt32(ostreamIn); /* get the function_id */ |
if (message) {fprintf(stderr,"\nfunction_id is %d\n",id);} |
if (message) {fprintf(stderr,"\nfunction_id is %d; %s\n",id,oxFIDtoStr(id));} |
switch( id ) { |
switch( id ) { |
case SM_mathcap: |
case SM_mathcap: |
if (message) fprintf(stderr," mathcap\n"); |
|
mathresult = (struct mathCap *)Sm1_mathcap(); |
mathresult = (struct mathCap *)Sm1_mathcap(); |
oxPushMathCap(mathresult); |
oxPushMathCap(mathresult); |
break; |
break; |
case SM_setMathCap: |
case SM_setMathCap: |
if (message) fprintf(stderr," setMathCap\n"); |
|
Sm1_setMathCap(ostreamOut); |
Sm1_setMathCap(ostreamOut); |
break; |
break; |
case SM_pops: |
case SM_pops: |
if (message) fprintf(stderr," pops \n"); |
|
Sm1_pops(); |
Sm1_pops(); |
break; |
break; |
case SM_getsp: |
case SM_getsp: |
if (message) fprintf(stderr," getsp \n"); |
|
Sm1_getsp(); |
Sm1_getsp(); |
break; |
break; |
case SM_dupErrors: |
case SM_dupErrors: |
if (message) fprintf(stderr," dupErrors \n"); |
|
Sm1_dupErrors(); |
Sm1_dupErrors(); |
break; |
break; |
case SM_pushCMOtag: |
case SM_pushCMOtag: |
if (message) fprintf(stderr," pushCMOtag \n"); |
|
Sm1_pushCMOtag(SerialCurrent); |
Sm1_pushCMOtag(SerialCurrent); |
break; |
break; |
case SM_setName: |
case SM_setName: |
if (message) fprintf(stderr," setName \n"); |
|
iresult = Sm1_setName(); |
iresult = Sm1_setName(); |
if (iresult < 0) { |
if (iresult < 0) { |
Sm1_pushError2(SerialCurrent,-1,"setName"); |
Sm1_pushError2(SerialCurrent,-1,"setName"); |
} |
} |
break; |
break; |
case SM_evalName: |
case SM_evalName: |
if (message) fprintf(stderr," evalName \n"); |
|
iresult = Sm1_evalName(); |
iresult = Sm1_evalName(); |
if (iresult < 0) { |
if (iresult < 0) { |
Sm1_pushError2(SerialCurrent,-1,"evalName"); |
Sm1_pushError2(SerialCurrent,-1,"evalName"); |
} |
} |
break; |
break; |
case SM_executeStringByLocalParser: |
case SM_executeStringByLocalParser: |
if (message) fprintf(stderr," executeStringByLocalParser\n"); |
|
OxCritical = 0; |
OxCritical = 0; |
iresult = Sm1_executeStringByLocalParser(); |
if (NoExecution) { |
|
iresult = 0; |
|
}else{ |
|
iresult = Sm1_executeStringByLocalParser(); |
|
} |
OxCritical = 1; signal(SIGUSR1,controlResetHandler); |
OxCritical = 1; signal(SIGUSR1,controlResetHandler); |
if (iresult < 0) { |
if (iresult < 0) { |
emsg = Sm1_popErrorMessage("executeString: "); |
emsg = Sm1_popErrorMessage("executeString: "); |
Line 290 nullserverCommand(ox_stream ostreamIn,ox_stream ostrea |
|
Line 305 nullserverCommand(ox_stream ostreamIn,ox_stream ostrea |
|
} |
} |
break; |
break; |
case SM_executeFunction: |
case SM_executeFunction: |
if (message) fprintf(stderr," executeFunction\n"); |
|
OxCritical = 0; |
OxCritical = 0; |
iresult = Sm1_executeStringByLocalParser(); |
if (NoExecution) { |
|
iresult = 0; |
|
}else{ |
|
iresult = Sm1_executeStringByLocalParser(); |
|
} |
OxCritical = 1; signal(SIGUSR1,controlResetHandler); |
OxCritical = 1; signal(SIGUSR1,controlResetHandler); |
if (iresult < 0) { |
if (iresult < 0) { |
emsg = Sm1_popErrorMessage("executeFunction: "); |
emsg = Sm1_popErrorMessage("executeFunction: "); |
Line 300 nullserverCommand(ox_stream ostreamIn,ox_stream ostrea |
|
Line 318 nullserverCommand(ox_stream ostreamIn,ox_stream ostrea |
|
return(-1); |
return(-1); |
} |
} |
break; |
break; |
|
case SM_executeFunctionWithOptionalArgument: |
|
OxCritical = 0; |
|
if (NoExecution) { |
|
iresult = 0; |
|
}else{ |
|
iresult = Sm1_executeStringByLocalParser(); |
|
} |
|
OxCritical = 1; signal(SIGUSR1,controlResetHandler); |
|
if (iresult < 0) { |
|
emsg = Sm1_popErrorMessage("executeFunctionWithOptionalArgument: "); |
|
Sm1_pushError2(SerialCurrent,-1,emsg); |
|
return(-1); |
|
} |
|
break; |
case SM_popCMO: |
case SM_popCMO: |
if (message) fprintf(stderr,"popCMO. Start to sending data.\n",n); |
|
oxSendOXheader(ostreamOut,OX_DATA,SerialOX++); |
oxSendOXheader(ostreamOut,OX_DATA,SerialOX++); |
n=Sm1_popCMO(ostreamOut,SerialCurrent); |
n=Sm1_popCMO(ostreamOut,SerialCurrent); |
if (message) fprintf(stderr,"Done.\n"); |
if (message) fprintf(stderr,"Done.\n"); |
break; |
break; |
case SM_popString: |
case SM_popString: |
if (message) fprintf(stderr,"popString. send data from the stack.\n",n); |
|
oxSendOXheader(ostreamOut,OX_DATA,SerialOX++); |
oxSendOXheader(ostreamOut,OX_DATA,SerialOX++); |
oxSendCmoString(ostreamOut,Sm1_popString()); |
oxSendCmoString(ostreamOut,Sm1_popString()); |
if (message) fprintf(stderr,"Done.\n"); |
if (message) fprintf(stderr,"Done.\n"); |
Line 334 nullserver_simplest(int fd) { |
|
Line 364 nullserver_simplest(int fd) { |
|
int c; |
int c; |
while(1) { |
while(1) { |
c = readOneByte(fd); |
c = readOneByte(fd); |
if (c == '@') { return; } |
if (c == '@') { return 0; } |
} |
} |
} |
} |
|
|
Line 349 void controlResetHandler(sig) |
|
Line 379 void controlResetHandler(sig) |
|
if (OxCritical) { |
if (OxCritical) { |
return; |
return; |
}else{ |
}else{ |
|
(void) traceShowStack(); traceClearStack(); |
#if defined(__CYGWIN__) |
#if defined(__CYGWIN__) |
siglongjmp(EnvOfChildServer,2); /* returns 2 for ctrl-C */ |
siglongjmp(EnvOfChildServer,2); /* returns 2 for ctrl-C */ |
#else |
#else |