2020-05-04 08:40:05 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#ifndef _HIO_PATH_H_
|
|
|
|
#define _HIO_PATH_H_
|
2020-05-04 08:40:05 +00:00
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#include <hio.h>
|
|
|
|
#include <hio-utl.h>
|
2020-05-04 08:40:05 +00:00
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
enum hio_canon_path_flag_t
|
2020-05-04 08:40:05 +00:00
|
|
|
{
|
|
|
|
/** if the final output is . logically, return an empty path */
|
2021-07-22 07:43:01 +00:00
|
|
|
HIO_CANON_PATH_EMPTY_SINGLE_DOT = (1 << 0),
|
2020-05-04 08:40:05 +00:00
|
|
|
|
|
|
|
/** keep the .. segment in the path name */
|
2021-07-22 07:43:01 +00:00
|
|
|
HIO_CANON_PATH_KEEP_DOUBLE_DOTS = (1 << 1),
|
2020-05-04 08:40:05 +00:00
|
|
|
|
|
|
|
/** drop a trailing separator even if the source contains one */
|
2021-07-22 07:43:01 +00:00
|
|
|
HIO_CANON_PATH_DROP_TRAILING_SEP = (1 << 2)
|
2020-05-04 08:40:05 +00:00
|
|
|
};
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
typedef enum hio_canon_path_flag_t hio_canon_path_flag_t;
|
2020-05-04 08:40:05 +00:00
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#define HIO_CANON_OOCSTR_PATH_EMPTY_SINGLE_DOT HIO_CANON_PATH_EMPTY_SINGLE_DOT
|
|
|
|
#define HIO_CANON_OOCSTR_PATH_KEEP_DOUBLE_DOTS HIO_CANON_PATH_KEEP_DOUBLE_DOTS
|
|
|
|
#define HIO_CANON_OOCSTR_PATH_DROP_TRAILING_SEP HIO_CANON_PATH_DROP_TRAILING_SEP
|
2020-05-04 08:40:05 +00:00
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#define HIO_CANON_UCSTR_PATH_EMPTY_SINGLE_DOT HIO_CANON_PATH_EMPTY_SINGLE_DOT
|
|
|
|
#define HIO_CANON_UCSTR_PATH_KEEP_DOUBLE_DOTS HIO_CANON_PATH_KEEP_DOUBLE_DOTS
|
|
|
|
#define HIO_CANON_UCSTR_PATH_DROP_TRAILING_SEP HIO_CANON_PATH_DROP_TRAILING_SEP
|
2020-05-04 08:40:05 +00:00
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#define HIO_CANON_BCSTR_PATH_EMPTY_SINGLE_DOT HIO_CANON_PATH_EMPTY_SINGLE_DOT
|
|
|
|
#define HIO_CANON_BCSTR_PATH_KEEP_DOUBLE_DOTS HIO_CANON_PATH_KEEP_DOUBLE_DOTS
|
|
|
|
#define HIO_CANON_BCSTR_PATH_DROP_TRAILING_SEP HIO_CANON_PATH_DROP_TRAILING_SEP
|
2020-05-04 08:40:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_IS_PATH_SEP(c) ((c) == '/' || (c) == '\\')
|
2020-05-04 08:40:05 +00:00
|
|
|
|
|
|
|
#else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_IS_PATH_SEP(c) ((c) == '/')
|
2020-05-04 08:40:05 +00:00
|
|
|
#endif
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#define HIO_IS_PATH_DRIVE(s) \
|
2020-05-04 08:40:05 +00:00
|
|
|
(((s[0] >= 'A' && s[0] <= 'Z') || \
|
|
|
|
(s[0] >= 'a' && s[0] <= 'z')) && \
|
|
|
|
s[1] == ':')
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#define HIO_IS_PATH_SEP_OR_NIL(c) (HIO_IS_PATH_SEP(c) || (c) == '\0')
|
2020-05-04 08:40:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
HIO_EXPORT hio_oow_t hio_canon_ucstr_path (
|
|
|
|
const hio_uch_t* path,
|
|
|
|
hio_uch_t* canon,
|
2020-05-04 08:40:05 +00:00
|
|
|
int flags
|
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
HIO_EXPORT hio_oow_t hio_canon_bcstr_path (
|
|
|
|
const hio_bch_t* path,
|
|
|
|
hio_bch_t* canon,
|
2020-05-04 08:40:05 +00:00
|
|
|
int flags
|
|
|
|
);
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|