diff options
author | Karl Berry <karl@freefriends.org> | 2006-11-26 14:50:06 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-11-26 14:50:06 +0000 |
commit | 70857ece47405fc45527b89c0bc2f6ec1ab54c60 (patch) | |
tree | 31be7dd64be72ad244533f73c4f898e380681049 /Build/source/utils/pdfopen/pdfopen.c | |
parent | 665cd37f2f9699808a65472bd97586fd2beaf662 (diff) |
update to xpdfopen 0.5
git-svn-id: svn://tug.org/texlive/trunk@2538 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/pdfopen/pdfopen.c')
-rw-r--r-- | Build/source/utils/pdfopen/pdfopen.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/Build/source/utils/pdfopen/pdfopen.c b/Build/source/utils/pdfopen/pdfopen.c index 8ede853bae0..f4eba4b3cfb 100644 --- a/Build/source/utils/pdfopen/pdfopen.c +++ b/Build/source/utils/pdfopen/pdfopen.c @@ -3,13 +3,15 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> /* returns 1 on failure */ extern int sendx_control_token(char *,char *); extern int sendx_alt_token(char *,char *); void usage (void) { - puts ("pdfopen 0.4: you are mistaking me for an actual program.\n"); + puts ("pdfopen 0.5: you are mistaking me for an actual program.\n"); puts(" pdfopen [--file filename.pdf]"); puts ("\nusing no arguments tells the Reader to 'go back'.\n"); } @@ -23,7 +25,8 @@ int main (int argc, char **argv){ char *newargv[3]; char *winname; char *filename; - int test = 1; + char *basefile; + pid_t reader; if (argc == 5 && (strcmp(argv[3],"--page") == 0 && strcmp(argv[1],"--file") == 0 )) { @@ -31,39 +34,54 @@ int main (int argc, char **argv){ } if (argc == 3 && strcmp(argv[1],"--file") == 0) { filename = malloc(strlen(argv[2])+1); - if (filename == NULL) { + basefile = malloc(strlen(argv[2])+1); + if (filename == NULL || basefile == NULL) { puts ("out of memory\n"); exit(EXIT_FAILURE); } strcpy(filename,argv[2]); + strcpy(basefile,filename); + if (rindex(basefile,'/')) + basefile = rindex(basefile,'/')+1; + winname = malloc(strlen(argv[2])+1+strlen(READERWINPREFIX)); - if (winname == NULL) { + if (winname == NULL ) { puts ("out of memory\n"); exit(EXIT_FAILURE); } strcpy (winname,READERWINPREFIX); - strcpy ((winname+strlen(READERWINPREFIX)), filename); + strcpy ((winname+strlen(READERWINPREFIX)), basefile); if (SUCCESS(sendx_control_token("W",winname))) { sendx_alt_token("Left",READERNAME); /* that's seven */ + sendx_control_token("Left",READERNAME); + /* that's seven, with artificial five keymaps */ } else if (SUCCESS(sendx_control_token("W",filename))) { sendx_control_token("Left",READERFIVE); /* that's five */ + } else if (SUCCESS(sendx_control_token("W",basefile))) { + sendx_control_token("Left",READERFIVE); /* that's five */ } else { - newargv[0] = "acroread"; - newargv[1] = filename; - newargv[2] = NULL; - if(!fork()) { - execvp("acroread",newargv); - /* this trick makes sure that there *is* a back option - in Acrobat Reader */ - while(test) { - test = sendx_control_token("+",filename); - } - } + if((reader = fork()) >= 0) { + if (reader) { + waitpid(reader,NULL,WNOHANG); + } else { + newargv[0] = "acroread"; + newargv[1] = filename; + newargv[2] = NULL; + if(execvp("acroread",newargv)) { + puts ("acroread startup failed\n"); + exit(EXIT_FAILURE); + } + } + } else { + puts ("fork failed\n"); + exit(EXIT_FAILURE); + } } } else if (argc != 1) { usage(); } else { sendx_alt_token("Left",READERNAME); + sendx_control_token("Left",READERNAME); /* that's seven */ sendx_control_token("Left",READERFIVE); } exit(EXIT_SUCCESS); |