=================================================================== RCS file: /home/cvs/OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c,v retrieving revision 1.1 retrieving revision 1.9 diff -u -p -r1.1 -r1.9 --- OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c 2013/08/27 05:51:50 1.1 +++ OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c 2014/05/10 08:23:33 1.9 @@ -1,54 +1,89 @@ -/* $OpenXM$ */ +/* $OpenXM: OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c,v 1.8 2013/11/28 18:53:32 ohara Exp $ */ // cl test.c user32.lib #include #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 containEnd(char s[]); +int abortAsir(HWND hnd); +int main(int argc, char *argv[]); +FILE *open_stdio(DWORD type) { + HANDLE hnd; + int fd; + if((hnd = GetStdHandle(type)) != INVALID_HANDLE_VALUE && (fd = _open_osfhandle((intptr_t)hnd, _O_TEXT)) >= 0) { + return _fdopen(fd, "w"); + } + return NULL; +} + +int WINAPI WinMain(HINSTANCE hins, HINSTANCE prev, LPSTR arg, int show) { + FILE *fp; +#if (_WIN32_WINNT > 0x0500) + if(AttachConsole(ATTACH_PARENT_PROCESS)) { + if(fp = open_stdio(STD_OUTPUT_HANDLE)) { + *stdout = *fp; + setvbuf(stdout, NULL, _IONBF, 0); + } + } +#endif + main(__argc, __argv); + return 0; +} + int main(int argc, char *argv[]) { HWND hnd; - int i,j,c,ii; + int c,ii; char *uname=NULL; FILE *fp=NULL; FILE *fp2=NULL; char snameWin[1024]; char *snameUx; - char *s; char msg[1024]; char cmd[1024]; int paste_contents=0; + int abort=0; /* MessageBox(NULL,TEXT("test"),TEXT("Error in cmdasir.c"),MB_OK); */ - sprintf(snameWin,"%s\\cmdasir-%d.txt",getenv("TEMP"),getpid()); + 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); + printf("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); } + if ((argc > 1) && (strcmp(argv[1],"--abort")==0)) { + return abortAsir(hnd); + } printf("Handler is %d\n",hnd); paste_contents=0; for (ii=1; ii= size-1) { @@ -205,7 +245,46 @@ int pasteFile(HWND hnd, char *uname) { } i++; } - sendFileName(hnd,s); + if (containEnd(s)) { + MessageBox(NULL,TEXT("The string contains end$ or end;"),TEXT(uname),MB_OK); + return(0); + } + if (strlen(s)>0) sendFileName(hnd,s); else { + MessageBox(NULL,TEXT("Empty string: "),TEXT(uname),MB_OK); + return 0; + } free(s); PostMessage(hnd,WM_CHAR,0xa,1); + return 0; +} + +int containEnd(char s[]) { + int i; + for (i=0; i