summaryrefslogtreecommitdiff
path: root/fluid
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2023-11-06 11:36:02 +0100
committerMatthias Melcher <github@matthiasm.com>2023-11-06 11:36:02 +0100
commitc86ca1a9fc3bb8b09eb429458b2ecf68b62cd1de (patch)
tree8c60474e660a584412fd590ef347c05ded35ac90 /fluid
parentacc96cdf5666a37ff87d0038af74c1af1628ca11 (diff)
FLUID: '\r' (CR) is skipped when reading project files
Project and code files are now always written with LF instead of CRLF, even on MSWindows machines.
Diffstat (limited to 'fluid')
-rw-r--r--fluid/code.cxx9
-rw-r--r--fluid/file.cxx26
-rw-r--r--fluid/file.h4
-rw-r--r--fluid/fluid.cxx4
-rw-r--r--fluid/mergeback.cxx2
5 files changed, 22 insertions, 23 deletions
diff --git a/fluid/code.cxx b/fluid/code.cxx
index 8651ca868..09d1eb257 100644
--- a/fluid/code.cxx
+++ b/fluid/code.cxx
@@ -61,7 +61,7 @@ int write_strings(const Fl_String &filename) {
Fl_Widget_Type *w;
int i;
- FILE *fp = fl_fopen(filename.c_str(), "w");
+ FILE *fp = fl_fopen(filename.c_str(), "wb");
if (!fp) return 1;
switch (g_project.i18n_type) {
@@ -743,22 +743,19 @@ Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) {
*/
int Fd_Code_Writer::write_code(const char *s, const char *t, bool to_sourceview) {
write_sourceview = to_sourceview;
- const char *filemode = "w";
- if (write_sourceview)
- filemode = "wb";
delete id_root; id_root = 0;
indentation = 0;
current_class = 0L;
current_widget_class = 0L;
if (!s) code_file = stdout;
else {
- FILE *f = fl_fopen(s, filemode);
+ FILE *f = fl_fopen(s, "wb");
if (!f) return 0;
code_file = f;
}
if (!t) header_file = stdout;
else {
- FILE *f = fl_fopen(t, filemode);
+ FILE *f = fl_fopen(t, "wb");
if (!f) {fclose(code_file); return 0;}
header_file = f;
}
diff --git a/fluid/file.cxx b/fluid/file.cxx
index 317fc0469..7c8e9e9cb 100644
--- a/fluid/file.cxx
+++ b/fluid/file.cxx
@@ -143,7 +143,7 @@ int Fd_Project_Reader::open_read(const char *s) {
fin = stdin;
fname = "stdin";
} else {
- FILE *f = fl_fopen(s, "r");
+ FILE *f = fl_fopen(s, "rb");
if (!f)
return 0;
fin = f;
@@ -181,7 +181,7 @@ const char *Fd_Project_Reader::filename_name() {
*/
int Fd_Project_Reader::read_quoted() { // read whatever character is after a \ .
int c,d,x;
- switch(c = fgetc(fin)) {
+ switch(c = nextchar()) {
case '\n': lineno++; return -1;
case 'a' : return('\a');
case 'b' : return('\b');
@@ -192,7 +192,7 @@ int Fd_Project_Reader::read_quoted() { // read whatever character is after
case 'v' : return('\v');
case 'x' : /* read hex */
for (c=x=0; x<3; x++) {
- int ch = fgetc(fin);
+ int ch = nextchar();
d = hexdigit(ch);
if (d > 15) {ungetc(ch,fin); break;}
c = (c<<4)+d;
@@ -202,7 +202,7 @@ int Fd_Project_Reader::read_quoted() { // read whatever character is after
if (c<'0' || c>'7') break;
c -= '0';
for (x=0; x<2; x++) {
- int ch = fgetc(fin);
+ int ch = nextchar();
d = hexdigit(ch);
if (d>7) {ungetc(ch,fin); break;}
c = (c<<3)+d;
@@ -512,11 +512,11 @@ const char *Fd_Project_Reader::read_word(int wantbrace) {
// skip all the whitespace before it:
for (;;) {
- x = getc(fin);
+ x = nextchar();
if (x < 0 && feof(fin)) { // eof
return 0;
} else if (x == '#') { // comment
- do x = getc(fin); while (x >= 0 && x != '\n');
+ do x = nextchar(); while (x >= 0 && x != '\n');
lineno++;
continue;
} else if (x == '\n') {
@@ -534,10 +534,10 @@ const char *Fd_Project_Reader::read_word(int wantbrace) {
int length = 0;
int nesting = 0;
for (;;) {
- x = getc(fin);
+ x = nextchar();
if (x<0) {read_error("Missing '}'"); break;}
else if (x == '#') { // embedded comment
- do x = getc(fin); while (x >= 0 && x != '\n');
+ do x = nextchar(); while (x >= 0 && x != '\n');
lineno++;
continue;
} else if (x == '\n') lineno++;
@@ -565,7 +565,7 @@ const char *Fd_Project_Reader::read_word(int wantbrace) {
else if (x<0 || isspace(x & 255) || x=='{' || x=='}' || x=='#') break;
buffer[length++] = x;
expand_buffer(length);
- x = getc(fin);
+ x = nextchar();
}
ungetc(x, fin);
buffer[length] = 0;
@@ -598,7 +598,7 @@ int Fd_Project_Reader::read_fdesign_line(const char*& name, const char*& value)
int x;
// find a colon:
for (;;) {
- x = getc(fin);
+ x = nextchar();
if (x < 0 && feof(fin)) return 0;
if (x == '\n') {length = 0; continue;} // no colon this line...
if (!isspace(x & 255)) {
@@ -612,7 +612,7 @@ int Fd_Project_Reader::read_fdesign_line(const char*& name, const char*& value)
// skip to start of value:
for (;;) {
- x = getc(fin);
+ x = nextchar();
if ((x < 0 && feof(fin)) || x == '\n' || !isspace(x & 255)) break;
}
@@ -622,7 +622,7 @@ int Fd_Project_Reader::read_fdesign_line(const char*& name, const char*& value)
else if (x == '\n') break;
buffer[length++] = x;
expand_buffer(length);
- x = getc(fin);
+ x = nextchar();
}
buffer[length] = 0;
name = buffer;
@@ -799,7 +799,7 @@ int Fd_Project_Writer::open_write(const char *s) {
if (!s) {
fout = stdout;
} else {
- FILE *f = fl_fopen(s,"w");
+ FILE *f = fl_fopen(s,"wb");
if (!f) return 0;
fout = f;
}
diff --git a/fluid/file.h b/fluid/file.h
index 3fabf244a..b2e3739a3 100644
--- a/fluid/file.h
+++ b/fluid/file.h
@@ -44,6 +44,8 @@ protected:
void expand_buffer(int length);
+ int nextchar() { for (;;) { int ret = fgetc(fin); if (ret!='\r') return ret; } }
+
public:
/// Holds the file version number after reading the "version" tag
double read_version;
@@ -67,7 +69,7 @@ public:
class Fd_Project_Writer
{
protected:
- // Project output file, mode "w" for files, "wb" for SourceView
+ // Project output file, always opened in "wb" mode
FILE *fout;
/// If set, one space is written before text unless the format starts with a newline character
int needspace;
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx
index 26bc5a500..fbfe5a870 100644
--- a/fluid/fluid.cxx
+++ b/fluid/fluid.cxx
@@ -946,7 +946,7 @@ bool new_project_from_template() {
char line[1024], *ptr, *next;
FILE *infile, *outfile;
- if ((infile = fl_fopen(tname, "r")) == NULL) {
+ if ((infile = fl_fopen(tname, "rb")) == NULL) {
fl_alert("Error reading template file \"%s\":\n%s", tname,
strerror(errno));
set_modflag(0);
@@ -954,7 +954,7 @@ bool new_project_from_template() {
return false;
}
- if ((outfile = fl_fopen(cutfname(1), "w")) == NULL) {
+ if ((outfile = fl_fopen(cutfname(1), "wb")) == NULL) {
fl_alert("Error writing buffer file \"%s\":\n%s", cutfname(1),
strerror(errno));
fclose(infile);
diff --git a/fluid/mergeback.cxx b/fluid/mergeback.cxx
index 4b3bf2807..9e830e152 100644
--- a/fluid/mergeback.cxx
+++ b/fluid/mergeback.cxx
@@ -443,7 +443,7 @@ int Fd_Mergeback::apply() {
*/
int Fd_Mergeback::merge_back(const Fl_String &s, const Fl_String &p, int task) {
int ret = 0;
- code = fl_fopen(s.c_str(), "r");
+ code = fl_fopen(s.c_str(), "rb");
if (!code) return -2;
do { // no actual loop, just make sure we close the code file
if (task == FD_MERGEBACK_ANALYSE) {