Yzena
/
Yc
2
1
Fork 0
Browse Source

Add the fs module back

Even though it was written by others, I need speed of development more
than anything else right now. I'll replace it later.

Signed-off-by: Gavin Howard <gavin@yzena.com>
afl_persistent_mode
Gavin Howard 8 months ago
parent
commit
187e4243f5
Signed by: gavin
GPG Key ID: C08038BDF280D33E
  1. 33
      NOTICE.md
  2. 2
      benchmarks/arith.c
  3. 2
      include/yc/alloc.h
  4. 2
      include/yc/arith.h
  5. 2
      include/yc/array.h
  6. 2
      include/yc/assert.h
  7. 2
      include/yc/atomics.h
  8. 2
      include/yc/error.h
  9. 672
      include/yc/fs.h
  10. 2
      include/yc/hash.h
  11. 2
      include/yc/json.h
  12. 2
      include/yc/map.h
  13. 2
      include/yc/mappool.h
  14. 4
      include/yc/ntree.h
  15. 2
      include/yc/num.h
  16. 2
      include/yc/nvector.h
  17. 183
      include/yc/opt.h
  18. 2
      include/yc/rig.h
  19. 2
      include/yc/simd.h
  20. 2
      include/yc/stack.h
  21. 2
      include/yc/stdio.h
  22. 2
      include/yc/str.h
  23. 2
      include/yc/string.h
  24. 2
      include/yc/strucon.h
  25. 2
      include/yc/tree.h
  26. 2
      include/yc/types.h
  27. 2
      include/yc/vector.h
  28. 2
      include/yc/yao.h
  29. 2
      include/yc/yc.h
  30. 2
      include/yc/yvm.h
  31. 42
      samples/fs/CMakeLists.txt
  32. 108
      samples/fs/file_open.c
  33. 147
      samples/fs/interactive.c
  34. 104
      samples/fs/iterate.c
  35. 142
      samples/fs/list_to_file.c
  36. 108
      samples/fs/random_access.c
  37. 8
      src/CMakeLists.txt
  38. 2
      src/arith.c
  39. 6
      src/assert.c
  40. 42
      src/fs/CMakeLists.txt
  41. 409
      src/fs/dir.c
  42. 179
      src/fs/dirent.c
  43. 147
      src/fs/file.c
  44. 169
      src/fs/fs.c
  45. 418
      src/fs/fs.h
  46. 48
      src/fs/os/CMakeLists.txt
  47. 31
      src/fs/os/posix/CMakeLists.txt
  48. 112
      src/fs/os/posix/dir.c
  49. 112
      src/fs/os/posix/posix.h
  50. 31
      src/fs/os/unix/CMakeLists.txt
  51. 249
      src/fs/os/unix/fs.c
  52. 102
      src/fs/os/unix/unix.h
  53. 40
      src/fs/os/windows/CMakeLists.txt
  54. 310
      src/fs/os/windows/fs.c
  55. 30
      src/fs/os/windows/msvc/CMakeLists.txt
  56. 127
      src/fs/os/windows/msvc/dir.c
  57. 174
      src/fs/os/windows/windows.h
  58. 237
      src/fs/path.c
  59. 2
      src/hash/hash.c
  60. 2
      src/hash/hash.h
  61. 2
      src/map/map.c
  62. 2
      src/map/map.h
  63. 2
      src/mappool/mappool.c
  64. 2
      src/mappool/mappool.h
  65. 29
      src/opt/CMakeLists.txt
  66. 484
      src/opt/opt.c
  67. 2
      src/pty/ceive.c
  68. 2
      src/pty/ceive.h
  69. 2
      src/stack/stack.c
  70. 2
      src/stdio.c
  71. 4
      src/str/str.c
  72. 2
      src/string/str.h
  73. 2
      src/string/string.c
  74. 2
      src/tree/ntree.c
  75. 2
      src/tree/ntree.h
  76. 2
      src/tree/tree.c
  77. 2
      src/tree/tree.h
  78. 2
      src/vector/nvector.c
  79. 2
      src/vector/vec.c
  80. 2
      src/vector/vec.h
  81. 2
      src/vector/vector.c
  82. 2
      src/yao/alloc.yvm
  83. 2
      src/yao/bootstrap/ast.c
  84. 2
      src/yao/bootstrap/ast.h
  85. 2
      src/yao/bootstrap/lex.c
  86. 2
      src/yao/bootstrap/lex.h
  87. 2
      src/yao/bootstrap/parse.c
  88. 2
      src/yao/bootstrap/parse.h
  89. 2
      src/yao/bootstrap/yao_lex.c
  90. 2
      src/yao/bootstrap/yao_parse.c
  91. 2
      src/yao/bootstrap/yvm_lex.c
  92. 2
      src/yao/bootstrap/yvm_parse.c
  93. 2
      src/yao/build.yao
  94. 2
      src/yao/example.y
  95. 2
      src/yao/main.y
  96. 2
      src/yao/path.y
  97. 2
      src/yao/posix.yvm
  98. 2
      src/yao/stdlib.yao
  99. 2
      src/yc.c
  100. 2
      src/yc.h
  101. Some files were not shown because too many files have changed in this diff Show More

33
NOTICE.md

@ -8,6 +8,39 @@ considered part of the "source code" as defined by that license.
[1]: https://yzena.com/yzena-network-license/
## tinydir
Yc contains code originally from [tinydir](https://github.com/cxong/tinydir),
which is under the following copyright and license:
> Copyright (c) 2013-2016, tinydir authors:
> - Cong Xu
> - Lautis Sun
> - Baudouin Feildel
> - Andargor <andargor@yahoo.com>
> 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
## `tests/map/map_countwords.c`
The file `tests/map/map_countwords.c` was created from code that was under the

2
benchmarks/arith.c

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/alloc.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/arith.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/array.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/assert.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/atomics.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/error.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

672
include/yc/fs.h

@ -0,0 +1,672 @@
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech
*
* Licensed under the Yzena Network License, Version 0.1 (the "Yzena Network
* License" or "YNL"). You may not use this file except in compliance with the
* Yzena Network License.
*
* You may obtain a copy of the Yzena Network License at
*
* https://yzena.com/yzena-network-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Yzena Network License is distributed under the
* following disclaimer:
*
* As far as the law allows, this software comes as is, without any
* warranty or condition, and no contributor will be liable to anyone for
* any damages related to this software or this license, under any kind of
* legal claim.
*
* ****** END LICENSE BLOCK ******
*
* *****************************************************************
*
* ******* BEGIN FILE DESCRIPTION *******
*
* Main public header file for Yfs.
*
* ******** END FILE DESCRIPTION ********
*/
#ifndef YC_FILE_H
#define YC_FILE_H
/* For C++ compatibility */
#ifdef __cplusplus
extern "C" {
#endif
#include <yc/yc.h>
#include <stdbool.h>
#include <stdint.h>
/**
* @file yc/fs.h
*/
/**
* @def YFS_PATH_SEP
* A define that is the correct path separator for the platform as a char.
*/
/**
* @def YFS_PATH_SEP_STR
* A define that is the correct path separator for the platform as a string.
*/
/**
* @def YFS_PATH_EXTRA
* The extra amount of space needed for paths for the platform.
*/
#if defined(_MSC_VER) || defined(__MINGW32__)
#define YFS_PATH_MAX (MAX_PATH)
#ifdef _MSC_VER
// Extra chars for the "\\*" mask.
#define YFS_PATH_EXTRA (2)
#endif
#define YFS_PATH_SEP (YPATHSTR('\\'))
#define YFS_PATH_SEP_STR (YPATHSTR("\\"))
#else
#ifdef __linux__
#include <limits.h>
#define YFS_PATH_MAX (PATH_MAX)
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#include <sys/param.h>
#if defined(BSD)
#include <limits.h>
#define YFS_PATH_MAX (PATH_MAX)
#endif
#endif
#define YFS_PATH_SEP (YPATHSTR('/'))
#define YFS_PATH_SEP_STR (YPATHSTR("/"))
#endif
#ifndef _MSC_VER
#include <sys/stat.h>
#include <dirent.h>
#include <libgen.h>
#include <stddef.h>
#define YFS_PATH_EXTRA (0)
#endif
/**
* @defgroup dir dir
* @{
*/
/**
* The public type for directories. This
* is a pointer to hide the implementation.
*/
typedef struct ydir* YDir;
/**
* @}
*/
/**
* @defgroup dirent dirent
* @{
*/
/**
* A struct to contain information
* about a directory entry.
*/
typedef struct YStat
{
/// The size of the entry, in bytes, on disk.
/// For files, this is the file size.
size_t size;
/// Whether the entry is a directory or not.
bool dir;
/// Whether the entry is a file or not.
bool file;
/// Whether the current user can read the entry or not.
bool read;
/// Whether the current user can write to the entry or not.
bool write;
/// Whether the current user can execute
/// the file or search the directory.
bool execute;
} YStat;
/**
* @}
*/
/**
* @defgroup yfs yfs
* Functions and data structures common to all of Yfs.
* @{
*/
/**
* @}
*/
/**
* @defgroup path path
* Functions and data types for paths.
* @{
*/
/**
* @def YFS_PATH_MAX
* The max number of ychar's that a path can contain.
*/
#ifndef YFS_PATH_MAX
#define YFS_PATH_MAX (4096)
#endif
/**
* @def YFS_FILENAME_MAX
* The max number of ychar's that a file (entry) name can contain.
*/
#define YFS_FILENAME_MAX (256)
/**
* A common definition for paths.
* Paths should not be modified.
*/
typedef ychar* YPath;
/**
* Removes the item at @a path.
* @param path The path to the item to remove.
* @return YSTATUS_SUCCESS on success,
* an error code otherwise.
*/
YStatus
yfs_path_remove(const YPath path) yallnonnull yinline;
/**
* Retrieves information about the item at @a path and
* returns it in the @a YStat struct pointed to by @a st.
* @param path The path to the item to collect data about.
* @param st A pointer to the structure to fill.
* @return YSTATUS_SUCCESS on success, an error
* code otherwise.
*/
YStatus
yfs_path_stat(const YPath path, YStat* st) yallnonnull;
/**
* Opens the parent directory of the item at @a path.
* The directory must be closed with @a yfs_dir_close().
* @param path The path to the item whose directory
* parent will be opened.
* @return The newly-created YDir, or NULL and @a
* ystatus will be set the the error.
*/
YDir
yfs_path_parent(YPath path) yallnonnull ynoretalias;
/**
* Gets the directory (parent) name of @a path. The
* path must be freed with @a yfs_path_free().
* @param path The path to get the dirname for.
* @return The dirname of @a path, or NULL
* on error with @a ystatus set.
*/
ychar*
yfs_path_dirname(YPath path) yallnonnull ynoretalias;
/**
* Gets the base (file) name of @a path. The
* path must be freed with @a yfs_path_free().
* @param path The path to get the basename for.
* @return The basename of @a path, or NULL
* on error with @a ystatus set.
*/
ychar*
yfs_path_basename(YPath path) yallnonnull ynoretalias;
/**
* Gets the path of the home directory. The
* path must be freed with @a yfs_path_free().
* @return The home directory path, or NULL
* on error with @a ystatus set.
*/
ychar*
yfs_path_home(void) ynoretalias;
/**
* Gets the path of the temp directory. The
* path must be freed with @a yfs_path_free().
* @return The temp directory path, or NULL
* on error with @a ystatus set.
*/
ychar*
yfs_path_temp(void) ynoretalias;
/**
* Returns the index within @a path that the file extension starts,
* not including the leading period.
* If there is no extension, this returns strlen(@a path).
* @param path The path to query for the extension.
* @return The index of the path that the extension starts.
*/
uint32_t
yfs_path_extIdx(const ychar path[]) yallnonnull;
/**
* Concatenates @a path and @a name into one
* path and returns the result. The path must
* be freed with @a yfs_path_free().
* @param path The beginning part of the path.
* @param name The file name.
* @return The concatenated path.
*/
ychar*
yfs_path_concat(YPath path, YPath name) yallnonnull ynoretalias;
/**
* Frees @a path.
* @param path The path to free.
*/
void
yfs_path_free(ychar path[]) yallnonnull yinline;
/**
* @}
*/
/**
* @defgroup dirent dirent
* Functions and data structures to manipulate directory entries.
* @{
*/
/**
* The public type for directory entries.
* Entries are always within the context
* of an open directory.
*/
typedef uint32_t YDirent;
/**
* Returns a pointer to the entry's name.
* @param parent The parent directory.
* @param dirent The index of the entry in the
* parent directory.
* @return A pointer to the name. This
* pointer is invalidated if the
* parent is changed in any way.
* @pre @a parent must be opened.
* @pre @a parent must have an entry
* associated with @a dirent.
*/
YPath
yfs_dirent_name(const YDir parent, YDirent dirent) yallnonnull yinline;
/**
* Returns a pointer to the entry's extension.
* @param parent The parent directory.
* @param dirent The index of the entry in the
* parent directory.
* @return A pointer to the extension. This
* pointer is invalidated if the
* parent is changed in any way.
* @pre @a parent must be opened.
* @pre @a parent must have an entry
* associated with @a dirent.
*/
YPath
yfs_dirent_ext(const YDir parent, YDirent dirent) yallnonnull yinline;
/**
* Returns the size of the entry (file size or
* directory data size in bytes).
* @param parent The parent directory.
* @param dirent The index of the entry in the
* parent directory.
* @return The entry's size, in bytes.
* @pre @a parent must be opened.
* @pre @a parent must have an entry
* associated with @a dirent.
*/
size_t
yfs_dirent_size(const YDir parent, YDirent dirent) yallnonnull yinline;
/**
* Returns true if the entry is a directory.
* @param parent The parent directory.
* @param dirent The index of the entry in the
* parent directory.
* @return true if directory, false otherwise.
* @pre @a parent must be opened.
* @pre @a parent must have an entry
* associated with @a dirent.
*/
bool
yfs_dirent_isDir(const YDir parent, YDirent dirent) yallnonnull yinline;
/**
* Returns true if the entry is a file.
* @param parent The parent directory.
* @param dirent The index of the entry in the
* parent directory.
* @return true if file, false otherwise.
* @pre @a parent must be opened.
* @pre @a parent must have an entry
* associated with @a dirent.
*/
bool
yfs_dirent_isFile(const YDir parent, YDirent dirent) yallnonnull yinline;
/**
* Returns true if the entry can be read by the
* current user.
* @param parent The parent directory.
* @param dirent The index of the entry in the
* parent directory.
* @return true if the entry can be read,
* false otherwise.
* @pre @a parent must be opened.
* @pre @a parent must have an entry
* associated with @a dirent.
*/
bool
yfs_dirent_canRead(const YDir parent, YDirent dirent) yallnonnull yinline;
/**
* Returns true if the entry can be written by the
* current user.
* @param parent The parent directory.
* @param dirent The index of the entry in the
* parent directory.
* @return true if the entry can be written,
* false otherwise.
* @pre @a parent must be opened.
* @pre @a parent must have an entry
* associated with @a dirent.
*/
bool
yfs_dirent_canWrite(const YDir parent, YDirent dirent) yallnonnull yinline;
/**
* Returns true if the entry can be executed (or
* searched in the case of directories) by the
* current user.
* @param parent The parent directory.
* @param dirent The index of the entry in the
* parent directory.
* @return true if the entry can be executed
* or searched, false otherwise.
* @pre @a parent must be opened.
* @pre @a parent must have an entry
* associated with @a dirent.
*/
bool
yfs_dirent_canExecute(const YDir parent, YDirent dirent) yallnonnull yinline;
/**
* @}
*/
/**
* @defgroup dir dir
* Functions and data structures to manipulate directories.
* @{
*/
/**
* Creates the directory at @a path.
* @param path The path to create the directory at.
* @return YSTATUS_SUCCESS on success,
* an error code otherwise.
*/
YStatus
yfs_dir_create(YPath path) yallnonnull;
/**
* Creates the directory at @a path, making sure to
* create any missing parent directories.
* @param path The path to create the directory at.
* @return YSTATUS_SUCCESS on success,
* an error code otherwise.
*/
YStatus
yfs_dir_createWithParents(YPath path) yallnonnull;
/**
* Opens and returns the directory at @a path.
* The opened directory must be closed by using
* @a yfs_dir_close().
* @param path The path to open the directory at.
* @return The opened directory, or NULL on
* error with @a ystatus set.
*/
YDir
yfs_dir_open(YPath path) yallnonnull ynoretalias;
/**
* Reopens @a dir with @a path.
* @param d The directory to reopen.
* @param path The path to open the directory at.
* @return YSTATUS_SUCCESS on success, an
* error code otherwise.
* @pre @a d must have been opened.
*/
YStatus
yfs_dir_reopen(YDir d, YPath path) yallnonnull;
/**
* Sorts the open directory @a d.
* @param d The directory to sort.
* @param dirsFirst Whether to put directories
* first or not.
* @pre @a d must have been opened.
*/
void
yfs_dir_sort(YDir d, bool dirsFirst) yallnonnull;
/**
* Unsorts @a d. This does not change the order of
* any entries, but if the directory is reopened with
* another path, or used to open its parent or a
* subdirectory, the new one will not be sorted.
* @param d The directory to not sort.
* @pre @a d must have been opened.
*/
void
yfs_dir_unsort(YDir d);
/**
* Opens the subdirectory of @a d at entry @a i.
* The directory must not be closed first.
* @param d The directory whose subdirectory
* will be opened.
* @param i The index of the entry that will
* be opened.
* @return YSTATUS_SUCCESS on success,
* an error code otherwise.
* @pre @a d must have been opened.
*/
YStatus
yfs_dir_subdir(YDir d, YDirent i) yallnonnull;
/**
* Opens the parent of @a d into @a d.
* The directory must not be closed first.
* @param d The directory whose parent
* will be opened.
* @return YSTATUS_SUCCESS on success,
* an error code otherwise.
* @pre @a d must have been opened.
*/
YStatus
yfs_dir_parent(YDir d) yallnonnull;
/**
* Opens the home directory into @a d. The directory
* must not be closed first.
* @param d The directory into which the home directory
* will be opened.
* @return YSTATUS_SUCCESS on success,
* an error code otherwise.
* @pre @a d must have been opened.
*/
YStatus
yfs_dir_home(YDir d);
/**
* Returns a pointer to the path of @a dir.
* The pointer will be invalidated if it is
* reopened or closed, or if its parent or
* a subdirectory is opened.
* @param dir The directory to query.
* @return The path of the directory.
* @pre @a dir must have been opened.
*/
YPath
yfs_dir_path(YDir dir) yallnonnull yinline;
/**
* Returns the number of entries in @a dir.
* @param dir The directory to query.
* @return The number of entries in @a dir.
* @pre @a dir must have been opened.
*/
uint32_t
yfs_dir_numEntries(YDir dir) yallnonnull yinline;
/**
* Returns true if @a dir is sorted, false otherwise.
* @param dir The directory to query.
* @return true if sorted, false otherwise.
* @pre @a dir must have been opened.
*/
bool
yfs_dir_sorted(YDir dir) yallnonnull yinline;
/**
* Returns true if @a dir is sorted with directories
* first, false otherwise.
* @param dir The directory to query.
* @return true if sorted with directories first,
* false otherwise.
* @pre @a dir must have been opened.
*/
bool
yfs_dir_dirsFirst(YDir dir) yallnonnull yinline;
/**
* Closes the directory @a dir.
* @param dir The directory to close.
* @pre @a dir must have been opened.
*/
void
yfs_dir_close(YDir dir) yallnonnull;
/**
* @}
*/
/**
* @defgroup file file
* Functions and data structures to manipulate files.
* @{
*/
/**
* Creates the file at @a path.
* @param path The path to create the file at.
* @return YSTATUS_SUCCESS on success,
* an error code otherwise.
*/
YStatus
yfs_file_create(YPath path) yallnonnull yinline;
/**
* Creates the file at @a path, making sure to
* create any missing parent directories.
* @param path The path to create the file at.
* @return YSTATUS_SUCCESS on success,
* an error code otherwise.
*/
YStatus
yfs_file_createWithParents(YPath path) yallnonnull;
/**
* Creates a temp file name, creates the file, and returns
* the path to the file.
* @param dir The directory to create the file in.
* @param prefix The prefix to prepend to the file name.
* @return The path of the temp file, or NULL on
* error with @a ystatus set.
*/
ychar*
yfs_file_temp(YPath dir, YPath prefix) yallnonnull ynoretalias;
/**
* The public definition of Yfs file contents.
* This allows the user to index it directly.
*/
typedef char* YFile;
/**
* Reads the entirety of the file at @a path and returns a
* @a YFile (byte array) with the contents. The param
* @a binary indicates whether the file is a binary file
* or not. If not, Yfs will add a terminating null char.
*
* The file must be freed with @a yfs_file_free().
* @param path The path to the file.
* @param binary true if the file is a binary file,
* false otherwise.
* @return The new @a YFile, or NULL on error and
* @a ystatus is set to the error code.
*/
YFile
yfs_file_read(YPath path, bool binary) yallnonnull ynoretalias;
/**
* Frees the data read into a YFile.
* @param file The file data to free.
*/
void
yfs_file_free(YFile file) yallnonnull yinline;
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // YC_FILE_H

2
include/yc/hash.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/json.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/map.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/mappool.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

4
include/yc/ntree.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech
@ -34,7 +34,7 @@
#ifndef YC_NTREE_H
#define YC_NTREE_H
/* For C++ compatibility */
// For C++ compatibility.
#ifdef __cplusplus
extern "C" {
#endif

2
include/yc/num.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/nvector.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

183
include/yc/opt.h

@ -20,13 +20,20 @@
* any damages related to this software or this license, under any kind of
* legal claim.
*
* *****************************************************************
*
* This code was modified from public domain code at:
*
* https://github.com/skeeto/optparse/
* https://github.com/eeeeeeeelias/optparse
*
* ****** END LICENSE BLOCK ******
*
* *****************************************************************
*
* ******* BEGIN FILE DESCRIPTION *******
*
* The public header file for option parsing.
* Header for option parsing.
*
* ******** END FILE DESCRIPTION ********
*/
@ -34,90 +41,150 @@
#ifndef YC_OPT_H
#define YC_OPT_H
/* For C++ compatibility */
#ifdef __cplusplus
extern "C" {
#endif
#include <yc/opt.h>
#include <yc/vector.h>
#include <yc/yc.h>
//! @cond Doxygen suppress.
#include <stdbool.h>
#include <stdint.h>
//! @endcond
#include <yc/yc.h>
/**
* @file yc/opt.h
* State for parsing command-line options.
*/
typedef struct YOpt
{
/// The command-line options.
ychar** argv;
/**
* @defgroup opt opt
* Public function definitions and types for option parsing.
* @{
*/
/// The argument given to an option.
ychar* optarg;
/// The index of the current option.
unsigned int optind;
//! @cond Doxygen suppress.
/// The value that will be returned.
unsigned int optopt;
typedef YStatus (*YOptCharF)(const char*, const uint32_t, const char*);
/// The index in the current set of options where the current option is.
unsigned int subopt;
/// If true, permutation is allowed.
bool permute;
/// An error message.
YVector errmsg;
} YOpt;
typedef enum YOptType
{
YOPT_NONE,
YOPT_REQUIRED,
YOPT_OPTIONAL,
YOPT_OPTIONAL
} YOptType;
typedef union YOptCharData
/**
* Information about valid long options.
*/
typedef struct YOptLong
{
bool* flag;
char* arg;
} YOptCharData;
/// The actual name of the long option.
const ychar* longname;
typedef struct YOptOption
{
uint32_t character;
/// The value that will be returned for the option.
unsigned int shortname;
/// The option type.
YOptType type;
YOptCharData data;
YOptCharF func;
char* desc;
} YOptOption;
typedef struct YOptArg
{
char* name;
char* desc;
} YOptArg;
} YOptLong;
typedef enum YOptCmdType
{
YOPT_CMD_CMD,
YOPT_CMD_PARENT,
} YOptCmdType;
/**
* Initializes the parser state.
* @param o The YOpt to initialize.
* @param argv The argument list that will be parsed.
* @pre @a o must not be NULL.
* @pre @a argv must not be NULL.
*/
yallnonnull void
yopt_init(YOpt* o, ychar** argv);
struct YOptCmd;
/**
* Puts a new argv into the parser state. This is for parsing more than one
* argument set.
* @param o The YOpt to initialize.
* @param argv The argument list that will be parsed.
* @pre @a o must not be NULL.
* @pre @a argv must not be NULL.
*/
yallnonnull void
yopt_argv(YOpt* o, ychar** argv);
typedef union YOptCmdData
{
struct YOptCmd* cmds;
YOptArg* args;
} YOptCmdData;
/**
* Frees the parser state.
* @param options The YOpt to free.
* @pre @a options must not be NULL.
*/
yallnonnull void
yopt_free(void* options);
typedef struct YOptCmd
{
YOptCmdType type;
char* name;
char* desc;
YOptOption* options;
} YOpt;
/**
* Reads the next option in the argv array.
*
* Just like getopt(), a character followed by no colons means no
* argument. One colon means the option has a required argument. Two
* colons means the option takes an optional argument.
*
* @param o The parse state.
* @param optstring A getopt()-formatted option string.
* @return The next option character, -1 for done, or '?' for error.
* @pre @a opts must not be NULL.
* @pre @a optstring must not be NULL.
*/
yallnonnull int
yopt_parse(YOpt* o, const ychar* optstring);
//! @endcond Doxygen suppress.
/**
* Handles GNU-style long options in addition to getopt() options.
*
* This works a lot like GNU's getopt_long(). The last option in
* longopts must be all zeros, marking the end of the array. The
* longindex argument may be NULL.
*
* @param o The parse state.
* @param longopts The long options.
* @param longidx The index of the found long option in @a longopts.
* @return The next option character, -1 for done, or '?' for error.
* @pre @a o must not be NULL.
* @pre @a longopts must not be NULL.
*/
int
yopt_parse_long(YOpt* o, const YOptLong* longopts, int* longidx);
/**
* @}
* Works a lot like GNU's getopt_long_only().
* @param o The parse state.
* @param longopts The long options.
* @param longidx The index of the found long option in @a longopts.
* @return The next option character, -1 for done, or '?' for error.
* @pre @a o must not be NULL.
* @pre @a longopts must not be NULL.
*/
int
yopt_parse_long_only(YOpt* o, const YOptLong* longopts, int* longidx);
#ifdef __cplusplus
}
#endif
/**
* Steps over non-option arguments.
*
* Argument parsing can continue with optparse() after using this
* function. That would be used to parse the options for the
* subcommand returned by optparse_arg(). This function allows you to
* ignore the value of optind.
*
* @param o The parse state.
* @return The next non-option argument, or NULL for no more arguments.
* @pre @a o must not be NULL.
*/
ychar*
yopt_arg(YOpt* o);
#endif // YC_OPT_H

2
include/yc/rig.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/simd.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/stack.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2018-2020 Yzena Tech

2
include/yc/stdio.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/str.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/string.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/strucon.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/tree.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/types.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/vector.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/yao.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

2
include/yc/yc.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2020 Yzena Tech

2
include/yc/yvm.h

@ -1,4 +1,4 @@
/*
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech

42
samples/fs/CMakeLists.txt

@ -0,0 +1,42 @@
# ***** BEGIN LICENSE BLOCK *****
#
# Copyright 2017-2021 Yzena Tech
#
# Licensed under the Yzena Network License, Version 0.1 (the "Yzena Network
# License" or "YNL"). You may not use this file except in compliance with the
# Yzena Network License.
#
# You may obtain a copy of the Yzena Network License at
#
# https://yzena.com/yzena-network-license/
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Yzena Network License is distributed under the
# following disclaimer:
#
# As far as the law allows, this software comes as is, without any
# warranty or condition, and no contributor will be liable to anyone for
# any damages related to this software or this license, under any kind of
# legal claim.
#
# ****** END LICENSE BLOCK ******
################################
# Add definitions
if(MSVC)
add_definitions(-W4 -WX -wd"4996")
endif()
################################
# Add targets
add_executable(file_open file_open.c)
target_link_libraries(file_open "${PROJECT_NAME}")
add_executable(file_iterate iterate.c)
target_link_libraries(file_iterate "${PROJECT_NAME}")
add_executable(file_random_access random_access.c)
target_link_libraries(file_random_access "${PROJECT_NAME}")
add_executable(file_interactive interactive.c)
target_link_libraries(file_interactive "${PROJECT_NAME}")
add_executable(list_to_file list_to_file.c)
target_link_libraries(list_to_file "${PROJECT_NAME}")

108
samples/fs/file_open.c

@ -0,0 +1,108 @@
/**
* ***** BEGIN LICENSE BLOCK *****
*
* Copyright 2017-2021 Yzena Tech
*
* Licensed under the Yzena Network License, Version 0.1 (the "Yzena Network
* License" or "YNL"). You may not use this file except in compliance with the
* Yzena Network License.
*
* You may obtain a copy of the Yzena Network License at
*
* https://yzena.com/yzena-network-license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Yzena Network License is distributed under the
* following disclaimer:
*
* As far as the law allows, this software comes as is, without any
* warranty or condition, and no contributor will be liable to anyone for
* any damages related to this software or this license, under any kind of
* legal claim.
*
* *****************************************************************
*
* This code was modified from code with the following copyright and license:
*
* Copyright (c) 2013-2017, tinydir authors:
* - Cong Xu
* - Lautis Sun
* - Baudouin Feildel
* - Andargor <andargor@yahoo.com>
* 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
*
* ****** END LICENSE BLOCK ******
*
* *****************************************************************
*
* ******* BEGIN FILE DESCRIPTION *******
*
* A sample to open a file.
*
* ******** END FILE DESCRIPTION ********
*/
#include <yc/fs.h>
#include <yc/stdio.h>
static const char yes[] = "yes";