File: main.c

package info (click to toggle)
gedit 0.5.4-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,388 kB
  • ctags: 1,622
  • sloc: ansic: 10,760; sh: 4,975; makefile: 463; sed: 93
file content (98 lines) | stat: -rw-r--r-- 2,513 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 3 -*-
 *
 * Shell plugin for gEdit
 * Copyright (C) 1998 Martin Baulig
 *
 * This program 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 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <config.h>
#include <gE_plugin.h>

#include <pwd.h>
#include <zvt/zvtterm.h>

static void init_plugin(gE_Plugin_Object *, gint);
static gboolean start_plugin(gE_Plugin_Object *, gint);

gint edit_context = 0;

gE_Plugin_Info gedit_plugin_info =
{
   "Shell Plugin",
   init_plugin,
   start_plugin,
};

#define DEFAULT_FONT "-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-1"

void
init_plugin(gE_Plugin_Object * plugin, gint context)
{
   start_plugin(plugin, context);
}

void
child_died_cb(ZvtTerm * zterm, int docid)
{
   g_message("Terminal %p child %d exited.\n", zterm, docid);

   gE_plugin_document_close(docid);
}

gboolean
start_plugin(gE_Plugin_Object * plugin, gint context)
{
   struct passwd *pw;
   GtkWidget *container,
   *zterm;
   gint docid;

   docid = gE_plugin_create_widget(context, _("Shell"), &container, NULL);

   g_message("Plugin context %d, widget %p, docid %d.\n",
	     context, container, docid);

   zterm = zvt_term_new();
   gtk_widget_ensure_style(zterm);

   zvt_term_set_scrollback(ZVT_TERM(zterm), 5000);
   zvt_term_set_font_name(ZVT_TERM(zterm), DEFAULT_FONT);

   gtk_signal_connect(GTK_OBJECT(zterm), "child_died",
		      child_died_cb, (gpointer) docid);

   switch (zvt_term_forkpty(ZVT_TERM(zterm),1)) {
     case -1:
	perror("ERROR: unable to fork:");
	exit(1);
	break;
     case 0:
	pw = getpwuid(getpid());
	if (pw) {
	   execl(pw->pw_shell, rindex(pw->pw_shell, '/'), 0);
	} else {
	   execl("/bin/bash", "bash", 0);
	}
	perror("ERROR: Cannot exec command:");
	exit(1);
     default:
   }

   gtk_container_add(GTK_CONTAINER(container), zterm);
   gtk_widget_show_all(container);

   return TRUE;
}