[BACK]Return to batch.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Annotation of OpenXM_contrib2/asir2000/builtin/batch.c, Revision 1.1.1.1

1.1       noro        1: /* $OpenXM: OpenXM/src/asir99/builtin/batch.c,v 1.1.1.1 1999/11/10 08:12:25 noro Exp $ */
                      2: #if !defined(VISUAL)
                      3:
                      4: #include <stdio.h>
                      5: #include <stdlib.h>
                      6:
                      7: int exec_file(char *bindir,char *fname) {
                      8:        char command[BUFSIZ*5];
                      9:        int status;
                     10:
                     11:        sprintf(command,"%s/asir -f %s",bindir,fname);
                     12:        status = system(command);
                     13:        return status;
                     14: }
                     15:
                     16: #else
                     17:
                     18: #include <windows.h>
                     19: #include <stdlib.h>
                     20: #include <stdio.h>
                     21: #include <io.h>
                     22: #include <fcntl.h>
                     23: #include <process.h>
                     24:
                     25: static void read_until_eof();
                     26:
                     27: static HANDLE hRead,hWrite,hNotify,hNotify_Ack,hIntr,hIntr_Ack,hKill,hProc;
                     28:
                     29: int exec_file(char *bindir,char *fname) {
                     30:        int i;
                     31:        char *av[BUFSIZ];
                     32:        char AsirExe[BUFSIZ];
                     33:        DWORD tid,mypid,pid,len;
                     34:        HANDLE hR0,hW0,hR1,hW1;
                     35:     SECURITY_ATTRIBUTES SecurityAttributes;
                     36:        char remread[10],remwrite[10];
                     37:        char notify[100],notify_ack[100],intr[100],intr_ack[100],kill[100];
                     38:
                     39:        mypid = GetCurrentProcessId();
                     40:        sprintf(notify,"asir_notify_%d",mypid);
                     41:        sprintf(notify_ack,"asir_ack_%d",mypid);
                     42:        sprintf(intr,"asir_intr_%d",mypid);
                     43:        sprintf(intr_ack,"asir_intr_ack_%d",mypid);
                     44:        sprintf(kill,"asir_kill_%d",mypid);
                     45:        hNotify = CreateEvent(NULL,TRUE,FALSE,notify);
                     46:        hNotify_Ack = CreateEvent(NULL,TRUE,FALSE,notify_ack);
                     47:        hIntr = CreateEvent(NULL,TRUE,FALSE,intr);
                     48:        hIntr_Ack = CreateEvent(NULL,TRUE,FALSE,intr_ack);
                     49:        hKill = CreateEvent(NULL,TRUE,FALSE,kill);
                     50:
                     51:     SecurityAttributes.nLength = sizeof(SecurityAttributes);
                     52:     SecurityAttributes.lpSecurityDescriptor = NULL;
                     53:     SecurityAttributes.bInheritHandle = TRUE;
                     54:     CreatePipe(&hR0, &hW0, &SecurityAttributes, 65536);
                     55:     CreatePipe(&hR1, &hW1, &SecurityAttributes, 65536);
                     56:
                     57:        hRead = hR0;
                     58:        hWrite = hW1;
                     59:        sprintf(remread,"%d",(DWORD)hR1);
                     60:        sprintf(remwrite,"%d",(DWORD)hW0);
                     61:
                     62:        sprintf(AsirExe,"%s\\engine.exe",bindir);
                     63:        _setargv();
                     64:        av[0] = "asir";
                     65:        av[1] = remread;
                     66:        av[2] = remwrite;
                     67:        av[3] = notify;
                     68:        av[4] = notify_ack;
                     69:        av[5] = intr;
                     70:        av[6] = intr_ack;
                     71:        av[7] = kill;
                     72:        av[8] = "-norc";
                     73:        av[9] = "-f";
                     74:        av[10] = fname;
                     75:        av[11] = NULL;
                     76:        hProc = (HANDLE)_spawnv(_P_NOWAIT,AsirExe,av);
                     77:        if ( hProc == (HANDLE)-1 ) {
                     78:                fprintf(stderr,"%s がありません",AsirExe);
                     79:                return 0;
                     80:        }
                     81:        read_until_eof();
                     82:        return 1;
                     83: }
                     84:
                     85: int doing_batch = 0;
                     86: static char insert_buf[BUFSIZ*10];
                     87: static int insert_buf_len = 0;
                     88:
                     89: static void read_until_eof()
                     90: {
                     91:        char *p;
                     92:        DWORD len;
                     93:        unsigned int cmdsize,cmd,size;
                     94:
                     95:        doing_batch = 1;
                     96:        while ( 1 ) {
                     97:                WaitForSingleObject(hNotify,(DWORD)-1);
                     98:                ResetEvent(hNotify);
                     99:                SetEvent(hNotify_Ack);
                    100:                ReadFile(hRead,&cmdsize,sizeof(unsigned int),&len,NULL);
                    101:                cmd = cmdsize>>16;
                    102:                size = cmdsize&0xffff;
                    103:                if ( !cmd ) {
                    104:                        doing_batch = 0;
                    105:                        return;
                    106:                } else if ( size )
                    107:                        ReadFile(hRead,insert_buf,size,&len,NULL);
                    108:        }
                    109: }
                    110:
                    111: void send_intr() {
                    112:        PulseEvent(hIntr);
                    113: }
                    114:
                    115: void terminate_batch() {
                    116:        TerminateProcess(hProc,0);
                    117: }
                    118: #endif /* VISUAL */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>