some playing with bbs - new fm
[mirrors/Programs.git] / bash / bbs / utils / fm / fm / fm.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
57 typedef struct File File;
58 struct 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
67 extern char *program_name;
68 extern GNode *tree_root;
69 extern WINDOW *tree_window, *info_window;
70 extern GList *lines, *selected_line, *first_line, *last_line;
71
72 /* cmd.c */
73 void get_key(void);
74 void run_program(GNode *current_directory, char *program_name_variable,
75 char *default_program_name, char *arg, gboolean wait_proccess);
76 void run_shell(GNode *directory);
77 void read_file(GNode *file);
78 void edit_file(GNode *file);
79
80 /* fm.c */
81 void clean_up(void);
82 void print_errno_and_exit(int last_errno, char *file, int line);
83 void handle_sigsegv(int signal_number);
84 void handle_sigint(int signal_number);
85 void set_sighandlers(void);
86 void unset_sighandlers(void);
87 void print_usage(void);
88
89 /* fs.c */
90 void init_tree(char *name);
91 File *create_new_file(char *name, char *path, gboolean exit_on_error);
92 gboolean read_directory(GNode *directory);
93 void free_element_data(gpointer element_data, gpointer data);
94 void destroy_dotfiles(GList *dotfiles);
95 gboolean free_node_data(GNode *node, gpointer data);
96 void destroy_directory_content(GNode *directory);
97 void destroy_directory_content_real(GNode *directory, gboolean remove_watch);
98 void add_dotfiles(GNode *directory);
99 void remove_dotfiles(GNode *directory);
100 int file_cmp(File *file1, File *file2);
101 int file_cmp_list(gconstpointer file1, gconstpointer file2);
102 void insert_sorted_in_dotfiles(GNode *directory, File *file);
103 GNode *insert_sorted_in_tree(GNode *directory, File *file);
104 char *get_path(GNode *file);
105 GNode *get_next_file_real(GNode *file, gboolean go_deeper);
106 GNode *get_previous_file(GNode *file);
107 GNode *get_next_file(GNode *file);
108 GNode *get_next_file_not_deepper(GNode *file);
109 char *get_file_info(GNode *file);
110
111 /* ui.c */
112 void init_lines(void);
113 void init_curses(void);
114 void init_ui(char *name);
115 void refresh_screen(void);
116 void handle_sigwinch(int signal_number);
117 void print_lines(GList *start_line, GList *end_line, gboolean clear_bottom_lines);
118 void print_parents_lines(GList *line);
119 void print_line(GList *line);
120 void clear_info(void);
121 void print_info(char *message, gboolean bold);
122 void print_error_info(int last_errno, char *file, int line, char *message);
123 void update_last_line(void);
124 void add_directory_content(GNode *directory);
125 void open_directory(GNode *directory);
126 void close_directory(GNode *directory);
127 void update_directory(GNode *directory);
128 void show_dotfiles(GNode *directory);
129 void hide_dotfiles(GNode *directory);
130 void select_line(GList *line);
131 void select_file(GNode *file);
132 void select_nth_line(int n_lines);
133 void scroll_tree(int n_lines);
134 void select_line_inside_window(void);
135 void select_next_line_by_first_letter(char letter);
136 void 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
144 extern gboolean inotify_enabled, debug_inotify;
145 extern GHashTable *watches_table;
146 extern int inotify_descriptor;
147 extern char events_buffer[BUFFER_LENGTH];
148
149 /* ino.c */
150 void init_inotify(GNode *tree_root);
151 void stop_inotify(void);
152 void free_key(gpointer key, gpointer value, gpointer data);
153 void add_watch_directory(GNode *directory);
154 void remove_watch_directory(GNode *directory, gboolean remove_watch);
155 void watch_events(void);
156 gboolean insert_in_tree(GNode *directory, File *file);
157 gboolean remove_from_tree(GNode *file, gboolean unmount);
158 GNode *search_node_by_name(GNode *directory, char *name);
159 void dump_event(struct inotify_event *event);
160 void dump_mask(int mask);
161 #endif
162
163 #endif
This page took 0.38831 seconds and 4 git commands to generate.