The R Project SVN R

Rev

Rev 73564 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73564 Rev 83755
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 2000-7  R Core Team
3
 *  Copyright (C) 2000-2023  R Core Team
4
 *
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
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
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
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
8
 *  (at your option) any later version.
Line 32... Line 32...
32
    /* tasks:
32
    /* tasks:
33
       find pwd of (only) arg
33
       find pwd of (only) arg
34
       convert to short name if contains spaces
34
       convert to short name if contains spaces
35
       print it to stdout.
35
       print it to stdout.
36
     */
36
     */
37
    char *p, buf[MAX_PATH];
-
 
38
    int hasspace = 0;
-
 
39
 
37
 
40
    if(argc == 2) {
38
    if(argc == 2) {
41
	if(chdir(argv[1])) exit(1);
39
	if(!SetCurrentDirectory(argv[1])) exit(1);
42
    }
40
    }
43
    if(argc <= 2) {
41
    if(argc <= 2) {
-
 
42
	char *p, *buf;
-
 
43
	int hasspace = 0;
-
 
44
	DWORD res = GetCurrentDirectory(0, NULL);
-
 
45
 
-
 
46
	if (!res)
-
 
47
	    exit(1);
44
	getcwd(buf, MAX_PATH);
48
	buf = (char *)malloc(res);
-
 
49
	if (!buf || !GetCurrentDirectory(res, buf))
-
 
50
	    exit(1);
-
 
51
 
45
	for (p = buf; *p; p++) 
52
	for (p = buf; *p; p++) 
46
	    if (isspace(*p)) { hasspace = 1; break; }
53
	    if (isspace(*p)) { hasspace = 1; break; }
-
 
54
 
47
	if (hasspace)
55
	if (hasspace) {
48
	    /* NOTE: short names are not always enabled */
56
	    /* NOTE: short names are not always enabled */
49
	    GetShortPathName(buf, buf, MAX_PATH);
57
	    res = GetShortPathName(buf, NULL, 0);
-
 
58
	    if (res > 0) {
-
 
59
		char *sbuf = (char *)malloc(res);
-
 
60
		if (!sbuf)
-
 
61
		    exit(1);
-
 
62
		DWORD res1 = GetShortPathName(buf, sbuf, res);
-
 
63
		if (res1 > 0 && res1 < res) {
-
 
64
		    free(buf);
-
 
65
		    buf = sbuf;
-
 
66
		    sbuf = NULL;
-
 
67
		} else
-
 
68
		    free(sbuf);
-
 
69
	    }
-
 
70
	}
50
	for (p = buf; *p; p++)
71
	for (p = buf; *p; p++)
51
	    if (*p == '\\') *p = '/';
72
	    if (*p == '\\') *p = '/';
52
	printf("%s", buf);
73
	printf("%s", buf);
-
 
74
	free(buf);
53
	exit(0);
75
	exit(0);
54
    } else exit(2);
76
    } else exit(2);
55
}
77
}
-
 
78