File cwalk.h

File List > engine > include > cwalk.h

Go to the documentation of this file

#pragma once

#ifndef CWK_LIBRARY_H
#define CWK_LIBRARY_H

#include <stdbool.h>
#include <stddef.h>

#if defined(_WIN32) || defined(__CYGWIN__)
#define CWK_EXPORT __declspec(dllexport)
#define CWK_IMPORT __declspec(dllimport)
#elif __GNUC__ >= 4
#define CWK_EXPORT __attribute__((visibility("default")))
#define CWK_IMPORT __attribute__((visibility("default")))
#else
#define CWK_EXPORT
#define CWK_IMPORT
#endif

#if defined(CWK_SHARED)
#if defined(CWK_EXPORTS)
#define CWK_PUBLIC CWK_EXPORT
#else
#define CWK_PUBLIC CWK_IMPORT
#endif
#else
#define CWK_PUBLIC
#endif

#ifdef __cplusplus
extern "C"
{
#endif

struct cwk_segment
{
  const char *path;
  const char *segments;
  const char *begin;
  const char *end;
  size_t size;
};

enum cwk_segment_type
{
  CWK_NORMAL,
  CWK_CURRENT,
  CWK_BACK
};

enum cwk_path_style
{
  CWK_STYLE_WINDOWS,
  CWK_STYLE_UNIX
};

CWK_PUBLIC size_t cwk_path_get_absolute(const char *base, const char *path,
  char *buffer, size_t buffer_size);

CWK_PUBLIC size_t cwk_path_get_relative(const char *base_directory,
  const char *path, char *buffer, size_t buffer_size);

CWK_PUBLIC size_t cwk_path_join(const char *path_a, const char *path_b,
  char *buffer, size_t buffer_size);

CWK_PUBLIC size_t cwk_path_join_multiple(const char **paths, char *buffer,
  size_t buffer_size);

CWK_PUBLIC void cwk_path_get_root(const char *path, size_t *length);

CWK_PUBLIC size_t cwk_path_change_root(const char *path, const char *new_root,
  char *buffer, size_t buffer_size);

CWK_PUBLIC bool cwk_path_is_absolute(const char *path);

CWK_PUBLIC bool cwk_path_is_relative(const char *path);

CWK_PUBLIC void cwk_path_get_basename(const char *path, const char **basename,
  size_t *length);

CWK_PUBLIC size_t cwk_path_change_basename(const char *path,
  const char *new_basename, char *buffer, size_t buffer_size);

CWK_PUBLIC void cwk_path_get_dirname(const char *path, size_t *length);

CWK_PUBLIC bool cwk_path_get_extension(const char *path, const char **extension,
  size_t *length);

CWK_PUBLIC bool cwk_path_has_extension(const char *path);

CWK_PUBLIC size_t cwk_path_change_extension(const char *path,
  const char *new_extension, char *buffer, size_t buffer_size);

CWK_PUBLIC size_t cwk_path_normalize(const char *path, char *buffer,
  size_t buffer_size);

CWK_PUBLIC size_t cwk_path_get_intersection(const char *path_base,
  const char *path_other);

CWK_PUBLIC bool cwk_path_get_first_segment(const char *path,
  struct cwk_segment *segment);

CWK_PUBLIC bool cwk_path_get_last_segment(const char *path,
  struct cwk_segment *segment);

CWK_PUBLIC bool cwk_path_get_next_segment(struct cwk_segment *segment);

CWK_PUBLIC bool cwk_path_get_previous_segment(struct cwk_segment *segment);

CWK_PUBLIC enum cwk_segment_type cwk_path_get_segment_type(
  const struct cwk_segment *segment);

CWK_PUBLIC size_t cwk_path_change_segment(struct cwk_segment *segment,
  const char *value, char *buffer, size_t buffer_size);

CWK_PUBLIC bool cwk_path_is_separator(const char *str);

CWK_PUBLIC enum cwk_path_style cwk_path_guess_style(const char *path);

CWK_PUBLIC void cwk_path_set_style(enum cwk_path_style style);

CWK_PUBLIC enum cwk_path_style cwk_path_get_style(void);

#ifdef __cplusplus
} // extern "C"
#endif

#endif