Browse Source

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
pull/49/head
Matthias Melcher 15 years ago
parent
commit
1e77c19688
  1. 1
      CHANGES
  2. 2
      fluid/Fl_Function_Type.cxx
  3. 4
      fluid/Fluid_Image.cxx
  4. 6
      fluid/code.cxx
  5. 4
      fluid/file.cxx
  6. 13
      fluid/fluid.cxx
  7. 3
      src/Fl_BMP_Image.cxx
  8. 2
      src/Fl_File_Icon2.cxx
  9. 3
      src/Fl_JPEG_Image.cxx
  10. 4
      test/colbrowser.cxx
  11. 4
      test/demo.cxx
  12. 4
      test/file_chooser.cxx

1
CHANGES

@ -1,5 +1,6 @@
CHANGES IN FLTK 1.3.0 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) - Fixed ARM Unicode cross compilation issue (STR #2432)
- Improved support for faulty X11 clients (STR #2385) - Improved support for faulty X11 clients (STR #2385)
- Fixed xclass support for Fl_Window (STR #2053) - Fixed xclass support for Fl_Window (STR #2053)

2
fluid/Fl_Function_Type.cxx

@ -879,7 +879,7 @@ void Fl_Data_Type::write_code1() {
int nData = -1; int nData = -1;
// path should be set correctly already // path should be set correctly already
if (filename_ && !write_sourceview) { if (filename_ && !write_sourceview) {
FILE *f = fopen(filename_, "rb"); FILE *f = fl_fopen(filename_, "rb");
if (!f) { if (!f) {
message = "Can't include binary file. Can't open"; message = "Can't include binary file. Can't open";
} else { } else {

4
fluid/Fluid_Image.cxx

@ -111,7 +111,7 @@ void Fluid_Image::write_static() {
write_c("static unsigned char %s[] =\n", write_c("static unsigned char %s[] =\n",
unique_id(this, "idata", fl_filename_name(name()), 0)); unique_id(this, "idata", fl_filename_name(name()), 0));
FILE *f = fopen(name(), "rb"); FILE *f = fl_fopen(name(), "rb");
if (!f) { if (!f) {
// message = "Can't include binary file. Can't open"; // message = "Can't include binary file. Can't open";
} else { } else {
@ -180,7 +180,7 @@ Fluid_Image* Fluid_Image::find(const char *iname) {
// no, so now see if the file exists: // no, so now see if the file exists:
goto_source_dir(); goto_source_dir();
FILE *f = fopen(iname,"rb"); FILE *f = fl_fopen(iname,"rb");
if (!f) { if (!f) {
read_error("%s : %s",iname,strerror(errno)); read_error("%s : %s",iname,strerror(errno));
leave_source_dir(); leave_source_dir();

6
fluid/code.cxx

@ -354,13 +354,13 @@ int write_code(const char *s, const char *t) {
current_widget_class = 0L; current_widget_class = 0L;
if (!s) code_file = stdout; if (!s) code_file = stdout;
else { else {
FILE *f = fopen(s, filemode); FILE *f = fl_fopen(s, filemode);
if (!f) return 0; if (!f) return 0;
code_file = f; code_file = f;
} }
if (!t) header_file = stdout; if (!t) header_file = stdout;
else { else {
FILE *f = fopen(t, filemode); FILE *f = fl_fopen(t, filemode);
if (!f) {fclose(code_file); return 0;} if (!f) {fclose(code_file); return 0;}
header_file = f; header_file = f;
} }
@ -468,7 +468,7 @@ int write_code(const char *s, const char *t) {
} }
int write_strings(const char *sfile) { int write_strings(const char *sfile) {
FILE *fp = fopen(sfile, "w"); FILE *fp = fl_fopen(sfile, "w");
Fl_Type *p; Fl_Type *p;
Fl_Widget_Type *w; Fl_Widget_Type *w;
int i; int i;

4
fluid/file.cxx

@ -43,7 +43,7 @@ static FILE *fout;
int open_write(const char *s) { int open_write(const char *s) {
if (!s) {fout = stdout; return 1;} if (!s) {fout = stdout; return 1;}
FILE *f = fopen(s,"w"); FILE *f = fl_fopen(s,"w");
if (!f) return 0; if (!f) return 0;
fout = f; fout = f;
return 1; return 1;
@ -135,7 +135,7 @@ static const char *fname;
int open_read(const char *s) { int open_read(const char *s) {
lineno = 1; lineno = 1;
if (!s) {fin = stdin; fname = "stdin"; return 1;} if (!s) {fin = stdin; fname = "stdin"; return 1;}
FILE *f = fopen(s,"r"); FILE *f = fl_fopen(s,"r");
if (!f) return 0; if (!f) return 0;
fin = f; fin = f;
fname = s; fname = s;

13
fluid/fluid.cxx

@ -326,7 +326,7 @@ void save_template_cb(Fl_Widget *, void *) {
FILE *fp; FILE *fp;
if ((fp = fopen(filename, "wb")) == NULL) { if ((fp = fl_fopen(filename, "wb")) == NULL) {
delete[] pixels; delete[] pixels;
fl_alert("Error writing %s: %s", filename, strerror(errno)); fl_alert("Error writing %s: %s", filename, strerror(errno));
return; return;
@ -354,7 +354,7 @@ void save_template_cb(Fl_Widget *, void *) {
# if 0 // The original PPM output code... # if 0 // The original PPM output code...
strcpy(ext, ".ppm"); strcpy(ext, ".ppm");
fp = fopen(filename, "wb"); fp = fl_fopen(filename, "wb");
fprintf(fp, "P6\n%d %d 255\n", w, h); fprintf(fp, "P6\n%d %d 255\n", w, h);
fwrite(pixels, w * h, 3, fp); fwrite(pixels, w * h, 3, fp);
fclose(fp); fclose(fp);
@ -595,7 +595,7 @@ void new_cb(Fl_Widget *, void *v) {
char line[1024], *ptr, *next; char line[1024], *ptr, *next;
FILE *infile, *outfile; 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, fl_alert("Error reading template file \"%s\":\n%s", tname,
strerror(errno)); strerror(errno));
set_modflag(0); set_modflag(0);
@ -603,7 +603,7 @@ void new_cb(Fl_Widget *, void *v) {
return; 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), fl_alert("Error writing buffer file \"%s\":\n%s", cutfname(1),
strerror(errno)); strerror(errno));
fclose(infile); fclose(infile);
@ -1252,7 +1252,7 @@ void print_cb(Fl_Return_Button *, void *) {
"Replace", NULL, outname) == 0) outname = NULL; "Replace", NULL, outname) == 0) outname = NULL;
} }
if (outname) outfile = fopen(outname, "w"); if (outname) outfile = fl_fopen(outname, "w");
else outfile = NULL; else outfile = NULL;
} }
@ -1909,8 +1909,9 @@ public:
Fl_Process() {_fpt= NULL;} Fl_Process() {_fpt= NULL;}
~Fl_Process() {if (_fpt) close();} ~Fl_Process() {if (_fpt) close();}
// FIXME: popen needs the utf8 equivalen fl_popen
FILE * popen (const char *cmd, const char *mode="r"); 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(); int close();
FILE * desc() const { return _fpt;} // non null if file is open FILE * desc() const { return _fpt;} // non null if file is open

3
src/Fl_BMP_Image.cxx

@ -35,6 +35,7 @@
// //
#include <FL/Fl_BMP_Image.H> #include <FL/Fl_BMP_Image.H>
#include <FL/fl_utf8.h>
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -93,7 +94,7 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
// Open the file... // Open the file...
if ((fp = fopen(bmp, "rb")) == NULL) return; if ((fp = fl_fopen(bmp, "rb")) == NULL) return;
// Get the header... // Get the header...
byte = (uchar)getc(fp); // Check "BM" sync chars byte = (uchar)getc(fp); // Check "BM" sync chars

2
src/Fl_File_Icon2.cxx

@ -853,7 +853,7 @@ load_kde_mimelnk(const char *filename, // I - mimelnk filename
pattern[0] = '\0'; pattern[0] = '\0';
iconfilename[0] = '\0'; iconfilename[0] = '\0';
if ((fp = fopen(filename, "rb")) != NULL) { if ((fp = fl_fopen(filename, "rb")) != NULL) {
while (fgets(tmp, sizeof(tmp), fp)) { while (fgets(tmp, sizeof(tmp), fp)) {
if ((val = get_kde_val(tmp, "Icon")) != NULL) if ((val = get_kde_val(tmp, "Icon")) != NULL)
strlcpy(iconfilename, val, sizeof(iconfilename)); strlcpy(iconfilename, val, sizeof(iconfilename));

3
src/Fl_JPEG_Image.cxx

@ -35,6 +35,7 @@
// //
#include <FL/Fl_JPEG_Image.H> #include <FL/Fl_JPEG_Image.H>
#include <FL/fl_utf8.h>
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -117,7 +118,7 @@ Fl_JPEG_Image::Fl_JPEG_Image(const char *filename) // I - File to load
array = (uchar *)0; array = (uchar *)0;
// Open the image file... // 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... // Setup the decompressor info and read the header...
dinfo.err = jpeg_std_error((jpeg_error_mgr *)&jerr); dinfo.err = jpeg_std_error((jpeg_error_mgr *)&jerr);

4
test/colbrowser.cxx

@ -149,9 +149,9 @@ load_browser(char *fname)
int r, g, b, lr = -1 , lg = -1, lb = -1; int r, g, b, lr = -1 , lg = -1, lb = -1;
char name[256], buf[256]; char name[256], buf[256];
#ifdef __EMX__ #ifdef __EMX__
if (!(fp = fopen(__XOS2RedirRoot(fname), "r"))) if (!(fp = fl_fopen(__XOS2RedirRoot(fname), "r")))
#else #else
if (!(fp = fopen(fname, "r"))) if (!(fp = fl_fopen(fname, "r")))
#endif #endif
{ {
fl_alert("%s\n%s\n%s","Load", fname, "Can't open"); fl_alert("%s\n%s\n%s","Load", fname, "Can't open");

4
test/demo.cxx

@ -434,7 +434,7 @@ int load_the_menu(const char* fname)
FILE *fin = 0; FILE *fin = 0;
char line[256], mname[64],iname[64],cname[64]; char line[256], mname[64],iname[64],cname[64];
int i,j, mi = 0; int i,j, mi = 0;
fin = fopen(fname,"r"); fin = fl_fopen(fname,"r");
if (fin == NULL) if (fin == NULL)
{ {
#if defined ( __APPLE__ ) #if defined ( __APPLE__ )
@ -445,7 +445,7 @@ int load_the_menu(const char* fname)
pos = strrchr(fname,'/'); pos = strrchr(fname,'/');
if (!pos) return 0; if (!pos) return 0;
strcpy(pos,"/Resources/demo.menu"); strcpy(pos,"/Resources/demo.menu");
fin = fopen(fname,"r"); fin = fl_fopen(fname,"r");
#endif #endif
} }
// if "fin" is still NULL, we will read the menu from the string array in the // if "fin" is still NULL, we will read the menu from the string array in the

4
test/file_chooser.cxx

@ -304,8 +304,8 @@ ps_check(const char *name, // I - Name of file
sprintf(outname, "%s/.preview.ps", home ? home : ""); sprintf(outname, "%s/.preview.ps", home ? home : "");
if (strcmp(name, outname) != 0) { if (strcmp(name, outname) != 0) {
in = fopen(name, "rb"); in = fl_fopen(name, "rb");
out = fopen(outname, "wb"); out = fl_fopen(outname, "wb");
page = 0; page = 0;
while (fgets(line, sizeof(line), in) != NULL) { while (fgets(line, sizeof(line), in) != NULL) {

Loading…
Cancel
Save