diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2004-03-26 03:22:11 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2004-03-26 03:22:11 +0000 |
commit | 5b821a81fc7c9ed7decfe5575a867ab82464b0cc (patch) | |
tree | 9a5ad718cc024066d53f46937b32dacb64d97e4d /externals/grill/flext/source | |
parent | 62a9baa7736d938b672a839b88f0bb4c8e511437 (diff) |
""
svn path=/trunk/; revision=1480
Diffstat (limited to 'externals/grill/flext/source')
-rw-r--r-- | externals/grill/flext/source/flatom_pr.cpp | 23 | ||||
-rw-r--r-- | externals/grill/flext/source/flstdc.h | 2 | ||||
-rw-r--r-- | externals/grill/flext/source/flsupport.cpp | 25 | ||||
-rw-r--r-- | externals/grill/flext/source/flsupport.h | 10 |
4 files changed, 32 insertions, 28 deletions
diff --git a/externals/grill/flext/source/flatom_pr.cpp b/externals/grill/flext/source/flatom_pr.cpp index 2e35f89c..9d5eeb29 100644 --- a/externals/grill/flext/source/flatom_pr.cpp +++ b/externals/grill/flext/source/flatom_pr.cpp @@ -18,34 +18,38 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include <string.h> #include <stdio.h> +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + // \TODO take bufsz into account! bool flext::PrintAtom(const t_atom &a,char *buf,int bufsz) { bool ok = true; if(IsFloat(a)) { - STD::sprintf(buf,"%g",GetFloat(a)); + STD::snprintf(buf,bufsz,"%g",GetFloat(a)); } else if(IsInt(a)) { - STD::sprintf(buf,"%i",GetInt(a)); + STD::snprintf(buf,bufsz,"%i",GetInt(a)); } else if(IsSymbol(a)) { if(!FLEXT_ASSERT(GetSymbol(a))) *buf = 0; else - STD::strcpy(buf,GetString(a)); + STD::strncpy(buf,GetString(a),bufsz); } else if(IsPointer(a)) { - STD::sprintf(buf,"%p",GetPointer(a)); + STD::snprintf(buf,bufsz,"%p",GetPointer(a)); } #if FLEXT_SYS == FLEXT_SYS_PD else if(a.a_type == A_DOLLAR) { - STD::sprintf(buf,"$%d",a.a_w.w_index); + STD::snprintf(buf,bufsz,"$%d",a.a_w.w_index); } else if(a.a_type == A_DOLLSYM) { - STD::sprintf(buf,"$%s",GetString(a)); + STD::snprintf(buf,bufsz,"$%s",GetString(a)); } #elif FLEXT_SYS == FLEXT_SYS_MAX else if(a.a_type == A_DOLLAR) { - STD::sprintf(buf,"$%d",a.a_w.w_long); + STD::snprintf(buf,bufsz,"$%d",a.a_w.w_long); } #else //#pragma message("Not implemented") @@ -74,11 +78,6 @@ bool flext::PrintList(int argc,const t_atom *argv,char *buf,int bufsz) return ok; } -bool flext::AtomList::Print(char *buffer,int buflen) const -{ - return flext::PrintList(Count(),Atoms(),buffer,buflen); -} - bool flext::ScanAtom(t_atom &a,const char *buf) { diff --git a/externals/grill/flext/source/flstdc.h b/externals/grill/flext/source/flstdc.h index 4927435c..f55b362b 100644 --- a/externals/grill/flext/source/flstdc.h +++ b/externals/grill/flext/source/flstdc.h @@ -111,7 +111,7 @@ typedef t_int t_flint; typedef t_symbol *t_symtype; typedef t_object *t_thing; -typedef qelem t_qelem; +typedef void *t_qelem; typedef method t_method; typedef method t_newmethod; diff --git a/externals/grill/flext/source/flsupport.cpp b/externals/grill/flext/source/flsupport.cpp index cc300b95..c453aae2 100644 --- a/externals/grill/flext/source/flsupport.cpp +++ b/externals/grill/flext/source/flsupport.cpp @@ -18,6 +18,11 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include <stdarg.h> #include <new> +#ifdef _MSC_VER +#define vsnprintf _vsnprintf +#define snprintf _snprintf +#endif + const t_symbol *flext::sym_float = NULL; const t_symbol *flext::sym_symbol = NULL; const t_symbol *flext::sym_bang = NULL; @@ -263,10 +268,9 @@ void flext::GetAString(const t_atom &a,char *buf,int szbuf) #if FLEXT_SYS == FLEXT_SYS_PD atom_string(const_cast<t_atom *>(&a),buf,szbuf); #else - // no checking for size here - if(IsSymbol(a)) STD::sprintf(buf,GetString(a)); - else if(IsFloat(a)) STD::sprintf(buf,"%f",GetFloat(a)); - else if(IsInt(a)) STD::sprintf(buf,"%i",GetInt(a)); + if(IsSymbol(a)) STD::strncpy(buf,GetString(a),szbuf); + else if(IsFloat(a)) STD::snprintf(buf,szbuf,"%f",GetFloat(a)); + else if(IsInt(a)) STD::snprintf(buf,szbuf,"%i",GetInt(a)); else *buf = 0; #endif } @@ -280,14 +284,14 @@ unsigned long flext::AtomHash(const t_atom &a) #endif } - void flext_root::post(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - char buf[1024]; // \TODO this is quite unsafe..... - vsprintf(buf, fmt, ap); + char buf[1024]; + vsnprintf(buf,sizeof buf,fmt, ap); + buf[sizeof buf-1] = 0; // in case of full buffer ::post(buf); va_end(ap); @@ -298,9 +302,10 @@ void flext_root::error(const char *fmt,...) va_list ap; va_start(ap, fmt); - char buf[1024]; // \TODO this is quite unsafe..... - STD::sprintf(buf,"error: "); - vsprintf(buf+7, fmt, ap); + char buf[1024]; + strcpy(buf,"error: "); + vsnprintf(buf+7,sizeof buf-7,fmt, ap); + buf[sizeof buf-1] = 0; // in case of full buffer ::post(buf); va_end(ap); diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h index f8191fd3..fca7535e 100644 --- a/externals/grill/flext/source/flsupport.h +++ b/externals/grill/flext/source/flsupport.h @@ -35,10 +35,10 @@ class FLEXT_SHARE FLEXT_CLASSDEF(flext_root) { public: // --- console output ----------------------------------------------- - //! post message to console - static void post(const char *s,...); - //! post error message to console - static void error(const char *s,...); + //! post message to console, with line feed (limited to 1k chars!) + static void post(const char *fmt,...); + //! post error message to console (limited to 1k chars!) + static void error(const char *fmt,...); // --- memory ------------------------------------------------------- @@ -567,7 +567,7 @@ public: AtomList &Part(int offs,int len) { return (*this = GetPart(offs,len)); } //! Represent as a string - bool Print(char *buffer,int buflen) const; + bool Print(char *buffer,int buflen) const { return flext::PrintList(Count(),Atoms(),buffer,buflen); } protected: int cnt; |