Relocated log and transaction stuffs from pacman.c to log.c and trans.c
This commit is contained in:
parent
4b272ae5b6
commit
0709c15543
|
@ -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 \
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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: */
|
|
@ -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: */
|
|
@ -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: */
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <alpm.h>
|
||||
/* pacman */
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "download.h"
|
||||
#include "list.h"
|
||||
#include "package.h"
|
||||
|
|
|
@ -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: */
|
|
@ -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: */
|
Loading…
Reference in New Issue