appletstrings.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletstrings.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include <Packages.h>
00008 #include "appletops.h"
00009 #include "appletmemory.h"
00010 #include "appletstrings.h"
00011 
00012 
00013 boolean isPunctuationChar (char ch) {
00014     
00015     if ((ch >= '!') && (ch <= '/')) 
00016         return (true);
00017         
00018     if ((ch >= ':') && (ch <= '?'))
00019         return (true);
00020     
00021     return (false);
00022     } /*isPunctuationChar*/
00023     
00024 
00025 boolean isAlphaChar (char ch) {
00026     
00027     if ((ch >= 'a') && (ch <= 'z'))
00028         return (true);
00029         
00030     if ((ch >= 'A') && (ch <= 'Z'))
00031         return (true);
00032         
00033     if ((ch >= '0') && (ch <= '9')) 
00034         return (true);
00035         
00036     if (ch == '_')
00037         return (true);
00038 
00039     return (false);
00040     } /*isAlphaChar*/
00041     
00042 
00043 static short IUcomparestrings (bigstring bs1, bigstring bs2) {
00044 
00045     /*
00046     return zero if the two strings (pascal type, with length-byte) are
00047     equal.  return -1 if bs1 is less than bs2, or +1 if bs1 is greater than
00048     bs2.
00049     
00050     use the Macintosh international utility routine IUCompString, which 
00051     performs dictionary string comparison and accounts for accented characters
00052     */
00053     
00054     short result;
00055     
00056     result = IUCompString (bs1, bs2);
00057     
00058     return (result);
00059     } /*IUcomparestrings*/
00060 
00061 
00062 short comparestrings (void *pvoid1, void *pvoid2) {
00063 
00064     /*
00065     return zero if the two strings (pascal type, with length-byte) are
00066     equal.  return -1 if bs1 is less than bs2, or +1 if bs1 is greater than
00067     bs2.
00068     
00069     this version does not call the IU package, and performs much better
00070     than the one that does.
00071     
00072     dmb 9/21/93: fixed two bugs
00073     */
00074     
00075     unsigned char *bs1 = (unsigned char *) pvoid1, *bs2 = (unsigned char *) pvoid2;
00076     unsigned char len1 = bs1 [0];
00077     unsigned char len2 = bs2 [0];
00078     unsigned char *p1 = &bs1 [1];
00079     unsigned char *p2 = &bs2 [1];
00080     
00081     while (len1 > 0) {
00082         
00083         if (len2 == 0) /*bs1 is longer, therefore bs1 is greater than bs2*/
00084             return (1);
00085         
00086         if (*p1 != *p2) {
00087             
00088             if (*p1 < *p2)
00089                 return (-1);
00090             else
00091                 return (+1);
00092             }
00093         
00094         p1++; p2++; 
00095         
00096         len1--; len2--;
00097         } /*while*/
00098     
00099     if (len2 == 0) /*the strings are of equal length, same chars*/
00100         return (0);
00101         
00102     return (-1); /*bs2 is longer, therefore bs1 is less than bs2*/
00103     } /*comparestrings*/
00104 
00105 
00106 boolean equalstrings (void *pvoid1, void *pvoid2) {
00107 
00108     /*
00109     return true if the two strings (pascal type, with length-byte) are
00110     equal.  return false otherwise.
00111     */
00112 
00113     ptrchar p1 = (ptrchar) pvoid1, p2 = (ptrchar) pvoid2;
00114     char ct = *p1 + 1;
00115     
00116     /*DW 12/31/95*/ {
00117     
00118         unsigned char len1, len2;
00119         
00120         len1 = *p1;
00121         
00122         len2 = *p2;
00123         
00124         if (len1 != len2)
00125             return (false);
00126         }
00127     
00128     while (ct--) 
00129         
00130         if (*p1++ != *p2++)
00131         
00132             return (false);
00133         
00134     return (true); /*loop terminated*/
00135     } /*equalstrings*/
00136     
00137     
00138 boolean unicaseequalstrings (void *pvoid1, void *pvoid2) {
00139     
00140     bigstring bscopy1, bscopy2;
00141     
00142     copystring (pvoid1, bscopy1);
00143     
00144     copystring (pvoid2, bscopy2);
00145     
00146     alllower (bscopy1);
00147     
00148     alllower (bscopy2);
00149     
00150     return (equalstrings (bscopy1, bscopy2));
00151     } /*unicaseequalstrings*/
00152     
00153 
00154 void copystring (void *bssource, void *bsdest) {
00155 
00156     /*
00157     create a copy of bssource in bsdest.  copy the length byte and
00158     all the characters in the source string.
00159 
00160     assume the strings are pascal strings, with the length byte in
00161     the first character of the string.
00162     
00163     DW 4/3/95: wouldn't copy strings that are longer than 128 chars!
00164     */
00165 
00166     short i, len;
00167     
00168     len = (short) ((unsigned char *) bssource) [0];
00169     
00170     for (i = 0; i <= len; i++) 
00171         ((unsigned char *) bsdest) [i] = ((unsigned char *) bssource) [i];
00172     } /*copystring*/
00173 
00174 
00175 boolean pushstring (void *bssource, void *bsdest) {
00176 
00177     /*
00178     insert the source string at the end of the destination string.
00179     
00180     assume the strings are pascal strings, with the length byte in
00181     the first character of the string.
00182     */
00183     
00184     unsigned short lensource = stringlength ((unsigned char *) bssource);
00185     unsigned short lendest = stringlength ((unsigned char *) bsdest);
00186     char *psource, *pdest;
00187     
00188     if ((lensource + lendest) > lenbigstring)
00189         return (false);
00190         
00191     pdest = (ptrchar) bsdest + (unsigned char) lendest + 1;
00192     
00193     psource = (ptrchar) bssource + 1;
00194     
00195     ((unsigned char *) bsdest) [0] += (unsigned char) lensource;
00196     
00197     while (lensource--) *pdest++ = *psource++;
00198     
00199     return (true);
00200     } /*pushstring*/
00201     
00202 
00203 boolean pushspace (void *pstring) {
00204         
00205     bigstring bsspace;
00206     
00207     setstringlength (bsspace, 1);
00208     
00209     bsspace [1] = ' ';
00210     
00211     return (pushstring (bsspace, pstring));
00212     } /*pushspace*/
00213     
00214 
00215 void pushlong (long num, void *pstring) {
00216 
00217     bigstring bsint;
00218     
00219     NumToString (num, bsint);
00220     
00221     pushstring (bsint, pstring);
00222     } /*pushlong*/
00223     
00224 
00225 void pushint (short num, void *pstring) {
00226     
00227     pushlong ((long) num, pstring);
00228     } /*pushint*/
00229     
00230     
00231 void pushostype (OSType os, void *pstring) {
00232     
00233     bigstring bsos;
00234     
00235     setstringlength (bsos, 4);
00236     
00237     moveleft (&os, &bsos [1], 4);
00238     
00239     pushstring (bsos, pstring);
00240     } /*pushostype*/
00241     
00242     
00243 void pushtimeonstring (void *pstring) {
00244     
00245     unsigned long now;
00246     bigstring bstime;
00247     
00248     GetDateTime (&now);
00249     
00250     gettimestring (now, bstime);
00251     
00252     pushstring (bstime, pstring);
00253     } /*pushtimeonstring*/
00254     
00255     
00256 void allupper (void *pstring) {
00257     
00258     ptrchar p = (ptrchar) pstring;
00259     char len = *p;
00260     char ch;
00261     
00262     p++;
00263     
00264     while (len--) {
00265         
00266         ch = *p;
00267         
00268         if ((ch >= 'a') && (ch <= 'z'))
00269             *p -= 32;
00270             
00271         p++;
00272         } /*while*/
00273     } /*allupper*/
00274     
00275     
00276 void alllower (void *pstring) {
00277     
00278     ptrchar p = (ptrchar) pstring;
00279     char len = *p;
00280     char ch;
00281     
00282     p++;
00283     
00284     while (len--) {
00285         
00286         ch = *p;
00287         
00288         if ((ch >= 'A') && (ch <= 'Z'))
00289             *p += 32;
00290             
00291         p++;
00292         } /*while*/
00293     } /*alllower*/
00294     
00295     
00296 boolean stringlessthan (void *p1, void *p2) {
00297     
00298     unsigned char *bs1 = (unsigned char *) p1, *bs2 = (unsigned char *) p2;
00299     short i, ctloops;
00300     char ch1, ch2;
00301     short len1, len2;
00302     
00303     len1 = (short) bs1 [0];
00304     
00305     len2 = (short) bs2 [0];
00306     
00307     ctloops = minint (len1, len2);
00308     
00309     for (i = 1; i <= ctloops; i++) {
00310         
00311         ch1 = bs1 [i];
00312         
00313         ch2 = bs2 [i];
00314         
00315         if (ch1 != ch2) /*we have our answer*/
00316             return (ch1 < ch2);
00317         } /*for*/
00318     
00319     return (len1 < len2); /*loop terminated, strings are equal up to the min length*/
00320     } /*stringlessthan*/
00321     
00322     
00323 void midstring (void *psource, short ix, short len, void *pdest) {
00324     
00325     unsigned char *bssource = (unsigned char *) psource, *bsdest = (unsigned char *) pdest;
00326     
00327     setstringlength (bsdest, len);
00328     
00329     moveleft (bssource + ix, bsdest + 1, (long) len);
00330     } /*midstring*/
00331     
00332     
00333 boolean pushchar (byte ch, void *pstring) {
00334     
00335     /*
00336     insert the character at the end of a pascal string.
00337     */
00338     
00339     unsigned char *bs = (unsigned char *) pstring;
00340     short len;
00341     
00342     len = bs [0]; 
00343     
00344     if (len >= lenbigstring)
00345         return (false);
00346     
00347     bs [++len] = ch;
00348     
00349     bs [0] = len;
00350     
00351     return (true);
00352     } /*pushchar*/
00353     
00354     
00355 boolean scanstring (byte ch, void *pstring, short *ix) {
00356     
00357     /*
00358     return in ix the index in the string of the first occurence of chscan.
00359     NOTE: ix MUST be initizlied to starting location!!!
00360     
00361     return false if it wasn't found, true otherwise.
00362     
00363     dmb 10/26/90: p is now initialized correctly to bs + i, not bs + 1
00364     
00365     ldr 10/08/95: get the length of pstring, not bs!
00366     */
00367     
00368     byte *bs = (byte *) pstring;
00369     short i;
00370     ptrbyte p;
00371     byte c = ch;
00372     short len = stringlength ((unsigned char *)pstring);
00373     
00374     for (i = *ix, p = bs + i; i <= len; i++) 
00375         
00376         if (*p++ == c) {
00377             
00378             *ix = i;
00379             
00380             return (true);
00381             }
00382             
00383     return (false);
00384     } /*scanstring*/
00385 
00386 
00387 boolean deletestring (void *pstring, short ixdelete, short ctdelete) {
00388     
00389     byte *bs = (byte *) pstring;
00390     short ix = ixdelete;
00391     short ct = ctdelete;
00392     short len = stringlength (bs);
00393     long ctmove;
00394     ptrbyte pfrom, pto;
00395     short maxct;
00396     
00397     maxct = len - ix + 1;
00398     
00399     if (ct > maxct)
00400         ct = maxct; 
00401     
00402     if ((ix > len) || (ix < 1))
00403         return (false);
00404         
00405     if (ct <= 0)
00406         return (ct == 0);
00407         
00408     ctmove = len - ix - ct + 1;
00409      
00410     if (ctmove > 0) {
00411         
00412         pfrom = bs + ix + ct;
00413         
00414         pto = bs + ix;
00415         
00416         moveleft (pfrom, pto, ctmove);
00417         }
00418     
00419     setstringlength (bs, len - ct);
00420     
00421     return (true);
00422     } /*deletestring*/
00423     
00424     
00425 boolean firstword (void *psource, char chdelim, void *pdest) {
00426     
00427     /*
00428     copy the first word from bs, and put it into bsdest.
00429     
00430     search forwards from the beginning of the source string until you 
00431     find chdelim.
00432     */
00433     
00434     unsigned char *bssource = (unsigned char *) psource, *bsdest = (unsigned char *) pdest;
00435     short len = stringlength (bssource);
00436     short i;
00437     char ch = chdelim;
00438     
00439     for (i = 1; i <= len; i++) {
00440         
00441         if (bssource [i] == ch) {
00442             
00443             midstring (bssource, 1, i - 1, bsdest);
00444             
00445             return (true);
00446             }
00447         } /*for*/
00448         
00449     copystring (bssource, bsdest);
00450     
00451     return (true);
00452     } /*firstword*/
00453 
00454 
00455 boolean lastword (void *psource, char chdelim, void *pdest) {
00456     
00457     /*
00458     copy the last word from bs, and put it into bsdest.
00459     
00460     search backwards from the end of the source string until you find
00461     chdelim.
00462     */
00463     
00464     unsigned char *bssource = (unsigned char *) psource, *bsdest = (unsigned char *) pdest;
00465     short len = stringlength (bssource);
00466     short i;
00467     char ch = chdelim;
00468     
00469     for (i = len; i > 0; i--) {
00470         
00471         if (bssource [i] == ch) {
00472             
00473             midstring (bssource, i + 1, len - i, bsdest);
00474             
00475             return (true);
00476             }
00477         } /*for*/
00478         
00479     copystring (bssource, bsdest);
00480     
00481     return (true);
00482     } /*lastword*/
00483     
00484     
00485 short patternmatch (void *ppattern, void *pstring) {
00486     
00487     unsigned char *bspattern = (unsigned char *) ppattern, *bs = (unsigned char *) pstring;
00488     short lenstring = stringlength (bs);
00489     short lenpattern = stringlength (bspattern);
00490     short ixstring = 1;
00491     byte chfirst;
00492     short i, ix;
00493     
00494     if ((lenstring == 0) || (lenpattern == 0))
00495         return (0);
00496     
00497     chfirst = bspattern [1];
00498     
00499     while (true) {
00500         
00501         if (bs [ixstring] == chfirst) { /*matched at least first character in string*/
00502             
00503             for (i = 2; i <= lenpattern; i++) {
00504                 
00505                 ix = ixstring + i - 1;
00506                 
00507                 if (ix > lenstring) /*gone off end of string, can't match*/
00508                     return (0);
00509                 
00510                 if (bs [ix] != bspattern [i]) 
00511                     goto L1;
00512                 } /*for*/
00513             
00514             return (ixstring); /*loop terminated, full match*/
00515             }
00516         
00517         L1: /*advance to next character in string*/
00518         
00519         if (++ixstring > lenstring) /*reached end of string, not found*/
00520             return (0);
00521         } /*while*/
00522     } /*patternmatch*/
00523 
00524 
00525 void filledstring (char ch, short ct, void *pstring) {
00526     
00527     unsigned char *bs = (unsigned char *) pstring;
00528     
00529     if (ct < 0)
00530         ct = 0;
00531         
00532     bs [0] = ct;
00533     
00534     fillchar (&bs [1], (long) ct, ch);
00535     } /*filledstring*/
00536 
00537 
00538 boolean insertstring (unsigned char *psource, unsigned char *pdest) {
00539     
00540     /*
00541     insert the source string at the beginning of the destination string.
00542     
00543     return false if the resulting string would be longer than 255 chars.
00544     */
00545     
00546     register short len1 = stringlength (psource), len2 = stringlength (pdest);
00547     bigstring bs;
00548     
00549     if ((len1 + len2) > lenbigstring) /*resulting string would be too long*/
00550         return (false);
00551         
00552     copystring (psource, bs);
00553     
00554     pushstring (pdest, bs);
00555     
00556     copystring (bs, pdest);
00557     
00558     return (true);
00559     } /*insertstring*/
00560 
00561 
00562 boolean insertchar (char ch, void *pstring) {
00563     
00564     byte *pdest = (byte *) pstring;
00565     short len = stringlength (pdest);
00566     
00567     if (len == lenbigstring)
00568         return (false);
00569     
00570     moveright (pdest + 1, pdest + 2, len);
00571     
00572     setstringlength (pdest, len + 1);
00573     
00574     pdest [1] = ch;
00575     
00576     return (true);
00577     } /*insertchar*/
00578 
00579 
00580 void stringtonumber (void *pstring, long *num, boolean *flerror) {
00581     
00582     unsigned char *bs = (unsigned char *) pstring;
00583     short len = stringlength (bs);
00584     boolean notfirstchar = false;
00585     short i;
00586     
00587     for (i = 1; i <= len; i++) {
00588         
00589         char ch = bs [i];
00590         
00591         if (ch == ' ')
00592             continue;
00593             
00594         if ((ch == '+') || (ch == '-')) {
00595             
00596             if (notfirstchar) {
00597                 
00598                 *flerror = true;
00599                 
00600                 return;
00601                 }
00602                 
00603             notfirstchar = true;
00604             
00605             continue;
00606             }
00607             
00608         if ((ch < '0') || (ch > '9')) {
00609             
00610             *flerror = true;
00611             
00612             return;
00613             }
00614             
00615         notfirstchar = true;
00616         } /*for*/
00617     
00618     StringToNum ((ConstStr255Param) bs, num); /*call the toolbox routine*/
00619     
00620     *flerror = false;
00621     } /*stringtonumber*/
00622     
00623     
00624 void getsizestring (unsigned long size, void *pstring) {
00625     
00626     unsigned char *bs = (unsigned char *) pstring;
00627     unsigned long meg = 1024L * 1024L;
00628     
00629     if (size > meg) { /*greater than 1 megabyte*/
00630         
00631         unsigned long leftofdecimal, rightofdecimal;
00632         bigstring bsright;
00633         
00634         leftofdecimal = size / meg;
00635         
00636         rightofdecimal = ((size % meg) + 50) / 100;
00637         
00638         NumToString (leftofdecimal, (byte *) bs);
00639         
00640         NumToString (rightofdecimal, bsright);
00641         
00642         setstringlength (bsright, 1);
00643         
00644         if (bsright [1] != '0') {
00645         
00646             pushstring ("\p.", bs);
00647         
00648             pushstring (bsright, bs);
00649             }
00650         
00651         pushstring ("\pMB", bs);
00652         }
00653     else {
00654         unsigned long x = size / 1024;
00655     
00656         if ((size % 1024) > 512)
00657             x++;
00658         
00659         if (x == 0)
00660             copystring ("\pzero ", bs);
00661         else
00662             NumToString (x, (byte *) bs);
00663             
00664         pushstring ("\pK", bs);
00665         }
00666     } /*getsizestring*/     
00667 
00668 
00669 void gettimestring (long time, void *pstring) {
00670     
00671     unsigned char *bs = (unsigned char *) pstring;
00672     bigstring bstime;
00673     
00674     IUDateString (time, abbrevDate, (byte *) bs);
00675     
00676     IUTimeString (time, false, bstime);
00677     
00678     pushstring ("\p; ", bs);
00679     
00680     pushstring (bstime, bs);
00681     } /*gettimestring*/ 
00682     
00683     
00684 void commentdelete (byte chdelim, void *pstring) {
00685     
00686     /*
00687     scan the string from left to right.  if we find a comment delimiting
00688     character, delete all the characters to the right, including the
00689     delimiter and return.
00690     
00691     10/30/91 dmb: ignore comment characters that are embedded in quoted strings
00692     */
00693     
00694     unsigned char *bs = (unsigned char *) pstring;
00695     byte chcomment = chdelim;
00696     short i, ct;
00697     byte ch;
00698     boolean flinstring = false;
00699     byte chendstring;
00700     
00701     ct = stringlength (bs);
00702     
00703     for (i = 1; i <= ct; i++) {
00704         
00705         ch = bs [i];
00706         
00707         if (flinstring)
00708             flinstring = ch != chendstring;
00709         
00710         else if (ch == (byte) '"') {
00711             
00712             flinstring = true;
00713             
00714             chendstring = '"';
00715             }
00716         
00717         else if (ch == (byte) '') {
00718             
00719             flinstring = true;
00720             
00721             chendstring = '';
00722             }
00723         
00724         else if (ch == chcomment) {
00725             
00726             setstringlength (bs, i - 1);
00727             
00728             return;
00729             }
00730         }
00731     } /*commentdelete*/
00732     
00733     
00734 static boolean whitespacechar (char ch) {
00735     
00736     return (ch == ' ');
00737     } /*whitespacechar*/
00738     
00739 
00740 boolean poptrailingwhitespace (void *pstring) {
00741     
00742     /*
00743     return true if there were trailing "whitespace" characters to be popped.
00744     */
00745     
00746     unsigned char *bs = (unsigned char *) pstring;
00747     short i, ct;
00748     
00749     ct = stringlength (bs);
00750     
00751     for (i = ct; i > 0; i--)
00752     
00753         if (!whitespacechar (bs [i])) { /*found a non-blank character*/
00754             
00755             setstringlength (bs, i);
00756             
00757             return (i < ct);
00758             }
00759     
00760     setemptystring (bs);
00761     
00762     return (true); /*string is all blank*/
00763     } /*poptrailingwhitespace*/
00764 
00765 
00766 static boolean midinsertstring (void *pinsert, void *pstring, short ixinsert) {
00767     
00768     /*
00769     insert bsinsert in the indicated string at offset ixinsert.
00770     */
00771     
00772     unsigned char *bsinsert = (unsigned char *) pinsert, *bs = (unsigned char *) pstring;
00773     short ix = ixinsert;
00774     short leninsert = stringlength (bsinsert);
00775     short origlen = stringlength (bs);
00776     short newlen = leninsert + origlen;
00777     
00778     if (newlen > lenbigstring)
00779         return (false);
00780     
00781     moveright (&bs [ix], &bs [ix + leninsert], (long) origlen - ix + 1);
00782     
00783     moveleft (&bsinsert [1], &bs [ix], (long) leninsert);
00784     
00785     setstringlength (bs, newlen);
00786     
00787     return (true);
00788     } /*midinsertstring*/
00789 
00790 
00791 boolean replacestring (void *preplace, short ix, short ctreplace, void *pinsert) {
00792     
00793     /*
00794     4/3/92 dmb: check for overflow before doing deletion
00795     */
00796     
00797     unsigned char *bsreplace = (unsigned char *) preplace, *bsinsert = (unsigned char *) pinsert;
00798     
00799     if (stringlength (bsreplace) + (stringlength (bsinsert) - ctreplace) > lenbigstring)
00800         return  (false);
00801     
00802     deletestring (bsreplace, ix, ctreplace);
00803     
00804     midinsertstring (bsinsert, bsreplace, ix);
00805     
00806     return (true);
00807     } /*replacestring*/
00808 
00809 
00810 boolean stringfindchar (byte ch, void *pstring) {
00811     
00812     /*
00813     simpler entrypoint for scanstring when caller just wants 
00814     to know if ch appears anywhere in bs
00815     */
00816     
00817     short ix = 1;
00818     
00819     return (scanstring (ch, pstring, &ix));
00820     } /*stringfindchar*/
00821 
00822 
00823 void parseparamstring (bigstring bssource, bigstring bs0, bigstring bs1, bigstring bs2, bigstring bs3, bigstring bsresult) {
00824     
00825     /*
00826     parse a string with up to four string parameters, following the syntax
00827     used by the Macintosh Dialog Manager in parsing strings.
00828     
00829     return the result of parsing bs in bsresult.
00830     
00831     where ^0 appears in text, push bs0 on the result string.
00832     
00833     may get fancier later, what if we allow you to imbed UserLand code?
00834     
00835     we work on a copy of the source string, so you may pass in the same string in
00836     bssource and bsresult.
00837     
00838     dmb 10/8/90: accept nil parameters
00839     */
00840     
00841     bigstring bs;
00842     short len;
00843     short i;
00844     byte ch;
00845     StringPtr params [4];
00846     short paramnum;
00847     
00848     copystring (bssource, bs); /*work on a copy of the source string*/
00849     
00850     len = stringlength (bs); /*copy into register*/
00851     
00852     params [0] = bs0;
00853     
00854     params [1] = bs1;
00855     
00856     params [2] = bs2;
00857     
00858     params [3] = bs3;
00859     
00860     setemptystring (bsresult);
00861     
00862     for (i = 1; i <= len; i++) {
00863         
00864         ch = bs [i];
00865         
00866         if (ch != '^')
00867             pushchar (ch, bsresult);
00868             
00869         else {
00870             if (i == len) /*the ^ is at the end of the string, no number*/
00871                 return;
00872             
00873             paramnum = bs [i + 1] - '0'; /*index into params array*/
00874             
00875             if ((paramnum >= 0) && (paramnum <= 3)) {
00876                 
00877                 assert (params [paramnum] != nil); /*string should always be provided*/
00878                 
00879                 pushstring (params [paramnum], bsresult);
00880                 
00881                 i++; /*advance over numeric character*/
00882                 }
00883             else
00884                 pushchar ('^', bsresult); 
00885             }
00886         } /*for*/
00887     
00888     /***subtractstrings (bsresult, "\p ", bsresult); /*in case there was a missing param*/
00889     } /*parseparamstring*/
00890 
00891 
00892 void colortostring (RGBColor rgb, bigstring bs) {
00893     
00894     setstringlength (bs, 0);
00895     
00896     pushint (rgb.red, bs);
00897     
00898     pushchar (',', bs);
00899     
00900     pushint (rgb.green, bs);
00901     
00902     pushchar (',', bs);
00903     
00904     pushint (rgb.blue, bs);
00905     } /*colortostring*/
00906      
00907     
00908 void stringtocolor (bigstring bs, RGBColor *rgb) {
00909     
00910     bigstring bsint;
00911     long num;
00912     boolean flerror;
00913     
00914     (*rgb).red = (*rgb).blue = (*rgb).green = 0;
00915     
00916     if (firstword (bs, ',', bsint)) {
00917         
00918         stringtonumber (bsint, &num, &flerror);
00919         
00920         if (!flerror)
00921             (*rgb).red = num;
00922         
00923         deletestring (bs, 1, stringlength (bsint) + 1);
00924         }
00925     
00926     if (firstword (bs, ',', bsint)) {
00927         
00928         stringtonumber (bsint, &num, &flerror);
00929         
00930         if (!flerror)
00931             (*rgb).green = num;
00932         
00933         deletestring (bs, 1, stringlength (bsint) + 1);
00934         }
00935     
00936     stringtonumber (bs, &num, &flerror);
00937         
00938     if (!flerror)
00939         (*rgb).blue = num;
00940     } /*stringtocolor*/
00941     
00942      
00943 boolean stringendswith (bigstring ending, bigstring bs, boolean flunicase) {
00944     
00945     short endinglength = stringlength (ending);
00946     bigstring bscopy;
00947     
00948     if (stringlength (bs) < endinglength)
00949         return (false);
00950         
00951     midstring (bs, stringlength (bs) - endinglength + 1, endinglength, bscopy);
00952     
00953     if (flunicase)
00954         return (unicaseequalstrings (bscopy, ending));
00955     else
00956         return (equalstrings (bscopy, ending));
00957     } /*stringendswith*/
00958     
00959 
00960     
00961     
00962     

Generated on Wed May 31 18:19:44 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6