Code cleanup
This commit is contained in:
parent
844f58e5ef
commit
7a43affb07
17
src/main.c
17
src/main.c
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
@ -57,7 +58,7 @@
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int _terminal(char const * shell, char const * directory);
|
static int _terminal(TerminalPrefs * prefs);
|
||||||
|
|
||||||
static int _error(char const * message, int ret);
|
static int _error(char const * message, int ret);
|
||||||
static int _usage(void);
|
static int _usage(void);
|
||||||
|
@ -65,11 +66,11 @@ static int _usage(void);
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
/* terminal */
|
/* terminal */
|
||||||
static int _terminal(char const * shell, char const * directory)
|
static int _terminal(TerminalPrefs * prefs)
|
||||||
{
|
{
|
||||||
Terminal * terminal;
|
Terminal * terminal;
|
||||||
|
|
||||||
if((terminal = terminal_new(shell, directory)) == NULL)
|
if((terminal = terminal_new(prefs)) == NULL)
|
||||||
return error_print(PACKAGE);
|
return error_print(PACKAGE);
|
||||||
gtk_main();
|
gtk_main();
|
||||||
terminal_delete(terminal);
|
terminal_delete(terminal);
|
||||||
|
@ -100,26 +101,26 @@ static int _usage(void)
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
int o;
|
int o;
|
||||||
char const * shell = NULL;
|
TerminalPrefs prefs;
|
||||||
char const * directory = NULL;
|
|
||||||
|
|
||||||
if(setlocale(LC_ALL, "") == NULL)
|
if(setlocale(LC_ALL, "") == NULL)
|
||||||
_error("setlocale", 1);
|
_error("setlocale", 1);
|
||||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
textdomain(PACKAGE);
|
textdomain(PACKAGE);
|
||||||
|
memset(&prefs, 0, sizeof(prefs));
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
while((o = getopt(argc, argv, "d:")) != -1)
|
while((o = getopt(argc, argv, "d:")) != -1)
|
||||||
switch(o)
|
switch(o)
|
||||||
{
|
{
|
||||||
case 'd':
|
case 'd':
|
||||||
directory = optarg;
|
prefs.directory = optarg;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return _usage();
|
return _usage();
|
||||||
}
|
}
|
||||||
if(argc - optind == 1)
|
if(argc - optind == 1)
|
||||||
shell = argv[optind];
|
prefs.shell = argv[optind];
|
||||||
else if(optind != argc)
|
else if(optind != argc)
|
||||||
return _usage();
|
return _usage();
|
||||||
return (_terminal(shell, directory) == 0) ? 0 : 2;
|
return (_terminal(&prefs) == 0) ? 0 : 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ static DesktopToolbar _terminal_toolbar[] =
|
||||||
/* public */
|
/* public */
|
||||||
/* functions */
|
/* functions */
|
||||||
/* terminal_new */
|
/* terminal_new */
|
||||||
Terminal * terminal_new(char const * shell, char const * directory)
|
Terminal * terminal_new(TerminalPrefs * prefs)
|
||||||
{
|
{
|
||||||
Terminal * terminal;
|
Terminal * terminal;
|
||||||
GtkAccelGroup * group;
|
GtkAccelGroup * group;
|
||||||
|
@ -186,15 +186,17 @@ Terminal * terminal_new(char const * shell, char const * directory)
|
||||||
|
|
||||||
if((terminal = object_new(sizeof(*terminal))) == NULL)
|
if((terminal = object_new(sizeof(*terminal))) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
terminal->shell = (shell != NULL) ? string_new(shell) : NULL;
|
terminal->shell = (prefs != NULL && prefs->shell != NULL)
|
||||||
terminal->directory = (directory != NULL)
|
? string_new(prefs->shell) : NULL;
|
||||||
? string_new(directory) : NULL;
|
terminal->directory = (prefs != NULL && prefs->directory != NULL)
|
||||||
|
? string_new(prefs->directory) : NULL;
|
||||||
terminal->tabs = NULL;
|
terminal->tabs = NULL;
|
||||||
terminal->tabs_cnt = 0;
|
terminal->tabs_cnt = 0;
|
||||||
terminal->window = NULL;
|
terminal->window = NULL;
|
||||||
/* check for errors */
|
/* check for errors */
|
||||||
if((shell != NULL && terminal->shell == NULL)
|
if((prefs != NULL && prefs->shell != NULL && terminal->shell == NULL)
|
||||||
|| (directory != NULL && terminal->directory == NULL))
|
|| (prefs != NULL && prefs->directory != NULL
|
||||||
|
&& terminal->directory == NULL))
|
||||||
{
|
{
|
||||||
terminal_delete(terminal);
|
terminal_delete(terminal);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -37,12 +37,18 @@
|
||||||
/* Terminal */
|
/* Terminal */
|
||||||
/* public */
|
/* public */
|
||||||
/* types */
|
/* types */
|
||||||
|
typedef struct _TerminalPrefs
|
||||||
|
{
|
||||||
|
char const * shell;
|
||||||
|
char const * directory;
|
||||||
|
} TerminalPrefs;
|
||||||
|
|
||||||
typedef struct _Terminal Terminal;
|
typedef struct _Terminal Terminal;
|
||||||
|
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
/* essential */
|
/* essential */
|
||||||
Terminal * terminal_new(char const * shell, char const * directory);
|
Terminal * terminal_new(TerminalPrefs * prefs);
|
||||||
void terminal_delete(Terminal * terminal);
|
void terminal_delete(Terminal * terminal);
|
||||||
|
|
||||||
#endif /* !TERMINAL_TERMINAL_H */
|
#endif /* !TERMINAL_TERMINAL_H */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user