version 1.2, 1999/11/09 11:43:35 |
version 1.12, 2003/11/19 01:02:40 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/kxx/oxserver00.c,v 1.11 2003/11/18 11:08:27 takayama Exp $ */ |
/* nullserver01 */ |
/* nullserver01 */ |
#include <stdio.h> |
#include <stdio.h> |
#include <sys/types.h> |
#include <sys/types.h> |
Line 20 extern int SerialOX; /* Serial number of the packets |
|
Line 20 extern int SerialOX; /* Serial number of the packets |
|
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? */ |
|
|
|
#if defined(__CYGWIN__) |
|
sigjmp_buf EnvOfChildServer; |
|
#else |
jmp_buf EnvOfChildServer; |
jmp_buf EnvOfChildServer; |
|
#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 33 main(int argc, char *argv[]) { |
|
Line 38 main(int argc, char *argv[]) { |
|
char *tigers[] = {"callsm1.sm1","tigers.sm1"}; |
char *tigers[] = {"callsm1.sm1","tigers.sm1"}; |
char *basicCD[] = {"basicCD.sm1"}; |
char *basicCD[] = {"basicCD.sm1"}; |
/* If you change the above, you need to change the argc of Sm1_start below. |
/* If you change the above, you need to change the argc of Sm1_start below. |
*/ |
*/ |
|
|
if (argc > 1) { |
if (argc > 1) { |
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{ |
}else{ |
fprintf(stderr,"Unknown option. Possible options are -monitor\n"); |
fprintf(stderr,"Unknown option. Possible options are -monitor\n"); |
} |
} |
Line 59 main(int argc, char *argv[]) { |
|
Line 67 main(int argc, char *argv[]) { |
|
Sm1_start(0, NULL, "ox_sm1"); |
Sm1_start(0, NULL, "ox_sm1"); |
} |
} |
|
|
nullserver(3); |
nullserver(3,4); |
} |
} |
|
|
static char *getSuffix(char *s) { |
static char *getSuffix(char *s) { |
/* getSuffix("ox_sm1_forAsir") returns "forAsir" */ |
/* getSuffix("ox_sm1_forAsir") returns "forAsir" */ |
|
/* getSuffix("ox_sm1_forAsir.exe") returns "forAsir" */ |
/* getSuffix("ox_sm1_gnuplot") returns "gnuplot" */ |
/* getSuffix("ox_sm1_gnuplot") returns "gnuplot" */ |
int n,i,k; |
int n,i,k; |
n = strlen(s); |
n = strlen(s); |
|
if (n > 5 && (strcmp(".exe",&(s[n-4]))==0 || strcmp(".EXE",&(s[n-4]))==0)) { |
|
s[n-4] = '\0'; |
|
} |
for (i=n-1; i>=0; i--) { |
for (i=n-1; i>=0; i--) { |
if (s[i] == '_') { |
if (s[i] == '_') { |
return( s+i+1 ); |
return( s+i+1 ); |
Line 74 static char *getSuffix(char *s) { |
|
Line 86 static char *getSuffix(char *s) { |
|
} |
} |
return(s); |
return(s); |
} |
} |
nullserver(int fdStream) { |
nullserver(int fdStreamIn,int fdStreamOut) { |
int mtag; |
int mtag; |
int message = 1; |
int message = 1; |
ox_stream ostream; |
ox_stream ostreamIn; |
|
ox_stream ostreamOut; |
char sreason[1024]; |
char sreason[1024]; |
extern void controlResetHandler(); |
extern void controlResetHandler(); |
|
#if defined(__CYGWIN__) |
|
extern sigjmp_buf EnvOfStackMachine; |
|
#else |
extern jmp_buf EnvOfStackMachine; |
extern jmp_buf EnvOfStackMachine; |
|
#endif |
int engineByteOrder; |
int engineByteOrder; |
|
|
engineByteOrder = oxTellMyByteOrder(fdStream); |
/* for debug, use -monitor |
|
PacketMonitor = 1; */ |
|
|
|
fflush(NULL); |
|
engineByteOrder = oxTellMyByteOrder(fdStreamOut,fdStreamIn); |
/* Set the network byte order. */ |
/* Set the network byte order. */ |
fprintf(stderr,"engineByteOrder=%x\n",engineByteOrder); |
fprintf(stderr,"engineByteOrder=%x\n",engineByteOrder); |
|
|
if (fdStream != -1) { |
if (fdStreamIn != -1) { |
ostream = fp2open(fdStream); |
ostreamIn = fp2open(fdStreamIn); |
if (ostream == NULL) { |
if (ostreamIn == NULL) { |
fprintf(stderr,"fp2open(fdStream) failed.\n"); |
fprintf(stderr,"fp2open(fdStreamIn) failed.\n"); |
fdStream = -1; |
fdStreamIn = -1; |
} |
} |
if (PacketMonitor) fp2watch(ostream,stdout); |
if (PacketMonitor) fp2watch(ostreamIn,stdout); |
} |
} |
|
if (fdStreamOut != -1) { |
|
ostreamOut = fp2open(fdStreamOut); |
|
if (ostreamOut == NULL) { |
|
fprintf(stderr,"fp2open(fdStreamOut) failed.\n"); |
|
fdStreamOut = -1; |
|
} |
|
if (PacketMonitor) fp2watch(ostreamOut,stdout); |
|
} |
|
|
aaa : ; |
aaa : ; |
|
#if defined(__CYGWIN__) |
|
if (sigsetjmp(EnvOfChildServer,1)) { |
|
#else |
if (setjmp(EnvOfChildServer)) { |
if (setjmp(EnvOfChildServer)) { |
|
#endif |
fprintf(stderr,"childServerMain: jump here.\n"); |
fprintf(stderr,"childServerMain: jump here.\n"); |
if (OxInterruptFlag == 0) { |
if (OxInterruptFlag == 0) { |
fprintf(stderr," ?! \n"); fflush(NULL); |
fprintf(stderr," ?! \n"); fflush(NULL); |
} |
} |
|
KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ |
|
KSexecuteString(" (Computation is interrupted.) "); |
signal(SIGUSR1,controlResetHandler); goto aaa; |
signal(SIGUSR1,controlResetHandler); goto aaa; |
} else { |
} else { |
if (JmpMessage) fprintf(stderr,"Set EnvOfChildServer.\n"); |
if (JmpMessage) fprintf(stderr,"Set EnvOfChildServer.\n"); |
signal(SIGUSR1,controlResetHandler); |
signal(SIGUSR1,controlResetHandler); |
} |
} |
|
#if defined(__CYGWIN__) |
|
if (sigsetjmp(EnvOfStackMachine,1)) { |
|
#else |
if (setjmp(EnvOfStackMachine)) { |
if (setjmp(EnvOfStackMachine)) { |
fprintf(stderr,"childServerMain: jump here by EnvOfStackMachine.\n"); |
#endif |
|
fprintf(stderr,"childServerMain: jump here by EnvOfStackMachine or timeout.\n"); |
if (OxInterruptFlag == 0) { |
if (OxInterruptFlag == 0) { |
fprintf(stderr," ?! \n"); fflush(NULL); |
fprintf(stderr," ?! \n"); fflush(NULL); |
} |
} |
/* In case of error in the stack machine, pop the error info |
/* In case of error in the stack machine, pop the error info |
and send the error packet. */ |
and send the error packet. */ |
/* oxSendOXheader(ostream,OX_DATA,SerialOX++); |
/* oxSendOXheader(ostream,OX_DATA,SerialOX++); |
oxSendCmoError(ostream); |
oxSendCmoError(ostream); |
oxSendOXheader(ostream,OX_DATA,SerialOX++); |
oxSendOXheader(ostream,OX_DATA,SerialOX++); |
sprintf(sreason,"Jump here by sm1 error."); |
sprintf(sreason,"Jump here by sm1 error."); |
oxSendCmoError2(ostream,sreason); |
oxSendCmoError2(ostream,sreason); |
*/ |
*/ |
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. */ |
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 131 nullserver(int fdStream) { |
|
Line 171 nullserver(int fdStream) { |
|
} |
} |
|
|
while (1) { |
while (1) { |
message = OXprintMessage; |
message = OXprintMessage; |
if (OxInterruptFlag) { |
if (OxInterruptFlag) { |
OxCritical = 1; |
OxCritical = 1; |
if (message) {fprintf(stderr,"Clearing the read buffer.\n");fflush(NULL); } |
if (message) {fprintf(stderr,"Clearing the read buffer.\n");fflush(NULL); } |
fp2clearReadBuf(ostream); /* clear the read buffer */ |
fp2clearReadBuf(ostreamIn); /* clear the read buffer */ |
if (message) {fprintf(stderr,"Throwing OX_SYNC_BALL\n"); fflush(NULL);} |
if (message) {fprintf(stderr,"Throwing OX_SYNC_BALL\n"); fflush(NULL);} |
oxSendSyncBall(ostream); |
oxSendSyncBall(ostreamOut); |
if (message) {fprintf(stderr,"Waiting for OX_SYNC_BALL\n");fflush(NULL);} |
if (message) {fprintf(stderr,"Waiting for OX_SYNC_BALL\n");fflush(NULL);} |
oxWaitSyncBall(ostream); |
oxWaitSyncBall(ostreamIn); |
if (message) {fprintf(stderr,"Done changing OX_SYNC_BALL\n"); fflush(NULL);} |
if (message) {fprintf(stderr,"Done changing OX_SYNC_BALL\n"); fflush(NULL);} |
OxInterruptFlag = 0; |
OxInterruptFlag = 0; |
OxCritical = 0; |
OxCritical = 0; |
goto aaa ; |
goto aaa ; |
} |
} |
OxCritical = 0; |
OxCritical = 0; |
if (fp2select(ostream,-1)) { |
if (fp2select(ostreamIn,-1)) { |
/* If there is an data in the ostream, then read data in the buffer and |
/* If there is an data in the ostream, then read data in the buffer and |
read data in the communication stream. */ |
read data in the communication stream. */ |
OxCritical = 1; |
OxCritical = 1; |
Line 155 nullserver(int fdStream) { |
|
Line 195 nullserver(int fdStream) { |
|
/* This part is never reached. */ |
/* This part is never reached. */ |
} |
} |
OxCritical = 1; |
OxCritical = 1; |
mtag = oxGetOXheader(ostream,&SerialCurrent); /* get the message_tag */ |
mtag = oxGetOXheader(ostreamIn,&SerialCurrent); /* get the message_tag */ |
if (message) { |
if (message) { |
fprintf(stderr,"\nmtag is %d (serial=%d) : ",mtag,SerialCurrent); |
fprintf(stderr,"\nmtag is %d (serial=%d) : ",mtag,SerialCurrent); |
switch(mtag) { |
switch(mtag) { |
Line 163 nullserver(int fdStream) { |
|
Line 203 nullserver(int fdStream) { |
|
case OX_DATA: fprintf(stderr," OX_DATA \n"); break; |
case OX_DATA: fprintf(stderr," OX_DATA \n"); break; |
case OX_SYNC_BALL: fprintf(stderr," OX_SYNC_BALL \n"); break; |
case OX_SYNC_BALL: fprintf(stderr," OX_SYNC_BALL \n"); break; |
case -1: fprintf(stderr," End of file. Exiting the server child.\n"); |
case -1: fprintf(stderr," End of file. Exiting the server child.\n"); |
exit(); break; |
exit(0); break; |
default: fprintf(stderr," ?! \n"); break; |
default: fprintf(stderr," ?! \n"); break; |
} |
} |
} |
} |
/*sleep(2); /* for dubug OX_SYNC_BALL */ |
/*sleep(2); /* for dubug OX_SYNC_BALL */ |
switch(mtag) { |
switch(mtag) { |
case OX_COMMAND: |
case OX_COMMAND: |
nullserverCommand(ostream); |
nullserverCommand(ostreamIn,ostreamOut); |
goto aaa ; /* We always reset the jump vector. cf. memo1.txt 1998 2/13*/ |
goto aaa ; /* We always reset the jump vector. cf. memo1.txt 1998 2/13*/ |
break; |
break; |
case OX_DATA: |
case OX_DATA: |
Sm1_pushCMO(ostream); |
Sm1_pushCMO(ostreamIn); |
break; |
break; |
case OX_SYNC_BALL: |
case OX_SYNC_BALL: |
/* if (OxInterruptFlag) think about it later. */ |
/* if (OxInterruptFlag) think about it later. */ |
Line 186 nullserver(int fdStream) { |
|
Line 226 nullserver(int fdStream) { |
|
} |
} |
} |
} |
|
|
nullserverCommand(ox_stream ostream) { |
nullserverCommand(ox_stream ostreamIn,ox_stream ostreamOut) { |
int id; |
int id; |
int mtag; |
int mtag; |
int n; |
int n; |
Line 198 nullserverCommand(ox_stream ostream) { |
|
Line 238 nullserverCommand(ox_stream ostream) { |
|
char *emsg; |
char *emsg; |
extern void controlResetHandler(); |
extern void controlResetHandler(); |
|
|
message = OXprintMessage; |
message = OXprintMessage; |
/* message_body */ |
/* message_body */ |
id = oxGetInt32(ostream); /* 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"); |
if (message) fprintf(stderr," mathcap\n"); |
Line 210 nullserverCommand(ox_stream ostream) { |
|
Line 250 nullserverCommand(ox_stream ostream) { |
|
break; |
break; |
case SM_setMathCap: |
case SM_setMathCap: |
if (message) fprintf(stderr," setMathCap\n"); |
if (message) fprintf(stderr," setMathCap\n"); |
Sm1_setMathCap(ostream); |
Sm1_setMathCap(ostreamOut); |
break; |
break; |
case SM_pops: |
case SM_pops: |
if (message) fprintf(stderr," pops \n"); |
if (message) fprintf(stderr," pops \n"); |
Line 224 nullserverCommand(ox_stream ostream) { |
|
Line 264 nullserverCommand(ox_stream ostream) { |
|
if (message) fprintf(stderr," dupErrors \n"); |
if (message) fprintf(stderr," dupErrors \n"); |
Sm1_dupErrors(); |
Sm1_dupErrors(); |
break; |
break; |
|
case SM_pushCMOtag: |
|
if (message) fprintf(stderr," pushCMOtag \n"); |
|
Sm1_pushCMOtag(SerialCurrent); |
|
break; |
case SM_setName: |
case SM_setName: |
if (message) fprintf(stderr," setName \n"); |
if (message) fprintf(stderr," setName \n"); |
iresult = Sm1_setName(); |
iresult = Sm1_setName(); |
Line 262 nullserverCommand(ox_stream ostream) { |
|
Line 306 nullserverCommand(ox_stream ostream) { |
|
break; |
break; |
case SM_popCMO: |
case SM_popCMO: |
if (message) fprintf(stderr,"popCMO. Start to sending data.\n",n); |
if (message) fprintf(stderr,"popCMO. Start to sending data.\n",n); |
oxSendOXheader(ostream,OX_DATA,SerialOX++); |
oxSendOXheader(ostreamOut,OX_DATA,SerialOX++); |
n=Sm1_popCMO(ostream,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); |
if (message) fprintf(stderr,"popString. send data from the stack.\n",n); |
oxSendOXheader(ostream,OX_DATA,SerialOX++); |
oxSendOXheader(ostreamOut,OX_DATA,SerialOX++); |
oxSendCmoString(ostream,Sm1_popString()); |
oxSendCmoString(ostreamOut,Sm1_popString()); |
if (message) fprintf(stderr,"Done.\n"); |
if (message) fprintf(stderr,"Done.\n"); |
break; |
break; |
case SM_shutdown: |
case SM_shutdown: |
|
fprintf(stderr,"Shutting down the engine.\n"); |
|
exit(0); |
|
break; |
case SM_beginBlock: |
case SM_beginBlock: |
case SM_endBlock: |
case SM_endBlock: |
fprintf(stderr,"This command has not yet been implemented.\n"); |
fprintf(stderr,"This command has not yet been implemented.\n"); |
Line 297 nullserver_simplest(int fd) { |
|
Line 344 nullserver_simplest(int fd) { |
|
|
|
|
|
void controlResetHandler(sig) |
void controlResetHandler(sig) |
int sig; |
int sig; |
{ |
{ |
signal(sig,SIG_IGN); |
signal(sig,SIG_IGN); |
|
cancelAlarm(); |
fprintf(stderr,"From controlResetHandler. OxCritical = %d\n",OxCritical); |
fprintf(stderr,"From controlResetHandler. OxCritical = %d\n",OxCritical); |
OxInterruptFlag = 1; |
OxInterruptFlag = 1; |
if (OxCritical) { |
if (OxCritical) { |
return; |
return; |
}else{ |
}else{ |
|
#if defined(__CYGWIN__) |
|
siglongjmp(EnvOfChildServer,2); /* returns 2 for ctrl-C */ |
|
#else |
longjmp(EnvOfChildServer,2); /* returns 2 for ctrl-C */ |
longjmp(EnvOfChildServer,2); /* returns 2 for ctrl-C */ |
|
#endif |
} |
} |
} |
} |
|
|