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