/*********************************************************************
 *
 *            EZFM---EZWGL based file manager for X11
 *
 *             Copyright (C) 1998  Maorong Zou
 *
 *
 *  This file is part of EZFM.
 *
 *  EZFM is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * EZFM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with EZFM; see the file COPYING.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *
 *************************************************************************/



/*************************************************************
 *
 *  Header for all source files.
 */
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <dirent.h>
#include <errno.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <signal.h>

#include "EZ.h"

#define  EZFMVERSIONSTRING  "ezfm-0.4.3"

/*************************************************************/
#ifdef LINUX 
#define REMOVABLE_DRIVES
#endif
/*************************************************************/
EXTERN   int erron, sys_nerr;
EXTERN   char *sys_errlist[];
#define syserr(en) (((en) >= 0 && (en) < sys_nerr) ? sys_errlist[(en)] : "Unknown error")
#define SECONDS_IN_YEAR         31536000
#define SelectionBackground     "yellow"
/*************************************************************/
#define IS_SH_ESCAPE_C(_c_)  ((_c_) == '"' || (_c_) == '\'' || (_c_) == '`' )
/*************************************************************
 *
 *  FontID indices
 */
#define ITEM_MEDIUM_FONT          0
#define ITEM_SLANT_FONT           1
#define ITEM_BOLD_FONT            2
#define ITEM_BOLD_SLANT_FONT      3
#define LABEL_MEDIUM_FONT         4
#define LABEL_BOLD_FONT           5
#define LABEL_LARGE_FONT          6
#define LABEL_SMALL_FONT          7
#define TEXT_FONT                 8
#define TEXT_BOLD_FONT            9

/*************************************************************
 *
 *  Drop to folder/dirItem action types
 */
#define    EZFM_CANCEL       0
#define    EZFM_MOVE_FILE    1
#define    EZFM_COPY_FILE    2
#define    EZFM_LINK_FILE    3
#define    EZFM_MOVE_MFILES  4
#define    EZFM_COPY_MFILES  5
#define    EZFM_LINK_MFILES  6


/*************************************************************
 *
 *  DnD message header length
 */
#define PATHNAME_OFFSET      80
#define HEADER_OFFSET        256

/*************************************************************
 *
 *  Special shell commands used by DnD 
 */
  
#define TAR_CREATE_CMD       "/bin/tar cfz - \"%s\""
#define TAR_EXTRACT_CMD      "/bin/tar xfz - \"%s\""

#define MOVE_CMD             "/bin/mv -f  \"%s\" \"%s\" "
#define COPY_CMD             "/bin/cp -rf  \"%s\" \"%s\" "
#define LINK_CMD             "/bin/ln -sf  \"%s\" \"%s\" "

/***********************************************************/
#define BIN_MOUNT            "/bin/mount"
#define BIN_UMOUNT           "/bin/umount"

/*************************************************************
 *
 *  Number of fields in file info specification
 */
#define   SPEC_NDIELDS                  6  
#define   SPEC_PIXMAP                   0
#define   SPEC_COLOR                    1
#define   SPEC_FONT                     2
#define   SPEC_DCLICK_ACTION            3
#define   SPEC_DROP_BY_NAME_ACTION      4
#define   SPEC_DROP_BY_CONTENT_ACTION   5

/*************************************************************
 *
 * For each entity displayed, there is a structure of the 
 * following type malloc'ed.
 */
#define   NOTHING                 0
#define   FOLDER                  1
#define   ITEM                    2
#define   ICON                    3

typedef struct {
  char    *pathname;       /* full path name, malloced  */
  char    *ezfmData;       /* action specification      */
  void    *obj;            /* icon/folder/item          */
  void    *host;           /* for items: host folder    */
  time_t  mtime;           /* last modification time    */
  off_t   size;            /* size in bytes             */
  char    type;            /* type of obj attached to   */
  char    glob;            /* pathname is glob ptrn?    */
  char    notused[2];
} FileInfo;

/*************************************************************
 *
 *   Folder, kept in a list.
 */
#define ICON_FOLDER              1
#define LIST_FOLDER              2
#define TREE_FOLDER              3
#define ICON_FOLDER_SMALL        4
#define defaultFolderType        ICON_FOLDER

#define EZFM_FLISTBOX_N_ENTRIES  10


typedef struct folder_ {
  int            type;        /* style to display contents  */
  EZ_Widget      *frame;      /* the container frame        */
  EZ_Widget      *barframe;   /* the top toolbar frame      */
  EZ_Widget      *optentry;   /* display dir name in o-bar  */
  EZ_Widget      *workarea;   /* file lister: ICON_FOLDER   */
  EZ_Widget      *workareaS;  /* ICON_FOLDER w small icons  */
  EZ_Widget      *flistbox;   /* file lister: LIST_FOLDER   */
  EZ_Widget      *listtree;   /* file lister: TREE_FOLDER   */
  char           *bgpixmap;   /* bg pixmap file name        */
  int            blocked;     /* set when DnD is in action  */
  FileInfo       *finfo;      /* directory info             */
  void           *toplevel;   /* toplevel widget it is in   */
  int            flags;       /* various flags,             */
  struct folder_ *next;       /* the chain                  */
} Folder;

/*************************************************************
 *
 * Toplevel widgets. The place holder for folders.
 */

typedef struct toplevel_ {
  EZ_Widget   *toplevel;      /* toplevel frame             */
  EZ_Widget   *menubar;       /* the  menubar               */
  EZ_Widget   *toolbar;       /* the optional toolbar       */
  EZ_Widget   *folderframe;   /* frame to hold folders      */
  EZ_Widget   *panehandle;    /* the divider                */
  Folder      *folder[2];     /* maximal two folders        */  
  Folder      *activeFolder;  /* one of the above           */
  EZ_Widget   *statuslabel;   /* the status label           */
  int         flags;          /* various flags,             */
} Toplevel;

/*************************************************************/
#define  AUTO_UPDATE_BIT         (1<<0)
#define  SHOW_HIDDEN_BIT         (1<<1)
#define  RUBBER_BAND_BIT         (1<<2)
#define  DONT_CONFIRM_ACT_BIT    (1<<3)
#define  DONT_CONFIRM_DND_BIT    (1<<4)
#define  DONT_CONFIRM_TOOL_BIT   (1<<5)
#define  IGNORE_EXEC_ERROR_BIT   (1<<6)

#define  SORT_BY_SIZE            (1<<7)
#define  SORT_BY_TIME            (1<<8)
#define  SORT_BY_BITS            ((1<<7)|(1<<8))
#define  SORTER_CHANGED          (1<<9)

#define  DND_UPDATE_PENDING      (1<<29)
/*************************************************************
 *
 * Icon,  also kept in a list
 */
typedef struct icon_ {
  EZ_Widget      *icon;       /* the icon widget            */
  FileInfo       *finfo;      /* directory info             */
  int            isTool;      /* is a tool item ?           */
  int            blocked;
  struct icon_   *next;
} Icon;

/*************************************************************
 *
 * Removable Drives.
 */
typedef struct {
  char         *name;             /* how we call it   */
  char         *mntPt;            /* dir to mount it  */
  char         *xpmlable[2];      /* label pixmaps    */
  int          status;            /* 0 for umounted, 1 for mounted */
  int          blocked;
  FileInfo     *finfo;
} removableDrive;


/****************************************************
 * 
 * Global variables
 */
#ifndef _MAIN_C_
EXTERN int                ezfmFontId[];
EXTERN EZ_LabelPixmap     *ezfmDirPixmaps[4];
EXTERN removableDrive     ezfmDrives[8];
EXTERN char               *ezfmRc;
EXTERN char               *ezfmMagicFile;
EXTERN char               *ezfmSuffixFile;
EXTERN char               *ezfmIconPath;
EXTERN char               ezfmHostname[64];
EXTERN EZ_Widget          *ezfmToolBox;
EXTERN EZ_Widget          *ezfmToolBar;
EXTERN EZ_Widget          *renameEntry;
EXTERN int                ezfmFlags;
EXTERN int                ezfmRbtnCounter;
EXTERN char               ezfmFolderBgPixmap[];
EXTERN EZ_Widget          *ezfmDragIcon;
EXTERN Cursor             ezfmDragCursor;
EXTERN Pixmap             rootBgPixmap;
EXTERN EZ_LabelPixmap     *bigPixmap;  
EXTERN int                transparent;
EXTERN Display            *theDisplay;
EXTERN Window             theRootWindow;
EXTERN int                theScreen, theDepth;
EXTERN Visual             *theVisual;         

#endif

#ifndef _ATOMS_C_

EXTERN Atom     ezfmWMProtocolsAtom;
EXTERN Atom     ezfmDeleteWindowAtom;

EXTERN Atom     ezfmFileNameAtom;
EXTERN Atom     ezfmFileContentAtom; 
EXTERN Atom     ezfmFileTaredContentAtom;

EXTERN Atom     ezfmMoveFileByNameAtom;

EXTERN Atom     ezfmCopyFileByNameAtom;
EXTERN Atom     ezfmCopyFileByContentAtom;
EXTERN Atom     ezfmCopyFileByTarAtom;

EXTERN Atom     ezfmLinkFileByNameAtom;

EXTERN Atom    ezfmFileInfoAtom;

EXTERN Atom    ezfmMsgFolderInqueryAtom;
EXTERN Atom    ezfmMsgFolderOpenedAtom;
EXTERN Atom    ezfmMsgFolderClosedAtom;

EXTERN Atom    ezfmMsgMountTbChangeAtom;
EXTERN Atom    ezfmToolExecutionAtom;

EXTERN Atom    ezfmMultipleFileNamesAtom;
EXTERN Atom    ezfmMoveMultipleFilesAtom;
EXTERN Atom    ezfmCopyMultipleFilesAtom;
EXTERN Atom    ezfmLinkMultipleFilesAtom;
EXTERN Atom    XROOTPMAP_ID;
#endif

#ifndef _TRANSPARENT_C_
EXTERN  float trgbtd[4];
#endif
/*************************************************************
 *
 *           Function Prototypes
 *
 *************************************************************/
#ifndef _BTNBOX_C_
EXTERN EZ_Widget *createButtonBox MY_ANSIARGS((EZ_Widget *par, char *lab));
EXTERN EZ_Widget *getBboxCurrentButton MY_ANSIARGS((EZ_Widget *btnBox));
EXTERN EZ_Widget *newBboxButton  MY_ANSIARGS(( EZ_Widget *bbox, int active));
#endif

#ifndef _ACTION_C_
EXTERN void ezfmDoSomething   MY_ANSIARGS((FileInfo *finfo));
EXTERN void ezfmItemOpenDir   MY_ANSIARGS((void *obj, void *data));
EXTERN void ezfmItemOpenDirN  MY_ANSIARGS((void *obj, void *data));
EXTERN void ezfmSend2Netscape MY_ANSIARGS((void *obj, void *data));
EXTERN void ezfmFollowLink    MY_ANSIARGS((void *obj, void *data));
EXTERN void ezfmProcessCmdline MY_ANSIARGS((char *cmd, char *path, char *cmd_ret));
EXTERN char **ezfmExtractDoubleClickCommands MY_ANSIARGS ((char *spec, int *cnt));

EXTERN void ezfmExecutionErrorI MY_ANSIARGS ((char *l1, char *l2, char *l3, char *l4));
EXTERN void ezfmExecutionError MY_ANSIARGS ((char *cmd, char *err));
EXTERN void ezfmWarning        MY_ANSIARGS ((char *what, char *msg));

EXTERN void executeShCmd        MY_ANSIARGS ((char *cmd, void (*f)(), int nargs, void **args));
EXTERN void oneCommandDialogue MY_ANSIARGS((char *t, char *msg, char *cmd, int fcs, 
				     void (*f)(), int nargs, void **args));
EXTERN void oneCommandDialogueNCF MY_ANSIARGS((char *t, char *msg, char *cmd, int fcs, 
                                        void (*f)(), int nargs, void **args, int ncf));
EXTERN void (*ezfmGetBuiltInCommand()) ();
EXTERN void ezfmQuotePathname   MY_ANSIARGS ((char *pin, char *pout));
#endif

#ifndef _ANIMATE_C_
EXTERN void setupAnimation   MY_ANSIARGS((EZ_Widget *widget, EZ_LabelPixmap **pixmaps, int n));
EXTERN void startAnimation   MY_ANSIARGS((EZ_Widget *widget, long sec, long usec, int count));
EXTERN void stopAnimation    MY_ANSIARGS((EZ_Widget *widget));
EXTERN void setupAnimationDF MY_ANSIARGS((EZ_Widget *w, char *dir, char *base, int dgts, int start));
#endif

#ifndef _ATOMS_C_
EXTERN void initAtoms MY_ANSIARGS((void));
#endif

#ifndef _BGN_C_
EXTERN void setObjBgPixmap    MY_ANSIARGS((void *obj, char *cptr, void *data));
EXTERN char **listBgPatterns  MY_ANSIARGS((int *cnt));
EXTERN void setBackdropCB     MY_ANSIARGS((void *obj, void *data));
#endif


#ifndef _CLIENT_MESSAGE_C_
EXTERN void clientMessageHandler MY_ANSIARGS((EZ_Widget *w, void *data, int et, XEvent *xev));
#endif

#ifndef _DNDA_C_
EXTERN int  finfoEncodeFileName  MY_ANSIARGS((FileInfo *finfo, char **message_ret, 
				       int *length_ret, int *needFree));
EXTERN int  finfoEncodeFileContent MY_ANSIARGS((FileInfo *finfo, char **message_ret,
					 int *length_ret, int *needFree));
EXTERN int  finfoEncodeTaredFileContent MY_ANSIARGS((FileInfo *finfo, char **message_ret,
					      int *length_ret, int *needFree));
EXTERN int  finfoEncodeFileInfo    MY_ANSIARGS((FileInfo *finfo, char **message_ret,
					 int *length_ret, int *needFree));

EXTERN void finfoEncodeStatInfoAndPathname MY_ANSIARGS((char *pathname, struct stat *statInfo,
						 char *dest));
EXTERN int  decodeStatInfoAndPathname MY_ANSIARGS((char *str, char **path, unsigned long *dev, 
					    unsigned long *ino, unsigned long *mode,
					    unsigned long *size));

EXTERN int canSeeTheFile MY_ANSIARGS((char *path, char *info));

#endif


#ifndef _DNDB_C_
EXTERN int moveToDirByName MY_ANSIARGS((char *destDir, char *message, int length));
EXTERN int linkToDirByName MY_ANSIARGS((char *destDir, char *message, int length));
EXTERN int copyToDirByName MY_ANSIARGS((char *destDir, char *message, int length));
EXTERN int copyToDirByContent MY_ANSIARGS((char *destDir, char *message, int length));
EXTERN int copyToDirByTar MY_ANSIARGS((char *destDir, char *message, int length));
#endif


#ifndef _DNDC_C_
EXTERN int dirDnDTargetStartFilter MY_ANSIARGS((void *obj, void *data, char *msg, int len));
EXTERN int dirDnDTargetFinishFilter MY_ANSIARGS((void *obj, void *data, char *msg, int len));
#endif


#ifndef _DNDD_C_
EXTERN int ezfmEncodeFileName MY_ANSIARGS((void *obj, void *data, char **message_ret,
				    int *length_ret, int *needFree));
EXTERN int ezfmEncodeFileContent MY_ANSIARGS((void *obj, void *data, char **message_ret,
				       int *length_ret, int *needFree));
EXTERN int ezfmEncodeTaredFileContent MY_ANSIARGS((void *obj, void *data, char **message_ret,
					    int *length_ret, int *needFree));

EXTERN int  ezfmEncodeFileInfo    MY_ANSIARGS((void *obj, void *data, char **message_ret,
					int *length_ret, int *needFree));

EXTERN int ezfmMoveToDirByName MY_ANSIARGS((void *obj, void *data, char *message, int length));

EXTERN int ezfmCopyToDirByName MY_ANSIARGS((void *obj, void *data, char *message, int length));
EXTERN int ezfmCopyToDirByContent MY_ANSIARGS((void *obj, void *data, char *message, int length));
EXTERN int ezfmCopyToDirByTar MY_ANSIARGS((void *obj, void *data, char *message, int length));

EXTERN int ezfmLinkToDirByName MY_ANSIARGS((void *obj, void *data, char *message, int length));
EXTERN int ezfmEncodeMultipleFileNames  MY_ANSIARGS((void *obj, void *data, char **message_ret,
                                                     int *length_ret, int *needFree));
EXTERN int ezfmMoveMultipleFilesD MY_ANSIARGS((void *obj, void *data, char *message, int length));
EXTERN int ezfmCopyMultipleFilesD MY_ANSIARGS((void *obj, void *data, char *message, int length));
EXTERN int ezfmLinkMultipleFilesD MY_ANSIARGS((void *obj, void *data, char *message, int length));
#endif


#ifndef _DNDE_C_

EXTERN int ezfmIIEncodeStartFilter MY_ANSIARGS((void *item, void *data, 
					 char **message, int *length,
					 int *needFree));
EXTERN int ezfmIIEncodeFinishFilter MY_ANSIARGS((void *item, void *data, 
					 char **message, int *length,
					 int *needFree));

EXTERN int ezfmIIDecodeStartFilter MY_ANSIARGS((void *item, void *data, 
					   char *message, int length));
EXTERN int ezfmIIDecodeFinishFilter MY_ANSIARGS((void *item, void *data, 
					  char *message, int length));

EXTERN int ezfmFolderEncodeStartFilter MY_ANSIARGS((void *item, void *data, 
					 char **message, int *length,
					 int *needFree));
EXTERN int ezfmFolderEncodeFinishFilter MY_ANSIARGS((void *item, void *data, 
					 char **message, int *length,
					 int *needFree));

#endif

#ifndef _DNDR_C_
EXTERN int  ezfmDropOnRootWin MY_ANSIARGS((EZ_Item *item, void *data, char **message,
				    int *length, int *needFree));
#endif


#ifndef _DRIVES_C_
EXTERN int   setupDrivesButtons    MY_ANSIARGS((EZ_Widget *toolbar, int start_idx));
EXTERN void  updateDriveMenusAndButtons MY_ANSIARGS((void));
EXTERN void  updateDriveMenu       MY_ANSIARGS((EZ_Widget *menu, void *data));
EXTERN void  addRemovableDevice    MY_ANSIARGS((char *buf));
#endif


#ifndef _FINFO_C_
EXTERN char *GetFileTypeInfo  MY_ANSIARGS((char *name));
EXTERN void getSpecField  MY_ANSIARGS ((char *spec, int field, char *filed_ret));
EXTERN char *gotoSpecField MY_ANSIARGS ((char *spec, int field1));
EXTERN void getSpecColor MY_ANSIARGS ((char *spec, char *ret));
EXTERN void getSpecPixmap MY_ANSIARGS ((char *spec, char *ret, char *ret1));
EXTERN int getSpecFontId  MY_ANSIARGS ((char *spec));
#endif

#ifndef _FOLDER_C_
EXTERN void     OpenFolder MY_ANSIARGS ((char *pathname, Folder *folder, int dp, int type));
EXTERN void     updateFolder  MY_ANSIARGS ((Folder *folder, int flag));
EXTERN Folder   *findFolder MY_ANSIARGS ((char *pathname));
EXTERN EZ_Item  *getFolderSelection MY_ANSIARGS ((Folder *folder));
EXTERN Folder   *createNewFolder MY_ANSIARGS((char *pathname, Toplevel *tp, int where, int type));
EXTERN int      countNFolders  MY_ANSIARGS ((void));
EXTERN void     BroadcastFolderOpenCloseded MY_ANSIARGS((char *pathname, int mode));
EXTERN void     OpenCloseDirItemInFolder MY_ANSIARGS((char *pathname, int mode));
EXTERN void     findOpenedFolderOtherClients MY_ANSIARGS((char *pathname, struct stat  *stat_buf));
EXTERN int      entryDirNameDecoder MY_ANSIARGS ((void *obj, void *data, char *msg, int len));
EXTERN int      isToplevel MY_ANSIARGS ((void *ptr));
EXTERN int      folderExists  MY_ANSIARGS ((Folder *folder));
EXTERN void     entryCanonicalString MY_ANSIARGS ((EZ_Widget *obj, void *data));
EXTERN Folder   *getFolderList MY_ANSIARGS((void));
EXTERN void     setToplevelName MY_ANSIARGS(( Toplevel *tp));
EXTERN EZ_Widget *makeToolBar MY_ANSIARGS ((Toplevel *tp));
EXTERN Folder   *ezfmGetFolderList MY_ANSIARGS((void));
EXTERN void     modifyDpyOptionAllFolders MY_ANSIARGS((int flag, char *bg));
EXTERN void     modifyDpyOptionOneFolder MY_ANSIARGS((Folder *folder, int flag, char *bg, int dobg));
EXTERN void     ezfmResetAllBgPixmaps MY_ANSIARGS ((void));
EXTERN void     ConfigureNotifyHandler MY_ANSIARGS((EZ_Widget *widget, void *data, int etype,
                                                    XEvent *xev));
EXTERN void      popupRenameEntry MY_ANSIARGS((EZ_Widget *widget, int x, int y, int w, int h,
                                               void *obj, int kind));
EXTERN void      ezfmSetFolderSorter MY_ANSIARGS((Folder *folder, int sorter));
#endif


#ifndef _HASH_C_
EXTERN char *lookupNameFromHashTable MY_ANSIARGS(( char *name ));
EXTERN void insertNameToHashTable    MY_ANSIARGS(( char *name, char *value ));
EXTERN void initNameHashTable        MY_ANSIARGS(( void ));
EXTERN void destroyNameHashTable     MY_ANSIARGS(( void ));
#endif


#ifndef _ICONS_C_
EXTERN EZ_Widget *getCreateIcon        MY_ANSIARGS((char *pathname, int x, int y));
EXTERN EZ_Widget *createToolItemIcon   MY_ANSIARGS((char *pathname, char *tspec, int x, int y));
EXTERN EZ_Widget *lookupIcon      MY_ANSIARGS((char *pathname));
EXTERN EZ_Widget *lookupToolIcon  MY_ANSIARGS((char *pathname));
EXTERN void itemOrIconCallback    MY_ANSIARGS((EZ_Widget *icon, void *data));
EXTERN void OpenCloseIcon         MY_ANSIARGS((char *pathname, int mode));
EXTERN void findOpenedIconOtherClients MY_ANSIARGS((char *path, struct stat *stbuf));
EXTERN Icon *getIconList     MY_ANSIARGS((void));
EXTERN void deleteIcon       MY_ANSIARGS((Icon *icon));
#endif


#ifndef _INFO_C_

EXTERN char    *getFileShortInfo    MY_ANSIARGS((char *pathname, char *str));
EXTERN char    *getFileOwnerString  MY_ANSIARGS((char *str, struct stat *sbuf));
EXTERN char    *getFileGroupString  MY_ANSIARGS((char *str, struct stat *sbuf));
EXTERN char    *getFilePermiString  MY_ANSIARGS((char *str, struct stat *sbuf));
EXTERN char    *getFileMTimeString  MY_ANSIARGS((char *str, struct stat *sbuf));
EXTERN char    *strStMode           MY_ANSIARGS((char *str, int mode));

EXTERN char    *getFileType         MY_ANSIARGS((char *name, char *info_ret));
EXTERN int      getFileInfo         MY_ANSIARGS((char *name, char *info_ret, struct stat *stat_ret));
#endif


#ifndef _INFO_BTN_C_
EXTERN void setupInfoButton  MY_ANSIARGS((void *btn, void *data));
EXTERN void infoDialogue     MY_ANSIARGS((char *pathname, char *info_str,
				   struct stat *stat_ptr, char *comment));
#endif


#ifndef _ITEMS_C_
EXTERN EZ_Item   *createFileItem MY_ANSIARGS((char *pathname, char *label, Folder *folder, 
				     EZ_Item **ret_array));
EXTERN void setupDnDForItem MY_ANSIARGS((EZ_Item *item, FileInfo *finfo, int isDir));
EXTERN int  ezfmSetDragIconEncoder MY_ANSIARGS((EZ_Item *i, void *v, char **c, int *n, int *t));
#endif


#ifndef _MAIN_C_
EXTERN void  exitEzfm               MY_ANSIARGS((void *widget, void *data));
#endif

#ifndef _MBTN_FILE_C_

EXTERN void setupMBtnFile      MY_ANSIARGS((void *btn, void *data));
EXTERN void disableMtnFileNewFileDirItems MY_ANSIARGS((void));
EXTERN void enableMtnFileNewFileDirItems MY_ANSIARGS((void));

EXTERN void mBarItemDestroyCB  MY_ANSIARGS((void *widget, void *data));
EXTERN void gotoHome           MY_ANSIARGS((void *widget, void *data));
EXTERN void startFolder         MY_ANSIARGS((Folder *fldr, char *iname, char *title, char *instr));
#endif


#ifndef _MBTN_HELP_C_
EXTERN void setupMBtnHelp      MY_ANSIARGS((void *btn, void *data));
#endif

#ifndef _MBTN_OPTION_C_
EXTERN void setupMBtnOption      MY_ANSIARGS((void *btn, void *data));
#endif


#ifndef _MBTN_SELECTION_C_
EXTERN void setupMBtnSelection      MY_ANSIARGS((void *btn, void *data));
#endif


#ifndef _MBTN_VIEW_C_
EXTERN void setupMBtnView      MY_ANSIARGS((void *btn, void *data));
#endif

#ifndef _VIEW_FILE_C_
EXTERN void ezfmEditTextFile MY_ANSIARGS((char *pathname, int flag, char *msg));
EXTERN void ezfmViewTextFile MY_ANSIARGS(( void *obj, void *data));
#endif

#ifndef _MISC_C_
EXTERN int   getSerialNumber          MY_ANSIARGS((void));
EXTERN char  *getNewFileName          MY_ANSIARGS((char *pname, char *dir,
					    int timestr, char *name_ret));
EXTERN char  *getTmpFileName          MY_ANSIARGS((char *name_ret));
EXTERN void  deleteTmpFile            MY_ANSIARGS((char *pname, int when));
EXTERN int   locateCommand            MY_ANSIARGS(( char *name, char *path_ret ));
EXTERN void  removeTrailingSpaces     MY_ANSIARGS(( char *buf));
#endif


#ifndef _MNT1_C_
EXTERN void ezfmMount  MY_ANSIARGS((char *mpt, int idx, int msgId));
EXTERN void ezfmuMount MY_ANSIARGS((char *mpt, int idx, int msgId));

EXTERN int  ezfmIsMounted MY_ANSIARGS((char *mpt, int conly));
EXTERN int  ezfmIsInFstab MY_ANSIARGS((char *mpt, int conly));

EXTERN void  ezfmUpdateMountTable   MY_ANSIARGS ((void));
EXTERN void  ezfmUpdateMountTable1  MY_ANSIARGS ((char *mpt));

EXTERN void openDrive  MY_ANSIARGS((void *widget, void *data));
EXTERN void mountDrive  MY_ANSIARGS((char *mountPt, int idx, Folder *folder));
EXTERN void umountDrive  MY_ANSIARGS((char *mountPt, int idx));

#endif

#ifndef _NETSCAPE_C_
EXTERN int netscapeIsRunning MY_ANSIARGS((void));
EXTERN int xerrCode;
EXTERN int xerrHdlr MY_ANSIARGS(( Display *dpy, XErrorEvent *err));
#endif


#ifndef _POPUP_C_
EXTERN EZ_Widget *createPopupFileInfo  MY_ANSIARGS((FileInfo *finfo));
EXTERN void copyMoveLinkCB  MY_ANSIARGS((EZ_Widget *widget, void *data));
EXTERN void popupInfoDialogue  MY_ANSIARGS((EZ_Widget *widget, void *data));
#endif


#ifndef _PRINTER_C_
EXTERN void setupPrinter  MY_ANSIARGS((void *btn, void *data));
EXTERN void doPrintDialogue  MY_ANSIARGS((char *pathname));
EXTERN void printerDialogue MY_ANSIARGS((EZ_Widget *widget, void *data));
#endif


#ifndef _RC_C_
EXTERN void ProcessRCFile          MY_ANSIARGS((char *file, char *fret));
EXTERN int  nextLine    MY_ANSIARGS((char *buf, int *cnt, FILE *fp));
EXTERN char *skipSpaces MY_ANSIARGS((char *buf));
EXTERN int  seekWord    MY_ANSIARGS((char *buf, char **ptr_ret, int *cnt, FILE *fp, char *word));
EXTERN int  matchWord   MY_ANSIARGS((char *buf, char **ptr_ret, char *word));
#endif

#ifndef _SIGNAL_C_
EXTERN void  handleSigChild MY_ANSIARGS((void));
EXTERN void  handleOtherSig MY_ANSIARGS((void));
EXTERN void  exitHandler  MY_ANSIARGS ((void));
#endif

#ifndef _STATE_C_
EXTERN void ezfmSaveState  MY_ANSIARGS((EZ_Widget *widget, void *data));
EXTERN int  ezfmReadState  MY_ANSIARGS((void));
EXTERN int  ezfmReadStateA MY_ANSIARGS((void));
#endif

#ifndef _TOOL_BOX_C_
EXTERN void  addItemInToolBox       MY_ANSIARGS((char *page, char *clr, char *name, char *spec));
EXTERN int ezfmEncodeToolInfo MY_ANSIARGS((void *obj, void *data, char **message_ret,
				    int *length_ret, int *needFree));
EXTERN int ezfmDecodeToolInfo MY_ANSIARGS((void *obj, void *data, char *message, int length));
EXTERN int toolExecByName      MY_ANSIARGS((void *item, void *data, char *message, int length));
EXTERN int toolExecByContent   MY_ANSIARGS((void *item, void *data, char *message, int length));
EXTERN void toolItemOrIconCB   MY_ANSIARGS((EZ_Item *item, void *data));
EXTERN char *getToolSpec       MY_ANSIARGS((char *pathname));
#endif



#ifndef _TRASH_BTN_C_
EXTERN void setupTrashButton MY_ANSIARGS((void *btn, void *data));
EXTERN void move2Trashcan MY_ANSIARGS((char *pathname));
#endif

#ifndef _EXTENSION_C_
EXTERN char  *GetSpecFromExtension    MY_ANSIARGS((char *pathname));
EXTERN void  ProcessSuffixFile         MY_ANSIARGS((char *fname));
#endif

#ifndef _TRANSPARENT_C_
EXTERN void doTransparencyDialogue MY_ANSIARGS((EZ_Widget *widget, void *data));
EXTERN void setupTransparencyDialogue MY_ANSIARGS((int flag));
EXTERN void ezfmPopupWarning MY_ANSIARGS((char *a, char *b, char *c, char *d));
EXTERN void ezfmSetroot       MY_ANSIARGS((void *obj, void *data));
EXTERN void ezfmScaleSetroot  MY_ANSIARGS((void *obj, void *data));
#endif
/****************************************************************************************/
EXTERN char *GetSpecFromMagic  MY_ANSIARGS((char *name));

