--status flag added
This commit is contained in:
parent
3d23af73c0
commit
bccd37ef96
@ -4,6 +4,10 @@
|
||||
again Chris for reporting it)
|
||||
|
||||
* src/io.c (io_unset_lock): function removed
|
||||
* src/io.c (io_get_pid): new function
|
||||
|
||||
* src/args.c (status_arg): new function
|
||||
* src/args.c: --status flag added
|
||||
|
||||
2009-07-23 Frederic Culot <frederic@culot.org>
|
||||
|
||||
|
53
src/args.c
53
src/args.c
@ -1,4 +1,4 @@
|
||||
/* $calcurse: args.c,v 1.57 2009/07/26 12:30:23 culot Exp $ */
|
||||
/* $calcurse: args.c,v 1.58 2009/07/26 20:26:14 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -40,6 +40,7 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
#include <getopt.h>
|
||||
#include <time.h>
|
||||
#include <regex.h>
|
||||
@ -165,6 +166,39 @@ help_arg ()
|
||||
fputs (htext, stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Used to display the status of running instances of calcurse.
|
||||
* The displayed message will look like one of the following ones:
|
||||
*
|
||||
* calcurse is running (pid #)
|
||||
* calcurse is running in background (pid #)
|
||||
* calcurse is not running
|
||||
*
|
||||
* The status is obtained by looking at pid files in user data directory
|
||||
* (.calcurse.pid and .daemon.pid).
|
||||
*/
|
||||
static void
|
||||
status_arg (void)
|
||||
{
|
||||
int cpid, dpid;
|
||||
|
||||
cpid = io_get_pid (path_cpid);
|
||||
dpid = io_get_pid (path_dpid);
|
||||
|
||||
EXIT_IF (cpid && dpid,
|
||||
_("Error: both calcurse (pid: %d) and its daemon (pid: %d)\n"
|
||||
"seem to be running at the same time!\n"
|
||||
"Please check manually and restart calcurse.\n"),
|
||||
cpid, dpid);
|
||||
|
||||
if (cpid)
|
||||
fprintf (stdout, _("calcurse is running (pid %d)\n"), cpid);
|
||||
else if (dpid)
|
||||
fprintf (stdout, _("calcurse is running in background (pid %d)\n"), dpid);
|
||||
else
|
||||
fprintf (stdout, _("calcurse is not running\n"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Display note contents if one is asociated with the currently displayed item
|
||||
* (to be used together with the '-a' or '-t' flag in non-interactive mode).
|
||||
@ -666,6 +700,13 @@ parse_args (int argc, char **argv, conf_t *conf)
|
||||
char *datadir = NULL, *ifile = NULL;
|
||||
regex_t reg, *preg = NULL;
|
||||
|
||||
/* Long options only */
|
||||
int statusflag = 0; /* --status: get the status of running instances */
|
||||
enum
|
||||
{
|
||||
STATUS_OPT = CHAR_MAX + 1
|
||||
};
|
||||
|
||||
static char *optstr = "hvnNax::t::d:c:r::s::S:D:i:";
|
||||
|
||||
struct option longopts[] = {
|
||||
@ -680,6 +721,7 @@ parse_args (int argc, char **argv, conf_t *conf)
|
||||
{"range", optional_argument, NULL, 'r'},
|
||||
{"startday", optional_argument, NULL, 's'},
|
||||
{"search", required_argument, NULL, 'S'},
|
||||
{"status", no_argument, NULL, STATUS_OPT},
|
||||
{"todo", optional_argument, NULL, 't'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"export", optional_argument, NULL, 'x'},
|
||||
@ -690,6 +732,9 @@ parse_args (int argc, char **argv, conf_t *conf)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case STATUS_OPT:
|
||||
statusflag = 1;
|
||||
break;
|
||||
case 'a':
|
||||
aflag = 1;
|
||||
multiple_flag++;
|
||||
@ -843,6 +888,12 @@ parse_args (int argc, char **argv, conf_t *conf)
|
||||
version_arg ();
|
||||
non_interactive = 1;
|
||||
}
|
||||
else if (statusflag)
|
||||
{
|
||||
io_init (cfile, datadir);
|
||||
status_arg ();
|
||||
non_interactive = 1;
|
||||
}
|
||||
else if (multiple_flag)
|
||||
{
|
||||
if (load_data)
|
||||
|
27
src/io.c
27
src/io.c
@ -1,4 +1,4 @@
|
||||
/* $calcurse: io.c,v 1.73 2009/07/26 12:47:15 culot Exp $ */
|
||||
/* $calcurse: io.c,v 1.74 2009/07/26 20:26:15 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -2976,3 +2976,28 @@ io_dump_pid (char *file)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the pid number contained in a file previously created with
|
||||
* io_dump_pid ().
|
||||
* If no file was found, return 0.
|
||||
*/
|
||||
unsigned
|
||||
io_get_pid (char *file)
|
||||
{
|
||||
FILE *fp;
|
||||
unsigned pid;
|
||||
|
||||
if (!file)
|
||||
return 0;
|
||||
|
||||
if ((fp = fopen (file, "r")) == 0)
|
||||
return 0;
|
||||
|
||||
if (fscanf (fp, "%u", &pid) != 1)
|
||||
return 0;
|
||||
|
||||
(void)fclose (fp);
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
3
src/io.h
3
src/io.h
@ -1,4 +1,4 @@
|
||||
/* $calcurse: io.h,v 1.24 2009/07/26 12:47:16 culot Exp $ */
|
||||
/* $calcurse: io.h,v 1.25 2009/07/26 20:26:15 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -88,5 +88,6 @@ void io_start_psave_thread (conf_t *);
|
||||
void io_stop_psave_thread (void);
|
||||
void io_set_lock (void);
|
||||
unsigned io_dump_pid (char *);
|
||||
unsigned io_get_pid (char *);
|
||||
|
||||
#endif /* !CALCURSE_IO_H */
|
||||
|
13
src/utils.c
13
src/utils.c
@ -1,4 +1,4 @@
|
||||
/* $calcurse: utils.c,v 1.79 2009/07/26 12:47:16 culot Exp $ */
|
||||
/* $calcurse: utils.c,v 1.80 2009/07/26 20:26:16 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -64,7 +64,7 @@
|
||||
void
|
||||
exit_calcurse (int status)
|
||||
{
|
||||
int remove_lock;
|
||||
int was_interactive;
|
||||
|
||||
if (ui_mode == UI_CURSES)
|
||||
{
|
||||
@ -73,10 +73,10 @@ exit_calcurse (int status)
|
||||
refresh ();
|
||||
endwin ();
|
||||
ui_mode = UI_CMDLINE;
|
||||
remove_lock = 1;
|
||||
was_interactive = 1;
|
||||
}
|
||||
else
|
||||
remove_lock = 0;
|
||||
was_interactive = 0;
|
||||
|
||||
calendar_stop_date_thread ();
|
||||
io_stop_psave_thread ();
|
||||
@ -93,15 +93,14 @@ exit_calcurse (int status)
|
||||
notify_free_app ();
|
||||
keys_free ();
|
||||
mem_stats ();
|
||||
if (remove_lock)
|
||||
if (was_interactive)
|
||||
{
|
||||
if (unlink (path_cpid) != 0)
|
||||
EXIT (_("Could not remove calcurse lock file: %s\n"),
|
||||
strerror (errno));
|
||||
dmon_start (status);
|
||||
}
|
||||
|
||||
dmon_start (status);
|
||||
|
||||
exit (status);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user