|
C-Menu 0.2.9
A User Interface Toolkit
|
list files matching a regular expression More...
#include <argp.h>#include <cm.h>#include <dirent.h>#include <errno.h>#include <fcntl.h>#include <grp.h>#include <linux/limits.h>#include <pthread.h>#include <pwd.h>#include <regex.h>#include <stdatomic.h>#include <stdbool.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <sys/sysinfo.h>#include <sys/types.h>#include <sys/wait.h>#include <time.h>#include <unistd.h>Go to the source code of this file.
Macros | |
| #define | _GNU_SOURCE |
| #define | DT_LNK_DIR 14 |
| #define | print_file_type(mask, lf_type, dt_type, name) |
Typedefs | |
| typedef struct TaskNode | TaskNode |
Functions | |
| void | debug_out (SearchFilters *f, int argc, char **argv, int nthreads) |
| Output debug information about the search filters and configuration. | |
| TaskNode * | dequeue_dir () |
| Dequeue a directory dir_path for processing by finder threads. | |
| void | enqueue_dir (TaskNode *new_task) |
| Enqueue a directory dir_path for processing by finder threads. | |
| void * | finder (void *arg) |
| Worker thread function to process directories from the queue. | |
| bool | init_find (SearchFilters *f, int argc, char **argv) |
| Initialize the file search based on the provided SearchFilters and start finder threads. | |
| int | main (int argc, char **argv) |
| int | scan_file (char *file_spec, const SearchFilters *f, const unsigned char effective_type) |
| scan a single file against search filters | |
| void | sort_lf_output (SearchFilters *, int, char **) |
Variables | |
| atomic_int | active_tasks = 0 |
| const char * | argp_program_bug_address = "billxwaller@gmail.com" |
| const char * | argp_program_version = CM_VERSION |
| pthread_cond_t | cond_var = PTHREAD_COND_INITIALIZER |
| char * | debug_p |
| const char | doc [] |
| char * | exec |
| char * | file_types_p |
| int | lfargc |
| char * | lfargs [3] |
| int | nthreads |
| char * | perms_p |
| TaskNode * | qhead = NULL |
| TaskNode * | qtail = NULL |
| pthread_mutex_t | queue_mutex = PTHREAD_MUTEX_INITIALIZER |
| int | shutdown = 0 |
| int | termination_status = EXIT_SUCCESS |
| struct tm | tm_info |
list files matching a regular expression
NOTICE: This file is part of the lf project, which is currently under development. There are two reasons not to use it at this time. First, it is not yet fully functional and may contain bugs or incomplete, unoptimized code. Second, the API and features are still being finalized, so using it now may lead to compatibility issues in the future as changes are made. Once the project is more mature and stable, this file will be ready for use. In the meantime, it serves as a work in progress and may be subject to significant changes as development continues.
Thank you for your patience and understanding.
Definition in file lf.c.
| #define print_file_type | ( | mask, | |
| lf_type, | |||
| dt_type, | |||
| name ) |
Definition at line 45 of file lf.c.
| void debug_out | ( | SearchFilters * | f, |
| int | argc, | ||
| char ** | argv, | ||
| int | nthreads ) |
Output debug information about the search filters and configuration.
| f | A pointer to a SearchFilters struct containing the options and flags for filtering. |
| argc | The number of command-line arguments. |
| argv | The array of command-line argument strings. |
| nthreads | The number of threads being used for the search. |
This function prints detailed information about the configuration and search filters as well as each of the options and arguments used on the command line invoking lf. The output is sent to the standard error stream, which can be redirected to standard output making it suitable as documentation for an audit trail.
Definition at line 581 of file lf.c.
References format_local_timestamp(), get_ip_addresses(), get_local_timestamp(), get_user_str(), LF_BLK, LF_CHR, LF_DIR, LF_EXC_REGEX, LF_FIFO, LF_IRUSR, LF_ISGID, LF_ISUID, LF_IWUSR, LF_IXUSR, LF_LNK, LF_REG, LF_REGEX, LF_SOCK, LF_UNKNOWN, LF_USER, and ssnprintf().
Referenced by init_find().
| TaskNode * dequeue_dir | ( | ) |
Dequeue a directory dir_path for processing by finder threads.
This function removes and returns the next TaskNode from the global queue. It uses a mutex to ensure thread-safe access to the queue, and waits on a condition variable if the queue is empty. The function also checks for shutdown conditions to allow finder threads to exit gracefully when there is no more work to process.
Definition at line 741 of file lf.c.
References active_tasks, cond_var, qhead, qtail, queue_mutex, and shutdown.
Referenced by finder().
| void enqueue_dir | ( | TaskNode * | new_task | ) |
Enqueue a directory dir_path for processing by finder threads.
| new_task | A pointer to a TaskNode containing the directory path and depth to be enqueued for processing by finder threads. |
This function adds a new TaskNode to the global queue of directories to be processed by finder threads. It uses a mutex to ensure thread-safe access to the queue and signals one waiting thread that a new task is available. If shutdown has been initiated, the signal will wake up any waiting threads so they can check the shutdown condition and exit gracefully.
Definition at line 708 of file lf.c.
References cond_var, qhead, qtail, and queue_mutex.
Referenced by finder(), and init_find().
| void * finder | ( | void * | arg | ) |
Worker thread function to process directories from the queue.
| arg | Pointer to the SearchFilters struct containing the options and flags for filtering. |
This function continuously dequeues directory dir_path from the global queue and processes them. For each directory, it lists its contents and applies the specified filters to each file. If a subdirectory is found and it meets the criteria for further searching (e.g., not hidden if hidden files are suppressed, and within max depth), it is enqueued for processing. The function uses atomic operations to track active tasks and condition variables to manage thread synchronization and shutdown when all work is complete.
Definition at line 808 of file lf.c.
References active_tasks, cond_var, dequeue_dir(), enqueue_dir(), scan_file(), and termination_status.
Referenced by init_find().
| bool init_find | ( | SearchFilters * | f, |
| int | argc, | ||
| char ** | argv ) |
Initialize the file search based on the provided SearchFilters and start finder threads.
| f | A pointer to a SearchFilters struct containing the options and flags for filtering. |
| argc | The number of command-line arguments. |
| argv | The array of command-line argument strings. |
This function processes the flags and options specified in the SearchFilters struct to set up the search criteria. It compiles any regular expressions provided by the user and initializes the queue with the base directory. It then creates a number of finder threads equal to the number of CPU cores to perform the directory traversal and file scanning concurrently. The function waits for all finder threads to complete before cleaning up resources and returning.
suppress file types that aren't included
Definition at line 486 of file lf.c.
References cond_var, debug_out(), enqueue_dir(), finder(), LF_EXC_REGEX, LF_HIDE, LF_ICASE, LF_REGEX, nthreads, queue_mutex, and shutdown.
Referenced by main(), and sort_lf_output().
| int main | ( | int | argc, |
| char ** | argv ) |
Definition at line 370 of file lf.c.
References expand_tilde(), init_find(), is_directory(), is_symlink_to_dir(), is_valid_regex(), LF_HIDE, LF_REGEX, lfargc, lfargs, sort_lf_output(), strnz__cpy(), and termination_status.
| int scan_file | ( | char * | file_spec, |
| const SearchFilters * | f, | ||
| const unsigned char | effective_type ) |
scan a single file against search filters
| file_spec | specification of file being scanned |
| f | SearchFilters struct |
| effective_type | type of file being scanned |
Definition at line 1019 of file lf.c.
References LF_EXC_REGEX, LF_IRUSR, LF_ISGID, LF_ISUID, LF_IWUSR, LF_IXUSR, LF_REGEX, LF_USER, and termination_status.
Referenced by finder().
| void sort_lf_output | ( | SearchFilters * | f, |
| int | argc, | ||
| char ** | argv ) |
If sorting is requested, execute the finder and pipe its output to the sort command. We can achieve this by creating a child process that runs the sort command, and redirecting the output of the file finder to the input of the sort command using a pipe. The parent process will run the finder and write its output to the pipe, while the child process will read from the pipe and execute the sort command.
Definition at line 435 of file lf.c.
References init_find().
Referenced by main().
| atomic_int active_tasks = 0 |
Definition at line 127 of file lf.c.
Referenced by dequeue_dir(), and finder().
| const char* argp_program_version = CM_VERSION |
| pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER |
Definition at line 126 of file lf.c.
Referenced by dequeue_dir(), enqueue_dir(), finder(), and init_find().
| const char doc[] |
| int nthreads |
Definition at line 60 of file lf.c.
Referenced by init_find().
| TaskNode* qhead = NULL |
Definition at line 123 of file lf.c.
Referenced by dequeue_dir(), and enqueue_dir().
| TaskNode* qtail = NULL |
Definition at line 124 of file lf.c.
Referenced by dequeue_dir(), and enqueue_dir().
| pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER |
Definition at line 125 of file lf.c.
Referenced by dequeue_dir(), enqueue_dir(), and init_find().
| int shutdown = 0 |
Definition at line 128 of file lf.c.
Referenced by dequeue_dir(), and init_find().
| int termination_status = EXIT_SUCCESS |
Definition at line 129 of file lf.c.
Referenced by finder(), main(), and scan_file().