1998-10-21 20:29:01 +04:00
|
|
|
//
|
2005-02-06 19:28:36 +03:00
|
|
|
// "$Id$"
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
|
|
|
// Code output routines for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2015-11-03 18:45:41 +03:00
|
|
|
// Copyright 1998-2015 by Bill Spitzak and others.
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04: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:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-05-16 16:47:44 +04:00
|
|
|
#include "../src/flstring.h"
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
1998-12-06 18:52:17 +03:00
|
|
|
#include "Fl_Type.h"
|
1998-12-06 18:09:22 +03:00
|
|
|
#include "alignment_panel.h"
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
static FILE *code_file;
|
|
|
|
static FILE *header_file;
|
2000-05-16 16:26:07 +04:00
|
|
|
|
|
|
|
extern char i18n_program[];
|
2000-04-24 22:22:50 +04:00
|
|
|
extern int i18n_type;
|
|
|
|
extern const char* i18n_include;
|
|
|
|
extern const char* i18n_function;
|
|
|
|
extern const char* i18n_file;
|
|
|
|
extern const char* i18n_set;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// return true if c can be in a C identifier. I needed this so
|
|
|
|
// it is not messed up by locale settings:
|
|
|
|
int is_id(char c) {
|
2010-10-29 01:47:01 +04:00
|
|
|
return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_';
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
// Generate unique but human-readable identifiers:
|
|
|
|
|
|
|
|
struct id {
|
|
|
|
char* text;
|
|
|
|
void* object;
|
|
|
|
id *left, *right;
|
|
|
|
id (const char* t, void* o) : text(strdup(t)), object(o) {left = right = 0;}
|
|
|
|
~id();
|
|
|
|
};
|
|
|
|
|
|
|
|
id::~id() {
|
|
|
|
delete left;
|
|
|
|
free((void *)text);
|
|
|
|
delete right;
|
|
|
|
}
|
|
|
|
|
|
|
|
static id* id_root;
|
|
|
|
|
|
|
|
const char* unique_id(void* o, const char* type, const char* name, const char* label) {
|
|
|
|
char buffer[128];
|
|
|
|
char* q = buffer;
|
|
|
|
while (*type) *q++ = *type++;
|
|
|
|
*q++ = '_';
|
|
|
|
const char* n = name;
|
|
|
|
if (!n || !*n) n = label;
|
|
|
|
if (n && *n) {
|
2000-06-16 11:08:16 +04:00
|
|
|
while (*n && !is_id(*n)) n++;
|
1998-10-06 22:21:25 +04:00
|
|
|
while (is_id(*n)) *q++ = *n++;
|
|
|
|
}
|
|
|
|
*q = 0;
|
|
|
|
// okay, search the tree and see if the name was already used:
|
|
|
|
id** p = &id_root;
|
|
|
|
int which = 0;
|
|
|
|
while (*p) {
|
|
|
|
int i = strcmp(buffer, (*p)->text);
|
|
|
|
if (!i) {
|
|
|
|
if ((*p)->object == o) return (*p)->text;
|
|
|
|
// already used, we need to pick a new name:
|
|
|
|
sprintf(q,"%x",++which);
|
|
|
|
p = &id_root;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (i < 0) p = &((*p)->left);
|
|
|
|
else p = &((*p)->right);
|
|
|
|
}
|
|
|
|
*p = new id(buffer, o);
|
|
|
|
return (*p)->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
// return current indentation:
|
|
|
|
|
|
|
|
static const char* spaces = " ";
|
|
|
|
int indentation;
|
|
|
|
const char* indent() {
|
|
|
|
int i = indentation; if (i>16) i = 16;
|
|
|
|
return spaces+16-i;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
// declarations/include files:
|
1999-08-05 12:01:40 +04:00
|
|
|
// Each string generated by write_declare is written only once to
|
|
|
|
// the header file. This is done by keeping a binary tree of all
|
|
|
|
// the calls so far and not printing it if it is in the tree.
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
struct included {
|
|
|
|
char *text;
|
|
|
|
included *left, *right;
|
|
|
|
included(const char *t) {
|
|
|
|
text = strdup(t);
|
|
|
|
left = right = 0;
|
|
|
|
}
|
|
|
|
~included();
|
|
|
|
};
|
|
|
|
|
|
|
|
included::~included() {
|
|
|
|
delete left;
|
|
|
|
free((void *)text);
|
|
|
|
delete right;
|
|
|
|
}
|
|
|
|
static included *included_root;
|
|
|
|
|
|
|
|
int write_declare(const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
char buf[1024];
|
|
|
|
va_start(args, format);
|
2002-05-16 16:47:44 +04:00
|
|
|
vsnprintf(buf, sizeof(buf), format, args);
|
1998-10-06 22:21:25 +04:00
|
|
|
va_end(args);
|
|
|
|
included **p = &included_root;
|
|
|
|
while (*p) {
|
|
|
|
int i = strcmp(buf,(*p)->text);
|
|
|
|
if (!i) return 0;
|
|
|
|
else if (i < 0) p = &((*p)->left);
|
|
|
|
else p = &((*p)->right);
|
|
|
|
}
|
1999-08-05 12:01:40 +04:00
|
|
|
fprintf(header_file,"%s\n",buf);
|
1998-10-06 22:21:25 +04:00
|
|
|
*p = new included(buf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-07-27 23:26:11 +04: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:
|
|
|
|
int varused_test;
|
|
|
|
int varused;
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
// write an array of C characters (adds a null):
|
2015-11-03 18:08:54 +03:00
|
|
|
void write_cstring(const char *s, int length) {
|
2006-07-27 23:26:11 +04:00
|
|
|
if (varused_test) {
|
|
|
|
varused = 1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-03 18:08:54 +03:00
|
|
|
const char *p = s;
|
|
|
|
const char *e = s+length;
|
1998-10-06 22:21:25 +04:00
|
|
|
int linelength = 1;
|
|
|
|
putc('\"', code_file);
|
2015-11-03 18:08:54 +03:00
|
|
|
for (; p < e;) {
|
|
|
|
int c = *p++;
|
1998-10-06 22:21:25 +04:00
|
|
|
switch (c) {
|
|
|
|
case '\b': c = 'b'; goto QUOTED;
|
|
|
|
case '\t': c = 't'; goto QUOTED;
|
|
|
|
case '\n': c = 'n'; goto QUOTED;
|
|
|
|
case '\f': c = 'f'; goto QUOTED;
|
|
|
|
case '\r': c = 'r'; goto QUOTED;
|
|
|
|
case '\"':
|
|
|
|
case '\'':
|
|
|
|
case '\\':
|
|
|
|
QUOTED:
|
1999-07-31 12:00:09 +04:00
|
|
|
if (linelength >= 77) {fputs("\\\n",code_file); linelength = 0;}
|
|
|
|
putc('\\', code_file);
|
|
|
|
putc(c, code_file);
|
1998-10-06 22:21:25 +04:00
|
|
|
linelength += 2;
|
|
|
|
break;
|
1999-07-31 12:00:09 +04:00
|
|
|
case '?': // prevent trigraphs by writing ?? as ?\?
|
2015-11-03 18:08:54 +03:00
|
|
|
if (p-2 >= s && *(p-2) == '?') goto QUOTED;
|
1998-10-06 22:21:25 +04:00
|
|
|
// else fall through:
|
|
|
|
default:
|
1999-07-31 12:00:09 +04:00
|
|
|
if (c >= ' ' && c < 127) {
|
|
|
|
// a legal ASCII character
|
|
|
|
if (linelength >= 78) {fputs("\\\n",code_file); linelength = 0;}
|
|
|
|
putc(c, code_file);
|
1998-10-06 22:21:25 +04:00
|
|
|
linelength++;
|
1999-07-31 12:00:09 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// otherwise we must print it as an octal constant:
|
|
|
|
c &= 255;
|
|
|
|
if (c < 8) {
|
|
|
|
if (linelength >= 76) {fputs("\\\n",code_file); linelength = 0;}
|
|
|
|
fprintf(code_file, "\\%o",c);
|
|
|
|
linelength += 2;
|
|
|
|
} else if (c < 64) {
|
|
|
|
if (linelength >= 75) {fputs("\\\n",code_file); linelength = 0;}
|
|
|
|
fprintf(code_file, "\\%o",c);
|
|
|
|
linelength += 3;
|
|
|
|
} else {
|
|
|
|
if (linelength >= 74) {fputs("\\\n",code_file); linelength = 0;}
|
|
|
|
fprintf(code_file, "\\%o",c);
|
|
|
|
linelength += 4;
|
|
|
|
}
|
|
|
|
// We must not put more numbers after it, because some C compilers
|
|
|
|
// consume them as part of the quoted sequence. Use string constant
|
|
|
|
// pasting to avoid this:
|
2015-11-03 18:08:54 +03:00
|
|
|
c = *p;
|
|
|
|
if (p < e && ( (c>='0'&&c<='9') || (c>='a'&&c<='f') || (c>='A'&&c<='F') )) {
|
1999-07-31 12:00:09 +04:00
|
|
|
putc('\"', code_file); linelength++;
|
|
|
|
if (linelength >= 79) {fputs("\n",code_file); linelength = 0;}
|
|
|
|
putc('\"', code_file); linelength++;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
putc('\"', code_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
// write a C string, quoting characters if necessary:
|
2015-11-03 18:08:54 +03:00
|
|
|
void write_cstring(const char *s) {write_cstring(s,strlen(s));}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2005-10-26 13:08:01 +04:00
|
|
|
// write an array of C binary data (does not add a null):
|
|
|
|
void write_cdata(const char *s, int length) {
|
2006-07-27 23:26:11 +04:00
|
|
|
if (varused_test) {
|
|
|
|
varused = 1;
|
|
|
|
return;
|
|
|
|
}
|
2010-02-21 00:43:18 +03:00
|
|
|
if (write_sourceview) {
|
|
|
|
if (length>=0)
|
|
|
|
fprintf(code_file, "{ /* ... %d bytes of binary data... */ }", length);
|
|
|
|
else
|
|
|
|
fprintf(code_file, "{ /* ... binary data... */ }");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (length==-1) {
|
|
|
|
fprintf(code_file, "{ /* ... undefined size binary data... */ }");
|
|
|
|
return;
|
|
|
|
}
|
2005-10-26 13:08:01 +04:00
|
|
|
const unsigned char *w = (const unsigned char *)s;
|
|
|
|
const unsigned char *e = w+length;
|
|
|
|
int linelength = 1;
|
|
|
|
putc('{', code_file);
|
|
|
|
for (; w < e;) {
|
|
|
|
unsigned char c = *w++;
|
|
|
|
if (c>99) linelength += 4;
|
|
|
|
else if (c>9) linelength += 3;
|
|
|
|
else linelength += 2;
|
|
|
|
if (linelength >= 77) {fputs("\n",code_file); linelength = 0;}
|
|
|
|
fprintf(code_file, "%d", c);
|
|
|
|
if (w<e) putc(',', code_file);
|
|
|
|
}
|
|
|
|
putc('}', code_file);
|
|
|
|
}
|
|
|
|
|
2015-12-18 21:56:58 +03:00
|
|
|
void vwrite_c(const char* format, va_list args) {
|
2006-07-27 23:26:11 +04:00
|
|
|
if (varused_test) {
|
|
|
|
varused = 1;
|
|
|
|
return;
|
|
|
|
}
|
2015-12-18 21:56:58 +03:00
|
|
|
vfprintf(code_file, format, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_c(const char* format,...) {
|
1998-10-06 22:21:25 +04:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2015-12-18 21:56:58 +03:00
|
|
|
vwrite_c(format, args);
|
1998-10-06 22:21:25 +04:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_h(const char* format,...) {
|
2006-07-27 23:26:11 +04:00
|
|
|
if (varused_test) return;
|
1998-10-06 22:21:25 +04:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(header_file, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <FL/filename.H>
|
|
|
|
int write_number;
|
2005-11-03 23:43:19 +03:00
|
|
|
int write_sourceview;
|
2006-09-17 22:34:17 +04:00
|
|
|
extern Fl_Widget_Class_Type *current_widget_class;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// recursively dump code, putting children between the two parts
|
|
|
|
// of the parent code:
|
|
|
|
static Fl_Type* write_code(Fl_Type* p) {
|
2005-11-03 23:43:19 +03:00
|
|
|
if (write_sourceview) {
|
2010-11-14 18:03:57 +03:00
|
|
|
p->code_position = (int)ftell(code_file);
|
|
|
|
if (p->header_position_end==-1)
|
|
|
|
p->header_position = (int)ftell(header_file);
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
|
|
|
// write all code that come before the children code
|
|
|
|
// (but don't write the last comment until the very end)
|
2005-03-10 00:26:53 +03:00
|
|
|
if (!(p==Fl_Type::last && p->is_comment()))
|
|
|
|
p->write_code1();
|
2005-11-03 23:43:19 +03:00
|
|
|
// recursively write the code of all children
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Type* q;
|
2005-03-29 17:28:43 +04:00
|
|
|
if (p->is_widget() && p->is_class()) {
|
|
|
|
// Handle widget classes specially
|
|
|
|
for (q = p->next; q && q->level > p->level;) {
|
|
|
|
if (strcmp(q->type_name(), "Function")) q = write_code(q);
|
2005-04-09 18:17:13 +04:00
|
|
|
else {
|
|
|
|
int level = q->level;
|
|
|
|
do {
|
|
|
|
q = q->next;
|
|
|
|
} while (q && q->level > level);
|
|
|
|
}
|
2005-03-29 17:28:43 +04:00
|
|
|
}
|
|
|
|
|
2005-11-03 23:43:19 +03:00
|
|
|
// write all code that come after the children
|
2005-03-29 17:28:43 +04:00
|
|
|
p->write_code2();
|
|
|
|
|
|
|
|
for (q = p->next; q && q->level > p->level;) {
|
|
|
|
if (!strcmp(q->type_name(), "Function")) q = write_code(q);
|
2005-04-09 18:17:13 +04:00
|
|
|
else {
|
|
|
|
int level = q->level;
|
|
|
|
do {
|
|
|
|
q = q->next;
|
|
|
|
} while (q && q->level > level);
|
|
|
|
}
|
2005-03-29 17:28:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
write_h("};\n");
|
2006-09-17 22:34:17 +04:00
|
|
|
current_widget_class = 0L;
|
2005-03-29 17:28:43 +04:00
|
|
|
} else {
|
|
|
|
for (q = p->next; q && q->level > p->level;) q = write_code(q);
|
2005-11-03 23:43:19 +03:00
|
|
|
// write all code that come after the children
|
2005-03-29 17:28:43 +04:00
|
|
|
p->write_code2();
|
|
|
|
}
|
2005-11-03 23:43:19 +03:00
|
|
|
if (write_sourceview) {
|
2010-11-14 18:03:57 +03:00
|
|
|
p->code_position_end = (int)ftell(code_file);
|
|
|
|
if (p->header_position_end==-1)
|
|
|
|
p->header_position_end = (int)ftell(header_file);
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
2001-08-02 20:17:04 +04:00
|
|
|
extern const char* header_file_name;
|
2008-01-05 01:18:40 +03:00
|
|
|
extern Fl_Class_Type *current_class;
|
2001-08-02 20:17:04 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
int write_code(const char *s, const char *t) {
|
2005-11-03 23:43:19 +03:00
|
|
|
const char *filemode = "w";
|
|
|
|
if (write_sourceview)
|
|
|
|
filemode = "wb";
|
1998-10-06 22:21:25 +04:00
|
|
|
write_number++;
|
|
|
|
delete id_root; id_root = 0;
|
|
|
|
indentation = 0;
|
2008-01-05 01:18:40 +03:00
|
|
|
current_class = 0L;
|
|
|
|
current_widget_class = 0L;
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!s) code_file = stdout;
|
|
|
|
else {
|
2010-11-18 23:00:01 +03:00
|
|
|
FILE *f = fl_fopen(s, filemode);
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!f) return 0;
|
|
|
|
code_file = f;
|
|
|
|
}
|
|
|
|
if (!t) header_file = stdout;
|
|
|
|
else {
|
2010-11-18 23:00:01 +03:00
|
|
|
FILE *f = fl_fopen(t, filemode);
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!f) {fclose(code_file); return 0;}
|
|
|
|
header_file = f;
|
|
|
|
}
|
2005-03-10 00:26:53 +03:00
|
|
|
// if the first entry in the Type tree is a comment, then it is probably
|
|
|
|
// a copyright notice. We print that before anything else in the file!
|
|
|
|
Fl_Type* first_type = Fl_Type::first;
|
|
|
|
if (first_type && first_type->is_comment()) {
|
2005-11-03 23:43:19 +03:00
|
|
|
if (write_sourceview) {
|
2010-11-14 18:03:57 +03:00
|
|
|
first_type->code_position = (int)ftell(code_file);
|
|
|
|
first_type->header_position = (int)ftell(header_file);
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
|
|
|
// it is ok to write non-recusive code here, because comments have no children or code2 blocks
|
2005-03-10 00:26:53 +03:00
|
|
|
first_type->write_code1();
|
2005-11-03 23:43:19 +03:00
|
|
|
if (write_sourceview) {
|
2010-11-14 18:03:57 +03:00
|
|
|
first_type->code_position_end = (int)ftell(code_file);
|
|
|
|
first_type->header_position_end = (int)ftell(header_file);
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
2005-03-10 00:26:53 +03:00
|
|
|
first_type = first_type->next;
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *hdr = "\
|
2000-02-25 06:44:22 +03:00
|
|
|
// generated by Fast Light User Interface Designer (fluid) version %.4f\n\n";
|
1998-10-06 22:21:25 +04:00
|
|
|
fprintf(header_file, hdr, FL_VERSION);
|
|
|
|
fprintf(code_file, hdr, FL_VERSION);
|
|
|
|
|
1999-01-19 22:10:39 +03:00
|
|
|
{char define_name[102];
|
2002-03-26 00:08:42 +03:00
|
|
|
const char* a = fl_filename_name(t);
|
1999-01-19 22:10:39 +03:00
|
|
|
char* b = define_name;
|
|
|
|
if (!isalpha(*a)) {*b++ = '_';}
|
|
|
|
while (*a) {*b++ = isalnum(*a) ? *a : '_'; a++;}
|
|
|
|
*b = 0;
|
|
|
|
fprintf(header_file, "#ifndef %s\n", define_name);
|
|
|
|
fprintf(header_file, "#define %s\n", define_name);
|
|
|
|
}
|
|
|
|
|
1999-08-05 12:01:40 +04:00
|
|
|
write_declare("#include <FL/Fl.H>");
|
2000-04-25 05:57:51 +04:00
|
|
|
if (i18n_type && i18n_include[0]) {
|
|
|
|
if (i18n_include[0] != '<' &&
|
|
|
|
i18n_include[0] != '\"')
|
|
|
|
write_c("#include \"%s\"\n", i18n_include);
|
2000-04-24 22:22:50 +04:00
|
|
|
else
|
2000-04-25 05:57:51 +04:00
|
|
|
write_c("#include %s\n", i18n_include);
|
|
|
|
if (i18n_type == 2) {
|
|
|
|
if (i18n_file[0]) write_c("extern nl_catd %s;\n", i18n_file);
|
2000-05-16 16:26:07 +04:00
|
|
|
else {
|
|
|
|
write_c("// Initialize I18N stuff now for menus...\n");
|
|
|
|
write_c("#include <locale.h>\n");
|
|
|
|
write_c("static char *_locale = setlocale(LC_MESSAGES, \"\");\n");
|
|
|
|
write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n",
|
|
|
|
i18n_program);
|
|
|
|
}
|
2000-04-25 05:57:51 +04:00
|
|
|
}
|
2000-04-24 22:22:50 +04:00
|
|
|
}
|
2001-08-02 20:17:04 +04:00
|
|
|
if (t && include_H_from_C) {
|
|
|
|
if (*header_file_name == '.' && strchr(header_file_name, '/') == NULL) {
|
2002-03-26 00:08:42 +03:00
|
|
|
write_c("#include \"%s\"\n", fl_filename_name(t));
|
2001-08-02 20:17:04 +04:00
|
|
|
} else {
|
|
|
|
write_c("#include \"%s\"\n", t);
|
|
|
|
}
|
|
|
|
}
|
2005-03-10 00:26:53 +03:00
|
|
|
for (Fl_Type* p = first_type; p;) {
|
1998-10-21 19:42:05 +04:00
|
|
|
// write all static data for this & all children first
|
2010-11-14 18:03:57 +03:00
|
|
|
if (write_sourceview) p->header_position = (int)ftell(header_file);
|
1998-10-21 19:42:05 +04:00
|
|
|
p->write_static();
|
2005-11-03 23:43:19 +03:00
|
|
|
if (write_sourceview) {
|
2010-11-14 18:03:57 +03:00
|
|
|
p->header_position_end = (int)ftell(header_file);
|
|
|
|
if (p->header_position==p->header_position_end) p->header_position_end = -1;
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
|
|
|
for (Fl_Type* q = p->next; q && q->level > p->level; q = q->next) {
|
2010-11-14 18:03:57 +03:00
|
|
|
if (write_sourceview) q->header_position = (int)ftell(header_file);
|
1998-10-21 19:42:05 +04:00
|
|
|
q->write_static();
|
2005-11-03 23:43:19 +03:00
|
|
|
if (write_sourceview) {
|
2010-11-14 18:03:57 +03:00
|
|
|
q->header_position_end = (int)ftell(header_file);
|
|
|
|
if (q->header_position==q->header_position_end) q->header_position_end = -1;
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
|
|
|
}
|
1998-10-21 19:42:05 +04:00
|
|
|
// then write the nested code:
|
|
|
|
p = write_code(p);
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
1999-08-05 12:01:40 +04:00
|
|
|
delete included_root; included_root = 0;
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!s) return 1;
|
2005-03-10 00:26:53 +03:00
|
|
|
|
|
|
|
fprintf(header_file, "#endif\n");
|
|
|
|
|
|
|
|
Fl_Type* last_type = Fl_Type::last;
|
|
|
|
if (last_type && last_type->is_comment()) {
|
2005-11-03 23:43:19 +03:00
|
|
|
if (write_sourceview) {
|
2010-11-14 18:03:57 +03:00
|
|
|
last_type->code_position = (int)ftell(code_file);
|
|
|
|
last_type->header_position = (int)ftell(header_file);
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
2005-03-10 00:26:53 +03:00
|
|
|
last_type->write_code1();
|
2005-11-03 23:43:19 +03:00
|
|
|
if (write_sourceview) {
|
2010-11-14 18:03:57 +03:00
|
|
|
last_type->code_position_end = (int)ftell(code_file);
|
|
|
|
last_type->header_position_end = (int)ftell(header_file);
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
2005-03-10 00:26:53 +03:00
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
int x = fclose(code_file);
|
|
|
|
code_file = 0;
|
|
|
|
int y = fclose(header_file);
|
|
|
|
header_file = 0;
|
|
|
|
return x >= 0 && y >= 0;
|
|
|
|
}
|
|
|
|
|
2000-04-24 22:22:50 +04:00
|
|
|
int write_strings(const char *sfile) {
|
2010-11-18 23:00:01 +03:00
|
|
|
FILE *fp = fl_fopen(sfile, "w");
|
2000-04-24 22:22:50 +04:00
|
|
|
Fl_Type *p;
|
2001-11-25 19:38:11 +03:00
|
|
|
Fl_Widget_Type *w;
|
2000-05-16 16:26:07 +04:00
|
|
|
int i;
|
2000-04-24 22:22:50 +04:00
|
|
|
|
|
|
|
if (!fp) return 1;
|
|
|
|
|
|
|
|
switch (i18n_type) {
|
|
|
|
case 0 : /* None, just put static text out */
|
|
|
|
fprintf(fp, "# generated by Fast Light User Interface Designer (fluid) version %.4f\n",
|
|
|
|
FL_VERSION);
|
|
|
|
for (p = Fl_Type::first; p; p = p->next) {
|
2001-11-25 19:38:11 +03:00
|
|
|
if (p->is_widget()) {
|
|
|
|
w = (Fl_Widget_Type *)p;
|
|
|
|
|
|
|
|
if (w->label()) {
|
|
|
|
for (const char *s = w->label(); *s; s ++)
|
|
|
|
if (*s < 32 || *s > 126 || *s == '\"')
|
|
|
|
fprintf(fp, "\\%03o", *s);
|
|
|
|
else
|
|
|
|
putc(*s, fp);
|
|
|
|
putc('\n', fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w->tooltip()) {
|
|
|
|
for (const char *s = w->tooltip(); *s; s ++)
|
|
|
|
if (*s < 32 || *s > 126 || *s == '\"')
|
|
|
|
fprintf(fp, "\\%03o", *s);
|
|
|
|
else
|
|
|
|
putc(*s, fp);
|
|
|
|
putc('\n', fp);
|
|
|
|
}
|
2000-04-24 22:22:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1 : /* GNU gettext, put a .po file out */
|
|
|
|
fprintf(fp, "# generated by Fast Light User Interface Designer (fluid) version %.4f\n",
|
|
|
|
FL_VERSION);
|
|
|
|
for (p = Fl_Type::first; p; p = p->next) {
|
2001-11-25 19:38:11 +03:00
|
|
|
if (p->is_widget()) {
|
|
|
|
w = (Fl_Widget_Type *)p;
|
|
|
|
|
|
|
|
if (w->label()) {
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
fputs("msgid \"", fp);
|
|
|
|
for (s = w->label(); *s; s ++)
|
|
|
|
if (*s < 32 || *s > 126 || *s == '\"')
|
|
|
|
fprintf(fp, "\\%03o", *s);
|
|
|
|
else
|
|
|
|
putc(*s, fp);
|
|
|
|
fputs("\"\n", fp);
|
|
|
|
|
|
|
|
fputs("msgstr \"", fp);
|
|
|
|
for (s = w->label(); *s; s ++)
|
|
|
|
if (*s < 32 || *s > 126 || *s == '\"')
|
|
|
|
fprintf(fp, "\\%03o", *s);
|
|
|
|
else
|
|
|
|
putc(*s, fp);
|
|
|
|
fputs("\"\n", fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w->tooltip()) {
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
fputs("msgid \"", fp);
|
|
|
|
for (s = w->tooltip(); *s; s ++)
|
|
|
|
if (*s < 32 || *s > 126 || *s == '\"')
|
|
|
|
fprintf(fp, "\\%03o", *s);
|
|
|
|
else
|
|
|
|
putc(*s, fp);
|
|
|
|
fputs("\"\n", fp);
|
|
|
|
|
|
|
|
fputs("msgstr \"", fp);
|
|
|
|
for (s = w->tooltip(); *s; s ++)
|
|
|
|
if (*s < 32 || *s > 126 || *s == '\"')
|
|
|
|
fprintf(fp, "\\%03o", *s);
|
|
|
|
else
|
|
|
|
putc(*s, fp);
|
|
|
|
fputs("\"\n", fp);
|
|
|
|
}
|
2000-04-24 22:22:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2 : /* POSIX catgets, put a .msg file out */
|
|
|
|
fprintf(fp, "$ generated by Fast Light User Interface Designer (fluid) version %.4f\n",
|
|
|
|
FL_VERSION);
|
2000-04-25 05:57:51 +04:00
|
|
|
fprintf(fp, "$set %s\n", i18n_set);
|
2000-04-24 22:22:50 +04:00
|
|
|
fputs("$quote \"\n", fp);
|
|
|
|
|
2000-05-16 16:26:07 +04:00
|
|
|
for (i = 1, p = Fl_Type::first; p; p = p->next) {
|
2001-11-25 19:38:11 +03:00
|
|
|
if (p->is_widget()) {
|
|
|
|
w = (Fl_Widget_Type *)p;
|
|
|
|
|
|
|
|
if (w->label()) {
|
|
|
|
fprintf(fp, "%d \"", i ++);
|
|
|
|
for (const char *s = w->label(); *s; s ++)
|
|
|
|
if (*s < 32 || *s > 126 || *s == '\"')
|
|
|
|
fprintf(fp, "\\%03o", *s);
|
|
|
|
else
|
|
|
|
putc(*s, fp);
|
|
|
|
fputs("\"\n", fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w->tooltip()) {
|
|
|
|
fprintf(fp, "%d \"", i ++);
|
|
|
|
for (const char *s = w->tooltip(); *s; s ++)
|
|
|
|
if (*s < 32 || *s > 126 || *s == '\"')
|
|
|
|
fprintf(fp, "\\%03o", *s);
|
|
|
|
else
|
|
|
|
putc(*s, fp);
|
|
|
|
fputs("\"\n", fp);
|
|
|
|
}
|
2000-04-24 22:22:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fclose(fp);
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void Fl_Type::write_static() {}
|
|
|
|
void Fl_Type::write_code1() {
|
|
|
|
write_h("// Header for %s\n", title());
|
|
|
|
write_c("// Code for %s\n", title());
|
|
|
|
}
|
|
|
|
void Fl_Type::write_code2() {}
|
1998-10-21 20:29:01 +04:00
|
|
|
|
|
|
|
//
|
2005-02-06 19:28:36 +03:00
|
|
|
// End of "$Id$".
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|