2005-11-23 03:10:03 -08:00
|
|
|
/* This file has been generated with opag 0.8.0. */
|
2005-10-13 07:08:18 -07:00
|
|
|
/*
|
2005-11-23 03:10:03 -08:00
|
|
|
* medit-app.c
|
2005-10-13 07:08:18 -07:00
|
|
|
*
|
2006-02-23 06:03:17 -08:00
|
|
|
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
2005-10-13 07:08:18 -07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "medit-ui.h"
|
2006-08-01 02:57:26 -07:00
|
|
|
#include "THANKS.h"
|
2006-08-01 04:36:16 -07:00
|
|
|
#include <moo.h>
|
2005-10-15 22:07:02 -07:00
|
|
|
#include <gtk/gtk.h>
|
2005-11-23 03:10:03 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-11-30 08:46:02 -08:00
|
|
|
#include <stdio.h>
|
2005-11-23 03:10:03 -08:00
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
#if GTK_CHECK_VERSION(2,8,0) && defined(GDK_WINDOWING_X11)
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#define TIMESTAMP (gdk_x11_display_get_user_time (gdk_display_get_default ()))
|
|
|
|
#else
|
|
|
|
#define TIMESTAMP (0)
|
|
|
|
#endif
|
|
|
|
|
2005-11-23 03:10:03 -08:00
|
|
|
|
2006-10-17 22:24:35 -07:00
|
|
|
#if 1
|
|
|
|
static void
|
|
|
|
init_mem_stuff (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define ALIGN 4
|
|
|
|
#include <libxml/xmlmemory.h>
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
my_malloc (gsize n_bytes)
|
|
|
|
{
|
|
|
|
char *mem = malloc (n_bytes + ALIGN);
|
|
|
|
return mem ? mem + ALIGN : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
my_realloc (gpointer mem,
|
|
|
|
gsize n_bytes)
|
|
|
|
{
|
|
|
|
if (mem)
|
|
|
|
{
|
|
|
|
char *new_mem = realloc ((char*) mem - ALIGN, n_bytes + ALIGN);
|
|
|
|
return new_mem ? new_mem + ALIGN : NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return my_malloc (n_bytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
my_strdup (const char *s)
|
|
|
|
{
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
char *new_s = my_malloc (strlen (s) + 1);
|
|
|
|
strcpy (new_s, s);
|
|
|
|
return new_s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
my_free (gpointer mem)
|
|
|
|
{
|
|
|
|
if (mem)
|
|
|
|
free ((char*) mem - ALIGN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_mem_stuff (void)
|
|
|
|
{
|
|
|
|
GMemVTable mem_table = {
|
|
|
|
my_malloc,
|
|
|
|
my_realloc,
|
|
|
|
my_free,
|
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
g_mem_set_vtable (&mem_table);
|
|
|
|
g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlMemSetup (my_free, my_malloc, my_realloc, my_strdup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
typedef enum {
|
|
|
|
MODE_SIMPLE,
|
|
|
|
MODE_PROJECT
|
|
|
|
} AppMode;
|
2006-06-03 00:26:18 -07:00
|
|
|
|
|
|
|
|
2005-11-23 03:10:03 -08:00
|
|
|
int _medit_parse_options (const char *const program_name,
|
|
|
|
const int argc,
|
|
|
|
char **const argv);
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* command line parsing code generated by Opag
|
|
|
|
* http://www.zero-based.org/software/opag/
|
|
|
|
*/
|
|
|
|
#ifndef STR_ERR_UNKNOWN_LONG_OPT
|
|
|
|
# define STR_ERR_UNKNOWN_LONG_OPT "%s: unrecognized option `--%s'\n"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef STR_ERR_LONG_OPT_AMBIGUOUS
|
|
|
|
# define STR_ERR_LONG_OPT_AMBIGUOUS "%s: option `--%s' is ambiguous\n"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef STR_ERR_MISSING_ARG_LONG
|
|
|
|
# define STR_ERR_MISSING_ARG_LONG "%s: option `--%s' requires an argument\n"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef STR_ERR_UNEXPEC_ARG_LONG
|
|
|
|
# define STR_ERR_UNEXPEC_ARG_LONG "%s: option `--%s' doesn't allow an argument\n"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef STR_ERR_UNKNOWN_SHORT_OPT
|
|
|
|
# define STR_ERR_UNKNOWN_SHORT_OPT "%s: unrecognized option `-%c'\n"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef STR_ERR_MISSING_ARG_SHORT
|
|
|
|
# define STR_ERR_MISSING_ARG_SHORT "%s: option `-%c' requires an argument\n"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STR_HELP_NEW_APP "\
|
2006-07-05 12:19:46 -07:00
|
|
|
-n, --new-app Run new instance of application\n"
|
|
|
|
|
2006-08-18 00:24:18 -07:00
|
|
|
#define STR_HELP_PID "\
|
|
|
|
--pid=PID Use existing instance with process id PID\n"
|
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
#define STR_HELP_MODE "\
|
|
|
|
-m, --mode=[simple|project] Use specified mode\n"
|
2005-11-23 03:10:03 -08:00
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
#define STR_HELP_PROJECT "\
|
|
|
|
-p, --project=PROJECT Open project file PROJECT\n"
|
|
|
|
|
|
|
|
#define STR_HELP_LINE "\
|
|
|
|
-l, --line=LINE Open file and position cursor on line LINE\n"
|
2006-06-25 02:24:26 -07:00
|
|
|
|
2005-11-23 03:10:03 -08:00
|
|
|
#define STR_HELP_LOG "\
|
2006-07-05 12:19:46 -07:00
|
|
|
--log[=FILE] Show debug output or write it to FILE\n"
|
2005-11-23 03:10:03 -08:00
|
|
|
|
|
|
|
#define STR_HELP_VERSION "\
|
2006-07-05 12:19:46 -07:00
|
|
|
--version Display version information and exit\n"
|
2005-11-23 03:10:03 -08:00
|
|
|
|
|
|
|
#define STR_HELP_HELP "\
|
2006-07-05 12:19:46 -07:00
|
|
|
-h, --help Display this help text and exit\n"
|
2005-11-23 03:10:03 -08:00
|
|
|
|
|
|
|
#define STR_HELP "\
|
2006-07-05 12:19:46 -07:00
|
|
|
-n, --new-app Run new instance of application\n\
|
2006-08-18 00:24:18 -07:00
|
|
|
--pid=PID Use existing instance with process id PID\n\
|
2006-07-05 12:19:46 -07:00
|
|
|
-m, --mode=[simple|project] Use specified mode\n\
|
|
|
|
-p, --project=PROJECT Open project file PROJECT\n\
|
|
|
|
-l, --line=LINE Open file and position cursor on line LINE\n\
|
|
|
|
--log[=FILE] Show debug output or write it to FILE\n\
|
|
|
|
--version Display version information and exit\n\
|
|
|
|
-h, --help Display this help text and exit\n"
|
2006-06-03 00:26:18 -07:00
|
|
|
|
2005-11-23 03:10:03 -08:00
|
|
|
/* Set to 1 if option --new-app (-n) has been specified. */
|
|
|
|
char _medit_opt_new_app;
|
|
|
|
|
2006-08-18 00:24:18 -07:00
|
|
|
/* Set to 1 if option --pid has been specified. */
|
|
|
|
char _medit_opt_pid;
|
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
/* Set to 1 if option --mode (-m) has been specified. */
|
|
|
|
char _medit_opt_mode;
|
|
|
|
|
|
|
|
/* Set to 1 if option --project (-p) has been specified. */
|
|
|
|
char _medit_opt_project;
|
2006-06-25 02:24:26 -07:00
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
/* Set to 1 if option --line (-l) has been specified. */
|
|
|
|
char _medit_opt_line;
|
|
|
|
|
|
|
|
/* Set to 1 if option --log has been specified. */
|
2005-11-23 03:10:03 -08:00
|
|
|
char _medit_opt_log;
|
|
|
|
|
|
|
|
/* Set to 1 if option --version has been specified. */
|
|
|
|
char _medit_opt_version;
|
|
|
|
|
|
|
|
/* Set to 1 if option --help (-h) has been specified. */
|
|
|
|
char _medit_opt_help;
|
|
|
|
|
2006-08-18 00:24:18 -07:00
|
|
|
/* Argument to option --pid. */
|
|
|
|
const char *_medit_arg_pid;
|
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
/* Argument to option --mode (-m). */
|
|
|
|
const char *_medit_arg_mode;
|
|
|
|
|
2006-08-18 00:24:18 -07:00
|
|
|
/* Argument to option --project (-p). */
|
2006-07-05 12:19:46 -07:00
|
|
|
const char *_medit_arg_project;
|
|
|
|
|
2006-07-05 12:32:28 -07:00
|
|
|
/* Argument to option --line (-l). */
|
2006-07-05 12:19:46 -07:00
|
|
|
const char *_medit_arg_line;
|
|
|
|
|
|
|
|
/* Argument to option --log, or a null pointer if no argument. */
|
2005-11-23 03:10:03 -08:00
|
|
|
const char *_medit_arg_log;
|
|
|
|
|
|
|
|
/* Parse command line options. Return index of first non-option argument,
|
|
|
|
or -1 if an error is encountered. */
|
|
|
|
int _medit_parse_options (const char *const program_name, const int argc, char **const argv)
|
|
|
|
{
|
|
|
|
static const char *const optstr__new_app = "new-app";
|
2006-08-18 00:24:18 -07:00
|
|
|
static const char *const optstr__pid = "pid";
|
2006-07-05 12:19:46 -07:00
|
|
|
static const char *const optstr__mode = "mode";
|
2006-08-18 00:24:18 -07:00
|
|
|
static const char *const optstr__project = "project";
|
2006-07-05 12:32:28 -07:00
|
|
|
static const char *const optstr__line = "line";
|
2005-11-23 03:10:03 -08:00
|
|
|
static const char *const optstr__version = "version";
|
|
|
|
static const char *const optstr__help = "help";
|
|
|
|
int i = 0;
|
|
|
|
_medit_opt_new_app = 0;
|
2006-08-18 00:24:18 -07:00
|
|
|
_medit_opt_pid = 0;
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_opt_mode = 0;
|
|
|
|
_medit_opt_project = 0;
|
|
|
|
_medit_opt_line = 0;
|
2005-11-23 03:10:03 -08:00
|
|
|
_medit_opt_log = 0;
|
|
|
|
_medit_opt_version = 0;
|
|
|
|
_medit_opt_help = 0;
|
2006-08-18 00:24:18 -07:00
|
|
|
_medit_arg_pid = 0;
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_arg_mode = 0;
|
|
|
|
_medit_arg_project = 0;
|
|
|
|
_medit_arg_line = 0;
|
2005-11-23 03:10:03 -08:00
|
|
|
_medit_arg_log = 0;
|
|
|
|
while (++i < argc)
|
|
|
|
{
|
|
|
|
const char *option = argv [i];
|
|
|
|
if (*option != '-')
|
|
|
|
return i;
|
|
|
|
else if (*++option == '\0')
|
|
|
|
return i;
|
|
|
|
else if (*option == '-')
|
|
|
|
{
|
|
|
|
const char *argument;
|
|
|
|
size_t option_len;
|
|
|
|
++option;
|
|
|
|
if ((argument = strchr (option, '=')) == option)
|
|
|
|
goto error_unknown_long_opt;
|
|
|
|
else if (argument == 0)
|
|
|
|
option_len = strlen (option);
|
|
|
|
else
|
|
|
|
option_len = argument++ - option;
|
|
|
|
switch (*option)
|
|
|
|
{
|
|
|
|
case '\0':
|
|
|
|
return i + 1;
|
|
|
|
case 'h':
|
|
|
|
if (strncmp (option + 1, optstr__help + 1, option_len - 1) == 0)
|
|
|
|
{
|
|
|
|
if (argument != 0)
|
|
|
|
{
|
|
|
|
option = optstr__help;
|
|
|
|
goto error_unexpec_arg_long;
|
|
|
|
}
|
|
|
|
_medit_opt_help = 1;
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
goto error_unknown_long_opt;
|
|
|
|
case 'l':
|
2006-07-05 12:32:28 -07:00
|
|
|
if (strncmp (option + 1, optstr__line + 1, option_len - 1) == 0)
|
2006-07-05 12:19:46 -07:00
|
|
|
{
|
|
|
|
if (option_len <= 1)
|
|
|
|
goto error_long_opt_ambiguous;
|
2006-07-05 12:32:28 -07:00
|
|
|
if (argument != 0)
|
|
|
|
_medit_arg_line = argument;
|
|
|
|
else if (++i < argc)
|
|
|
|
_medit_arg_line = argv [i];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
option = optstr__line;
|
|
|
|
goto error_missing_arg_long;
|
|
|
|
}
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_opt_line = 1;
|
|
|
|
break;
|
|
|
|
}
|
2005-11-23 03:10:03 -08:00
|
|
|
if (strncmp (option + 1, "og", option_len - 1) == 0)
|
|
|
|
{
|
2006-07-05 12:19:46 -07:00
|
|
|
if (option_len <= 1)
|
|
|
|
goto error_long_opt_ambiguous;
|
2005-11-23 03:10:03 -08:00
|
|
|
_medit_arg_log = argument;
|
|
|
|
_medit_opt_log = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto error_unknown_long_opt;
|
2006-07-05 12:19:46 -07:00
|
|
|
case 'm':
|
|
|
|
if (strncmp (option + 1, optstr__mode + 1, option_len - 1) == 0)
|
2005-11-23 03:10:03 -08:00
|
|
|
{
|
|
|
|
if (argument != 0)
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_arg_mode = argument;
|
|
|
|
else if (++i < argc)
|
|
|
|
_medit_arg_mode = argv [i];
|
|
|
|
else
|
2005-11-23 03:10:03 -08:00
|
|
|
{
|
2006-07-05 12:19:46 -07:00
|
|
|
option = optstr__mode;
|
|
|
|
goto error_missing_arg_long;
|
2005-11-23 03:10:03 -08:00
|
|
|
}
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_opt_mode = 1;
|
2005-11-23 03:10:03 -08:00
|
|
|
break;
|
|
|
|
}
|
2006-06-03 00:26:18 -07:00
|
|
|
goto error_unknown_long_opt;
|
2006-07-05 12:19:46 -07:00
|
|
|
case 'n':
|
|
|
|
if (strncmp (option + 1, optstr__new_app + 1, option_len - 1) == 0)
|
2006-06-25 02:24:26 -07:00
|
|
|
{
|
|
|
|
if (argument != 0)
|
|
|
|
{
|
2006-07-05 12:19:46 -07:00
|
|
|
option = optstr__new_app;
|
2006-06-25 02:24:26 -07:00
|
|
|
goto error_unexpec_arg_long;
|
|
|
|
}
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_opt_new_app = 1;
|
2006-06-25 02:24:26 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto error_unknown_long_opt;
|
2006-07-05 12:19:46 -07:00
|
|
|
case 'p':
|
2006-08-18 00:24:18 -07:00
|
|
|
if (strncmp (option + 1, optstr__pid + 1, option_len - 1) == 0)
|
|
|
|
{
|
|
|
|
if (option_len <= 1)
|
|
|
|
goto error_long_opt_ambiguous;
|
|
|
|
if (argument != 0)
|
|
|
|
_medit_arg_pid = argument;
|
|
|
|
else if (++i < argc)
|
|
|
|
_medit_arg_pid = argv [i];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
option = optstr__pid;
|
|
|
|
goto error_missing_arg_long;
|
|
|
|
}
|
|
|
|
_medit_opt_pid = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strncmp (option + 1, optstr__project + 1, option_len - 1) == 0)
|
2006-06-03 00:26:18 -07:00
|
|
|
{
|
2006-08-18 00:24:18 -07:00
|
|
|
if (option_len <= 1)
|
|
|
|
goto error_long_opt_ambiguous;
|
|
|
|
if (argument != 0)
|
|
|
|
_medit_arg_project = argument;
|
|
|
|
else if (++i < argc)
|
|
|
|
_medit_arg_project = argv [i];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
option = optstr__project;
|
|
|
|
goto error_missing_arg_long;
|
|
|
|
}
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_opt_project = 1;
|
2006-06-03 00:26:18 -07:00
|
|
|
break;
|
|
|
|
}
|
2005-11-23 03:10:03 -08:00
|
|
|
goto error_unknown_long_opt;
|
|
|
|
case 'v':
|
|
|
|
if (strncmp (option + 1, optstr__version + 1, option_len - 1) == 0)
|
|
|
|
{
|
|
|
|
if (argument != 0)
|
|
|
|
{
|
|
|
|
option = optstr__version;
|
|
|
|
goto error_unexpec_arg_long;
|
|
|
|
}
|
|
|
|
_medit_opt_version = 1;
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
error_unknown_long_opt:
|
|
|
|
fprintf (stderr, STR_ERR_UNKNOWN_LONG_OPT, program_name, option);
|
|
|
|
return -1;
|
2006-07-05 12:19:46 -07:00
|
|
|
error_long_opt_ambiguous:
|
|
|
|
fprintf (stderr, STR_ERR_LONG_OPT_AMBIGUOUS, program_name, option);
|
|
|
|
return -1;
|
|
|
|
error_missing_arg_long:
|
|
|
|
fprintf (stderr, STR_ERR_MISSING_ARG_LONG, program_name, option);
|
|
|
|
return -1;
|
2005-11-23 03:10:03 -08:00
|
|
|
error_unexpec_arg_long:
|
|
|
|
fprintf (stderr, STR_ERR_UNEXPEC_ARG_LONG, program_name, option);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
do
|
|
|
|
{
|
|
|
|
switch (*option)
|
|
|
|
{
|
|
|
|
case 'h':
|
|
|
|
_medit_opt_help = 1;
|
|
|
|
return i + 1;
|
|
|
|
case 'l':
|
|
|
|
if (option [1] != '\0')
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_arg_line = option + 1;
|
2006-07-05 12:32:28 -07:00
|
|
|
else if (++i < argc)
|
|
|
|
_medit_arg_line = argv [i];
|
2005-11-23 03:10:03 -08:00
|
|
|
else
|
2006-07-05 12:32:28 -07:00
|
|
|
goto error_missing_arg_short;
|
|
|
|
option = "\0";
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_opt_line = 1;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (option [1] != '\0')
|
|
|
|
_medit_arg_mode = option + 1;
|
|
|
|
else if (++i < argc)
|
|
|
|
_medit_arg_mode = argv [i];
|
|
|
|
else
|
|
|
|
goto error_missing_arg_short;
|
|
|
|
option = "\0";
|
|
|
|
_medit_opt_mode = 1;
|
2005-11-23 03:10:03 -08:00
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
_medit_opt_new_app = 1;
|
|
|
|
break;
|
2006-07-05 12:19:46 -07:00
|
|
|
case 'p':
|
|
|
|
if (option [1] != '\0')
|
|
|
|
_medit_arg_project = option + 1;
|
2006-08-18 00:24:18 -07:00
|
|
|
else if (++i < argc)
|
|
|
|
_medit_arg_project = argv [i];
|
2006-07-05 12:19:46 -07:00
|
|
|
else
|
2006-08-18 00:24:18 -07:00
|
|
|
goto error_missing_arg_short;
|
|
|
|
option = "\0";
|
2006-07-05 12:19:46 -07:00
|
|
|
_medit_opt_project = 1;
|
2006-06-03 00:26:18 -07:00
|
|
|
break;
|
2005-11-23 03:10:03 -08:00
|
|
|
default:
|
|
|
|
fprintf (stderr, STR_ERR_UNKNOWN_SHORT_OPT, program_name, *option);
|
|
|
|
return -1;
|
2006-07-05 12:19:46 -07:00
|
|
|
error_missing_arg_short:
|
|
|
|
fprintf (stderr, STR_ERR_MISSING_ARG_SHORT, program_name, *option);
|
|
|
|
return -1;
|
2005-11-23 03:10:03 -08:00
|
|
|
}
|
|
|
|
} while (*++option != '\0');
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
/* end of generated code
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
|
2006-06-03 00:26:18 -07:00
|
|
|
static void
|
|
|
|
usage (void)
|
2005-11-23 03:10:03 -08:00
|
|
|
{
|
|
|
|
g_print ("Usage: %s [OPTIONS] [FILES]\n", g_get_prgname ());
|
2006-07-05 12:19:46 -07:00
|
|
|
g_print ("Options:\n%s", STR_HELP);
|
2005-11-23 03:10:03 -08:00
|
|
|
}
|
|
|
|
|
2006-06-03 00:26:18 -07:00
|
|
|
static void
|
|
|
|
version (void)
|
2005-11-23 03:10:03 -08:00
|
|
|
{
|
|
|
|
g_print ("medit %s\n", MOO_VERSION);
|
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
static void
|
|
|
|
check_args (int opt_remain)
|
|
|
|
{
|
|
|
|
if (_medit_opt_help)
|
|
|
|
{
|
|
|
|
usage ();
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt_remain < 0)
|
|
|
|
{
|
|
|
|
usage ();
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2006-08-18 00:24:18 -07:00
|
|
|
if (_medit_opt_pid)
|
|
|
|
{
|
|
|
|
if (_medit_opt_mode)
|
|
|
|
{
|
|
|
|
g_print ("--mode can't be used together with --pid\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_medit_opt_project)
|
|
|
|
{
|
|
|
|
g_print ("--project can't be used together with --pid\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_medit_opt_new_app)
|
|
|
|
{
|
|
|
|
g_print ("--new-app can't be used together with --pid\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_medit_arg_pid || !_medit_arg_pid[0])
|
|
|
|
{
|
|
|
|
usage ();
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
if (_medit_opt_mode)
|
|
|
|
{
|
|
|
|
if (!_medit_arg_mode ||
|
|
|
|
(strcmp (_medit_arg_mode, "simple") &&
|
|
|
|
strcmp (_medit_arg_mode, "project")))
|
|
|
|
{
|
|
|
|
usage ();
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_medit_opt_project && _medit_arg_mode &&
|
|
|
|
strcmp (_medit_arg_mode, "project"))
|
|
|
|
{
|
|
|
|
usage ();
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_medit_opt_version)
|
|
|
|
{
|
|
|
|
version ();
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-03 00:37:54 -07:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
|
|
|
MooApp *app;
|
2005-11-23 03:10:03 -08:00
|
|
|
int opt_remain;
|
2005-10-13 07:08:18 -07:00
|
|
|
MooEditor *editor;
|
2006-03-16 12:01:15 -08:00
|
|
|
char **files;
|
2006-05-08 23:10:14 -07:00
|
|
|
gpointer window;
|
2006-05-20 00:12:34 -07:00
|
|
|
int retval;
|
2006-07-05 12:19:46 -07:00
|
|
|
gboolean new_instance = FALSE;
|
2006-06-25 02:24:26 -07:00
|
|
|
gboolean run_input = TRUE;
|
2006-07-05 12:19:46 -07:00
|
|
|
AppMode mode = MODE_SIMPLE;
|
|
|
|
guint32 stamp;
|
2006-09-26 12:48:32 -07:00
|
|
|
guint32 line = 0;
|
2006-08-22 21:25:08 -07:00
|
|
|
const char *pid_string = NULL;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-10-17 22:24:35 -07:00
|
|
|
init_mem_stuff ();
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
gtk_init (&argc, &argv);
|
2006-07-05 12:19:46 -07:00
|
|
|
stamp = TIMESTAMP;
|
|
|
|
|
2006-10-17 22:24:35 -07:00
|
|
|
#if 0
|
|
|
|
gdk_window_set_debug_updates (TRUE);
|
|
|
|
#endif
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2005-11-23 03:10:03 -08:00
|
|
|
opt_remain = _medit_parse_options (g_get_prgname (), argc, argv);
|
2006-07-05 12:19:46 -07:00
|
|
|
check_args (opt_remain);
|
2005-11-23 03:10:03 -08:00
|
|
|
|
|
|
|
if (_medit_opt_log)
|
|
|
|
{
|
|
|
|
if (_medit_arg_log)
|
|
|
|
moo_set_log_func_file (_medit_arg_log);
|
|
|
|
else
|
|
|
|
moo_set_log_func_window (TRUE);
|
|
|
|
}
|
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
if (_medit_opt_mode)
|
2006-06-25 02:24:26 -07:00
|
|
|
{
|
2006-07-05 12:19:46 -07:00
|
|
|
if (!strcmp (_medit_arg_mode, "simple"))
|
|
|
|
mode = MODE_SIMPLE;
|
|
|
|
else
|
|
|
|
mode = MODE_PROJECT;
|
2006-06-25 02:24:26 -07:00
|
|
|
}
|
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
if (_medit_opt_project)
|
|
|
|
mode = MODE_PROJECT;
|
|
|
|
|
|
|
|
if (_medit_opt_new_app || mode == MODE_PROJECT)
|
|
|
|
new_instance = TRUE;
|
|
|
|
|
2006-03-16 12:01:15 -08:00
|
|
|
files = moo_filenames_from_locale (argv + opt_remain);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
app = g_object_new (MOO_TYPE_APP,
|
|
|
|
"argv", argv,
|
2006-06-25 02:24:26 -07:00
|
|
|
"run-input", run_input,
|
2005-10-13 07:08:18 -07:00
|
|
|
"short-name", "medit",
|
|
|
|
"full-name", "medit",
|
|
|
|
"description", "medit is a text editor",
|
2006-05-25 21:45:01 -07:00
|
|
|
"website", "http://mooedit.sourceforge.net/",
|
|
|
|
"website-label", "http://mooedit.sourceforge.net/",
|
2006-03-12 22:46:33 -08:00
|
|
|
"default-ui", MEDIT_UI,
|
2006-04-28 14:07:52 -07:00
|
|
|
"logo", MOO_STOCK_MEDIT,
|
2006-08-01 02:57:26 -07:00
|
|
|
"credits", THANKS,
|
2005-10-13 07:08:18 -07:00
|
|
|
NULL);
|
|
|
|
|
2006-08-18 00:24:18 -07:00
|
|
|
if (_medit_arg_line)
|
|
|
|
line = strtol (_medit_arg_line, NULL, 10);
|
|
|
|
|
|
|
|
if (_medit_opt_pid)
|
2006-08-22 21:25:08 -07:00
|
|
|
pid_string = _medit_arg_pid;
|
|
|
|
else if (!_medit_opt_new_app)
|
|
|
|
pid_string = g_getenv ("MEDIT_PID");
|
|
|
|
|
|
|
|
if (pid_string)
|
2006-08-18 00:24:18 -07:00
|
|
|
{
|
2006-09-26 12:48:32 -07:00
|
|
|
if (moo_app_send_files (app, files, line, stamp, pid_string))
|
2006-08-18 00:24:18 -07:00
|
|
|
{
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-22 21:25:08 -07:00
|
|
|
g_print ("Could not send files to pid %s\n", pid_string);
|
2006-08-18 00:24:18 -07:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-26 12:48:32 -07:00
|
|
|
if ((!new_instance && moo_app_send_files (app, files, line, stamp, NULL)) ||
|
2006-06-03 00:26:18 -07:00
|
|
|
!moo_app_init (app))
|
2006-05-08 23:10:14 -07:00
|
|
|
{
|
2006-05-31 13:31:10 -07:00
|
|
|
gdk_notify_startup_complete ();
|
2006-06-03 00:26:18 -07:00
|
|
|
g_strfreev (files);
|
|
|
|
g_object_unref (app);
|
2005-11-23 03:10:03 -08:00
|
|
|
return 0;
|
2006-05-08 23:10:14 -07:00
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-07-05 12:19:46 -07:00
|
|
|
if (mode == MODE_PROJECT)
|
|
|
|
{
|
|
|
|
MooPlugin *plugin;
|
|
|
|
|
|
|
|
plugin = moo_plugin_lookup ("ProjectManager");
|
|
|
|
|
|
|
|
if (!plugin)
|
|
|
|
{
|
|
|
|
g_printerr ("Could not initialize project manager plugin\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2006-07-08 07:59:12 -07:00
|
|
|
if (_medit_arg_project && *_medit_arg_project)
|
2006-07-05 12:19:46 -07:00
|
|
|
{
|
|
|
|
char *project = moo_filename_from_locale (_medit_arg_project);
|
|
|
|
g_object_set (plugin, "project", _medit_arg_project, NULL);
|
|
|
|
g_free (project);
|
|
|
|
}
|
|
|
|
|
|
|
|
moo_plugin_set_enabled (plugin, TRUE);
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
editor = moo_app_get_editor (app);
|
2006-05-08 23:10:14 -07:00
|
|
|
window = moo_editor_new_window (editor);
|
2006-06-03 00:26:18 -07:00
|
|
|
|
|
|
|
if (files && *files)
|
|
|
|
{
|
|
|
|
char **p;
|
|
|
|
|
|
|
|
for (p = files; p && *p; ++p)
|
2006-07-05 12:32:28 -07:00
|
|
|
{
|
2006-09-26 12:48:32 -07:00
|
|
|
if (p == files && line > 0)
|
|
|
|
moo_editor_open_file_line (editor, *p, line - 1, window);
|
2006-07-05 12:32:28 -07:00
|
|
|
else
|
|
|
|
moo_editor_new_file (editor, window, NULL, *p, NULL);
|
|
|
|
}
|
2006-06-03 00:26:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (files);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-02-21 06:34:38 -08:00
|
|
|
g_signal_connect_swapped (editor, "all-windows-closed",
|
|
|
|
G_CALLBACK (moo_app_quit), app);
|
|
|
|
|
2006-05-20 00:12:34 -07:00
|
|
|
retval = moo_app_run (app);
|
|
|
|
|
|
|
|
g_object_unref (app);
|
|
|
|
return retval;
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
2006-06-12 23:13:19 -07:00
|
|
|
|
|
|
|
|
|
|
|
#if defined(__WIN32__) && !defined(__GNUC__)
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
int __stdcall
|
|
|
|
WinMain (HINSTANCE hInstance,
|
|
|
|
HINSTANCE hPrevInstance,
|
|
|
|
char *lpszCmdLine,
|
|
|
|
int nCmdShow)
|
|
|
|
{
|
|
|
|
return main (__argc, __argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|