|
From: <set...@us...> - 2006-05-03 23:28:01
|
Revision: 1345 Author: sethdill Date: 2006-05-03 16:27:53 -0700 (Wed, 03 May 2006) ViewCVS: http://svn.sourceforge.net/frontierkernel/?rev=1345&view=rev Log Message: ----------- Mergd trunk changes r1339:1342 into the Conversant branch (Common directory only.) **ALSO** improved conv_concatenateTableStrings in conversant.c, thanks to a little help from a ghost whose name I can't mention yet. ;-) Modified Paths: -------------- Frontier/branches/Conversant/Common/source/conversantverbs.c Frontier/branches/Conversant/Common/source/langmath.c Frontier/branches/Conversant/Common/source/strings.c Modified: Frontier/branches/Conversant/Common/source/conversantverbs.c =================================================================== --- Frontier/branches/Conversant/Common/source/conversantverbs.c 2006-05-03 22:53:20 UTC (rev 1344) +++ Frontier/branches/Conversant/Common/source/conversantverbs.c 2006-05-03 23:27:53 UTC (rev 1345) @@ -966,56 +966,8 @@ return CONV_NOTYPE; } -/** - * Get the size of the value, but coerce val to a string if necessary - * This is essentially a wrapper for langgetvalsize -**/ -static boolean conv_getValueStringLength( tyvaluerecord * pVal, long * pLen ) -{ - if ( (*pVal).valuetype != stringvaluetype ) - { - if ( ! copyvaluerecord( *pVal, pVal ) || ! coercetostring( pVal ) ) - return ( false ); - } - - langgetvalsize( *pVal, pLen ); - - return ( true ); -} - -#if 0 /** - * Add up the lengths of all of the strings in the table -**/ -static unsigned long conv_getTableStringLength( ptrhashtable pTable ) -{ - hdlhashnode nomad; /* trip-trip-tripping merrily through the strings */ - tyvaluerecord val; /* the value record associated with the table cell */ - unsigned long lenResult, /* the final length of the string */ - lenItem; /* the length of one string in the table */ - - lenResult = lenItem = 0; - - nomad = (*pTable).hfirstsort; - - while ( nomad != NULL ) - { - val = (**nomad).val; - - lenItem = conv_getValueStringLength( &val ); - - lenResult += lenItem; - - nomad = (**nomad).sortedlink; - } - - return ( lenResult ); -} -#endif - - -/** * walk through a table, concatenating evertyhing into the result string **/ static boolean conv_concatenateTableStrings( ptrhashtable pTable, Handle * hOutString ) @@ -1023,7 +975,9 @@ handlestream hs; /* this is how we handle writing to the string */ hdlhashnode nomad; /* trip-trip-tripping merrily through the strings */ tyvaluerecord val; /* the value record associated with the table cell */ + tyvaluerecord * pVal; /* pointer to the value being written to the string stream */ long ix; /* position in the handle */ + boolean flCopied = false; /* was the value copied? */ newemptyhandle( hOutString ); @@ -1035,28 +989,43 @@ while ( nomad != NULL ) { - val = (**nomad).val; + pVal = &((**nomad).val); - if ( ! conv_getValueStringLength( &val, &ix ) ) - return ( false ); - - if ( ! writehandlestreamhandle( &hs, val.data.stringvalue ) ) + if ( (*pVal).valuetype != stringvaluetype ) { - closehandlestream( &hs ); - return ( false ); + if ( ! copyvaluerecord( *pVal, &val ) || ! coercetostring( &val ) ) + goto error; + + flCopied = true; + + pVal = &val; } - /* - if ( ! enlargehandle( *hOutString, ix, (ptrvoid) (*((*pVal).data.stringvalue)) ) ) - return ( false ); - */ + if ( ! writehandlestreamhandle( &hs, (*pVal).data.stringvalue ) ) + goto error; nomad = (**nomad).sortedlink; + + if ( flCopied ) + disposevalues( &val, nil ); + + flCopied = false; } closehandlestream( &hs ); return ( true ); + + error: + + closehandlestream( &hs ); + + disposehandlestream( &hs ); + + if ( flCopied ) + disposevalues( &val, nil ); + + return ( false ); } @@ -1076,7 +1045,7 @@ return ( false ); /* - conver the address to an hdlhashtable + convert the address to an hdlhashtable */ if ( ! findnamedtable( adr.ht, adr.bs, &htbl ) ) return ( false ); Modified: Frontier/branches/Conversant/Common/source/langmath.c =================================================================== --- Frontier/branches/Conversant/Common/source/langmath.c 2006-05-03 22:53:20 UTC (rev 1344) +++ Frontier/branches/Conversant/Common/source/langmath.c 2006-05-03 23:27:53 UTC (rev 1345) @@ -1,14 +1,30 @@ /* $Id$ */ -/* - * langmath.c - * Frontier - * - * Created by Seth Dillingham on 12/29/04. - * Copyright 2004 __MyCompanyName__. All rights reserved. - * - */ +/****************************************************************************** + + UserLand Frontier(tm) -- High performance Web content management, + object database, system-level and Internet scripting environment, + including source code editing and debugging. + + Copyright (C) 1992-2004 UserLand Software, Inc. + + 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 + +******************************************************************************/ + #include <math.h> #include "frontier.h" @@ -56,70 +72,87 @@ case minfunc: { /* 2004/12/29 smd */ tyvaluerecord v1, v2; - boolean fl; + tyvaluerecord v1copy, v2copy; + tyvaluerecord * vResult = NULL; + boolean fl = false; - if (!getparamvalue (hp1, 1, &v1)) + if (!getreadonlyparamvalue (hp1, 1, &v1)) break; flnextparamislast = true; - if (!getparamvalue (hp1, 2, &v2)) + if (!getreadonlyparamvalue (hp1, 2, &v2)) break; - if (!coercetypes (&v1, &v2)) { + if (!copyvaluerecord (v1, &v1copy)) /* so that we don't coerce the original */ + break; + + if (!copyvaluerecord (v2, &v2copy)) /* so that we don't coerce the original */ + break; + + if (!coercetypes (&v1copy, &v2copy)) + { + disposevalues (&v1copy, &v2copy); break; } - switch (v1.valuetype) { + switch (v1copy.valuetype) { case novaluetype: { /* no test needed, nil is nil*/ initvalue (v, novaluetype); - return true; + + fl = true; + + break; } - case booleanvaluetype: /* just return an or */ - return setbooleanvalue (v1.data.flvalue || v2.data.flvalue, v); + case booleanvaluetype: /* if v2 is true, then return v1 (false < true) */ + vResult = v2copy.data.flvalue ? &v1 : &v2; + + break; /* all the rest return the greater of the two values */ case charvaluetype: - return setcharvalue (min (v1.data.chvalue, v2.data.chvalue), v); + vResult = ( v1copy.data.chvalue <= v2copy.data.chvalue ) ? &v1 : &v2; + + break; case intvaluetype: - return setintvalue (min (v1.data.intvalue, v2.data.intvalue), v); + vResult = ( v1copy.data.intvalue <= v2copy.data.intvalue ) ? &v1 : &v2; + + break; case longvaluetype: - return setlongvalue (min (v1.data.longvalue, v2.data.longvalue), v); - case ostypevaluetype: - return setostypevalue (min (v1.data.longvalue, v2.data.longvalue), v); + vResult = ( v1copy.data.longvalue <= v2copy.data.longvalue ) ? &v1 : &v2; -/* case fixedvaluetype: - return setfixedvalue (min (v1.data.longvalue, v2.data.longvalue), v); -*/ + break; + case directionvaluetype: - return setdirectionvalue (min ((short) v1.data.dirvalue, (short) v2.data.dirvalue), v); + vResult = ( (short) v1copy.data.dirvalue <= (short) v2copy.data.dirvalue ) ? &v1 : &v2; + break; + case datevaluetype: - return setdatevalue (timegreaterthan (v1.data.datevalue, v2.data.datevalue) ? v1.data.datevalue : v2.data.datevalue, v); + vResult = timegreaterthan( v2copy.data.datevalue, v1copy.data.datevalue ) ? &v1 : &v2; + + break; case singlevaluetype: - return setsinglevalue (min (v1.data.singlevalue, v2.data.singlevalue), v); + vResult = ( v1copy.data.singlevalue <= v2copy.data.singlevalue ) ? &v1 : &v2; + + break; case doublevaluetype: - return setdoublevalue (min (**v1.data.doublevalue, **v2.data.doublevalue), v); + vResult = ( **v1copy.data.doublevalue <= **v2copy.data.doublevalue ) ? &v1 : &v2; + + break; - case stringvaluetype: { + case stringvaluetype: + vResult = ( comparehandles( v1copy.data.stringvalue, v2copy.data.stringvalue ) == 1 ) ? &v2 : &v1; - Handle h; - - if (comparehandles (v1.data.stringvalue, v2.data.stringvalue) == 1) - copyhandle (v2.data.stringvalue, &h); - else - copyhandle (v1.data.stringvalue, &h); - - return (setheapvalue (h, stringvaluetype, v)); - } + break; default: langerror (comparisonnotpossibleerror); @@ -127,80 +160,103 @@ fl = false; /*operation is not defined*/ break; - } /*switch*/ + } /*switch*/ - return (false); + if ( vResult != NULL ) + { + if ( copyvaluerecord( *vResult, v ) ) + fl = true; + + disposevalues( &v1copy, &v2copy ); } + + return ( fl ); + } case maxfunc: { /* 2004/12/29 smd */ tyvaluerecord v1, v2; - boolean fl; + tyvaluerecord v1copy, v2copy; + tyvaluerecord * vResult = NULL; + boolean fl = false; - if (!getparamvalue (hparam1, 1, &v1)) + if (!getreadonlyparamvalue (hp1, 1, &v1)) break; flnextparamislast = true; - if (!getparamvalue (hparam1, 2, &v2)) + if (!getreadonlyparamvalue (hp1, 2, &v2)) break; - if (!coercetypes (&v1, &v2)) { - + if (!copyvaluerecord (v1, &v1copy)) /* so that we don't coerce the original */ + break; + + if (!copyvaluerecord (v2, &v2copy)) /* so that we don't coerce the original */ + break; + + if (!coercetypes (&v1copy, &v2copy)) + { disposevalues (&v1, &v2); break; } - switch (v1.valuetype) { + switch (v1copy.valuetype) { case novaluetype: { /* no test needed, nil is nil*/ initvalue (v, novaluetype); - return true; + + fl = true; + + break; } - case booleanvaluetype: /* just return an or */ - return setbooleanvalue (v1.data.flvalue || v2.data.flvalue, v); + case booleanvaluetype: /* if v2 is true, then return v1 (false < true) */ + vResult = v1copy.data.flvalue ? &v1 : &v2; + + break; /* all the rest return the greater of the two values */ case charvaluetype: - return setcharvalue (max (v1.data.chvalue, v2.data.chvalue), v); + vResult = ( v1copy.data.chvalue >= v2copy.data.chvalue ) ? &v1 : &v2; + + break; case intvaluetype: - return setintvalue (max (v1.data.intvalue, v2.data.intvalue), v); + vResult = ( v1copy.data.intvalue >= v2copy.data.intvalue ) ? &v1 : &v2; + + break; case longvaluetype: - return setlongvalue (max (v1.data.longvalue, v2.data.longvalue), v); - case ostypevaluetype: - return setostypevalue (max (v1.data.longvalue, v2.data.longvalue), v); + vResult = ( v1copy.data.longvalue >= v2copy.data.longvalue ) ? &v1 : &v2; -/* case fixedvaluetype: - return setfixedvalue (max (v1.data.longvalue, v2.data.longvalue), v); -*/ + break; + case directionvaluetype: - return setdirectionvalue (max ((short) v1.data.dirvalue, (short) v2.data.dirvalue), v); + vResult = ( (short) v1copy.data.dirvalue >= (short) v2copy.data.dirvalue ) ? &v1 : &v2; + break; + case datevaluetype: - return setdatevalue (timegreaterthan (v1.data.datevalue, v2.data.datevalue) ? v1.data.datevalue : v2.data.datevalue, v); + vResult = timegreaterthan( v1copy.data.datevalue, v2copy.data.datevalue ) ? &v1 : &v2; + + break; case singlevaluetype: - return setsinglevalue (max (v1.data.singlevalue, v2.data.singlevalue), v); + vResult = ( v1copy.data.singlevalue >= v2copy.data.singlevalue ) ? &v1 : &v2; + + break; case doublevaluetype: - return setdoublevalue (max (**v1.data.doublevalue, **v2.data.doublevalue), v); + vResult = ( **v1copy.data.doublevalue >= **v2copy.data.doublevalue ) ? &v1 : &v2; + + break; - case stringvaluetype: { + case stringvaluetype: + vResult = ( comparehandles( v1copy.data.stringvalue, v2copy.data.stringvalue ) != -1 ) ? &v1 : &v2; - Handle h; - - if (comparehandles (v1.data.stringvalue, v2.data.stringvalue) == 1) - copyhandle (v1.data.stringvalue, &h); - else - copyhandle (v2.data.stringvalue, &h); - - return (setheapvalue (h, stringvaluetype, v)); - } + break; default: langerror (comparisonnotpossibleerror); @@ -208,10 +264,18 @@ fl = false; /*operation is not defined*/ break; - } /*switch*/ + } /*switch*/ - return (false); + if ( vResult != NULL ) + { + if ( copyvaluerecord( *vResult, v ) ) + fl = true; + + disposevalues( &v1copy, &v2copy ); } + + return ( fl ); + } case sqrtfunc: { /* 2004/12/29 smd */ Modified: Frontier/branches/Conversant/Common/source/strings.c =================================================================== --- Frontier/branches/Conversant/Common/source/strings.c 2006-05-03 22:53:20 UTC (rev 1344) +++ Frontier/branches/Conversant/Common/source/strings.c 2006-05-03 23:27:53 UTC (rev 1345) @@ -3000,6 +3000,8 @@ boolean macromantoutf8 (Handle h, Handle hresult) { /* + 2006-05-03 creedon: fixed bug introduced in changeover to use converttextencoding function, reverse encIn and encOut + values 2006-02-24 creedon: convert from Mac Roman character set to UTF-8, cribbed from ansitoutf8 */ @@ -3015,8 +3017,8 @@ #ifdef MACVERSION - encIn = kCFStringEncodingUTF8; - encOut = kTextEncodingMacRoman; + encIn = kTextEncodingMacRoman; + encOut = kCFStringEncodingUTF8; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |