⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfm.c

📁 a graphic tools for MTools
💻 C
📖 第 1 页 / 共 5 页
字号:
      void *success;      gint row;      gchar *tmppoint[5];      int status;      pid_t childpid;      int stdoutpipe[2];      int stderrpipe[2];/*       GtkWidget *busywindow; */      if (debug)	printf ("  reading from floppy...\n");/*       busywindow=ambusy("working...","Reading directory contents. Please wait."); */      tmppoint[0] = NULL;      tmppoint[1] = (gchar *) & vfatname;      tmppoint[2] = (gchar *) & size;      tmppoint[3] = (gchar *) & date;      tmppoint[4] = (gchar *) & time;      gtk_statusbar_pop (GTK_STATUSBAR (whichside->status),			 whichside->context);      gtk_statusbar_push (GTK_STATUSBAR (whichside->status),			  whichside->context, path);      if (pipe (stdoutpipe) < 0)	{	  printf ("  Error with pipe()\n");	  gtk_main_quit ();	}      if (pipe (stderrpipe) < 0)	{	  printf ("  Error with pipe()\n");	  gtk_main_quit ();	}      if ((childpid = fork ()) < 0)	{	  printf ("  Error with fork()\n");	  exit (-1);	}      else if (childpid == 0)	/* child */	{	  if (debug)	    printf ("  in child\n");	  close (stdoutpipe[0]);	  close (stderrpipe[0]);	  if (stdoutpipe[1] != STDOUT_FILENO)	    {	      if (dup2 (stdoutpipe[1], STDOUT_FILENO) != STDOUT_FILENO)		{		  printf ("  Error with dup2()\n");		  gtk_main_quit ();		}	      close (stdoutpipe[1]);	    }	  if (stderrpipe[1] != STDERR_FILENO)	    {	      if (dup2 (stderrpipe[1], STDERR_FILENO) != STDERR_FILENO)		{		  printf ("  Error with dup2()\n");		  gtk_main_quit ();		}	      close (stderrpipe[1]);	    }	  execl (mtoolscommand, "mdir", path, NULL);	  printf ("  error in execl()\n");	  printf ("  errno:%d\n", errno);	  _exit (-1);	}      else			/* parent */	{	  if (debug)	    printf ("  in parent. childpid:%i\n", childpid);	  close (stdoutpipe[1]);	  close (stderrpipe[1]);	  if ((outpipe = fdopen (stdoutpipe[0], "r")) == NULL)	    {	      printf ("  Error while opening stdout pipe for reading\n");	      gtk_main_quit ();	    }	  if ((stderrout = fdopen (stderrpipe[0], "r")) == NULL)	    {	      printf ("  Error while opening stderr pipe for reading\n");	      gtk_main_quit ();	    }	  er_interface (stderrout);	  while ((success = fgets (buff, 340, outpipe))		 && strncmp (buff, " Directory for", 14)		 && strncmp (buff, "Directory for", 13));	  if (!success)	    {	      if (debug)		printf ("  could not get \"Directory for\"\n");	      pclose (outpipe);	      /*          gtk_grab_remove(busywindow); */	      /*          gtk_widget_destroy(busywindow); */	      if (whichside->length)		{		  if (debug)		    printf ("  trying again...\n");		  clearpath (whichside);		  refresh_event (whichside->list, whichside);		}	      free (path);	      return;	    }	  if (!fgets (buff, 340, outpipe) || (strlen (buff) != 1))	    {	      if (debug)		printf ("  unexpected output\n");	      pclose (outpipe);	      /*          gtk_grab_remove(busywindow); */	      /*          gtk_widget_destroy(busywindow); */	      if (whichside->length)		{		  if (debug)		    printf ("  trying again...\n");		  clearpath (whichside);		  refresh_event (whichside->list, whichside);		}	      free (path);	      return;	    }	  if (debug)	    printf ("  entering loop and reading directory contents...\n");	  gtk_clist_freeze (GTK_CLIST (whichside->list));	  while (fgets (buff, 340, outpipe) && (buff[0] != ' ')		 && (strlen (buff) >= 40))	    {	      if (debug)		printf ("  read line: %s+\n", buff);	      entcount += 1;	      strncpy (dosname, buff, 8);	      strncpy (dosext, buff + 9, 3);	      strncpy (size, buff + 13, 9);	      strncpy (date, buff + 23, 10);	      strncpy (time, buff + 35, 5);	      if (*time == ' ')		*time = '0';	      dosname[8] = '\0';	      dosext[3] = '\0';	      size[9] = '\0';	      date[10] = '\0';	      time[5] = '\0';	      removespace (dosname);	      removespace (dosext);	      removespace (size);	      removespace (time);	      if (strlen (buff) > 42)		{		  strncpy (vfatname, buff + 42, strlen (buff) - 42);		  vfatname[strlen (buff + 42) - 1] = '\0';		}	      else		{		  strcpy (vfatname, dosname);		  if (strlen (dosext))		    {		      strcat (vfatname, ".");		      strcat (vfatname, dosext);		    }		}	      if (strcmp (vfatname, "."))		{		  current = malloc (sizeof (dentry));		  strcpy (current->name, vfatname);		  if (strcmp (size, "<DIR>"))		    current->dir = 0;		  else		    {		      current->dir = 1;		      strcpy (size, "0");		    }		  current->size = atol (size);		  row =		    gtk_clist_append (GTK_CLIST (whichside->list), tmppoint);		  if (!strcmp (vfatname, ".."))		    gtk_clist_set_selectable (GTK_CLIST (whichside->list),					      row, FALSE);#ifndef NOPIXMAPS		  if (current->dir)		    gtk_clist_set_pixmap (GTK_CLIST (whichside->list), row, 0,					  dirpix, dirmask);		  else		    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);		}	    }	  if (debug)	    printf ("  end of loop\n");	  if (!entcount && whichside->length)	    {	      if (debug)		printf ("  strange output: zero entries in subdir\n");	      clearpath (whichside);	      gtk_clist_thaw (GTK_CLIST (whichside->list));	      if (debug)		printf ("  trying again...\n");	      refresh_event (whichside->list, whichside);	    }	  else	    gtk_clist_thaw (GTK_CLIST (whichside->list));	  if (waitpid (childpid, &status, WNOHANG) == childpid)	    waitpid (childpid, &status, WUNTRACED);	}/*       gtk_grab_remove(busywindow); *//*       gtk_widget_destroy(busywindow); */    }  free (path);  gtk_clist_sort (GTK_CLIST (whichside->list));  if (debug)    printf ("End refresh_event()\n");  return;}voiddelete_event (GtkWidget * widget, GdkEvent * event, side * whichside){  if (debug)    printf ("In delete_event()\n");  if (!nosave)    save_config (whichside);  if (debug)    printf ("End delete_event()\n");  gtk_main_quit ();}voidquit_event (GtkWidget * widget, side * whichside){  if (debug)    printf ("In quit_event()\n");  if (!nosave)    save_config (whichside);  if (debug)    printf ("End quit_event()\n");  gtk_main_quit ();}voidcopy_event (GtkWidget * widget, side * from){  side *to = from->other;  GList *items;  gint row;  msgenv msg;  GtkWidget *progressdialog, *progressbar, *progresslabel, *cancelbutton;  long copiedbytes = 0;  char *text, *frompath, *topath, *frombeginfile, *tobeginfile, *buff;  char warning[400];  int status, i, j, flag = 0, lex_result;  int copypipe[2];  FILE *mcopyout;  pid_t childpid;  char buff1[500];  if (debug)    printf ("In copy_event()\n");  msg.mvar = &flag;  msg.msg = 1;  getpath (from, &frompath);  if (from->drive)    {      shiftstring (frompath, 2);      frompath[0] = from->drive;      frompath[1] = ':';    }  frombeginfile = frompath + strlen (frompath);  getpath (to, &topath);  if (to->drive)    {      shiftstring (topath, 2);      topath[0] = to->drive;      topath[1] = ':';    }  tobeginfile = topath + strlen (topath);  if (debug)    printf ("  creating dialog\n");  progressdialog = gtk_dialog_new ();  gtk_window_set_title (GTK_WINDOW (progressdialog),			"Copying files. Please wait.");  gtk_widget_set_usize (GTK_WIDGET (progressdialog), 300, 0);  gtk_signal_connect (GTK_OBJECT (progressdialog), "delete_event",		      GTK_SIGNAL_FUNC (dialogclose_event), &msg);#ifndef OLDGTK  gtk_window_set_position (GTK_WINDOW (progressdialog), GTK_WIN_POS_CENTER);  gtk_container_set_border_width (GTK_CONTAINER (progressdialog), 10);#endif  progressbar = gtk_progress_bar_new ();  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (progressdialog)->vbox),		      progressbar, TRUE, TRUE, 5);  gtk_widget_show (progressbar);  progresslabel =    gtk_label_new    ("Copying files...\n\nThis progressbar will be updated\nafter each copied file.");  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (progressdialog)->vbox),		      progresslabel, TRUE, TRUE, 5);  gtk_widget_show (progresslabel);  cancelbutton = gtk_button_new_with_label ("Cancel");  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (progressdialog)->action_area),		      cancelbutton, TRUE, FALSE, 0);  gtk_signal_connect (GTK_OBJECT (cancelbutton), "clicked",		      GTK_SIGNAL_FUNC (dialog_event), &msg);  gtk_widget_show (cancelbutton);  GTK_WIDGET_SET_FLAGS (cancelbutton, GTK_CAN_DEFAULT);  gtk_widget_grab_default (cancelbutton);  gtk_widget_show (progressdialog);#ifndef NOPIXMAPS  gdk_window_set_icon (progressdialog->window, NULL, mfmpix, mfmmask);#endif  gtk_grab_add (progressdialog);  if (debug)    printf ("  entering loop...\n");  items = GTK_CLIST (from->list)->selection;  while (items && (!flag))    {      row = (gint) items->data;      gtk_clist_get_text (GTK_CLIST (from->list), row, 1, &text);      i = 0;      j = gtk_clist_get_text (GTK_CLIST (to->list), i, 1, &buff);      while (j)	{	  if (casecompare (buff, text))	    {	      i = -1;	      break;	    }	  i += 1;	  j = gtk_clist_get_text (GTK_CLIST (to->list), i, 1, &buff);	}      if (i == -1)	{	  if (debug)	    printf ("  file exists\n");	  strcpy (warning, "The file\n\n");	  strcat (warning, text);	  strcat (warning,		  "\n\nseems to exist in the target directory. If you want to overwrite it,\n\delete it in the target directory first and copy it again.");	  warnme ("File exists", warning);	  items = items->next;	  continue;	}      strcpy (frombeginfile, text);      strcpy (tobeginfile, text);      if (pipe (copypipe) < 0)	{	  printf ("  Error with pipe()\n");	  gtk_main_quit ();	}      if ((childpid = fork ()) < 0)	{	  printf ("  Error with fork()\n");	  exit (-1);	}      else if (childpid == 0)	/* child */	{	  if (debug)	    printf ("  in child\n");	  close (copypipe[0]);	  if (copypipe[1] != STDERR_FILENO)	    {	      if (dup2 (copypipe[1], STDERR_FILENO) != STDERR_FILENO)		{		  printf ("  Error with dup2()\n");		  gtk_main_quit ();		}	      close (copypipe[1]);	    }	  if (GTK_CHECK_MENU_ITEM (textmode)->active)	    execl (mtoolscommand, "mcopy", "-nmot", frompath, topath, NULL);	  else	    execl (mtoolscommand, "mcopy", "-nmo", frompath, topath, NULL);	  printf ("  error in execl()\n");	  printf ("  errno:%d\n", errno);	  _exit (-1);	}      else			/* parent */	{	  if (debug)	    printf ("  in parent. childpid:%i\n", childpid);	  close (copypipe[1]);	  if ((mcopyout = fdopen (copypipe[0], "r")) == NULL)	    {	      printf ("  Error while opening pipe for reading\n");	      gtk_main_quit ();	    }	  lex_result = er_interface (mcopyout);	  while (1)	    {	      if (waitpid (childpid, &status, WNOHANG) == childpid)		{		  waitpid (childpid, &status, WUNTRACED);		  break;		}	    }	}      if (lex_result != 2)	copiedbytes +=	  ((dentry *)	   gtk_clist_get_row_data (GTK_CLIST (from->list),				   (int) (items->data)))->size;      if (from->totsize)	gtk_progress_bar_update (GTK_PROGRESS_BAR (progressbar),				 (float) copiedbytes / (from->totsize));      switch (lex_result)	{	case 1:	  items = NULL;	case 2:	  break;	default:	  items = items->next;	  break;	}    }  gtk_grab_remove (progressdialog);  gtk_widget_destroy (progressdialog);  if (debug)    printf ("  freeing memory...\n");  free (frompath);  free (topath);  if (debug)    printf ("  calling refresh_event\n");  refresh_event (to->list, to);  if (debug)    printf ("End copy_event()\n");}voidconfig_event (GtkWidget * widget, side * leftside){  GtkWidget *dialog, *button, *entrydrive, *entrympath, *box;  GtkWidget *label;  msgenv msg[2];  int flag = 0;  int i;  char *buttonlabels[] = { "OK", "Cancel" };  char newdrives[27];  char *pos;  if (debug)    printf ("In config_event()\n");  dialog = gtk_dialog_new ();  gtk_window_set_title (GTK_WINDOW (dialog), "Configure MToolsFM");#ifndef OLDGTK  gtk_container_set_border_width (GTK_CONTAINER (dialog), 10);#endif  /* Display help */  box = gtk_hbox_new (FALSE, 0);  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), box, TRUE, TRUE,		      5);  gtk_widget_show (box);  label = gtk_label_new (CONFDRIVES);  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);  gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);  gtk_widget_show (label);  /* Create textfield for driveletters */  box = gtk_hbox_new (FALSE, 0);  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), box, TRUE, TRUE,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -