📄 mfm.c
字号:
return (n);}voidgetpath (side * whichside, char **path){ int i; if (debug) printf ("In getpath()\n"); *path = (char *) malloc ((pathlength (whichside) + 300) * sizeof (char)); strcpy (*path, "/"); for (i = 0; i < whichside->length; i++) { strcat (*path, whichside->path[i]); strcat (*path, "/"); } if (debug) { printf (" path: %s+\n", *path); printf ("End getpath()\n"); }}voidclearpath (side * whichside){ int i; if (debug) { printf ("In clearpath()\n"); printf (" length: %i\n", whichside->length); } for (i = 0; i < whichside->length; i++) free (whichside->path[i]); whichside->length = 0; if (debug) printf ("End clearpath()\n");}voidgethdpath (side * whichside){ char *path = NULL; char *position; char *nextposition; if (debug) { printf ("In gethdpath()\n"); printf (" whichside: %p\n", whichside); } clearpath (whichside); errno = 0; path = malloc (50 * sizeof (char)); while ((!getcwd (path, 49)) && (errno == ERANGE)) path = g_realloc (path, (strlen (path) + 50) * sizeof (char)); strcat (path, "/"); if (debug) printf (" path: %s\n", path); position = path + 1; nextposition = strstr (position, "/"); while (nextposition && (whichside->length < DIR_DEPTH - 1)) { whichside->path[whichside->length] = malloc (sizeof (char) * ((nextposition - position) + 1)); strncpy (whichside->path[whichside->length], position, nextposition - position); whichside->path[whichside->length][nextposition - position] = '\0'; whichside->length += 1; position = nextposition + 1; nextposition = strstr (position, "/"); } free (path); if (debug) { printf (" length: %i\n", whichside->length); printf ("End gethdpath()\n"); } return;}intread_configfile (side * leftside, const char *cfname){ int i; char buff[120]; char *pos; FILE *cfile; if (debug) { printf ("In read_configfile()\n"); printf (" leftside: %p\n", leftside); } if ((cfile = fopen (cfname, "r"))) { strcpy (drives, ""); while (fgets (buff, 119, cfile)) { if ((pos = strchr (buff, '#'))) *pos = '\0'; if ((pos = strchr (buff, '\n'))) *pos = '\0'; if (!strncmp (buff, "DRIVES=\"", 8)) for (i = 8; (pos = strchr ("abcdefghijklmnopqrstuvwxyz", buff[i])); i++) if (!strchr (drives, *pos)) { drives[strlen (drives) + 1] = '\0'; drives[strlen (drives)] = *pos; } if (!strncmp (buff, "MPATH=\"", 7)) { for (i = 0; (buff[i + 7] != '\"') && buff[i + 7] && (buff[i + 7] != '\n'); i++) mpath[i] = buff[i + 7]; mpath[i] = '\0'; } if (!strncmp (buff, "LEFTDRIVE=\"", 11)) leftside->drive = buff[11]; if (!strncmp (buff, "RIGHTDRIVE=\"", 12)) leftside->other->drive = buff[12]; } fclose (cfile); if (!strchr (drives, leftside->drive)) leftside->drive = '\0'; if (!strchr (drives, leftside->other->drive)) leftside->other->drive = '\0'; if (debug) { printf (" found %s\n", cfname); printf (" drives %s\n", drives); printf (" leftside->drive %c\n", leftside->drive); printf (" leftside->other->drive %c\n", leftside->other->drive); printf ("End read_configfile()\n"); } return (0); } else { if (debug) { printf (" didn磘 find %s\n", cfname); printf ("End read_configfile()\n"); } return (1); }}voidsave_config (side * leftside){ char *cfname; FILE *cfile; cfname = malloc ((strlen (homedir) + 11) * sizeof (char)); strcpy (cfname, homedir); strcat (cfname, "/.mtoolsfm"); if (debug) printf ("In save_config()\n"); if ((cfile = fopen (cfname, "w"))) { fprintf (cfile, "# MToolsFM config file. comments start with a hash sign.\n"); fprintf (cfile, "# \n"); fprintf (cfile, "# This variable sets the allowed driveletters (all lowercase). Example:\n"); fprintf (cfile, "# DRIVES=\"ab\"\n"); fprintf (cfile, "DRIVES=\"%s\"\n", drives); fprintf (cfile, "# \n"); fprintf (cfile, "# This variable sets the driveletter upon startup in the left window. \n"); fprintf (cfile, "# An empty string or space is for the hardisk. Example: \n"); fprintf (cfile, "# LEFTDRIVE=\"a\"\n"); fprintf (cfile, "LEFTDRIVE=\"%c\"\n", leftside->drive ? leftside->drive : ' '); fprintf (cfile, "# \n"); fprintf (cfile, "# This variable sets the driveletter upon startup in the right window. \n"); fprintf (cfile, "# An empty string or space is for the hardisk. Example: \n"); fprintf (cfile, "# RIGHTDRIVE=\"a\"\n"); fprintf (cfile, "RIGHTDRIVE=\"%c\"\n", leftside->other->drive ? leftside->other->drive : ' '); fprintf (cfile, "# This variable sets the path to the mtools commands. \n"); fprintf (cfile, "# If left empty, " MTOOLSDIR " is assumed.\n"); fprintf (cfile, "MPATH=\"%s\"\n", mpath); fclose (cfile); } free (cfname);}voidset_combo_entries (side * whichside){ char *pos, *buff; char curdrive[3] = " :"; GList *listpos, *bufflist; if (debug) printf ("In set_combo_entries()\n"); listpos = NULL; listpos = g_list_append (listpos, "Harddisk"); for (pos = drives; *pos; pos++) { buff = malloc (3 * sizeof (char)); buff[0] = *pos; buff[1] = ':'; buff[2] = '\0'; listpos = g_list_append (listpos, buff); } bufflist = whichside->comboglist; gtk_combo_set_popdown_strings (GTK_COMBO (whichside->combo), listpos); for (listpos = bufflist; listpos; listpos = listpos->next) free (listpos->data); g_list_free (bufflist); if (!whichside->drive) gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (whichside->combo)->entry), "Harddisk"); else { curdrive[0] = whichside->drive; gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (whichside->combo)->entry), curdrive); } if (debug) printf ("End set_combo_entries()\n");}intdelete_recursive (const char *path){ DIR *directory; char *fullpath; struct dirent *entry; struct stat buf; int result = 0; if (debug) printf ("In delete_recursive()\n"); fullpath = malloc ((strlen (path) + 258) * sizeof (char)); directory = opendir (path); if (directory) { entry = readdir (directory); while (entry) { strcpy (fullpath, path); strcat (fullpath, "/"); strcat (fullpath, entry->d_name); if (strcmp (entry->d_name, "..") && strcmp (entry->d_name, ".")) { stat (fullpath, &buf); if (S_ISDIR (buf.st_mode)) { if (delete_recursive (fullpath)) { break; result = 1; } } else { if (unlink (fullpath)) { break; result = 1; } } } entry = readdir (directory); } if (rmdir (path)) result = 1; } free (fullpath); if (debug) printf ("End delete_recursive()\n"); return (result);}voiddestroy_dentry (gpointer data){ if (debug) printf ("In destroy_dentry()\n"); free (data); if (debug) printf ("End destroy_dentry()\n");}voidselectall_event (GtkWidget * widget, side * whichside){ if (debug) printf ("In selectall_event()\n"); if (!GTK_CLIST (whichside->list)->rows) return; gtk_clist_select_all (GTK_CLIST (whichside->list));}voidselectnone_event (GtkWidget * widget, side * whichside){ if (debug) printf ("In selectnone_event()\n"); gtk_clist_unselect_all (GTK_CLIST (whichside->list));}voidrefresh_event (GtkWidget * widget, side * whichside){ char *path, *filebegin; dentry *current; if (debug) printf ("In refresh_event()\n"); gtk_clist_clear (GTK_CLIST (whichside->list)); getpath (whichside, &path); if (whichside->drive) { shiftstring (path, 2); path[0] = whichside->drive; path[1] = ':'; } filebegin = path + strlen (path); if (!whichside->drive) { DIR *directory; struct stat buf; struct dirent *entry; char *position; char size[16] = ""; char date[11] = ""; char time[6] = ""; int pathlen; gint row; gchar *tmppoint[5]; if (debug) printf (" reading from unix-filesystem...\n"); tmppoint[0] = NULL; tmppoint[2] = (gchar *) & size; tmppoint[3] = (gchar *) & date; tmppoint[4] = (gchar *) & time; pathlen = pathlength (whichside); position = path + strlen (path); gtk_statusbar_pop (GTK_STATUSBAR (whichside->status), whichside->context); gtk_statusbar_push (GTK_STATUSBAR (whichside->status), whichside->context, path); directory = opendir (path); if (directory) { gtk_clist_freeze (GTK_CLIST (whichside->list)); if (debug) printf (" entering loop and reading directory contents...\n"); entry = readdir (directory); while (entry) { strcpy (position, entry->d_name); if (debug) printf (" filename: %s+\n", path); if ( (GTK_CHECK_MENU_ITEM (showdots)->active || !strcmp (position, "..") || (*position != '.')) && strcmp (position, ".") && (!((pathlen == 1) && (!strcmp (position, ".."))))) { current = malloc (sizeof (dentry)); strcpy (current->name, entry->d_name); stat (path, &buf); if (S_ISDIR (buf.st_mode)) current->dir = 1; else current->dir = 0; tmppoint[1] = current->name; sprintf (size, "%li", buf.st_size); current->size = buf.st_size; sprintf (date, "%-2.2i-%-2.2i-%-4.4i", localtime (&(buf.st_ctime))->tm_mon, localtime (&(buf.st_ctime))->tm_mday, localtime (&(buf.st_ctime))->tm_year + 1900); sprintf (time, "%-2.2i:%-2.2i", localtime (&(buf.st_ctime))->tm_hour, localtime (&(buf.st_ctime))->tm_min); row = gtk_clist_append (GTK_CLIST (whichside->list), tmppoint); if (!strcmp (position, "..")) gtk_clist_set_selectable (GTK_CLIST (whichside->list), row, FALSE); lstat (path, &buf); if (current->dir) { if (S_ISLNK (buf.st_mode)) { gtk_clist_set_foreground (GTK_CLIST (whichside->list), row, whichside->linkcolor);#ifndef NOPIXMAPS gtk_clist_set_pixmap (GTK_CLIST (whichside->list), row, 0, linkdirpix, linkdirmask);#endif } else { gtk_clist_set_foreground (GTK_CLIST (whichside->list), row, whichside->dircolor);#ifndef NOPIXMAPS gtk_clist_set_pixmap (GTK_CLIST (whichside->list), row, 0, dirpix, dirmask);#endif } } else { if (S_ISLNK (buf.st_mode)) { gtk_clist_set_foreground (GTK_CLIST (whichside->list), row, whichside->linkcolor);#ifndef NOPIXMAPS gtk_clist_set_pixmap (GTK_CLIST (whichside->list), row, 0, linkfilepix, linkfilemask);#endif } else {#ifndef NOPIXMAPS gtk_clist_set_pixmap (GTK_CLIST (whichside->list), row, 0, filepix, filemask);#endif } } gtk_clist_set_row_data_full (GTK_CLIST (whichside->list), row, (gpointer) current, destroy_dentry); } entry = readdir (directory); } closedir (directory); if (debug) printf (" end of loop\n"); gtk_clist_thaw (GTK_CLIST (whichside->list)); } else if (whichside->length) { if (debug) { printf (" Opening of directory not successfull.\n"); printf (" cd to parent and recurse.\n"); } whichside->length -= 1; free (whichside->path[whichside->length]); free (path); refresh_event (whichside->list, whichside); if (debug) printf ("End refresh_event()\n"); return; } } else { FILE *outpipe, *stderrout; char buff[340]; char *command; char dosname[9]; char dosext[4]; char size[10]; char date[11]; char time[6]; char vfatname[298]; int entcount = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -