ppastats_SOURCES = \
cache.h cache.c\
html.h html.c\
+ io.h io.c\
list.h list.c\
lp.h lp.c\
lp_json.h lp_json.c\
CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
PROGRAMS = $(bin_PROGRAMS)
-am_ppastats_OBJECTS = cache.$(OBJEXT) html.$(OBJEXT) list.$(OBJEXT) \
- lp.$(OBJEXT) lp_json.$(OBJEXT) lp_ws.$(OBJEXT) main.$(OBJEXT) \
- ppastats.$(OBJEXT)
+am_ppastats_OBJECTS = cache.$(OBJEXT) html.$(OBJEXT) io.$(OBJEXT) \
+ list.$(OBJEXT) lp.$(OBJEXT) lp_json.$(OBJEXT) lp_ws.$(OBJEXT) \
+ main.$(OBJEXT) ppastats.$(OBJEXT)
ppastats_OBJECTS = $(am_ppastats_OBJECTS)
ppastats_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
ppastats_SOURCES = \
cache.h cache.c\
html.h html.c\
+ io.h io.c\
list.h list.c\
lp.h lp.c\
lp_json.h lp_json.c\
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cache.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/html.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lp_json.Po@am__quote@
#include <json/json.h>
#include "html.h"
+#include "io.h"
#include "lp.h"
#include "lp_ws.h"
#include "ppastats.h"
-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
-};
-
#define HTML_FOOTER \
" <div id=\"footer\">Generated by \
<a href='http://wpitchoune.net/ppastats'>ppastats</a></div>\n\
</div>\n\
%s"
-#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
-fcopy(const char *src, const char *dst)
-{
- FILE *fsrc, *fdst;
- int ret = 0;
-
- if (debug)
- printf("DEBUG: copy: %s to %s\n", 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;
-}
-
static char *path_new(const char *dir, const char *file, const char *suffixe)
{
char *path = malloc(strlen(dir)+1+
--- /dev/null
+/*
+ * Copyright (C) 2011 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 <stdio.h>
+#include <stdlib.h>
+
+#include "io.h"
+
+#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 fcopy(const char *src, const char *dst)
+{
+ FILE *fsrc, *fdst;
+ int ret = 0;
+
+ 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;
+}
--- /dev/null
+/*
+ * Copyright (C) 2011 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 _PPASTATS_IO_H_
+#define _PPASTATS_IO_H_
+
+/*
+ * Convenience functions for copying files.
+ */
+
+
+enum file_copy_code {
+ FILE_COPY_OK = 0,
+ FILE_COPY_ERROR_OPEN_SRC = 1,
+ FILE_COPY_ERROR_OPEN_DST,
+ FILE_COPY_ERROR_READ,
+ FILE_COPY_ERROR_WRITE,
+ FILE_COPY_ERROR_ALLOC_BUFFER
+};
+
+/*
+ * Copies file 'src' to 'dst'.
+ *
+ * Returns FILE_COPY_OK on success otherwise error code.
+ */
+int fcopy(const char *src, const char *dst);
+
+#endif
.PP
ppastats home page: <http://wpitchoune.net/ppastats>
.SH COPYRIGHT
-Copyright \(co 2010\-2011 jeanfi@gmail.com
+Copyright \(co 2011 jeanfi@gmail.com
License GPLv2: GNU GPL version 2 or later <http://www.gnu.org/licenses/old\-licenses/gpl\-2.0.html>
.br
This is free software: you are free to change and redistribute it.