]> cygwin.com Git - cygwin-apps/setup.git/blame - concat.cc
Change concat to cygpath throughout. Change map_filename to cygpath
[cygwin-apps/setup.git] / concat.cc
CommitLineData
23c9e63c
DD
1/*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16/* See concat.h. Note that we canonicalize the result, this avoids
17 multiple slashes being interpreted as UNCs. */
18
8507f105
DD
19static char *cvsid = "\n%%% $Id$\n";
20
23c9e63c
DD
21#include <stdarg.h>
22#include <stdlib.h>
23#include <string.h>
a351e48c 24#include "concat.h"
23c9e63c
DD
25
26char *
a351e48c
CF
27concat (const char *s, ...)
28{
29 va_list v;
30
31 va_start (v, s);
32
33 return vconcat (s, v);
34}
35
36char *
37vconcat (const char *s, va_list v)
23c9e63c 38{
ed3e8b9b 39 int len;
23c9e63c 40 char *rv, *arg;
a351e48c
CF
41 va_list save_v = v;
42 int unc;
23c9e63c
DD
43
44 if (!s)
45 return 0;
46
ed3e8b9b
DD
47 len = strlen (s);
48
a351e48c
CF
49 unc = SLASH_P (*s) && SLASH_P (s[1]);
50
23c9e63c
DD
51 while (1)
52 {
1fd6d0a2 53 arg = va_arg (v, char *);
23c9e63c
DD
54 if (arg == 0)
55 break;
1fd6d0a2 56 len += strlen (arg);
23c9e63c 57 }
1fd6d0a2 58 va_end (v);
23c9e63c
DD
59
60 rv = (char *) malloc (len+1);
1fd6d0a2 61 strcpy (rv, s);
a351e48c 62 v = save_v;
23c9e63c
DD
63 while (1)
64 {
1fd6d0a2 65 arg = va_arg (v, char *);
23c9e63c
DD
66 if (arg == 0)
67 break;
1fd6d0a2 68 strcat (rv, arg);
23c9e63c 69 }
1fd6d0a2 70 va_end (v);
23c9e63c 71
a351e48c
CF
72 char *d, *p;
73 for (p = rv; *p; p++)
74 if (*p == '\\')
75 *p = '/';
76
23c9e63c
DD
77 /* concat is only used for urls and files, so we can safely
78 canonicalize the results */
a351e48c 79 for (p = d = rv; *p; p++)
23c9e63c 80 {
a351e48c 81 *d++ = *p;
23c9e63c 82 /* special case for URLs */
a351e48c
CF
83 if (*p == ':' && p[1] == '/' && p[2] == '/' && p > rv + 1)
84 {
85 *d++ = *++p;
86 *d++ = *++p;
87 }
88 else if (*p == '/' || *p == '\\')
23c9e63c 89 {
a351e48c
CF
90 if (p == rv && unc)
91 p++;
92 while (p[1] == '/')
93 p++;
23c9e63c 94 }
23c9e63c
DD
95 }
96 *d = 0;
97
98 return rv;
99}
f57c332f
DD
100
101char *
102backslash (char *s)
103{
104 for (char *t = s; *t; t++)
105 if (*t == '/')
106 *t = '\\';
107 return s;
108}
This page took 0.037613 seconds and 5 git commands to generate.