Nothing Fancy File Manager
 All Classes
nffm.h
1 /*
2  * Copyright (C) 2012 by Mario St-Gelais
3  *
4  * This file is part of NFFM.
5  *
6  * NFFM is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * NFFM is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NFFM. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef NFFM_H
21 #define NFFM_H
22 
23 #include <ctype.h>
24 #include <dirent.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <libtar.h>
28 #include <malloc.h>
29 #include <ncurses.h> //includes stdio.h and stdbool.h
30 #include <pwd.h> //for current user directory
31 #include <stdarg.h>
32 #include <stdbool.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <sys/ioctl.h>
36 #include <sys/stat.h>
37 #include <sys/types.h> //pid
38 #include <sys/wait.h> //waitpid
39 #include <time.h> //for file info
40 #include <unistd.h> //exec
41 #include <zlib.h>
42 
43 #define errno (*__errno_location ())
44 
45 #define AT_DIR -1
46 #define AT_FILE 1
47 #define CONF_FILE "extension.conf"
48 #define USER_CONF ".config/nffm/"
49 #define COLOR_FILE "color.conf"
50 #define COLORINDEX 40
51 #define SYSTEM_CONF "/etc/nffm/"
52 #define FILEMAX 30 //The number of files listed
53 #define MAXBEGIN 20 //Max number of characters allowed to set file begin with option.
54 #define MAXDIGIT 3 //not more than 999
55 #define MAXDIRECTORY 80 //Max Length of directory name
56 #define MAXDIRLIST 3000
57 #define MAXEXTENSION 380
58 #define MAXFILELIST 3000
59 #define MAXMENUSIZE 3000 //Max number of menu items
60 #define MENUHT 30 //The height of menu + header
61 #define MENUMAX 30 //The number of directories listed
62 #define MENUW 45 //The width of the directory and file listing.
63 #define ROOT "/"
64 #define SHOW_HIDDEN 0
65 #define STRLEN 1024
66 #define WINFILEW 46 //The width of file window
67 #define WINTRANSITW 35 //The width of the temporary display area of selected files
68 
69 enum nffm_colors{MAGENTA_BLACK=1, YELLOW_BLACK=2, GREEN_BLACK=3, RED_BLACK=4};
70 
71 typedef struct{
72  int menuitem; //index of directory or filelist
73  int diritemold; //index to retain menuitem when tabbing
74  int fileitemold; //index to retain menuitem when tabbing
75  int winmarker; //-1=AT_DIR, 1=AT_FILE
76  int linemarker; //Goes from 0 to linecount
77  int linemarkerfile;
78  int linemarkerdir;
79  int linemax; //or FILEMAX
80  int linecount; //from directories or files list length
81  int arrowcounter; //Switch from arrowcounterdir or arrowcounterfile. 0 to linemax
82  int arrowcounterdir; //The screen row of the highlighted directory
83  int arrowcounterfile; //The screen row of the highlighted file
84 }cursor;
85 
86 struct filemarker { //Keep a list of selected file to be actionned
87  char fullpath[MAXDIRECTORY];
88  struct filemarker *next;
89 };
90 
91 struct filemarker *filemarker = NULL;
92 
93 enum direction {UP=-1, DOWN=1, SAME=0};//To specify whether the cursor moves up or down.
94 
95 
96 typedef struct{
97  char dirname[STRLEN];
98  int dir_count;
99  int file_count;
100  long dir_size;
101 }directories;
102 
103 typedef struct
104 {
105  char extension[20];
106  char path[80];
107  char executable[80];
108  char arg[3];
109  char execarg[30];
110 }appCommand;
111 
112 typedef struct{
113  bool show_hidden;
114  char file_ext[20];
115  char file_begin[MAXBEGIN+1];
116 }options;
117 
118 struct colorext{
119  char ext[60];
120  short colorindex;
121 }color[MAXEXTENSION];
122 
123 WINDOW *winheader, *winfooter, *windirinfo, *winmenu,
124  *winscrollable, *currentwin, *winfileinfo, *wintransit;
125 
126 FILE * file_open(const char *filename, const char *mode);
127 appCommand getCommand(const char *extension);
128 bool UnmarkFile(struct filemarker **filelist, const char *filepath);
129 bool begins_with(const char *string, const char *begins);
130 bool ends_with(const char *string, const char *ends);
131 bool findMarkedFile(struct filemarker *filelist, char *filepath);
132 bool isHiddenFile(char s[]);
133 char * getFileExtension(const char *filename);
134 char *GetUserDir(void);
135 char *delimLong(long nbr);
136 char *delimStr(char nbr[]);
137 char *dtg(time_t *tm);
138 char *getUserText(const char *question);
139 char *join(const char s1[], const char s2[]);
140 char *join_words(int n, char *delim, ...);
141 char *printCursor(cursor c);
142 char *printCursor(cursor c);
143 cursor setCursor(int direction, int selection, cursor c);
144 directories DoDirectoryList(char adir[], char *directory_list[], char *file_list[], options opt);
145 int ReadLine(char c, char aLine[]);
146 int addslash(char adir[]);
147 int createDir(const char *parentDir, const char *childDir);
148 int createFile(const char *filepath);
149 int deleteFile(const char *filepath, bool confirmDeleteMany);
150 int deleteMarkedFile(struct filemarker **filelist);
151 int displayList(struct filemarker *filelist);
152 int drawmenu(char *list[], char *item, WINDOW *w, int fromline);
153 int filterfile(const struct dirent *d);
154 int findItemIndex(const char *item, char **itemList);
155 int find_color(char *ext);
156 int getNumber(WINDOW *w);
157 int gzCompress(char *infile, char *outfile);
158 int moveSelectedFiles(const char *newpath, struct filemarker **f);
159 int readlscolor(void);
160 int renameSelectedFile(const char *currentPath, const char *oldName);
161 int split(char delim, char *stringtosplit);
162 int tarOneFile(char tarFileName[], char tarPathname[], char tarSaveName[]);
163 int xdgFile(char *file);
164 int YesOrNo(const char *question);
165 int zipMarkedFiles(char *destDir, char *zipathname, struct filemarker **f);
166 options setFileFilter(options opt);
167 struct stat fileStat(char filepath[]);
168 void logger(const char *logger);
169 void markOneMoreFile(struct filemarker **filelist, char *filepath);
170 void message(char *msg);
171 void my_tolower(char *s);
172 void nffm_init_color(void);
173 void normalColor(WINDOW *w, cursor c, char *item);
174 void refreshDirInfo(directories dirs);
175 void refreshFileInfo(char currentDir[], char currentFile[]);
176 void showkeys();
177 int toStringFileType(mode_t perm, char *ft);
178 int toStringPerms(mode_t perm, char sp[]);
179 
180 #endif /* NFFM_H */