[Gridflow-cvs] [svn] commit: r3323 - in /trunk/format: aalib.c jpeg.c main.c netpbm.c png.c quicktimehw.c x11.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Fri Mar 28 11:54:57 EDT 2008


Author: matju
Date: Fri Mar 28 11:54:57 2008
New Revision: 3323

Log:
derubify a bit

Modified:
    trunk/format/aalib.c
    trunk/format/jpeg.c
    trunk/format/main.c
    trunk/format/netpbm.c
    trunk/format/png.c
    trunk/format/quicktimehw.c
    trunk/format/x11.c

Modified: trunk/format/aalib.c
==============================================================================
--- trunk/format/aalib.c (original)
+++ trunk/format/aalib.c Fri Mar 28 11:54:57 2008
@@ -26,7 +26,7 @@
 #include <aalib.h>
 
 /* MINNOR is a typo in aalib.h, sorry */
-typedef 
+typedef
 #if AA_LIB_MINNOR == 2
       int
 #else
@@ -143,16 +143,8 @@
 	post("aalib image size: %s",(new Dim(3,v))->to_s());
 }
 
-\end class FormatAALib {
-
-	Ruby drivers = rb_ivar_set(rself,SI(@drivers),rb_hash_new());
-	const aa_driver *const *p = aa_drivers;
-	for (; *p; p++) {
-		rb_hash_aset(drivers,ID2SYM(rb_intern((*p)->shortname)), PTR2FIX(*p));
-	}
-// IEVAL(rself,"GridFlow.post('aalib supports: %s', @drivers.keys.join(', '))");
-	install_format("#io.aalib",2,"");
-}
+/*const aa_driver *const *p = aa_drivers; for (; *p; p++) rb_hash_aset(drivers,ID2SYM(rb_intern((*p)->shortname)), PTR2FIX(*p));*/
+\end class FormatAALib {install_format("#io.aalib",2,"");}
 void startup_aalib () {
 	\startall
 }

Modified: trunk/format/jpeg.c
==============================================================================
--- trunk/format/jpeg.c (original)
+++ trunk/format/jpeg.c Fri Mar 28 11:54:57 2008
@@ -38,7 +38,7 @@
 	struct jpeg_compress_struct cjpeg;
 	struct jpeg_decompress_struct djpeg;
 	struct jpeg_error_mgr jerr;
-	\decl void initialize (Symbol mode, String filename);
+	\decl void initialize (t_symbol *mode, string filename);
 	\decl 0 bang ();
 	\decl 0 quality (short quality);
 	\grin 0 int
@@ -111,7 +111,7 @@
 	jpeg_set_quality(&cjpeg,quality,false);
 }
 
-\def void initialize (Symbol mode, String filename) {
+\def void initialize (t_symbol *mode, string filename) {
 	SUPER;
 	Format::_0_open(0,0,mode,filename);
 	uint32 mask[3] = {0x0000ff,0x00ff00,0xff0000};

Modified: trunk/format/main.c
==============================================================================
--- trunk/format/main.c (original)
+++ trunk/format/main.c Fri Mar 28 11:54:57 2008
@@ -70,11 +70,11 @@
 
 \class SuffixLookup : FObject {
   \decl void initialize ();
-  \decl 0 symbol (String str);
+  \decl 0 symbol (t_symbol *str);
 };
 \def void initialize () {}
-\def 0 symbol (String str) {
-	char *s = strdup(rb_str_ptr(str));
+\def 0 symbol (t_symbol *str) {
+	char *s = strdup(str->s_name);
 	char *t = strrchr(s,'.');
 	if (!t) outlet_symbol(bself->out[2],gensym(s));
 	else {
@@ -90,15 +90,13 @@
 // not in use
 \class FormatLookup : FObject {
   \decl void initialize ();
-  \decl 0 symbol (String str);
+  \decl 0 symbol (string str);
 };
 \def void initialize () {}
-\def 0 symbol (String str) {
-	char *s = strdup(rb_str_ptr(str));
-	std::map<std::string,std::string>::iterator u = format_table.find(std::string(s));
+\def 0 symbol (string str) {
+	std::map<std::string,std::string>::iterator u = format_table.find(str);
 	if (u!=format_table.end()) outlet_symbol(bself->out[0],gensym((char *)u->second.data()));
 	else outlet_bang(bself->out[0]);
-	free(s);
 }
 \end class FormatLookup {install("gf.format_lookup",1,1);}
 
@@ -116,16 +114,15 @@
 //	//end or raise "Format '#{self.class.instance_eval{@symbol_name}}' does not support mode '#{mode}'"
 }
 
-\def 0 open(Symbol mode, String filename) {
-	if (TYPE(mode)==T_STRING) mode=ID2SYM(rb_intern(rb_str_ptr(mode))); // source_filter doesn't figure this out.
+\def 0 open(t_symbol *mode, string filename) {
 	const char *fmode;
-	if (mode==SYM(in))  fmode="r"; else
-	if (mode==SYM(out)) fmode="w"; else
+	if (mode==gensym("in"))  fmode="r"; else
+	if (mode==gensym("out")) fmode="w"; else
 	RAISE("bad mode");
 	if (f) _0_close(0,0);
-	if (mode==SYM(in)) {filename = rb_funcall(mGridFlow,SI(find_file),1,filename);}
-	f = fopen(rb_str_ptr(filename),fmode);
-	if (!f) RAISE("can't open file '%s': %s",rb_str_ptr(filename),strerror(errno));
+	if (mode==gensym("in")) {filename = gf_find_file(filename);}
+	f = fopen(filename.data(),fmode);
+	if (!f) RAISE("can't open file '%s': %s",filename.data(),strerror(errno));
 	fd = fileno(f);
 //	case gzfile:
 //		if (mode==SYM(in)) {filename = GridFlow.find_file(filename);}
@@ -183,7 +180,7 @@
 	NumberTypeE nt;
 	P<Dim> headerless; // if null: headerful; if Dim: it is the assumed dimensions of received grids
 	\grin 0
-	\decl void initialize(Symbol mode, String filename);
+	\decl void initialize(t_symbol *mode, string filename);
 	\decl 0 bang ();
 	\decl 0 headerless_m (...);
 	\decl 0 headerful ();
@@ -193,7 +190,7 @@
 //	\decl void raw_open_gzip_out(String filename);
 };
 
-\def void initialize(Symbol mode, String filename) {
+\def void initialize(t_symbol *mode, string filename) {
 	SUPER;
 	strncpy(head.magic,is_le()?"\7fgrid":"\7fGRID",5);
 	head.type = 32;

Modified: trunk/format/netpbm.c
==============================================================================
--- trunk/format/netpbm.c (original)
+++ trunk/format/netpbm.c Fri Mar 28 11:54:57 2008
@@ -29,15 +29,12 @@
 \class FormatNetPBM : Format {
 	struct pam inpam, outpam;
 	\grin 0
-	\decl void initialize(String mode, String filename);
+	\decl void initialize(t_symbol *mode, string filename);
 	\decl 0 bang ();
 };
-\def void initialize(String mode, String filename) {
+\def void initialize(t_symbol *mode, string filename) {
 	SUPER;
 	Format::_0_open(0,0,mode,filename);
-	Ruby stream = rb_ivar_get(rself,SI(@stream));
-	fd = NUM2INT(rb_funcall(stream,SI(fileno),0));
-	f = fdopen(fd,mode==SYM(in)?"r":"w");
 	memset(& inpam,sizeof(pam),0);
 	memset(&outpam,sizeof(pam),0);
 }

Modified: trunk/format/png.c
==============================================================================
--- trunk/format/png.c (original)
+++ trunk/format/png.c Fri Mar 28 11:54:57 2008
@@ -34,7 +34,7 @@
 	png_structp png;
 	png_infop info;
 	FormatPNG () : bit_packing(0), png(0) {}
-	\decl void initialize (Symbol mode, String filename);
+	\decl void initialize (t_symbol *mode, string filename);
 	\decl 0 bang ();
 	\grin 0 int
 };
@@ -106,7 +106,7 @@
 	png_destroy_read_struct(&png, &info, NULL);
 }
 
-\def void initialize (Symbol mode, String filename) {
+\def void initialize (t_symbol *mode, string filename) {
 	SUPER;
 	Format::_0_open(0,0,mode,filename);
 	uint32 mask[3] = {0x0000ff,0x00ff00,0xff0000};

Modified: trunk/format/quicktimehw.c
==============================================================================
--- trunk/format/quicktimehw.c (original)
+++ trunk/format/quicktimehw.c Fri Mar 28 11:54:57 2008
@@ -42,7 +42,7 @@
 	int jpeg_quality; // in theory we shouldn't need this, but...
 	FormatQuickTimeHW() : track(0), dim(0), codec(QUICKTIME_RAW), 
 		started(false), force(0), framerate(29.97), bit_packing(0), jpeg_quality(75) {}
-	\decl void initialize (Symbol mode, String filename);
+	\decl void initialize (t_symbol *mode, string filename);
 	\decl 0 close ();
 	\decl 0 bang ();
 	\decl 0 seek (int frame);
@@ -183,13 +183,13 @@
 }
 
 // libquicktime may be nice, but it won't take a filehandle, only filename
-\def void initialize (Symbol mode, String filename) {
+\def void initialize (t_symbol *mode, string filename) {
 	SUPER;
-	filename = rb_funcall(mGridFlow,SI(find_file),1,filename);
-	anim = quicktime_open(rb_str_ptr(filename),mode==SYM(in),mode==SYM(out));
+	filename = gf_find_file(filename);
+	anim = quicktime_open(filename.data(),mode==gensym("in"),mode==gensym("out"));
 	if (!anim) RAISE("can't open file `%s': %s (or some other reason that libquicktime won't tell us)",
-		rb_str_ptr(filename), strerror(errno));
-	if (mode==SYM(in)) {
+		filename.data(), strerror(errno));
+	if (mode==gensym("in")) {
 		length = quicktime_video_length(anim,track);
 		post("quicktime: codec=%s height=%d width=%d depth=%d framerate=%f",
 			quicktime_video_compressor(anim,track),

Modified: trunk/format/x11.c
==============================================================================
--- trunk/format/x11.c (original)
+++ trunk/format/x11.c Fri Mar 28 11:54:57 2008
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <string>
 #include <sys/time.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -70,6 +71,7 @@
 	bool lock_size;
 	bool override_redirect;
 	t_clock *clock;
+	std::string title;
 #ifdef HAVE_X11_SHARED_MEMORY
 	XShmSegmentInfo *shm_info; /* to share memory with X11/Unix */
 #endif
@@ -107,7 +109,7 @@
 	\decl 0 set_geometry (int y, int x, int sy, int sx);
 	\decl 0 move (int y, int x);
 	\decl 0 transfer (Symbol s);
-	\decl 0 title (String s=Qnil);
+	\decl 0 title (string title="");
 	\decl 0 warp (int y, int x);
 	\grin 0 int
 };
@@ -143,14 +145,13 @@
 
 /* window manager hints, defines the window as non-resizable */
 void FormatX11::set_wm_hints () {
-	Ruby title = rb_ivar_get(rself,SI(@title));
 	if (!is_owner) return;
 	XWMHints wmh;
 	char buf[256],*bufp=buf;
-	if (title==Qnil) {
+	if (title=="") {
 		sprintf(buf,"GridFlow (%d,%d,%d)",dim->get(0),dim->get(1),dim->get(2));
 	} else {
-		sprintf(buf,"%.255s",rb_str_ptr(title));
+		sprintf(buf,"%.255s",title.data());
 	}
 	XTextProperty wtitle; XStringListToTextProperty((char **)&bufp, 1, &wtitle);
 	XSizeHints sh;
@@ -552,15 +553,11 @@
 	XFlush(display);
 }
 
-\def 0 title (String s=Qnil) {
-	rb_ivar_set(rself,SI(@title),s);
-	set_wm_hints();
-}
+\def 0 title (string title="") {this->title = title; set_wm_hints();}
 
 \def void initialize (...) {
 	int sy=240, sx=320; // defaults
 	SUPER;
-	rb_ivar_set(rself,SI(@title),Qnil);
 	argv++, argc--;
 	VALUE domain = argc<1 ? SYM(here) : argv[0];
 	int i;



More information about the Gridflow-cvs mailing list