=================================================================== RCS file: /home/cvs/OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -p -r1.2 -r1.3 --- OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c 2013/08/27 07:41:22 1.2 +++ OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c 2013/08/28 05:33:02 1.3 @@ -1,220 +1,220 @@ -/* $OpenXM: OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c,v 1.1 2013/08/27 05:51:50 takayama Exp $ */ -// cl test.c user32.lib - -#include -#include -#include -#include -#include -#include - -char *winname2uxname(char winname[]); -FILE *findAsirHandler(); -int sendFileName(HWND hnd,char uname[]); -int loadFile(HWND hnd, char *uname); -int terminateAsir(HWND hnd); -int hasTemp(char *s); -int pasteFile(HWND hnd, char *uname); - -int main(int argc, char *argv[]) -{ - HWND hnd; - int c,ii; - char *uname=NULL; - FILE *fp=NULL; - FILE *fp2=NULL; - char snameWin[1024]; - char *snameUx; - char msg[1024]; - char cmd[1024]; - int paste_contents=0; - - /* MessageBox(NULL,TEXT("test"),TEXT("Error in cmdasir.c"),MB_OK); */ - sprintf(snameWin,"%s\\cmdasir-%d.txt",getenv("TEMP"),getpid()); - snameUx = winname2uxname(snameWin); - if ((argc > 1) && (strcmp(argv[1],"--delete-tmp")==0)) { - sprintf(cmd,"del %s\\cmdasir-*",getenv("TEMP")); - system(cmd); - return(0); - } - fp = findAsirHandler(); - if (fp == NULL) { - fprintf(stderr,"handler file is not found.\n"); return(-1); - } - fscanf(fp,"%d",&hnd); - fclose(fp); - if ((argc > 1) && (strcmp(argv[1],"--quit")==0)) { - return terminateAsir(hnd); - } - printf("Handler is %d\n",hnd); - paste_contents=0; - for (ii=1; ii= 0) fputc(c,fp2); - if (!paste_contents) fprintf(fp2,"\nend$\n"); - fclose(fp2); - uname=snameUx; - } - printf("filename=%s\n",argv[ii]); - if(access(argv[ii],0)==0) { - if (paste_contents) return pasteFile(hnd, (uname != NULL)? uname: winname2uxname(argv[ii])); - else return loadFile(hnd, (uname != NULL)? uname: winname2uxname(argv[ii])); - } - } - /* work file is kept. Prepare a commnd to delete all the work files under temp - */ - while ((c=getchar()) != EOF) { - if (!PostMessage(hnd,WM_CHAR,c,1)) { - MessageBox(NULL,TEXT("asirgui is not running."), TEXT("ERROR in cmdasir.c"),MB_OK); - return(-1); - } - } - return 0; -} - -int loadFile(HWND hnd, char *uname) { - char *s="load(@);\n"; - int i; - for (i=0; i= size-1) { - sold = s; - size = size*2; - s = (char*)malloc(size+1); - strcpy(s,sold); - free(sold); - } - i++; - } - sendFileName(hnd,s); - free(s); - PostMessage(hnd,WM_CHAR,0xa,1); - return 0; -} +/* $OpenXM: OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c,v 1.2 2013/08/27 07:41:22 ohara Exp $ */ +// cl test.c user32.lib + +#include +#include +#include +#include +#include +#include + +char *winname2uxname(char winname[]); +FILE *findAsirHandler(); +int sendFileName(HWND hnd,char uname[]); +int loadFile(HWND hnd, char *uname); +int terminateAsir(HWND hnd); +int hasTemp(char *s); +int pasteFile(HWND hnd, char *uname); + +int main(int argc, char *argv[]) +{ + HWND hnd; + int c,ii; + char *uname=NULL; + FILE *fp=NULL; + FILE *fp2=NULL; + char snameWin[1024]; + char *snameUx; + char msg[1024]; + char cmd[1024]; + int paste_contents=0; + + /* MessageBox(NULL,TEXT("test"),TEXT("Error in cmdasir.c"),MB_OK); */ + sprintf(snameWin,"%s\\cmdasir-%d.txt",getenv("TEMP"),getpid()); + snameUx = winname2uxname(snameWin); + if ((argc > 1) && (strcmp(argv[1],"--delete-tmp")==0)) { + sprintf(cmd,"del %s\\cmdasir-*",getenv("TEMP")); + system(cmd); + return(0); + } + fp = findAsirHandler(); + if (fp == NULL) { + fprintf(stderr,"handler file is not found.\n"); return(-1); + } + fscanf(fp,"%d",&hnd); + fclose(fp); + if ((argc > 1) && (strcmp(argv[1],"--quit")==0)) { + return terminateAsir(hnd); + } + printf("Handler is %d\n",hnd); + paste_contents=0; + for (ii=1; ii= 0) fputc(c,fp2); + if (!paste_contents) fprintf(fp2,"\nend$\n"); + fclose(fp2); + uname=snameUx; + } + printf("filename=%s\n",argv[ii]); + if(access(argv[ii],0)==0) { + if (paste_contents) return pasteFile(hnd, (uname != NULL)? uname: winname2uxname(argv[ii])); + else return loadFile(hnd, (uname != NULL)? uname: winname2uxname(argv[ii])); + } + } + /* work file is kept. Prepare a commnd to delete all the work files under temp + */ + while ((c=getchar()) != EOF) { + if (!PostMessage(hnd,WM_CHAR,c,1)) { + MessageBox(NULL,TEXT("asirgui is not running."), TEXT("ERROR in cmdasir.c"),MB_OK); + return(-1); + } + } + return 0; +} + +int loadFile(HWND hnd, char *uname) { + char *s="load(@);\n"; + int i; + for (i=0; i= size-1) { + sold = s; + size = size*2; + s = (char*)malloc(size+1); + strcpy(s,sold); + free(sold); + } + i++; + } + sendFileName(hnd,s); + free(s); + PostMessage(hnd,WM_CHAR,0xa,1); + return 0; +}