The R Project SVN R

Rev

Rev 59039 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
47626 ripley 1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
59039 ripley 3
 *  Copyright (C) 2008-10  R Core Team
47626 ripley 4
 *
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not,  a copy is available at
68956 ripley 17
 *  https://www.R-project.org/Licenses/
47626 ripley 18
 */
19
 
20
#include <windows.h>
21
#include <stdio.h>
22
#include <stdlib.h>		/* for exit */
23
 
24
 
25
int main (int argc, char **argv)
26
{
27
    int i, status = 0;
28
    unsigned int ret;
51875 ripley 29
    char fn[2001];
47626 ripley 30
 
31
    if (argc < 2 || strcmp(argv[1], "--help") == 0) {
32
	fprintf(stderr, "Usage: Rcmd open file [file ...]\n\n");
33
	fprintf(stderr, "  opens each file with the application given by\n");
34
	fprintf(stderr, "  the Windows file association (if any)\n");
35
	exit(0);
36
    }
37
    for(i = 1; i < argc; i++) {
51875 ripley 38
	strncpy(fn, argv[i], 2000); fn[2000] = '\0';
39
	for(char *p = fn; *p; p++) if(*p == '/') *p = '\\';
40
	ret = (size_t) ShellExecute(NULL, "open", fn, NULL, ".", SW_SHOW);
47626 ripley 41
	if(ret <= 32) { /* an error condition */
42
	    status = 32 + ret;
43
	    if(ret == ERROR_FILE_NOT_FOUND  || ret == ERROR_PATH_NOT_FOUND
44
	       || ret == SE_ERR_FNF || ret == SE_ERR_PNF)
51626 ripley 45
		fprintf(stderr, "'%s' not found\n", argv[i]);
47626 ripley 46
	    else if(ret == SE_ERR_ASSOCINCOMPLETE || ret == SE_ERR_NOASSOC)
47
		fprintf(stderr, 
48
			"file association for '%s' not available or invalid\n",
49
			argv[i]);
50
	    else if(ret == SE_ERR_ACCESSDENIED || ret == SE_ERR_SHARE)
51
		fprintf(stderr, "access to '%s' denied\n", argv[i]);
52
	    else
53
		fprintf(stderr, "problem in displaying '%s'\n", argv[i]);
54
	}
55
    }
56
    exit(status);
57
}