util: fall cleaning on single file programs
* Add a bunch of static declarations where possible * Fix void functions to be proper syntax, e.g. void func(void) * Consistency fixes (such as argv references) * Remove dead str_cmp() function from testdb * Remove unneeded config.h header includes * vercmp: remove completely unnecessary string copying Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
05f0a28932
commit
0ff2a91497
4 changed files with 19 additions and 35 deletions
|
@ -49,7 +49,7 @@ void output_cb(pmloglevel_t level, char *fmt, va_list args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void checkpkgs(alpm_list_t *pkglist)
|
static void checkpkgs(alpm_list_t *pkglist)
|
||||||
{
|
{
|
||||||
alpm_list_t *i, *j;
|
alpm_list_t *i, *j;
|
||||||
for(i = pkglist; i; i = alpm_list_next(i)) {
|
for(i = pkglist; i; i = alpm_list_next(i)) {
|
||||||
|
@ -63,7 +63,7 @@ void checkpkgs(alpm_list_t *pkglist)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkdbs(char *dbpath, alpm_list_t *dbnames) {
|
static void checkdbs(char *dbpath, alpm_list_t *dbnames) {
|
||||||
char syncdbpath[PATH_MAX];
|
char syncdbpath[PATH_MAX];
|
||||||
pmdb_t *db = NULL;
|
pmdb_t *db = NULL;
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
@ -82,14 +82,14 @@ void checkdbs(char *dbpath, alpm_list_t *dbnames) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage() {
|
static void usage(void) {
|
||||||
fprintf(stderr, "usage:\n");
|
fprintf(stderr, "usage:\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\t%s [-b <pacman db>] core extra ... : check the listed sync databases\n", BASENAME);
|
"\t%s [-b <pacman db>] core extra ... : check the listed sync databases\n", BASENAME);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *dbpath = DBPATH;
|
char *dbpath = DBPATH;
|
||||||
int a = 1;
|
int a = 1;
|
||||||
|
|
|
@ -30,11 +30,6 @@
|
||||||
|
|
||||||
#define BASENAME "testdb"
|
#define BASENAME "testdb"
|
||||||
|
|
||||||
int str_cmp(const void *s1, const void *s2)
|
|
||||||
{
|
|
||||||
return(strcmp(s1, s2));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanup(int signum) {
|
static void cleanup(int signum) {
|
||||||
if(alpm_release() == -1) {
|
if(alpm_release() == -1) {
|
||||||
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
|
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
|
||||||
|
@ -100,7 +95,7 @@ static int db_test(char *dbpath, int local)
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int checkdeps(alpm_list_t *pkglist)
|
static int checkdeps(alpm_list_t *pkglist)
|
||||||
{
|
{
|
||||||
alpm_list_t *data, *i;
|
alpm_list_t *data, *i;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -119,7 +114,7 @@ int checkdeps(alpm_list_t *pkglist)
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int checkconflicts(alpm_list_t *pkglist)
|
static int checkconflicts(alpm_list_t *pkglist)
|
||||||
{
|
{
|
||||||
alpm_list_t *data, *i;
|
alpm_list_t *data, *i;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -135,7 +130,7 @@ int checkconflicts(alpm_list_t *pkglist)
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_localdb(char *dbpath) {
|
static int check_localdb(char *dbpath) {
|
||||||
char localdbpath[PATH_MAX];
|
char localdbpath[PATH_MAX];
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
pmdb_t *db = NULL;
|
pmdb_t *db = NULL;
|
||||||
|
@ -159,7 +154,7 @@ int check_localdb(char *dbpath) {
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_syncdbs(char *dbpath, alpm_list_t *dbnames) {
|
static int check_syncdbs(char *dbpath, alpm_list_t *dbnames) {
|
||||||
char syncdbpath[PATH_MAX];
|
char syncdbpath[PATH_MAX];
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
pmdb_t *db = NULL;
|
pmdb_t *db = NULL;
|
||||||
|
@ -190,7 +185,7 @@ cleanup:
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage() {
|
static void usage(void) {
|
||||||
fprintf(stderr, "usage:\n");
|
fprintf(stderr, "usage:\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\t%s [-b <pacman db>] : check the local database\n", BASENAME);
|
"\t%s [-b <pacman db>] : check the local database\n", BASENAME);
|
||||||
|
@ -199,7 +194,7 @@ void usage() {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *dbpath = DBPATH;
|
char *dbpath = DBPATH;
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <stdio.h> /* printf */
|
#include <stdio.h> /* printf */
|
||||||
#include <stdarg.h> /* va_list */
|
#include <stdarg.h> /* va_list */
|
||||||
|
|
||||||
|
@ -26,7 +24,7 @@
|
||||||
|
|
||||||
#define BASENAME "testpkg"
|
#define BASENAME "testpkg"
|
||||||
|
|
||||||
static void output_cb(pmloglevel_t level, char *fmt, va_list args)
|
void output_cb(pmloglevel_t level, char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
if(fmt[0] == '\0') {
|
if(fmt[0] == '\0') {
|
||||||
return;
|
return;
|
||||||
|
@ -39,7 +37,7 @@ static void output_cb(pmloglevel_t level, char *fmt, va_list args)
|
||||||
vprintf(fmt, args);
|
vprintf(fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int retval = 1; /* default = false */
|
int retval = 1; /* default = false */
|
||||||
pmpkg_t *pkg = NULL;
|
pmpkg_t *pkg = NULL;
|
||||||
|
|
|
@ -18,20 +18,16 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <stdio.h> /* printf */
|
#include <stdio.h> /* printf */
|
||||||
#include <string.h> /* strncpy */
|
#include <string.h> /* strncpy */
|
||||||
|
|
||||||
#define BASENAME "vercmp"
|
#define BASENAME "vercmp"
|
||||||
|
|
||||||
#define MAX_LEN 255
|
|
||||||
|
|
||||||
/* forward declaration, comes from vercmp.o in libalpm source that is linked in
|
/* forward declaration, comes from vercmp.o in libalpm source that is linked in
|
||||||
* directly so we don't have any library deps */
|
* directly so we don't have any library deps */
|
||||||
int alpm_pkg_vercmp(const char *a, const char *b);
|
int alpm_pkg_vercmp(const char *a, const char *b);
|
||||||
|
|
||||||
static void usage()
|
static void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s <ver1> <ver2>\n\n", BASENAME);
|
fprintf(stderr, "usage: %s <ver1> <ver2>\n\n", BASENAME);
|
||||||
fprintf(stderr, "return values:\n");
|
fprintf(stderr, "return values:\n");
|
||||||
|
@ -42,8 +38,8 @@ static void usage()
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char s1[MAX_LEN] = "";
|
const char *s1 = "";
|
||||||
char s2[MAX_LEN] = "";
|
const char *s2 = "";
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if(argc == 1) {
|
if(argc == 1) {
|
||||||
|
@ -56,16 +52,11 @@ int main(int argc, char *argv[])
|
||||||
usage();
|
usage();
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
if(argc > 1) {
|
|
||||||
strncpy(s1, argv[1], MAX_LEN);
|
|
||||||
s1[MAX_LEN -1] = '\0';
|
|
||||||
}
|
|
||||||
if(argc > 2) {
|
if(argc > 2) {
|
||||||
strncpy(s2, argv[2], MAX_LEN);
|
s2 = argv[2];
|
||||||
s2[MAX_LEN -1] = '\0';
|
}
|
||||||
} else {
|
if(argc > 1) {
|
||||||
printf("0\n");
|
s1 = argv[1];
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = alpm_pkg_vercmp(s1, s2);
|
ret = alpm_pkg_vercmp(s1, s2);
|
||||||
|
|
Loading…
Add table
Reference in a new issue