diff --git a/externals/Makefile b/externals/Makefile index 220ccb28899fc9d47eae5291032cbf2553cec359..68119758fe35085a390d26bea268a15f4452a0c4 100644 --- a/externals/Makefile +++ b/externals/Makefile @@ -374,7 +374,7 @@ boids_clean: #------------------------------------------------------------------------------# # BSAYLOR bsaylor: - make -C $(externals_src)/bsaylor PD_PATH=$(pd_src) CFLAGS="$(CFLAGS)" + make -C $(externals_src)/bsaylor PD_PATH=$(pd_src) CFLAGS="$(CFLAGS) -fno-strict-aliasing" bsaylor_install: make -C $(externals_src)/bsaylor \ @@ -1300,7 +1300,7 @@ moocow_clean: #------------------------------------------------------------------------------# # MOONLIB moonlib: - make -C $(externals_src)/moonlib PD_PATH=$(pd_src) CFLAGS="$(CFLAGS)" + make -C $(externals_src)/moonlib PD_PATH=$(pd_src) CFLAGS="$(CFLAGS) -fno-strict-aliasing" moonlib_install: make -C $(externals_src)/moonlib DESTDIR="$(DESTDIR)" objectsdir="$(objectsdir)" install diff --git a/externals/OSCx/configure.ac b/externals/OSCx/configure.ac index 99807ac1646e4e6641f4bf5dd98d89d53777737a..683c0d42ef44ae3cea025ef4f110643220f51ae7 100644 --- a/externals/OSCx/configure.ac +++ b/externals/OSCx/configure.ac @@ -78,7 +78,7 @@ if test -z "$GCC"; then else case $host in *86*-linux*) - CFLAGS="$CFLAGS -DUNIX -Wall -Wimplicit -Wunused -Wmissing-prototypes -O2 -fPIC" + CFLAGS="$CFLAGS -DUNIX -Wall -Wimplicit -Wunused -Wmissing-prototypes -O2 -fno-strict-aliasing -fPIC" LDFLAGS="-Wl,--export-dynamic -shared" dnl we could test for bad glibc here, but don't pd_suffix=pd_linux @@ -115,7 +115,7 @@ else LIBS="-L../../../pd/src -L../../../pd/bin -L../../../pd/obj -lpd -lm -lwsock32" ;; *-*-darwin*) - CFLAGS="$CFLAGS -DUNIX -Wall -Wimplicit -Wunused -Wmissing-prototypes -O3 " + CFLAGS="$CFLAGS -DUNIX -Wall -Wimplicit -Wunused -Wmissing-prototypes -O3 -fno-strict-aliasing " LDFLAGS=" -bundle -bundle_loader ../../../pd/bin/pd-l2ork -flat_namespace " pd_suffix=pd_darwin LIBS="-lc -lm" diff --git a/externals/bsaylor/Makefile b/externals/bsaylor/Makefile index af62094581f6993acdbc948969acb2fa71dee5c6..bc2d032dc3bbdb4e8c0c4f1f51310376f62233b0 100644 --- a/externals/bsaylor/Makefile +++ b/externals/bsaylor/Makefile @@ -84,7 +84,7 @@ ifeq ($(UNAME),Darwin) CXX=$(IPHONE_BASE)/g++ ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6 - OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer -fno-strict-aliasing CFLAGS := $(IPHONE_CFLAGS) $(OPT_CFLAGS) $(CFLAGS) LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT) LIBS += -lc @@ -120,7 +120,7 @@ ifeq ($(UNAME),Linux) EXTENSION = pd_linux OS = linux PD_PATH = /usr - OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing CFLAGS += -fPIC LDFLAGS += -Wl,--export-dynamic -shared -fPIC LIBS += -lc @@ -133,7 +133,7 @@ ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME))) EXTENSION = dll OS = cygwin PD_PATH = $(cygpath $(PROGRAMFILES))/pd - OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing CFLAGS += LDFLAGS += -Wl,--export-dynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" LIBS += -lc -lpd @@ -146,7 +146,7 @@ ifeq (MINGW,$(findstring MINGW,$(UNAME))) EXTENSION = dll OS = windows PD_PATH = $(shell cd "$(PROGRAMFILES)"/pd && pwd) - OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing CFLAGS += -mms-bitfields LDFLAGS += -s -shared -Wl,--enable-auto-import LIBS += -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj" -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 diff --git a/externals/cxc/cxc_split.c b/externals/cxc/cxc_split.c index 0d55f3a8f4791b455db37e4619e89164b669b04f..d91f05cef9d36ac4677f088e0b6a924a899cd57f 100644 --- a/externals/cxc/cxc_split.c +++ b/externals/cxc/cxc_split.c @@ -30,8 +30,8 @@ typedef struct _split void split_symbol(t_split *x, t_symbol *s) { - t_atom* a; - split_anything(x, s, 0, a); + t_atom a; + split_anything(x, s, 0, &a); } diff --git a/externals/ext13/scramble~.c b/externals/ext13/scramble~.c index ec1f1e240763a7e678e9a3ac020e42abe80e12c3..e7b3d9d3a283c384c4f4c744c057e75f4a275160 100644 --- a/externals/ext13/scramble~.c +++ b/externals/ext13/scramble~.c @@ -4,13 +4,12 @@ #include <string.h> #include <math.h> #ifndef _WIN32 -#include <netinet/in.h> -#include <netdb.h> -#include <sys/errno.h> +#include <netinet/in.h> +#include <netdb.h> +#include <sys/errno.h> #include <sys/socket.h> -#else -#include <stdlib.h> #endif +#include <stdlib.h> /* ------------------------ scramble_tilde~ ----------------------------- */ @@ -115,10 +114,10 @@ t_int *scramble_tilde_perform(t_int *w) #ifndef _WIN32 t_float* out[x->x_channels]; t_float* in[x->x_channels]; -#else - t_float** out = (t_float**)malloc(x->x_channels*sizeof(t_float*)); - t_float** in = (t_float**)malloc(x->x_channels*sizeof(t_float*)); -#endif +#else + t_float** out = (t_float**)malloc(x->x_channels*sizeof(t_float*)); + t_float** in = (t_float**)malloc(x->x_channels*sizeof(t_float*)); +#endif float n_factor, frac, a, b, c, d, cminusb; int index; @@ -448,10 +447,10 @@ t_int *scramble_tilde_perform(t_int *w) if (x->x_channels == 2) *out[1]++ = 0; }/*end if play */ - }/*end while n-- */ -#ifdef _WIN32 - free(in); - free(out); + }/*end while n-- */ +#ifdef _WIN32 + free(in); + free(out); #endif return (w + x->x_channels * 2 + 3); } diff --git a/externals/ggee/control/serial_bird.c b/externals/ggee/control/serial_bird.c index 6423dc714a3ed29e939fa4e654ea535bb61f6c08..24ff5da1714e255cce6757e78a8f21f7f5a11832 100644 --- a/externals/ggee/control/serial_bird.c +++ b/externals/ggee/control/serial_bird.c @@ -128,8 +128,8 @@ static void serial_bird_float( t_serial_bird* x,t_floatarg f) /* post("posx %d, posy %d",x->x_posx,x->x_posy);*/ outlet_list(x->x_obj.ob_outlet,&s_list, ac, at); } - - x->x_count = (++x->x_count)%(x->x_maxcount); + x->x_count++; + x->x_count = x->x_count % x->x_maxcount; } static void serial_bird_poll( t_serial_bird* x) diff --git a/externals/ggee/control/serial_ms.c b/externals/ggee/control/serial_ms.c index b012fdf636bb6d6867ca89522589aa92edd408df..e06ce341ae90910fc33cd48bd45c9942242cde25 100644 --- a/externals/ggee/control/serial_ms.c +++ b/externals/ggee/control/serial_ms.c @@ -69,7 +69,8 @@ static void serial_ms_float( t_serial_ms* x,t_floatarg f) x->x_c[x->x_count] = (char) f; - x->x_count = (++x->x_count)%3; + x->x_count++; + x->x_count = x->x_count % 3; if (x->x_count==2) { dx= (signed char)(((x->x_c[0] & 0x03) << 6) | diff --git a/externals/ggee/control/serial_mt.c b/externals/ggee/control/serial_mt.c index 02a1aac63864706376f85b1bd70d83ca72701429..2b4e24a1ec77a65157310a44865a0b93d6d0912b 100644 --- a/externals/ggee/control/serial_mt.c +++ b/externals/ggee/control/serial_mt.c @@ -31,7 +31,8 @@ static void serial_mt_float( t_serial_mt* x,t_floatarg f) x->x_c[x->x_count] = (char) f; - x->x_count = (++x->x_count)%3; + x->x_count++; + x->x_count = x->x_count % 3; if (x->x_count==2) { dx= (signed char)(((x->x_c[0] & 0x03) << 6) | diff --git a/externals/jasch_lib/detox/detox.c b/externals/jasch_lib/detox/detox.c index 9889e458632da633c05f4c051fe9cb3cc6b8f102..5a393e5d5d3ac82707265bd55df3d720ffd759c5 100644 --- a/externals/jasch_lib/detox/detox.c +++ b/externals/jasch_lib/detox/detox.c @@ -1 +1,776 @@ -/*__________________________________________________________________________ detox á extract value/content from tag-structured symbol Copyright (C) 2003 - 2006 jan schacher This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA pd-port 20060517 revised tree output 20040712 initial build 20030502 ____________________________________________________________________________*/ #include "m_pd.h" #include <string.h> #include <stdlib.h> #include <ctype.h> #include <locale.h> #include <stdio.h> #define VERSION "1.3" #define CLIP(x,a,b) (x)=(x)<(a)?(a):(x)>(b)?(b):(x) #define MAXLENGTH 4096 typedef struct _detox { t_object ob; t_atom t_tree[257], t_attrpair[2]; t_atom t_comp, t_blip; t_atom t_checkat[2]; char t_charbuf[MAXLENGTH]; long t_treecount; short t_debug; short t_mode; void *s_outlet, *s_outlet2, *s_outlet3, *s_outlet4; } t_detox; t_symbol *ps_nothing; void *detox_class; void *detox_new(t_symbol *s, short argc, t_atom *argv); void detox_bang(t_detox *x); void detox_float(t_detox *x, t_float f); void detox_list(t_detox *x, t_symbol *s, short argc, t_atom *argv); void detox_anything(t_detox *x, t_symbol *s, short argc, t_atom *argv); void detox_free(t_detox *x); void detox_reset(t_detox *x); void detox_debug(t_detox *x, float f); void detox_mode(t_detox *x, float f); void detox_anything(t_detox *x, t_symbol *s, short argc, t_atom *argv); void detox_action(t_detox *x); void detox_fixsymbol(t_detox *x); void version(t_detox *x); void detox_setup(void) { detox_class = class_new(gensym("detox"), (t_newmethod)detox_new, (t_method)detox_free, sizeof(t_detox), 0, A_GIMME, 0); class_addsymbol(detox_class, (t_method)detox_anything); class_addmethod(detox_class, (t_method)detox_list, gensym("list"), A_GIMME,0); class_addmethod(detox_class, (t_method)detox_debug, gensym("debug"), A_FLOAT, 0); class_addmethod(detox_class, (t_method)detox_mode, gensym("mode"), A_FLOAT, 0); class_addmethod(detox_class, (t_method)detox_reset, gensym("reset"), 0); class_addmethod(detox_class, (t_method)version, gensym("version"), 0); post("- detox - jasch - "__DATE__" "); ps_nothing = gensym(""); } void *detox_new(t_symbol *s, short argc, t_atom *argv) { t_detox *x = (t_detox *)pd_new(detox_class); x->s_outlet = outlet_new(&x->ob, NULL); x->s_outlet2 = outlet_new(&x->ob, NULL); x->s_outlet3 = outlet_new(&x->ob, NULL); x->s_outlet4 = outlet_new(&x->ob, gensym("float")); x->t_treecount = 0; x->t_debug = 0; if((argc >= 1)&&(argv[0].a_type == A_FLOAT)){ if(argv[0].a_w.w_float == 0){ x->t_mode = 0; }else{ x->t_mode = 1; } }else{ x->t_mode = 1; } x->t_debug = 0; if(x->t_debug) post("mode is %ld", x->t_mode); x->t_checkat[0].a_type = A_SYMBOL; x->t_checkat[0].a_w.w_symbol = gensym("none"); x->t_checkat[1].a_type = A_SYMBOL; x->t_checkat[1].a_w.w_symbol = gensym("none"); return (x); } void detox_free(t_detox *x) { // notify_free((t_object *)x); } void detox_bang(t_detox *x) { detox_action(x); } void detox_float(t_detox *x, t_float f) { sprintf(x->t_charbuf, "%.6f", f); detox_action(x); } void detox_list(t_detox *x, t_symbol *s, short argc, t_atom *argv) { long i; char temp[MAXLENGTH]; x->t_charbuf[0] = 0; for(i = 0; i < argc; i++){ if(i) strcat(x->t_charbuf, " "); temp[0] = 0; if(argv[i].a_type == A_FLOAT){ sprintf(temp, "%.6f", argv[i].a_w.w_float); }else if(argv[i].a_type == A_SYMBOL){ // check for whitespace in symbol and add back doublequotes if(strchr(argv[i].a_w.w_symbol->s_name, 32) == NULL) { // no whitespace : normal proc strcpy(temp, argv[i].a_w.w_symbol->s_name); } else { // with whitespace : fix it x->t_checkat[0] = argv[i]; detox_fixsymbol(x); strcpy(temp, x->t_checkat[1].a_w.w_symbol->s_name); } } if((strlen(x->t_charbuf) + strlen(temp)) < MAXLENGTH){ strcat(x->t_charbuf, temp); }else{ return; } } detox_action(x); } void detox_anything(t_detox *x, t_symbol *s, short argc, t_atom *argv) { long i; char temp[MAXLENGTH]; x->t_charbuf[0] = 0; strcpy(x->t_charbuf, s->s_name); for(i = 0; i < argc; i++){ strcat(x->t_charbuf, " "); temp[0] = 0; if(argv[i].a_type == A_FLOAT){ sprintf(temp, "%.6f", argv[i].a_w.w_float); }else if(argv[i].a_type == A_SYMBOL){ // check for whitespace in symbol and add back doublequotes if(strchr(argv[i].a_w.w_symbol->s_name, 32) == NULL) { // no whitespace : normal proc strcpy(temp, argv[i].a_w.w_symbol->s_name); } else { // with whitespace : fix it x->t_checkat[0] = argv[i]; detox_fixsymbol(x); strcpy(temp, x->t_checkat[1].a_w.w_symbol->s_name); } } // post("temp is %s", temp); if((strlen(x->t_charbuf) + strlen(temp)) < MAXLENGTH){ strcat(x->t_charbuf, temp); }else{ return; } } detox_action(x); return; } void detox_reset(t_detox *x) { short i; x->t_treecount = 0; for(i=0;i<256; i++) x->t_tree[i].a_w.w_symbol = ps_nothing; } void detox_debug(t_detox *x, float f) { if(f == 0.0){ x->t_debug = 0; }else if(f != 0){ x->t_debug = 1; } } void detox_mode(t_detox *x, float f) { if(f == 0.0){ x->t_mode = 0; }else if(f != 0){ x->t_mode = 1; } } void detox_action(t_detox *x) { t_atom *outlist, *attrpair; // *comp, char local[MAXLENGTH], local2[MAXLENGTH]; char temp[MAXLENGTH]; char tempstring[2]; // for strtok char *ptr1 = NULL, *ptr2 = NULL, *ptr3 = NULL; long i, j, k, last, len, tempcount = 0; short tagtype = 0; // 0 = closed, 1 = open, 2 = closing short outsize = 0; char quotetype[1]; short digitflag = 0; short punctflag = 0; short quoteflag = 0; // short attrpresent = 0; quotetype[0] = '\"'; // init to standard double quotes i = 0; strcpy(tempstring, " "); outlist = x->t_tree; attrpair = x->t_attrpair; x->t_attrpair[0].a_type = A_SYMBOL; x->t_attrpair[1].a_type = A_SYMBOL; // check type and recast on output strcpy(local2, x->t_charbuf); last = strlen(local2); // test for tag // if(x->t_debug) post("input is %s", x->t_charbuf); k = 0; while(isspace(local2[k])){ // remove whitespace/tab/cr/linefeed k++; } // if(x->t_debug) post("k is %ld, last is %ld", k, last); for(i=k, j=0; i<last; i++, j++){ // remove whitespace/tab/cr/linefeed local[j] = local2[i]; } local[j] = 0; // terminate string if((local[0] != '<') || (local[j-1] != '>')){ tagtype = 0; // not a well formed tag if(x->t_debug) post("tagtype 0"); goto content; } if((local[1] == '?') || (local[1] == '!')){ tagtype = 4; // this might be a metatag if(x->t_debug) post("tagtype 4"); goto content; } for(i = 0, ptr1 = NULL, quoteflag = 0; i < (long)(strlen(local) -1); i++) { if((local[i] == '\"') || (local[i] == '\'')){ quoteflag = !quoteflag; } if((local[i] == '/') && (quoteflag == 0)) { ptr1 = &local[i]; } } //ptr1 = strchr(local, '/'); // is it a closing tag ? // bug: if slash is within quotes: should ignore if(x->t_debug) post("ptr1 contains %s", x->t_charbuf); if(ptr1 == NULL){ // we have new open tag tagtype = 2; if(x->t_debug) post("tagtype 2"); }else if((local[1] == '/')){ // is it at beginning tagtype = 3; if(x->t_debug) post("tagtype 3"); }else if(local[1] != '/'){ // is it elsewhere if(x->t_debug) post("tagtype 1"); tagtype = 1; } switch(tagtype){ case 1: // closed tag :: add temporarily to tree ptr1 = strchr(local, '>'); ptr2 = strchr(local, ' '); if(ptr2 != NULL) *ptr2 = 0; if(ptr1 != NULL){ *ptr1 = 0; }else{ return; } len = strlen(local); ptr3 = (char *)memmove((local + 0),(local + 1), len-1); local[len-1] = 0; ptr3 = local; x->t_blip.a_type = A_SYMBOL; x->t_blip.a_w.w_symbol = gensym(ptr3); tempcount = 1; break; case 2: // opening tag :: add to tree, increment count ptr2 = strchr(local, ' '); if(ptr2 != NULL){ *ptr2 = 0; if(x->t_debug) post("inside opening tag w/ whitespace, %s", local); }else{ local[strlen(local) - 1] = 0; // local[strlen(ptr2) -1] = 0; if(x->t_debug) post("inside opening tag no whitespace, %s", local); // return; } len = strlen(local); ptr3 = (char *)memmove((local + 0),(local + 1), len-1); if(x->t_debug) post("ptr3 is %s", ptr3); local[len-1] = 0; ptr3 = local; SETSYMBOL(x->t_tree + x->t_treecount, gensym(ptr3)); x->t_treecount++; x->t_treecount = CLIP(x->t_treecount, 0, 255); break; case 3: // closing tag :: remove from tree, decrement count ptr2 = strchr(local, '>'); if(ptr2 != NULL){ *ptr2 = 0; }else{ return; } len = strlen(local); ptr3 = (char *)memmove((local + 0),(local + 2), len-2); local[len-2] = 0; ptr3 = local; x->t_comp.a_type = A_SYMBOL; x->t_comp.a_w.w_symbol = gensym(ptr3); if(x->t_comp.a_w.w_symbol->s_name == x->t_tree[x->t_treecount-1].a_w.w_symbol->s_name){ x->t_treecount -= 1; x->t_treecount = CLIP(x->t_treecount, 0, 255); }else{ outlet_float(x->s_outlet4, 3); outlet_float(x->s_outlet3, -1); return; } break; } content: outlet_float(x->s_outlet4, tagtype); if(tagtype == 0) return; // the tree if(x->t_treecount > 0){ if(tempcount){ outsize = x->t_treecount + 1; x->t_tree[outsize-1] = x->t_blip; }else{ outsize = x->t_treecount; } outlet_list(x->s_outlet3, 0L, outsize, outlist); // ouput tree }else if(x->t_treecount == 0){ if(tempcount){ outlet_anything(x->s_outlet3, x->t_blip.a_w.w_symbol, 0, 0L); // ouput tree }else{ outlet_float(x->s_outlet3, 0); // ouput tree } } strcpy(local, x->t_charbuf); ptr1 = strchr(local, '>'); // parse content between enclosing tags <tag>blah</tag> if(ptr1 == NULL) goto attributes; *ptr1 = 0; ++ptr1; ptr2 = strchr(ptr1, '<'); if(ptr2 == NULL) goto attributes; *ptr2 = 0; outlet_anything(x->s_outlet2, gensym(ptr1), 0, 0L); attributes: strcpy(local, x->t_charbuf); // retrieve full buffer again switch(x->t_mode) { // the old way of attribute parsing (mode 0) case 0: if(x->t_debug) post("content: before strtok %s", local); ptr1 = local; ptr2 = strchr(local, '>'); // find tag end ptr2++; // terminate local buffer after tag end ptr2[0] = 0; if(strcspn(ptr1, "=\"\'") == strlen(ptr1)) { // check for attributes inside tag break; // no attr-chars found, bail ouit } ptr1 = strchr(local, ' '); // find first whitespace if(ptr1 == NULL) { break; // no whitespace found bail } while((ptr1[0] == ' ') && (ptr1 != NULL)) { // find next non-whitespace char -> potential start of attr ptr1++; } ptr2 = ptr1; // setup second pointer from end of attr name while( !((ptr2[0] == ' ') || (ptr2[0] == '=')) && (ptr2 != NULL)) { // find next non-white or not equal-sign -> what if not well formed ?? ptr2++; } if(ptr2 == NULL) { error("detox: mode 0, attrloop ptr2 reached NULL looking for \" \" and \"=\""); return; } /*len = 0; len = strlen(ptr1) - strlen(ptr2); // determine length of attr name: name minus whitespace/equal sign for(i = 0; i < len; i++) { temp[i] = ptr1[i]; } temp[len] = 0; // terminate temp_buffer */ ptr1 = ptr2; // copy start pointer to position of end pointer -> remainder while(ptr1 != NULL) { // move start pointer until single or double quote if ((ptr1[0] == '\'') || (ptr1[0] == '\"')) { quotetype[0] = ptr1[0]; break; } ptr1++; } if(ptr1 == NULL) { // bail if no quotes found and end reached error("detox: mode 0, attrloop ptr1 reached NULL"); return; } // store quote char for later comparison if (x->t_debug) post("first quotetype found is %c", quotetype[0]); ptr2 = ++ptr1; // copy end pointer to pos of startpointer + 1, right after the quote while(ptr2 != NULL) { // looking for next quote of stored type if(ptr2[0] == quotetype[0]) { break; } ptr2++; } // post("quotetype is %c and ptr2 is %c", quotetype[0], ptr2[0]); if(ptr2 == NULL) { error("detox: mode 0, attrloop ptr2 reached NULL"); return; } len = 0; digitflag = 1; // reset check for long punctflag = 0; // reset check for float len = strlen(ptr1) - strlen(ptr2); // get the length of the attr content // post("ptr2 ends scan at %c", ptr2[0]); for(i = 0; i < len; i++) { // copy attr-content into temp-buffer temp[i] = ptr1[i]; punctflag += (temp[i] == '.'); // digitflag = digitflag && (isdigit(temp[i]) || ispunct(temp[i])); // are all digits? } temp[len] = 0; if (x->t_debug) post("temp is %s, digitflag is %ld, punctflag is %ld", temp, digitflag, punctflag); if(digitflag == 0){ attrpair[0].a_type = A_SYMBOL; // to do: check atom type and cast accordingly js 20061202 attrpair[0].a_w.w_symbol = gensym(temp); outlet_anything(x->s_outlet, x->t_attrpair[0].a_w.w_symbol, 0, 0L); } else if ((digitflag == 1)&&(punctflag == 0)){ attrpair[1].a_type = A_FLOAT; // to do: check atom type and cast accordingly js 20061202 attrpair[1].a_w.w_float = atoi(temp); outlet_float(x->s_outlet, x->t_attrpair[2].a_w.w_float); } else if ((digitflag == 1)&&(punctflag == 1)){ attrpair[1].a_type = A_FLOAT; // to do: check atom type and cast accordingly js 20061202 attrpair[1].a_w.w_float = atof(temp); outlet_float(x->s_outlet, x->t_attrpair[1].a_w.w_float); } break; case 1: // the new way of attribute parsing (mode 1) ¥¥¥¥ fixed 20070322 ptr1 = local; ptr2 = strchr(local, '>'); // find tag end ptr2++; // terminate local buffer after tag end ptr2[0] = 0; if(strcspn(ptr1, "=\"\'") == strlen(ptr1)) { // check for attributes inside tag break; // no attr-chars found, bail ouit } ptr1 = strchr(local, ' '); // find first whitespace if(ptr1 == NULL) { break; // no whitespace found bail } for(;;) { // ¥¥ attribute loop; example: <person name = 'Alan Turing' died = '07/06/1954' born = "1912-06-23" /> while((ptr1[0] == ' ') && (ptr1 != NULL)) { // find next non-whitespace char -> potential start of attr ptr1++; } ptr2 = ptr1; // setup second pointer from end of attr name while( !((ptr2[0] == ' ') || (ptr2[0] == '=')) && (ptr2 != NULL)) { // find next non-white or not equal-sign -> what if not well formed ?? ptr2++; } if(ptr2 == NULL) { error("detox: mode 1, attrloop ptr2 reached NULL looking for \" \" and \"=\""); return; } len = 0; len = strlen(ptr1) - strlen(ptr2); // determine length of attr name: name minus whitespace/equal sign for(i = 0; i < len; i++) { temp[i] = ptr1[i]; } temp[len] = 0; // terminate temp_buffer attrpair[0].a_w.w_symbol = gensym(temp); // put tempbuffer into output symbol // ¥ done with the attr-name ptr1 = ptr2; // copy start pointer to position of end pointer -> remainder while(ptr1 != NULL) { // move start pointer until single or double quote if ((ptr1[0] == '\'') || (ptr1[0] == '\"')) { quotetype[0] = ptr1[0]; // store quote char for later comparison break; } ptr1++; } if(ptr1 == NULL) { // bail if no quotes found and end reached error("detox: mode 1, attrloop ptr1 reached NULL"); return; } if (x->t_debug) post("first quotetype found is %c", quotetype[0]); ptr2 = ++ptr1; // copy end pointer to pos of startpointer + 1, right after the quote while(ptr2 != NULL) { // looking for next quote of stored type if(ptr2[0] == quotetype[0]) { break; } ptr2++; } // post("quotetype is %c and ptr2 is %c", quotetype[0], ptr2[0]); if(ptr2 == NULL) { error("detox: mode 1, attrloop ptr2 reached NULL"); return; } len = 0; digitflag = 1; // reset check for long punctflag = 0; // reset check for float len = strlen(ptr1) - strlen(ptr2); // get the length of the attr content // post("ptr2 ends scan at %c", ptr2[0]); for(i = 0; i < len; i++) { // copy attr-content into temp-buffer temp[i] = ptr1[i]; punctflag += (temp[i] == '.'); // digitflag = digitflag && (isdigit(temp[i]) || ispunct(temp[i])); // are all digits? } temp[len] = 0; if (x->t_debug) post("temp is %s, digitflag is %ld, punctflag is %ld", temp, digitflag, punctflag); if(digitflag == 0){ attrpair[1].a_type = A_SYMBOL; // to do: check atom type and cast accordingly js 20061202 attrpair[1].a_w.w_symbol = gensym(temp); } else if ((digitflag == 1)&&(punctflag == 0)){ attrpair[1].a_type = A_FLOAT; // to do: check atom type and cast accordingly js 20061202 attrpair[1].a_w.w_float = atoi(temp); } else if ((digitflag == 1)&&(punctflag == 1)){ attrpair[1].a_type = A_FLOAT; // to do: check atom type and cast accordingly js 20061202 attrpair[1].a_w.w_float = atof(temp); } outlet_anything(x->s_outlet, x->t_attrpair[0].a_w.w_symbol, 1, &x->t_attrpair[1]); ptr1 = ++ptr2; // move start pointer to end of atrr-content while(ptr1 != NULL) { // find next non-whitespace char if (ptr1[0] != ' ') { break; } ptr1++; } if((ptr1[0] == '/') || (ptr1[0] == '>') || (ptr1[0] == '?') || (ptr1 == NULL)) { // if char is "/" or ">" or "?" or end of string finish up if (x->t_debug) post("ptr1 reached ending meta characters"); return; } if (x->t_debug) post("ptr1 reached loop point"); } break; } } void detox_fixsymbol(t_detox *x) // this is an ugly hack for max stripping double quotes from symbols with whitespace in them (language problem) { long i = 0; long len = 0; x->t_checkat[1].a_w.w_symbol->s_name[0] = '\"'; // first char in output is " len = strlen(x->t_checkat[0].a_w.w_symbol->s_name); len = CLIP(len, 0, (MAXLENGTH-3)); for(i = 0; i < len; i++) { if ((x->t_checkat[0].a_w.w_symbol->s_name[i] == '/') || (x->t_checkat[0].a_w.w_symbol->s_name[i] == '>')) { // check for syntax differences break; } x->t_checkat[1].a_w.w_symbol->s_name[i+1] = x->t_checkat[0].a_w.w_symbol->s_name[i]; } x->t_checkat[1].a_w.w_symbol->s_name[i+1] = '\"'; // last char in output is " x->t_checkat[1].a_w.w_symbol->s_name[i+2] = 0; // terminate string } void version(t_detox *x) { post("á detox á jasch á v. "VERSION" á compiled "__DATE__" - "__TIME__ ); } \ No newline at end of file +/*__________________________________________________________________________ + + detox extract value/content from tag-structured symbol + + Copyright (C) 2003 - 2006 jan schacher + + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + pd-port 20060517 + revised tree output 20040712 + initial build 20030502 + + + +____________________________________________________________________________*/ + + +#include "m_pd.h" +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <locale.h> +#include <stdio.h> + +#define VERSION "1.3" +#define CLIP(x,a,b) (x)=(x)<(a)?(a):(x)>(b)?(b):(x) +#define MAXLENGTH 4096 + +typedef struct _detox +{ + t_object ob; + t_atom t_tree[257], t_attrpair[2]; + t_atom t_comp, t_blip; + t_atom t_checkat[2]; + char t_charbuf[MAXLENGTH]; + long t_treecount; + short t_debug; + short t_mode; + void *s_outlet, *s_outlet2, *s_outlet3, *s_outlet4; +} t_detox; + +t_symbol *ps_nothing; + +void *detox_class; +void *detox_new(t_symbol *s, short argc, t_atom *argv); +void detox_bang(t_detox *x); +void detox_float(t_detox *x, t_float f); +void detox_list(t_detox *x, t_symbol *s, short argc, t_atom *argv); +void detox_anything(t_detox *x, t_symbol *s, short argc, t_atom *argv); +void detox_free(t_detox *x); +void detox_reset(t_detox *x); +void detox_debug(t_detox *x, float f); +void detox_mode(t_detox *x, float f); +void detox_anything(t_detox *x, t_symbol *s, short argc, t_atom *argv); +void detox_action(t_detox *x); +void detox_fixsymbol(t_detox *x); +void version(t_detox *x); + + +void detox_setup(void) +{ + detox_class = class_new(gensym("detox"), (t_newmethod)detox_new, + (t_method)detox_free, sizeof(t_detox), 0, A_GIMME, 0); + class_addsymbol(detox_class, (t_method)detox_anything); + class_addmethod(detox_class, (t_method)detox_list, + gensym("list"), A_GIMME,0); + class_addmethod(detox_class, (t_method)detox_debug, + gensym("debug"), A_FLOAT, 0); + class_addmethod(detox_class, (t_method)detox_mode, + gensym("mode"), A_FLOAT, 0); + class_addmethod(detox_class, (t_method)detox_reset, + gensym("reset"), 0); + class_addmethod(detox_class, (t_method)version, + gensym("version"), 0); + post("- detox - jasch - "__DATE__" "); + ps_nothing = gensym(""); +} + +void *detox_new(t_symbol *s, short argc, t_atom *argv) +{ + t_detox *x = (t_detox *)pd_new(detox_class); + x->s_outlet = outlet_new(&x->ob, NULL); + x->s_outlet2 = outlet_new(&x->ob, NULL); + x->s_outlet3 = outlet_new(&x->ob, NULL); + x->s_outlet4 = outlet_new(&x->ob, gensym("float")); + + x->t_treecount = 0; + x->t_debug = 0; + + if ((argc >= 1) && (argv[0].a_type == A_FLOAT)) + { + if (argv[0].a_w.w_float == 0) + { + x->t_mode = 0; + } + else + { + x->t_mode = 1; + } + } + else + { + x->t_mode = 1; + } + x->t_debug = 0; + if(x->t_debug) post("mode is %ld", x->t_mode); + + x->t_checkat[0].a_type = A_SYMBOL; + x->t_checkat[0].a_w.w_symbol = gensym("none"); + x->t_checkat[1].a_type = A_SYMBOL; + x->t_checkat[1].a_w.w_symbol = gensym("none"); + + return (x); +} + +void detox_free(t_detox *x) +{ + // notify_free((t_object *)x); +} + +void detox_bang(t_detox *x) +{ + detox_action(x); +} + +void detox_float(t_detox *x, t_float f) +{ + sprintf(x->t_charbuf, "%.6f", f); + detox_action(x); +} + +void detox_list(t_detox *x, t_symbol *s, short argc, t_atom *argv) +{ + long i; + char temp[MAXLENGTH]; + + x->t_charbuf[0] = 0; + for (i = 0; i < argc; i++) + { + if (i) strcat(x->t_charbuf, " "); + temp[0] = 0; + if (argv[i].a_type == A_FLOAT) + { + sprintf(temp, "%.6f", argv[i].a_w.w_float); + } + else if (argv[i].a_type == A_SYMBOL) + { + // check for whitespace in symbol and add back doublequotes + if (strchr(argv[i].a_w.w_symbol->s_name, 32) == NULL) + { // no whitespace : normal proc + strcpy(temp, argv[i].a_w.w_symbol->s_name); + } + else + { // with whitespace : fix it + x->t_checkat[0] = argv[i]; + detox_fixsymbol(x); + strcpy(temp, x->t_checkat[1].a_w.w_symbol->s_name); + } + } + if ((strlen(x->t_charbuf) + strlen(temp)) < MAXLENGTH) + { + strcat(x->t_charbuf, temp); + } + else + { + return; + } + } + detox_action(x); +} + +void detox_anything(t_detox *x, t_symbol *s, short argc, t_atom *argv) +{ + long i; + char temp[MAXLENGTH]; + + x->t_charbuf[0] = 0; + strcpy(x->t_charbuf, s->s_name); + for (i = 0; i < argc; i++) + { + strcat(x->t_charbuf, " "); + temp[0] = 0; + if (argv[i].a_type == A_FLOAT) + { + sprintf(temp, "%.6f", argv[i].a_w.w_float); + } + else if (argv[i].a_type == A_SYMBOL) + { + // check for whitespace in symbol and add back doublequotes + if (strchr(argv[i].a_w.w_symbol->s_name, 32) == NULL) + { // no whitespace : normal proc + strcpy(temp, argv[i].a_w.w_symbol->s_name); + } + else + { // with whitespace : fix it + x->t_checkat[0] = argv[i]; + detox_fixsymbol(x); + strcpy(temp, x->t_checkat[1].a_w.w_symbol->s_name); + } + } + // post("temp is %s", temp); + if ((strlen(x->t_charbuf) + strlen(temp)) < MAXLENGTH) + { + strcat(x->t_charbuf, temp); + } + else + { + return; + } + } + detox_action(x); + return; +} + +void detox_reset(t_detox *x) +{ + short i; + x->t_treecount = 0; + for (i = 0; i < 256; i++) x->t_tree[i].a_w.w_symbol = ps_nothing; +} + +void detox_debug(t_detox *x, float f) +{ + if (f == 0.0) + { + x->t_debug = 0; + } + else if (f != 0) + { + x->t_debug = 1; + } +} + +void detox_mode(t_detox *x, float f) +{ + if (f == 0.0) + { + x->t_mode = 0; + } + else if (f != 0) + { + x->t_mode = 1; + } +} + +void detox_action(t_detox *x) +{ + t_atom *outlist, *attrpair; // *comp, + char local[MAXLENGTH], local2[MAXLENGTH]; + char temp[MAXLENGTH]; + char tempstring[2]; // for strtok + char *ptr1 = NULL, *ptr2 = NULL, *ptr3 = NULL; + long i, j, k, last, len, tempcount = 0; + short tagtype = 0; // 0 = closed, 1 = open, 2 = closing + short outsize = 0; + char quotetype[1]; + short digitflag = 0; + short punctflag = 0; + short quoteflag = 0; + // short attrpresent = 0; + quotetype[0] = '\"'; // init to standard double quotes + i = 0; + strcpy(tempstring, " "); + + outlist = x->t_tree; + attrpair = x->t_attrpair; + + x->t_attrpair[0].a_type = A_SYMBOL; + x->t_attrpair[1].a_type = A_SYMBOL; // check type and recast on output + + strcpy(local2, x->t_charbuf); + last = strlen(local2); // test for tag + + // if(x->t_debug) post("input is %s", x->t_charbuf); + + k = 0; + while (isspace(local2[k])) + { // remove whitespace/tab/cr/linefeed + k++; + } + // if(x->t_debug) post("k is %ld, last is %ld", k, last); + + for (i = k, j = 0; i < last; i++, j++) + { // remove whitespace/tab/cr/linefeed + local[j] = local2[i]; + } + local[j] = 0; // terminate string + + if ((local[0] != '<') || (local[j-1] != '>')) + { + tagtype = 0; // not a well formed tag + if (x->t_debug) post("tagtype 0"); + goto content; + } + if ((local[1] == '?') || (local[1] == '!')) + { + tagtype = 4; // this might be a metatag + if (x->t_debug) post("tagtype 4"); + goto content; + } + + + + for (i = 0, ptr1 = NULL, quoteflag = 0; i < (long)(strlen(local) -1); i++) + { + if ((local[i] == '\"') || (local[i] == '\'')) + { + quoteflag = !quoteflag; + } + if ((local[i] == '/') && (quoteflag == 0)) + { + ptr1 = &local[i]; + } + } + //ptr1 = strchr(local, '/'); // is it a closing tag ? // bug: if slash is within quotes: should ignore + + if(x->t_debug) post("ptr1 contains %s", x->t_charbuf); + + if (ptr1 == NULL) + { // we have new open tag + tagtype = 2; + if (x->t_debug) post("tagtype 2"); + } + else if ((local[1] == '/')) + { // is it at beginning + tagtype = 3; + if (x->t_debug) post("tagtype 3"); + } + else if (local[1] != '/') + { // is it elsewhere + if (x->t_debug) post("tagtype 1"); + tagtype = 1; + } + + switch (tagtype) + { + case 1: // closed tag :: add temporarily to tree + ptr1 = strchr(local, '>'); + ptr2 = strchr(local, ' '); + + if (ptr2 != NULL) *ptr2 = 0; + if (ptr1 != NULL) + { + *ptr1 = 0; + } + else + { + return; + } + len = strlen(local); + ptr3 = (char *)memmove((local + 0), (local + 1), len-1); + local[len-1] = 0; + ptr3 = local; + x->t_blip.a_type = A_SYMBOL; + x->t_blip.a_w.w_symbol = gensym(ptr3); + tempcount = 1; + break; + case 2: // opening tag :: add to tree, increment count + ptr2 = strchr(local, ' '); + if (ptr2 != NULL) + { + *ptr2 = 0; + if (x->t_debug) + post("inside opening tag w/ whitespace, %s", local); + } + else + { + local[strlen(local) - 1] = 0; + // local[strlen(ptr2) -1] = 0; + if (x->t_debug) + post("inside opening tag no whitespace, %s", local); + // return; + } + len = strlen(local); + ptr3 = (char *)memmove((local + 0),(local + 1), len-1); + if (x->t_debug) post("ptr3 is %s", ptr3); + local[len-1] = 0; + ptr3 = local; + SETSYMBOL(x->t_tree + x->t_treecount, gensym(ptr3)); + x->t_treecount++; + CLIP(x->t_treecount, 0, 255); + break; + case 3: // closing tag :: remove from tree, decrement count + ptr2 = strchr(local, '>'); + if (ptr2 != NULL) + { + *ptr2 = 0; + } + else + { + return; + } + len = strlen(local); + ptr3 = (char *)memmove((local + 0),(local + 2), len-2); + local[len-2] = 0; + ptr3 = local; + x->t_comp.a_type = A_SYMBOL; + x->t_comp.a_w.w_symbol = gensym(ptr3); + if (x->t_comp.a_w.w_symbol->s_name == + x->t_tree[x->t_treecount-1].a_w.w_symbol->s_name) + { + x->t_treecount -= 1; + CLIP(x->t_treecount, 0, 255); + } + else + { + outlet_float(x->s_outlet4, 3); + outlet_float(x->s_outlet3, -1); + return; + } + break; + } +content: + + outlet_float(x->s_outlet4, tagtype); + if (tagtype == 0) return; + // the tree + if (x->t_treecount > 0) + { + if (tempcount) + { + outsize = x->t_treecount + 1; + x->t_tree[outsize-1] = x->t_blip; + } + else + { + outsize = x->t_treecount; + } + outlet_list(x->s_outlet3, 0L, outsize, outlist); // ouput tree + } + else if (x->t_treecount == 0) + { + if (tempcount) + { + // ouput tree + outlet_anything(x->s_outlet3, x->t_blip.a_w.w_symbol, 0, 0L); + } + else + { + // ouput tree + outlet_float(x->s_outlet3, 0); + } + } + + strcpy(local, x->t_charbuf); + + // parse content between enclosing tags <tag>blah</tag> + ptr1 = strchr(local, '>'); + if (ptr1 == NULL) goto attributes; + *ptr1 = 0; + ++ptr1; + ptr2 = strchr(ptr1, '<'); + if (ptr2 == NULL) goto attributes; + *ptr2 = 0; + outlet_anything(x->s_outlet2, gensym(ptr1), 0, 0L); + +attributes: + + strcpy(local, x->t_charbuf); // retrieve full buffer again + + switch(x->t_mode) + { // the old way of attribute parsing (mode 0) + case 0: + if (x->t_debug) post("content: before strtok %s", local); + ptr1 = local; + ptr2 = strchr(local, '>'); // find tag end + ptr2++; // terminate local buffer after tag end + ptr2[0] = 0; + if (strcspn(ptr1, "=\"\'") == strlen(ptr1)) + { // check for attributes inside tag + break; // no attr-chars found, bail ouit + } + + ptr1 = strchr(local, ' '); // find first whitespace + if (ptr1 == NULL) + { + break; // no whitespace found bail + } + while((ptr1[0] == ' ') && (ptr1 != NULL)) + { // find next non-whitespace char -> potential start of attr + ptr1++; + } + ptr2 = ptr1; // setup second pointer from end of attr name + while ( !((ptr2[0] == ' ') || (ptr2[0] == '=')) && (ptr2 != NULL)) + { + // find next non-white or not equal-sign -> + // what if not well formed ?? + ptr2++; + } + if (ptr2 == NULL) + { + error("detox: mode 0, " + "attrloop ptr2 reached NULL looking for \" \" and \"=\""); + return; + } + /*len = 0; + // determine length of attr name: name minus whitespace/equal sign + len = strlen(ptr1) - strlen(ptr2); + for (i = 0; i < len; i++) + { + temp[i] = ptr1[i]; + } + // terminate temp_buffer + temp[len] = 0; + */ + // copy start pointer to position of end pointer -> remainder + ptr1 = ptr2; + while (ptr1 != NULL) + { // move start pointer until single or double quote + if ((ptr1[0] == '\'') || (ptr1[0] == '\"')) + { + quotetype[0] = ptr1[0]; + break; + } + ptr1++; + } + if (ptr1 == NULL) + { // bail if no quotes found and end reached + error("detox: mode 0, attrloop ptr1 reached NULL"); + return; + } + // store quote char for later comparison + if (x->t_debug) post("first quotetype found is %c", quotetype[0]); + // copy end pointer to pos of startpointer + 1, + // right after the quote + ptr1++; + ptr2 = ptr1; + while (ptr2 != NULL) + { // looking for next quote of stored type + if (ptr2[0] == quotetype[0]) + { + break; + } + ptr2++; + } + // post("quotetype is %c and ptr2 is %c", quotetype[0], ptr2[0]); + if (ptr2 == NULL) + { + error("detox: mode 0, attrloop ptr2 reached NULL"); + return; + } + len = 0; + digitflag = 1; // reset check for long + punctflag = 0; // reset check for float + + // get the length of the attr content + len = strlen(ptr1) - strlen(ptr2); + // post("ptr2 ends scan at %c", ptr2[0]); + for (i = 0; i < len; i++) + { // copy attr-content into temp-buffer + temp[i] = ptr1[i]; + punctflag += (temp[i] == '.'); + // are all digits? + digitflag = digitflag && (isdigit(temp[i]) || ispunct(temp[i])); + } + temp[len] = 0; + if (x->t_debug) + post("temp is %s, digitflag is %ld, punctflag is %ld", + temp, digitflag, punctflag); + + if (digitflag == 0) + { + // to do: check atom type and cast accordingly js 20061202 + attrpair[0].a_type = A_SYMBOL; + attrpair[0].a_w.w_symbol = gensym(temp); + outlet_anything(x->s_outlet, x->t_attrpair[0].a_w.w_symbol, + 0, 0L); + } + else if ((digitflag == 1) && (punctflag == 0)) + { + // to do: check atom type and cast accordingly js 20061202 + attrpair[1].a_type = A_FLOAT; + attrpair[1].a_w.w_float = atoi(temp); + outlet_float(x->s_outlet, x->t_attrpair[1].a_w.w_float); + } + else if ((digitflag == 1) && (punctflag == 1)) + { + // to do: check atom type and cast accordingly js 20061202 + attrpair[1].a_type = A_FLOAT; + attrpair[1].a_w.w_float = atof(temp); + outlet_float(x->s_outlet, x->t_attrpair[1].a_w.w_float); + } + break; + case 1:// the new way of attribute parsing (mode 1) ¥¥¥¥ fixed 20070322 + ptr1 = local; + ptr2 = strchr(local, '>'); // find tag end + ptr2++; // terminate local buffer after tag end + ptr2[0] = 0; + if (strcspn(ptr1, "=\"\'") == strlen(ptr1)) + { // check for attributes inside tag + break; // no attr-chars found, bail ouit + } + + ptr1 = strchr(local, ' '); // find first whitespace + if (ptr1 == NULL) + { + break; // no whitespace found bail + } + + // ¥¥ attribute loop; example: + // <person name = 'Alan Turing' died = '07/06/1954' born = "1912-06-23" /> + for(;;) + { + while ((ptr1[0] == ' ') && (ptr1 != NULL)) + { // find next non-whitespace char -> potential start of attr + ptr1++; + } + ptr2 = ptr1; // setup second pointer from end of attr name + while ( !((ptr2[0] == ' ') || (ptr2[0] == '=')) && + (ptr2 != NULL)) + { + // find next non-white or not equal-sign -> + // what if not well formed ?? + ptr2++; + } + if (ptr2 == NULL) + { + error("detox: mode 1, attrloop ptr2 reached NULL " + "looking for \" \" and \"=\""); + return; + } + len = 0; + // determine length of attr name: name minus + // whitespace/equal sign + len = strlen(ptr1) - strlen(ptr2); + for(i = 0; i < len; i++) + { + temp[i] = ptr1[i]; + } + // terminate temp_buffer + temp[len] = 0; + // put tempbuffer into output symbol + attrpair[0].a_w.w_symbol = gensym(temp); + // ¥ done with the attr-name + // copy start pointer to position of end pointer -> remainder + ptr1 = ptr2; + while (ptr1 != NULL) + { // move start pointer until single or double quote + if ((ptr1[0] == '\'') || (ptr1[0] == '\"')) + { + // store quote char for later comparison + quotetype[0] = ptr1[0]; + break; + } + ptr1++; + } + if (ptr1 == NULL) + { // bail if no quotes found and end reached + error("detox: mode 1, attrloop ptr1 reached NULL"); + return; + } + if (x->t_debug) + post("first quotetype found is %c", quotetype[0]); + // copy end pointer to pos of startpointer + 1, + // right after the quote + ptr1++; + ptr2 = ptr1; + while (ptr2 != NULL) + { // looking for next quote of stored type + if (ptr2[0] == quotetype[0]) + { + break; + } + ptr2++; + } + // post("quotetype is %c and ptr2 is %c", quotetype[0], ptr2[0]); + if (ptr2 == NULL) + { + error("detox: mode 1, attrloop ptr2 reached NULL"); + return; + } + len = 0; + digitflag = 1; // reset check for long + punctflag = 0; // reset check for float + + // get the length of the attr content + len = strlen(ptr1) - strlen(ptr2); + // post("ptr2 ends scan at %c", ptr2[0]); + for (i = 0; i < len; i++) + { // copy attr-content into temp-buffer + temp[i] = ptr1[i]; + punctflag += (temp[i] == '.'); + digitflag = digitflag && (isdigit(temp[i]) || + ispunct(temp[i])); // are all digits? + } + temp[len] = 0; + if (x->t_debug) + post("temp is %s, digitflag is %ld, punctflag is %ld", + temp, digitflag, punctflag); + + if (digitflag == 0) + { + // to do: check atom type and cast accordingly js 20061202 + attrpair[1].a_type = A_SYMBOL; + attrpair[1].a_w.w_symbol = gensym(temp); + } + else if ((digitflag == 1)&&(punctflag == 0)) + { + // to do: check atom type and cast accordingly js 20061202 + attrpair[1].a_type = A_FLOAT; + attrpair[1].a_w.w_float = atoi(temp); + } + else if ((digitflag == 1)&&(punctflag == 1)) + { + // to do: check atom type and cast accordingly js 20061202 + attrpair[1].a_type = A_FLOAT; + attrpair[1].a_w.w_float = atof(temp); + } + outlet_anything(x->s_outlet, x->t_attrpair[0].a_w.w_symbol, + 1, &x->t_attrpair[1]); + + ptr2++; + ptr1 = ptr2; // move start pointer to end of attr-content + while (ptr1 != NULL) + { // find next non-whitespace char + if (ptr1[0] != ' ') + { + break; + } + ptr1++; + } + if ((ptr1[0] == '/') || (ptr1[0] == '>') || + (ptr1[0] == '?') || (ptr1 == NULL)) + { // if char is "/" or ">" or "?" or end of string finish up + if (x->t_debug) post("ptr1 reached ending meta characters"); + return; + } + if (x->t_debug) post("ptr1 reached loop point"); + } + break; + } +} + +// this is an ugly hack for max stripping double quotes from symbols with +// whitespace in them (language problem) +void detox_fixsymbol(t_detox *x) +{ + long i = 0; + long len = 0; + x->t_checkat[1].a_w.w_symbol->s_name[0] = '\"'; // first char in output is " + len = strlen(x->t_checkat[0].a_w.w_symbol->s_name); + CLIP(len, 0, (MAXLENGTH-3)); + + for (i = 0; i < len; i++) + { + if ((x->t_checkat[0].a_w.w_symbol->s_name[i] == '/') || + (x->t_checkat[0].a_w.w_symbol->s_name[i] == '>')) + { // check for syntax differences + break; + } + x->t_checkat[1].a_w.w_symbol->s_name[i+1] = + x->t_checkat[0].a_w.w_symbol->s_name[i]; + } + // last char in output is " + x->t_checkat[1].a_w.w_symbol->s_name[i+1] = '\"'; + // terminate string + x->t_checkat[1].a_w.w_symbol->s_name[i+2] = 0; +} + +void version(t_detox *x) +{ + post(". detox . jasch . v. "VERSION" . compiled "__DATE__" - "__TIME__ ); +} diff --git a/externals/loaders/hexloader/hexloader.c b/externals/loaders/hexloader/hexloader.c index f11e722486dd1571f00e32933995992802dc790a..063dc2377dec75ecf8738c6d6a7f76d2367258a3 100644 --- a/externals/loaders/hexloader/hexloader.c +++ b/externals/loaders/hexloader/hexloader.c @@ -36,7 +36,7 @@ #ifdef DL_OPEN # include <dlfcn.h> #endif -#ifdef UNISTD +#ifdef HAVE_UNISTD_H # include <stdlib.h> # include <unistd.h> #endif diff --git a/externals/moonlib/Makefile b/externals/moonlib/Makefile index 63623f03df0e4d17f5b31cc5241af2d5a2d79fff..b5ee48d9fc9af54db72d46c256357dc20214623c 100644 --- a/externals/moonlib/Makefile +++ b/externals/moonlib/Makefile @@ -143,7 +143,7 @@ ifeq ($(UNAME),ANDROID) NDK_UNAME := $(shell uname -s | tr '[A-Z]' '[a-z]') NDK_TOOLCHAIN_BASE=$(NDK_BASE)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$(NDK_UNAME)-x86 CC := $(NDK_TOOLCHAIN_BASE)/bin/arm-linux-androideabi-gcc --sysroot=$(NDK_SYSROOT) - OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing CFLAGS += LDFLAGS += -rdynamic -shared SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared @@ -159,7 +159,7 @@ ifeq ($(UNAME),Linux) SHARED_EXTENSION = so OS = linux PD_PATH = /usr - OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing ALL_CFLAGS += -fPIC ALL_LDFLAGS += -rdynamic -shared -fPIC SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared @@ -175,7 +175,7 @@ ifeq ($(UNAME),GNU) SHARED_EXTENSION = so OS = linux PD_PATH = /usr - OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing ALL_CFLAGS += -fPIC ALL_LDFLAGS += -rdynamic -shared -fPIC SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB) @@ -191,7 +191,7 @@ ifeq ($(UNAME),GNU/kFreeBSD) SHARED_EXTENSION = so OS = linux PD_PATH = /usr - OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing ALL_CFLAGS += -fPIC ALL_LDFLAGS += -rdynamic -shared -fPIC SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB) @@ -206,7 +206,7 @@ ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME))) SHARED_EXTENSION = dll OS = cygwin PD_PATH = $(shell cygpath $$PROGRAMFILES)/pd - OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing ALL_CFLAGS += ALL_LDFLAGS += -rdynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB) @@ -223,7 +223,7 @@ ifeq (MINGW,$(findstring MINGW,$(UNAME))) PD_PATH = $(shell cd "$$PROGRAMFILES/pd" && pwd) # MinGW doesn't seem to include cc so force gcc CC=gcc - OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer + OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing ALL_CFLAGS += -mms-bitfields ALL_LDFLAGS += -s -shared -Wl,--enable-auto-import -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj" SHARED_LDFLAGS += -shared diff --git a/externals/moonlib/tabsort.c b/externals/moonlib/tabsort.c index 1658426837893156ade7035670e3d78de11a4934..2e3e3a719c5693f9ebe3abca19a2d0e9b199ca6d 100644 --- a/externals/moonlib/tabsort.c +++ b/externals/moonlib/tabsort.c @@ -89,7 +89,10 @@ static void tabsort_float(t_tabsort *x, t_floatarg n) if(n>n2) n=n2; - for(i=0; i<n; vec2[i]=i++); + for(i = 0; i < n; i++) + { + vec2[i] = i; + } for(i=0; i<n-1; i++) for(j=n-1; j>i; j--) diff --git a/externals/moonlib/tabsort2.c b/externals/moonlib/tabsort2.c index 67232de253d5465e952f13bde32aa56c7518ec6b..7f19a3e0c9de5f98c162b503ce2797bf8806d41a 100644 --- a/externals/moonlib/tabsort2.c +++ b/externals/moonlib/tabsort2.c @@ -111,7 +111,10 @@ static void tabsort2_float(t_tabsort2 *x, t_floatarg n) if(n>n2) n=n2; if(n>n3) n=n3; - for(i=0; i<n; vec3[i]=i++); + for(i = 0; i < n; i++) + { + vec3[i] = i; + } for(i=0; i<n-1; i++) for(j=n-1; j>i; j--) diff --git a/pd/src/configure.ac b/pd/src/configure.ac index 77e491283dce6b057c7b0fe707227a28aeef7b90..3f1395ecc2724a59403c47a3a02b095b259f5c42 100644 --- a/pd/src/configure.ac +++ b/pd/src/configure.ac @@ -121,7 +121,7 @@ dnl This should be fixed so Pd can use ALSA shared libraries where appropriate. LDFLAGS="$LDFLAGS -static" fi EXT=pd_linux - CPPFLAGS="-DHAVE_LIBDL -DPA_USE_OSS -DUNIX -DUNISTD -fno-strict-aliasing" + CPPFLAGS="-DHAVE_LIBDL -DPA_USE_OSS -DUNIX -DHAVE_UNISTD_H -fno-strict-aliasing" dnl No OSS on hurd if test `uname -s` = "GNU"; then diff --git a/pd/src/s_main.c b/pd/src/s_main.c index 86cd504f3cb6ecd04c39016d8c765ddc128c8d31..975e42dc97c9d9ae7c9d5284dc1f932e00163ff2 100644 --- a/pd/src/s_main.c +++ b/pd/src/s_main.c @@ -14,7 +14,7 @@ #include <fcntl.h> #include <stdlib.h> -#ifdef UNISTD +#ifdef HAVE_UNISTD_H #include <unistd.h> #endif #ifdef MSW @@ -519,7 +519,7 @@ static char *(usagemessage[]) = { "-send \"msg...\" -- send a message at startup, after patches are loaded\n", "-noprefs -- suppress loading preferences on startup\n", "-console -- open the console along with the pd window\n", -#ifdef UNISTD +#ifdef HAVE_UNISTD_H "-rt or -realtime -- use real-time priority\n", "-nrt -- don't use real-time priority\n", #endif @@ -996,7 +996,7 @@ int sys_argparse(int argc, char **argv) sys_noautopatch = 0; argc--; argv++; } -#ifdef UNISTD +#ifdef HAVE_UNISTD_H else if (!strcmp(*argv, "-rt") || !strcmp(*argv, "-realtime")) { sys_hipriority = 1; diff --git a/pd/src/s_path.c b/pd/src/s_path.c index e7ac2b1ecb8c18937772e7c99b408647333cc252..82df1fcce09135a73fa8a7bdebce750287e9f132 100644 --- a/pd/src/s_path.c +++ b/pd/src/s_path.c @@ -14,7 +14,7 @@ #define DEBUG(x) #include <stdlib.h> -#ifdef UNISTD +#ifdef HAVE_UNISTD_H #include <unistd.h> #include <sys/stat.h> #endif @@ -360,7 +360,7 @@ int sys_trytoopenone(const char *dir, const char *name, const char* ext, if ((fd=open(dirresult,O_RDONLY | MSWOPENFLAG(bin))) >= 0) { /* in unix, further check that it's not a directory */ -#ifdef UNISTD +#ifdef HAVE_UNISTD_H struct stat statbuf; int ok = ((fstat(fd, &statbuf) >= 0) && !S_ISDIR(statbuf.st_mode));