summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2007-01-18 16:52:57 +0000
committerAaron Griffin <aaron@archlinux.org>2007-01-18 16:52:57 +0000
commit86b136bb592bf576a3da950fee153f6d4f5b9d15 (patch)
treef6289e427de5c5b2cfd3e3d37b75fc9506eb3bdb /src
parent46e26ac5c8d15fbb2385ad972f2f69891a0bd8d0 (diff)
downloadpacman-86b136bb592bf576a3da950fee153f6d4f5b9d15.tar.xz
Dan McGee <dpmcgee@gmail.com>
* Removed some unnecessary headers and library links * Made things static if possible * Cleaned up makefiles a bit * Fixed some old comments in the code * Fixed some errors the static code checker splint pointed out * Backwards arguments in a memset call in _alpm_db_read (could have been worse) * Other various small fixes Other: * Default to 80 columns when getcols cannot determine display width * Removal of ._install as a valid install file in packages
Diffstat (limited to 'src')
-rw-r--r--src/pacman/Makefile.am4
-rw-r--r--src/pacman/downloadprog.c31
-rw-r--r--src/pacman/log.c8
-rw-r--r--src/pacman/package.c2
-rw-r--r--src/pacman/pacman.c17
-rw-r--r--src/pacman/sync.c6
-rw-r--r--src/pacman/trans.c2
-rw-r--r--src/pacman/util.c37
-rw-r--r--src/pacman/util.h6
9 files changed, 58 insertions, 55 deletions
diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am
index 129fbee5..d637dc2d 100644
--- a/src/pacman/Makefile.am
+++ b/src/pacman/Makefile.am
@@ -17,9 +17,9 @@ pacman_SOURCES = util.c log.c list.c package.c downloadprog.c trans.c add.c \
pacman_static_SOURCES = $(pacman_SOURCES)
pacman_LDADD = -L$(top_srcdir)/lib/libalpm/.libs \
- -ldownload -larchive -lm -lalpm -lssl -lcrypto
+ -ldownload -lm -lalpm
pacman_static_LDADD = -L$(top_srcdir)/lib/libalpm/.libs/ \
- -ldownload -larchive -lm -lalpm -lssl -lcrypto
+ -ldownload -lm -lalpm
pacman_static_LDFLAGS = $(LDFLAGS) -all-static
diff --git a/src/pacman/downloadprog.c b/src/pacman/downloadprog.c
index 16cfd6c9..29a98124 100644
--- a/src/pacman/downloadprog.c
+++ b/src/pacman/downloadprog.c
@@ -39,10 +39,10 @@
#include "conf.h"
/* progress bar */
-float rate_last;
-int xfered_last;
-struct timeval last_time;
-struct timeval initial_time;
+static float rate_last;
+static int xfered_last;
+static struct timeval last_time;
+static struct timeval initial_time;
/* pacman options */
extern config_t *config;
@@ -52,13 +52,13 @@ extern config_t *config;
void log_progress(const char *filename, int xfered, int total)
{
- static int lasthash = 0, mouth = 0;
- int i, hash;
- long chomp = 0;
+ static unsigned int lasthash = 0, mouth = 0;
+ unsigned int i, hash;
+ unsigned int chomp = 0;
char *fname, *p;
unsigned int maxcols = getcols();
unsigned int progresslen = maxcols - 57;
- int percent = ((float)xfered) / ((float)total) * 100;
+ int percent = (int)((float)xfered) / ((float)total) * 100;
struct timeval current_time;
float rate = 0.0;
unsigned int eta_h = 0, eta_m = 0, eta_s = 0;
@@ -87,17 +87,17 @@ void log_progress(const char *filename, int xfered, int total)
if(xfered == total) {
/* compute final values */
- rate = total / (total_timediff * 1024);
- eta_s = (int)total_timediff;
+ rate = (float)total / (total_timediff * 1024);
+ eta_s = (unsigned int)total_timediff;
set_output_padding(0); /* shut off padding */
} else if(timediff < UPDATE_SPEED_SEC) {
/* we avoid computing the ETA on too small periods of time, so that
results are more significant */
return;
} else {
- rate = (xfered - xfered_last) / (timediff * 1024);
- rate = (rate + 2*rate_last) / 3;
- eta_s = (total - xfered) / (rate * 1024);
+ rate = (float)(xfered - xfered_last) / (timediff * 1024);
+ rate = (float)(rate + 2*rate_last) / 3;
+ eta_s = (unsigned int)(total - xfered) / (rate * 1024);
}
rate_last = rate;
@@ -130,11 +130,12 @@ void log_progress(const char *filename, int xfered, int total)
rate = 9999.9;
}
- printf(" %-*s %6dK %#6.1fK/s %02d:%02d:%02d [", FILENAME_TRIM_LEN, fname, xfered/1024, rate, eta_h, eta_m, eta_s);
+ printf(" %-*s %6dK %#6.1fK/s %02u:%02u:%02u [", FILENAME_TRIM_LEN, fname,
+ xfered/1024, rate, eta_h, eta_m, eta_s);
free(fname);
- hash = percent*progresslen/100;
+ hash = (unsigned int)percent*progresslen/100;
for(i = progresslen; i > 0; --i) {
if(chomp) {
if(i > progresslen - hash) {
diff --git a/src/pacman/log.c b/src/pacman/log.c
index 7231545e..a7a493aa 100644
--- a/src/pacman/log.c
+++ b/src/pacman/log.c
@@ -38,8 +38,8 @@
extern config_t *config;
-int neednl = 0; /* for cleaner message output */
-int needpad = 0; /* pad blanks to terminal width */
+static int neednl = 0; /* for cleaner message output */
+static int needpad = 0; /* pad blanks to terminal width */
/* simple helper for needpad */
void set_output_padding(int on)
@@ -131,8 +131,8 @@ void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...)
fprintf(file, str);
if(needpad == 1) {
- unsigned int cols = getcols();
- for(int i=len; i < cols; ++i) {
+ unsigned int i, cols = getcols();
+ for(i=len; i < cols; ++i) {
fprintf(file, " ");
}
if(neednl == 1) {
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 33b5f7a9..b4874aaf 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -218,7 +218,7 @@ void dump_pkg_changelog(char *clfile, const char *pkgname)
{
while(!feof(fp))
{
- fgets(line, PATH_MAX, fp);
+ fgets(line, (int)PATH_MAX, fp);
printf("%s", line);
line[0] = '\0';
}
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 54612383..fa3003e2 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -72,15 +72,13 @@ enum {
PM_OP_DEPTEST
};
-config_t *config = NULL;
+config_t *config;
pmdb_t *db_local;
/* list of (sync_t *) structs for sync locations */
-list_t *pmc_syncs = NULL;
+list_t *pmc_syncs;
/* list of targets specified on command line */
-list_t *pm_targets = NULL;
-
-unsigned int maxcols = 80;
+static list_t *pm_targets;
extern int neednl;
@@ -134,8 +132,7 @@ static void usage(int op, char *myname)
printf(_(" -l, --list list the contents of the queried package\n"));
printf(_(" -m, --foreign list all packages that were not found in the sync db(s)\n"));
printf(_(" -o, --owns <file> query the package that owns <file>\n"));
- printf(_(" -p, --file pacman will query the package file [package] instead of\n"));
- printf(_(" looking in the database\n"));
+ printf(_(" -p, --file query the package file [package] instead of the database\n"));
printf(_(" -s, --search search locally-installed packages for matching strings\n"));
} else if(op == PM_OP_SYNC) {
printf(_("usage: %s {-S --sync} [options] [package]\n"), myname);
@@ -278,7 +275,7 @@ static int parseargs(int argc, char *argv[])
{0, 0, 0, 0}
};
char root[PATH_MAX];
- struct stat st = {0};
+ struct stat st;
while((opt = getopt_long(argc, argv, "ARUFQSTDYr:b:vkhscVfmnoldepiuwyg", opts, &option_index))) {
if(opt < 0) {
@@ -325,7 +322,7 @@ static int parseargs(int argc, char *argv[])
case 'b':
if(stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) {
pm_fprintf(stderr, NL, _("error: '%s' is not a valid db path\n"), optarg);
- exit(1);
+ exit(EXIT_FAILURE);
}
alpm_option_set_dbpath(optarg);
config->dbpath = alpm_option_get_dbpath(optarg);
@@ -481,7 +478,7 @@ int main(int argc, char *argv[])
} else {
ERR(NL, _("you cannot perform this operation unless you are root.\n"));
config_free(config);
- exit(1);
+ exit(EXIT_FAILURE);
}
}
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index c6eb603d..fdc0fb92 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -212,6 +212,12 @@ static int sync_synctree(int level, list_t *syncs)
if(ret < 0) {
if(pm_errno == PM_ERR_DB_SYNC) {
/* use libdownload error */
+ /* TODO breaking abstraction barrier here?
+ * pacman -> libalpm -> libdownload
+ *
+ * Yes. This will be here until we add a nice pacman "pm_errstr" or
+ * something, OR add all libdownload error codes into the pm_error enum
+ */
ERR(NL, _("failed to synchronize %s: %s\n"), sync->treename, downloadLastErrString);
} else {
ERR(NL, _("failed to update %s (%s)\n"), sync->treename, alpm_strerror(pm_errno));
diff --git a/src/pacman/trans.c b/src/pacman/trans.c
index 50e80cd6..1d003251 100644
--- a/src/pacman/trans.c
+++ b/src/pacman/trans.c
@@ -41,7 +41,7 @@
extern config_t *config;
-int prevpercent=0; /* for less progressbar output */
+static int prevpercent=0; /* for less progressbar output */
/* Callback to handle transaction events
*/
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 6d395bb1..406583d3 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -30,7 +30,6 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
@@ -52,27 +51,28 @@ extern config_t *config;
extern int neednl;
/* gets the current screen column width */
-int getcols()
+unsigned int getcols()
{
if(!isatty(1)) {
/* We will default to 80 columns if we're not a tty
* this seems a fairly standard file width.
*/
return 80;
- }
+ } else {
#ifdef TIOCGSIZE
- struct ttysize win;
- if(ioctl(1, TIOCGSIZE, &win) == 0) {
- return win.ts_cols;
- }
+ struct ttysize win;
+ if(ioctl(1, TIOCGSIZE, &win) == 0) {
+ return win.ts_cols;
+ }
#elif defined(TIOCGWINSZ)
- struct winsize win;
- if(ioctl(1, TIOCGWINSZ, &win) == 0) {
- return win.ws_col;
- }
+ struct winsize win;
+ if(ioctl(1, TIOCGWINSZ, &win) == 0) {
+ return win.ws_col;
+ }
#endif
- else {
- return -1;
+ /* If we can't figure anything out, we'll just assume 80 columns */
+ /* TODO any problems caused by this assumption? */
+ return 80;
}
/* Original envvar way - prone to display issues
const char *cenv = getenv("COLUMNS");
@@ -155,15 +155,14 @@ int rmrf(char *path)
}
return(errflag);
}
- return(0);
}
/* output a string, but wrap words properly with a specified indentation
*/
-void indentprint(const char *str, int indent)
+void indentprint(const char *str, unsigned int indent)
{
const char *p = str;
- int cidx = indent;
+ unsigned int cidx = indent;
while(*p) {
if(*p == ' ') {
@@ -178,7 +177,7 @@ void indentprint(const char *str, int indent)
len = next - p;
if(len > (getcols()-cidx-1)) {
/* newline */
- int i;
+ unsigned int i;
fprintf(stdout, "\n");
for(i = 0; i < indent; i++) {
fprintf(stdout, " ");
@@ -200,7 +199,7 @@ void indentprint(const char *str, int indent)
char *buildstring(list_t *strlist)
{
char *str;
- int size = 1;
+ size_t size = 1;
list_t *lp;
for(lp = strlist; lp; lp = lp->next) {
@@ -208,7 +207,7 @@ char *buildstring(list_t *strlist)
}
str = (char *)malloc(size);
if(str == NULL) {
- ERR(NL, _("failed to allocated %d bytes\n"), size);
+ ERR(NL, _("failed to allocate %d bytes\n"), size);
}
str[0] = '\0';
for(lp = strlist; lp; lp = lp->next) {
diff --git a/src/pacman/util.h b/src/pacman/util.h
index b1730385..763c5081 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -28,7 +28,7 @@
p = malloc(b); \
if (!(p)) { \
fprintf(stderr, "malloc failure: could not allocate %d bytes\n", (int)b); \
- exit(1); \
+ exit(EXIT_FAILURE); \
} \
} else { \
p = NULL; \
@@ -43,10 +43,10 @@
} while(0)
#define _(str) gettext(str)
-int getcols();
+unsigned int getcols();
int makepath(char *path);
int rmrf(char *path);
-void indentprint(const char *str, int indent);
+void indentprint(const char *str, unsigned int indent);
char *buildstring(list_t *strlist);
char *strtoupper(char *str);
char *strtrim(char *str);