From 1e77c19688a76f96813d76b68323a6030aed8230 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 18 Nov 2010 20:00:01 +0000 Subject: [PATCH] Fixed file access code to use UTF-8 strings (STR #2440) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7874 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 1 + fluid/Fl_Function_Type.cxx | 2 +- fluid/Fluid_Image.cxx | 4 ++-- fluid/code.cxx | 6 +++--- fluid/file.cxx | 4 ++-- fluid/fluid.cxx | 13 +++++++------ src/Fl_BMP_Image.cxx | 3 ++- src/Fl_File_Icon2.cxx | 2 +- src/Fl_JPEG_Image.cxx | 3 ++- test/colbrowser.cxx | 4 ++-- test/demo.cxx | 4 ++-- test/file_chooser.cxx | 4 ++-- 12 files changed, 27 insertions(+), 23 deletions(-) diff --git a/CHANGES b/CHANGES index 82a863959..447266289 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ CHANGES IN FLTK 1.3.0 + - Fixed file access code to use UTF-8 strings (STR #2440) - Fixed ARM Unicode cross compilation issue (STR #2432) - Improved support for faulty X11 clients (STR #2385) - Fixed xclass support for Fl_Window (STR #2053) diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx index e1749f596..614f783b8 100644 --- a/fluid/Fl_Function_Type.cxx +++ b/fluid/Fl_Function_Type.cxx @@ -879,7 +879,7 @@ void Fl_Data_Type::write_code1() { int nData = -1; // path should be set correctly already if (filename_ && !write_sourceview) { - FILE *f = fopen(filename_, "rb"); + FILE *f = fl_fopen(filename_, "rb"); if (!f) { message = "Can't include binary file. Can't open"; } else { diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx index 244dc812e..4fa3bf308 100644 --- a/fluid/Fluid_Image.cxx +++ b/fluid/Fluid_Image.cxx @@ -111,7 +111,7 @@ void Fluid_Image::write_static() { write_c("static unsigned char %s[] =\n", unique_id(this, "idata", fl_filename_name(name()), 0)); - FILE *f = fopen(name(), "rb"); + FILE *f = fl_fopen(name(), "rb"); if (!f) { // message = "Can't include binary file. Can't open"; } else { @@ -180,7 +180,7 @@ Fluid_Image* Fluid_Image::find(const char *iname) { // no, so now see if the file exists: goto_source_dir(); - FILE *f = fopen(iname,"rb"); + FILE *f = fl_fopen(iname,"rb"); if (!f) { read_error("%s : %s",iname,strerror(errno)); leave_source_dir(); diff --git a/fluid/code.cxx b/fluid/code.cxx index 2e55d9f7a..c235e25d1 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -354,13 +354,13 @@ int write_code(const char *s, const char *t) { current_widget_class = 0L; if (!s) code_file = stdout; else { - FILE *f = fopen(s, filemode); + FILE *f = fl_fopen(s, filemode); if (!f) return 0; code_file = f; } if (!t) header_file = stdout; else { - FILE *f = fopen(t, filemode); + FILE *f = fl_fopen(t, filemode); if (!f) {fclose(code_file); return 0;} header_file = f; } @@ -468,7 +468,7 @@ int write_code(const char *s, const char *t) { } int write_strings(const char *sfile) { - FILE *fp = fopen(sfile, "w"); + FILE *fp = fl_fopen(sfile, "w"); Fl_Type *p; Fl_Widget_Type *w; int i; diff --git a/fluid/file.cxx b/fluid/file.cxx index d5168a7ee..beee3f4da 100644 --- a/fluid/file.cxx +++ b/fluid/file.cxx @@ -43,7 +43,7 @@ static FILE *fout; int open_write(const char *s) { if (!s) {fout = stdout; return 1;} - FILE *f = fopen(s,"w"); + FILE *f = fl_fopen(s,"w"); if (!f) return 0; fout = f; return 1; @@ -135,7 +135,7 @@ static const char *fname; int open_read(const char *s) { lineno = 1; if (!s) {fin = stdin; fname = "stdin"; return 1;} - FILE *f = fopen(s,"r"); + FILE *f = fl_fopen(s,"r"); if (!f) return 0; fin = f; fname = s; diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx index e9f13b271..3ecdd293f 100644 --- a/fluid/fluid.cxx +++ b/fluid/fluid.cxx @@ -326,7 +326,7 @@ void save_template_cb(Fl_Widget *, void *) { FILE *fp; - if ((fp = fopen(filename, "wb")) == NULL) { + if ((fp = fl_fopen(filename, "wb")) == NULL) { delete[] pixels; fl_alert("Error writing %s: %s", filename, strerror(errno)); return; @@ -354,7 +354,7 @@ void save_template_cb(Fl_Widget *, void *) { # if 0 // The original PPM output code... strcpy(ext, ".ppm"); - fp = fopen(filename, "wb"); + fp = fl_fopen(filename, "wb"); fprintf(fp, "P6\n%d %d 255\n", w, h); fwrite(pixels, w * h, 3, fp); fclose(fp); @@ -595,7 +595,7 @@ void new_cb(Fl_Widget *, void *v) { char line[1024], *ptr, *next; FILE *infile, *outfile; - if ((infile = fopen(tname, "r")) == NULL) { + if ((infile = fl_fopen(tname, "r")) == NULL) { fl_alert("Error reading template file \"%s\":\n%s", tname, strerror(errno)); set_modflag(0); @@ -603,7 +603,7 @@ void new_cb(Fl_Widget *, void *v) { return; } - if ((outfile = fopen(cutfname(1), "w")) == NULL) { + if ((outfile = fl_fopen(cutfname(1), "w")) == NULL) { fl_alert("Error writing buffer file \"%s\":\n%s", cutfname(1), strerror(errno)); fclose(infile); @@ -1252,7 +1252,7 @@ void print_cb(Fl_Return_Button *, void *) { "Replace", NULL, outname) == 0) outname = NULL; } - if (outname) outfile = fopen(outname, "w"); + if (outname) outfile = fl_fopen(outname, "w"); else outfile = NULL; } @@ -1909,8 +1909,9 @@ public: Fl_Process() {_fpt= NULL;} ~Fl_Process() {if (_fpt) close();} + // FIXME: popen needs the utf8 equivalen fl_popen FILE * popen (const char *cmd, const char *mode="r"); - //not necessary here: FILE * fopen (const char *file, const char *mode="r"); + //not necessary here: FILE * fl_fopen (const char *file, const char *mode="r"); int close(); FILE * desc() const { return _fpt;} // non null if file is open diff --git a/src/Fl_BMP_Image.cxx b/src/Fl_BMP_Image.cxx index 2b8693264..845f489b9 100644 --- a/src/Fl_BMP_Image.cxx +++ b/src/Fl_BMP_Image.cxx @@ -35,6 +35,7 @@ // #include +#include #include #include #include @@ -93,7 +94,7 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read // Open the file... - if ((fp = fopen(bmp, "rb")) == NULL) return; + if ((fp = fl_fopen(bmp, "rb")) == NULL) return; // Get the header... byte = (uchar)getc(fp); // Check "BM" sync chars diff --git a/src/Fl_File_Icon2.cxx b/src/Fl_File_Icon2.cxx index 410d8b91f..b5288a6b2 100644 --- a/src/Fl_File_Icon2.cxx +++ b/src/Fl_File_Icon2.cxx @@ -853,7 +853,7 @@ load_kde_mimelnk(const char *filename, // I - mimelnk filename pattern[0] = '\0'; iconfilename[0] = '\0'; - if ((fp = fopen(filename, "rb")) != NULL) { + if ((fp = fl_fopen(filename, "rb")) != NULL) { while (fgets(tmp, sizeof(tmp), fp)) { if ((val = get_kde_val(tmp, "Icon")) != NULL) strlcpy(iconfilename, val, sizeof(iconfilename)); diff --git a/src/Fl_JPEG_Image.cxx b/src/Fl_JPEG_Image.cxx index 054027b81..be5c23159 100644 --- a/src/Fl_JPEG_Image.cxx +++ b/src/Fl_JPEG_Image.cxx @@ -35,6 +35,7 @@ // #include +#include #include #include #include @@ -117,7 +118,7 @@ Fl_JPEG_Image::Fl_JPEG_Image(const char *filename) // I - File to load array = (uchar *)0; // Open the image file... - if ((fp = fopen(filename, "rb")) == NULL) return; + if ((fp = fl_fopen(filename, "rb")) == NULL) return; // Setup the decompressor info and read the header... dinfo.err = jpeg_std_error((jpeg_error_mgr *)&jerr); diff --git a/test/colbrowser.cxx b/test/colbrowser.cxx index 53018eb2e..a1ecd373c 100644 --- a/test/colbrowser.cxx +++ b/test/colbrowser.cxx @@ -149,9 +149,9 @@ load_browser(char *fname) int r, g, b, lr = -1 , lg = -1, lb = -1; char name[256], buf[256]; #ifdef __EMX__ - if (!(fp = fopen(__XOS2RedirRoot(fname), "r"))) + if (!(fp = fl_fopen(__XOS2RedirRoot(fname), "r"))) #else - if (!(fp = fopen(fname, "r"))) + if (!(fp = fl_fopen(fname, "r"))) #endif { fl_alert("%s\n%s\n%s","Load", fname, "Can't open"); diff --git a/test/demo.cxx b/test/demo.cxx index e4e2383a6..a71bb7a94 100644 --- a/test/demo.cxx +++ b/test/demo.cxx @@ -434,7 +434,7 @@ int load_the_menu(const char* fname) FILE *fin = 0; char line[256], mname[64],iname[64],cname[64]; int i,j, mi = 0; - fin = fopen(fname,"r"); + fin = fl_fopen(fname,"r"); if (fin == NULL) { #if defined ( __APPLE__ ) @@ -445,7 +445,7 @@ int load_the_menu(const char* fname) pos = strrchr(fname,'/'); if (!pos) return 0; strcpy(pos,"/Resources/demo.menu"); - fin = fopen(fname,"r"); + fin = fl_fopen(fname,"r"); #endif } // if "fin" is still NULL, we will read the menu from the string array in the diff --git a/test/file_chooser.cxx b/test/file_chooser.cxx index 872994e2c..0677d0d30 100644 --- a/test/file_chooser.cxx +++ b/test/file_chooser.cxx @@ -304,8 +304,8 @@ ps_check(const char *name, // I - Name of file sprintf(outname, "%s/.preview.ps", home ? home : ""); if (strcmp(name, outname) != 0) { - in = fopen(name, "rb"); - out = fopen(outname, "wb"); + in = fl_fopen(name, "rb"); + out = fl_fopen(outname, "wb"); page = 0; while (fgets(line, sizeof(line), in) != NULL) {