Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

cstring.c File Reference

#include "lclintMacros.nf"
#include "basic.h"
#include "osd.h"
#include "portab.h"

Go to the source code of this file.

Functions

char cstring_firstChar (cstring s)
char cstring_getChar (cstring s, int n)
cstring cstring_suffix (cstring s, int n)
cstring cstring_prefix (cstring s, int n)
int cstring_toPosInt (cstring s)
cstring cstring_beforeChar (cstring s, char c)
void cstring_setChar (cstring s, int n, char c)
char cstring_lastChar (cstring s)
cstring cstring_copy (cstring s)
cstring cstring_copyLength (char *s, int len)
bool cstring_containsChar (cstring c, char ch)
void cstring_replaceLit ( cstring s, char *old, char *snew)
void cstring_stripChars (cstring s, const char *clist)
bool cstring_contains ( cstring c, cstring sub)
cmpcode cstring_genericEqual (cstring s, cstring t, int nchars, bool caseinsensitive, bool lookalike)
bool cstring_equalFree ( cstring c1, cstring c2)
bool cstring_equal (cstring c1, cstring c2)
bool cstring_equalLen (cstring c1, cstring c2, int len)
bool cstring_equalCaseInsensitive (cstring c1, cstring c2)
bool cstring_equalLenCaseInsensitive (cstring c1, cstring c2, int len)
bool cstring_equalPrefix (cstring c1, char *c2)
bool cstring_equalCanonicalPrefix (cstring c1, char *c2)
int cstring_xcompare (cstring *c1, cstring *c2)
int cstring_compare (cstring c1, cstring c2)
void cstring_markOwned ( cstring s)
void cstring_free ( cstring s)
cstring cstring_fromChars ( const char *cp)
char* cstring_toCharsSafe (cstring s)
int cstring_length (cstring s)
cstring cstring_capitalize (cstring s)
cstring cstring_capitalizeFree (cstring s)
cstring cstring_clip (cstring s, int len)
cstring cstring_elide (cstring s, int len)
cstring cstring_fill (cstring s, int n)
cstring cstring_downcase (cstring s)
cstring cstring_appendChar ( cstring s1, char c)
cstring cstring_concatFree (cstring s, cstring t)
cstring cstring_concatFree1 (cstring s, cstring t)
cstring cstring_concatChars (cstring s, char *t)
cstring cstring_concatLength (cstring s1, char *s2, int len)
cstring cstring_concat (cstring s, cstring t)
cstring cstring_prependCharO (char c, cstring s1)
cstring cstring_prependChar (char c, cstring s1)
bool cstring_hasNonAlphaNumBar (cstring s)
cstring cstring_create (int n)
lsymbol cstring_toSymbol (cstring s)
cstring cstring_bsearch (cstring key, char **table, int nentries)
cstring cstring_advanceWhiteSpace (cstring s)


Function Documentation

cstring cstring_advanceWhiteSpace ( cstring s )
 

Definition at line 934 of file cstring.c.

00935 {
00936   if (cstring_isDefined (s)) {
00937     char *t = s;
00938 
00939     while (*t != '\0' && isspace ((int) *t)) {
00940       t++;
00941     }
00942 
00943     return t;
00944   }
00945   
00946   return cstring_undefined;
00947 }

cstring cstring_appendChar ( cstring s1,
char c )
 

Definition at line 738 of file cstring.c.

Referenced by context_setString(), describeModes(), globSet_dump(), lhType(), multiVal_undump(), programNode_unparse(), sRefSet_dump(), sRef_undump(), sRef_unparseOpt(), termNode_unparse(), typeExpr_unparse(), and typeExpr_unparseNoBase().

00739 {
00740   int l = cstring_length (s1);
00741   char *s;
00742 
00743   s = (char *) dmalloc (sizeof (*s) * (l + 2));
00744 
00745   if (cstring_isDefined (s1))
00746     {  
00747       strcpy (s, s1);
00748       *(s + l) = c;
00749       *(s + l + 1) = '\0';
00750       sfree (s1); 
00751     }
00752   else
00753     {
00754       *(s) = c;
00755       *(s + 1) = '\0';
00756     } 
00757 
00758   return s;
00759 }

cstring cstring_beforeChar ( cstring s,
char c )
 

Definition at line 111 of file cstring.c.

00112 {
00113   if (cstring_isDefined (s))
00114     {
00115       char *cp = strchr (s, c);
00116 
00117       if (cp != NULL)
00118         {
00119           cstring ret;
00120 
00121           /*@-mods@*/
00122           *cp = '\0';
00123           ret = cstring_copy (s);
00124           *cp = c;
00125           /*@=mods@*/ /* modification is undone */
00126           
00127           return ret;
00128         }
00129     }
00130 
00131   return cstring_undefined;
00132 }

cstring cstring_bsearch ( cstring key,
char ** table,
int nentries )
 

Definition at line 885 of file cstring.c.

00886 {
00887   if (cstring_isDefined (key))
00888     {
00889       int low = 0;
00890       int high = nentries;
00891       int mid = (high + low + 1) / 2;
00892       int last = -1;
00893       cstring res = cstring_undefined;
00894 
00895       while (low <= high && mid < nentries)
00896         {
00897           int cmp;
00898 
00899           llassert (mid != last);
00900           llassert (mid >= 0 && mid < nentries);
00901 
00902           cmp = cstring_compare (key, table[mid]);
00903           
00904           if (cmp == 0)
00905             {
00906               res = table[mid];
00907               break;
00908             }
00909           else if (cmp < 0) /* key is before table[mid] */
00910             {
00911               high = mid - 1;
00912             }
00913           else /* key of after table[mid] */
00914             {
00915               low = mid + 1;
00916             }
00917 
00918           last = mid;
00919           mid = (high + low + 1) / 2;
00920         }
00921 
00922       if (mid != 0 && mid < nentries - 1)
00923         {
00924           llassert (cstring_compare (key, table[mid - 1]) > 0);
00925           llassert (cstring_compare (key, table[mid + 1]) < 0);
00926         }
00927 
00928       return res;
00929     }
00930   
00931   return cstring_undefined;
00932 }

cstring cstring_capitalize ( cstring s )
 

Definition at line 616 of file cstring.c.

00617 {
00618   if (!cstring_isEmpty (s))
00619     {
00620       cstring ret = cstring_copy (s);
00621 
00622       cstring_setChar (ret, 1, (char) toupper ((int) cstring_firstChar (ret)));
00623       return ret;
00624     }
00625   
00626   return cstring_undefined;
00627 }

cstring cstring_capitalizeFree ( cstring s )
 

Definition at line 630 of file cstring.c.

00631 {
00632   if (!cstring_isEmpty (s))
00633     {
00634       cstring_setChar (s, 1, (char) toupper ((int) cstring_firstChar (s)));
00635       return s;
00636     }
00637   
00638   return s;
00639 }

cstring cstring_clip ( cstring s,
int len )
 

Definition at line 642 of file cstring.c.

00643 {
00644   if (cstring_isUndefined (s) || cstring_length (s) <= len)
00645     {
00646       ;
00647     }
00648   else
00649     {
00650       llassert (s != NULL);
00651       *(s + len) = '\0';
00652     }
00653 
00654   return s;
00655 }

int cstring_compare ( cstring c1,
cstring c2 )
 

Definition at line 531 of file cstring.c.

Referenced by cstring_bsearch(), cstring_xcompare(), multiVal_compare(), sRef_compare(), uentryList_compareFields(), and uentry_xcomparealpha().

00532 {
00533   int res;
00534 
00535   if (c1 == c2)
00536     {
00537       res = 0;
00538     }
00539   else if (cstring_isUndefined (c1))
00540     {
00541       if (cstring_isEmpty (c2))
00542         {
00543           res = 0;
00544         }
00545       else
00546         {
00547           res = 1;
00548         }
00549     }
00550   else if (cstring_isUndefined (c2))
00551     {
00552       if (cstring_isEmpty (c1))
00553         {
00554           res = 0;
00555         }
00556       else
00557         {
00558           res = -1;
00559         }
00560     }
00561   else
00562     {
00563       res = strcmp (c1, c2);
00564     }
00565 
00566     return (res);
00567 }

cstring cstring_concat ( cstring s,
cstring t )
 

Definition at line 800 of file cstring.c.

Referenced by cstring_concatChars(), cstring_concatFree(), cstring_concatFree1(), cstring_concatLength(), osd_fixDefine(), and stmtNode_unparse().

00801 {
00802   char *ret = mstring_create (cstring_length (s) + cstring_length (t));
00803 
00804   if (cstring_isDefined (s))
00805     {
00806       strcpy (ret, s);
00807     }
00808   if (cstring_isDefined (t))
00809     {
00810       strcat (ret, t);
00811     }
00812 
00813   return ret;
00814 }

cstring cstring_concatChars ( cstring s,
char * t )
 

Definition at line 780 of file cstring.c.

Referenced by fileTable_addCTempFile().

00781 {
00782   cstring res = cstring_concat (s, cstring_fromChars (t));
00783   cstring_free (s);
00784   return res;
00785 }

cstring cstring_concatFree ( cstring s,
cstring t )
 

Definition at line 762 of file cstring.c.

Referenced by globSet_dump(), lclTypeSpecNode_unparseComments(), sRefSet_dump(), and sortSet_unparseOr().

00763 {
00764   cstring res = cstring_concat (s, t);
00765   cstring_free (s);
00766   cstring_free (t);
00767   return res;
00768 }

cstring cstring_concatFree1 ( cstring s,
cstring t )
 

Definition at line 771 of file cstring.c.

00772 {
00773   cstring res = cstring_concat (s, t);
00774   cstring_free (s);
00775   return res;
00776 }

cstring cstring_concatLength ( cstring s1,
char * s2,
int len )
 

Definition at line 789 of file cstring.c.

00790 {
00791   cstring tmp = cstring_copyLength (s2, len);
00792   cstring res = cstring_concat (s1, tmp);
00793   cstring_free (tmp);
00794   cstring_free (s1);
00795 
00796   return res;
00797 }

bool cstring_contains ( cstring c,
cstring sub )
 

Definition at line 280 of file cstring.c.

00281 {
00282   if (cstring_isDefined (c))
00283     {
00284       llassert (cstring_isDefined (sub));
00285       
00286       return (strstr (c, sub) != NULL);
00287     }
00288   else
00289     {
00290       return FALSE;
00291     }
00292 }

bool cstring_containsChar ( cstring c,
char ch )
 

Definition at line 175 of file cstring.c.

00176 {
00177   if (cstring_isDefined (c))
00178     {
00179       return (strchr (c, ch) != NULL);
00180     }
00181   else
00182     {
00183       return FALSE;
00184     }
00185 }

cstring cstring_copy ( cstring s )
 

Definition at line 154 of file cstring.c.

Referenced by checkLclPredicate(), context_setMode(), context_setString(), cppAddIncludeDir(), cstringList_unparseAbbrev(), cstringList_unparseSep(), cstringSList_unparseAbbrev(), cstringSList_unparseSep(), cstring_beforeChar(), cstring_capitalize(), cstring_elide(), cstring_prefix(), ctypeList_unparse(), describeFlag(), enumNameList_dump(), enumNameList_unparse(), enumNameList_unparseBrief(), exprNodeList_unparse(), exprNodeSList_unparse(), exprNode_arrowAccess(), exprNode_fieldAccess(), exprNode_functionCall(), fileloc_unparse(), fileloc_unparseFilename(), importNodeList_unparse(), loadState(), ltokenList_unparse(), multiVal_copy(), nameNode_unparse(), opFormNode_unparse(), sRefSet_unparseUnconstrained(), sRefSet_unparseUnconstrainedPlain(), sigNodeSet_unparseSomeSigs(), sortList_unparse(), termNode_unparse(), typeExpr_name(), uentry_getName(), uentry_makeConstantAux(), uentry_makeDatatypeAux(), and uentry_unparse().

00155 {
00156   if (cstring_isDefined (s))
00157     {
00158       return (mstring_copy (s));
00159     }
00160   else
00161     {
00162       return cstring_undefined;
00163     }
00164 }

cstring cstring_copyLength ( char * s,
int len )
 

Definition at line 166 of file cstring.c.

Referenced by REST_EXTENSION_LENGTH(), and cstring_concatLength().

00167 {
00168   char *res = mstring_create (len + 1);
00169 
00170   strncpy (res, s, size_fromInt (len));
00171   res[len] = '\0';
00172   return res;
00173 }

cstring cstring_create ( int n )
 

Definition at line 867 of file cstring.c.

Referenced by cstring_downcase(), cstring_elide(), and cstring_fill().

00868 {
00869   char *s = dmalloc (sizeof (*s) * (n + 1));
00870 
00871   *s = '\0';
00872   return s;
00873 }

cstring cstring_downcase ( cstring s )
 

Definition at line 710 of file cstring.c.

00711 {
00712   if (cstring_isDefined (s))
00713     {
00714       cstring t = cstring_create (strlen (s) + 1);
00715       cstring ot = t;
00716       char c;
00717       
00718       while ((c = *s) != '\0')
00719         {
00720           if (c >= 'A' && c <= 'Z')
00721             {
00722               c = c - 'A' + 'a';
00723             }
00724           *t++ = c;
00725           s++;
00726         }
00727       *t = '\0';
00728       
00729       return ot;
00730     }
00731   else
00732     {
00733       return cstring_undefined;
00734     }
00735 }

cstring cstring_elide ( cstring s,
int len )
 

Definition at line 658 of file cstring.c.

Referenced by exprNode_unparseFirst().

00659 {
00660   if (cstring_isUndefined (s) || cstring_length (s) <= len)
00661     {
00662       return cstring_copy (s);
00663     }
00664   else
00665     {
00666       cstring sc = cstring_create (len);
00667      
00668       strncpy (sc, s, size_fromInt (len));
00669       *(sc + len - 1) = '\0';
00670       *(sc + len - 2) = '.';      
00671       *(sc + len - 3) = '.';      
00672       *(sc + len - 4) = '.';      
00673       return sc;
00674     }
00675 }

bool cstring_equal ( cstring c1,
cstring c2 )
 

Definition at line 397 of file cstring.c.

Referenced by cstring_equalFree(), ctype_dump(), ctype_sameName(), describeFlag(), enumNameList_match(), enumNameList_member(), exprNode_checkMacroBody(), exprNode_iter(), fileloc_almostSameFile(), fileloc_sameModule(), hashTable_remove(), hashTable_replaceKey(), identifyFlag(), macrocache_processFileElements(), processNamedDecl(), sRef_compare(), sRef_includedBy(), sRef_isRecursiveField(), sRef_realSame(), sRef_same(), sRef_sameName(), sRef_similar(), uentryList_lookupRealName(), uentryList_matchFields(), uentryList_showFieldDifference(), usymtab_allUsed(), and usymtab_isBoolType().

00398 {
00399   if (c1 == c2) return TRUE;
00400   else if (cstring_isUndefined (c1)) return cstring_isEmpty (c2);
00401   else if (cstring_isUndefined (c2)) return cstring_isEmpty (c1);
00402   else return (strcmp (c1, c2) == 0);
00403 }

bool cstring_equalCanonicalPrefix ( cstring c1,
char * c2 )
 

Definition at line 443 of file cstring.c.

Referenced by context_isSystemDir().

00444 {
00445   llassert (c2 != NULL);
00446 
00447   if (cstring_isUndefined (c1)) 
00448     {
00449       return (strlen (c2) == 0);
00450     }
00451 
00452 # if defined (WIN32) || defined (OS2)
00453   /*
00454   ** If one has a drive specification, but the other doesn't, skip it.
00455   */
00456   
00457   if (strchr (c1, ':') == NULL
00458       && strchr (c2, ':') != NULL)
00459     {
00460       c2 = strchr (c2 + 1, ':');
00461     }
00462   else 
00463     {
00464       if (strchr (c2, ':') == NULL
00465           && strchr (c1, ':') != NULL)
00466         {
00467           c1 = strchr (c1 + 1, ':');
00468         }
00469     }
00470 
00471   {
00472     int len = size_toInt (strlen (c2));
00473     int i = 0;
00474     int slen = 0;
00475 
00476     if (cstring_length (c1) < len)
00477       {
00478         return FALSE;
00479       }
00480 
00481     for (i = 0; i < len; i++)
00482       {
00483         if (c1[slen] == c2[i]
00484             || (osd_isConnectChar (c1[slen]) && osd_isConnectChar (c2[i])))
00485           {
00486             ;
00487           }
00488         else 
00489           {
00490             /*
00491             ** We allow \\ to match \ because MS-DOS screws up the directory
00492             ** names.
00493             */
00494             
00495             if (c1[slen] == '\\'
00496                 && (slen > 0
00497                     && c1[slen - 1] == '\\'
00498                     && c2[i - 1] == '\\'))
00499               {
00500                 slen++;
00501                 if (c1[slen] != c2[i])
00502                   {
00503                     return FALSE;
00504                   }
00505               }
00506             else
00507               {
00508                 return FALSE;
00509               }
00510           }
00511 
00512         slen++;
00513         if (slen >= cstring_length (c1))
00514           {
00515             return FALSE;
00516           }
00517       }
00518   }
00519 
00520   return TRUE;
00521 # else
00522   return (strncmp (c1, c2, strlen (c2)) == 0);
00523 # endif
00524 }

bool cstring_equalCaseInsensitive ( cstring c1,
cstring c2 )
 

Definition at line 413 of file cstring.c.

00414 {
00415   if (c1 == c2) return TRUE;
00416   else if (cstring_isUndefined (c1)) return cstring_isEmpty (c2);
00417   else if (cstring_isUndefined (c2)) return cstring_isEmpty (c1);
00418   else return (cstring_genericEqual (c1, c2, 0, TRUE, FALSE) != CGE_DISTINCT);
00419 }

bool cstring_equalFree ( cstring c1,
cstring c2 )
 

Definition at line 389 of file cstring.c.

Referenced by sRef_sameName(), and usymtab_allUsed().

00390 {
00391   bool res = cstring_equal (c1, c2);
00392   cstring_free (c1);
00393   cstring_free (c2);
00394   return res;
00395 }

bool cstring_equalLen ( cstring c1,
cstring c2,
int len )
 

Definition at line 405 of file cstring.c.

Referenced by cppReader_lookup().

00406 {
00407   if (c1 == c2) return TRUE;
00408   else if (cstring_isUndefined (c1)) return cstring_isEmpty (c2);
00409   else if (cstring_isUndefined (c2)) return cstring_isEmpty (c1);
00410   else return (strncmp (c1, c2, size_fromInt (len)) == 0);
00411 }

bool cstring_equalLenCaseInsensitive ( cstring c1,
cstring c2,
int len )
 

Definition at line 421 of file cstring.c.

00422 {
00423   llassert (len >= 0);
00424 
00425   if (c1 == c2) return TRUE;
00426   else if (cstring_isUndefined (c1)) return cstring_isEmpty (c2);
00427   else if (cstring_isUndefined (c2)) return cstring_isEmpty (c1);
00428   else return (cstring_genericEqual (c1, c2, len, TRUE, FALSE) != CGE_DISTINCT);
00429 }

bool cstring_equalPrefix ( cstring c1,
char * c2 )
 

Definition at line 431 of file cstring.c.

Referenced by checkAnsiName(), checkParamNames(), exprNode_iter(), and fileloc_createLib().

00432 {
00433   llassert (c2 != NULL);
00434 
00435   if (cstring_isUndefined (c1)) 
00436     {
00437       return (strlen (c2) == 0);
00438     }
00439 
00440   return (strncmp (c1, c2, strlen (c2)) == 0);
00441 }

cstring cstring_fill ( cstring s,
int n )
 

Definition at line 678 of file cstring.c.

Referenced by cstringList_printSpaced(), cstringSList_printSpaced(), and summarizeErrors().

00679 {
00680   cstring t = cstring_create (n + 1);
00681   cstring ot = t;
00682   int len = cstring_length (s);
00683   int i;
00684   
00685   if (len > n)
00686     {
00687       for (i = 0; i < n; i++)
00688         {
00689           *t++ = *s++;
00690         }
00691       *t = '\0';
00692     }
00693   else
00694     {
00695       for (i = 0; i < len; i++)
00696         {
00697           *t++ = *s++;
00698         }
00699       for (i = 0; i < n - len; i++)
00700         {
00701           *t++ = ' ';
00702         }
00703       *t = '\0';
00704     }
00705 
00706   return ot;
00707 }

char cstring_firstChar ( cstring s )
 

Definition at line 45 of file cstring.c.

Referenced by checkAnsiName(), checkLclPredicate(), context_setString(), cstring_capitalize(), cstring_capitalizeFree(), fixParamName(), fixTagName(), identifyFlag(), isFakeTag(), main(), makeParam(), and makeStruct().

00046 {
00047   llassert (cstring_isDefined (s));
00048   llassert (cstring_length (s) > 0);
00049 
00050   return (s[0]);
00051 }

void cstring_free ( cstring s )
 

Definition at line 574 of file cstring.c.

Referenced by checkParamNames(), checkPrefix(), context_clearMessageAnnote(), context_destroyMod(), context_dumpModuleAccess(), context_setMode(), context_setString(), context_userSetFlag(), cppCleanup(), cstringList_printSpaced(), cstringSList_printSpaced(), cstring_concatChars(), cstring_concatFree(), cstring_concatFree1(), cstring_concatLength(), cstring_equalFree(), cstring_prependCharO(), cstring_toSymbol(), ctype_createForwardStruct(), ctype_createForwardUnion(), ctype_createUnnamedStruct(), ctype_createUnnamedUnion(), ctype_dump(), describeFlag(), doVaDcl(), enumNameList_free(), exprChecks_checkUsedGlobs(), exprNode_checkAllMods(), exprNode_checkMacroBody(), exprNode_free(), exprNode_freeShallow(), exprNode_iter(), exprNode_iterId(), exprNode_iterNewId(), filelocList_unparseUses(), fixModifiesId(), fixSpecClausesId(), genppllerror(), genppllerrorhint(), handleEnum(), handleStruct(), handleUnion(), idDecl_free(), importNode_makeQuoted(), lclTypeSpecNode_unparseComments(), lhOutLine(), llbugaux(), llgenhinterror(), llgloberror(), llhint(), llquietbugaux(), loadState(), main(), modListArrowAccess(), modListFieldAccess(), multiVal_free(), optgenerror2(), optgenerror2n(), printCodePoint(), processNamedDecl(), sRef_isMacroParamRef(), sigNodeSet_unparseSomeSigs(), summarizeErrors(), typeIdSet_dumpTable(), uentryList_lookupRealName(), uentry_checkYieldParam(), uentry_makeEnumTag(), uentry_makeEnumTagLoc(), uentry_makeStructTag(), uentry_makeStructTagLoc(), uentry_makeUnionTag(), uentry_makeUnionTagLoc(), uentry_setName(), uentry_setParam(), uentry_showWhereLastExtra(), uentry_unparse(), usymtab_dump(), usymtab_existsEnumTag(), usymtab_existsStructTag(), usymtab_existsUnionTag(), usymtab_lookupEnumTag(), usymtab_lookupStructTag(), usymtab_lookupUnionTag(), and usymtab_printOut().

00575 {
00576   if (cstring_isDefined (s)) 
00577     {
00578       sfree (s);
00579     }
00580 }

cstring cstring_fromChars ( const char * cp )
 

Definition at line 582 of file cstring.c.

Referenced by BUFLEN(), FILE_NAME_MAP_FILE(), FNAME_HASHSIZE(), LSLUpdateToken(), cppReader_initializeReader(), cppReader_install(), dicalloc(), dimalloc(), direalloc(), docheckChar(), fileTable_addltemp(), flagcodeHint(), flagcode_name(), importCTrait(), listAllCategories(), lldecodeerror(), lsymbol_toString(), main(), message(), o_fctInfo(), osd_fixDefine(), osd_unlink(), printAllFlags(), printCategory(), processImport(), sort_import(), sort_unparseName(), and symtable_import().

00583 {
00584   return (cstring) cp;
00585 }

cmpcode cstring_genericEqual ( cstring s,
cstring t,
int nchars,
bool caseinsensitive,
bool lookalike )
 

Definition at line 318 of file cstring.c.

Referenced by cstring_equalCaseInsensitive(), and cstring_equalLenCaseInsensitive().

00322 {
00323   if (s == t) return CGE_SAME;
00324   else if (cstring_isUndefined (s))
00325     {
00326       return cstring_isEmpty (t) ? CGE_SAME : CGE_DISTINCT;
00327     }
00328   else if (cstring_isUndefined (t))
00329     {
00330       return cstring_isEmpty (s) ? CGE_SAME : CGE_DISTINCT;
00331     }
00332   else
00333     {
00334       int i = 0;
00335       bool diffcase = FALSE;
00336       bool difflookalike = FALSE;
00337 
00338       while (*s != '\0')
00339         {
00340           if (nchars > 0 && i >= nchars)
00341             {
00342               break;
00343             }
00344 
00345           if (*t == *s)
00346             {
00347               ; /* no difference */
00348             }
00349           else if (caseinsensitive 
00350                    && (toupper ((int) *t) == toupper ((int) *s)))
00351             {
00352               diffcase = TRUE;
00353             }
00354           else if (lookalike && (lookLike (*t) == lookLike (*s)))
00355             {
00356               difflookalike = TRUE;
00357             }
00358           else 
00359             {
00360               return CGE_DISTINCT;
00361             }
00362           i++;
00363           s++;
00364           t++;
00365         }
00366 
00367       if (*s == '\0' && *t != '\0')
00368         {
00369           return CGE_DISTINCT;
00370         }
00371 
00372       if (diffcase)
00373         {
00374           return CGE_CASE;
00375         }
00376       else if (difflookalike)
00377         {
00378           return CGE_LOOKALIKE;
00379         }
00380       else
00381         {
00382           return CGE_SAME;
00383         }
00384     }
00385 }

char cstring_getChar ( cstring s,
int n )
 

Definition at line 53 of file cstring.c.

Referenced by checkAnsiName(), context_setString(), and isFakeTag().

00054 {
00055   int length = cstring_length (s);
00056 
00057   llassert (cstring_isDefined (s));
00058   llassert (n >= 1 && n <= length);
00059 
00060   return (s[n - 1]);
00061 }

bool cstring_hasNonAlphaNumBar ( cstring s )
 

Definition at line 846 of file cstring.c.

Referenced by fileTable_addltemp().

00847 {
00848   int c;
00849 
00850   if (cstring_isUndefined (s)) return FALSE;
00851 
00852   while ((c = (int) *s) != (int) '\0')
00853     {
00854       if ((isalnum (c) == 0) && (c != (int) '_')
00855           && (c != (int) '.') && (c != (int) CONNECTCHAR))
00856         {
00857           return TRUE;
00858         }
00859 
00860       s++;
00861     }
00862   return FALSE;
00863 }

char cstring_lastChar ( cstring s )
 

Definition at line 142 of file cstring.c.

Referenced by checkAnsiName(), context_setString(), and setStringFlag().

00143 {
00144   int length;
00145 
00146   llassert (cstring_isDefined (s));
00147 
00148   length = cstring_length (s);
00149   llassert (length > 0);
00150 
00151   return (s[length - 1]);
00152 }

int cstring_length ( cstring s )
 

Definition at line 606 of file cstring.c.

Referenced by checkAnsiName(), context_setString(), cppReader_addIncludeChain(), cppReader_initializeReader(), cstringList_printSpaced(), cstringSList_printSpaced(), cstring_appendChar(), cstring_clip(), cstring_concat(), cstring_elide(), cstring_equalCanonicalPrefix(), cstring_fill(), cstring_getChar(), cstring_lastChar(), cstring_prependChar(), cstring_stripChars(), exprNode_stringLiteral(), filelocList_unparseUses(), fixParamName(), identifyFlag(), isFakeTag(), lclerror(), lhOutLine(), llgenmsg(), main(), makeParam(), setValueFlag(), and usymtab_dump().

00607 {
00608   if (cstring_isDefined (s))
00609     {
00610       return size_toInt (strlen (s));
00611     }
00612   return 0;
00613 }

void cstring_markOwned ( cstring s )
 

Definition at line 569 of file cstring.c.

Referenced by ctype_unparseSafe(), exprNode_arrowAccess(), exprNode_fieldAccess(), exprNode_functionCall(), exprNode_unparseFirst(), modListArrowAccess(), modListFieldAccess(), and sRef_undump().

00570 {
00571   sfreeEventually (s);
00572 }

cstring cstring_prefix ( cstring s,
int n )
 

Definition at line 71 of file cstring.c.

Referenced by context_setString().

00072 {
00073   cstring t;
00074   char c;
00075   llassert (cstring_isDefined (s));
00076   llassert (n <= cstring_length (s));
00077 
00078   c = *(s + n);
00079   /*@-mods@*/  /* The modifications cancel out. */
00080   *(s + n) = '\0';
00081   t = cstring_copy (s);
00082   *(s + n) = c;
00083   /*@=mods@*/
00084 
00085   return t;
00086 }

cstring cstring_prependChar ( char c,
cstring s1 )
 

Definition at line 826 of file cstring.c.

Referenced by cstring_prependCharO(), makeEnum(), makeParam(), makeStruct(), and makeUnion().

00827 {
00828   int l = cstring_length (s1);
00829   char *s = (char *) dmalloc (sizeof (*s) * (l + 2));
00830   
00831   *(s) = c;
00832 
00833   if (cstring_isDefined (s1)) 
00834     {
00835       /*@-mayaliasunique@*/ 
00836       strcpy (s + 1, s1);
00837       /*@=mayaliasunique@*/ 
00838     }
00839 
00840   *(s + l + 1) = '\0';
00841   return s;
00842 }

cstring cstring_prependCharO ( char c,
cstring s1 )
 

Definition at line 817 of file cstring.c.

Referenced by sRef_unparsePreOpt().

00818 {
00819   cstring res = cstring_prependChar (c, s1);
00820 
00821   cstring_free (s1);
00822   return (res);
00823 }

void cstring_replaceLit ( cstring s,
char * old,
char * snew )
 

Definition at line 211 of file cstring.c.

00212 {
00213   
00214   llassert (strlen (old) >= strlen (snew));
00215 
00216   if (cstring_isDefined (s))
00217     {
00218       char *sp = strstr (s, old);
00219 
00220       while (sp != NULL)
00221         {
00222           int lendiff = size_toInt (strlen (old) - strlen (snew));
00223           char *tsnew = snew;
00224           
00225           while (*tsnew != '\0')
00226             {
00227               *sp++ = *tsnew++;
00228             }
00229 
00230           if (lendiff > 0)
00231             {
00232               while (*(sp + lendiff) != '\0')
00233                 {
00234                   *sp = *(sp + lendiff);
00235                   sp++;
00236                 }
00237 
00238               *sp = '\0';
00239             }
00240 
00241           sp = strstr (s, old);
00242         }
00243           }
00244 }

void cstring_setChar ( cstring s,
int n,
char c )
 

Definition at line 134 of file cstring.c.

Referenced by checkLclPredicate(), cstring_capitalize(), and cstring_capitalizeFree().

00135 {
00136   llassert (cstring_isDefined (s));
00137   llassert (n > 0 && n <= cstring_length (s));
00138 
00139   s[n - 1] = c;
00140 }

void cstring_stripChars ( cstring s,
const char * clist )
 

Definition at line 250 of file cstring.c.

00251 {
00252   if (cstring_isDefined (s))
00253     {
00254       int i;
00255       int size = cstring_length (s);
00256 
00257       for (i = 0; i < size; i++)
00258         {
00259           char c = s[i];
00260           
00261           if (strchr (clist, c) != NULL)
00262             {
00263               /* strip this char */
00264               int j;
00265               
00266               size--;
00267 
00268               for (j = i; j < size; j++)
00269                 {
00270                   s[j] = s[j+1];
00271                 }
00272 
00273               s[size] = '\0'; 
00274               i--;
00275             }
00276         }
00277     }
00278 }

cstring cstring_suffix ( cstring s,
int n )
 

Definition at line 63 of file cstring.c.

Referenced by fixParamName(), and main().

00064 {
00065   llassert (cstring_isDefined (s));
00066   llassert (n <= cstring_length (s));
00067 
00068   return (s + n);
00069 }

char * cstring_toCharsSafe ( cstring s )
 

Definition at line 587 of file cstring.c.

Referenced by callLSL(), context_dumpModuleAccess(), context_isSystemDir(), cppDoUndefine(), dumpState(), exprNode_stringLiteral(), fileTable_addltemp(), fileTable_printTemps(), lcllib_isSkipHeader(), llbugaux(), lldecodeerror(), loadState(), main(), message(), parseSignatures(), readlsignatures(), and usymtab_dump().

00588 {
00589   static /*@only@*/ cstring emptystring = cstring_undefined;
00590 
00591   if (cstring_isDefined (s))
00592     {
00593       return (char *) s;
00594     }
00595   else
00596     {
00597       if (cstring_isUndefined (emptystring))
00598         {
00599           emptystring = cstring_newEmpty ();
00600         }
00601 
00602       return emptystring;
00603     }
00604 }

int cstring_toPosInt ( cstring s )
 

Definition at line 92 of file cstring.c.

Referenced by setValueFlag().

00093 {
00094   int val = 0;
00095 
00096   cstring_chars (s, c)
00097     {
00098       if (isdigit ((unsigned char) c))
00099         {
00100           val = (val * 10) + (int)(c - '0');
00101         }
00102       else
00103         {
00104           return -1;
00105         }
00106     } end_cstring_chars ; 
00107 
00108   return val;
00109 }

lsymbol cstring_toSymbol ( cstring s )
 

Definition at line 876 of file cstring.c.

Referenced by sort_makeHOFSort().

00877 {
00878   lsymbol res = lsymbol_fromChars (cstring_toCharsSafe (s));
00879 
00880   cstring_free (s);
00881   return res;
00882 }

int cstring_xcompare ( cstring * c1,
cstring * c2 )
 

Definition at line 526 of file cstring.c.

00527 {
00528   return (cstring_compare (*c1, *c2));
00529 }


Generated at Fri Nov 3 18:57:54 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000