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.
This commit is contained in:
parent
acc96cdf56
commit
c86ca1a9fc
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user