summaryrefslogtreecommitdiff
path: root/fluid/code.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2023-10-26 14:41:33 +0200
committerMatthias Melcher <github@matthiasm.com>2023-10-26 14:41:33 +0200
commit8663b867497de6d370b9c8376c4bdfc909744663 (patch)
treed35fabe5132a6a392641fa62ebf815400d28a8c2 /fluid/code.cxx
parent19d1e3f1953bf7777dfcb5f2789f7cd1fcff2b43 (diff)
FLUID: Fixes compile time error and docs.
Diffstat (limited to 'fluid/code.cxx')
-rw-r--r--fluid/code.cxx44
1 files changed, 24 insertions, 20 deletions
diff --git a/fluid/code.cxx b/fluid/code.cxx
index 16999ec99..ed9046b3c 100644
--- a/fluid/code.cxx
+++ b/fluid/code.cxx
@@ -931,7 +931,7 @@ void Fd_Code_Writer::tag(int type, unsigned short uid) {
}
unsigned long Fd_Code_Writer::block_crc(const void *data, int n, unsigned long in_crc, bool *inout_line_start) {
- if (!data) return;
+ if (!data) return 0;
if (n==-1) n = (int)strlen((const char*)data);
bool line_start = true;
if (inout_line_start) line_start = *inout_line_start;
@@ -1022,8 +1022,11 @@ static Fl_String unindent_block(FILE *f, long start, long end) {
long here = ::ftell(f);
::fseek(f, start, SEEK_SET);
char *block = (char*)::malloc(bsize+1);
- (void)fread(block, bsize, 1, f);
- block[bsize] = 0;
+ size_t n = ::fread(block, bsize, 1, f);
+ if (n!=1)
+ block[0] = 0; // read error
+ else
+ block[bsize] = 0;
unindent(block);
Fl_String str = block;
::free(block);
@@ -1042,36 +1045,37 @@ static Fl_String unindent_block(FILE *f, long start, long end) {
Merge external changes in a source code file back into the current project.
This experimental function reads a source code file line by line. When it
- encounters a special tag in a line, the crc32 stored in the line is compared
- to the crc32 that was calculate from the code lines since the previous tag.
+ encounters a special tag in a line, the crc32 stored in the tag is compared
+ to the crc32 that was calculated from the code lines since the previous tag.
- If the crc's differ, the user has modified the source file, and the given block
- differs from the block as it was generated by FLUID. Depending on the block
- type, the user has modified the widget code (FD_TAG_GENERIC), which can not be
- transferred back into the project.
+ If the crc's differ, the user has modified the source file externally, and the
+ given block differs from the block as it was generated by FLUID. Depending on
+ the block type, the user has modified the widget code (FD_TAG_GENERIC), which
+ can not be transferred back into the project.
Modifications to code blocks and callbacks (CODE, CALLBACK) can be merged back
into the project. Their corresponding Fl_Type is found using the unique
- node id that is part of the tag.
+ node id that is part of the tag. The block is only merged back if the crc's
+ from the project and from the edited block differ.
The caller must make sure that this code file was generated by the currently
loaded project.
- Since this is an experimental function, the user is informed in detailed
- dialogs what the function discovered, and FLUID offers the option to merge
- or cancel to the user. Just in case this function is destructive, "undo"
- restores the state before a MergeBack.
+ The user is informed in detailed dialogs what the function discovered and
+ offered to merge or cancel if appropriate. Just in case this function is
+ destructive, "undo" restores the state before a MergeBack.
Callers can set different task. FD_MERGEBACK_CHECK checks if there are any
modifications in the code file and returns -1 if there was an error, or a
- bit field where bit 0 is set if internal structures were modified, bit 1 or
- bit 2 if code blocks or callbacks were changed, and bit 3 if modified blocks
- were found, but no Type node.
+ bit field where bit 0 is set if internal structures were modified, bit 1 if
+ code was changed, and bit 2 if modified blocks were found, but no Type node.
+ Bit 3 is set, if code was changed in the code file *and* the project.
FD_MERGEBACK_INTERACTIVE checks for changes and presents a status dialog box
to the user if there were conflicting changes or if a mergeback is possible,
- presenting the user a list of options. Returns 0 if nothing changed, and 1 if
- the user merged changes back. -1 is returned if an invalid tag was found.
+ presenting the user the option to merge or cancel. Returns 0 if the project
+ remains unchanged, and 1 if the user merged changes back. -1 is returned if an
+ invalid tag was found.
FD_MERGEBACK_GO merges all changes back into the project without any
interaction. Returns 0 if nothing changed, and 1 if it merged any changes back.
@@ -1150,7 +1154,6 @@ int Fd_Code_Writer::merge_back(const char *s, int task) {
}
}
} else {
- bool find_node = false;
if (type==FD_TAG_MENU_CALLBACK || type==FD_TAG_WIDGET_CALLBACK) {
Fl_Type *tp = Fl_Type::find_by_uid(uid);
if (tp && tp->is_true_widget()) {
@@ -1201,6 +1204,7 @@ int Fd_Code_Writer::merge_back(const char *s, int task) {
if (num_changed_structure) ret |= 1;
if (num_changed_code) ret |= 2;
if (num_uid_not_found) ret |= 4;
+ if (num_possible_override) ret |= 8;
break;
} else if (task==FD_MERGEBACK_INTERACTIVE) {
if (tag_error) {