gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog extensions/fileio/fileio.h exte...


From: Udo Giacomozzi
Subject: [Gnash-commit] gnash ChangeLog extensions/fileio/fileio.h exte...
Date: Wed, 07 Mar 2007 12:44:54 +0000

CVSROOT:        /cvsroot/gnash
Module name:    gnash
Changes by:     Udo Giacomozzi <udog>   07/03/07 12:44:53

Modified files:
        .              : ChangeLog 
        extensions/fileio: fileio.h fileio.cpp 

Log message:
        experimental scandir() extension (may move to a separate extension)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2563&r2=1.2564
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/fileio/fileio.h?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/fileio/fileio.cpp?cvsroot=gnash&r1=1.4&r2=1.5

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/gnash/gnash/ChangeLog,v
retrieving revision 1.2563
retrieving revision 1.2564
diff -u -b -r1.2563 -r1.2564
--- ChangeLog   7 Mar 2007 10:59:42 -0000       1.2563
+++ ChangeLog   7 Mar 2007 12:44:53 -0000       1.2564
@@ -2,6 +2,8 @@
 
        * backend/render_handler_agg.cpp: fixed segfault #19223; set correct
          visiblerect; fixed Range2d.width() usage; fixed getMaxY() usage       
+       * extensions/fileio/fileio.{h,cpp}: implemented an experimental 
+         scandir() function (may move to a separate extension)         
 
 2007-03-06 Sandro Santilli <address@hidden>
 

Index: extensions/fileio/fileio.h
===================================================================
RCS file: /cvsroot/gnash/gnash/extensions/fileio/fileio.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- extensions/fileio/fileio.h  17 Feb 2007 15:26:46 -0000      1.1
+++ extensions/fileio/fileio.h  7 Mar 2007 12:44:53 -0000       1.2
@@ -48,6 +48,7 @@
     int fseek(long offset);
     int fseek(long offset, int whence);
     long ftell();
+    void scandir(const string dir, as_value* result);
 private:
     FILE        *_stream;
     std::string _filespec;

Index: extensions/fileio/fileio.cpp
===================================================================
RCS file: /cvsroot/gnash/gnash/extensions/fileio/fileio.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- extensions/fileio/fileio.cpp        22 Feb 2007 13:44:26 -0000      1.4
+++ extensions/fileio/fileio.cpp        7 Mar 2007 12:44:53 -0000       1.5
@@ -24,13 +24,15 @@
 #include <cstdio>
 #include <boost/algorithm/string/case_conv.hpp>
 
+#include <dirent.h> // used by scandir()
+
 #include "VM.h"
 #include "log.h"
 #include "fn_call.h"
 #include "as_object.h"
 #include "builtin_function.h" // need builtin_function
 #include "fileio.h"
-
+#include "array.h"  // used by scandir()
 
 using namespace std;
 
@@ -56,6 +58,12 @@
 void fileio_ftell(const fn_call& fn);
 void fileio_fseek(const fn_call& fn);
 
+// <Udo> I needed a scandir() function and implemented it here for simplicity.
+// Maybe this should be moved to a dedicated extension and a different class? 
+// The scandir() syntax comes from PHP, since the C syntax is not quite 
+// applicable in ActionScript.
+void fileio_scandir(const fn_call& fn);
+
 LogFile& dbglogfile = LogFile::getDefaultInstance();
 
 static void
@@ -80,6 +88,8 @@
     obj->set_member("fseek", &fileio_fseek);
     obj->set_member("ftell", &fileio_ftell);
     obj->set_member("fclose", &fileio_fclose);
+    
+    obj->set_member("scandir", &fileio_scandir);
 }
 
 static as_object*
@@ -169,7 +179,6 @@
 Fileio::fopen(string &filespec, string &mode)
 {
 //    GNASH_REPORT_FUNCTION;
-
     _stream = ::fopen(filespec.c_str(), mode.c_str());
     if (_stream) {
         return true;
@@ -263,6 +272,36 @@
 }
 
 void
+Fileio::scandir(const string dir, as_value* result) 
+{
+
+       struct dirent **namelist;
+       
+       int n = ::scandir(dir.c_str(), &namelist, 0, alphasort);
+       
+       if (n<0) {
+               result->set_bool(false);
+               return;
+       }
+       
+       as_array_object* array = new as_array_object(); 
+       as_value item;
+       
+       //array->resize(n);
+       // TODO: Looks like I can't set an array item by index since
+       // array::at() returns not a reference.
+       
+       for (int idx=0; idx<n; idx++) {
+               item.set_string(namelist[idx]->d_name);
+               array->push(item);
+               free(namelist[idx]);
+       }
+       free(namelist);
+       
+       result->set_as_object(array);
+}
+
+void
 fileio_fopen(const fn_call& fn)
 {
 //    GNASH_REPORT_FUNCTION;
@@ -418,6 +457,20 @@
     fn.result->set_int(i);
 }
 
+void
+fileio_scandir(const fn_call& fn)
+{
+//    GNASH_REPORT_FUNCTION;
+
+               // TODO: Check optional second parameter and sort array if it's 
true
+               // or missing.
+
+    Fileio *ptr = (Fileio*)fn.this_ptr;
+    assert(ptr);    
+    string str = fn.env->bottom(fn.first_arg_bottom_index).to_string();
+    ptr->scandir(str, fn.result);
+}
+
 std::auto_ptr<as_object>
 init_fileio_instance()
 {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]