summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c52
1 files changed, 48 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 98d1263..19b0544 100644
--- a/src/main.c
+++ b/src/main.c
@@ -25,6 +25,7 @@
#include <getopt.h>
#include <locale.h>
#include <stdlib.h>
+#include <unistd.h>
#include <gtk/gtk.h>
#include <config.h>
@@ -81,7 +82,7 @@ static void show_chrysalide_help(const char *name)
printf("\n");
printf("Usage: %s [--help] [--version]\n", base);
- printf(" %s [--batch] <filename(s)...>\n", base);
+ printf(" %s [args] <filename(s)...>\n", base);
printf("\n");
@@ -92,6 +93,7 @@ static void show_chrysalide_help(const char *name)
printf("\t--verbosity=level\tSet the log level (0 for all messages, %u for none).\n", LMT_COUNT);
printf("\t--batch\t\t\tExit after processing files.\n");
+ printf("\t--project=filename\tOpen an existing project or create a new one.\n");
printf("\n");
@@ -149,6 +151,7 @@ int main(int argc, char **argv)
bool show_version; /* Affichage de la version ? */
LogMessageType verbosity; /* Niveau de filtre de message */
bool batch_mode; /* Exécution sans GUI ? */
+ char *prj_filename; /* Chemin vers un projet */
int index; /* Indice d'argument */
int ret; /* Bilan d'un appel */
GtkWidget *editor; /* Fenêtre graphique */
@@ -161,12 +164,14 @@ int main(int argc, char **argv)
char *pub; /* Chemin de la clef publique */
bool welcome; /* Affichage de la bienvenue ? */
+ GStudyProject *project; /* Nouveau projet courant */
static struct option long_options[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'v' },
{ "verbosity", required_argument, NULL, 'V' },
{ "batch", no_argument, NULL, 'b' },
+ { "project", required_argument, NULL, 'p' },
{ NULL, 0, NULL, 0 }
};
@@ -186,10 +191,11 @@ int main(int argc, char **argv)
verbosity = LMT_INFO;
batch_mode = false;
+ prj_filename = NULL;
while (true)
{
- ret = getopt_long(argc, argv, "hvV:b", long_options, &index);
+ ret = getopt_long(argc, argv, "hvV:bp:", long_options, &index);
if (ret == -1) break;
switch (ret)
@@ -210,6 +216,10 @@ int main(int argc, char **argv)
batch_mode = true;
break;
+ case 'p':
+ prj_filename = optarg;
+ break;
+
}
}
@@ -287,11 +297,43 @@ int main(int argc, char **argv)
else
g_generic_config_get_value(config, MPK_WELCOME_STARTUP, &welcome);
- if (!welcome)
+ if (!welcome && prj_filename == NULL)
g_idle_add((GSourceFunc)load_last_project, config);
else
- set_current_project(g_study_project_new());
+ {
+ if (prj_filename == NULL)
+ project = g_study_project_new();
+
+ else
+ {
+ ret = access(prj_filename, R_OK);
+
+ if (ret == 0)
+ {
+ project = g_study_project_open(prj_filename);
+ if (project == NULL) goto bad_project;
+ }
+
+ else
+ {
+ project = g_study_project_new();
+
+ status = g_study_project_save(project, prj_filename);
+
+ if (!status)
+ {
+ g_object_unref(G_OBJECT(project));
+ goto bad_project;
+ }
+
+ }
+
+ }
+
+ set_current_project(project);
+
+ }
/* Exécution du programme */
@@ -303,6 +345,8 @@ int main(int argc, char **argv)
else
gtk_main();
+ bad_project:
+
g_db_server_stop(server);
g_object_unref(G_OBJECT(server));