GRASS GIS 7 Programmer's Manual
7.9.dev(2021)-e5379bbd7
|
Functions to list the files in a directory. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <grass/gis.h>
#include <grass/config.h>
#include <grass/glocale.h>
#include <termios.h>
#include <sys/ioctl.h>
Go to the source code of this file.
Typedefs | |
typedef int | ls_filter_func(const char *, void *) |
Functions | |
void | G_set_ls_filter (ls_filter_func *func, void *closure) |
Sets a function and its complementary data for G_ls2 filtering. More... | |
void | G_set_ls_exclude_filter (ls_filter_func *func, void *closure) |
char ** | G_ls2 (const char *dir, int *num_files) |
Stores a sorted directory listing in an array. More... | |
void | G_ls (const char *dir, FILE *stream) |
Prints a directory listing to a stream, in prettified column format. More... | |
void | G_ls_format (char **list, int num_items, int perline, FILE *stream) |
Prints a listing of items to a stream, in prettified column format. More... | |
Functions to list the files in a directory.
(C) 2007, 2008 by the GRASS Development Team
This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
Definition in file ls.c.
void G_ls | ( | const char * | dir, |
FILE * | stream | ||
) |
Prints a directory listing to a stream, in prettified column format.
A replacement for system("ls -C"). Lists the contents of the directory specified to the given stream, e.g. stderr. Tries to determine an appropriate column width to keep the number of lines used to a minimum and look pretty on the screen.
dir | Directory to list |
stream | Stream to print listing to |
Definition at line 137 of file ls.c.
References G_free(), G_ls2(), and G_ls_format().
char** G_ls2 | ( | const char * | dir, |
int * | num_files | ||
) |
Stores a sorted directory listing in an array.
The filenames in the specified directory are stored in an array of strings, then sorted alphabetically. Each filename has space allocated using G_store(), which can be freed using G_free() if necessary. The same goes for the array itself.
dir | Directory to list |
num_files | Pointer to an integer in which the total number of files listed will be stored |
Definition at line 95 of file ls.c.
References _, G_fatal_error(), G_realloc, G_store(), NULL, opendir(), and readdir().
Referenced by G_ls(), and list_subgroups().
void G_ls_format | ( | char ** | list, |
int | num_items, | ||
int | perline, | ||
FILE * | stream | ||
) |
Prints a listing of items to a stream, in prettified column format.
Lists the contents of the array passed to the given stream, e.g. stderr. Prints the number of items specified by "perline" to each line, unless perline is given as 0 in which case the function tries to determine an appropriate column width to keep the number of lines used to a minimum and look pretty on the screen.
list | Array of strings containing items to be printed |
num_items | Number of items in the array |
perline | Number of items to print per line, 0 for autodetect |
stream | Stream to print listing to |
Definition at line 165 of file ls.c.
References max, and screen_width.
Referenced by G_ls().
void G_set_ls_exclude_filter | ( | ls_filter_func * | func, |
void * | closure | ||
) |
void G_set_ls_filter | ( | ls_filter_func * | func, |
void * | closure | ||
) |
Sets a function and its complementary data for G_ls2 filtering.
Defines a filter function and its rule data that allow G_ls2 to filter out unwanted file names. Call this function before G_ls2.
func | Filter callback function to compare a file name and closure pattern (if NULL, no filter will be used). func(filename, closure) should return 1 on success, 0 on failure. |
closure | Data used to determine if a file name matches the rule. |