]> cygwin.com Git - cygwin-apps/setup.git/blame - concat.cc
* net.cc (do_net): Default to direct download.
[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>
24
25char *
26concat (char *s, ...)
27{
ed3e8b9b 28 int len;
23c9e63c
DD
29 char *rv, *arg;
30 va_list v;
31
32 if (!s)
33 return 0;
34
ed3e8b9b
DD
35 len = strlen (s);
36
23c9e63c
DD
37 va_start (v, s);
38 while (1)
39 {
1fd6d0a2 40 arg = va_arg (v, char *);
23c9e63c
DD
41 if (arg == 0)
42 break;
1fd6d0a2 43 len += strlen (arg);
23c9e63c 44 }
1fd6d0a2 45 va_end (v);
23c9e63c
DD
46
47 rv = (char *) malloc (len+1);
1fd6d0a2
DD
48 strcpy (rv, s);
49 va_start (v, s);
23c9e63c
DD
50 while (1)
51 {
1fd6d0a2 52 arg = va_arg (v, char *);
23c9e63c
DD
53 if (arg == 0)
54 break;
1fd6d0a2 55 strcat (rv, arg);
23c9e63c 56 }
1fd6d0a2 57 va_end (v);
23c9e63c
DD
58
59 /* concat is only used for urls and files, so we can safely
60 canonicalize the results */
61 char *d;
62 for (s=rv; *s; s++)
63 if (*s == '\\')
64 *s = '/';
65 for (s=d=rv; *s; s++)
66 {
67 *d++ = *s;
68 /* special case for URLs */
f5d0464b 69 if (*s == ':' && s[1] == '/' && s[2] == '/' && s > rv+1)
23c9e63c
DD
70 {
71 *d++ = *++s;
72 *d++ = *++s;
73 }
74 else if (*s == '/')
75 while (s[1] == '/')
76 s++;
77 }
78 *d = 0;
79
80 return rv;
81}
f57c332f
DD
82
83char *
84backslash (char *s)
85{
86 for (char *t = s; *t; t++)
87 if (*t == '/')
88 *t = '\\';
89 return s;
90}
This page took 0.032457 seconds and 5 git commands to generate.