summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-03-19 09:00:40 +0000
committerAurelien Foret <aurelien@archlinux.org>2005-03-19 09:00:40 +0000
commit0709c155431545f540fb512834ee0ffb6c0cb7d3 (patch)
treef27b0aea57ca0df4dbfcb4cc3b3b191076024bff
parent4b272ae5b6a7de9a110ba9e444607ef44ff1f652 (diff)
downloadpacman-0709c155431545f540fb512834ee0ffb6c0cb7d3.tar.xz
Relocated log and transaction stuffs from pacman.c to log.c and trans.c
-rw-r--r--src/pacman/Makefile2
-rw-r--r--src/pacman/add.c3
-rw-r--r--src/pacman/conf.c2
-rw-r--r--src/pacman/download.c2
-rw-r--r--src/pacman/log.c115
-rw-r--r--src/pacman/log.h49
-rw-r--r--src/pacman/pacman.c134
-rw-r--r--src/pacman/pacman.h23
-rw-r--r--src/pacman/query.c2
-rw-r--r--src/pacman/remove.c3
-rw-r--r--src/pacman/sync.c1
-rw-r--r--src/pacman/trans.c87
-rw-r--r--src/pacman/trans.h29
13 files changed, 292 insertions, 160 deletions
diff --git a/src/pacman/Makefile b/src/pacman/Makefile
index 3d2874ac..9aebc67c 100644
--- a/src/pacman/Makefile
+++ b/src/pacman/Makefile
@@ -6,10 +6,12 @@ AR=ar rc
RAN=ranlib
OBJECTS=util.o \
+ log.o \
list.o \
package.o \
db.o \
download.o \
+ trans.o \
add.o \
remove.o \
upgrade.o \
diff --git a/src/pacman/add.c b/src/pacman/add.c
index 1bf46f36..b3bc05ad 100644
--- a/src/pacman/add.c
+++ b/src/pacman/add.c
@@ -25,9 +25,10 @@
#include <alpm.h>
/* pacman */
+#include "log.h"
#include "list.h"
#include "download.h"
-#include "pacman.h"
+#include "trans.h"
extern unsigned char pmo_upgrade;
extern unsigned char pmo_flags;
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index c5df8352..bc6b214f 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -27,10 +27,10 @@
#include <alpm.h>
/* pacman */
#include "util.h"
+#include "log.h"
#include "list.h"
#include "sync.h"
#include "download.h"
-#include "pacman.h"
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
diff --git a/src/pacman/download.c b/src/pacman/download.c
index 8fbcd647..f994cab4 100644
--- a/src/pacman/download.c
+++ b/src/pacman/download.c
@@ -31,9 +31,9 @@
#include <alpm.h>
/* pacman */
+#include "log.h"
#include "list.h"
#include "download.h"
-#include "pacman.h"
/* progress bar */
static char sync_fnm[25];
diff --git a/src/pacman/log.c b/src/pacman/log.c
new file mode 100644
index 00000000..c0bb62b6
--- /dev/null
+++ b/src/pacman/log.c
@@ -0,0 +1,115 @@
+/*
+ * log.c
+ *
+ * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include <alpm.h>
+
+/* pacman */
+#include "log.h"
+
+#define LOG_STR_LEN 256
+
+extern unsigned short pmo_verbose;
+
+static int neednl; /* for cleaner message output */
+
+/* Callback to handle notifications from the library
+ */
+void cb_log(unsigned short level, char *msg)
+{
+ char str[8] = "";
+
+ switch(level) {
+ case PM_LOG_DEBUG:
+ sprintf(str, "DEBUG");
+ break;
+ case PM_LOG_ERROR:
+ sprintf(str, "ERROR");
+ break;
+ case PM_LOG_WARNING:
+ sprintf(str, "WARNING");
+ break;
+ case PM_LOG_FLOW1:
+ sprintf(str, "FLOW1");
+ break;
+ case PM_LOG_FLOW2:
+ sprintf(str, "FLOW2");
+ break;
+ case PM_LOG_FUNCTION:
+ sprintf(str, "FUNCTION");
+ break;
+ default:
+ sprintf(str, "???");
+ break;
+ }
+
+ if(strlen(str) > 0) {
+ MSG(NL, "%s: %s\n", str, msg);
+ }
+}
+
+/* Wrapper to fprintf() that allows to choose if we want the output
+ * to be appended on the current line, or written to a new one
+ */
+void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...)
+{
+ va_list args;
+
+ char str[LOG_STR_LEN];
+
+ if(neednl == 1 && line == NL) {
+ fprintf(stdout, "\n");
+ neednl = 0;
+ }
+
+ va_start(args, fmt);
+ vsnprintf(str, LOG_STR_LEN, fmt, args);
+ va_end(args);
+
+ fprintf(file, str);
+ fflush(file);
+
+ neednl = (str[strlen(str)-1] == 10) ? 0 : 1;
+}
+
+/* Check verbosity option and, if set, print the
+ * string to stdout
+ */
+void vprint(char *fmt, ...)
+{
+ va_list args;
+
+ if(pmo_verbose > 1) {
+ if(neednl == 1) {
+ fprintf(stdout, "\n");
+ neednl = 0;
+ }
+ va_start(args, fmt);
+ pm_fprintf(stdout, NL, fmt, args);
+ va_end(args);
+ }
+}
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/log.h b/src/pacman/log.h
new file mode 100644
index 00000000..bb982b88
--- /dev/null
+++ b/src/pacman/log.h
@@ -0,0 +1,49 @@
+/*
+ * log.h
+ *
+ * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+#ifndef _PM_LOG_H
+#define _PM_LOG_H
+
+#define MSG(line, fmt, args...) pm_fprintf(stdout, line, fmt, ##args)
+#define ERR(line, fmt, args...) do { \
+ pm_fprintf(stderr, line, "error: "); \
+ pm_fprintf(stderr, CL, fmt, ##args); \
+} while(0)
+#define DBG(line, fmt, args...) do { \
+ char str[256]; \
+ snprintf(str, 256, fmt, ##args); \
+ cb_log(PM_LOG_DEBUG, str); \
+} while(0)
+
+enum {
+ NL, /* new line */
+ CL /* current line */
+};
+
+/* callback to handle messages/notifications from pacman library */
+void cb_log(unsigned short level, char *msg);
+
+void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...);
+
+void vprint(char *fmt, ...);
+
+#endif /* _PM_LOG_H */
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index ff96cf48..0b2b9bab 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -24,19 +24,14 @@
#include <limits.h>
#include <getopt.h>
#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
#include <signal.h>
-#include <stdarg.h>
#include <mcheck.h> /* debug */
#include <alpm.h>
/* pacman */
#include "list.h"
#include "util.h"
+#include "log.h"
#include "download.h"
#include "conf.h"
#include "package.h"
@@ -88,8 +83,6 @@ list_t *pm_targets = NULL;
int maxcols = 80;
-int neednl = 0; /* for cleaner message output */
-
int main(int argc, char *argv[])
{
int ret = 0;
@@ -234,92 +227,6 @@ void cleanup(int signum)
exit(signum);
}
-/* Callback to handle notifications from the library
- */
-void cb_log(unsigned short level, char *msg)
-{
- char str[8] = "";
-
- switch(level) {
- case PM_LOG_DEBUG:
- sprintf(str, "DEBUG");
- break;
- case PM_LOG_ERROR:
- sprintf(str, "ERROR");
- break;
- case PM_LOG_WARNING:
- sprintf(str, "WARNING");
- break;
- case PM_LOG_FLOW1:
- sprintf(str, "FLOW1");
- break;
- case PM_LOG_FLOW2:
- sprintf(str, "FLOW2");
- break;
- case PM_LOG_FUNCTION:
- sprintf(str, "FUNCTION");
- break;
- default:
- sprintf(str, "???");
- break;
- }
-
- if(strlen(str) > 0) {
- MSG(NL, "%s: %s\n", str, msg);
- }
-}
-
-/* Callback to handle transaction events
- */
-void cb_trans(unsigned short event, void *data1, void *data2)
-{
- char str[256] = "";
-
- switch(event) {
- case PM_TRANS_EVT_DEPS_START:
- MSG(NL, "checking dependencies... ");
- break;
- case PM_TRANS_EVT_CONFLICTS_START:
- MSG(NL, "checking for file conflicts... ");
- break;
- case PM_TRANS_EVT_DEPS_DONE:
- case PM_TRANS_EVT_CONFLICTS_DONE:
- MSG(CL, "done.\n");
- break;
- case PM_TRANS_EVT_ADD_START:
- MSG(NL, "installing %s... ", (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
- break;
- case PM_TRANS_EVT_ADD_DONE:
- MSG(CL, "done.\n");
- snprintf(str, 256, "installed %s (%s)",
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
- alpm_logaction(str);
- break;
- case PM_TRANS_EVT_REMOVE_START:
- MSG(NL, "removing %s... ", (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
- break;
- case PM_TRANS_EVT_REMOVE_DONE:
- MSG(CL, "done.\n");
- snprintf(str, 256, "removed %s (%s)",
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
- alpm_logaction(str);
- break;
- case PM_TRANS_EVT_UPGRADE_START:
- MSG(NL, "upgrading %s... ", (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
- break;
- case PM_TRANS_EVT_UPGRADE_DONE:
- MSG(CL, "done.\n");
- snprintf(str, 256, "upgraded %s (%s -> %s)",
- (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
- (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION),
- (char *)alpm_pkg_getinfo(data2, PM_PKG_VERSION));
- alpm_logaction(str);
- break;
- }
-}
-
int pacman_deptest(list_t *targets)
{
PM_LIST *lp, *data;
@@ -645,43 +552,4 @@ char *buildstring(list_t *strlist)
return(str);
}
-/* Check verbosity option and, if set, print the
- * string to stdout
- */
-void vprint(char *fmt, ...)
-{
- va_list args;
-
- if(pmo_verbose > 1) {
- if(neednl == 1) {
- fprintf(stdout, "\n");
- neednl = 0;
- }
- va_start(args, fmt);
- pm_fprintf(stdout, NL, fmt, args);
- va_end(args);
- }
-}
-
-void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...)
-{
- va_list args;
-
- char str[256];
-
- if(neednl == 1 && line == NL) {
- fprintf(stdout, "\n");
- neednl = 0;
- }
-
- va_start(args, fmt);
- vsnprintf(str, 256, fmt, args);
- va_end(args);
-
- fprintf(file, str);
- fflush(file);
-
- neednl = (str[strlen(str)-1] == 10) ? 0 : 1;
-}
-
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/pacman.h b/src/pacman/pacman.h
index e4e99b50..fd8a5cfb 100644
--- a/src/pacman/pacman.h
+++ b/src/pacman/pacman.h
@@ -37,26 +37,6 @@
#define PM_OP_SYNC 6
#define PM_OP_DEPTEST 7
-#define MSG(line, fmt, args...) pm_fprintf(stdout, line, fmt, ##args)
-#define ERR(line, fmt, args...) do { \
- pm_fprintf(stderr, line, "error: "); \
- pm_fprintf(stderr, CL, fmt, ##args); \
-} while(0)
-#define DBG(line, fmt, args...) do { \
- char str[256]; \
- snprintf(str, 256, fmt, ##args); \
- cb_log(PM_LOG_DEBUG, str); \
-} while(0)
-
-enum {
- NL, /* new line */
- CL /* current line */
-};
-/* callback to handle messages/notifications from pacman library */
-void cb_log(unsigned short level, char *msg);
-/* callback to handle messages/notifications from pacman transactions */
-void cb_trans(unsigned short event, void *data1, void *data2);
-
void cleanup(int signum);
int pacman_deptest(list_t *targets);
@@ -64,11 +44,10 @@ int pacman_deptest(list_t *targets);
int parseargs(int argc, char **argv);
void usage(int op, char *myname);
+
void version();
char *buildstring(list_t *strlist);
-void vprint(char *fmt, ...);
-void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...);
#endif /* _PM_PACMAN_H */
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 235a8b6d..22e16b84 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -31,7 +31,7 @@
#include "package.h"
#include "db.h"
#include "query.h"
-#include "pacman.h"
+#include "log.h"
extern unsigned short pmo_q_isfile;
extern unsigned short pmo_q_info;
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 2f543106..4da11898 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -26,8 +26,9 @@
#include <alpm.h>
/* pacman */
#include "util.h"
+#include "log.h"
#include "list.h"
-#include "pacman.h"
+#include "trans.h"
extern unsigned char pmo_flags;
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 4dac47d7..86ede1cd 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -30,6 +30,7 @@
#include <alpm.h>
/* pacman */
#include "util.h"
+#include "log.h"
#include "download.h"
#include "list.h"
#include "package.h"
diff --git a/src/pacman/trans.c b/src/pacman/trans.c
new file mode 100644
index 00000000..37645e91
--- /dev/null
+++ b/src/pacman/trans.c
@@ -0,0 +1,87 @@
+/*
+ * trans.c
+ *
+ * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+
+#include <alpm.h>
+/* pacman */
+#include "log.h"
+#include "trans.h"
+
+/* Callback to handle transaction events
+ */
+void cb_trans(unsigned short event, void *data1, void *data2)
+{
+ char str[256] = "";
+
+ switch(event) {
+ case PM_TRANS_EVT_DEPS_START:
+ MSG(NL, "checking dependencies... ");
+ break;
+ case PM_TRANS_EVT_CONFLICTS_START:
+ MSG(NL, "checking for file conflicts... ");
+ break;
+ case PM_TRANS_EVT_DEPS_DONE:
+ case PM_TRANS_EVT_CONFLICTS_DONE:
+ MSG(CL, "done.\n");
+ break;
+ case PM_TRANS_EVT_ADD_START:
+ MSG(NL, "installing %s... ", (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
+ break;
+ case PM_TRANS_EVT_ADD_DONE:
+ MSG(CL, "done.\n");
+ snprintf(str, 256, "installed %s (%s)",
+ (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
+ (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
+ alpm_logaction(str);
+ break;
+ case PM_TRANS_EVT_REMOVE_START:
+ MSG(NL, "removing %s... ", (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
+ break;
+ case PM_TRANS_EVT_REMOVE_DONE:
+ MSG(CL, "done.\n");
+ snprintf(str, 256, "removed %s (%s)",
+ (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
+ (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION));
+ alpm_logaction(str);
+ break;
+ case PM_TRANS_EVT_UPGRADE_START:
+ MSG(NL, "upgrading %s... ", (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME));
+ break;
+ case PM_TRANS_EVT_UPGRADE_DONE:
+ MSG(CL, "done.\n");
+ snprintf(str, 256, "upgraded %s (%s -> %s)",
+ (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME),
+ (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION),
+ (char *)alpm_pkg_getinfo(data2, PM_PKG_VERSION));
+ alpm_logaction(str);
+ break;
+ }
+}
+
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/trans.h b/src/pacman/trans.h
new file mode 100644
index 00000000..368da617
--- /dev/null
+++ b/src/pacman/trans.h
@@ -0,0 +1,29 @@
+/*
+ * trans.h
+ *
+ * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+#ifndef _PM_TRANS_H
+#define _PM_TRANS_H
+
+/* callback to handle messages/notifications from pacman transactions */
+void cb_trans(unsigned short event, void *data1, void *data2);
+
+#endif /* _PM_TRANS_H */
+
+/* vim: set ts=2 sw=2 noet: */