diff --git a/TODO b/TODO index 0263048..9571f78 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ for release 1.0: - - beesh: add all prefix variables to autoexclude while packaging - search and fix bugs - auto-triggers to update various databases like mime/icons/mandb - handle aborted wget diff --git a/src/beecut/beecut.c b/src/beecut/beecut.c index 03131be..804880b 100644 --- a/src/beecut/beecut.c +++ b/src/beecut/beecut.c @@ -24,44 +24,60 @@ #include #define BEECUT_MAJOR 0 -#define BEECUT_MINOR 2 +#define BEECUT_MINOR 4 #define BEECUT_PATCHLVL 0 #define OPT_DELIMETER 'd' #define OPT_SHORT 's' +#define OPT_PREPEND 'p' +#define OPT_APPEND 'a' +#define OPT_NEWLINE 'n' #define OPT_VERSION 128 #define OPT_HELP 129 void print_version(void) { printf("beecut v%d.%d.%d - " - "by Marius Tolzmann 2010\n", + "by Marius Tolzmann 2010-2011\n", BEECUT_MAJOR, BEECUT_MINOR, BEECUT_PATCHLVL); } void print_full_usage(void) { - printf("usage: beecut [--delimeter=] [--short] \n\n"); - + printf("usage: beecut [options] \n\n"); + + printf("options:\n\n"); + + printf(" -d | --delimeter specify the delimeter character\n\n"); + + printf(" -s | --short output short elements\n"); + printf(" -n | --newline output each element on a seperate line\n\n"); + + printf(" -p | --prepend prepend to each output element\n"); + printf(" -a | --append append to each output element\n\n"); + printf("examples:\n\n"); - + printf(" beecut 2.4.23.0 will print '2.4.23.0 2 2.4 2.4.23 2.4.23.0'\n"); printf(" beecut -s 2.4.23.0 will print '2.4.23.0 2 4 23 0'\n"); printf(" beecut -s -d '-' a-b-c will print 'a-b-c a b c'\n\n"); } -void cut_and_print(char *string, char delimeter, char opt_short) +void cut_and_print(char *string, char delimeter, char opt_short, char opt_newline, char *prefix, char *suffix) { char *p, *s; + char nl; + + nl = opt_newline ? '\n' : ' '; p = s = string; - printf("%s", string); + printf("%s%s", prefix, string); while((p=strchr(p, delimeter))) { if(s < p) /* only print space if we have something to print */ - putchar(' '); - + printf("%s%c%s", suffix, nl, prefix); + while(s < p) putchar(*(s++)); @@ -70,7 +86,7 @@ void cut_and_print(char *string, char delimeter, char opt_short) s = (opt_short) ? p : string; } - printf(" %s", s); + printf("%s%c%s%s%s\n", suffix, nl, prefix, s, suffix); } int main(int argc, char *argv[]) @@ -80,12 +96,20 @@ int main(int argc, char *argv[]) char delimeter = '.'; - char opt_short = 0; + char opt_short = 0; + char opt_newline = 0; + char *opt_prepend = ""; + char *opt_append = opt_prepend; + struct option long_options[] = { - {"delimeter", required_argument, 0, 'd'}, - - {"short", no_argument, 0, 's'}, + {"delimeter", required_argument, 0, OPT_DELIMETER}, + + {"prepend", required_argument, 0, OPT_PREPEND}, + {"append", required_argument, 0, OPT_APPEND}, + + {"short", no_argument, 0, OPT_SHORT}, + {"newline", no_argument, 0, OPT_NEWLINE}, {"version", no_argument, 0, OPT_VERSION}, {"help", no_argument, 0, OPT_HELP}, @@ -93,35 +117,44 @@ int main(int argc, char *argv[]) {0, 0, 0, 0} }; - while ((c = getopt_long_only(argc, argv, "d:s", long_options, &option_index)) != -1) { - - if(c == OPT_DELIMETER) { - delimeter = optarg[0]; - continue; - } - - if(c == OPT_SHORT) { - opt_short = 1; - continue; - } - - if(c == OPT_HELP) { - printf("\n"); - print_version(); - printf("\n"); - print_full_usage(); - exit(0); - } - - if(c == OPT_VERSION) { - print_version(); - exit(0); + while ((c = getopt_long_only(argc, argv, "p:a:d:sn", long_options, &option_index)) != -1) { + + switch (c) { + case OPT_DELIMETER: + if (!optarg[0] || optarg[1]) { + fprintf(stderr, "invalid delimeter '%s'\n", optarg); + exit(1); + } + delimeter = optarg[0]; + break; + + case OPT_PREPEND: + opt_prepend = strdup(optarg); + break; + + case OPT_APPEND: + opt_append = strdup(optarg); + break; + + case OPT_SHORT: + opt_short = 1; + break; + + case OPT_NEWLINE: + opt_newline = 1; + break; + + case OPT_HELP: + printf("\n"); + print_version(); + printf("\n"); + print_full_usage(); + exit(0); + + case OPT_VERSION: + print_version(); + exit(0); } - - if(opterr) - continue; - - fprintf(stderr, "YOU HIT A BUG #001 opterr=%d c='%c'\n", opterr, delimeter); } /* end while getopt_long_only */ if(argc-optind < 1) { @@ -129,9 +162,9 @@ int main(int argc, char *argv[]) exit(1); } - cut_and_print(argv[optind], delimeter, opt_short); - - printf("\n"); + while(optind < argc) + cut_and_print(argv[optind++], delimeter, opt_short, + opt_newline, opt_prepend, opt_append); return(0); } diff --git a/src/beesh.sh.in b/src/beesh.sh.in index 2727c7c..5a51f73 100755 --- a/src/beesh.sh.in +++ b/src/beesh.sh.in @@ -311,7 +311,10 @@ function bee_install() { # $EXCLUDE is read from .bee file # $BEE_SKIPLIST is found in $BEEFAULTS function bee_pkg_pack() { - for e in ${EXCLUDE} ; do + + aex=$(beecut -d '/' -p '^' -a '$' -n ${BEE_AUTO_EXCLUDE} | sort -u) + + for e in ${EXCLUDE} ${aex} ; do exargs="${exargs} --exclude=${e}"; done @@ -588,8 +591,11 @@ for var in prefix eprefix bindir sbindir libexecdir sysconfdir \ sharedstatedir localstatedir libdir includedir \ datarootdir datadir infodir localedir mandir docdir ; do eval eval ${var^^}=\${${var^^}} + eval 'BEE_AUTO_EXCLUDE="${BEE_AUTO_EXCLUDE} \${${var^^}}"' done +eval "BEE_AUTO_EXCLUDE=\"${BEE_AUTO_EXCLUDE}\"" + ############################################################################### print_info "current working directory: ${PWD}"