summaryrefslogtreecommitdiff
path: root/fluid/io/Project_Reader.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2025-03-08 00:14:09 +0100
committerMatthias Melcher <github@matthiasm.com>2025-03-08 00:14:27 +0100
commit15ad447e2a0301b2aa4ea350615ae71f0e5e5ef5 (patch)
tree706f8f9a6317f1074951e6174a4857ebafbca117 /fluid/io/Project_Reader.cxx
parentca22660bbb7efe4b38ab5af6a233a1ef5ef33389 (diff)
Fluid: last incremental chage, restructuring
Diffstat (limited to 'fluid/io/Project_Reader.cxx')
-rw-r--r--fluid/io/Project_Reader.cxx266
1 files changed, 25 insertions, 241 deletions
diff --git a/fluid/io/Project_Reader.cxx b/fluid/io/Project_Reader.cxx
index ba1afeb1b..ff88238ba 100644
--- a/fluid/io/Project_Reader.cxx
+++ b/fluid/io/Project_Reader.cxx
@@ -19,37 +19,33 @@
// https://www.fltk.org/bugs.php
//
-#include "io/file.h"
+#include "io/Project_Reader.h"
#include "app/fluid.h"
+#include "app/project.h"
#include "app/shell_command.h"
#include "app/undo.h"
-#include "io/code.h"
+#include "app/Fd_Snap_Action.h"
#include "nodes/factory.h"
#include "nodes/Fl_Function_Type.h"
#include "nodes/Fl_Widget_Type.h"
#include "nodes/Fl_Grid_Type.h"
#include "nodes/Fl_Window_Type.h"
-#include "panels/settings_panel.h"
#include "widgets/Node_Browser.h"
-#include <FL/Fl.H>
-#include <FL/Fl_Group.H>
-#include <FL/fl_string_functions.h>
+#include <FL/Fl_Window.H>
#include <FL/fl_message.H>
-#include "../src/flstring.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
/// \defgroup flfile .fl Project File Operations
/// \{
+using namespace fld;
+using namespace fld::io;
+
// This file contains code to read and write .fl files.
/// If set, we read an old fdesign file and widget y coordinates need to be flipped.
-int fdesign_flip = 0;
+int fld::io::fdesign_flip = 0;
/** \brief Read a .fl project file.
@@ -61,26 +57,12 @@ int fdesign_flip = 0;
\param[in] strategy add new nodes after current or as last child
\return 0 if the operation failed, 1 if it succeeded
*/
-int read_file(const char *filename, int merge, Strategy strategy) {
- Fd_Project_Reader f;
+int fld::io::read_file(const char *filename, int merge, Strategy strategy) {
+ Project_Reader f;
strategy.source(Strategy::FROM_FILE);
return f.read_project(filename, merge, strategy);
}
-/** \brief Write an .fl design description file.
-
- The .fl file format is documented in `fluid/README_fl.txt`.
-
- \param[in] filename create this file, and if it exists, overwrite it
- \param[in] selected_only write only the selected nodes in the widget_tree. This
- is used to implement copy and paste.
- \return 0 if the operation failed, 1 if it succeeded
- */
-int write_file(const char *filename, int selected_only, bool to_codeview) {
- Fd_Project_Writer out;
- return out.write_project(filename, selected_only, to_codeview);
-}
-
/**
Convert a single ASCII char, assumed to be a hex digit, into its decimal value.
\param[in] x ASCII character
@@ -94,14 +76,14 @@ static int hexdigit(int x) {
return 20;
}
-// ---- Fd_Project_Reader ---------------------------------------------- MARK: -
+// ---- Project_Reader ---------------------------------------------- MARK: -
/**
A simple growing buffer.
Oh how I wish sometimes we would upgrade to modern C++.
\param[in] length minimum length in bytes
*/
-void Fd_Project_Reader::expand_buffer(int length) {
+void Project_Reader::expand_buffer(int length) {
if (length >= buflen) {
if (!buflen) {
buflen = length+1;
@@ -115,7 +97,7 @@ void Fd_Project_Reader::expand_buffer(int length) {
}
/** \brief Construct local project reader. */
-Fd_Project_Reader::Fd_Project_Reader()
+Project_Reader::Project_Reader()
: fin(NULL),
lineno(0),
fname(NULL),
@@ -126,7 +108,7 @@ Fd_Project_Reader::Fd_Project_Reader()
}
/** \brief Release project reader resources. */
-Fd_Project_Reader::~Fd_Project_Reader()
+Project_Reader::~Project_Reader()
{
// fname is not copied, so do not free it
if (buffer)
@@ -138,7 +120,7 @@ Fd_Project_Reader::~Fd_Project_Reader()
\param[in] s filename, if NULL, read from stdin instead
\return 0 if the operation failed, 1 if it succeeded
*/
-int Fd_Project_Reader::open_read(const char *s) {
+int Project_Reader::open_read(const char *s) {
lineno = 1;
if (!s) {
fin = stdin;
@@ -157,7 +139,7 @@ int Fd_Project_Reader::open_read(const char *s) {
Close the .fl file.
\return 0 if the operation failed, 1 if it succeeded
*/
-int Fd_Project_Reader::close_read() {
+int Project_Reader::close_read() {
if (fin != stdin) {
int x = fclose(fin);
fin = 0;
@@ -170,7 +152,7 @@ int Fd_Project_Reader::close_read() {
Return the name part of the current filename and path.
\return a pointer into a string that is not owned by this class
*/
-const char *Fd_Project_Reader::filename_name() {
+const char *Project_Reader::filename_name() {
return fl_filename_name(fname);
}
@@ -180,7 +162,7 @@ const char *Fd_Project_Reader::filename_name() {
values, and \\o### octal values.
\return a character in the ASCII range
*/
-int Fd_Project_Reader::read_quoted() { // read whatever character is after a \ .
+int Project_Reader::read_quoted() { // read whatever character is after a \ .
int c,d,x;
switch(c = nextchar()) {
case '\n': lineno++; return -1;
@@ -225,7 +207,7 @@ int Fd_Project_Reader::read_quoted() { // read whatever character is after
a previous call, and there is no need to waste time searching for them.
\return the last type that was created
*/
-Fl_Type *Fd_Project_Reader::read_children(Fl_Type *p, int merge, Strategy strategy, char skip_options) {
+Fl_Type *Project_Reader::read_children(Fl_Type *p, int merge, Strategy strategy, char skip_options) {
Fl_Type::current = p;
Fl_Type *last_child_read = NULL;
Fl_Type *t = NULL;
@@ -432,7 +414,7 @@ Fl_Type *Fd_Project_Reader::read_children(Fl_Type *p, int merge, Strategy strate
\param[in] strategy add new nodes after current or as last child
\return 0 if the operation failed, 1 if it succeeded
*/
-int Fd_Project_Reader::read_project(const char *filename, int merge, Strategy strategy) {
+int Project_Reader::read_project(const char *filename, int merge, Strategy strategy) {
Fl_Type *o;
undo_suspend();
read_version = 0.0;
@@ -482,7 +464,7 @@ int Fd_Project_Reader::read_project(const char *filename, int merge, Strategy st
operations.
\param[in] format printf style format string, followed by an argument list
*/
-void Fd_Project_Reader::read_error(const char *format, ...) {
+void Project_Reader::read_error(const char *format, ...) {
va_list args;
va_start(args, format);
if (!fin) { // FIXME: this line suppresses any error messages in interactive mode
@@ -515,7 +497,7 @@ void Fd_Project_Reader::read_error(const char *format, ...) {
overwrite this buffer. If wantbrace is not set, but we read a leading '{',
the returned string will be stripped of its leading and trailing braces.
*/
-const char *Fd_Project_Reader::read_word(int wantbrace) {
+const char *Project_Reader::read_word(int wantbrace) {
int x;
// skip all the whitespace before it:
@@ -585,7 +567,7 @@ const char *Fd_Project_Reader::read_word(int wantbrace) {
/** Read a word and interpret it as an integer value.
\return integer value, or 0 if the word is not an integer
*/
-int Fd_Project_Reader::read_int() {
+int Project_Reader::read_int() {
const char *word = read_word();
if (word) {
return atoi(word);
@@ -601,7 +583,7 @@ int Fd_Project_Reader::read_int() {
\param[out] value string
\return 0 if end of file, else 1
*/
-int Fd_Project_Reader::read_fdesign_line(const char*& name, const char*& value) {
+int Project_Reader::read_fdesign_line(const char*& name, const char*& value) {
int length = 0;
int x;
// find a colon:
@@ -727,7 +709,7 @@ static void forms_end(Fl_Group *g, int flip) {
FLTK widgets.
\see http://xforms-toolkit.org
*/
-void Fd_Project_Reader::read_fdesign() {
+void Project_Reader::read_fdesign() {
int fdesign_magic = atoi(read_word());
fdesign_flip = (fdesign_magic < 13000);
Fl_Widget_Type *window = 0;
@@ -782,202 +764,4 @@ void Fd_Project_Reader::read_fdesign() {
}
}
-// ---- Fd_Project_Writer ---------------------------------------------- MARK: -
-
-/** \brief Construct local project writer. */
-Fd_Project_Writer::Fd_Project_Writer()
-: fout(NULL),
- needspace(0),
- write_codeview_(false)
-{
-}
-
-/** \brief Release project writer resources. */
-Fd_Project_Writer::~Fd_Project_Writer()
-{
-}
-
-/**
- Open the .fl design file for writing.
- If the filename is NULL, associate stdout instead.
- \param[in] s the filename or NULL for stdout
- \return 1 if successful. 0 if the operation failed
- */
-int Fd_Project_Writer::open_write(const char *s) {
- if (!s) {
- fout = stdout;
- } else {
- FILE *f = fl_fopen(s,"wb");
- if (!f) return 0;
- fout = f;
- }
- return 1;
-}
-
-/**
- Close the .fl design file.
- Don't close, if data was sent to stdout.
- \return 1 if succeeded, 0 if fclose failed
- */
-int Fd_Project_Writer::close_write() {
- if (fout != stdout) {
- int x = fclose(fout);
- fout = stdout;
- return x >= 0;
- }
- return 1;
-}
-
-/** \brief Write an .fl design description file.
- \param[in] filename create this file, and if it exists, overwrite it
- \param[in] selected_only write only the selected nodes in the widget_tree. This
- is used to implement copy and paste.
- \param[in] sv if set, this file will be used by codeview
- \return 0 if the operation failed, 1 if it succeeded
- */
-int Fd_Project_Writer::write_project(const char *filename, int selected_only, bool sv) {
- write_codeview_ = sv;
- undo_suspend();
- if (!open_write(filename)) {
- undo_resume();
- return 0;
- }
- write_string("# data file for the Fltk User Interface Designer (fluid)\n"
- "version %.4f",FL_VERSION);
- if(!g_project.include_H_from_C)
- write_string("\ndo_not_include_H_from_C");
- if(g_project.use_FL_COMMAND)
- write_string("\nuse_FL_COMMAND");
- if (g_project.utf8_in_src)
- write_string("\nutf8_in_src");
- if (g_project.avoid_early_includes)
- write_string("\navoid_early_includes");
- if (g_project.i18n_type) {
- write_string("\ni18n_type %d", g_project.i18n_type);
- switch (g_project.i18n_type) {
- case FD_I18N_NONE:
- break;
- case FD_I18N_GNU : /* GNU gettext */
- write_string("\ni18n_include"); write_word(g_project.i18n_gnu_include.c_str());
- write_string("\ni18n_conditional"); write_word(g_project.i18n_gnu_conditional.c_str());
- write_string("\ni18n_gnu_function"); write_word(g_project.i18n_gnu_function.c_str());
- write_string("\ni18n_gnu_static_function"); write_word(g_project.i18n_gnu_static_function.c_str());
- break;
- case FD_I18N_POSIX : /* POSIX catgets */
- write_string("\ni18n_include"); write_word(g_project.i18n_pos_include.c_str());
- write_string("\ni18n_conditional"); write_word(g_project.i18n_pos_conditional.c_str());
- if (!g_project.i18n_pos_file.empty()) {
- write_string("\ni18n_pos_file");
- write_word(g_project.i18n_pos_file.c_str());
- }
- write_string("\ni18n_pos_set"); write_word(g_project.i18n_pos_set.c_str());
- break;
- }
- }
-
- if (!selected_only) {
- write_string("\nheader_name"); write_word(g_project.header_file_name.c_str());
- write_string("\ncode_name"); write_word(g_project.code_file_name.c_str());
- g_layout_list.write(this);
- if (g_shell_config)
- g_shell_config->write(this);
- if (g_project.write_mergeback_data)
- write_string("\nmergeback %d", g_project.write_mergeback_data);
- }
-
- for (Fl_Type *p = Fl_Type::first; p;) {
- if (!selected_only || p->selected) {
- p->write(*this);
- write_string("\n");
- int q = p->level;
- for (p = p->next; p && p->level > q; p = p->next) {/*empty*/}
- } else {
- p = p->next;
- }
- }
- int ret = close_write();
- undo_resume();
- return ret;
-}
-
-/**
- Write a string to the .fl file, quoting characters if necessary.
- \param[in] w NUL terminated text
- */
-void Fd_Project_Writer::write_word(const char *w) {
- if (needspace) putc(' ', fout);
- needspace = 1;
- if (!w || !*w) {fprintf(fout,"{}"); return;}
- const char *p;
- // see if it is a single word:
- for (p = w; is_id(*p); p++) ;
- if (!*p) {fprintf(fout,"%s",w); return;}
- // see if there are matching braces:
- int n = 0;
- for (p = w; *p; p++) {
- if (*p == '{') n++;
- else if (*p == '}') {n--; if (n<0) break;}
- }
- int mismatched = (n != 0);
- // write out brace-quoted string:
- putc('{', fout);
- for (; *w; w++) {
- switch (*w) {
- case '{':
- case '}':
- if (!mismatched) break;
- case '\\':
- case '#':
- putc('\\',fout);
- break;
- }
- putc(*w,fout);
- }
- putc('}', fout);
-}
-
-/**
- Write an arbitrary formatted word to the .fl file, or a comment, etc .
- If needspace is set, then one space is written before the string
- unless the format starts with a newline character \\n.
- \param[in] format printf style formatting string followed by a list of arguments
- */
-void Fd_Project_Writer::write_string(const char *format, ...) {
- va_list args;
- va_start(args, format);
- if (needspace && *format != '\n') fputc(' ',fout);
- vfprintf(fout, format, args);
- va_end(args);
- needspace = !isspace(format[strlen(format)-1] & 255);
-}
-
-/**
- Start a new line in the .fl file and indent it for a given nesting level.
- \param[in] n indent level
- */
-void Fd_Project_Writer::write_indent(int n) {
- fputc('\n',fout);
- while (n--) {fputc(' ',fout); fputc(' ',fout);}
- needspace = 0;
-}
-
-/**
- Write a '{' to the .fl file at the given indenting level.
- */
-void Fd_Project_Writer::write_open() {
- if (needspace) fputc(' ',fout);
- fputc('{',fout);
- needspace = 0;
-}
-
-/**
- Write a '}' to the .fl file at the given indenting level.
- \param[in] n indent level
- */
-void Fd_Project_Writer::write_close(int n) {
- if (needspace) write_indent(n);
- fputc('}',fout);
- needspace = 1;
-}
-
/// \}