Bladeren bron

nodebug and doc

tags/v20240404
Chad C. Starz 1 maand geleden
bovenliggende
commit
35b8abdb82
Geen bekende sleutel gevonden voor deze handtekening in de database GPG sleutel-ID: CEEBC9208C287297
3 gewijzigde bestanden met toevoegingen van 15 en 78 verwijderingen
  1. +8
    -0
      bake.1
  2. +3
    -77
      bake.c
  3. +4
    -1
      shake

+ 8
- 0
bake.1 Bestand weergeven

@@ -36,6 +36,14 @@ returns target\-file without suffix (abc.x.txt \-> abc.x)
.B $+
returns
.B arguments

.PP
Additional Features And Notes

\fB@{\fPEXPUNGE_THIS_FILE\fB}\fP is a inline block to delete files or directories, non-recursive, only one file per block, removed from left to right. Has no influence on the normal command execution.

\\SPECIAL_NAME will result in SPECIAL_NAME in the executed shell command. Backslashes are applicable to all symbols used by Bake, they are ignored otherwise.

.SH EXAMPLE
.\" SRC BEGIN (example.c)
.EX


+ 3
- 77
bake.c Bestand weergeven

@@ -3,7 +3,7 @@
*
* 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
@@ -29,7 +29,7 @@
#define START "@BAKE"
#define STOP "@STOP"

#define EXPUNGE_START "${"
#define EXPUNGE_START "@{"
#define EXPUNGE_STOP "}"

#define VERSION "20240404"
@@ -53,9 +53,7 @@
"\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."
@@ -160,35 +158,6 @@ find(char * buf, char * x, char * end) {
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;
@@ -377,44 +346,11 @@ bake_expand(char * buf, char * filename, int argc, char ** argv) {
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] == '\\') {
@@ -431,7 +367,6 @@ remove_expand(char * buf) {
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';
@@ -449,16 +384,7 @@ stop:
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;


+ 4
- 1
shake Bestand weergeven

@@ -29,6 +29,8 @@ usage() {
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
@@ -79,8 +81,9 @@ if [[ -n $line ]]; 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"


Laden…
Annuleren
Opslaan