#include "lclintMacros.nf"#include "basic.h"#include "portab.h"#include <stdlib.h>Go to the source code of this file.
Functions | |
| void | sfree (void *x) |
| void | sfreeEventually (void *x) |
| void* | dimalloc (size_t size, char *name, int line) |
| void* | dicalloc (size_t num, size_t size, char *name, int line) |
| void* | direalloc ( void *x, size_t size, char *name, int line) |
| char* | FormatInt (int i) |
| bool | isCext (char *ext) |
| bool | isLCLfile (cstring s) |
| char* | removeExtension ( char *s, const char *suffix) |
| bool | firstWord (char *s, char *w) |
| char* | removePath (char *s) |
| char* | removePathFree ( char *s) |
| void | mstring_markFree (char *s) |
| char* | removeAnyExtension (char *s) |
| char* | addExtension (char *s, const char *suffix) |
| int | getInt (char **s) |
| char | loadChar (char **s) |
| double | getDouble (char **s) |
| char* | getWord (char **s) |
| bool | optCheckChar (char **s, char c) |
| void | docheckChar (char **s, char c, char *file, int line) |
| char* | mstring_spaces (int n) |
| char* | mstring_concat (const char *s1, const char *s2) |
| char* | mstring_concatFree ( char *s1, char *s2) |
| char* | mstring_concatFree1 ( char *s1, const char *s2) |
| char* | mstring_append ( char *s1, char c) |
| char* | mstring_copy (char *s1) |
| char* | mstring_safePrint (char *s) |
| char* | mstring_create (int n) |
| void | fputline (FILE *out, char *s) |
| int | int_log (int x) |
| long unsigned int | longUnsigned_fromInt (int x) |
| size_t | size_fromInt (int x) |
| int | size_toInt (size_t x) |
| long | size_toLong (size_t x) |
| char | char_fromInt (int x) |
| int | longUnsigned_toInt (long unsigned int x) |
| int | long_toInt (long int x) |
| bool | mstring_equalPrefix (const char *c1, const char *c2) |
| bool | mstring_equal ( const char *s1, const char *s2) |
| char* | filenameExtension ( char *s) |
| char* | removePreDirs (char *s) |
| void | checkUngetc (int c, FILE *f) |
| bool | isHeaderFile (cstring fname) |
|
|
Definition at line 173 of file general.c. 00174 {
00175 char temp[255]; /* assume the integer has at most 254 digits */
00176 char *outs;
00177
00178 sprintf (temp, "%i", i);
00179 outs = (char *) dmalloc (sizeof (*outs) * (1 + strlen (temp)));
00180 strcpy (outs, temp);
00181
00182 return (outs);
00183 }
|
|
|
Definition at line 304 of file general.c. Referenced by dumpState(), loadStandardState(), and loadState(). 00305 {
00306 if (strrchr (s, '.') == (char *) 0)
00307 {
00308 /* <<< was mstring_concatFree1 --- bug detected by lclint >>> */
00309 return (mstring_concat (s, suffix));
00310 }
00311 else
00312 {
00313 return mstring_copy (s);
00314 }
00315 }
|
|
|
Definition at line 632 of file general.c. 00633 {
00634 llassert ((x >= (int)'\0') && (x <= (int)'~'));
00635
00636 return ((char) x);
00637 }
|
|
|
Definition at line 719 of file general.c. Referenced by swallowMacro(). 00720 {
00721 int res;
00722
00723 llassert (c != EOF);
00724 res = ungetc (c, f);
00725 llassert (res == c);
00726 }
|
|
|
Definition at line 130 of file general.c. 00131 {
00132 void *ret = (void *) calloc (num, size);
00133
00134 if (ret == NULL)
00135 {
00136 llfatalerrorLoc
00137 (message ("Out of memory. Allocating %w bytes at %s:%d.",
00138 size_toLongUnsigned (size),
00139 cstring_fromChars (name), line));
00140 }
00141
00142 return ret;
00143 }
|
|
|
Definition at line 86 of file general.c. 00087 {
00088 /*
00089 static void *lastaddr = 0;
00090 static int numallocs = 0;
00091 static int numbad = 0;
00092 */
00093
00094 /* was malloc, use calloc to initialize to zero */
00095 void *ret = (void *) calloc (1, size);
00096
00097 /*
00098 numallocs++;
00099
00100 if (ret < lastaddr)
00101 {
00102 numbad++;
00103 fprintf (stderr, "Bad alloc: %d / %d\n", numbad, numallocs);
00104 }
00105
00106 lastaddr = ret;
00107 */
00108
00109 if (ret == NULL)
00110 {
00111 if (size == 0)
00112 {
00113 llbug (message ("Zero allocation at %q.",
00114 fileloc_unparseRaw (cstring_fromChars (name), line)));
00115 }
00116 else
00117 {
00118 llfatalerrorLoc
00119 (message ("Out of memory. Allocating %w bytes at %s:%d.",
00120 size_toLongUnsigned (size),
00121 cstring_fromChars (name), line));
00122 }
00123 }
00124
00125 /*@-null@*/ /* null okay for size = 0 */
00126 return ret;
00127 /*@=null@*/
00128 }
|
|
|
Definition at line 145 of file general.c. 00147 {
00148 void *ret;
00149
00150 if (x == NULL)
00151 {
00152 ret = (void *) dmalloc (size);
00153 }
00154 else
00155 {
00156 ret = (void *) realloc (x, size);
00157 }
00158
00159 if (ret == NULL)
00160 {
00161 llfatalerrorLoc
00162 (message ("Out of memory. Allocating %w bytes at %s:%d.",
00163 size_toLongUnsigned (size),
00164 cstring_fromChars (name), line));
00165 }
00166
00167 return ret;
00168 }
|
|
|
Definition at line 439 of file general.c. 00440 {
00441 /*@unchecked@*/ static int nbadchars = 0;
00442
00443 if (**s == c)
00444 {
00445 (*s)++;
00446 }
00447 else
00448 {
00449 nbadchars++;
00450
00451 if (nbadchars > 5)
00452 {
00453 llfatalbug (cstring_makeLiteral
00454 ("checkChar: Too many errors. Check library is up to date."));
00455 }
00456 else
00457 {
00458 llbug (message ("checkChar: %q: Bad char, expecting %h: %s",
00459 fileloc_unparseRaw (cstring_fromChars (file), line),
00460 c,
00461 cstring_fromChars (*s)));
00462 }
00463 }
00464 }
|
|
|
Definition at line 694 of file general.c. Referenced by context_isSpecialFile(), isHeaderFile(), and isLCLfile(). 00695 {
00696 llassert (s != NULL);
00697
00698 return (strrchr(s, '.'));
00699 }
|
|
|
Definition at line 228 of file general.c. Referenced by o_fctInfo(), processImport(), sort_import(), and symtable_import(). 00229 {
00230 llassert (s != NULL);
00231 llassert (w != NULL);
00232
00233 for (; *w != '\0'; w++, s++)
00234 {
00235 if (*w != *s || *s == '\0')
00236 return FALSE;
00237 }
00238 return TRUE;
00239 }
|
|
|
Definition at line 573 of file general.c. 00574 {
00575 if (strlen (s) > 0)
00576 {
00577 check (fputs (s, out) != EOF);
00578 }
00579
00580 check (fputc ('\n', out) == (int) '\n');
00581 }
|
|
|
Definition at line 385 of file general.c. 00386 {
00387 char *end = mstring_createEmpty ();
00388 double ret;
00389
00390 ret = strtod (*s, &end);
00391
00392 *s = end;
00393 return ret;
00394 }
|
|
|
Definition at line 318 of file general.c. Referenced by GETPRINTF(), ctype_undump(), multiVal_undump(), sRef_undump(), sRef_undumpGlobal(), typeIdSet_undump(), and uentry_undump(). 00319 {
00320 bool gotOne = FALSE;
00321 int i = 0;
00322
00323 while (**s == ' ')
00324 {
00325 (*s)++;
00326 }
00327
00328 if (**s == '-')
00329 {
00330 (*s)++;
00331 if (**s < '0' || **s > '9')
00332 {
00333 llbug (message ("getInt: bad int: %s", cstring_fromChars (*s)));
00334 }
00335 else
00336 {
00337 i = -1 * (int) (**s - '0');
00338 gotOne = TRUE;
00339 }
00340
00341 (*s)++;
00342 }
00343
00344 while (**s >= '0' && **s <= '9')
00345 {
00346 i *= 10;
00347 i += (int) (**s - '0');
00348 (*s)++;
00349 gotOne = TRUE;
00350 }
00351
00352 if (!gotOne)
00353 {
00354 llbug (message ("No int to read: %s", cstring_fromChars (*s)));
00355 }
00356
00357 while (**s == '\n' || **s == ' ' || **s == '\t')
00358 {
00359 (*s)++;
00360 }
00361
00362 return i;
00363 }
|
|
|
Definition at line 401 of file general.c. 00402 {
00403 char *res;
00404 char *t = *s;
00405 char c;
00406
00407 while ((c = **s) != '\0' && (c != ' ') && (c != ',')
00408 && (c != '\n') && (c != '\t') && (c != '#'))
00409 {
00410 (*s)++;
00411 }
00412
00413 if (*s == t)
00414 {
00415 return NULL;
00416 }
00417
00418 **s = '\0';
00419 res = mstring_copy (t);
00420 **s = c;
00421 return res;
00422 }
|
|
|
Definition at line 583 of file general.c. Referenced by filelocList_unparseUses(). 00584 {
00585 int ret = 1;
00586
00587 while (x > 10)
00588 {
00589 ret++;
00590 x /= 10;
00591 }
00592
00593 return ret;
00594 }
|
|
|
Definition at line 187 of file general.c. Referenced by isLCLfile(), and main(). 00188 {
00189 return (!mstring_equal (ext, ".lcl") &&
00190 !mstring_equal (ext, ".spc") &&
00191 !mstring_equal (ext, ".ll"));
00192 }
|
|
|
Definition at line 728 of file general.c. 00729 {
00730 char *ext = filenameExtension (cstring_toCharsSafe (fname));
00731
00732 return (mstring_equal (ext, ".h")
00733 || mstring_equal (ext, ".H")
00734 || mstring_equal (ext, ".lh"));
00735 }
|
|
|
Definition at line 195 of file general.c. 00196 {
00197 char *ext;
00198
00199 ext = filenameExtension (cstring_toCharsSafe (s));
00200
00201 if (ext != NULL)
00202 {
00203 return (!(isCext (ext)));
00204 }
00205
00206 return (TRUE);
00207 }
|
|
|
Definition at line 366 of file general.c. 00367 {
00368 char ret;
00369
00370 while (**s == ' ')
00371 {
00372 (*s)++;
00373 }
00374
00375 ret = **s;
00376 (*s)++;
00377 return ret;
00378 }
|
|
|
Definition at line 598 of file general.c. 00599 {
00600 llassert (x >= 0);
00601
00602 return (long unsigned) x;
00603 }
|
|
|
Definition at line 641 of file general.c. 00642 {
00643 int res = (int) x;
00644
00645 llassert ((long unsigned) res == x);
00646 return res;
00647 }
|
|
|
Definition at line 650 of file general.c. Referenced by cppGetToken(). 00651 {
00652 int res = (int) x;
00653
00654 /*@+ignorequals@*/ llassert (res == x); /*@=ignorequals@*/
00655 return res;
00656 }
|
|
|
Definition at line 520 of file general.c. Referenced by LCLScanLine(), and message(). 00521 {
00522 size_t l = strlen (s1);
00523 char *s;
00524
00525 s = (char *) dmalloc (sizeof (*s) * (l + 2));
00526
00527 strcpy (s, s1);
00528 *(s + l) = c;
00529 *(s + l + 1) = '\0';
00530 sfree (s1);
00531 return s;
00532 }
|
|
|
Definition at line 487 of file general.c. Referenced by addExtension(), outputLCSFile(), and processImport(). 00488 {
00489 char *s = (char *) dmalloc (strlen (s1) + strlen (s2) + 1);
00490 strcpy (s, s1);
00491 strcat (s, s2);
00492 return s;
00493 }
|
|
|
Definition at line 496 of file general.c. Referenced by lslOp_unparse(), and message(). |
|
|
Definition at line 509 of file general.c. Referenced by message(), and nd_charp(). 00510 {
00511 char *s = (char *) dmalloc (strlen (s1) + strlen (s2) + 1);
00512 strcpy (s, s1);
00513 strcat (s, s2);
00514 sfree (s1);
00515
00516 return s;
00517 }
|
|
|
Definition at line 535 of file general.c. Referenced by addExtension(), cppReader_initializeReader(), cstring_copy(), getWord(), main(), nd_charp(), processImport(), removeAnyExtension(), removeExtension(), removePath(), removePathFree(), tsource_fromString(), usymtab_printComplete(), and usymtab_printOut(). 00536 {
00537 if (s1 == NULL)
00538 {
00539 return NULL;
00540 }
00541 else
00542 {
00543 char *s = (char *) dmalloc ((strlen (s1) + 1) * sizeof (*s));
00544 strcpy (s, s1);
00545 return s;
00546 }
00547 }
|
|
|
Definition at line 563 of file general.c. Referenced by context_loadModuleAccess(), cstring_concat(), cstring_copyLength(), loadStandardState(), lsymbol_toCharsSafe(), summarizeErrors(), typeIdSet_loadTable(), and usymtab_load(). 00564 {
00565 char *s;
00566
00567 s = dmalloc (sizeof (*s) * (n + 1));
00568 *s = '\0';
00569 return s;
00570 }
|
|
|
Definition at line 675 of file general.c. Referenced by LCLScanLine(), context_isSpecialFile(), isCext(), isHeaderFile(), lcllib_isSkipHeader(), main(), outputLCSFile(), and removeExtension(). 00676 {
00677 if (s1 == NULL)
00678 {
00679 return (s2 == NULL);
00680 }
00681 else
00682 {
00683 if (s2 == NULL)
00684 {
00685 return FALSE;
00686 }
00687 else
00688 {
00689 return (strcmp(s1, s2) == 0);
00690 }
00691 }
00692 }
|
|
|
Definition at line 660 of file general.c. Referenced by BUFLEN(), and cppReader_parseNumber(). 00661 {
00662 llassert (c1 != NULL);
00663 llassert (c2 != NULL);
00664
00665 if (strncmp(c1, c2, strlen(c2)) == 0)
00666 {
00667 return TRUE;
00668 }
00669 else
00670 {
00671 return FALSE;
00672 }
00673 }
|
|
|
Definition at line 278 of file general.c. Referenced by main(), and nd_charp(). 00279 {
00280 sfreeEventually (s);
00281 }
|
|
|
Definition at line 550 of file general.c. 00551 {
00552 if (s == NULL)
00553 {
00554 return ("<undefined>");
00555 }
00556 else
00557 {
00558 return s;
00559 }
00560 }
|
|
|
Definition at line 466 of file general.c. 00467 {
00468 int i;
00469 char *ret;
00470 char *ptr;
00471
00472 llassert (n >= 0);
00473
00474 ret = (char *) dmalloc (size_fromInt (n + 1));
00475 ptr = ret;
00476
00477 for (i = 0; i < n; i++)
00478 {
00479 *ptr++ = ' ';
00480 }
00481
00482 *ptr = '\0';
00483
00484 return ret;
00485 }
|
|
|
Definition at line 425 of file general.c. Referenced by uentry_undump(). 00426 {
00427 if (**s == c)
00428 {
00429 (*s)++;
00430 return TRUE;
00431 }
00432 else
00433 {
00434 return FALSE;
00435 }
00436 }
|
|
|
Definition at line 284 of file general.c. Referenced by callLSL(). 00285 {
00286 char *ret;
00287 char *t = strrchr (s, '.');
00288
00289 if (t == (char *) 0)
00290 {
00291 return mstring_copy (s);
00292 }
00293
00294 /*@-mods@*/
00295 *t = '\0';
00296 ret = mstring_copy (s);
00297 *t = '.';
00298 /*@=mods@*/ /* modification is undone */
00299
00300 return ret;
00301 }
|
|
|
Definition at line 209 of file general.c. Referenced by context_exitLCLfile(), and lcllib_isSkipHeader(). 00210 {
00211 char *t = strrchr (s, '.');
00212 char *s2;
00213
00214 if (t == (char *) 0 || !mstring_equal (t, suffix))
00215 {
00216 return mstring_copy (s);
00217 }
00218
00219 /*@-mods@*/
00220 *t = '\0';
00221 s2 = mstring_copy (s);
00222 *t = '.';
00223 /*@=mods@*/ /* Modification is undone. */
00224 return s2;
00225 }
|
|
|
Definition at line 243 of file general.c. Referenced by callLSL(). 00244 {
00245 char *t = strrchr (s, CONNECTCHAR);
00246
00247 if (t == NULL) return (mstring_copy (s));
00248 else return (mstring_copy (t + 1));
00249 }
|
|
|
Definition at line 253 of file general.c. 00254 {
00255 char *t = strrchr (s, CONNECTCHAR);
00256
00257 # ifdef ALTCONNECTCHAR
00258 {
00259 char *at = strrchr (s, ALTCONNECTCHAR);
00260 if (t == NULL || (at > t)) {
00261 t = at;
00262 }
00263 }
00264 # endif
00265
00266 if (t == NULL)
00267 {
00268 return (s);
00269 }
00270 else
00271 {
00272 char *res = mstring_copy (t + 1);
00273 mstring_free (s);
00274 return res;
00275 }
00276 }
|
|
|
Definition at line 701 of file general.c. 00702 {
00703 while (*s == '.' && *(s + 1) == CONNECTCHAR)
00704 {
00705 s += 2;
00706 }
00707
00708 # if defined(OS2) || defined(MSDOS)
00709 /* remove remainders from double path delimiters... */
00710 while (*s == CONNECTCHAR)
00711 {
00712 ++s;
00713 }
00714 # endif /* !defined(OS2) && !defined(MSDOS) */
00715
00716 return s;
00717 }
|
|
|
|
Definition at line 65 of file general.c. Referenced by cstring_markOwned(), ltoken_markOwned(), mstring_markFree(), sigNode_markOwned(), uentry_markOwned(), and argdata::use_count(). 00066 {
00067 if (x != NULL)
00068 {
00069 ; /* should keep in a table */
00070 }
00071 /*@-mustfree@*/
00072 }
|
|
|
Definition at line 605 of file general.c. Referenced by LSLRootName(), cppReader_checkMacroName(), cppReader_initializeReader(), and cppReader_parseExpression(). 00606 {
00607 size_t res = (size_t) x;
00608
00609 llassert ((int) res == x);
00610 return res;
00611 }
|
|
|
Definition at line 613 of file general.c. Referenced by FILE_NAME_MAP_FILE(), REST_EXTENSION_LENGTH(), cppReader_checkMacroName(), cstring_equalCanonicalPrefix(), cstring_length(), cstring_replaceLit(), lclctype_toSort(), lclctype_toSortDebug(), lhCleanup(), nd_charp(), and specFullName(). 00614 {
00615 int res = (int) x;
00616
00617 llassert ((size_t) res == x);
00618 return res;
00619 }
|
|
|
Definition at line 621 of file general.c. 00622 {
00623 long res = (long) x;
00624
00625 llassert ((size_t) res == x);
00626 return res;
00627 }
|
1.2.3 written by Dimitri van Heesch,
© 1997-2000