about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation/HTDOS.c
blob: a1b5cb4bbf64eeeb8deb2c063796ad482bde33f0 (plain) (blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*	       DOS specific routines

 */

#include <HTUtils.h>
#include <HTDOS.h>

#ifdef _WINDOWS
#include <HTString.h>
#include <stdio.h>
#include <windows.h>
#endif

/*
 * Make a copy of the source argument in the result, allowing some extra
 * space so we can append directly onto the result without reallocating.
 */
PRIVATE char * copy_plus ARGS2(char **, result, char *, source)
{
    int length = strlen(source);
    HTSprintf0(result, "%-*s", length+10, source);
    (*result)[length] = 0;
    return (*result);
}

/* PUBLIC							HTDOS_wwwName()
**		CONVERTS DOS Name into WWW Name
** ON ENTRY:
**	dosname 	DOS file specification (NO NODE)
**
** ON EXIT:
**	returns 	WWW file specification
**
*/
char * HTDOS_wwwName ARGS1(char *, dosname)
{
    static char *wwwname = NULL;
    char *cp_url = copy_plus(&wwwname, dosname);
    int wwwname_len;

#ifdef SH_EX
    char ch;

    while ((ch = *dosname) != '\0') {
	switch (ch) {
	case '\\':
	/* convert dos backslash to unix-style */
	    *cp_url++ = '/';
	    break;
	case ' ':
	    *cp_url++ = '%';
	    *cp_url++ = '2';
	    *cp_url++ = '0';
	    break;
      default:
	    *cp_url++ = ch;
	    break;;
      }
      dosname++;
    }
    *cp_url = '\0';
#else
    for ( ; *cp_url != '\0' ; cp_url++)
	if(*cp_url == '\\')
	    *cp_url = '/';   /* convert dos backslash to unix-style */
#endif

    wwwname_len = strlen(wwwname);
    if (wwwname_len > 1)
	cp_url--;	/* point last char */

    if (wwwname_len > 3 && *cp_url == '/')
	*cp_url = '\0';

#ifdef NOTUSED
    if(*cp_url == ':') {
	cp_url++;
	*cp_url = '/';	/* terminate drive letter to survive */
    }
#endif

    return(wwwname);
}


/* PUBLIC							HTDOS_name()
**		CONVERTS WWW name into a DOS name
** ON ENTRY:
**	wwwname 	WWW file name
**
** ON EXIT:
**	returns 	DOS file specification
*/
char * HTDOS_name ARGS1(char *, wwwname)
{
#ifdef _WINDOWS	/* 1998/04/02 (Thu) 08:47:20 */
    extern char windows_drive[];
    char temp_buff[LY_MAXPATH];
#endif
    static char *cp_url = NULL;
    char *result, *ret;
    int joe;

    CTRACE(tfp, "HTDOS_name changed `%s'\n", wwwname);
    copy_plus(&cp_url, wwwname);

    for (joe = 0; cp_url[joe] != '\0'; joe++)	{
	if (cp_url[joe] == '/')	{
	    cp_url[joe] = '\\';	/* convert slashes to dos-style */
	}
    }

    /* pesky leading slash, rudiment from file://localhost/  */
    /* the rest of path may be with or without drive letter  */
    if((cp_url[1] == '\\') || (cp_url[0]  != '\\')) {
	result = cp_url;
    } else {
	result = cp_url+1;
    }

#ifdef _WINDOWS	/* 1998/04/02 (Thu) 08:59:48 */
    if (strchr(result, '\\') && strchr(result, ':')==NULL) {
	sprintf(temp_buff, "%s\\%s", windows_drive, result);
	ret = NULL;
	StrAllocCopy(ret, temp_buff);
	free(cp_url);
    } else {
	char *p;
	p = strchr(result, ':');
	if (p && (strcmp(p, ":\\") == 0)) {
	    p[2] = '.';
	    p[3] = '\0';
	}
	ret = result;
    }
#else
    ret = result;
#endif

    CTRACE(tfp, "HTDOS_name changed `%s' to `%s'\n", wwwname, ret);
    return (ret);
}