home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / XAP / XFM / XFM-1.3 / XFM-1 / xfm-1.3 / xfm / Fm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-16  |  11.1 KB  |  416 lines

  1. /*-----------------------------------------------------------------------------
  2.   Fm.h
  3.   
  4.   (c) Simon Marlow 1990-1993
  5.   (c) Albert Graef 1994
  6. -----------------------------------------------------------------------------*/
  7.  
  8. #ifndef FM_H
  9. #define FM_H
  10.  
  11. #ifdef DEBUG_MALLOC
  12. #include <malloc.h>
  13. #endif
  14.  
  15. #include <stdio.h>
  16. #include <sys/types.h> /* just in case */
  17. #include <sys/stat.h>
  18. #include <dirent.h>
  19. #include <sys/param.h>
  20. #include <unistd.h>
  21.  
  22. #ifdef SYSV
  23. #define getwd(s) getcwd(s,MAXPATHLEN)
  24. #endif
  25.  
  26. #ifndef FILENAME_MAX
  27. #define FILENAME_MAX 1024
  28. #endif
  29.  
  30. /*--FmDirs-------------------------------------------------------------------*/
  31.  
  32. #define MAXCFGSTRINGLEN MAXPATHLEN
  33.  
  34. /* structure representing user-defined file types */
  35. typedef struct {
  36.   char *pattern;
  37.   char *icon;
  38.   char *push_action;
  39.   char *drop_action;
  40.   int len, dir;
  41.   Pixmap icon_bm;
  42. } TypeRec, *TypeList;
  43.  
  44. /* structure representing configured devices */
  45. typedef struct {
  46.   char *name;
  47.   char *mount_action;
  48.   char *umount_action;
  49.   int mounted;
  50. } DevRec, *DevList;
  51.  
  52. /* structure containing the widget ids of an icon */
  53. typedef struct {
  54.     Widget form, toggle, label, arrow;
  55. } IconRec;
  56.  
  57. /* structure into which the directory information is read */
  58. typedef struct {
  59.     char name[FILENAME_MAX];
  60.     Boolean sym_link;
  61.     struct stat stats;
  62.     IconRec icon;
  63.     Boolean selected;
  64.     TypeRec *type;
  65. } FileRec, **FileList;
  66.  
  67. /* enumerated arguments passed to functions */
  68. typedef enum { Files, Directories, All } FilterType;
  69. typedef enum { SortByName, SortBySize, SortByMTime } SortType;
  70. typedef enum { Tree, Icons, Text } DisplayType;
  71.  
  72. typedef struct _FileWindowRec {
  73.   struct _FileWindowRec *next;
  74.   DisplayType display_type;
  75.   Boolean show_dirs, dirs_first, show_hidden;
  76.   Boolean update;
  77.   SortType sort_type;
  78.   Widget shell, form, button_box, label, viewport, status, icon_box;
  79.   char directory[MAXPATHLEN];
  80.   int dev;
  81.   struct stat stats;
  82.   FileList files;
  83.   int n_files;
  84.   int n_selections;
  85.   long n_bytes, n_bytes_selected;
  86.   Widget *file_items, *folder_items, *view_items;
  87.   Widget unreadable;
  88. } FileWindowRec, *FileWindowList;
  89.  
  90. #define P_READ 0x1
  91. #define P_WRITE 0x2
  92. #define P_EXECUTE 0x4
  93.  
  94. /* public functions */
  95. Boolean readDirectory(FileWindowRec *fw);
  96. void filterDirectory(FileWindowRec *fw, FilterType type);
  97. void sortDirectory(FileList fl, int n, SortType type, Boolean dirs_first);
  98. int permission(struct stat *stats, int perms);
  99. void makePermissionsString(char *s, int perms);
  100. void freeFileList(FileWindowRec *fw);
  101.  
  102. /*--FmFw---------------------------------------------------------------------*/
  103.  
  104. extern FileWindowList file_windows;
  105. extern Widget file_popup_widget, *file_popup_items;
  106. extern Widget dir_popup_widget, *dir_popup_items;
  107. extern FileWindowRec *popup_fw;
  108.  
  109. extern int n_types;
  110. extern TypeList types;
  111.  
  112. extern int n_devices;
  113. extern DevList devs;
  114.  
  115. int findDev(char *path);
  116. void mountDev(int d);
  117. void umountDev(int d);
  118.  
  119. void initFileWindows();
  120. void createFileDisplay(FileWindowRec *fw);
  121. void newFileWindow(String path, DisplayType format, 
  122.                  Boolean by_cursor);
  123. void updateFileDisplay(FileWindowRec *fw);
  124. void reSortFileDisplay(FileWindowRec *fw);
  125. void reDisplayFileWindow(FileWindowRec *fw);
  126.  
  127. void clearUpdateMarks();
  128. void markForUpdate(String path);
  129. void intUpdate();
  130.  
  131. void updateStatus(FileWindowRec *fw);
  132.  
  133. /* Braindamaged Intrinsic.h gives no way to declare a callback properly */
  134. typedef void FmCallbackProc(Widget w, FileWindowRec *fw,
  135.                 XtPointer call_data);
  136.  
  137. /*--FmFwCb-------------------------------------------------------------------*/
  138.  
  139. FmCallbackProc
  140.   fileOpenCb, fileSelectAllCb, fileDeselectCb, fileTreeCb, fileIconsCb,
  141.   fileTextCb, fileSortNameCb, fileSortSizeCb, fileSortMTimeCb, fileShowDirsCb,
  142.   fileDirsFirstCb, fileCloseCb, mainArrowCb, fileHomeCb, fileUpCb, 
  143.   floatingMenuCb, fileShowHiddenCb, fileEditCb;
  144.  
  145. void timeoutCb(XtPointer data, XtIntervalId *id);
  146.  
  147. /*---FmFwActions-------------------------------------------------------------*/
  148.  
  149. typedef enum { SingleFile, MultipleFiles, Executable, Directory } FileType;
  150.  
  151. typedef struct {
  152.   Widget dragged_from;
  153.   FileWindowRec *fw;
  154.   FileType type;
  155. } MoveInfo;
  156.  
  157. extern MoveInfo move_info;
  158. extern Boolean dragging;
  159.  
  160. typedef void FmActionProc(Widget w, XEvent *event, String *params, 
  161.             Cardinal *num_params);
  162.  
  163. FmActionProc fileHighlight, fileMaybeHighlight, fileToggle, fileSelect,
  164.   fileRefresh, fileOpenDir, fileBeginDrag, treeOpenDir, fileExecAction,
  165.   fileExecFile, resetCursor, filePopup, dirPopup;
  166.  
  167. void doEdit(char *directory, char *fname);
  168.  
  169. /*---FmBitmaps---------------------------------------------------------------*/
  170.  
  171. /* Cursor bitmaps */
  172.  
  173. #define FILE_CBM 0
  174. #define FILEMSK_CBM 1
  175. #define FILES_CBM 2
  176. #define FILESMSK_CBM 3
  177. #define NOENTRY_CBM 4
  178. #define NOENTRYMSK_CBM 5
  179. #define DIR_CBM 6
  180. #define DIRMSK_CBM 7
  181. #define EXEC_CBM 8
  182. #define EXECMSK_CBM 9
  183. #define WATCH_CBM 10
  184. #define WATCHMSK_CBM 11
  185.  
  186. /* Tree view bitmaps */
  187.  
  188. #define LLINE_BM 12
  189. #define TLINE_BM 13
  190. #define FLINE_BM 14
  191. #define CLINE_BM 15
  192. #define LARROW_BM 16
  193. #define RARROW_BM 17
  194. #define WAVY_BM 18
  195.  
  196. /* Misc */
  197.  
  198. #define TICK_BM 19
  199. #define NOTICK_BM 20
  200. #define EXCL_BM 21
  201. #define FILES_BM 22
  202.  
  203. /* File pixmaps */
  204.  
  205. #define DIR_BM 23
  206. #define UPDIR_BM 24
  207. #define FILE_BM 25
  208. #define EXEC_BM 26
  209. #define SYMLNK_BM 27
  210. #define DIRLNK_BM 28
  211. #define EXECLNK_BM 29
  212. #define BLACKHOLE_BM 30
  213.  
  214. /* Application icons: */
  215.  
  216. #define ICON_BM 31
  217. #define ICONMSK_BM 32
  218. #define APPMGR_BM 33
  219. #define APPMGRMSK_BM 34
  220.  
  221. /* Hardcoded bitmaps stop here: */
  222.  
  223. #define END_BM 35
  224.  
  225. /* Cursors */
  226.  
  227. #define FILE_CUR 0
  228. #define FILES_CUR 1
  229. #define NOENTRY_CUR 2
  230. #define DIR_CUR 3
  231. #define EXEC_CUR 4
  232. #define WATCH_CUR 5
  233.  
  234. extern Cursor *curs;
  235. extern Pixmap *bm;
  236.  
  237. void readBitmaps();
  238. Pixmap readIcon(char *name);
  239.  
  240. /*--FmChmod------------------------------------------------------------------*/
  241.  
  242. void createChmodPopup();
  243. FmCallbackProc chmodPopup;
  244.  
  245. /*--FmConfirm----------------------------------------------------------------*/
  246.  
  247. extern Boolean aborted;
  248. void createConfirmPopup();
  249. int confirm(String s1, String s2, String s3);
  250.  
  251. /*--FmDelete-----------------------------------------------------------------*/
  252.  
  253. FmCallbackProc deleteItems, emptyDir;
  254.  
  255. /*--FmErrors-----------------------------------------------------------------*/
  256.  
  257. void createErrorPopup();
  258. void error(String label1, String label2);
  259. void sysError(String label);
  260. void abortXfm(String message);
  261.  
  262. /*--FmExec-------------------------------------------------------------------*/
  263.  
  264. typedef struct {
  265.   String pattern, command;
  266. } ExecMapRec;
  267.  
  268. extern ExecMapRec *exec_map;
  269. extern int n_exec_maps;
  270.  
  271. char **makeArgv(char *action);
  272. char **makeArgv2(char *action, char *fname);
  273. char **expandArgv(char **argv);
  274. void freeArgv(char **argv);
  275. void executeApplication(char *path, char *directory, char **argv);
  276.  
  277. /*--FmInfo-------------------------------------------------------------------*/
  278.  
  279. void createInfoPopup();
  280. FmCallbackProc infoPopup;
  281.  
  282. /*--FmMain-------------------------------------------------------------------*/
  283.  
  284. /* Structure containing information about the user */
  285. typedef struct {
  286.   int uid, gid;
  287.   char home[MAXPATHLEN];
  288.   char shell[MAXPATHLEN];
  289.   mode_t umask;
  290. } UserInfo;
  291.  
  292. typedef struct {
  293.   Boolean appmgr, filemgr;
  294.   String init_geometry;
  295.   XFontStruct *icon_font, *button_font, *menu_font, *label_font, *status_font,
  296.     *bold_font, *cell_font;
  297.   int app_icon_width, app_icon_height, file_icon_width, file_icon_height,
  298.     tree_icon_width, tree_icon_height;
  299.   String app_file_r, cfg_file_r, dev_file_r;
  300.   Boolean confirm_deletes, confirm_delete_folder, confirm_moves,
  301.     confirm_copies, confirm_overwrite, confirm_quit;
  302.   Boolean echo_actions;
  303.   SortType default_sort_type;
  304.   DisplayType default_display_type, initial_display_type;
  305.   Boolean show_owner, show_perms, show_date, show_length;
  306.   char app_file[MAXPATHLEN], cfg_file[MAXPATHLEN], dev_file[MAXPATHLEN];
  307.   Boolean auto_save;
  308.   int double_click_time, update_interval;
  309.   String default_editor;
  310.   String bitmap_path, pixmap_path;
  311. } Resources;
  312.  
  313. extern char *progname;
  314. extern Resources resources;
  315. extern XtAppContext app_context;
  316. extern UserInfo user;
  317.  
  318. /* The following implements a semaphor for preventing the processing of update
  319.    events in the refresh timer and the client message handler while a complex
  320.    operation is in progress. This is a dreadful kludge, but we have to keep
  321.    these events from modifying global data structures of the file manager
  322.    while an operation is running. Update events which happen to get dispatched
  323.    while the semaphor is set (for instance when an operation like file-copy
  324.    is processing a popup form) will be simply ignored. -ag */
  325.  
  326. extern int freeze;
  327.  
  328. void quit();
  329.  
  330. /*---FmPopup-----------------------------------------------------------------*/
  331.  
  332. void createMainPopups();
  333.  
  334. FmCallbackProc selectPopup, mkdirPopup, createFilePopup, goToPopup, movePopup,
  335.     copyPopup, linkPopup;
  336.  
  337. /*--FmUtils------------------------------------------------------------------*/
  338.  
  339. /* structures containing information required to set up a menu */
  340. typedef struct {
  341.   String item_name;
  342.   String item_label;
  343.   FmCallbackProc *callback;
  344. } MenuItemRec, *MenuItemList;
  345.  
  346.  
  347. /* structures containing information required to set up a button */
  348. typedef struct {
  349.   String button_name;
  350.   String button_label;
  351.   FmCallbackProc *callback;
  352. } ButtonRec, *ButtonList;
  353.  
  354.  
  355. /* structure for creating a popup questionaire */
  356. typedef struct {
  357.   String label;
  358.   String value;
  359.   Cardinal length;
  360.   Widget widget;
  361. } QuestionRec, *QuestionList;
  362.  
  363. /* functions */
  364.  
  365. void initUtils();
  366.  
  367. Widget *createMenu(String menu_name, String menu_label, MenuItemList items,
  368.            Cardinal n_items, Dimension left_margin, Widget parent,
  369.            XtPointer client_data);
  370. Widget *createButtons(ButtonList buttons, Cardinal n_buttons, Widget parent,
  371.               XtPointer client_data);
  372. Widget createPopupQuestions(String name, String title, Pixmap bitmap, 
  373.                 QuestionList questions, Cardinal n_questions,
  374.                 ButtonList buttons, Cardinal n_buttons);
  375. void fillIn(Widget w);
  376. void grayOut(Widget w);
  377. void tick(Widget w);
  378. void noTick(Widget w);
  379. void popupByCursor(Widget shell, XtGrabKind grab_kind);
  380. void zzz(void), wakeUp(void);
  381. Widget *createFloatingMenu(String menu_name,
  382.                MenuItemRec *items, Cardinal n_items, 
  383.                Dimension left_margin, Widget parent, 
  384.                XtPointer client_data,
  385.                Widget *menu_widget);
  386. char *varPopup(Pixmap icon_bm, char *action);
  387.  
  388. /*--FmComms------------------------------------------------------------------*/
  389.  
  390. extern Atom xfm_open_window, xfm_update_window, wm_delete_window,
  391.     wm_protocols;
  392. void clientMessageHandler(Widget w, XtPointer closure, XEvent *e);
  393. void initComms(void);
  394.  
  395. /*--FmOps--------------------------------------------------------------------*/
  396.  
  397. char *split(char *s, char c);
  398. char *expand(char *s, char *t, char *c);
  399. char *strparse(char *s, char *t, char *c);
  400. int fnmatch(String pattern, String name);
  401. char *fnexpand(char *fn);
  402. int prefix(char *s, char *t);
  403. int exists(char *path);
  404. char *searchPath(char *s1, char *p, char *s2);
  405.  
  406. int create(char *path, mode_t mode), rcopy(char *oldpath, char *newpath),
  407.   rdel(char *path);
  408.  
  409. /*---------------------------------------------------------------------------*/
  410.  
  411. /* Horrible kludge to avoid warnings, as XtFree is designed to take a (char *)*/
  412. #define XTFREE(p) XtFree((void *)(p))
  413. #define XTREALLOC(p,n) XtRealloc((void *)(p),(n))
  414.  
  415. #endif
  416.