summaryrefslogtreecommitdiff
path: root/Build/source/utils/pdfopen/pdfclose.c
blob: faf5866355a8bacd4fbc336176fbe586235acb04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


extern int sendx_control_token(char *,char *);

#define READERWINPREFIX "Adobe Reader - "
#define SUCCESS(a) (!a)

void usage (void) {
  puts ("pdfclose 0.5: you are mistaking me for an actual program.\n");
  puts ("  pdfclose --file filename.pdf");
  puts ("\n");
}


int main (int argc, char **argv){
  char *filename;
  char *winname;
  if (argc == 3 && strcmp(argv[1],"--file") == 0) {
    filename = malloc(strlen(argv[2])+1);
    if (filename == NULL) {
      puts ("out of memory\n");
      exit(EXIT_FAILURE);
    }
    strcpy(filename,argv[2]);
    if(sendx_control_token("W",filename)) {
      /* failed try reader 7 */
      winname = malloc(strlen(argv[2])+1+strlen(READERWINPREFIX));
      if (winname == NULL) {
	puts ("out of memory\n");
	exit(EXIT_FAILURE);
      }
      strcpy (winname, READERWINPREFIX);
      strcpy ((winname+strlen(READERWINPREFIX)), filename);
      sendx_control_token("W",winname);
    }
  } else if (argc == 2 && strcmp(argv[1],"--all") == 0) {
    ; 
  } else {
    usage();
  }
  exit(EXIT_SUCCESS);
}