Added new function; yon_dir_get_contents marked as deprecated

pull/83/head
parent 427bf1a542
commit fd4d701367

@ -140,6 +140,17 @@ config_str yon_file_ls(char *path, int *size){
return NULL; return NULL;
} }
char *yon_file_get_parent(const char *path){
if (yon_char_is_empty(path)|| !strstr(path,"/")) return NULL;
char *parent_path = NULL;
int size;
config_str parsed = yon_char_parse(path,&size,"/");
free(parsed[size-1]);
parsed[size-1] = NULL;
parent_path = yon_char_parsed_to_string_full(parsed,size,"/");
return parent_path;
}
int yon_file_is_directory(const char *path) int yon_file_is_directory(const char *path)
{ {
struct stat path_stat; struct stat path_stat;

@ -68,7 +68,7 @@ void yon_locale_set(struct yon_locale *target,char *locale_name){
void yon_locale_init(){ void yon_locale_init(){
int size; int size;
config_str locales_list = yon_dir_get_contents(locales_path,&size); config_str locales_list = yon_file_ls(locales_path,&size);
locales_hash_table = yon_hash_new(size*2,yon_str_hash); locales_hash_table = yon_hash_new(size*2,yon_str_hash);
for (int i=0;i<size;i++){ for (int i=0;i<size;i++){
if (!strcmp(locales_list[i],".")||!strcmp(locales_list[i],"..")) continue; if (!strcmp(locales_list[i],".")||!strcmp(locales_list[i],"..")) continue;

@ -1114,78 +1114,56 @@ double yon_size_long_convert_to_mod(double size, char mod);
double yon_size_long_convert_automatic(unsigned long bytes, char *size); double yon_size_long_convert_automatic(unsigned long bytes, char *size);
/**yon_file_path_proceed_spaces(char *path) /// @brief Wrap all spaces in paths for proper handling in commands
* [EN] /// @return A newly allocated string or NULL if path was empty.
*
* [RU]
* Оборачивает все пробелы в пути для правильной обработки
*/
char *yon_file_path_proceed_spaces(char *path); char *yon_file_path_proceed_spaces(char *path);
/**yon_file_open(char *file_path, int *size) /// @brief Read file and return its contents as string array, separated by new line symbols.
* [EN] /// @param file_path Path to file.
* /// @param size Size of returned list.
* [RU] /// @return A newly allocated array of strings containing the entire contents of the file.
* Открывает файл [file_path], возвращает содержимое в виде массива строк размера [size]
*/
config_str yon_file_open(char *file_path, int *size); config_str yon_file_open(char *file_path, int *size);
/**yon_file_save(char *file_path, char *text) /// @brief Save string to file
* [EN] /// @param file_path File where text will be saved.
* /// @param text Text to save.
* [RU] /// @return TRUE if successful, FALSE otherwise
* Сохранить текст [text] в файл по пути [file_path]. Если файла не существует, он создаётся
*/
int yon_file_save(char *file_path, char *text); int yon_file_save(char *file_path, char *text);
/**yon_file_create(char *path, char *name, int rules) /// @brief Create a file for path.
* [EN] /// @param path Path to create file.
* /// @param name File name.
* [RU] /// @param rules Rules for all created directories and file (from 0000 to 0777).
* Создать файл с названием [name], находящимся по пути [path] /// @return TRUE if file were successfully created, FALSE if file exist/invalid path/error occured while creating file.
* С правами доступа [rules] (от 0000 до 0777)
*/
int yon_file_create(char *path, char *name, int rules); int yon_file_create(char *path, char *name, int rules);
/**yon_file_create_full_path(char *path, char *name, int rules) /// @brief Create a file and any missing directories for path.
* [EN] /// @param rules Rules for all created directories and file (from 0000 to 0777).
* /// @return TRUE if file were successfully created, FALSE if file exist/invalid path/error occured while creating file.
* [RU]
* Создать файл по пути [path]
* С правами доступа [rules] (от 0000 до 0777)
*/
int yon_file_create_full_path(char *path, mode_t rules); int yon_file_create_full_path(char *path, mode_t rules);
/**yon_file_ls (char *path, int *size)
* [EN] /// @brief Get a list of directory names for path.
* /// @param size Size of returned list.
* [RU] /// @return A newly allocated string array or NULL.
* Возвращает массив названий директорий размера [size], находящихся внутри директории [path].
*/
config_str yon_file_list_dirs (char *path, int *size); config_str yon_file_list_dirs (char *path, int *size);
/** /// @brief Get a list of file/directory names for path.
* [EN] /// @param path Path string.
* /// @param size Size of returned list.
* [RU] /// @return A newly allocated string array or NULL.
* Возвращает массив строк размера [size] с именами всех файлов и папок из директории [path]
*/
config_str yon_file_ls(char *path, int *size); config_str yon_file_ls(char *path, int *size);
/**yon_file_is_directory(const char *path) /// @brief Get parent directory from path.
* [EN] /// @return Newly allocated string with parent path or NULL.
* char *yon_file_get_parent(const char *path);
* [RU]
* Проверяет указывает ли путь [path] на директорию /// @brief Check if path points to directory.
*/ /// @return TRUE if path is pointing to directory, 0 otherwise.
int yon_file_is_directory(const char *path); int yon_file_is_directory(const char *path);
/**yon_dir_remove(const char *path)
* [EN] /// @brief Removes directory for path. If path is not directory, nothing happens.
*
* [RU]
* Проверяет указывает ли путь [path] на директорию и удаляет её
*/
void yon_dir_remove(const char *path); void yon_dir_remove(const char *path);
/** yon_dir_get_contents(char *dir_path, int *size) /** yon_dir_get_contents(char *dir_path, int *size)
@ -1196,7 +1174,7 @@ void yon_dir_remove(const char *path);
* возвращает список всех вложенных файлов и папок, * возвращает список всех вложенных файлов и папок,
* передавая в [size] длину списка. * передавая в [size] длину списка.
*/ */
config_str yon_dir_get_contents(char *dir_path, int *size); __attribute__((deprecated("Use yon_file_ls() instead"))) config_str yon_dir_get_contents(char *dir_path, int *size);
config_str yon_dir_get_by_mask(char *path, char *mask, int *size); config_str yon_dir_get_by_mask(char *path, char *mask, int *size);

Loading…
Cancel
Save