]>
Commit | Line | Data |
---|---|---|
7939f6d1 RC |
1 | /* |
2 | * Copyright (c) 2001, Robert Collins. | |
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 Robert Collins <rbtcollins@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
fa0c0d10 RC |
16 | /* this is the parent class for all package source (not source code - installation |
17 | * source as in http/ftp/disk file) operations. | |
7939f6d1 RC |
18 | */ |
19 | ||
20 | #if 0 | |
21 | static const char *cvsid = | |
22 | "\n%%% $Id$\n"; | |
23 | #endif | |
bb849dbd RC |
24 | |
25 | #include <stdlib.h> | |
26 | #include <strings.h> | |
27 | #include "package_source.h" | |
28 | ||
29 | void | |
30 | packagesource::set_canonical (char const *fn) | |
31 | { | |
32 | if (canonical) | |
33 | delete canonical; | |
34 | canonical = new char[strlen (fn) + 1]; | |
35 | strcpy (canonical, fn); | |
36 | ||
37 | /* The base is from the last '/' to the first '.' following the last - */ | |
38 | char const *bstart = strchr (fn, '/'); | |
39 | char const *tmp; | |
40 | while (bstart && (tmp = strchr (bstart + 1, '/'))) | |
41 | bstart = tmp; | |
42 | ||
43 | if (!bstart) | |
44 | bstart = fn; | |
45 | char const *bend = strchr (bstart, '-'); | |
46 | while (bend && (tmp = strchr (bend + 1, '-'))) | |
47 | bend = tmp; | |
48 | if (bend) | |
49 | bend = strchr (bend, '.'); | |
50 | else | |
51 | bend = strchr (bstart, '.'); | |
52 | ||
53 | if (!bend) | |
54 | bend = strchr (bstart, '\0'); | |
55 | char const *end = strchr (fn, '\0'); | |
56 | if (base) | |
57 | delete (base); | |
58 | base = new char[bend - bstart]; | |
59 | memcpy (base, bstart + 1, bend - bstart - 1); | |
60 | base[bend - bstart - 1] = '\0'; | |
61 | ||
62 | if (filename) | |
63 | delete filename; | |
071c1c54 RC |
64 | filename = new char[end - bstart]; |
65 | memcpy (filename, bstart + 1, end - bstart - 1); | |
66 | filename[end - bstart - 1] = '\0'; | |
bb849dbd RC |
67 | |
68 | if (cached) | |
69 | delete cached; | |
70 | cached = 0; | |
71 | } | |
72 | ||
73 | void | |
74 | packagesource::set_cached (char const *fp) | |
75 | { | |
76 | if (cached) | |
77 | delete cached; | |
78 | cached = new char[strlen (fp) + 1]; | |
79 | strcpy (cached, fp); | |
80 | } |