*
* Licensed under the GNU Public License version 3 only, see LICENSE.
*
- * @BAKE cc -std=c89 -O2 @FILENAME -o @SHORT @ARGS @STOP
+ * @BAKE cc -std=c89 -O2 @FILENAME -o @{@SHORT} @ARGS @STOP
*/
#define _POSIX_C_SOURCE 200809L
#define START "@BAKE"
#define STOP "@STOP"
-#define EXPUNGE_START "${"
+#define EXPUNGE_START "@{"
#define EXPUNGE_STOP "}"
#define VERSION "20240404"
"\tinfluence on the normal command execution.\n" \
"\t" YELLOW "\\" RESET \
"SPECIAL_NAME will result in SPECIAL_NAME in the executed shell command.\n" \
- "\t" RED "\\\\" RESET \
- "SPECIAL NAME will result as the rule above.\n" \
- "\tThis is applicable to all meaningful symbols in Bake, it is ignored otherwise."
+ "Backslashing is applicable to all meaningful symbols in Bake, it is ignored otherwise."
#define COPYRIGHT "2023 Emil Williams"
#define LICENSE "Licensed under the GNU Public License version 3 only, see LICENSE."
return NULL;
}
-#if 0
-static string_t
-find_region(char * buf, char * findstart, char * findstop,
- char ** end) {
- char * start = find(buf, findstart, *end),
- * stop;
- size_t findstart_len = strlen(findstart);
-
- if (!start) {
- return (string_t) {
- NULL, 0
- };
- }
-
- stop = find(start + findstart_len, findstop, *end);
-
- if (!stop) {
- return (string_t) {
- NULL, 0
- };
- }
-
- *end = stop;
- return (string_t) {
- start, stop - start
- };
-}
-#endif
-
static char *
get_region(string_t m, char * findstart, char * findstop) {
char * buf = NULL, * start, * stop, * end = m.len + m.buf;
return buf;
}
-#if 0
-/* this function somehow rapes the end of the string and removes one character or it's a off by one in strip */
-static string_t *
-remove_expand(char * buf) {
- string_t * rem = malloc(sizeof(string_t));
- char * start = buf, * bend = start + strlen(buf), * end = bend;
- size_t i = 0;
-
- while (rem) {
- rem[i] = find_region(start, EXPUNGE_START, EXPUNGE_STOP, &end);
- printf("\nrem:%d %s\n", rem[i].len, rem[i]);
-
- if (rem[i].buf) {
- start += rem[i].buf - buf + end - rem[i].buf;
- rem[i].len = end - rem[i].buf - strlen(EXPUNGE_START);
- printf("\nrem:%d %s\n", rem[i].len, start);
- insert(start, "", bend - start, 0, 1);
- } else {
- break;
- }
-
- rem = realloc(rem, (1 + ++i) * sizeof(string_t));
- }
-
- expand(buf, EXPUNGE_START, "");
-
- return rem;
-}
-#endif
-
static char *
remove_expand(char * buf) {
size_t i, f, plen = 0, len = 1, end = strlen(buf);
char * l = NULL;
- /* "a\0b\0\0" */
- /* ${a} \${} ${b} -> insert at beginning of } shift 1 -> */
- /* ${a \${} ${b -> expand -> a ${} b */
for (i = 0; i < end; ++i) {
if (!strncmp(buf + i, EXPUNGE_START, strlen(EXPUNGE_START))) {
if (buf + i > buf && buf[i - 1] == '\\') {
i += strlen(EXPUNGE_START);
plen = (len != 1) * (len - 1);
len += f - i + 1;
- printf("plen: %d, len: %d\n", plen, len);
l = realloc(l, len);
memcpy(l + plen, buf + i, f - i);
l[plen + f - i] = '\0';
expand(buf, EXPUNGE_START, "");
if (l) {
- size_t i, xz = 0;
l[len - 1] = '\0';
-
- for (i = 0; i < len; ++i) {
- if (l[i] == '\0') ++xz;
- };
-
- printf("xz: %d\n", xz);
-
- printf("l: %s\n", l);
}
return l;
echo -e "\t${YELLOW}@FILENAME${NORMAL} returns target-file (abc.x.txt)"
echo -e "\t${YELLOW}@SHORT${NORMAL} returns target-file without suffix (^-> abc.x)"
echo -e "\t${YELLOW}@ARGS${NORMAL} returns ${GREEN}arguments${NORMAL}"
+ echo -e "\t${YELLOW}@{${NORMAL}${BOLD}EXPUNGE_THIS_FILE${YELLOW}}${NORMAL} inline region to delete this or many files or directories,"
+ echo -e "\tnon-recursive, only one file per block, removed from left to right. This has no\n\tinfluence on the normal command execution.\n"
}
if [[ $# -lt 1 ]]; then
line=${line//@ARGS/$@}
line=$(echo "$line" | sed 's/\W*@STOP.*//')
+ echo -e "${BOLD}${GREEN}$0${NORMAL}: ${line#*${MARK}}"
+ echo=$(echo "$line" | sed 's/@{\(.*\)\([^\\]\)}.*$/\1\2/')
command="${line#*${MARK}}"
- echo -e "${BOLD}${GREEN}$0${NORMAL}: $command"
if [[ $run -eq 1 ]]; then
echo -e "${BOLD}${GREEN}output${NORMAL}:"
sh -c "$command"