sensors displayed directly in the top bar.\r
</p>\r
</li>\r
+<li>\r
+<p>\r
+improved status icon in hicolor theme to fit well with white\r
+ background. (LP: #1310323).\r
+</p>\r
+</li>\r
</ul></div>\r
</div>\r
</div>\r
<div id="footnotes"><hr /></div>\r
<div id="footer">\r
<div id="footer-text">\r
-Last updated 2014-04-19 11:17:37 CEST\r
+Last updated 2014-04-21 21:10:46 CEST\r
</div>\r
</div>\r
</body>\r
# We use $(mkdir_p).
# In automake <= 1.9.x, $(mkdir_p) is defined either as "mkdir -p --" or as
# "$(mkinstalldirs)" or as "$(install_sh) -d". For these automake versions,
-# ${SHELL} /home/jporsini/work.local/psensor/install-sh does not start with $(SHELL), so we add it.
+# ${SHELL} /home/jporsini/work/psensor/install-sh does not start with $(SHELL), so we add it.
# In automake >= 1.10, /bin/mkdir -p is derived from ${MKDIR_P}, which is defined
# either as "/path/to/mkdir -p" or ".../install-sh -c -d". For these automake
# versions, $(mkinstalldirs) and $(install_sh) are unused.
-mkinstalldirs = $(SHELL) ${SHELL} /home/jporsini/work.local/psensor/install-sh -d
-install_sh = $(SHELL) ${SHELL} /home/jporsini/work.local/psensor/install-sh
+mkinstalldirs = $(SHELL) ${SHELL} /home/jporsini/work/psensor/install-sh -d
+install_sh = $(SHELL) ${SHELL} /home/jporsini/work/psensor/install-sh
MKDIR_P = /bin/mkdir -p
mkdir_p = /bin/mkdir -p
src/lib/hdd_atasmart.c
src/lib/hdd_hddtemp.c
src/lib/lmsensor.c
-src/lib/log.c
+src/lib/plog.c
src/lib/nvidia.c
src/lib/psensor.c
src/lib/slog.c
#include <ctype.h>
#include "cfg.h"
-#include "log.h"
+#include <plog.h>
static const char *KEY_SENSORS = "/apps/psensor/sensors";
#include <gtk/gtk.h>
#include "cfg.h"
-#include "log.h"
+#include <plog.h>
#include "psensor.h"
/* horizontal padding */
cpu.h \
hdd.h hdd_hddtemp.c\
lmsensor.h lmsensor.c \
- log.h log.c \
+ plog.h plog.c \
measure.h measure.c \
ptime.h ptime.c \
nvidia.h \
EXTRA_DIST=$(libpsensor_a_SOURCES) \
amd.c \
cpu.c \
- nvidia.c
\ No newline at end of file
+ nvidia.c
libpsensor_a_AR = $(AR) $(ARFLAGS)
libpsensor_a_LIBADD =
am__libpsensor_a_SOURCES_DIST = amd.h bool.h color.h color.c cpu.h \
- hdd.h hdd_hddtemp.c lmsensor.h lmsensor.c log.h log.c \
+ hdd.h hdd_hddtemp.c lmsensor.h lmsensor.c plog.h plog.c \
measure.h measure.c ptime.h ptime.c nvidia.h psensor.h \
psensor.c pio.h pio.c slog.c slog.h url.c url.h hdd_atasmart.c \
nvidia.c amd.c cpu.c psensor_json.h psensor_json.c
@GTOP_TRUE@am__objects_4 = cpu.$(OBJEXT)
@JSON_TRUE@am__objects_5 = psensor_json.$(OBJEXT)
am_libpsensor_a_OBJECTS = color.$(OBJEXT) hdd_hddtemp.$(OBJEXT) \
- lmsensor.$(OBJEXT) log.$(OBJEXT) measure.$(OBJEXT) \
+ lmsensor.$(OBJEXT) plog.$(OBJEXT) measure.$(OBJEXT) \
ptime.$(OBJEXT) psensor.$(OBJEXT) pio.$(OBJEXT) slog.$(OBJEXT) \
url.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
$(am__objects_3) $(am__objects_4) $(am__objects_5)
top_srcdir = @top_srcdir@
noinst_LIBRARIES = libpsensor.a
libpsensor_a_SOURCES = amd.h bool.h color.h color.c cpu.h hdd.h \
- hdd_hddtemp.c lmsensor.h lmsensor.c log.h log.c measure.h \
+ hdd_hddtemp.c lmsensor.h lmsensor.c plog.h plog.c measure.h \
measure.c ptime.h ptime.c nvidia.h psensor.h psensor.c pio.h \
pio.c slog.c slog.h url.c url.h $(am__append_1) \
$(am__append_4) $(am__append_7) $(am__append_8) \
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdd_atasmart.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdd_hddtemp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lmsensor.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/measure.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nvidia.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plog.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/psensor.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/psensor_json.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptime.Po@am__quote@
#include "pio.h"
#include "hdd.h"
-#include "log.h"
+#include <plog.h>
static int filter_sd(const char *p)
{
+++ /dev/null
-/*
- * Copyright (C) 2010-2014 jeanfi@gmail.com
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-#define _LARGEFILE_SOURCE 1
-#include "config.h"
-
-#include <locale.h>
-#include <libintl.h>
-#define _(str) gettext(str)
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <time.h>
-
-#include "log.h"
-#include "ptime.h"
-
-static FILE *file;
-int log_level = LOG_WARN;
-
-void log_open(const char *path)
-{
- file = fopen(path, "a");
-
- if (!file)
- log_printf(LOG_ERR, _("Cannot open log file: %s"), path);
-}
-
-void log_close()
-{
- if (!file)
- return ;
-
- fclose(file);
-
- file = NULL;
-}
-
-
-#define LOG_BUFFER 4096
-static void vlogf(int lvl, const char *fmt, va_list ap)
-{
- char buffer[1 + LOG_BUFFER];
- char *lvl_str, *t;
- FILE *stdf;
-
- if (lvl > LOG_INFO && (!file || lvl > log_level))
- return ;
-
- vsnprintf(buffer, LOG_BUFFER, fmt, ap);
- buffer[LOG_BUFFER] = '\0';
-
- switch (lvl) {
- case LOG_WARN:
- lvl_str = "[WARN]";
- break;
- case LOG_ERR:
- lvl_str = "[ERR]";
- break;
- case LOG_DEBUG:
- lvl_str = "[DEBUG]";
- break;
- case LOG_INFO:
- lvl_str = "[INFO]";
- break;
- default:
- lvl_str = "[??]";
- }
-
- t = get_time_str();
- if (!t)
- return ;
-
- if (file && lvl <= log_level) {
- fprintf(file, "[%s] %s %s\n", t, lvl_str, buffer);
- fflush(file);
- } else {
- t = NULL;
- }
-
- if (lvl <= LOG_INFO) {
- if (lvl == LOG_WARN || lvl == LOG_ERR)
- stdf = stderr;
- else
- stdf = stdout;
-
-
- fprintf(stdf, "[%s] %s %s\n", t, lvl_str, buffer);
- }
-
- free(t);
-}
-
-void log_printf(int lvl, const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vlogf(lvl, fmt, ap);
- va_end(ap);
-}
-
-void log_debug(const char *fmt, ...)
-{
- va_list ap;
-
- if (log_level < LOG_DEBUG)
- return ;
-
- va_start(ap, fmt);
- vlogf(LOG_DEBUG, fmt, ap);
- va_end(ap);
-}
-
-void log_err(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vlogf(LOG_ERR, fmt, ap);
- va_end(ap);
-}
-
-void log_warn(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vlogf(LOG_WARN, fmt, ap);
- va_end(ap);
-}
-
-void log_info(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vlogf(LOG_INFO, fmt, ap);
- va_end(ap);
-}
+++ /dev/null
-/*
- * Copyright (C) 2010-2014 jeanfi@gmail.com
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-#ifndef _PSENSOR_LOG_H_
-#define _PSENSOR_LOG_H_
-
-enum log_level {
- LOG_ERR ,
- LOG_WARN,
- LOG_INFO,
- LOG_DEBUG
-};
-
-void log_open(const char *path);
-
-void log_printf(int lvl, const char *fmt, ...);
-void log_debug(const char *fmt, ...);
-void log_err(const char *fmt, ...);
-void log_info(const char *fmt, ...);
-void log_warn(const char *fmt, ...);
-
-void log_close();
-
-/* level of the log file. */
-extern int log_level;
-
-#endif
#define _LARGEFILE_SOURCE 1
#include "config.h"
-#include <stdlib.h>
+#include <dirent.h>
+#include <fts.h>
#include <stdio.h>
-#include <sys/stat.h>
+#include <stdlib.h>
#include <string.h>
-#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <plog.h>
+#include <pio.h>
+
+/* Directory separator is \ when cross-compiling for MS Windows
+ systems */
+#if defined(__MINGW32__)
+#define DIRSEP ('\\')
+#else
+#define DIRSEP '/'
+#endif
-#include "pio.h"
+#define FCOPY_BUF_SZ 4096
-static char *path_append(const char *dir, const char *path)
+int is_dir(const char *path)
{
- char *result;
+ struct stat st;
- result = malloc(strlen(dir) + 1 + strlen(path) + 1);
+ int ret = lstat(path, &st);
- strcpy(result, dir);
- strcat(result, "/");
- strcat(result, path);
+ if (ret == 0 && S_ISDIR(st.st_mode))
+ return 1;
- return result;
+ return 0;
+}
+
+int is_file(const char *path)
+{
+ struct stat st;
+
+ int ret = lstat(path, &st);
+
+ if (ret == 0 && S_ISREG(st.st_mode))
+ return 1;
+
+ return 0;
+}
+
+char *dir_normalize(const char *dpath)
+{
+ char *npath;
+ int n;
+
+ if (!dpath || !strlen(dpath))
+ return NULL;
+
+ npath = strdup(dpath);
+
+ n = strlen(npath);
+
+ if (n > 1 && npath[n - 1] == '/')
+ npath[n - 1] = '\0';
+
+ return npath;
}
static char **paths_add(char **paths, int n, char *path)
free(paths);
}
+
+char *file_get_content(const char *fpath)
+{
+ long size;
+
+ char *page;
+
+ size = file_get_size(fpath);
+ if (size == -1) {
+ page = NULL;
+
+ } else if (size == 0) {
+ page = malloc(1);
+ *page = '\0';
+
+ } else {
+ FILE *fp = fopen(fpath, "rb");
+ if (fp) {
+ page = malloc(size + 1);
+ if (!page || size != fread(page, 1, size, fp)) {
+ free(page);
+ return NULL;
+ }
+
+ *(page + size) = '\0';
+
+ fclose(fp);
+ } else {
+ page = NULL;
+ }
+ }
+
+ return page;
+}
+
+long file_get_size(const char *path)
+{
+ FILE *fp;
+
+ if (!is_file(path))
+ return -1;
+
+ fp = fopen(path, "rb");
+ if (fp) {
+ long size;
+
+ if (fseek(fp, 0, SEEK_END) == -1)
+ return -1;
+
+ size = ftell(fp);
+
+ fclose(fp);
+
+ return size;
+ }
+
+ return -1;
+}
+
+#define FCOPY_BUF_SZ 4096
+static int FILE_copy(FILE *src, FILE *dst)
+{
+ int ret = 0;
+ char *buf = malloc(FCOPY_BUF_SZ);
+ int n;
+
+ if (!buf)
+ return FILE_COPY_ERROR_ALLOC_BUFFER;
+
+ while (!ret) {
+ n = fread(buf, 1, FCOPY_BUF_SZ, src);
+ if (n) {
+ if (fwrite(buf, 1, n, dst) != n)
+ ret = FILE_COPY_ERROR_WRITE;
+ } else {
+ if (!feof(src))
+ ret = FILE_COPY_ERROR_READ;
+ else
+ break;
+ }
+ }
+
+ free(buf);
+
+ return ret;
+}
+
+int
+file_copy(const char *src, const char *dst)
+{
+ FILE *fsrc, *fdst;
+ int ret = 0;
+
+ log_fct("copy %s to %s", src, dst);
+
+ fsrc = fopen(src, "r");
+
+ if (fsrc) {
+ fdst = fopen(dst, "w+");
+
+ if (fdst) {
+ ret = FILE_copy(fsrc, fdst);
+ fclose(fdst);
+ } else {
+ ret = FILE_COPY_ERROR_OPEN_DST;
+ }
+
+ fclose(fsrc);
+ } else {
+ ret = FILE_COPY_ERROR_OPEN_SRC;
+ }
+
+ return ret;
+}
+
+char *path_append(const char *dir, const char *path)
+{
+ char *ret, *ndir;
+
+ ndir = dir_normalize(dir);
+
+ if (!ndir && (!path || !strlen(path)))
+ ret = NULL;
+
+ else if (!ndir) {
+ ret = strdup(path);
+
+ } else if (!path || !strlen(path)) {
+ return ndir;
+
+ } else {
+ ret = malloc(strlen(ndir) + 1 + strlen(path) + 1);
+ strcpy(ret, ndir);
+ strcat(ret, "/");
+ strcat(ret, path);
+ }
+
+ free(ndir);
+
+ return ret;
+}
+
+void mkdirs(const char *dirs, mode_t mode)
+{
+ char *c, *dir;
+ int i;
+
+ log_fct("mkdirs %s", dirs);
+
+ c = (char *)dirs;
+ dir = malloc(strlen(dirs) + 1);
+
+ i = 0;
+ while (*c) {
+ if ((*c == DIRSEP || *c == '\0') && c != dirs) {
+ strncpy(dir, dirs, i);
+ dir[i] = '\0';
+ mkdir(dir, mode);
+ }
+
+ c++;
+ i++;
+ }
+
+ mkdir(dirs, mode);
+
+ free(dir);
+}
+
+void
+file_copy_print_error(int code, const char *src, const char *dst)
+{
+ switch (code) {
+ case 0:
+ break;
+ case FILE_COPY_ERROR_OPEN_SRC:
+ printf("File copy error: failed to open %s.\n", src);
+ break;
+ case FILE_COPY_ERROR_OPEN_DST:
+ printf("File copy error: failed to open %s.\n", dst);
+ break;
+ case FILE_COPY_ERROR_READ:
+ printf("File copy error: failed to read %s.\n", src);
+ break;
+ case FILE_COPY_ERROR_WRITE:
+ printf("File copy error: failed to write %s.\n", src);
+ break;
+ case FILE_COPY_ERROR_ALLOC_BUFFER:
+ printf("File copy error: failed to allocate buffer.\n");
+ break;
+ default:
+ printf("File copy error: unknown error %d.\n", code);
+ }
+}
+
+int dir_rcopy(const char *src, const char *dst)
+{
+ int ret;
+ char **paths;
+ FTS *ftsp;
+ FTSENT *p, *chp;
+ int fts_options = FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOCHDIR;
+ char *p_dst, *n_dst;
+
+ log_fct_enter();
+
+ log_fct("copy dir %s to %s", src, dst);
+
+ paths = malloc(2 * sizeof(char *));
+ paths[0] = strdup(src);
+ paths[1] = NULL;
+
+ ftsp = fts_open(paths, fts_options, NULL);
+ if (!ftsp)
+ return 1;
+
+ chp = fts_children(ftsp, 0);
+ if (!chp)
+ return 0;
+
+ n_dst = dir_normalize(dst);
+
+ while ((p = fts_read(ftsp)) != NULL) {
+ switch (p->fts_info) {
+ case FTS_D:
+ p_dst = path_append(n_dst,
+ p->fts_path + strlen(src) + 1);
+ mkdirs(p_dst, 0777);
+ free(p_dst);
+ break;
+ case FTS_F:
+ p_dst = path_append(n_dst,
+ p->fts_path + strlen(src) + 1);
+ file_copy(p->fts_path, p_dst);
+ free(p_dst);
+ break;
+ default:
+ break;
+ }
+ }
+ fts_close(ftsp);
+
+ free(n_dst);
+ free(paths);
+
+ ret = 0;
+
+ log_fct_exit();
+
+ return ret;
+}
/*
- * Copyright (C) 2010-2014 jeanfi@gmail.com
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
+ Copyright (C) 2010-2014 jeanfi@gmail.com
+
+ 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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA
+*/
+
#ifndef _P_IO_H
#define _P_IO_H
+#define P_IO_VER 3
+
+/* Returns '1' if a given 'path' denotates a directory else returns
+ 0 */
+int is_dir(const char *path);
+
+/* Returns '1' if a given 'path' denotates a file else returns
+ 0 */
+int is_file(const char *path);
+
+/* Returns a normalized path */
+char *path_normalize(const char *dpath);
+
+/* Returns the null-terminated entries of a directory */
char **dir_list(const char *dpath, int (*filter) (const char *path));
void paths_free(char **paths);
+char *path_append(const char *dir, const char *path);
+
+/*
+ Returns the size of a file.
+ Returns '-1' if the size cannot be retrieved or not a file.
+*/
+long file_get_size(const char *path);
+
+/*
+ Returns the content of a file.
+ Returns 'NULL' if the file cannot be read or failed to allocate
+ enough memory.
+ Returns an empty string if the file exists but is empty.
+*/
+char *file_get_content(const char *path);
+
+enum file_copy_error {
+ FILE_COPY_ERROR_OPEN_SRC = 1,
+ FILE_COPY_ERROR_OPEN_DST,
+ FILE_COPY_ERROR_READ,
+ FILE_COPY_ERROR_WRITE,
+ FILE_COPY_ERROR_ALLOC_BUFFER
+};
+
+void file_copy_print_error(int code, const char *src, const char *dst);
+
+/*
+ Copy a file.
+
+ Returns '0' if sucessfull, otherwise return the error code.
+*/
+int file_copy(const char *src, const char *dst);
+
+int dir_rcopy(const char *, const char *);
+
+void mkdirs(const char *dirs, mode_t mode);
+
#endif
--- /dev/null
+/*
+ * Copyright (C) 2010-2014 jeanfi@gmail.com
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#define _LARGEFILE_SOURCE 1
+#include "config.h"
+
+#include <locale.h>
+#include <libintl.h>
+#define _(str) gettext(str)
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include <plog.h>
+#include <ptime.h>
+
+static FILE *file;
+int log_level = LOG_WARN;
+
+void log_open(const char *path)
+{
+ file = fopen(path, "a");
+
+ if (!file)
+ log_printf(LOG_ERR, _("Cannot open log file: %s"), path);
+}
+
+void log_close()
+{
+ if (!file)
+ return ;
+
+ fclose(file);
+
+ file = NULL;
+}
+
+
+#define LOG_BUFFER 4096
+static void vlogf(int lvl, const char *fct, const char *fmt, va_list ap)
+{
+ char buffer[1 + LOG_BUFFER];
+ char *lvl_str, *t;
+ FILE *stdf;
+
+ if (lvl > LOG_INFO && (!file || lvl > log_level))
+ return ;
+
+ vsnprintf(buffer, LOG_BUFFER, fmt, ap);
+ buffer[LOG_BUFFER] = '\0';
+
+ switch (lvl) {
+ case LOG_WARN:
+ lvl_str = "[WARN]";
+ break;
+ case LOG_ERR:
+ lvl_str = "[ERR]";
+ break;
+ case LOG_DEBUG:
+ lvl_str = "[DEBUG]";
+ break;
+ case LOG_INFO:
+ lvl_str = "[INFO]";
+ break;
+ default:
+ lvl_str = "[??]";
+ }
+
+ t = get_current_ISO8601_time();
+ if (!t)
+ return ;
+
+ if (file && lvl <= log_level) {
+ if (fct)
+ fprintf(file,
+ "[%s] %s %s(): %s\n", t, lvl_str, fct, buffer);
+ else
+ fprintf(file, "[%s] %s %s\n", t, lvl_str, buffer);
+ fflush(file);
+ } else {
+ t = NULL;
+ }
+
+ if (lvl <= LOG_INFO) {
+ if (lvl == LOG_WARN || lvl == LOG_ERR)
+ stdf = stderr;
+ else
+ stdf = stdout;
+
+ if (fct)
+ fprintf(file,
+ "[%s] %s %s(): %s\n", t, lvl_str, fct, buffer);
+ else
+ fprintf(stdf, "[%s] %s %s\n", t, lvl_str, buffer);
+ }
+
+ free(t);
+}
+
+void log_printf(int lvl, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(lvl, NULL, fmt, ap);
+ va_end(ap);
+}
+
+void log_debug(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (log_level < LOG_DEBUG)
+ return ;
+
+ va_start(ap, fmt);
+ vlogf(LOG_DEBUG, NULL, fmt, ap);
+ va_end(ap);
+}
+
+void log_err(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(LOG_ERR, NULL, fmt, ap);
+ va_end(ap);
+}
+
+void log_warn(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(LOG_WARN, NULL, fmt, ap);
+ va_end(ap);
+}
+
+void log_info(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(LOG_INFO, NULL, fmt, ap);
+ va_end(ap);
+}
+
+void _log(const char *fct, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlogf(LOG_DEBUG, fct, fmt, ap);
+ va_end(ap);
+}
--- /dev/null
+/*
+ Copyright (C) 2010-2014 jeanfi@gmail.com
+
+ 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.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA
+ */
+#ifndef _P_LOG_H_
+#define _P_LOG_H_
+
+#define P_LOG_VER 2
+
+enum log_level {
+ LOG_ERR ,
+ LOG_WARN,
+ LOG_INFO,
+ LOG_DEBUG
+};
+
+void log_open(const char *path);
+void log_close();
+
+void log_printf(int lvl, const char *fmt, ...);
+void log_debug(const char *fmt, ...);
+void log_err(const char *fmt, ...);
+void log_info(const char *fmt, ...);
+void log_warn(const char *fmt, ...);
+
+void _log(const char *fct, const char *fmt, ...);
+
+#define log_fct(...) _log(__func__, __VA_ARGS__)
+#define log_fct_enter() log_fct("ENTER")
+#define log_fct_exit() log_fct("EXIT")
+
+/* level of the log file. */
+extern int log_level;
+
+#endif
#include "bool.h"
#include "color.h"
-#include "log.h"
+#include <plog.h>
#include "measure.h"
enum psensor_type {
/*
- * Copyright (C) 2010-2014 jeanfi@gmail.com
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
+ Copyright (C) 2010-2014 jeanfi@gmail.com
+
+ 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.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA
*/
#include <stdlib.h>
+#include <string.h>
+
+#include <ptime.h>
+
+const int P_TIME_VER = 2;
+
+static const int ISO8601_TIME_LENGTH = 19; /* YYYY-MM-DDThh:mm:ss */
+static const int ISO8601_DATE_LENGTH = 10; /* YYYY-MM-DD */
+
+char *time_to_ISO8601_time(time_t *t)
+{
+ struct tm lt;
-#include "ptime.h"
+ memset(<, 0, sizeof(struct tm));
+ if (!gmtime_r(t, <))
+ return NULL;
-char *time_to_str(time_t *t)
+ return tm_to_ISO8601_time(<);
+}
+
+char *time_to_ISO8601_date(time_t *t)
{
struct tm lt;
+
+ memset(<, 0, sizeof(struct tm));
+ if (!gmtime_r(t, <))
+ return NULL;
+
+ return tm_to_ISO8601_date(<);
+}
+
+char *tm_to_ISO8601_date(struct tm *tm)
+{
char *str;
- if (!localtime_r(t, <))
+ str = malloc(ISO8601_DATE_LENGTH + 1);
+
+ if (strftime(str, ISO8601_DATE_LENGTH + 1, "%F", tm)) {
+ return str;
+ } else {
+ free(str);
return NULL;
+ }
+}
+
+char *tm_to_ISO8601_time(struct tm *tm)
+{
+ char *str;
- str = malloc(64);
+ str = malloc(ISO8601_TIME_LENGTH + 1);
- if (strftime(str, 64, "%s", <)) {
+ if (strftime(str, ISO8601_TIME_LENGTH + 1, "%FT%T", tm)) {
return str;
} else {
free(str);
}
}
-char *get_time_str()
+char *get_current_ISO8601_time()
{
time_t t;
t = time(NULL);
- return time_to_str(&t);
+ return time_to_ISO8601_time(&t);
}
#include <time.h>
-char *get_time_str();
-char *time_to_str(time_t *t);
+extern const int P_TIME_VER;
+
+char *get_current_ISO8601_time();
+
+char *time_to_ISO8601_time(time_t *);
+char *time_to_ISO8601_date(time_t *);
+
+char *tm_to_ISO8601_date(struct tm *);
+char *tm_to_ISO8601_time(struct tm *);
#endif
#include "bool.h"
#include "config.h"
-#include "log.h"
+#include <plog.h>
#include "ptime.h"
#include "slog.h"
static const char *DEFAULT_FILENAME = "sensors.log";
+static char *time_to_str(time_t *t)
+{
+ struct tm lt;
+ char *str;
+
+ if (!localtime_r(t, <))
+ return NULL;
+
+ str = malloc(64);
+
+ if (strftime(str, 64, "%s", <)) {
+ return str;
+ } else {
+ free(str);
+ return NULL;
+ }
+}
+
static char *get_default_path()
{
char *home, *path, *dir;
#include "cpu.h"
#endif
-#include "log.h"
+#include <plog.h>
#include "psensor_json.h"
#include "url.h"
#include "server.h"
return GTK_WIDGET(menu);
}
-void ui_appindicator_update(struct ui_psensor *ui, unsigned int attention)
+static void update_label(struct ui_psensor *ui)
{
- AppIndicatorStatus status;
- char *label, *str, *tmp;
+ char *label, *str, *tmp, *guide;
struct psensor **p;
- if (!indicator)
- return;
-
- status = app_indicator_get_status(indicator);
-
p = ui_get_sensors_ordered_by_position(ui);
label = NULL;
+ guide = NULL;
while (*p) {
if (config_is_appindicator_label_enabled((*p)->id)) {
str = psensor_current_value_to_str
(*p, ui->config->temperature_unit == CELCIUS);
+
if (label == NULL) {
label = str;
} else {
free(str);
label = tmp;
}
+
+ if (is_temp_type((*p)->type))
+ str = "999UUU";
+ else if (is_fan_type((*p)->type))
+ str = "999UUU";
+ else /* cpu load */
+ str = "999%";
+
+ if (guide == NULL) {
+ guide = strdup(str);
+ } else {
+ tmp = malloc(strlen(guide)
+ + 1
+ + strlen(str)
+ + 1);
+ sprintf(tmp, "%sW%s", guide, str);
+ free(guide);
+ guide = tmp;
+ }
+
}
p++;
}
+ printf("%s\n", label);
+ printf("%s\n", guide);
+
+ app_indicator_set_label(indicator, label, guide);
+}
- app_indicator_set_label(indicator, label, NULL);
+void ui_appindicator_update(struct ui_psensor *ui, unsigned int attention)
+{
+ AppIndicatorStatus status;
+
+ if (!indicator)
+ return;
+
+ update_label(ui);
+
+ status = app_indicator_get_status(indicator);
if (!attention && status == APP_INDICATOR_STATUS_ATTENTION)
app_indicator_set_status(indicator,
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
-#include "log.h"
+#include <plog.h>
#include "ui_status.h"
static const char *ICON = "psensor_normal";
test_io_dir_list_SOURCES = test_io_dir_list.c
test_psensor_type_to_unit_str_SOURCES = test_psensor_type_to_unit_str.c
+test_psensor_type_to_unit_str_CFLAGS = -I$(top_srcdir)/src/lib
test_psensor_value_to_str_SOURCES = test_psensor_value_to_str.c
+test_psensor_value_to_str_CFLAGS = -I$(top_srcdir)/src/lib
test_url_encode_SOURCES = test_url_encode.c
test_url_normalize_SOURCES = test_url_normalize.c
if CPPCHECK
TESTS += test-cppcheck.sh
-endif
\ No newline at end of file
+endif
am_test_io_dir_list_OBJECTS = test_io_dir_list.$(OBJEXT)
test_io_dir_list_OBJECTS = $(am_test_io_dir_list_OBJECTS)
test_io_dir_list_LDADD = $(LDADD)
-am_test_psensor_type_to_unit_str_OBJECTS = \
- test_psensor_type_to_unit_str.$(OBJEXT)
+am_test_psensor_type_to_unit_str_OBJECTS = test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.$(OBJEXT)
test_psensor_type_to_unit_str_OBJECTS = \
$(am_test_psensor_type_to_unit_str_OBJECTS)
test_psensor_type_to_unit_str_LDADD = $(LDADD)
+test_psensor_type_to_unit_str_LINK = $(CCLD) \
+ $(test_psensor_type_to_unit_str_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
am_test_psensor_value_to_str_OBJECTS = \
- test_psensor_value_to_str.$(OBJEXT)
+ test_psensor_value_to_str-test_psensor_value_to_str.$(OBJEXT)
test_psensor_value_to_str_OBJECTS = \
$(am_test_psensor_value_to_str_OBJECTS)
test_psensor_value_to_str_LDADD = $(LDADD)
+test_psensor_value_to_str_LINK = $(CCLD) \
+ $(test_psensor_value_to_str_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
am_test_url_encode_OBJECTS = test_url_encode.$(OBJEXT)
test_url_encode_OBJECTS = $(am_test_url_encode_OBJECTS)
test_url_encode_LDADD = $(LDADD)
AM_CPPFLAGS = -Wall -Werror
test_io_dir_list_SOURCES = test_io_dir_list.c
test_psensor_type_to_unit_str_SOURCES = test_psensor_type_to_unit_str.c
+test_psensor_type_to_unit_str_CFLAGS = -I$(top_srcdir)/src/lib
test_psensor_value_to_str_SOURCES = test_psensor_value_to_str.c
+test_psensor_value_to_str_CFLAGS = -I$(top_srcdir)/src/lib
test_url_encode_SOURCES = test_url_encode.c
test_url_normalize_SOURCES = test_url_normalize.c
all: all-am
$(LINK) $(test_io_dir_list_OBJECTS) $(test_io_dir_list_LDADD) $(LIBS)
test-psensor-type-to-unit-str$(EXEEXT): $(test_psensor_type_to_unit_str_OBJECTS) $(test_psensor_type_to_unit_str_DEPENDENCIES) $(EXTRA_test_psensor_type_to_unit_str_DEPENDENCIES)
@rm -f test-psensor-type-to-unit-str$(EXEEXT)
- $(LINK) $(test_psensor_type_to_unit_str_OBJECTS) $(test_psensor_type_to_unit_str_LDADD) $(LIBS)
+ $(test_psensor_type_to_unit_str_LINK) $(test_psensor_type_to_unit_str_OBJECTS) $(test_psensor_type_to_unit_str_LDADD) $(LIBS)
test-psensor-value-to-str$(EXEEXT): $(test_psensor_value_to_str_OBJECTS) $(test_psensor_value_to_str_DEPENDENCIES) $(EXTRA_test_psensor_value_to_str_DEPENDENCIES)
@rm -f test-psensor-value-to-str$(EXEEXT)
- $(LINK) $(test_psensor_value_to_str_OBJECTS) $(test_psensor_value_to_str_LDADD) $(LIBS)
+ $(test_psensor_value_to_str_LINK) $(test_psensor_value_to_str_OBJECTS) $(test_psensor_value_to_str_LDADD) $(LIBS)
test-url-encode$(EXEEXT): $(test_url_encode_OBJECTS) $(test_url_encode_DEPENDENCIES) $(EXTRA_test_url_encode_DEPENDENCIES)
@rm -f test-url-encode$(EXEEXT)
$(LINK) $(test_url_encode_OBJECTS) $(test_url_encode_LDADD) $(LIBS)
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_io_dir_list.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_psensor_type_to_unit_str.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_psensor_value_to_str.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_psensor_value_to_str-test_psensor_value_to_str.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_url_encode.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_url_normalize.Po@am__quote@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.o: test_psensor_type_to_unit_str.c
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_psensor_type_to_unit_str_CFLAGS) $(CFLAGS) -MT test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.o -MD -MP -MF $(DEPDIR)/test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.Tpo -c -o test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.o `test -f 'test_psensor_type_to_unit_str.c' || echo '$(srcdir)/'`test_psensor_type_to_unit_str.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.Tpo $(DEPDIR)/test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test_psensor_type_to_unit_str.c' object='test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_psensor_type_to_unit_str_CFLAGS) $(CFLAGS) -c -o test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.o `test -f 'test_psensor_type_to_unit_str.c' || echo '$(srcdir)/'`test_psensor_type_to_unit_str.c
+
+test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.obj: test_psensor_type_to_unit_str.c
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_psensor_type_to_unit_str_CFLAGS) $(CFLAGS) -MT test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.obj -MD -MP -MF $(DEPDIR)/test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.Tpo -c -o test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.obj `if test -f 'test_psensor_type_to_unit_str.c'; then $(CYGPATH_W) 'test_psensor_type_to_unit_str.c'; else $(CYGPATH_W) '$(srcdir)/test_psensor_type_to_unit_str.c'; fi`
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.Tpo $(DEPDIR)/test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test_psensor_type_to_unit_str.c' object='test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_psensor_type_to_unit_str_CFLAGS) $(CFLAGS) -c -o test_psensor_type_to_unit_str-test_psensor_type_to_unit_str.obj `if test -f 'test_psensor_type_to_unit_str.c'; then $(CYGPATH_W) 'test_psensor_type_to_unit_str.c'; else $(CYGPATH_W) '$(srcdir)/test_psensor_type_to_unit_str.c'; fi`
+
+test_psensor_value_to_str-test_psensor_value_to_str.o: test_psensor_value_to_str.c
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_psensor_value_to_str_CFLAGS) $(CFLAGS) -MT test_psensor_value_to_str-test_psensor_value_to_str.o -MD -MP -MF $(DEPDIR)/test_psensor_value_to_str-test_psensor_value_to_str.Tpo -c -o test_psensor_value_to_str-test_psensor_value_to_str.o `test -f 'test_psensor_value_to_str.c' || echo '$(srcdir)/'`test_psensor_value_to_str.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/test_psensor_value_to_str-test_psensor_value_to_str.Tpo $(DEPDIR)/test_psensor_value_to_str-test_psensor_value_to_str.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test_psensor_value_to_str.c' object='test_psensor_value_to_str-test_psensor_value_to_str.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_psensor_value_to_str_CFLAGS) $(CFLAGS) -c -o test_psensor_value_to_str-test_psensor_value_to_str.o `test -f 'test_psensor_value_to_str.c' || echo '$(srcdir)/'`test_psensor_value_to_str.c
+
+test_psensor_value_to_str-test_psensor_value_to_str.obj: test_psensor_value_to_str.c
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_psensor_value_to_str_CFLAGS) $(CFLAGS) -MT test_psensor_value_to_str-test_psensor_value_to_str.obj -MD -MP -MF $(DEPDIR)/test_psensor_value_to_str-test_psensor_value_to_str.Tpo -c -o test_psensor_value_to_str-test_psensor_value_to_str.obj `if test -f 'test_psensor_value_to_str.c'; then $(CYGPATH_W) 'test_psensor_value_to_str.c'; else $(CYGPATH_W) '$(srcdir)/test_psensor_value_to_str.c'; fi`
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/test_psensor_value_to_str-test_psensor_value_to_str.Tpo $(DEPDIR)/test_psensor_value_to_str-test_psensor_value_to_str.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test_psensor_value_to_str.c' object='test_psensor_value_to_str-test_psensor_value_to_str.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_psensor_value_to_str_CFLAGS) $(CFLAGS) -c -o test_psensor_value_to_str-test_psensor_value_to_str.obj `if test -f 'test_psensor_value_to_str.c'; then $(CYGPATH_W) 'test_psensor_value_to_str.c'; else $(CYGPATH_W) '$(srcdir)/test_psensor_value_to_str.c'; fi`
+
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \