version 1.1, 2013/08/27 05:51:50 |
version 1.5, 2013/11/27 04:23:07 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM_contrib2/windows/post-msg-asirgui/cmdasir.c,v 1.4 2013/11/05 23:59:20 takayama Exp $ */ |
// cl test.c user32.lib |
// cl test.c user32.lib |
|
|
#include <windows.h> |
#include <windows.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
|
#include <string.h> |
|
#include <io.h> |
#include <process.h> |
#include <process.h> |
|
|
char *winname2uxname(char winname[]); |
char *winname2uxname(char winname[]); |
Line 11 FILE *findAsirHandler(); |
|
Line 13 FILE *findAsirHandler(); |
|
int sendFileName(HWND hnd,char uname[]); |
int sendFileName(HWND hnd,char uname[]); |
int loadFile(HWND hnd, char *uname); |
int loadFile(HWND hnd, char *uname); |
int terminateAsir(HWND hnd); |
int terminateAsir(HWND hnd); |
|
int hasTemp(char *s); |
|
int pasteFile(HWND hnd, char *uname); |
|
|
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
{ |
{ |
HWND hnd; |
HWND hnd; |
int i,j,c,ii; |
int c,ii; |
char *uname=NULL; |
char *uname=NULL; |
FILE *fp=NULL; |
FILE *fp=NULL; |
FILE *fp2=NULL; |
FILE *fp2=NULL; |
char snameWin[1024]; |
char snameWin[1024]; |
char *snameUx; |
char *snameUx; |
char *s; |
|
char msg[1024]; |
char msg[1024]; |
char cmd[1024]; |
char cmd[1024]; |
int paste_contents=0; |
int paste_contents=0; |
|
int abort=0; |
|
|
/* MessageBox(NULL,TEXT("test"),TEXT("Error in cmdasir.c"),MB_OK); */ |
/* 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()); |
Line 34 int main(int argc, char *argv[]) |
|
Line 38 int main(int argc, char *argv[]) |
|
system(cmd); |
system(cmd); |
return(0); |
return(0); |
} |
} |
|
|
fp = findAsirHandler(); |
fp = findAsirHandler(); |
if (fp == NULL) { |
if (fp == NULL) { |
fprintf(stderr,"handler file is not found.\n"); return(-1); |
fprintf(stderr,"handler file is not found.\n"); return(-1); |
Line 43 int main(int argc, char *argv[]) |
|
Line 48 int main(int argc, char *argv[]) |
|
if ((argc > 1) && (strcmp(argv[1],"--quit")==0)) { |
if ((argc > 1) && (strcmp(argv[1],"--quit")==0)) { |
return terminateAsir(hnd); |
return terminateAsir(hnd); |
} |
} |
|
if ((argc > 1) && (strcmp(argv[1],"--abort")==0)) { |
|
return abortAsir(hnd); |
|
} |
printf("Handler is %d\n",hnd); |
printf("Handler is %d\n",hnd); |
paste_contents=0; |
paste_contents=0; |
for (ii=1; ii<argc; ii++) { |
for (ii=1; ii<argc; ii++) { |
if (strcmp(argv[ii],"--paste-contents")==0) { |
if (strcmp(argv[ii],"--paste-contents")==0) { |
paste_contents=1; continue; |
paste_contents=1; continue; |
} |
} |
uname = NULL; |
uname = NULL; |
if (hasTemp(argv[ii])) { |
if (hasTemp(argv[ii])) { |
fp = fopen(winname2uxname(argv[ii]),"r"); |
fp = fopen(winname2uxname(argv[ii]),"r"); |
Line 121 char *winname2uxname(char wname[]) { |
|
Line 129 char *winname2uxname(char wname[]) { |
|
return(uname); |
return(uname); |
} |
} |
|
|
|
#if 0 |
int hasTemp(char *s) { |
int hasTemp(char *s) { |
int i,n; |
int i; |
n=strlen(s); |
size_t n=strlen(s); |
for (i=0; i<n-3; i++) { |
for (i=0; i<n-3; i++) { |
if (strncmp(&(s[i]),"Temp",4)==0) return(1); |
if (strncmp(&(s[i]),"Temp",4)==0) return(1); |
} |
} |
return(0); |
return(0); |
} |
} |
|
#endif |
|
|
|
int hasTemp(char *s) { |
|
return strstr(s, "Temp")!=NULL; |
|
} |
|
|
FILE *findAsirHandler() { |
FILE *findAsirHandler() { |
int i; |
int i; |
FILE *hnd = NULL; |
FILE *hnd = NULL; |
Line 163 int sendFileName_ascii(HWND hnd,char uname[]) { |
|
Line 177 int sendFileName_ascii(HWND hnd,char uname[]) { |
|
} |
} |
#endif |
#endif |
int sendFileName(HWND hnd,char uname[]) { |
int sendFileName(HWND hnd,char uname[]) { |
int j; |
size_t len=strlen(uname)+1; |
int len=strlen(uname)+1; |
|
HGLOBAL hMem; |
HGLOBAL hMem; |
LPTSTR pMem; |
LPTSTR pMem; |
if (!OpenClipboard(NULL) ) return 1; |
if (!OpenClipboard(NULL) ) return 1; |
Line 193 int pasteFile(HWND hnd, char *uname) { |
|
Line 206 int pasteFile(HWND hnd, char *uname) { |
|
return -1; |
return -1; |
} |
} |
s = (char *)malloc(size+1); |
s = (char *)malloc(size+1); |
i = 0; |
i = 0;s[0]=0; |
while ((c=fgetc(fp)) != EOF) { |
while ((c=fgetc(fp)) != EOF) { |
s[i] = c; s[i+1]=0; |
s[i] = c; s[i+1]=0; |
if (i >= size-1) { |
if (i >= size-1) { |
Line 205 int pasteFile(HWND hnd, char *uname) { |
|
Line 218 int pasteFile(HWND hnd, char *uname) { |
|
} |
} |
i++; |
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); |
free(s); |
PostMessage(hnd,WM_CHAR,0xa,1); |
PostMessage(hnd,WM_CHAR,0xa,1); |
|
return 0; |
|
} |
|
|
|
int containEnd(char s[]) { |
|
int i; |
|
for (i=0; i<strlen(s)-4; i++) { |
|
if (strncmp(&(s[i]),"end$",4)==0) return 1; |
|
if (strncmp(&(s[i]),"end;",4)==0) return 1; |
|
} |
|
return(0); |
|
} |
|
|
|
int abortAsir(int hnd) { |
|
int c; |
|
int result; |
|
result=MessageBox(NULL,TEXT("Do you abort this computation?"),TEXT("Abort"),MB_OKCANCEL); |
|
if (result == IDCANCEL) return(0); |
|
c=0x3; |
|
if (!PostMessage(hnd,WM_CHAR,c,1)) { |
|
MessageBox(NULL,TEXT("asirgui is not running."), TEXT("ERROR in cmdasir.c"),MB_OK); |
|
return(-1); |
|
} |
|
|
|
printf("Sending ctrl-C\n"); |
|
/* Sleep(3*1000); */ |
|
result=MessageBox(NULL,TEXT("Interrupt is displayed in asirgui?"),TEXT("Sent ctrl-C."),MB_OKCANCEL); |
|
if (result == IDCANCEL) return(0); |
|
c='t'; PostMessage(hnd,WM_CHAR,c,1); |
|
c=0xd; PostMessage(hnd,WM_CHAR,c,1); |
|
c='y'; PostMessage(hnd,WM_CHAR,c,1); |
|
c=0xd; PostMessage(hnd,WM_CHAR,c,1); |
|
return(0); |
} |
} |