diff --git a/Makefile b/Makefile index 514b753..096caa1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ BEE_VERSION = 1.2.24 CC=gcc -CFLAGS=-Wall -g +CFLAGS=-Wall -Wextra -Wno-override-init -Werror -g -O3 LDFLAGS= PREFIX = /usr diff --git a/src/bee_version_compare.c b/src/bee_version_compare.c index 43824b8..6514fe8 100644 --- a/src/bee_version_compare.c +++ b/src/bee_version_compare.c @@ -28,86 +28,40 @@ #include "bee_version.h" -int compare_version_strings(char *v1, char *v2) { - char *a, *b; - long long i,j; - assert(v1); - assert(v2); - - a = v1; - b = v2; - - while(*a && *b && *a == *b) { - a++; - b++; - - if (*a == *b) +// '2.23.2' > '2.23.0' +//' 2.23.10' > '2.23.8' +// '2.23.001' == '2.23.1' +// '2.23.1001' > '2.23.101' + +static int compare_version_strings(char *a, char *b) { + while (1) { + + if (isdigit(*a) && isdigit (*b)) { + long i_a = atoll(a); + long i_b = atoll(b); + if (i_a < i_b) + return -1; + if (i_a > i_b) + return 1; + while(isdigit(*a)) + a++; + while(isdigit(*b)) + b++; continue; - - /* skip leading zeros of numbers != 0 */ - if (isdigit(*a) && isdigit(*b)) { - char *c; - - for (c=a; *c == '0'; c++) - ; - if (isdigit(*c)) - a = c; - - for (c=b; *c == '0'; c++) - ; - if (isdigit(*c)) - b = c; - } - } - - /* strings are equal ; *a==*b==0*/ - if(*a == *b) - return(0); - - if(isdigit(*a)) { - if(isdigit(*b)) { - /* rewind string to first digit */ - /* e.g. to compare 12 vs 100 and not 2 vs 00 */ - while(a > v1 && isdigit(*(a-1)) && - b > v2 && isdigit(*(b-1))) { - a--; - b--; - } - i = atoll(a); - j = atoll(b); - - if(ij) - return(1); - - /* numbers are equal but strings are not? */ - /* yes -> leading zeros: atoll("01") == atoll("1") */ - return(0); } - /* a > ('.',alpha, 0) */ - return(1); - } - if(isalpha(*a)) { + if (*a < *b) + return -1; + if (*a > *b) + return 1; - /* alpha < digit */ - if(isdigit(*b)) - return(-1); + if (*a == '\0') // implies *b == '\0', too + return 0; - if(isalpha(*b)) { - if(*a < *b) - return(-1); - return(1); - } - return(1); + a++; + b++; } - - if(! *b) - return(1); - - return(-1); } int compare_beepackage_names(struct beeversion *v1, struct beeversion *v2) { diff --git a/src/bee_version_compare.h b/src/bee_version_compare.h index 5af38ef..3a333fb 100644 --- a/src/bee_version_compare.h +++ b/src/bee_version_compare.h @@ -24,7 +24,6 @@ #include "bee_version.h" -int compare_version_strings(char *v1, char *v2); int compare_beepackage_names(struct beeversion *v1, struct beeversion *v2); int compare_beeversions(struct beeversion *v1, struct beeversion *v2); int compare_beepackages(struct beeversion *v1, struct beeversion *v2); diff --git a/src/bee_version_output.c b/src/bee_version_output.c index aa67df5..26443ac 100644 --- a/src/bee_version_output.c +++ b/src/bee_version_output.c @@ -156,6 +156,7 @@ void print_format(char* s, struct beeversion *v, char *filter_pkgfullname) p++; continue; } + // fall through default: printf("%%%c", *p); break; diff --git a/src/beeflock.c b/src/beeflock.c index f663a0f..95bcb1a 100644 --- a/src/beeflock.c +++ b/src/beeflock.c @@ -66,7 +66,7 @@ void usage(void) #define BEEFLOCK_UNLOCK LOCK_UN #define BEEFLOCK_NOBLOCK LOCK_NB -int bee_flock_fd(int fd, int operation, int flags) +int bee_flock_fd(int fd, int operation) { int res; @@ -123,7 +123,7 @@ int bee_flock_close(int fd) return res; } -int bee_flock(char *filename, int operation, int flags) +int bee_flock(char *filename, int operation) { int res; int fd, fd2; @@ -134,7 +134,7 @@ int bee_flock(char *filename, int operation, int flags) return -1; while (1) { - res = bee_flock_fd(fd, operation, 0); + res = bee_flock_fd(fd, operation); if (res < 0) return -1; @@ -169,7 +169,7 @@ int bee_flock(char *filename, int operation, int flags) } -int bee_execute_command(char *command[], int flags) +int bee_execute_command(char *command[]) { pid_t fpid, wpid; int wstatus; @@ -265,12 +265,12 @@ int main(int argc, char *argv[]) BEE_EXIT(OSERR); } - fd = bee_flock(lockfilename, operation, 0); + fd = bee_flock(lockfilename, operation); if (fd < 0) { BEE_EXIT(SOFTWARE); } - res = bee_execute_command(command, 0); + res = bee_execute_command(command); bee_flock_close(fd); if (res < 0) { BEE_EXIT(SOFTWARE); diff --git a/src/beegetopt.c b/src/beegetopt.c index c82acf1..8889b81 100644 --- a/src/beegetopt.c +++ b/src/beegetopt.c @@ -114,6 +114,7 @@ int main(int argc, char *argv[]) switch(opt) { case 'V': printf("beegetopt Vx.x\n"); + // fall through case 'h': usage(); exit(0); diff --git a/src/beesep.c b/src/beesep.c index e7aaa60..1e13135 100644 --- a/src/beesep.c +++ b/src/beesep.c @@ -70,7 +70,7 @@ static void print_escaped(char *s, size_t n) bee_fprint(stdout, "'"); - while ((c = strchr(s, '\'')) && c - s < n) { + while ((c = strchr(s, '\'')) && c < s + n) { if (c-s) bee_fnprint(stdout, c - s, s); bee_fprint(stdout, "'\\''"); diff --git a/src/beesort.c b/src/beesort.c index b8fa6b4..69fe110 100644 --- a/src/beesort.c +++ b/src/beesort.c @@ -61,6 +61,7 @@ int my_compare_data(void *a, void *b) void my_print(void *key, void *data) { + (void)key; fputs(data, stdout); }