some playing with bbs - new fm
[mirrors/Programs.git] / bash / bbs / utils / fm / fm / fm.h
CommitLineData
db4042d6
H
1/* Copyright (C) 2008 Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef FM_H
18#define FM_H
19
20#define _XOPEN_SOURCE 500
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <unistd.h>
25#include <string.h>
26#include <sys/types.h>
27#include <sys/stat.h>
28#include <sys/wait.h>
29#include <sys/select.h>
30#include <dirent.h>
31#include <signal.h>
32#include <ctype.h>
33#include <time.h>
34#include <pwd.h>
35#include <grp.h>
36#include <errno.h>
37#include <locale.h>
38#include <glib.h>
39#include <ncurses.h>
40
41#undef FILE
42#define FILE(node) ((File *) (node)->data)
43#define NODE(element) ((GNode *) (element)->data)
44#define PRINT_ERRNO_AND_EXIT() print_errno_and_exit(errno, __FILE__, __LINE__)
45#define PRINT_ERRNO_INFO() print_error_info(errno, __FILE__, __LINE__, NULL)
46#define PRINT_ERROR_INFO(message) print_error_info(0, __FILE__, __LINE__, message)
47#define PRINT_LAST_INFO() print_info(NULL, -1)
48
49#define DEFAULT_EDITOR "vim"
50#define DEFAULT_PAGER "less"
51#define DEFAULT_SHELL "bash"
52#define DEFAULT_PS_VIEWER "gv"
53#define DEFAULT_PDF_VIEWER "xpdf"
54#define DEFAULT_IMAGE_VIEWER "display"
55#define GETCH_DELAY 5
56
57typedef struct File File;
58struct File {
59 char *name, *link_path;
60 enum Type {file_type, directory_type} type;
61 struct stat info;
62 gboolean read, open, show_dotfiles, link;
63 GList *line, *dotfiles;
64 int watch;
65};
66
67extern char *program_name;
68extern GNode *tree_root;
69extern WINDOW *tree_window, *info_window;
70extern GList *lines, *selected_line, *first_line, *last_line;
71
72/* cmd.c */
73void get_key(void);
74void run_program(GNode *current_directory, char *program_name_variable,
75 char *default_program_name, char *arg, gboolean wait_proccess);
76void run_shell(GNode *directory);
77void read_file(GNode *file);
78void edit_file(GNode *file);
79
80/* fm.c */
81void clean_up(void);
82void print_errno_and_exit(int last_errno, char *file, int line);
83void handle_sigsegv(int signal_number);
84void handle_sigint(int signal_number);
85void set_sighandlers(void);
86void unset_sighandlers(void);
87void print_usage(void);
88
89/* fs.c */
90void init_tree(char *name);
91File *create_new_file(char *name, char *path, gboolean exit_on_error);
92gboolean read_directory(GNode *directory);
93void free_element_data(gpointer element_data, gpointer data);
94void destroy_dotfiles(GList *dotfiles);
95gboolean free_node_data(GNode *node, gpointer data);
96void destroy_directory_content(GNode *directory);
97void destroy_directory_content_real(GNode *directory, gboolean remove_watch);
98void add_dotfiles(GNode *directory);
99void remove_dotfiles(GNode *directory);
100int file_cmp(File *file1, File *file2);
101int file_cmp_list(gconstpointer file1, gconstpointer file2);
102void insert_sorted_in_dotfiles(GNode *directory, File *file);
103GNode *insert_sorted_in_tree(GNode *directory, File *file);
104char *get_path(GNode *file);
105GNode *get_next_file_real(GNode *file, gboolean go_deeper);
106GNode *get_previous_file(GNode *file);
107GNode *get_next_file(GNode *file);
108GNode *get_next_file_not_deepper(GNode *file);
109char *get_file_info(GNode *file);
110
111/* ui.c */
112void init_lines(void);
113void init_curses(void);
114void init_ui(char *name);
115void refresh_screen(void);
116void handle_sigwinch(int signal_number);
117void print_lines(GList *start_line, GList *end_line, gboolean clear_bottom_lines);
118void print_parents_lines(GList *line);
119void print_line(GList *line);
120void clear_info(void);
121void print_info(char *message, gboolean bold);
122void print_error_info(int last_errno, char *file, int line, char *message);
123void update_last_line(void);
124void add_directory_content(GNode *directory);
125void open_directory(GNode *directory);
126void close_directory(GNode *directory);
127void update_directory(GNode *directory);
128void show_dotfiles(GNode *directory);
129void hide_dotfiles(GNode *directory);
130void select_line(GList *line);
131void select_file(GNode *file);
132void select_nth_line(int n_lines);
133void scroll_tree(int n_lines);
134void select_line_inside_window(void);
135void select_next_line_by_first_letter(char letter);
136void select_previous_line_by_first_letter(char letter);
137
138#ifdef INOTIFY
139#include <sys/inotify.h>
140
141#define CHECK_INOTIFY_ENABLED() if (inotify_enabled == FALSE) return
142#define BUFFER_LENGTH 10 * (sizeof(struct inotify_event) + 16)
143
144extern gboolean inotify_enabled, debug_inotify;
145extern GHashTable *watches_table;
146extern int inotify_descriptor;
147extern char events_buffer[BUFFER_LENGTH];
148
149/* ino.c */
150void init_inotify(GNode *tree_root);
151void stop_inotify(void);
152void free_key(gpointer key, gpointer value, gpointer data);
153void add_watch_directory(GNode *directory);
154void remove_watch_directory(GNode *directory, gboolean remove_watch);
155void watch_events(void);
156gboolean insert_in_tree(GNode *directory, File *file);
157gboolean remove_from_tree(GNode *file, gboolean unmount);
158GNode *search_node_by_name(GNode *directory, char *name);
159void dump_event(struct inotify_event *event);
160void dump_mask(int mask);
161#endif
162
163#endif
This page took 0.547805 seconds and 4 git commands to generate.