Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package cbonsai for openSUSE:Factory checked in at 2021-06-28 15:33:49 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/cbonsai (Old) and /work/SRC/openSUSE:Factory/.cbonsai.new.2625 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "cbonsai" Mon Jun 28 15:33:49 2021 rev:3 rq:902813 version:1.2.1 Changes: -------- --- /work/SRC/openSUSE:Factory/cbonsai/cbonsai.changes 2021-06-11 22:31:29.386215020 +0200 +++ /work/SRC/openSUSE:Factory/.cbonsai.new.2625/cbonsai.changes 2021-06-28 15:34:23.979242664 +0200 @@ -1,0 +2,6 @@ +Mon Jun 28 11:39:56 UTC 2021 - Martin Hauke <mar...@gmx.de> + +- Update to version 1.2.1 + * Update does not provide a changelog + +------------------------------------------------------------------- Old: ---- cbonsai-v1.2.0.tar.bz2 New: ---- cbonsai-v1.2.1.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ cbonsai.spec ++++++ --- /var/tmp/diff_new_pack.enBn4G/_old 2021-06-28 15:34:24.395243175 +0200 +++ /var/tmp/diff_new_pack.enBn4G/_new 2021-06-28 15:34:24.399243179 +0200 @@ -18,7 +18,7 @@ Name: cbonsai -Version: 1.2.0 +Version: 1.2.1 Release: 0 Summary: A bonsai tree generator for your terminal License: GPL-3.0-or-later ++++++ cbonsai-v1.2.0.tar.bz2 -> cbonsai-v1.2.1.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cbonsai-v1.2.0/README.md new/cbonsai-v1.2.1/README.md --- old/cbonsai-v1.2.0/README.md 2021-05-30 00:49:41.000000000 +0200 +++ new/cbonsai-v1.2.1/README.md 2021-06-28 00:10:11.000000000 +0200 @@ -108,13 +108,13 @@ This is helpful for a situations like the following: let's say you're growing a really big tree, really slowly: ```bash -$ cbonsai --screensaver --life 40 --multiplier 5 --time 20 --screensaver +$ cbonsai --life 40 --multiplier 5 --time 20 --screensaver ``` Normally, when you quite `cbonsai` (e.g. by you hitting `q` or `ctrl-c`), you would lose all progress on that tree. However, by specifying `--screensaver`, the tree is automatically saved to a cache file upon quitting. The next time you run that exact same screensaver command: ```bash -$ cbonsai --screensaver --life 40 --multiplier 5 --time 20 --screensaver +$ cbonsai --life 40 --multiplier 5 --time 20 --screensaver ``` The tree is automatically loaded from the cache file! And, since infinite mode is automatically turned on, it will finish the cached tree and just keep generating more. When you quit `cbonsai` again, the tree is once again written to the cache file for next time. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cbonsai-v1.2.0/cbonsai.c new/cbonsai-v1.2.1/cbonsai.c --- old/cbonsai-v1.2.0/cbonsai.c 2021-05-30 00:49:41.000000000 +0200 +++ new/cbonsai-v1.2.1/cbonsai.c 2021-06-28 00:10:11.000000000 +0200 @@ -12,7 +12,6 @@ #include <wchar.h> #include <ctype.h> #include <unistd.h> -#include <wordexp.h> enum branchType {trunk, shootLeft, shootRight, dying, dead}; @@ -58,6 +57,24 @@ int shootCounter; }; +void quit(struct config *conf, struct ncursesObjects *objects, int returnCode) { + // delete panels + del_panel(objects->basePanel); + del_panel(objects->treePanel); + del_panel(objects->messageBorderPanel); + del_panel(objects->messagePanel); + + // delete windows + delwin(objects->baseWin); + delwin(objects->treeWin); + delwin(objects->messageBorderWin); + delwin(objects->messageWin); + + free(conf->saveFile); + free(conf->loadFile); + exit(returnCode); +} + int saveToFile(char* fname, int seed, int branchCount) { FILE *fp = fopen(fname, "w"); @@ -103,7 +120,7 @@ saveToFile(conf->saveFile, conf->seed, myCounters->branches); } -void printHelp(const struct config *conf) { +void printHelp(void) { printf("Usage: cbonsai [OPTION]...\n"); printf("\n"); printf("cbonsai is a beautifully random bonsai tree generator.\n"); @@ -111,10 +128,10 @@ printf("Options:\n"); printf(" -l, --live live mode: show each step of growth\n"); printf(" -t, --time=TIME in live mode, wait TIME secs between\n"); - printf(" steps of growth (must be larger than 0) [default: %.2f]\n", conf->timeStep); + printf(" steps of growth (must be larger than 0) [default: 0.03]\n"); printf(" -i, --infinite infinite mode: keep growing trees\n"); printf(" -w, --wait=TIME in infinite mode, wait TIME between each tree\n"); - printf(" generation [default: %.2f]\n", conf->timeWait); + printf(" generation [default: 4.00]\n"); printf(" -S, --screensaver screensaver mode; equivalent to -li and\n"); printf(" quit on any keypress\n"); printf(" -m, --message=STR attach message next to the tree\n"); @@ -122,12 +139,12 @@ printf(" -c, --leaf=LIST list of comma-delimited strings randomly chosen\n"); printf(" for leaves\n"); printf(" -M, --multiplier=INT branch multiplier; higher -> more\n"); - printf(" branching (0-20) [default: %i]\n", conf->multiplier); - printf(" -L, --life=INT life; higher -> more growth (0-200) [default: %i]\n", conf->lifeStart); + printf(" branching (0-20) [default: 5]\n"); + printf(" -L, --life=INT life; higher -> more growth (0-200) [default: 32]\n"); printf(" -p, --print print tree to terminal when finished\n"); printf(" -s, --seed=INT seed random number generator\n"); - printf(" -W, --save=FILE save progress to file [default: %s]\n", conf->saveFile); - printf(" -C, --load=FILE load progress from file [default: %s]\n", conf->loadFile); + printf(" -W, --save=FILE save progress to file [default: $XDG_CACHE_HOME/cbonsai or $HOME/.cache/cbonsai]\n"); + printf(" -C, --load=FILE load progress from file [default: $XDG_CACHE_HOME/cbonsai]\n"); printf(" -v, --verbose increase output verbosity\n"); printf(" -h, --help show help \n"); } @@ -214,11 +231,12 @@ void roll(int *dice, int mod) { *dice = rand() % mod; } // check for key press -void checkKeyPress(const struct config *conf, struct counters *myCounters) { +int checkKeyPress(const struct config *conf, struct counters *myCounters) { if ((conf->screensaver && wgetch(stdscr) != ERR) || (wgetch(stdscr) == 'q')) { finish(conf, myCounters); - exit(0); + return 1; } + return 0; } // display changes @@ -386,7 +404,7 @@ return branchStr; } -void branch(const struct config *conf, struct ncursesObjects *objects, struct counters *myCounters, int y, int x, enum branchType type, int life) { +void branch(struct config *conf, struct ncursesObjects *objects, struct counters *myCounters, int y, int x, enum branchType type, int life) { myCounters->branches++; int dx = 0; int dy = 0; @@ -394,7 +412,9 @@ int shootCooldown = conf->multiplier; while (life > 0) { - checkKeyPress(conf, myCounters); + if (checkKeyPress(conf, myCounters) == 1) + quit(conf, objects, 0); + life--; // decrement remaining life counter age = conf->lifeStart - life; @@ -658,7 +678,7 @@ drawMessage(conf, objects, conf->message); } -void growTree(const struct config *conf, struct ncursesObjects *objects, struct counters *myCounters) { +void growTree(struct config *conf, struct ncursesObjects *objects, struct counters *myCounters) { int maxY, maxX; getmaxyx(objects->treeWin, maxY, maxX); @@ -725,23 +745,40 @@ printf("\033[0m\n"); } -// find homedir for default file location -void expandWords(char **input) { - wordexp_t exp_result; - wordexp(*input, &exp_result, 0); - - if (exp_result.we_wordc < 1) { - printf("error: could not parse filename: %s\n", *input); - return; +char* createDefaultCachePath(void) { + char* result; + size_t envlen; + char* toAppend; + + // follow XDG Base Directory Specification for default cache file path + const char* env_XDG_CACHE_HOME = getenv("XDG_CACHE_HOME"); + if (env_XDG_CACHE_HOME && (envlen = strlen(env_XDG_CACHE_HOME))) { + toAppend = "/cbonsai"; + + // create result buffer + result = malloc(envlen + strlen(toAppend) + 1); + strncpy(result, env_XDG_CACHE_HOME, envlen); + strcpy(result + envlen, toAppend); + return result; } - char* result = exp_result.we_wordv[0]; - - size_t bufsize = (strlen(result)*sizeof(char)) + sizeof(char); - *input = (char *) malloc(bufsize); - strncpy(*input, result, bufsize - 1); + // if we don't have $XDG_CACHE_HOME, try $HOME + const char* env_HOME = getenv("HOME"); + if (env_HOME && (envlen = strlen(env_HOME))) { + toAppend = "/.cache/cbonsai"; + + // create result buffer + result = malloc(envlen + strlen(toAppend) + 1); + strncpy(result, env_HOME, envlen); + strcpy(result + envlen, toAppend); + return result; + } - wordfree(&exp_result); + // if we also don't have $HOME, just use ./cbonsai + toAppend = "cbonsai"; + result = malloc(strlen(toAppend) + 1); + strcpy(result, toAppend); + return result; } int main(int argc, char* argv[]) { @@ -767,8 +804,8 @@ .message = NULL, .leaves = {0}, - .saveFile = "~/.cache/cbonsai", - .loadFile = "~/.cache/cbonsai", + .saveFile = createDefaultCachePath(), + .loadFile = createDefaultCachePath(), }; struct option long_options[] = { @@ -807,11 +844,11 @@ if (strtold(optarg, NULL) != 0) conf.timeStep = strtod(optarg, NULL); else { printf("error: invalid step time: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } if (conf.timeStep < 0) { printf("error: invalid step time: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } break; case 'i': @@ -821,11 +858,11 @@ if (strtold(optarg, NULL) != 0) conf.timeWait = strtod(optarg, NULL); else { printf("error: invalid wait time: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } if (conf.timeWait < 0) { printf("error: invalid wait time: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } break; case 'S': @@ -833,9 +870,7 @@ conf.infinite = 1; conf.save = 1; - expandWords(&conf.saveFile); conf.load = 1; - expandWords(&conf.loadFile); conf.screensaver = 1; break; @@ -846,7 +881,7 @@ if (strtold(optarg, NULL) != 0) conf.baseType = strtod(optarg, NULL); else { printf("error: invalid base index: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } break; case 'c': @@ -857,22 +892,22 @@ if (strtold(optarg, NULL) != 0) conf.multiplier = strtod(optarg, NULL); else { printf("error: invalid multiplier: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } if (conf.multiplier < 0) { printf("error: invalid multiplier: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } break; case 'L': if (strtold(optarg, NULL) != 0) conf.lifeStart = strtod(optarg, NULL); else { printf("error: invalid initial life: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } if (conf.lifeStart < 0) { printf("error: invalid initial life: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } break; case 'p': @@ -882,28 +917,38 @@ if (strtold(optarg, NULL) != 0) conf.seed = strtod(optarg, NULL); else { printf("error: invalid seed: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } if (conf.seed < 0) { printf("error: invalid seed: '%s'\n", optarg); - exit(1); + quit(&conf, &objects, 1); } break; case 'W': // skip argument if it's actually an option if (optarg[0] == '-') optind -= 1; - else conf.saveFile = optarg; + else { + free(conf.saveFile); + size_t bufsize = strlen(optarg) + 1; + conf.saveFile = malloc(bufsize); + strncpy(conf.saveFile, optarg, bufsize - 1); + conf.saveFile[bufsize - 1] = '\0'; + } conf.save = 1; - expandWords(&conf.saveFile); break; case 'C': // skip argument if it's actually an option if (optarg[0] == '-') optind -= 1; - else conf.loadFile = optarg; + else { + free(conf.loadFile); + size_t bufsize = strlen(optarg) + 1; + conf.loadFile = malloc(bufsize); + strncpy(conf.loadFile, optarg, bufsize - 1); + conf.loadFile[bufsize - 1] = '\0'; + } conf.load = 1; - expandWords(&conf.loadFile); break; case 'v': conf.verbosity++; @@ -914,15 +959,13 @@ switch (optopt) { case 'W': conf.save = 1; - expandWords(&conf.saveFile); break; case 'C': conf.load = 1; - expandWords(&conf.loadFile); break; default: printf("error: option requires an argument -- '%c'\n", optopt); - printHelp(&conf); + printHelp(); return 0; break; } @@ -931,12 +974,12 @@ // invalid option was given case '?': printf("error: invalid option -- '%c'\n", optopt); - printHelp(&conf); + printHelp(); return 0; break; case 'h': - printHelp(&conf); + printHelp(); return 0; break; } @@ -965,7 +1008,8 @@ if (conf.load) conf.targetBranchCount = 0; if (conf.infinite) { timeout(conf.timeWait * 1000); - checkKeyPress(&conf, &myCounters); + if (checkKeyPress(&conf, &myCounters) == 1) + quit(&conf, &objects, 0); // seed random number generator srand(time(NULL)); @@ -987,11 +1031,5 @@ finish(&conf, &myCounters); } - // free window memory - delwin(objects.baseWin); - delwin(objects.treeWin); - delwin(objects.messageBorderWin); - delwin(objects.messageWin); - - return 0; + quit(&conf, &objects, 0); }