2021-12-08 17:52:15 +03:00
|
|
|
//
|
|
|
|
// Fluid file routines for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2023-01-26 17:23:43 +03:00
|
|
|
// Copyright 1998-2023 by Bill Spitzak and others.
|
2021-12-08 17:52:15 +03:00
|
|
|
//
|
|
|
|
// 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_FILE_H
|
|
|
|
#define _FLUID_FILE_H
|
|
|
|
|
2021-12-11 21:43:00 +03:00
|
|
|
#include "Fl_Type.h"
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
#include <FL/fl_attr.h>
|
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
class Fl_Type;
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
extern int fdesign_flip;
|
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
int read_file(const char *, int merge, Strategy strategy=kAddAsLastChild);
|
2023-10-24 15:28:56 +03:00
|
|
|
int write_file(const char *, int selected_only = 0, bool to_sourceview = false);
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
class Fd_Project_Reader
|
|
|
|
{
|
|
|
|
protected:
|
2023-10-27 17:09:01 +03:00
|
|
|
/// Project input file
|
2023-01-26 17:23:43 +03:00
|
|
|
FILE *fin;
|
2023-10-27 17:09:01 +03:00
|
|
|
/// Number of most recently read line
|
2023-01-26 17:23:43 +03:00
|
|
|
int lineno;
|
2023-10-27 17:09:01 +03:00
|
|
|
/// Pointer to the file path and name (not copied!)
|
2023-01-26 17:23:43 +03:00
|
|
|
const char *fname;
|
2023-10-27 17:09:01 +03:00
|
|
|
/// Expanding buffer to store the most recently read word
|
2023-01-26 17:23:43 +03:00
|
|
|
char *buffer;
|
2023-10-27 17:09:01 +03:00
|
|
|
/// Exact size of the expanding buffer in bytes
|
2023-01-26 17:23:43 +03:00
|
|
|
int buflen;
|
2023-10-27 17:09:01 +03:00
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
void expand_buffer(int length);
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-11-06 13:36:02 +03:00
|
|
|
int nextchar() { for (;;) { int ret = fgetc(fin); if (ret!='\r') return ret; } }
|
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
public:
|
2023-10-27 17:09:01 +03:00
|
|
|
/// Holds the file version number after reading the "version" tag
|
2023-01-26 17:23:43 +03:00
|
|
|
double read_version;
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
public:
|
|
|
|
Fd_Project_Reader();
|
|
|
|
~Fd_Project_Reader();
|
|
|
|
int open_read(const char *s);
|
|
|
|
int close_read();
|
2023-03-18 19:33:27 +03:00
|
|
|
const char *filename_name();
|
2023-01-26 17:23:43 +03:00
|
|
|
int read_quoted();
|
2023-10-27 19:31:14 +03:00
|
|
|
Fl_Type *read_children(Fl_Type *p, int merge, Strategy strategy, char skip_options=0);
|
2023-01-26 17:23:43 +03:00
|
|
|
int read_project(const char *, int merge, Strategy strategy=kAddAsLastChild);
|
|
|
|
void read_error(const char *format, ...);
|
|
|
|
const char *read_word(int wantbrace = 0);
|
2023-03-18 19:33:27 +03:00
|
|
|
int read_int();
|
2023-01-26 17:23:43 +03:00
|
|
|
int read_fdesign_line(const char*& name, const char*& value);
|
|
|
|
void read_fdesign();
|
|
|
|
};
|
|
|
|
|
|
|
|
class Fd_Project_Writer
|
|
|
|
{
|
|
|
|
protected:
|
2023-11-06 13:36:02 +03:00
|
|
|
// Project output file, always opened in "wb" mode
|
2023-01-26 17:23:43 +03:00
|
|
|
FILE *fout;
|
2023-10-27 17:09:01 +03:00
|
|
|
/// If set, one space is written before text unless the format starts with a newline character
|
2023-01-26 17:23:43 +03:00
|
|
|
int needspace;
|
2023-10-27 17:09:01 +03:00
|
|
|
/// Set if this file will be used in the SourceView dialog
|
2023-10-24 15:28:56 +03:00
|
|
|
bool write_sourceview_;
|
2023-01-26 17:23:43 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
Fd_Project_Writer();
|
|
|
|
~Fd_Project_Writer();
|
|
|
|
int open_write(const char *s);
|
|
|
|
int close_write();
|
2023-10-24 15:28:56 +03:00
|
|
|
int write_project(const char *filename, int selected_only, bool sourceview);
|
2023-01-26 17:23:43 +03:00
|
|
|
void write_word(const char *);
|
|
|
|
void write_string(const char *,...) __fl_attr((__format__ (__printf__, 2, 3)));
|
|
|
|
void write_indent(int n);
|
2023-10-27 17:09:01 +03:00
|
|
|
void write_open();
|
2023-01-26 17:23:43 +03:00
|
|
|
void write_close(int n);
|
2023-10-24 15:28:56 +03:00
|
|
|
FILE *file() const { return fout; }
|
|
|
|
bool write_sourceview() const { return write_sourceview_; }
|
2023-01-26 17:23:43 +03:00
|
|
|
};
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
#endif // _FLUID_FILE_H
|