-
-
Notifications
You must be signed in to change notification settings - Fork 80
Add this_file, this_counter, GNUremake #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: remake-4-3
Are you sure you want to change the base?
Changes from all commits
5fd18a2
0cab240
4f3c4d2
38438dd
1284d31
9d6be5e
e7e147c
039fe4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1370,6 +1370,65 @@ func_value (char *o, char **argv, const char *funcname UNUSED) | |
| return o; | ||
| } | ||
|
|
||
| ///// added by <[email protected]> | ||
|
|
||
|
|
||
| /** | ||
| $(this_file) | ||
|
|
||
| Always expands to the current Makefile path. Inspired by the __FILE__ macro of C. | ||
| **/ | ||
|
|
||
| static char * | ||
| func_this_file (char *o UNUSED, char **argv UNUSED, const char *funcname UNUSED) | ||
| { | ||
| if (reading_file) { | ||
| return xstrdup(reading_file->filenm); | ||
| } | ||
| else | ||
| return xstrdup("?"); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| $(this_line) | ||
|
|
||
| Always expands to the current line number. Inspired by the __LINE__ macro of C. | ||
| **/ | ||
|
|
||
| static char * | ||
| func_this_line (char *o UNUSED, char **argv UNUSED, const char *funcname UNUSED) | ||
| { | ||
| if (reading_file) { | ||
| char linumbuf[32]; | ||
| memset (linumbuf, 0, sizeof(linumbuf)); | ||
| snprintf(linumbuf, sizeof(linumbuf), "%lu", reading_file->lineno); | ||
| return xstrdup(linumbuf); | ||
| } | ||
| else | ||
| return xstrdup("0"); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| $(this_counter) | ||
|
|
||
| Always expands to a unique, incremented, counter. Inspired by the __COUNTER__ macro of GCC. | ||
| **/ | ||
|
|
||
| static char * | ||
| func_this_counter (char *o UNUSED, char **argv UNUSED, const char *funcname UNUSED) | ||
| { | ||
| static long counter; | ||
| char cntbuf[32]; | ||
| memset (cntbuf, 0, sizeof(cntbuf)); | ||
| counter++; | ||
| snprintf (cntbuf, sizeof(cntbuf), "%ld", counter); | ||
| return xstrdup(cntbuf); | ||
| } | ||
| ///// end of functions added by <[email protected]> | ||
|
|
||
|
|
||
| /* | ||
| \r is replaced on UNIX as well. Is this desirable? | ||
| */ | ||
|
|
@@ -2210,6 +2269,10 @@ static struct function_table_entry function_table_init[] = | |
| FT_ENTRY ("eval", 0, 1, 1, func_eval), | ||
| FT_ENTRY ("file", 1, 2, 1, func_file), | ||
| FT_ENTRY ("debugger", 0, 1, 1, func_debugger), | ||
| /// three functions added by <[email protected]> | ||
| FT_ENTRY ("this_file", 0, 0, 0, func_this_file), | ||
| FT_ENTRY ("this_line", 0, 0, 0, func_this_line), | ||
| FT_ENTRY ("this_counter", 0, 0, 0, func_this_counter), | ||
| #ifdef EXPERIMENTAL | ||
| FT_ENTRY ("eq", 2, 2, 1, func_eq), | ||
| FT_ENTRY ("not", 0, 1, 1, func_not), | ||
|
|
@@ -2236,7 +2299,10 @@ expand_builtin_function (char *o, int argc, char **argv, | |
| but so far no internal ones do, so just test it for all functions here | ||
| rather than in each one. We can change it later if necessary. */ | ||
|
|
||
| if (!argc && !entry_p->alloc_fn) | ||
| if (!argc | ||
| /// the functions named this_* by <[email protected]> take no arguments... | ||
| && strncmp(entry_p->name, "this", sizeof("this")-1) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my untrained eye There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a constant string, But |
||
| && !entry_p->alloc_fn) | ||
| return o; | ||
|
|
||
| if (!entry_p->fptr.func_ptr) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using
o = variable_buffer_outputandreturn oinstead ofxstrdupand the internal function(s) do work if adding a pseudo argument, like$(this_file fluffy).Then it's down to the handling of no-arg functions.