=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/ext.c,v retrieving revision 1.8 retrieving revision 1.48 diff -u -p -r1.8 -r1.48 --- OpenXM/src/kan96xx/Kan/ext.c 2001/08/21 14:12:46 1.8 +++ OpenXM/src/kan96xx/Kan/ext.c 2016/03/31 05:27:34 1.48 @@ -1,28 +1,42 @@ -/* $OpenXM: OpenXM/src/kan96xx/Kan/ext.c,v 1.7 2001/08/10 13:48:38 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/Kan/ext.c,v 1.47 2016/03/31 03:22:54 takayama Exp $ */ #include +#include #include #include #include #include #include #include +#include +#include #include "datatype.h" #include "stackm.h" #include "extern.h" #include "extern2.h" #include #include "plugin.h" +#include "kclass.h" +#include +#include +#include +#include "ox_pathfinder.h" +#include "mysig.h" +extern int Quiet; +extern char **environ; +extern char *MsgSourceTrace; + #define MYCP_SIZE 100 static int Mychildren[MYCP_SIZE]; static int Mycp = 0; +static int Verbose_mywait = 0; static void mywait() { int status; int pid; int i,j; - signal(SIGCHLD,SIG_IGN); + /* mysignal(SIGCHLD,SIG_IGN); */ pid = wait(&status); - fprintf(stderr,"Child process %d is exiting.\n",pid); + if ((!Quiet) && (Verbose_mywait)) fprintf(stderr,"Child process %d is exiting.\n",pid); for (i=0; i 0) Mycp--; } } - signal(SIGCHLD,mywait); + mysignal(SIGCHLD,mywait); } #define SIZE_OF_ENVSTACK 5 -static jmp_buf EnvStack[SIZE_OF_ENVSTACK]; +#if defined(__CYGWIN__) +#define JMP_BUF sigjmp_buf +#else +#define JMP_BUF jmp_buf +#endif +static JMP_BUF EnvStack[SIZE_OF_ENVSTACK]; static int Envp = 0; -static void pushEnv(jmp_buf jb) { +static void pushEnv(JMP_BUF jb) { if (Envp < SIZE_OF_ENVSTACK) { *(EnvStack[Envp]) = *jb; Envp++; @@ -46,7 +65,7 @@ static void pushEnv(jmp_buf jb) { exit(2); } } -static void popEnv(jmp_buf jbp) { +static void popEnv(JMP_BUF jbp) { if (Envp <= 0) { fprintf(stderr,"Underflow of EnvStack.\n"); exit(3); @@ -74,22 +93,31 @@ static char *ext_generateUniqueFileName(char *s) return(NULL); } +static struct object oregexec(struct object oregex,struct object ostrArray,struct object oflag); + struct object Kextension(struct object obj) { char *key; int size; - struct object keyo; + struct object keyo = OINIT; struct object rob = NullObject; - struct object obj1,obj2,obj3,obj4; - int m,i,pid; + struct object obj1 = OINIT; + struct object obj2 = OINIT; + struct object obj3 = OINIT; + struct object obj4 = OINIT; + int m,i,pid, uid; int argListc, fdListc; char *abc; char *abc2; extern struct context *CurrentContextp; + struct timeval tm; +#if (__CYGWIN__) + extern sigjmp_buf EnvOfStackMachine; +#else extern jmp_buf EnvOfStackMachine; +#endif extern void ctrlC(); extern int SigIgn; - extern errno; extern int DebugCMO; extern int OXprintMessage; struct stat buf; @@ -97,6 +125,8 @@ struct object Kextension(struct object obj) FILE *fp; void (*oldsig)(); extern SecureMode; + extern char *UD_str; + extern int UD_attr; if (obj.tag != Sarray) errorKan1("%s\n","Kextension(): The argument must be an array."); size = getoaSize(obj); @@ -114,10 +144,10 @@ struct object Kextension(struct object obj) pushEnv(EnvOfStackMachine); m = KSexecuteString(obj1.lc.str); /* This is critical area. If you catch ctrl-c here, program crashes. */ - oldsig = signal(SIGINT,SIG_IGN); + oldsig = mysignal(SIGINT,SIG_IGN); popEnv(EnvOfStackMachine); /* OK! We passed the critical area. */ - signal(SIGINT,oldsig); + mysignal(SIGINT,oldsig); rob = KpoInteger(m); }else if (strcmp(key,"getpid") == 0) { rob = KpoInteger( (int) getpid() ); @@ -130,10 +160,17 @@ struct object Kextension(struct object obj) obj1 = getoa(obj,1); if (obj1.tag != Sinteger) errorKan1("%s\n","[(chattrs) num] extension."); m = KopInteger(obj1); - if (!( m == 0 || m == PROTECT || m == ABSOLUTE_PROTECT)) - errorKan1("%s\n","The number must be 0, 1 or 2."); + /* if (!( m == 0 || m == PROTECT || m == ABSOLUTE_PROTECT || m == ATTR_INFIX)) + errorKan1("%s\n","The number must be 0, 1 or 2.");*/ putUserDictionary2((char *)NULL,0,0,m | SET_ATTR_FOR_ALL_WORDS, CurrentContextp->userDictionary); + }else if (strcmp(key,"or_attrs")==0) { + if (size != 2) errorKan1("%s\n","[(or_attrs) num] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sinteger) errorKan1("%s\n","[(or_attrs) num] extension."); + m = KopInteger(obj1); + putUserDictionary2((char *)NULL,0,0,m | OR_ATTR_FOR_ALL_WORDS, + CurrentContextp->userDictionary); }else if (strcmp(key,"keywords")==0) { if (size != 1) errorKan1("%s\n","[(keywords)] extension."); rob = showSystemDictionary(1); @@ -144,6 +181,10 @@ struct object Kextension(struct object obj) else { system(KopString(getoa(obj,1))); exit(0); } */ + }else if (strcmp(key,"date")==0) { + if (size != 1) errorKan1("%s\n","[(date)] extension."); + gettimeofday(&tm,NULL); + rob = KpoString(ctime((time_t *)&(tm.tv_sec))); }else if (strcmp(key,"defaultPolyRing")==0) { if (size != 2) errorKan1("%s\n","[(defaultPolyRing) n] extension."); rob = KdefaultPolyRing(getoa(obj,1)); @@ -152,7 +193,17 @@ struct object Kextension(struct object obj) obj1 = getoa(obj,1); if (obj1.tag != Sdollar) errorKan1("%s\n","[(getenv) envstr] extension"); abc = getenv(KopString(obj1)); +#if defined(__CYGWIN__) if (abc == NULL) { + abc2 = (char *)sGC_malloc(sizeof(char)*(strlen(KopString(obj1))+2)); + strcpy(abc2,KopString(obj1)); + for (i=0; i= MYCP_SIZE-1) { @@ -235,7 +295,7 @@ struct object Kextension(struct object obj) sleep(5); fprintf(stderr,">>>\n"); } - execv(argv[0],argv); + execve(argv[0],argv,environ); /* This place will never be reached unless execv fails. */ fprintf(stderr,"forkExec fails: "); for (i=0; ilc).ival,(obj2.rc.op->rc).ival, m,CurrentContextp->userDictionary); + }else if (strcmp(key,"or_attr")==0) { + if (size != 3) errorKan1("%s\n","[(or_attr) num symbol] extension."); + obj1 = getoa(obj,1); + obj2 = getoa(obj,2); + if (obj1.tag != Sinteger) errorKan1("%s\n","[(or_attr) num symbol] extension."); + if (obj2.tag != Sstring) errorKan1("%s\n","[(or_attr) num symbol] extension."); + m = KopInteger(obj1); + rob = KfindUserDictionary(obj2.lc.str); + if (rob.tag != NoObject.tag) { + if (strcmp(UD_str,obj2.lc.str) == 0) { + m |= UD_attr; + }else errorKan1("%s\n","or_attr: internal error."); + } + rob = KpoInteger(m); + putUserDictionary2(obj2.lc.str,(obj2.rc.op->lc).ival,(obj2.rc.op->rc).ival, + m,CurrentContextp->userDictionary); + }else if (strcmp(key,"getattr")==0) { + if (size != 2) errorKan1("%s\n","[(getattr) symbol] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sstring) errorKan1("%s\n","[(getattr) symbol] extension."); + rob = KfindUserDictionary(obj1.lc.str); + if (rob.tag != NoObject.tag) { + if (strcmp(UD_str,obj1.lc.str) == 0) { + rob = KpoInteger(UD_attr); + }else errorKan1("%s\n","getattr: internal error."); + }else rob = NullObject; + }else if (strcmp(key,"getServerEnv")==0) { + if (size != 2) errorKan1("%s\n","[(getServerEnv) serverName] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sdollar) errorKan1("%s\n","[(getServerEnv) serverName] extension."); + { + char **se; int ii; int nn; + char **getServerEnv(char *); + se = getServerEnv(KopString(obj1)); + if (se == NULL) { + debugServerEnv(KopString(obj1)); + rob = NullObject; + }else{ + for (ii=0,nn=0; se[ii] != NULL; ii++) nn++; + rob = newObjectArray(nn); + for (ii=0; ii0) { + n = read(fd, s, total); + if (n < 0) { perror("read"); errorKan1("%s\n","[(read) ...]; read error.");} + s[n] = 0; + total -= n; s = &(s[n]); + } + rob = KpoString(s0); + } + }else if (strcmp(key,"regionMatches")==0) { + if (size != 3) errorKan1("%s\n","[(regionMatches) str strArray] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sdollar) errorKan1("%s\n","[(regionMatches) str strArray] extension. str must be a string."); + obj2 = getoa(obj,2); + if (obj2.tag != Sarray) errorKan1("%s\n","[(regionMatches) str strArray] extension. strArray must be an array."); + rob = KregionMatches(obj1,obj2); + }else if (strcmp(key,"newVector")==0) { + if (size != 2) errorKan1("%s\n","[(newVector) m] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sinteger) errorKan1("%s\n","[(newVector) m] extension. m must be an integer."); + rob = newObjectArray(KopInteger(obj1)); + }else if (strcmp(key,"newMatrix")==0) { + if (size != 3) errorKan1("%s\n","[(newMatrix) m n] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sinteger) errorKan1("%s\n","[(newMatrix) m n] extension. m must be an integer."); + obj2 = getoa(obj,2); + if (obj2.tag != Sinteger) errorKan1("%s\n","[(newMatrix) m n] extension. n must be an integer."); + rob = newObjectArray(KopInteger(obj1)); + for (i=0; i