comparison src/editors.c @ 443:e7361d06d83a

editor_command_one(): tidy up.
author zas_
date Sun, 20 Apr 2008 13:30:36 +0000
parents 4b2d7f9af171
children 452b7ffeb7ad
comparison
equal deleted inserted replaced
442:4b2d7f9af171 443:e7361d06d83a
543 543
544 544
545 static gint editor_command_one(const gchar *template, GList *list, EditorData *ed) 545 static gint editor_command_one(const gchar *template, GList *list, EditorData *ed)
546 { 546 {
547 gchar *command; 547 gchar *command;
548 gchar *working_directory;
549 FileData *fd = list->data; 548 FileData *fd = list->data;
550 gchar *args[4];
551 GPid pid; 549 GPid pid;
552 gint standard_output; 550 gint standard_output;
553 gint standard_error; 551 gint standard_error;
554 gboolean ok; 552 gboolean ok;
555 553
556
557 ed->pid = -1; 554 ed->pid = -1;
558
559 working_directory = remove_level_from_path(fd->path);
560
561 ed->flags = editor_command_parse(template, list, &command); 555 ed->flags = editor_command_parse(template, list, &command);
562 556
563 ok = !(ed->flags & EDITOR_ERROR_MASK); 557 ok = !(ed->flags & EDITOR_ERROR_MASK);
564 558
565
566 args[0] = COMMAND_SHELL;
567 args[1] = COMMAND_OPT;
568 args[2] = command;
569 args[3] = NULL;
570
571 if (ok) 559 if (ok)
572 { 560 {
561 gchar *working_directory;
562 gchar *args[4];
563
564 working_directory = remove_level_from_path(fd->path);
565 args[0] = COMMAND_SHELL;
566 args[1] = COMMAND_OPT;
567 args[2] = command;
568 args[3] = NULL;
569
573 ok = g_spawn_async_with_pipes(working_directory, args, NULL, 570 ok = g_spawn_async_with_pipes(working_directory, args, NULL,
574 G_SPAWN_DO_NOT_REAP_CHILD, /* GSpawnFlags */ 571 G_SPAWN_DO_NOT_REAP_CHILD, /* GSpawnFlags */
575 NULL, NULL, 572 NULL, NULL,
576 &pid, 573 &pid,
577 NULL, 574 NULL,
578 ed->vd ? &standard_output : NULL, 575 ed->vd ? &standard_output : NULL,
579 ed->vd ? &standard_error : NULL, 576 ed->vd ? &standard_error : NULL,
580 NULL); 577 NULL);
578
579 g_free(working_directory);
581 580
582 if (!ok) ed->flags |= EDITOR_ERROR_CANT_EXEC; 581 if (!ok) ed->flags |= EDITOR_ERROR_CANT_EXEC;
583 } 582 }
584 583
585 if (ok) 584 if (ok)
586 { 585 {
587 g_child_watch_add(pid, editor_child_exit_cb, ed); 586 g_child_watch_add(pid, editor_child_exit_cb, ed);
588 ed->pid = pid; 587 ed->pid = pid;
589 } 588 }
590
591 589
592 if (ed->vd) 590 if (ed->vd)
593 { 591 {
594 592
595 if (!ok) 593 if (!ok)
620 editor_verbose_io_cb, ed, NULL); 618 editor_verbose_io_cb, ed, NULL);
621 g_io_channel_unref(channel_error); 619 g_io_channel_unref(channel_error);
622 } 620 }
623 } 621 }
624 622
625
626
627 g_free(command); 623 g_free(command);
628 g_free(working_directory);
629 624
630 return ed->flags & EDITOR_ERROR_MASK; 625 return ed->flags & EDITOR_ERROR_MASK;
631 } 626 }
632 627
633 static gint editor_command_next_start(EditorData *ed) 628 static gint editor_command_next_start(EditorData *ed)
743 738
744 void editor_resume(gpointer ed) 739 void editor_resume(gpointer ed)
745 { 740 {
746 editor_command_next_start(ed); 741 editor_command_next_start(ed);
747 } 742 }
743
748 void editor_skip(gpointer ed) 744 void editor_skip(gpointer ed)
749 { 745 {
750 editor_command_done(ed); 746 editor_command_done(ed);
751 } 747 }
752 748
768 ed->data = data; 764 ed->data = data;
769 765
770 if ((flags & EDITOR_VERBOSE_MULTI) && list && list->next) 766 if ((flags & EDITOR_VERBOSE_MULTI) && list && list->next)
771 flags |= EDITOR_VERBOSE; 767 flags |= EDITOR_VERBOSE;
772 768
773
774 if (flags & EDITOR_VERBOSE) 769 if (flags & EDITOR_VERBOSE)
775 editor_verbose_window(ed, text); 770 editor_verbose_window(ed, text);
776 771
777 editor_command_next_start(ed); 772 editor_command_next_start(ed);
778 /* errors from editor_command_next_start will be handled via callback */ 773 /* errors from editor_command_next_start will be handled via callback */