summaryrefslogtreecommitdiff
path: root/fluid/io/Code_Writer.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'fluid/io/Code_Writer.cxx')
-rw-r--r--fluid/io/Code_Writer.cxx67
1 files changed, 40 insertions, 27 deletions
diff --git a/fluid/io/Code_Writer.cxx b/fluid/io/Code_Writer.cxx
index 0998ed287..357db80dd 100644
--- a/fluid/io/Code_Writer.cxx
+++ b/fluid/io/Code_Writer.cxx
@@ -302,14 +302,14 @@ void Code_Writer::write_cstring(const char *s, int length) {
}
// if we are rendering to the source code preview window, and the text is
// longer than four lines, we only render a placeholder.
- if (write_codeview && ((s==nullptr) || (length>300))) {
+ if (write_codeview && ((s==0) || (length>300))) {
if (length>=0)
crc_printf("\" ... %d bytes of text... \"", length);
else
crc_puts("\" ... text... \"");
return;
}
- if (length==-1 || s==nullptr) {
+ if (length==-1 || s==0) {
crc_puts("\n#error string not found\n");
crc_puts("\" ... undefined size text... \"");
return;
@@ -639,7 +639,7 @@ Node* Code_Writer::write_code(Node* p) {
}
write_h("};\n");
- current_widget_class = nullptr;
+ current_widget_class = 0;
} else {
for (q = p->next; q && q->level > p->level;) q = write_code(q);
// write all code that come after the children
@@ -667,8 +667,8 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
write_codeview = to_codeview;
unique_id_list.clear();
indentation = 0;
- current_class = nullptr;
- current_widget_class = nullptr;
+ current_class = 0;
+ current_widget_class = 0;
if (!s) code_file = stdout;
else {
FILE *f = fl_fopen(s, "wb");
@@ -683,11 +683,16 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
}
// Remember the last code file location for MergeBack
if (s && proj_.write_mergeback_data && !to_codeview) {
- std::string filename = proj_.projectfile_path() + proj_.projectfile_name();
- int i, n = (int)filename.size();
+ char filename[FL_PATH_MAX];
+ char path_buf[FL_PATH_MAX];
+ int i, n;
+ proj_.projectfile_path(path_buf, FL_PATH_MAX);
+ const char *pname = proj_.projectfile_name();
+ snprintf(filename, FL_PATH_MAX, "%s%s", path_buf, pname ? pname : "");
+ n = (int)strlen(filename);
for (i=0; i<n; i++) if (filename[i]=='\\') filename[i] = '/';
Fl_Preferences build_records(Fl_Preferences::USER_L, "fltk.org", "fluid-build");
- Fl_Preferences path(build_records, filename.c_str());
+ Fl_Preferences path(build_records, filename);
path.set("code", s);
}
// if the first entry in the Type tree is a comment, then it is probably
@@ -723,16 +728,18 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
//
// To make the include guard consistent across l=platforms, it can be
// explicitly set by the user in the Project Settings.
- std::string macro_name_str = proj_.include_guard;
- if (macro_name_str.empty()) {
- char macro_name[1024];
- char *mp = macro_name;
- char *mp_end = macro_name + sizeof(macro_name) - 16;
- std::string header_name;
+ char macro_name_str[1024];
+ const char *guard = proj_.include_guard();
+ if (guard && guard[0]) {
+ strlcpy(macro_name_str, guard, sizeof(macro_name_str));
+ } else {
+ char *mp = macro_name_str;
+ char *mp_end = macro_name_str + sizeof(macro_name_str) - 16;
+ char header_name[FL_PATH_MAX];
const char* a = 0;
if (write_codeview) {
- header_name = proj_.headerfile_name();
- a = header_name.c_str();
+ proj_.headerfile_name(header_name, FL_PATH_MAX);
+ a = header_name;
} else {
a = fl_filename_name(t);
}
@@ -755,10 +762,9 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
a += len;
}
*mp = 0;
- macro_name_str = macro_name;
}
- fprintf(header_file, "#ifndef %s\n", macro_name_str.c_str());
- fprintf(header_file, "#define %s\n", macro_name_str.c_str());
+ fprintf(header_file, "#ifndef %s\n", macro_name_str);
+ fprintf(header_file, "#define %s\n", macro_name_str);
}
if (proj_.avoid_early_includes==0) {
@@ -767,10 +773,13 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
if (t && proj_.include_H_from_C) {
if (to_codeview) {
write_c("#include \"CodeView.h\"\n");
- } else if (proj_.header_file_name[0] == '.' && strchr(proj_.header_file_name.c_str(), '/') == nullptr) {
- write_c("#include \"%s\"\n", fl_filename_name(t));
} else {
- write_c("#include \"%s\"\n", proj_.header_file_name.c_str());
+ const char *hfn = proj_.header_file_name();
+ if (hfn && hfn[0] == '.' && strchr(hfn, '/') == 0) {
+ write_c("#include \"%s\"\n", fl_filename_name(t));
+ } else {
+ write_c("#include \"%s\"\n", hfn ? hfn : "");
+ }
}
}
std::string loc_include, loc_conditional;
@@ -798,7 +807,11 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
write_c("// Initialize I18N stuff now for menus...\n");
write_c("#%sinclude <locale.h>\n", indent());
write_c("static char *_locale = setlocale(LC_MESSAGES, \"\");\n");
- write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n", proj_.basename().c_str());
+ {
+ char basename_buf[FL_PATH_MAX];
+ proj_.basename(basename_buf, FL_PATH_MAX);
+ write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n", basename_buf);
+ }
}
}
if (conditional) {
@@ -851,10 +864,10 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
if (code_file != stdout)
x = fclose(code_file);
- code_file = nullptr;
+ code_file = 0;
if (header_file != stdout)
y = fclose(header_file);
- header_file = nullptr;
+ header_file = 0;
return x >= 0 && y >= 0;
}
@@ -883,7 +896,7 @@ void Code_Writer::write_public(int state) {
Code_Writer::Code_Writer(Project &proj)
: proj_ { proj }
{
- block_crc_ = crc32(0, nullptr, 0);
+ block_crc_ = crc32(0, 0, 0);
}
/**
@@ -906,7 +919,7 @@ void Code_Writer::tag(proj::Mergeback::Tag prev_type, proj::Mergeback::Tag next_
if (proj_.write_mergeback_data) {
Mergeback::print_tag(code_file, prev_type, next_type, uid, (uint32_t)block_crc_);
}
- block_crc_ = crc32(0, nullptr, 0);
+ block_crc_ = crc32(0, 0, 0);
}
/**