Skip to content

Commit

Permalink
Merge branch 'auto-exclude-prefix-vars'
Browse files Browse the repository at this point in the history
* auto-exclude-prefix-vars:
  TODO: removed auto-exclude TODO
  beesh: auto exclude splitted prefix variables
  beecut: bump version to 0.4.0
  beecut: added --newline to print each element on a seperate line
  beecut: accept more than one argument
  beecut: cleanup option definitions
  beecut: added --append and --prepend
  beecut: fixed handling of options
  • Loading branch information
mariux committed Jul 7, 2011
2 parents 731738d + 03c79b2 commit 2f2a439
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 47 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -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
Expand Down
123 changes: 78 additions & 45 deletions src/beecut/beecut.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,60 @@
#include <ctype.h>

#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 <tolzmann@molgen.mpg.de> 2010\n",
"by Marius Tolzmann <tolzmann@molgen.mpg.de> 2010-2011\n",
BEECUT_MAJOR, BEECUT_MINOR, BEECUT_PATCHLVL);
}

void print_full_usage(void)
{
printf("usage: beecut [--delimeter=<delimchar>] [--short] <string>\n\n");

printf("usage: beecut [options] <string>\n\n");

printf("options:\n\n");

printf(" -d | --delimeter <char> 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 <string> prepend <string> to each output element\n");
printf(" -a | --append <string> append <string> 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++));

Expand All @@ -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[])
Expand All @@ -80,58 +96,75 @@ 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},

{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) {
print_full_usage();
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);
}
8 changes: 7 additions & 1 deletion src/beesh.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 2f2a439

Please sign in to comment.