summaryrefslogtreecommitdiff
path: root/fluid/code.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <git@matthiasm.com>2021-12-09 21:06:04 +0100
committerMatthias Melcher <git@matthiasm.com>2021-12-09 21:51:37 +0100
commitc175d1276df0c3c96799e57ed20535e547416757 (patch)
treeb13f3d8f39c09b76dfb3d30ce961b977b37527bc /fluid/code.cxx
parent0c1f78c1f2eadc464cca6861c07bd98818a79068 (diff)
STR 3210: fixing indentation of Fl_Menu_Item cnd Widget allbacks.
also added and fixed a few comments STR 3210: fixed indenting of widget callbacks. Also fixed what is considered a 'name' (could still be improved). Also better formatting inlined functions in the header.
Diffstat (limited to 'fluid/code.cxx')
-rw-r--r--fluid/code.cxx64
1 files changed, 58 insertions, 6 deletions
diff --git a/fluid/code.cxx b/fluid/code.cxx
index 005a07d1c..848f4d27c 100644
--- a/fluid/code.cxx
+++ b/fluid/code.cxx
@@ -137,6 +137,10 @@ included::~included() {
}
static included *included_root;
+/**
+ Print a formatted line to the header file, unless the same line was produced before.
+ \param[in] format printf-style formatting text, followed by a vararg list
+ */
int write_declare(const char *format, ...) {
va_list args;
char buf[1024];
@@ -164,7 +168,20 @@ int varused_test;
int varused;
/**
- Write an array of C characters (adds a null).
+ Write a C string to the code file, escaping non-ASCII characters.
+
+ Adds " before and after the text.
+
+ A list of control characters and ", ', and \\ are escaped by adding a \\ in
+ front of them. Escape ?? by wrinting ?\\?. All other characters that are not
+ between 32 and 126 inclusive will be escaped as octal characters.
+
+ This function is utf8 agnostic.
+
+ \param[in] s write this string
+ \param[in] length write so many bytes in this string
+
+ \see write_cstring(const char*)
*/
void write_cstring(const char *s, int length) {
if (varused_test) {
@@ -249,12 +266,18 @@ void write_cstring(const char *s, int length) {
}
/**
- Write a C string, quoting characters if necessary.
+ Write a C string, escaping non-ASCII characters.
+ \param[in] s write this string
+ \see write_cstring(const char*, int)
*/
-void write_cstring(const char *s) {write_cstring(s, (int)strlen(s));}
+void write_cstring(const char *s) {
+ write_cstring(s, (int)strlen(s));
+}
/**
Write an array of C binary data (does not add a null).
+ The output is bracketed in { and }. The content is written
+ as decimal bytes, i.e. `{ 1, 2, 200 }`
*/
void write_cdata(const char *s, int length) {
if (varused_test) {
@@ -289,7 +312,11 @@ void write_cdata(const char *s, int length) {
putc('}', code_file);
}
-// TODO: document me
+/**
+ Print a formatted line to the source file.
+ \param[in] format printf-style formatting text
+ \param[in] arg list of arguments
+ */
void vwrite_c(const char* format, va_list args) {
if (varused_test) {
varused = 1;
@@ -298,7 +325,10 @@ void vwrite_c(const char* format, va_list args) {
vfprintf(code_file, format, args);
}
-// TODO: document me
+/**
+ Print a formatted line to the source file.
+ \param[in] format printf-style formatting text, followed by a vararg list
+ */
void write_c(const char* format,...) {
va_list args;
va_start(args, format);
@@ -316,7 +346,10 @@ void write_cc(const char *indent, int n, const char *c, const char *com) {
write_c("%s%.*s;\n", indent, n, c);
}
-// TODO: document me
+/**
+ Print a formatted line to the header file.
+ \param[in] format printf-style formatting text, followed by a vararg list
+ */
void write_h(const char* format,...) {
if (varused_test) return;
va_list args;
@@ -335,6 +368,25 @@ void write_hc(const char *indent, int n, const char* c, const char *com) {
write_h("%s%.*s;\n", indent, n, c);
}
+/**
+ Write one or more lines of code, indenting each one of them.
+ \param[in] textlines one or more lines of text, seperated by \\n
+ */
+void write_c_indented(const char *textlines) {
+ if (textlines) {
+ indentation+=2;
+ for (;;) {
+ const char *newline = strchr(textlines, '\n');
+ if (!newline) break;
+ write_c("%s%.*s\n", indent(), (int)(newline-textlines), textlines);
+ textlines = newline+1;
+ }
+ if (*textlines)
+ write_c("%s%s", indent(), textlines);
+ indentation-=2;
+ }
+}
+
/**
Recursively dump code, putting children between the two parts of the parent code.