2021-12-08 17:52:15 +03:00
|
|
|
//
|
|
|
|
// Code output routines for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
|
|
|
// Copyright 1998-2021 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_CODE_H
|
|
|
|
#define _FLUID_CODE_H
|
|
|
|
|
|
|
|
#include <FL/fl_attr.h>
|
2023-10-22 20:30:37 +03:00
|
|
|
#include "../src/Fl_String.H"
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
2023-01-26 17:23:43 +03:00
|
|
|
#include <stdio.h>
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
class Fl_Type;
|
|
|
|
struct Fd_Identifier_Tree;
|
|
|
|
struct Fd_Text_Tree;
|
|
|
|
struct Fd_Pointer_Tree;
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
int is_id(char c);
|
2023-09-05 16:11:09 +03:00
|
|
|
int write_strings(const Fl_String &filename);
|
2023-01-26 17:23:43 +03:00
|
|
|
|
|
|
|
class Fd_Code_Writer
|
|
|
|
{
|
|
|
|
protected:
|
2023-10-27 00:31:12 +03:00
|
|
|
/// file pointer for the C++ code file
|
2023-01-26 17:23:43 +03:00
|
|
|
FILE *code_file;
|
2023-10-27 00:31:12 +03:00
|
|
|
/// file pointer for the C++ header file
|
2023-01-26 17:23:43 +03:00
|
|
|
FILE *header_file;
|
2023-10-27 00:31:12 +03:00
|
|
|
|
|
|
|
/// tree of unique but human-readable identifiers
|
2023-01-26 17:23:43 +03:00
|
|
|
Fd_Identifier_Tree* id_root;
|
2023-10-27 00:31:12 +03:00
|
|
|
/// searchable text tree for text that is only written once to the header file
|
2023-01-26 17:23:43 +03:00
|
|
|
Fd_Text_Tree *text_in_header;
|
2023-10-27 00:31:12 +03:00
|
|
|
/// searchable text tree for text that is only written once to the code file
|
2023-01-26 17:23:43 +03:00
|
|
|
Fd_Text_Tree *text_in_code;
|
2023-10-27 00:31:12 +03:00
|
|
|
/// searchable tree for pointers that are only written once to the code file
|
2023-01-26 17:23:43 +03:00
|
|
|
Fd_Pointer_Tree *ptr_in_code;
|
|
|
|
|
2023-10-27 00:31:12 +03:00
|
|
|
/// crc32 for blocks of text written to the code file
|
2023-10-26 01:38:58 +03:00
|
|
|
unsigned long block_crc_;
|
2023-10-27 00:31:12 +03:00
|
|
|
/// if set, we are at the start of a line and can ignore leading spaces in crc
|
|
|
|
bool block_line_start_;
|
|
|
|
/// expanding buffer for vsnprintf
|
2023-10-26 01:38:58 +03:00
|
|
|
char *block_buffer_;
|
2023-10-27 00:31:12 +03:00
|
|
|
/// size of expanding buffer for vsnprintf
|
2023-10-26 01:38:58 +03:00
|
|
|
int block_buffer_size_;
|
2023-10-27 00:31:12 +03:00
|
|
|
|
2023-10-26 01:38:58 +03:00
|
|
|
void crc_add(const void *data, int n=-1);
|
|
|
|
int crc_printf(const char *format, ...);
|
|
|
|
int crc_vprintf(const char *format, va_list args);
|
|
|
|
int crc_puts(const char *text);
|
|
|
|
int crc_putc(int c);
|
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
public:
|
2023-10-27 00:31:12 +03:00
|
|
|
/// current level of source code indentation
|
2023-01-26 17:23:43 +03:00
|
|
|
int indentation;
|
2023-10-27 00:31:12 +03:00
|
|
|
/// set if we write abbreviated file for the source code previewer
|
|
|
|
/// (disables binary data blocks, for example)
|
2023-01-26 17:23:43 +03:00
|
|
|
bool write_sourceview;
|
2023-10-27 00:31:12 +03:00
|
|
|
/// silly thing to prevent declaring unused variables:
|
|
|
|
/// When this symbol is on, all attempts to write code don't write
|
|
|
|
/// anything, but set a variable if it looks like the variable "o" is used:
|
2023-01-26 17:23:43 +03:00
|
|
|
int varused_test;
|
2023-10-27 00:31:12 +03:00
|
|
|
/// set to 1 if varused_test found that a variable is actually used
|
2023-01-26 17:23:43 +03:00
|
|
|
int varused;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Fd_Code_Writer();
|
|
|
|
~Fd_Code_Writer();
|
|
|
|
const char* unique_id(void* o, const char*, const char*, const char*);
|
2023-10-27 00:31:12 +03:00
|
|
|
/// Increment source code indentation level.
|
2023-01-26 17:23:43 +03:00
|
|
|
void indent_more() { indentation++; }
|
2023-10-27 00:31:12 +03:00
|
|
|
/// Decrement source code indentation level.
|
2023-01-26 17:23:43 +03:00
|
|
|
void indent_less() { indentation--; }
|
|
|
|
const char *indent();
|
|
|
|
const char *indent(int set);
|
|
|
|
const char *indent_plus(int offset);
|
|
|
|
int write_h_once(const char *, ...) __fl_attr((__format__ (__printf__, 2, 3)));
|
|
|
|
int write_c_once(const char *, ...) __fl_attr((__format__ (__printf__, 2, 3)));
|
|
|
|
bool c_contains(void* ptr);
|
|
|
|
void write_cstring(const char *,int length);
|
|
|
|
void write_cstring(const char *);
|
|
|
|
void write_cdata(const char *,int length);
|
|
|
|
void vwrite_c(const char* format, va_list args);
|
|
|
|
void write_c(const char*, ...) __fl_attr((__format__ (__printf__, 2, 3)));
|
|
|
|
void write_cc(const char *, int, const char*, const char*);
|
|
|
|
void write_h(const char*, ...) __fl_attr((__format__ (__printf__, 2, 3)));
|
|
|
|
void write_hc(const char *, int, const char*, const char*);
|
|
|
|
void write_c_indented(const char *textlines, int inIndent, char inTrailwWith);
|
|
|
|
Fl_Type* write_code(Fl_Type* p);
|
|
|
|
int write_code(const char *cfile, const char *hfile, bool to_sourceview=false);
|
|
|
|
void write_public(int state); // writes pubic:/private: as needed
|
2023-11-14 20:14:48 +03:00
|
|
|
|
2023-10-26 01:38:58 +03:00
|
|
|
void tag(int type, unsigned short uid);
|
|
|
|
|
2023-10-26 15:15:51 +03:00
|
|
|
static unsigned long block_crc(const void *data, int n=-1, unsigned long in_crc=0, bool *inout_line_start=NULL);
|
2023-01-26 17:23:43 +03:00
|
|
|
};
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
#endif // _FLUID_CODE_H
|