|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
#include <string> |
|
|
|
|
#include <unistd.h> |
|
|
|
|
#include <sys/wait.h> |
|
|
|
|
#include <pthread.h> |
|
|
|
|
|
|
|
|
|
int print_func(FILE* fd, const char* str) |
|
|
|
|
{ |
|
|
|
@ -10,57 +11,27 @@ int print_func(FILE* fd, const char* str)
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() |
|
|
|
|
{ |
|
|
|
|
char* text="GMT"; |
|
|
|
|
//void* out;
|
|
|
|
|
void* gmtapi; |
|
|
|
|
std::string args="-R130/160/40/60 -JM12c -Xa2c -Ya2c -B5/5/swNE --GMT_HISTORY=f --FONT_ANNOT_PRIMARY=14p,Times-Bold,red"; |
|
|
|
|
struct GMT_OPTION* opts; |
|
|
|
|
int io,ret; |
|
|
|
|
char fname[16]; |
|
|
|
|
int pipefd[2]; |
|
|
|
|
std::string out; |
|
|
|
|
char buffer[4096]; |
|
|
|
|
pid_t pid; |
|
|
|
|
|
|
|
|
|
gmtapi=GMT_Create_Session(text,2,0,print_func); |
|
|
|
|
//io=GMT_Register_IO(gmtapi,GMT_IS_TEXTSET,GMT_IS_DUPLICATE,GMT_IS_NONE,GMT_OUT,0,0);
|
|
|
|
|
//GMT_Encode_ID(gmtapi,fname,io);
|
|
|
|
|
opts=GMT_Create_Options(gmtapi,0,(void*)args.c_str()); |
|
|
|
|
//ret=GMT_Init_IO(gmtapi,GMT_IS_TEXTSET,GMT_IS_NONE,GMT_OUT,5,0,opts);
|
|
|
|
|
std::cout<<io<<" "<<GMT_NOTSET<<" "<<fname<<" "<<ret<<std::endl; |
|
|
|
|
|
|
|
|
|
pipe(pipefd); |
|
|
|
|
pid=fork(); |
|
|
|
|
if(0==pid) |
|
|
|
|
void* thr(void* p) |
|
|
|
|
{ |
|
|
|
|
dup2(pipefd[1],1); |
|
|
|
|
GMT_Call_Module(gmtapi,"psbasemap",GMT_MODULE_OPT,opts); |
|
|
|
|
exit(0); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
ssize_t br; |
|
|
|
|
std::string s="CALL\n"; |
|
|
|
|
// write(1,s.c_str(),s.length());
|
|
|
|
|
close(pipefd[1]); |
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
br=read(pipefd[0],buffer,4096); |
|
|
|
|
std::cout<<out.max_size()<<" "<<out.capacity()<<" "<<out.size()<<std::endl; |
|
|
|
|
out.append(buffer,br); |
|
|
|
|
} while(0!=br); |
|
|
|
|
wait(0); |
|
|
|
|
close(pipefd[0]); |
|
|
|
|
std::cout<<"Thread Phase1\n"; |
|
|
|
|
close(1); |
|
|
|
|
std::cout<<"Thread Phase2\n"; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
out.shrink_to_fit(); |
|
|
|
|
std::cout<<out.max_size()<<" "<<out.capacity()<<" "<<out.size()<<std::endl; |
|
|
|
|
|
|
|
|
|
GMT_Destroy_Options(gmtapi,&opts); |
|
|
|
|
GMT_Destroy_Session(gmtapi); |
|
|
|
|
int main() |
|
|
|
|
{ |
|
|
|
|
int savefd; |
|
|
|
|
pthread_t t; |
|
|
|
|
|
|
|
|
|
std::cout<<"Phase1\n"; |
|
|
|
|
savefd=dup(1); |
|
|
|
|
pthread_create(&t,0,&thr,0); |
|
|
|
|
pthread_join(t,0); |
|
|
|
|
std::cout<<"Phase2\n"; |
|
|
|
|
dup2(savefd,1); |
|
|
|
|
std::cout<<"Phase3\n"; |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|