1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
//
// MergeBack header for the Fast Light Tool Kit (FLTK).
//
// Copyright 2023-2025 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
// https://www.fltk.org/bugs.php
//
#ifndef FLUID_PROJ_MERGEBACK_H
#define FLUID_PROJ_MERGEBACK_H
#include <FL/fl_attr.h>
#include <stdint.h>
#include <stdio.h>
#include <string>
namespace fld {
class Project;
namespace proj {
/** Class that implements the MergeBack functionality.
\see merge_back(const std::string &s, int task)
*/
enum {
FLD_MERGEBACK_TAG_GENERIC = 0,
FLD_MERGEBACK_TAG_CODE,
FLD_MERGEBACK_TAG_MENU_CALLBACK,
FLD_MERGEBACK_TAG_WIDGET_CALLBACK,
FLD_MERGEBACK_TAG_UNUSED_
};
enum {
FLD_MERGEBACK_TASK_ANALYSE = 0,
FLD_MERGEBACK_TASK_INTERACTIVE,
FLD_MERGEBACK_TASK_APPLY,
FLD_MERGEBACK_TASK_APPLY_IF_SAFE = 3
};
class Mergeback
{
public:
typedef int Tag;
typedef int Task;
enum Feedback { QUIET = 0, CHATTY = 1 };
protected:
/// Apply mergeback for this project.
Project &proj_;
/// Pointer to the C++ code file.
FILE *code;
/// Current line number in the C++ code file.
int line_no;
/// Set if there was an error reading a tag.
int tag_error;
/// Number of code blocks that were different than the CRC in their tag.
int num_changed_code;
/// Number of generic structure blocks that were different than the CRC in their tag.
int num_changed_structure;
/// Number of code block that were modified, but a type node by that uid was not found.
int num_uid_not_found;
/// Number of modified code block where the corresponding project block also changed.
int num_possible_override;
void unindent(char *s);
std::string read_and_unindent_block(long start, long end);
void analyse_callback(unsigned long code_crc, unsigned long tag_crc, int uid);
void analyse_code(unsigned long code_crc, unsigned long tag_crc, int uid);
int apply_callback(long block_end, long block_start, unsigned long code_crc, int uid);
int apply_code(long block_end, long block_start, unsigned long code_crc, int uid);
static uint32_t decode_trichar32(const char *text);
static void print_trichar32(FILE *out, uint32_t value);
static const char *find_mergeback_tag(const char *line);
static bool read_tag(const char *tag, Tag *prev_type, uint16_t *uid, uint32_t *crc);
public:
Mergeback(Project &proj);
~Mergeback();
int merge_back(const std::string &s, const std::string &p, Task task);
int ask_user_to_merge(const std::string &s, const std::string &p);
int analyse();
int apply();
static void print_tag(FILE *out, Tag prev_type, Tag next_type, uint16_t uid, uint32_t crc);
};
extern int merge_back(const std::string &s, const std::string &p, int task);
} // namespace proj
} // namespace fld
extern void start_auto_mergeback();
extern void mergeback_on_load();
#endif // FLUID_PROJ_MERGEBACK_H
|