]>
cygwin.com Git - cygwin-apps/setup.git/blob - filemanip.cc
2 * Copyright (c) 2000, 2001, Red Hat, Inc.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <rbtcollins@redhat.com>
16 /* The purpose of this file is to put all general purpose file manipulation
20 static const char *cvsid
=
30 #include "filemanip.h"
33 get_file_size (String
const &name
)
39 h
= FindFirstFileA (name
.cstr_oneuse(), &buf
);
40 if (h
!= INVALID_HANDLE_VALUE
)
42 if (buf
.nFileSizeHigh
== 0)
43 ret
= buf
.nFileSizeLow
;
50 base (String
const &aString
)
54 const char *t
= aString
.cstr();
59 if ((*s
== '/' || *s
== ':' || *s
== '\\') && s
[1])
67 /* returns the number of characters of path that
68 * precede the extension
71 find_tar_ext (const char *path
)
73 char *end
= strchr (path
, '\0');
74 /* check in longest first order */
76 if ((ext
= strstr (path
, ".tar.bz2")) && (end
- ext
) == 8)
78 if ((ext
= strstr (path
, ".tar.gz")) && (end
- ext
) == 7)
80 if ((ext
= strstr (path
, ".tar")) && (end
- ext
) == 4)
85 /* Parse a filename into package, version, and extension components. */
87 parse_filename (String
const &in_fn
, fileparse
& f
)
90 char fn
[in_fn
.size() + 1];
91 strcpy (fn
, in_fn
.cstr_oneuse());
93 int n
= find_tar_ext (fn
);
100 f
.pkg
= f
.what
= String();
101 p
= base (fn
).cstr();
102 for (ver
= p
; *ver
; ver
++)
104 if (isdigit (ver
[1]))
110 else if (strcasecmp (ver
, "-src") == 0 ||
111 strcasecmp (ver
, "-patch") == 0)
115 f
.what
= strlwr (ver
);
116 ver
= strchr (ver
, '\0');
126 char *p1
= strchr (ver
, '\0');
127 if ((p1
-= 4) >= ver
&& strcasecmp (p1
, "-src") == 0)
129 else if ((p1
-= 2) >= ver
&& strcasecmp (p1
, "-patch") == 0)
135 // get the 'src' or 'patch'.
140 f
.ver
= *ver
? ver
: "0.0";
146 backslash (String
const & aString
)
148 char * tempString
= aString
.cstr();
149 for (char *t
= tempString
; *t
; t
++)
152 String
theString(tempString
);
This page took 0.042243 seconds and 5 git commands to generate.