Skip to content
Myr

Merge branch 'master' into working

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parents 8cf9f5a, a0b521f · Browse files · 27 files+398 added−386 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

27 files+398 added−386 removed

  • tests:+0 added−0 removed
  • other:+398 added−386 removed

27 files+398 added−386 removed

This commit is too large to show whole: its files are listed by path, without their changes.

modified:tests/image_test.cnot shown

Its text is not shown, modified.

modified:tests/image_write_test.cnot shown

Its text is not shown, modified.

modified:tests/resample_test.cppnot shown

Its text is not shown, modified.

modified:tests/stb_cpp.cppnot shown

Its text is not shown, modified.

added:tests/stb_static.cnot shown

Its text is not shown, added.

modified:tests/stb.cnot shown

Its text is not shown, modified.

modified:tests/stretchy_buffer_test.cnot shown

Its text is not shown, modified.

modified:tests/test_cpp_compilation.cppnot shown

Its text is not shown, modified.

added:tests/test_ds_cpp.cppnot shown

Its text is not shown, added.

modified:tests/test_ds.cnot shown

Its text is not shown, modified.

modified:tests/test_easyfont.cnot shown

Its text is not shown, modified.

modified:tests/test_image_write.cnot shown

Its text is not shown, modified.

modified:tests/test_image.cnot shown

Its text is not shown, modified.

modified:tests/test_vorbis.cnot shown

Its text is not shown, modified.

added:tests/test.sbmnot shown

Its text is not shown, added.

modified:tests/textedit_sample.cnot shown

Its text is not shown, modified.

modified:stb_c_lexer.h+5 added-4 removed
512 unmodified lines
513 *out++ = (char) n;514 }515 *out = 0;516 lexer->string = lexer->string_storage;517 lexer->string_len = out - lexer->string_storage;517 lexer->string_len = (int) (out - lexer->string_storage);518 return stb__clex_token(lexer, type, start, p);519}520521int stb_c_lexer_get_token(stb_lexer *lexer)
301 unmodified lines
823}824#endif // STB_C_LEXER_IMPLEMENTATION825826#ifdef STB_C_LEXER_SELF_TEST827827#define _CRT_SECURE_NO_WARNINGS828#include <stdio.h>829#include <stdlib.h>830831static void print_token(stb_lexer *lexer)
51 unmodified lines
883void dummy(void)884{885 double some_floats[] = {886 1.0501, -10.4e12, 5E+10,887#if 0 // not support in C++ or C-pre-99, so don't try to compile it887#if 0 // not supported in C++ or C-pre-99, so don't try to compile it, but let our parser test it888 0x1.0p+24, 0xff.FP-8, 0x1p-23,889#endif890 4.891 };892 (void) sizeof(some_floats);893894 printf("test %d",1); // https://github.com/nothings/stb/issues/13895}896897int main(int argc, char **argv)898{899 FILE *f = fopen("stb_c_lexer.h","rb");900 char *text = (char *) malloc(1 << 20);900 int len = f ? fread(text, 1, 1<<20, f) : -1;901 int len = f ? (int) fread(text, 1, 1<<20, f) : -1;902 stb_lexer lex;903 if (len < 0) {904 fprintf(stderr, "Error opening file\n");905 free(text);
58 unmodified lines
modified:stb_connected_components.h+6 added-3 removed
707 unmodified lines
708}709710static void stbcc__add_connections_to_adjacent_cluster(stbcc_grid *g, int cx, int cy, int dx, int dy)711{712 unsigned char connected[STBCC__MAX_EDGE_CLUMPS_PER_CLUSTER][STBCC__MAX_EDGE_CLUMPS_PER_CLUSTER/8] = { 0 };712 unsigned char connected[STBCC__MAX_EDGE_CLUMPS_PER_CLUSTER][STBCC__MAX_EDGE_CLUMPS_PER_CLUSTER/8] = { { 0 } };713 int x = cx * STBCC__CLUSTER_SIZE_X;714 int y = cy * STBCC__CLUSTER_SIZE_Y;715 int step_x, step_y=0, i, j, k, n;716
33 unmodified lines
750 step_y = 0;751 n = STBCC__CLUSTER_SIZE_X;752 } else {753 assert(0);754 return;755 }756757 for (k=0; k < n; ++k) {758 if (STBCC__MAP_OPEN(g, x+i, y+j) && STBCC__MAP_OPEN(g, x+i+dx, y+j+dy)) {
13 unmodified lines
772}773774static void stbcc__remove_connections_to_adjacent_cluster(stbcc_grid *g, int cx, int cy, int dx, int dy)775{775 unsigned char disconnected[STBCC__MAX_EDGE_CLUMPS_PER_CLUSTER][STBCC__MAX_EDGE_CLUMPS_PER_CLUSTER/8] = { 0 };776 unsigned char disconnected[STBCC__MAX_EDGE_CLUMPS_PER_CLUSTER][STBCC__MAX_EDGE_CLUMPS_PER_CLUSTER/8] = { { 0 } };777 int x = cx * STBCC__CLUSTER_SIZE_X;778 int y = cy * STBCC__CLUSTER_SIZE_Y;779 int step_x, step_y=0, i, j, k, n;780
30 unmodified lines
811 step_y = 0;812 n = STBCC__CLUSTER_SIZE_X;813 } else {814 assert(0);815 return;816 }817818 for (k=0; k < n; ++k) {819 if (STBCC__MAP_OPEN(g, x+i, y+j) && STBCC__MAP_OPEN(g, x+i+dx, y+j+dy)) {
135 unmodified lines
955 // label any internal clusters956 for (j=1; j < STBCC__CLUSTER_SIZE_Y-1; ++j) {957 for (i=1; i < STBCC__CLUSTER_SIZE_X-1; ++i) {958 stbcc__tinypoint p = cbi.parent[j][i];957 if (p.x == i && p.y == j)959 if (p.x == i && p.y == j) {960 if (STBCC__MAP_OPEN(g,x+i,y+j))961 cbi.label[j][i] = label++;962 else963 cbi.label[j][i] = STBCC__NULL_CLUMPID;964 }965 }966 }967968 // label all other nodes
80 unmodified lines
modified:stb_ds.h+43 added-20 removed
273 unmodified lines
274NOTES - HASH MAP275276 * For compilers other than GCC and clang (e.g. Visual Studio), for hmput/hmget/hmdel277 and variants, the key must be an lvalue (so the macro can take the address of it).278 For GCC and clang, extensions are used that eliminate this requirement if you're279 using C99 and later or using C++.278 Extensions are used that eliminate this requirement if you're using C99 and later279 in GCC or clang, or if you're using C++ in GCC.280281 * To test for presence of a key in a hashmap, just do 'hmget(foo,key) >= 0'.281 * To test for presence of a key in a hashmap, just do 'hmgeti(foo,key) >= 0'.282283 * The iteration order of your data in the hashmap is determined solely by the284 order of insertions and deletions. In particular, if you never delete, new285 keys are always added at the end of the array. This will be consistent
22 unmodified lines
308 Sean Barrett -- library, idea for dynamic array API/implementation309 Per Vognsen -- idea for hash table API/implementation310*/311312#ifdef STBDS_UNIT_TESTS313#define _CRT_SECURE_NO_WARNINGS314#endif315316#ifndef INCLUDE_STB_DS_H317#define INCLUDE_STB_DS_H318319#include <stdlib.h>
102 unmodified lines
422#if defined(STBDS_HAS_LITERAL_ARRAY) && defined(STBDS_HAS_TYPEOF)423 #if __clang__424 #define STBDS_ADDRESSOF(typevar, value) ((__typeof__(typevar)[1]){value}) // literal array decays to pointer to value425 #else422 #define STBDS_ADDRESSOF(typevar, value) ((typeof(typevar)[]){value}) // literal array decays to pointer to value426 #define STBDS_ADDRESSOF(typevar, value) ((typeof(typevar)[1]){value}) // literal array decays to pointer to value427 #endif428#else429#define STBDS_ADDRESSOF(typevar, value) &(value)430#endif
168 unmodified lines
599#include <assert.h>600#include <string.h>601602#ifndef STBDS_ASSERT603#define STBDS_ASSERT_WAS_UNDEFINED604#define STBDS_ASSERT(x) ((void) 0)605#endif606607#ifdef STBDS_STATISTICS
47 unmodified lines
655//656// stbds_hm hash table implementation657//658654#define STBDS_CACHE_LINE_SIZE 64659#ifdef STBDS_INTERNAL_SMALL_BUCKET660#define STBDS_BUCKET_LENGTH 4661#else662#define STBDS_BUCKET_LENGTH 8656#define STBDS_BUCKET_SHIFT 3663#endif664665#define STBDS_BUCKET_SHIFT (STBDS_BUCKET_LENGTH == 8 ? 3 : 2)666#define STBDS_BUCKET_MASK (STBDS_BUCKET_LENGTH-1)667#define STBDS_CACHE_LINE_SIZE 64668669#define STBDS_ALIGN_FWD(n,a) (((n) + (a) - 1) & ~((a)-1))670671typedef struct
38 unmodified lines
710#define STBDS_SIZE_T_BITS ((sizeof (size_t)) * 8)711712static size_t stbds_probe_position(size_t hash, size_t slot_count, size_t slot_log2)713{704 #if 1705 size_t pos = (hash >> (STBDS_SIZE_T_BITS-slot_log2));706 STBDS_ASSERT(pos < slot_count);707 return pos;708 #else709 return hash & (slot_count-1);714 size_t pos;715 pos = hash & (slot_count-1);716 #ifdef STBDS_INTERNAL_BUCKET_START717 pos &= ~STBDS_BUCKET_MASK;718 #endif719 return pos;720}721722static size_t stbds_log2(size_t slot_count)723{
99 unmodified lines
823 STBDS_STATS(++stbds_rehash_items);824 for (;;) {825 size_t limit,z;826 stbds_hash_bucket *bucket;818 pos &= (t->slot_count-1);827 bucket = &t->storage[pos >> STBDS_BUCKET_SHIFT];828 STBDS_STATS(++stbds_rehash_probes);829830 for (z=pos & STBDS_BUCKET_MASK; z < STBDS_BUCKET_LENGTH; ++z) {
14 unmodified lines
845 }846847 pos += step; // quadratic probing848 step += STBDS_BUCKET_LENGTH;849 pos &= (t->slot_count-1);850 }851 }852 done:853 ;
96 unmodified lines
950 STBDS_SIPROUND();951#ifdef STBDS_SIPHASH_2_4952 return v0^v1^v2^v3;953#else945 return v1^v2^v3; // slightly stronger since v0^v3 in above cancels out final round operation954 return v1^v2^v3; // slightly stronger since v0^v3 in above cancels out final round operation? I tweeted at the authors of SipHash about this but they didn't reply955#endif956}957958size_t stbds_hash_bytes(void *p, size_t len, size_t seed)
6 unmodified lines
965 if (len == 4) {966 unsigned int hash = d[0] | (d[1] << 8) | (d[2] << 16) | (d[3] << 24);967 #if 0968 // HASH32-A Bob Jenkin's hash function w/o large constants960 hash ^= seed ^ len;969 hash ^= seed;970 hash -= (hash<<6);971 hash ^= (hash>>17);972 hash -= (hash<<9);973 hash ^= seed;974 hash ^= (hash<<4);975 hash -= (hash<<3);976 hash ^= (hash<<10);977 hash ^= (hash>>15);978 #elif 1979 // HASH32-BB Bob Jenkin's presumably-accidental version of Thomas Wang hash with rotates turned into shifts.980 // Note that converting these back to rotates makes it run a lot slower, presumably due to collisions, so I'm981 // not really sure what's going on.972 hash ^= seed ^ len;982 hash ^= seed;983 hash = (hash ^ 61) ^ (hash >> 16);984 hash = hash + (hash << 3);985 hash = hash ^ (hash >> 4);986 hash = hash * 0x27d4eb2d;987 hash ^= seed;988 hash = hash ^ (hash >> 15);989 #else // HASH32-C - Murmur3990 hash ^= seed;991 hash *= 0xcc9e2d51;992 hash = (hash << 17) | (hash >> 15);993 hash *= 0x1b873593;994 hash ^= seed;995 hash = (hash << 19) | (hash >> 13);996 hash = hash*5 + 0xe6546b64;985 hash ^= len;997 hash ^= hash >> 16;998 hash *= 0x85ebca6b;999 hash ^= seed;1000 hash ^= hash >> 13;1001 hash *= 0xc2b2ae35;1002 hash ^= hash >> 16;1003 #endif
16 unmodified lines
1020 return (((size_t) hash << 16 << 16) | hash) ^ seed;1021 } else if (len == 8 && sizeof(size_t) == 8) {1022 size_t hash = d[0] | (d[1] << 8) | (d[2] << 16) | (d[3] << 24);1023 hash |= (size_t) (d[4] | (d[5] << 8) | (d[6] << 16) | (d[7] << 24)) << 16 << 16; // avoid warning if size_t == 41012 hash ^= seed ^ len;1024 hash ^= seed;1025 hash = (~hash) + (hash << 21);1026 hash ^= STBDS_ROTATE_RIGHT(hash,24);1027 hash *= 265;1028 hash ^= STBDS_ROTATE_RIGHT(hash,14);1029 hash ^= seed;1030 hash *= 21;1031 hash ^= STBDS_ROTATE_RIGHT(hash,28);1032 hash += (hash << 31);1033 hash = (~hash) + (hash << 18);1021 return hash^seed;1034 return hash;1035 } else {1036 return stbds_siphash_bytes(p,len,seed);1037 }1038#endif
248 unmodified lines
1287void * stbds_shmode_func(size_t elemsize, int mode)1288{1289 void *a = stbds_arrgrowf(0, elemsize, 0, 1);1290 stbds_hash_index *h;1291 memset(a, 0, elemsize);1292 stbds_header(a)->length = 1;1293 stbds_header(a)->hash_table = h = (stbds_hash_index *) stbds_make_hash_index(STBDS_BUCKET_LENGTH, NULL);1294 h->string.mode = mode;1295 return STBDS_ARR_TO_HASH(a,elemsize);1296}
152 unmodified lines
1449//14501451#ifdef STBDS_UNIT_TESTS1452#include <stdio.h>1453#ifdef STBDS_ASSERT_WAS_UNDEFINED1454#undef STBDS_ASSERT1455#endif1456#ifndef STBDS_ASSERT1457#define STBDS_ASSERT assert1458#include <assert.h>1459#endif
2 unmodified lines
14621463static char buffer[256];1464char *strkey(int n)1465{1466#if defined(_WIN32) && defined(__STDC_WANT_SECURE_LIB__)1467 sprintf_s(buffer, sizeof(buffer), "test_%d", n);1468#else1469 sprintf(buffer, "test_%d", n);1470#endif1471 return buffer;1472}14731474void stbds_unit_tests(void)
134 unmodified lines
1609 hmfree(map);16101611 for (i=0; i < testsize; i += 1) {1612 stbds_struct s = { i,i*2,i*3,i*4 };1591 stbds_struct t = { i,i*2,i*3,i*4 };1613 stbds_struct t = { i,i*2,i*3+1,i*4 };1614 if (i & 1) STBDS_ASSERT(hmgets(map2, s.key).d == 0);1615 else STBDS_ASSERT(hmgets(map2, s.key).d == i*4);1616 STBDS_ASSERT(hmget(map, t) == 0);1617 }1618 hmfree(map2);1619#endif1620}
44 unmodified lines
modified:stb_herringbone_wang_tile.h+7 added-7 removed
164 unmodified lines
165166typedef struct stbhw_tileset stbhw_tileset;167168// returns description of last error produced by any function (not thread-safe)169STBHW_EXTERN char *stbhw_get_last_error(void);169STBHW_EXTERN const char *stbhw_get_last_error(void);170171// build a tileset from an image that conforms to a template created by this172// library. (you allocate storage for stbhw_tileset and function fills it out;173// memory for individual tiles are malloc()ed).
170 unmodified lines
344static signed char c_color[STB_HBWANG_MAX_Y+6][STB_HBWANG_MAX_X+6];345static signed char v_color[STB_HBWANG_MAX_Y+6][STB_HBWANG_MAX_X+5];346static signed char h_color[STB_HBWANG_MAX_Y+5][STB_HBWANG_MAX_X+6];347348static char *stbhw_error;349STBHW_EXTERN char *stbhw_get_last_error(void)348static const char *stbhw_error;349STBHW_EXTERN const char *stbhw_get_last_error(void)350{351 char *temp = stbhw_error;351 const char *temp = stbhw_error;352 stbhw_error = 0;353 return temp;354}355
360 unmodified lines
716 // now go back through and make sure we don't have adjancent 3x2 vertices that are identical,717 // to avoid really obvious repetition (which happens easily with extreme weights)718 for (j=0; j < ymax-3; ++j) {719 for (i=0; i < xmax-3; ++i) {720 int p = (i-j+1) & 3; // corner type720 //int p = (i-j+1) & 3; // corner type // unused, not sure what the intent was so commenting it out721 STB_HBWANG_ASSERT(i+3 < STB_HBWANG_MAX_X+6);722 STB_HBWANG_ASSERT(j+3 < STB_HBWANG_MAX_Y+6);723 if (stbhw__match(i,j) && stbhw__match(i,j+1) && stbhw__match(i,j+2)724 && stbhw__match(i+1,j) && stbhw__match(i+1,j+1) && stbhw__match(i+1,j+2)) {
21 unmodified lines
746 i = 0;747 } else {748 i = phase-4;749 }750 for (i;; i += 4) {750 for (;; i += 4) {751 int xpos = i * sidelen;752 if (xpos >= w)753 break;754 // horizontal left-block
42 unmodified lines
797 i = 0;798 } else {799 i = phase-4;800 }801 for (i;; i += 4) {801 for (;; i += 4) {802 int xpos = i * sidelen;803 if (xpos >= w)804 break;805 // horizontal left-block
415 unmodified lines
modified:stb_image_resize.h+4 added-2 removed
191 unmodified lines
192typedef uint16_t stbir_uint16;193typedef uint32_t stbir_uint32;194#endif195196#ifndef STBIRDEF197#ifdef STB_IMAGE_RESIZE_STATIC198#define STBIRDEF static199#else200#ifdef __cplusplus
1 unmodified line
202#else203#define STBIRDEF extern204#endif205#endif206#endif207206208//////////////////////////////////////////////////////////////////////////////209//210// Easy-to-use API:211//
2112 unmodified lines
23242325 if (alpha_channel < 0)2326 flags |= STBIR_FLAG_ALPHA_USES_COLORSPACE | STBIR_FLAG_ALPHA_PREMULTIPLIED;23272327 if (!(flags&STBIR_FLAG_ALPHA_USES_COLORSPACE) || !(flags&STBIR_FLAG_ALPHA_PREMULTIPLIED))2328 if (!(flags&STBIR_FLAG_ALPHA_USES_COLORSPACE) || !(flags&STBIR_FLAG_ALPHA_PREMULTIPLIED)) {2329 STBIR_ASSERT(alpha_channel >= 0 && alpha_channel < info->channels);2330 }23312332 if (alpha_channel >= info->channels)2333 return 0;2334
295 unmodified lines
modified:stb_image_write.hnot shown

Its text is not shown, modified.

modified:stb_image.h+3 added-1 removed
337 unmodified lines
338#ifdef __cplusplus339extern "C" {340#endif341342#ifndef STBIDEF343#ifdef STB_IMAGE_STATIC344#define STBIDEF static345#else346#define STBIDEF extern347#endif348#endif349350//////////////////////////////////////////////////////////////////////////////351//352// PRIMARY API - works on images of any type
830 unmodified lines
11831184#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)1185STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input)1186{1185 return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, bufferlen, NULL, NULL);1187 return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL);1188}1189#endif11901191static FILE *stbi__fopen(char const *filename, char const *mode)
6355 unmodified lines
modified:stb_tilemap_editor.hnot shown

Its text is not shown, modified.

modified:stb_vorbis.cnot shown

Its text is not shown, modified.

modified:stb_voxel_render.hnot shown

Its text is not shown, modified.

modified:stb.h+330 added-349 removed
415 unmodified lines
416#ifdef STB_DEBUG417 #include <assert.h>418#endif419420//////////////////////////////////////////////////////////////////////////////421//422// C library function platform handling423//424425#ifdef STB_DEFINE426427#if defined(_WIN32) && defined(__STDC_WANT_SECURE_LIB__)428static FILE * stb_p_fopen(const char *filename, const char *mode)429{430 FILE *f;431 if (0 == fopen_s(&f, filename, mode))432 return f;433 else434 return NULL;435}436static FILE * stb_p_wfopen(const wchar_t *filename, const wchar_t *mode)437{438 FILE *f;439 if (0 == _wfopen_s(&f, filename, mode))440 return f;441 else442 return NULL;443}444static char *stb_p_strcpy_s(char *a, size_t size, const char *b)445{446 strcpy_s(a,size,b);447 return a;448}449static char *stb_p_strncpy_s(char *a, size_t size, const char *b, size_t count)450{451 strncpy_s(a,size,b,count);452 return a;453}454#define stb_p_mktemp(s) (_mktemp_s(s, strlen(s)+1) == 0)455#define stb_p_sprintf sprintf_s456#define stb_p_size(x) ,(x)457#else458#define stb_p_fopen fopen459#define stb_p_wfopen _wfopen460#define stb_p_strcpy_s(a,s,b) strcpy(a,b)461#define stb_p_strncpy_s(a,s,b,c) strncpy(a,b,c)462#define stb_p_mktemp(s) (mktemp(s) != NULL)463464#define stb_p_sprintf sprintf465#define stb_p_size(x) 466#endif467468#if defined(_WIN32)469#define stb_p_vsnprintf _vsnprintf470#else471#define stb_p_vsnprintf vsnprintf472#endif473474#if defined(_WIN32) && (_MSC_VER >= 1300)475#define stb_p_stricmp _stricmp476#define stb_p_strnicmp _strnicmp477#define stb_p_strdup _strdup478#else479#define stb_p_strdup strdup480#define stb_p_stricmp stricmp481#define stb_p_strnicmp strnicmp482#endif483484#endif // STB_DEFINE485486421STB_EXTERN void stb_wrapper_malloc(void *newp, int sz, char *file, int line);487STB_EXTERN void stb_wrapper_malloc(void *newp, size_t sz, char *file, int line);488STB_EXTERN void stb_wrapper_free(void *oldp, char *file, int line);423STB_EXTERN void stb_wrapper_realloc(void *oldp, void *newp, int sz, char *file, int line);489STB_EXTERN void stb_wrapper_realloc(void *oldp, void *newp, size_t sz, char *file, int line);490STB_EXTERN void stb_wrapper_calloc(size_t num, size_t sz, char *file, int line);425STB_EXTERN void stb_wrapper_listall(void (*func)(void *ptr, int sz, char *file, int line));491STB_EXTERN void stb_wrapper_listall(void (*func)(void *ptr, size_t sz, char *file, int line));492STB_EXTERN void stb_wrapper_dump(char *filename);427STB_EXTERN int stb_wrapper_allocsize(void *oldp);493STB_EXTERN size_t stb_wrapper_allocsize(void *oldp);494STB_EXTERN void stb_wrapper_check(void *oldp);495496#ifdef STB_DEFINE497// this is a special function used inside malloc wrapper
38 unmodified lines
536 #endif537#endif538539#ifdef STB_MALLOC_WRAPPER474 STB_EXTERN void * stb__malloc(int, char *, int);475 STB_EXTERN void * stb__realloc(void *, int, char *, int);540 STB_EXTERN void * stb__malloc(size_t, char *, int);541 STB_EXTERN void * stb__realloc(void *, size_t, char *, int);542 STB_EXTERN void * stb__calloc(size_t n, size_t s, char *, int);543 STB_EXTERN void stb__free(void *, char *file, int);544 STB_EXTERN char * stb__strdup(char *s, char *file, int);545 STB_EXTERN void stb_malloc_checkall(void);
35 unmodified lines
581 stb_wrapper_check(STB__ptr(p, STB__BIAS));582 return 1;583 }584519 static void stb__check2(void *p, int sz, char *file, int line)585 static void stb__check2(void *p, size_t sz, char *file, int line)586 {587 stb_mcheck(p);588 }589
30 unmodified lines
620 STB_EXTERN __declspec(dllimport) int __stdcall VirtualFree(void *p, unsigned long size, unsigned long freetype);621 #endif622 #endif623558 static void *stb__malloc_final(int sz)624 static void *stb__malloc_final(size_t sz)625 {626 #ifdef STB_MALLOC_WRAPPER_PAGED561 int aligned = (sz + STB__WINDOWS_PAGE - 1) & ~(STB__WINDOWS_PAGE-1);627 size_t aligned = (sz + STB__WINDOWS_PAGE - 1) & ~(STB__WINDOWS_PAGE-1);628 char *p = VirtualAlloc(NULL, aligned + STB__WINDOWS_PAGE, 0x2000, 0x04); // RESERVE, READWRITE629 if (p == NULL) return p;630 VirtualAlloc(p, aligned, 0x1000, 0x04); // COMMIT, READWRITE631 return p;
11 unmodified lines
643 #endif644 }645646 int stb__malloc_failure;647 #ifdef STB_MALLOC_WRAPPER_PAGED581 static void *stb__realloc_final(void *p, int sz, int old_sz)648 static void *stb__realloc_final(void *p, size_t sz, size_t old_sz)649 {583 #ifdef STB_MALLOC_WRAPPER_PAGED650 void *q = stb__malloc_final(sz);651 if (q == NULL)652 return ++stb__malloc_failure, q;653 // @TODO: deal with p being smaller!654 memcpy(q, p, sz < old_sz ? sz : old_sz);655 stb__free_final(p);656 return q;591 #else592 return realloc(p,sz);593 #endif657 }658 #endif659660 void stb__free(void *p, char *file, int line)661 {662 stb_mcheck_all();
11 unmodified lines
674 #endif675 stb__free_final(p);676 }677614 void * stb__malloc(int sz, char *file, int line)678 void * stb__malloc(size_t sz, char *file, int line)679 {680 void *p;681 stb_mcheck_all();682 if (sz == 0) return NULL;
21 unmodified lines
704 stb_wrapper_malloc(p,sz,file,line);705 return p;706 }707644 void * stb__realloc(void *p, int sz, char *file, int line)708 void * stb__realloc(void *p, size_t sz, char *file, int line)709 {710 void *q;711712 stb_mcheck_all();
5 unmodified lines
718 p = STB__ptr(p,-STB__BIAS);719 #endif720 #ifdef STB_MALLOC_WRAPPER_PAGED721 {658 int n = stb_wrapper_allocsize(STB__ptr(p,STB__BIAS));722 size_t n = stb_wrapper_allocsize(STB__ptr(p,STB__BIAS));723 if (!n)724 stb_wrapper_check(STB__ptr(p,STB__BIAS));725 q = stb__realloc_final(p, STB__FIXSIZE(sz), STB__FIXSIZE(n));726 }
18 unmodified lines
745 stb_wrapper_realloc(p,q,sz,file,line);746 return q;747 }748685 STB_EXTERN int stb_log2_ceil(unsigned int);749 STB_EXTERN int stb_log2_ceil(size_t);750 static void *stb__calloc(size_t n, size_t sz, char *file, int line)751 {752 void *q;753 stb_mcheck_all();
9 unmodified lines
763 char *p;764 stb_mcheck_all();765 p = stb__malloc(strlen(s)+1, file, line);766 if (!p) return p;703 strcpy(p, s);767 stb_p_strcpy_s(p, strlen(s)+1, s);768 return p;769 }770 #endif // STB_DEFINE771
14 unmodified lines
786 #define realloc(p,s) stb__realloc(p,s, __FILE__, __LINE__)787 #define calloc(n,s) stb__calloc (n,s, __FILE__, __LINE__)788 #define free(p) stb__free (p, __FILE__, __LINE__)789 #define strdup(p) stb__strdup (p, __FILE__, __LINE__)726790#endif791792//////////////////////////////////////////////////////////////////////////////793//
6 unmodified lines
800STB_EXTERN int stb_snprintf(char *s, size_t n, const char *fmt, ...);801STB_EXTERN int stb_vsnprintf(char *s, size_t n, const char *fmt, va_list v);802803#ifdef STB_DEFINE741804int stb_vsnprintf(char *s, size_t n, const char *fmt, va_list v)805{806 int res;807 #ifdef _WIN32746 // Could use "_vsnprintf_s(s, n, _TRUNCATE, fmt, v)" ?747 res = _vsnprintf(s,n,fmt,v);808 #ifdef __STDC_WANT_SECURE_LIB__809 res = _vsnprintf_s(s, n, _TRUNCATE, fmt, v);810 #else811 res = stb_p_vsnprintf(s,n,fmt,v);812 #endif813 #else814 res = vsnprintf(s,n,fmt,v);815 #endif816 if (n) s[n-1] = 0;
27 unmodified lines
844 va_list v;845 va_start(v,fmt);846 stb_vsnprintf(buffer,1024,fmt,v);847 va_end(v);783 return strdup(buffer);848 return stb_p_strdup(buffer);849}850851#ifdef _WIN32852
2 unmodified lines
855STB_EXTERN __declspec(dllimport) void * __stdcall GetStdHandle(unsigned int);856STB_EXTERN __declspec(dllimport) int __stdcall SetConsoleTextAttribute(void *, unsigned short);857#endif858794static void stb__print_one(void *handle, char *s, int len)859static void stb__print_one(void *handle, char *s, ptrdiff_t len)860{861 if (len)797 if (0==WriteConsoleA(handle, s, len, NULL,NULL))798 fwrite(s, 1, len, stdout); // if it fails, maybe redirected, so do normal862 if (0==WriteConsoleA(handle, s, (unsigned) len, NULL,NULL))863 // if it fails, maybe redirected, so output normally...864 // but it's supriously reporting failure now on Win7 and later865 {}//fwrite(s, 1, (unsigned) len, stdout);866}867868static void stb__print(char *s)869{
49 unmodified lines
919 SetConsoleTextAttribute(handle, 0x08); // 0,7,8,15 => shades of grey920 t = s+1;921 }922856 lpad = (t-s);923 lpad = (int) (t-s);924 s = t;925 while (*s && *s != '}') ++s;926 if (!*s) break;927 stb__print_one(handle, t, s-t);
23 unmodified lines
951952 if (res < 0) {953 tbuf = (char *) malloc(16384);954 va_start(v,fmt);888 res = _vsnprintf(tbuf,16384, fmt, v);955 res = stb_vsnprintf(tbuf,16384, fmt, v);956 va_end(v);957 tbuf[16383] = 0;958 }959
26 unmodified lines
986// file functions. So, ok, we do.987988989#ifdef _WIN32923 #define stb__fopen(x,y) _wfopen((const wchar_t *)stb__from_utf8(x), (const wchar_t *)stb__from_utf8_alt(y))990 #define stb__fopen(x,y) stb_p_wfopen((const wchar_t *)stb__from_utf8(x), (const wchar_t *)stb__from_utf8_alt(y))991 #define stb__windows(x,y) x992#else926 #define stb__fopen(x,y) fopen(x,y)993 #define stb__fopen(x,y) stb_p_fopen(x,y)994 #define stb__windows(x,y) y995#endif996997998typedef unsigned short stb__wchar;999933STB_EXTERN stb__wchar * stb_from_utf8(stb__wchar *buffer, char *str, int n);934STB_EXTERN char * stb_to_utf8 (char *buffer, stb__wchar *str, int n);1000STB_EXTERN stb__wchar * stb_from_utf8(stb__wchar *buffer, const char *str, int n);1001STB_EXTERN char * stb_to_utf8 (char *buffer, const stb__wchar *str, int n);1002936STB_EXTERN stb__wchar *stb__from_utf8(char *str);937STB_EXTERN stb__wchar *stb__from_utf8_alt(char *str);938STB_EXTERN char *stb__to_utf8(stb__wchar *str);1003STB_EXTERN stb__wchar *stb__from_utf8(const char *str);1004STB_EXTERN stb__wchar *stb__from_utf8_alt(const char *str);1005STB_EXTERN char *stb__to_utf8(const stb__wchar *str);100610071008#ifdef STB_DEFINE942stb__wchar * stb_from_utf8(stb__wchar *buffer, char *ostr, int n)1009stb__wchar * stb_from_utf8(stb__wchar *buffer, const char *ostr, int n)1010{1011 unsigned char *str = (unsigned char *) ostr;1012 stb_uint32 c;1013 int i=0;
41 unmodified lines
1055 buffer[i] = 0;1056 return buffer;1057}1058992char * stb_to_utf8(char *buffer, stb__wchar *str, int n)1059char * stb_to_utf8(char *buffer, const stb__wchar *str, int n)1060{1061 int i=0;1062 --n;1063 while (*str) {
27 unmodified lines
1091 buffer[i] = 0;1092 return buffer;1093}10941028stb__wchar *stb__from_utf8(char *str)1095stb__wchar *stb__from_utf8(const char *str)1096{1097 static stb__wchar buffer[4096];1098 return stb_from_utf8(buffer, str, 4096);1099}11001034stb__wchar *stb__from_utf8_alt(char *str)1101stb__wchar *stb__from_utf8_alt(const char *str)1102{1103 static stb__wchar buffer[4096];1104 return stb_from_utf8(buffer, str, 4096);1105}11061040char *stb__to_utf8(stb__wchar *str)1107char *stb__to_utf8(const stb__wchar *str)1108{1109 static char buffer[4096];1110 return stb_to_utf8(buffer, str, 4096);1111}
4 unmodified lines
1116//1117// Miscellany1118//11191053STB_EXTERN void stb_fatal(char *fmt, ...);1120STB_EXTERN void stb_fatal(const char *fmt, ...);1121STB_EXTERN void stb_(char *fmt, ...);1122STB_EXTERN void stb_append_to_file(char *file, char *fmt, ...);1123STB_EXTERN void stb_log(int active);1124STB_EXTERN void stb_log_fileline(int active);
6 unmodified lines
11311132#define stb_arrcount(x) (sizeof(x)/sizeof((x)[0]))113311341068STB_EXTERN int stb__record_fileline(char *f, int n);1135STB_EXTERN int stb__record_fileline(const char *f, int n);11361137#ifdef STB_DEFINE11381139static char *stb__file;1140static int stb__line;11411075int stb__record_fileline(char *f, int n)1142int stb__record_fileline(const char *f, int n)1143{1077 stb__file = f;1144 stb__file = (char*) f;1145 stb__line = n;1146 return 0;1147}11481082void stb_fatal(char *s, ...)1149void stb_fatal(const char *s, ...)1150{1151 va_list a;1152 if (stb__file)1153 fprintf(stderr, "[%s:%d] ", stb__file, stb__line);
28 unmodified lines
1182 stb__log_fileline = active;1183}11841185#ifdef STB_NO_STB_STRINGS1119char *stb__log_filename = "temp.log";1186const char *stb__log_filename = "temp.log";1187#else1121char *stb__log_filename = "stb.log";1188const char *stb__log_filename = "stb.log";1189#endif11901191void stb_log_name(char *s)1192{
2 unmodified lines
11951196void stb_(char *s, ...)1197{1198 if (stb__log_active) {1132 FILE *f = fopen(stb__log_filename, "a");1199 FILE *f = stb_p_fopen(stb__log_filename, "a");1200 if (f) {1201 va_list a;1202 if (stb__log_fileline && stb__file)1203 fprintf(f, "[%s:%4d] ", stb__file, stb__line);
7 unmodified lines
1211}12121213void stb_append_to_file(char *filename, char *s, ...)1214{1148 FILE *f = fopen(filename, "a");1215 FILE *f = stb_p_fopen(filename, "a");1216 if (f) {1217 va_list a;1218 va_start(a,s);1219 vfprintf(f, s, a);
274 unmodified lines
1494STB_EXTERN int stb_bitcount(unsigned int a);1495STB_EXTERN unsigned int stb_bitreverse8(unsigned char n);1496STB_EXTERN unsigned int stb_bitreverse(unsigned int n);14971431STB_EXTERN int stb_is_pow2(unsigned int n);1432STB_EXTERN int stb_log2_ceil(unsigned int n);1433STB_EXTERN int stb_log2_floor(unsigned int n);1498STB_EXTERN int stb_is_pow2(size_t);1499STB_EXTERN int stb_log2_ceil(size_t);1500STB_EXTERN int stb_log2_floor(size_t);15011502STB_EXTERN int stb_lowbit8(unsigned int n);1503STB_EXTERN int stb_highbit8(unsigned int n);1504
23 unmodified lines
1528 n = ((n & 0xFF00FF00) >> 8) | ((n & 0x00FF00FF) << 8);1529 return (n >> 16) | (n << 16);1530}15311465int stb_is_pow2(unsigned int n)1532int stb_is_pow2(size_t n)1533{1534 return (n & (n-1)) == 0;1535}1536
1 unmodified line
1538// 3-bit table would require another tree level; 5-bit table wouldn't save one1539#if defined(_WIN32) && !defined(__MINGW32__)1540#pragma warning(push)1541#pragma warning(disable: 4035) // disable warning about no return value1475int stb_log2_floor(unsigned int n)1542int stb_log2_floor(size_t n)1543{1544 #if _MSC_VER > 17001545 unsigned long i;1546 #ifdef STB_PTR641547 _BitScanReverse64(&i, n);1548 #else1549 _BitScanReverse(&i, n);1550 #endif1551 return i != 0 ? i : -1;1552 #else1553 __asm {1554 bsr eax,n
4 unmodified lines
1559 #endif1560}1561#pragma warning(pop)1562#else1492int stb_log2_floor(unsigned int n)1563int stb_log2_floor(size_t n)1564{1565 static signed char log2_4[16] = { -1,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3 };15661567#ifdef STB_PTR641568 if (n >= ((size_t) 1u << 32))1569 return stb_log2_floor(n >> 32);1570#endif15711572 // 2 compares if n < 16, 3 compares otherwise1573 if (n < (1U << 14))1574 if (n < (1U << 4)) return 0 + log2_4[n ];1575 else if (n < (1U << 9)) return 5 + log2_4[n >> 5];
6 unmodified lines
1582}1583#endif15841585// define ceil from floor1510int stb_log2_ceil(unsigned int n)1586int stb_log2_ceil(size_t n)1587{1588 if (stb_is_pow2(n)) return stb_log2_floor(n);1589 else return 1 + stb_log2_floor(n);1590}
21 unmodified lines
1612// qsort Compare Routines1613//16141615#ifdef _WIN321540 #define stb_stricmp(a,b) stricmp(a,b)1541 #define stb_strnicmp(a,b,n) strnicmp(a,b,n)1616 #define stb_stricmp(a,b) stb_p_stricmp(a,b)1617 #define stb_strnicmp(a,b,n) stb_p_strnicmp(a,b,n)1618#else1619 #define stb_stricmp(a,b) strcasecmp(a,b)1620 #define stb_strnicmp(a,b,n) strncasecmp(a,b,n)1621#endif
9 unmodified lines
16311632#ifdef STB_DEFINE1633static int stb__intcmpoffset, stb__ucharcmpoffset, stb__strcmpoffset;1634static int stb__floatcmpoffset, stb__doublecmpoffset;1635static int stb__memcmpoffset, stb__memcmpsize;16361637int stb__intcmp(const void *a, const void *b)1638{1639 const int p = *(const int *) ((const char *) a + stb__intcmpoffset);
42 unmodified lines
1682 const char *q = *(const char **) ((const char *) b + stb__strcmpoffset);1683 return stb_stricmp(p,q);1684}16851686int stb__memcmp(const void *a, const void *b)1687{1688 return memcmp((char *) a + stb__memcmpoffset, (char *) b + stb__memcmpoffset, stb__memcmpsize);1689}16901691int (*stb_intcmp(int offset))(const void *, const void *)1692{1693 stb__intcmpoffset = offset;1694 return &stb__intcmp;
33 unmodified lines
1728{1729 stb__doublecmpoffset = offset;1730 return &stb__doublecmp;1731}17321733int (*stb_memcmp(int offset, int size))(const void *, const void *)1734{1735 stb__memcmpoffset = offset;1736 stb__memcmpsize = size;1737 return &stb__memcmp;1738}1739#endif17401741//////////////////////////////////////////////////////////////////////////////1742//
181 unmodified lines
1924 if (len >= n) {1925 if (n) d[0] = 0;1926 return 0;1927 }1839 strcpy(d,s);1928 stb_p_strcpy_s(d,n+1,s);1929 return len + 1;1930}19311932const char *stb_plural(int n)
73 unmodified lines
2006}20072008char *stb_strncpy(char *s, char *t, int n)2009{1921 strncpy(s,t,n);2010 stb_p_strncpy_s(s,n+1,t,n);2011 s[n-1] = 0;2012 return s;2013}2014
2 unmodified lines
2017 char *a;2018 int z = (int) strlen(t);2019 if (z < n) n = z;2020 a = (char *) malloc(n+1);1932 strncpy(a,t,n);2021 stb_p_strncpy_s(a,n+1,t,n);2022 a[n] = 0;2023 return a;2024}20252026char *stb_duplower(char *s)2027{1939 char *p = strdup(s), *q = p;2028 char *p = stb_p_strdup(s), *q = p;2029 while (*q) {2030 *q = tolower(*q);2031 ++q;2032 }
271 unmodified lines
23042305 char *s,*p,*q;23062307 s = strstr(src, find);2219 if (s == NULL) return strdup(src);2308 if (s == NULL) return stb_p_strdup(src);2309 do {2310 ++count;2311 s = strstr(s + len_find, find);2312 } while (s != NULL);
4 unmodified lines
2317 s = src;2318 for (;;) {2319 char *t = strstr(s, find);2320 if (t == NULL) {2232 strcpy(q,s);2321 stb_p_strcpy_s(q,strlen(src)+count*(len_replace-len_find)+1,s);2322 assert(strlen(p) == strlen(src) + count*(len_replace-len_find));2323 return p;2324 }2325 memcpy(q, s, t-s);
11 unmodified lines
2337 int delta;23382339 char *s,*p,*q;23402252 delta = len_replace - len_find;2341 delta = (int) (len_replace - len_find);2342 assert(delta <= 0);2343 if (delta > 0) return;23442345 p = strstr(src, find);
19 unmodified lines
2365 if (*path == '\\')2366 *path = '/';2367}23682280void stb__add_section(char *buffer, char *data, int curlen, int newlen)2369void stb__add_section(char *buffer, char *data, ptrdiff_t curlen, ptrdiff_t newlen)2370{2371 if (newlen < curlen) {2283 int z1 = newlen >> 1, z2 = newlen-z1;2372 ptrdiff_t z1 = newlen >> 1, z2 = newlen-z1;2373 memcpy(buffer, data, z1-1);2374 buffer[z1-1] = '.';2375 buffer[z1-0] = '.';2376 memcpy(buffer+z1+1, data+curlen-z2+1, z2-1);
3 unmodified lines
23802381char * stb_shorten_path_readable(char *path, int len)2382{2383 static char buffer[1024];2295 int n = strlen(path),n1,n2,r1,r2;2384 ptrdiff_t n = strlen(path),n1,n2,r1,r2;2385 char *s;2386 if (n <= len) return path;2387 if (len > 1024) return path;2388 s = stb_strrchr2(path, '/', '\\');
28 unmodified lines
2417}24182419static char *stb__splitpath_raw(char *buffer, char *path, int flag)2420{2332 int len=0,x,y, n = (int) strlen(path), f1,f2;2421 ptrdiff_t len=0,x,y, n = (int) strlen(path), f1,f2;2422 char *s = stb_strrchr2(path, '/', '\\');2423 char *t = strrchr(path, '.');2424 if (s && t && t < s) t = NULL;2425 if (s) ++s;
28 unmodified lines
2454 buffer = (char *) malloc(y-x + len + 1);2455 if (!buffer) return NULL;2456 }24572369 if (len) { strcpy(buffer, "./"); return buffer; }2370 strncpy(buffer, path+x, y-x);2458 if (len) { stb_p_strcpy_s(buffer, sizeof(buffer), "./"); return buffer; }2459 stb_p_strncpy_s(buffer, sizeof(buffer),path+x, y-x);2460 buffer[y-x] = 0;2461 return buffer;2462}2463
11 unmodified lines
2475{2476 char buffer[4096];2477 stb_splitpath(buffer, src, STB_FILE | STB_EXT);2478 if (dir)2390 sprintf(output, "%s/%s", dir, buffer);2479 stb_p_sprintf(output stb_p_size(9999), "%s/%s", dir, buffer);2480 else2392 strcpy(output, buffer);2481 stb_p_strcpy_s(output, sizeof(buffer), buffer); // @UNSAFE2482 return output;2483}24842485char *stb_replaceext(char *output, char *src, char *ext)2486{2487 char buffer[4096];2488 stb_splitpath(buffer, src, STB_PATH | STB_FILE);2489 if (ext)2401 sprintf(output, "%s.%s", buffer, ext[0] == '.' ? ext+1 : ext);2490 stb_p_sprintf(output stb_p_size(9999), "%s.%s", buffer, ext[0] == '.' ? ext+1 : ext);2491 else2403 strcpy(output, buffer);2492 stb_p_strcpy_s(output, sizeof(buffer), buffer); // @UNSAFE2493 return output;2494}2495#endif2496
404 unmodified lines
29012902 if (align <= 0) {2903 // compute worst-case C packed alignment2904 // e.g. a 24-byte struct is 8-aligned2816 int align_proposed = 1 << stb_lowbit8(size);2905 int align_proposed = 1 << stb_lowbit8((unsigned int) size);29062907 if (align_proposed < 0)2908 align_proposed = 4;2909
41 unmodified lines
2951 break;2952 }29532954 case STB__chunk_raw: {2866 p = stb__alloc_chunk(src, size, align, 0);2955 p = stb__alloc_chunk(src, (int) size, align, 0);2956 if (p == NULL) return NULL;2957 break;2958 }29592960 case STB__chunked: {2961 stb__chunked *s;2962 if (align < sizeof(stb_uintptr)) align = sizeof(stb_uintptr);2874 s = (stb__chunked *) stb__alloc_chunk(src, size, align, sizeof(*s));2963 s = (stb__chunked *) stb__alloc_chunk(src, (int) size, align, sizeof(*s));2964 if (s == NULL) return NULL;2965 stb__setparent(s, src);2966 p = s+1;2967 break;
534 unmodified lines
3502 return hash1 + (hash2 >> 16);3503}35043505// Paul Hsieh hash3417#define stb__get16_slow(p) ((p)[0] + ((p)[1] << 8))3418#if defined(_MSC_VER)3419 #define stb__get16(p) (*((unsigned short *) (p)))3420#else3421 #define stb__get16(p) stb__get16_slow(p)3422#endif3506#define stb__get16(p) ((p)[0] | ((p)[1] << 8))35073508unsigned int stb_hash_fast(void *p, int len)3509{3510 unsigned char *q = (unsigned char *) p;
1 unmodified line
35123513 if (len <= 0 || q == NULL) return 0;35143515 /* Main loop */3432 if (((int)(size_t) q & 1) == 0) {3433 for (;len > 3; len -= 4) {3434 unsigned int val;3435 hash += stb__get16(q);3436 val = (stb__get16(q+2) << 11);3437 hash = (hash << 16) ^ hash ^ val;3438 q += 4;3439 hash += hash >> 11;3516 for (;len > 3; len -= 4) {3517 unsigned int val;3518 hash += stb__get16(q);3519 val = (stb__get16(q+2) << 11);3520 hash = (hash << 16) ^ hash ^ val;3521 q += 4;3522 hash += hash >> 11;3440 }3441 } else {3442 for (;len > 3; len -= 4) {3443 unsigned int val;3444 hash += stb__get16_slow(q);3445 val = (stb__get16_slow(q+2) << 11);3446 hash = (hash << 16) ^ hash ^ val;3447 q += 4;3448 hash += hash >> 11;3449 }3523 }35243525 /* Handle end cases */3526 switch (len) {3454 case 3: hash += stb__get16_slow(q);3527 case 3: hash += stb__get16(q);3528 hash ^= hash << 16;3529 hash ^= q[2] << 18;3530 hash += hash >> 11;3531 break;3459 case 2: hash += stb__get16_slow(q);3532 case 2: hash += stb__get16(q);3533 hash ^= hash << 11;3534 hash += hash >> 17;3535 break;3536 case 1: hash += q[0];
694 unmodified lines
42314232// extra fields needed for stua_dict4233#define STB_IEMPTY ((int) 1)4234#define STB_IDEL ((int) 3)4162stb_define_hash_base(STB_noprefix, stb_idict, short type; short gc; STB_nofields, stb_idict_,stb_idict_,0.85f,4235stb_define_hash_base(STB_noprefix, stb_idict, short type; short gc; STB_nofields, stb_idict_,stb_idict_,0.95f,4236 stb_int32,STB_IEMPTY,STB_IDEL,STB_nocopy,STB_nodelete,STB_nosafe,4237 STB_equal,STB_equal,4238 return stb_rehash_improved(k);,stb_int32,STB_nonullvalue,0)4239
61 unmodified lines
4301static stb__ptrpair stb__ptrpair_del = { (void *) 2, (void *) 2 };43024303#define STB__equal_ptrpair(x,y) ((x).a == (y).a && (x).b == (y).b)43044232stb_define_hash_base(static, stb_spmatrix, int val_size; void *arena;, stb__spmatrix_,stb__spmatrix_, 0.85,4305stb_define_hash_base(STB_noprefix, stb_spmatrix, int val_size; void *arena;, stb__spmatrix_,stb__spmatrix_, 0.85,4306 stb__ptrpair, stb__ptrpair_empty, stb__ptrpair_del,4307 STB_nocopy, STB_nodelete, STB_nosafe,4308 STB__equal_ptrpair, STB__equal_ptrpair, return stb_rehash(stb_hashptr(k.a))+stb_hashptr(k.b);,4309 void *, STB_nullvalue, 0)
63 unmodified lines
43734374#define STB_DEL ((void *) 1)4375#define STB_SDEL ((char *) 1)43764304#define stb_sdict__copy(x) \4305 strcpy(a->arena ? stb_malloc_string(a->arena, strlen(x)+1) \4306 : (char *) malloc(strlen(x)+1), x)4377#define stb_sdict__copy(x) \4378 stb_p_strcpy_s(a->arena ? stb_malloc_string(a->arena, strlen(x)+1) \4379 : (char *) malloc(strlen(x)+1), strlen(x)+1, x)43804381#define stb_sdict__dispose(x) if (!a->arena) free(x)43824383stb_define_hash_base(STB_noprefix, stb_sdict, void*arena;, stb_sdict_,stb_sdictinternal_, 0.85f,
749 unmodified lines
5133// File Processing5134//513551365064#ifdef _MSC_VER5137#ifdef _WIN325138 #define stb_rename(x,y) _wrename((const wchar_t *)stb__from_utf8(x), (const wchar_t *)stb__from_utf8_alt(y))5066 #define stb_mktemp _mktemp5139#else5068 #define stb_mktemp mktemp5140 #define stb_rename rename5141#endif51425143STB_EXTERN void stb_fput_varlen64(FILE *f, stb_uint64 v);
17 unmodified lines
5161STB_EXTERN int stb_feq(char *s1, char *s2);5162STB_EXTERN time_t stb_ftimestamp(char *filename);51635164STB_EXTERN int stb_fullpath(char *abs, int abs_size, char *rel);5094STB_EXTERN FILE * stb_fopen(char *filename, char *mode);5165STB_EXTERN FILE * stb_fopen(char *filename, const char *mode);5166STB_EXTERN int stb_fclose(FILE *f, int keep);51675168enum5169{
42 unmodified lines
5212#if 05213STBF *stb_tfopen(char *filename, char *mode)5214{5215 STBF *z;5145 FILE *f = fopen(filename, mode);5216 FILE *f = stb_p_fopen(filename, mode);5217 if (!f) return NULL;5218 z = (STBF *) malloc(sizeof(*z));5219 if (!z) { fclose(f); return NULL; }5220 z->base_file = f;
40 unmodified lines
5261{5262 fwrite(&x, 4, 1, f);5263}52645194#if defined(_MSC_VER) || defined(__MINGW32__)5265#if defined(_WIN32)5266 #define stb__stat _stat5267#else5268 #define stb__stat stat5269#endif
22 unmodified lines
5292}52935294size_t stb_filelen(FILE *f)5295{5225 size_t len, pos;5296 long len, pos;5297 pos = ftell(f);5298 fseek(f, 0, SEEK_END);5299 len = ftell(f);5300 fseek(f, pos, SEEK_SET);5230 return len;5301 return (size_t) len;5302}53035304void *stb_file(char *filename, size_t *length)5305{
95 unmodified lines
5401 // recopy the file so there's just a single allocation to free5402 memcpy(&list[count+1], buffer, len+1);5403 free(buffer);5404 buffer = (char *) &list[count+1];5334 if (plen) *plen = count;5405 if (plen) *plen = (int) count;5406 }5407 }5408 return list;5409}
18 unmodified lines
5428 char *p;5429 buffer[0] = 0;5430 p = fgets(buffer, buflen, f);5431 if (p) {5361 int n = strlen(p)-1;5432 int n = (int) (strlen(p)-1);5433 if (n >= 0)5434 if (p[n] == '\n')5435 p[n] = 0;5436 }
8 unmodified lines
5445 if (!fgets(quick_buffer, sizeof(quick_buffer), f))5446 return NULL;54475448 if (quick_buffer[sizeof(quick_buffer)-2] == 0) {5378 int n = strlen(quick_buffer);5449 size_t n = strlen(quick_buffer);5450 if (n > 0 && quick_buffer[n-1] == '\n')5451 quick_buffer[n-1] = 0;5381 return strdup(quick_buffer);5452 return stb_p_strdup(quick_buffer);5453 } else {5454 char *p;5384 char *a = strdup(quick_buffer);5385 int len = sizeof(quick_buffer)-1;5455 char *a = stb_p_strdup(quick_buffer);5456 size_t len = sizeof(quick_buffer)-1;54575458 while (!feof(f)) {5459 if (a[len-1] == '\n') break;5460 a = (char *) realloc(a, len*2);5461 p = &a[len];5462 p[len-2] = 0;5392 if (!fgets(p, len, f))5463 if (!fgets(p, (int) len, f))5464 break;5465 if (p[len-2] == 0) {5466 len += strlen(p);5467 break;
7 unmodified lines
5475}54765477int stb_fullpath(char *abs, int abs_size, char *rel)5478{5408 #ifdef _MSC_VER5479 #ifdef _WIN325480 return _fullpath(abs, rel, abs_size) != NULL;5481 #else5482 if (rel[0] == '/' || rel[0] == '~') {5483 if ((int) strlen(rel) >= abs_size)5484 return 0;5414 strcpy(abs,rel);5485 stb_p_strcpy_s(abs,65536,rel);5486 return STB_TRUE;5487 } else {5488 int n;5489 getcwd(abs, abs_size);5490 n = strlen(abs);5491 if (n+(int) strlen(rel)+2 <= abs_size) {5492 abs[n] = '/';5422 strcpy(abs+n+1, rel);5493 stb_p_strcpy_s(abs+n+1, 65536,rel);5494 return STB_TRUE;5495 } else {5496 return STB_FALSE;5497 }
6 unmodified lines
5504 char buf1[1024],buf2[1024];5505 int n1,n2, res=0;55065507 while (1) {5437 n1 = fread(buf1, 1, sizeof(buf1), f);5438 n2 = fread(buf2, 1, sizeof(buf2), g);5508 n1 = (int) fread(buf1, 1, sizeof(buf1), f);5509 n2 = (int) fread(buf2, 1, sizeof(buf2), g);5510 res = memcmp(buf1,buf2,stb_min(n1,n2));5511 if (res)5512 break;5513 if (n1 != n2) {
55 unmodified lines
5569 char *name;5570 int errors;5571} stb__file_data;55725502static FILE *stb__open_temp_file(char *temp_name, char *src_name, char *mode)5573static FILE *stb__open_temp_file(char *temp_name, char *src_name, const char *mode)5574{5504 int p;5575 size_t p;5576#ifdef _MSC_VER5577 int j;5578#endif5579 FILE *f;
9 unmodified lines
5589 #ifdef _MSC_VER5590 // try multiple times to make a temp file... just in5591 // case some other process makes the name first5592 for (j=0; j < 32; ++j) {5522 strcpy(temp_name+p, "stmpXXXXXX");5523 if (stb_mktemp(temp_name) == NULL)5593 stb_p_strcpy_s(temp_name+p, 65536, "stmpXXXXXX");5594 if (!stb_p_mktemp(temp_name))5595 return 0;55965526 f = fopen(temp_name, mode);5597 f = stb_p_fopen(temp_name, mode);5598 if (f != NULL)5599 break;5600 }5601 #else5602 {5532 strcpy(temp_name+p, "stmpXXXXXX");5603 stb_p_strcpy_s(temp_name+p, 65536, "stmpXXXXXX");5604 #ifdef __MINGW32__5534 int fd = open(mktemp(temp_name), O_RDWR);5605 int fd = open(stb_p_mktemp(temp_name), O_RDWR);5606 #else5607 int fd = mkstemp(temp_name);5608 #endif5609 if (fd == -1) return NULL;
8 unmodified lines
5618 return f;5619}562056215551FILE * stb_fopen(char *filename, char *mode)5622FILE * stb_fopen(char *filename, const char *mode)5623{5624 FILE *f;5625 char name_full[4096];5626 char temp_full[sizeof(name_full) + 12];
13 unmodified lines
5640 if (f != NULL) {5641 stb__file_data *d = (stb__file_data *) malloc(sizeof(*d));5642 if (!d) { assert(0); /* NOTREACHED */fclose(f); return NULL; }5643 if (stb__files == NULL) stb__files = stb_ptrmap_create();5573 d->temp_name = strdup(temp_full);5574 d->name = strdup(name_full);5644 d->temp_name = stb_p_strdup(temp_full);5645 d->name = stb_p_strdup(name_full);5646 d->errors = 0;5647 stb_ptrmap_add(stb__files, f, d);5648 return f;5649 }
121 unmodified lines
5771 buf_size = sizeof(raw_buffer);5772 }57735774 while (!feof(f)) {5704 int n = fread(buffer, 1, buf_size, f);5775 size_t n = fread(buffer, 1, buf_size, f);5776 if (n != 0)5777 fwrite(buffer, 1, n, g);5778 }5779
167 unmodified lines
5947}59485949void stb_fput_string(FILE *f, char *s)5950{5880 int len = strlen(s);5881 stb_fput_varlenu(f, len);5951 size_t len = strlen(s);5952 stb_fput_varlenu(f, (unsigned int) len);5953 fwrite(s, 1, len, f);5954}59555956// inverse of the above algorithm
9 unmodified lines
5966}59675968char *stb_strdup(char *str, void *pool)5969{5899 int len = strlen(str);5970 size_t len = strlen(str);5971 char *p = stb_malloc_string(pool, len+1);5901 strcpy(p, str);5972 stb_p_strcpy_s(p, len+1, str);5973 return p;5974}59755976// strip the trailing '/' or '\\' from a directory so we can refer to it
47 unmodified lines
6024}60256026char **stb_getopt(int *argc, char **argv)6027{5957 return stb_getopt_param(argc, argv, "");6028 return stb_getopt_param(argc, argv, (char*) "");6029}60306031char **stb_getopt_param(int *argc, char **argv, char *param)6032{
9 unmodified lines
6042 argv[j++] = argv[i++];6043 break;6044 } else if (argv[i][1] == '-') {6045 // copy argument through including initial '-' for clarity5975 stb_arr_push(opts, strdup(argv[i]));6046 stb_arr_push(opts, stb_p_strdup(argv[i]));6047 } else {6048 int k;6049 char *q = argv[i]; // traverse options list6050 for (k=1; q[k]; ++k) {6051 char *s;6052 if (strchr(param, q[k])) { // does it take a parameter?6053 char *t = &q[k+1], z = q[k];5983 int len=0;6054 size_t len=0;6055 if (*t == 0) {6056 if (i == *argc-1) { // takes a parameter, but none found6057 *argc = 0;6058 stb_getopt_free(opts);6059 return NULL;6060 }6061 t = argv[++i];6062 } else5992 k += strlen(t);6063 k += (int) strlen(t);6064 len = strlen(t);6065 s = (char *) malloc(len+2);6066 if (!s) return NULL;6067 s[0] = z;5997 strcpy(s+1, t);6068 stb_p_strcpy_s(s+1, len+2, t);6069 } else {6070 // no parameter6071 s = (char *) malloc(2);6072 if (!s) return NULL;
127 unmodified lines
6200 if ( stb_snprintf(buffer, sizeof(buffer), "%s%s", with_slash, name) < 0 )6201 break;6202 if (buffer[0] == '.' && buffer[1] == '/')6203 p = buffer+2;6133 stb_arr_push(results, strdup(p));6204 stb_arr_push(results, stb_p_strdup(p));6205 }6206 }6207 }6208 }
27 unmodified lines
6236 if (stb_arr_len(sofar) >= stb__rec_max) return sofar;62376238 files = stb_readdir_files_mask(dir, filespec);6239 stb_arr_for(p, files) {6169 stb_arr_push(sofar, strdup(*p));6240 stb_arr_push(sofar, stb_p_strdup(*p));6241 if (stb_arr_len(sofar) >= stb__rec_max) break;6242 }6243 stb_readdir_free(files);6244 if (stb_arr_len(sofar) >= stb__rec_max) return sofar;
70 unmodified lines
6315stb_dirtree2 *stb_dirtree2_from_files_relative(char *src, char **filelist, int count)6316{6317 char buffer1[1024];6318 int i;6248 int dlen = strlen(src), elen;6319 int dlen = (int) strlen(src), elen;6320 stb_dirtree2 *d;6321 char ** descendents = NULL;6322 char ** files = NULL;6323 char *s;
24 unmodified lines
6348 // now create a record6349 d = (stb_dirtree2 *) malloc(sizeof(*d));6350 d->files = files;6351 d->subdirs = NULL;6281 d->fullpath = strdup(src);6352 d->fullpath = stb_p_strdup(src);6353 s = stb_strrchr2(d->fullpath, '/', '\\');6354 if (s)6355 ++s;6356 else
6 unmodified lines
6363 char buffer2[1024];6364 char *s = descendents[i] + elen, *t;6365 t = stb_strchr2(s, '/', '\\');6366 assert(t);6296 stb_strncpy(buffer2, descendents[i], t-descendents[i]+1);6367 stb_strncpy(buffer2, descendents[i], (int) (t-descendents[i]+1));6368 if (stb_stricmp(buffer1, buffer2)) {6369 stb_dirtree2 *t = stb_dirtree2_from_files_relative(buffer2, descendents, stb_arr_len(descendents));6370 assert(t != NULL);6300 strcpy(buffer1, buffer2);6371 stb_p_strcpy_s(buffer1, sizeof(buffer1), buffer2);6372 stb_arr_push(d->subdirs, t);6373 }6374 }6375 d->num_subdir = stb_arr_len(d->subdirs);
2 unmodified lines
6378}63796380stb_dirtree2 *stb_dirtree2_from_files(char **filelist, int count)6381{6311 return stb_dirtree2_from_files_relative("", filelist, count);6382 return stb_dirtree2_from_files_relative((char*) "", filelist, count);6383}6384#endif63856386//////////////////////////////////////////////////////////////////////////////
202 unmodified lines
6589 h[3] = 0x10325476;6590 h[4] = 0xc3d2e1f0;65916592 for(;;) {6522 int n = fread(buffer, 1, 64, f);6593 size_t n = fread(buffer, 1, 64, f);6594 if (n == 64) {6595 stb__sha1(buffer, h);6596 length += n;6597 } else {
73 unmodified lines
6671// we'll never actually use this?66726673#if defined(_WIN32)66746604STB_EXTERN void * stb_reg_open(char *mode, char *where); // mode: "rHKLM" or "rHKCU" or "w.."6675STB_EXTERN void * stb_reg_open(const char *mode, const char *where); // mode: "rHKLM" or "rHKCU" or "w.."6676STB_EXTERN void stb_reg_close(void *reg);6606STB_EXTERN int stb_reg_read(void *zreg, char *str, void *data, unsigned long len);6607STB_EXTERN int stb_reg_read_string(void *zreg, char *str, char *data, int len);6608STB_EXTERN void stb_reg_write(void *zreg, char *str, void *data, unsigned long len);6609STB_EXTERN void stb_reg_write_string(void *zreg, char *str, char *data);6677STB_EXTERN int stb_reg_read(void *zreg, const char *str, void *data, unsigned long len);6678STB_EXTERN int stb_reg_read_string(void *zreg, const char *str, char *data, int len);6679STB_EXTERN void stb_reg_write(void *zreg, const char *str, const void *data, unsigned long len);6680STB_EXTERN void stb_reg_write_string(void *zreg, const char *str, const char *data);66816682#if defined(STB_DEFINE) && !defined(STB_NO_REGISTRY)66836684#define STB_HAS_REGISTRY
27 unmodified lines
6712#define STB__HKEY_CURRENT_USER 0x800000016713#define STB__HKEY_LOCAL_MACHINE 0x800000026714#endif67156645void *stb_reg_open(char *mode, char *where)6716void *stb_reg_open(const char *mode, const char *where)6717{6718 long res;6719 HKEY base;6720 HKEY zreg;
22 unmodified lines
6743#define STB__REG_SZ 16744#define STB__REG_BINARY 36745#define STB__REG_DWORD 467466676int stb_reg_read(void *zreg, char *str, void *data, unsigned long len)6747int stb_reg_read(void *zreg, const char *str, void *data, unsigned long len)6748{6749 unsigned long type;6750 unsigned long alen = len;6751 if (0 == RegQueryValueExA((HKEY) zreg, str, 0, &type, (unsigned char *) data, &len))
4 unmodified lines
6756 }6757 return 0;6758}67596689void stb_reg_write(void *zreg, char *str, void *data, unsigned long len)6760void stb_reg_write(void *zreg, const char *str, const void *data, unsigned long len)6761{6762 if (zreg)6763 RegSetValueExA((HKEY) zreg, str, 0, STB__REG_BINARY, (const unsigned char *) data, len);6764}67656695int stb_reg_read_string(void *zreg, char *str, char *data, int len)6766int stb_reg_read_string(void *zreg, const char *str, char *data, int len)6767{6768 if (!stb_reg_read(zreg, str, data, len)) return 0;6769 data[len-1] = 0; // force a 0 at the end of the string no matter what6770 return 1;6771}67726702void stb_reg_write_string(void *zreg, char *str, char *data)6773void stb_reg_write_string(void *zreg, const char *str, const char *data)6774{6775 if (zreg)6705 RegSetValueExA((HKEY) zreg, str, 0, STB__REG_SZ, (const unsigned char *) data, strlen(data)+1);6776 RegSetValueExA((HKEY) zreg, str, 0, STB__REG_SZ, (const unsigned char *) data, (int) strlen(data)+1);6777}6778#endif // STB_DEFINE6779#endif // _WIN326780
7 unmodified lines
67886789#ifndef STB_NO_STB_STRINGS6790typedef struct stb_cfg_st stb_cfg;67916721STB_EXTERN stb_cfg * stb_cfg_open(char *config, char *mode); // mode = "r", "w"6792STB_EXTERN stb_cfg * stb_cfg_open(char *config, const char *mode); // mode = "r", "w"6793STB_EXTERN void stb_cfg_close(stb_cfg *cfg);6794STB_EXTERN int stb_cfg_read(stb_cfg *cfg, char *key, void *value, int len);6795STB_EXTERN void stb_cfg_write(stb_cfg *cfg, char *key, void *value, int len);6796STB_EXTERN int stb_cfg_read_string(stb_cfg *cfg, char *key, char *value, int len);
16 unmodified lines
6813 char *loaded_file; // this needs to be freed6814 FILE *f; // write the data to this file on close6815};68166746static char *stb__cfg_sig = "sTbCoNfIg!\0\0";6817static const char *stb__cfg_sig = "sTbCoNfIg!\0\0";6818static char stb__cfg_dir[512];6819STB_EXTERN void stb_cfg_set_directory(char *dir)6820{6750 strcpy(stb__cfg_dir, dir);6821 stb_p_strcpy_s(stb__cfg_dir, sizeof(stb__cfg_dir), dir);6822}68236753STB_EXTERN stb_cfg * stb_cfg_open(char *config, char *mode)6824STB_EXTERN stb_cfg * stb_cfg_open(char *config, const char *mode)6825{6826 size_t len;6827 stb_cfg *z;6828 char file[512];6829 if (mode[0] != 'r' && mode[0] != 'w') return NULL;68306831 if (!stb__cfg_dir[0]) {6832 #ifdef _WIN326762 strcpy(stb__cfg_dir, "c:/stb");6833 stb_p_strcpy_s(stb__cfg_dir, sizeof(stb__cfg_dir), "c:/stb");6834 #else6835 strcpy(stb__cfg_dir, "~/.stbconfig");6836 #endif6837
7 unmodified lines
6845 }6846 #endif6847 }68486778 sprintf(file, "%s/%s.cfg", stb__cfg_dir, config);6849 stb_p_sprintf(file stb_p_size(sizeof(file)), "%s/%s.cfg", stb__cfg_dir, config);68506851 z = (stb_cfg *) stb_malloc(0, sizeof(*z));6852 z->data = NULL;6853
17 unmodified lines
6871 }6872 }68736874 if (mode[0] == 'w')6804 z->f = fopen(file, "wb");6875 z->f = stb_p_fopen(file, "wb");6876 else6877 z->f = NULL;68786879 return z;
5 unmodified lines
6885 int i;6886 // write the file out6887 fwrite(stb__cfg_sig, 12, 1, z->f);6888 for (i=0; i < stb_arr_len(z->data); ++i) {6818 stb_int16 n = strlen(z->data[i].key)+1;6889 stb_int16 n = (stb_int16) strlen(z->data[i].key)+1;6890 fwrite(&n, 2, 1, z->f);6891 fwrite(z->data[i].key, n, 1, z->f);6892 fwrite(&z->data[i].value_len, 4, 1, z->f);6893 fwrite(z->data[i].value, z->data[i].value_len, 1, z->f);
56 unmodified lines
6950}69516952void stb_cfg_write_string(stb_cfg *z, char *key, char *value)6953{6883 stb_cfg_write(z, key, value, strlen(value)+1);6954 stb_cfg_write(z, key, value, (int) strlen(value)+1);6955}6956#endif69576958//////////////////////////////////////////////////////////////////////////////
82 unmodified lines
70417042static void stb__dirtree_save_db(char *filename, stb_dirtree *data, char *root)7043{7044 int i, num_dirs_final=0, num_files_final;6974 char *info = root ? root : "";7045 char *info = root ? root : (char*)"";7046 int *remap;6976 FILE *f = fopen(filename, "wb");7047 FILE *f = stb_p_fopen(filename, "wb");7048 if (!f) return;70497050 fwrite(stb__signature, sizeof(stb__signature), 1, f);7051 fwrite(info, strlen(info)+1, 1, f);
39 unmodified lines
7091static void stb__dirtree_load_db(char *filename, stb_dirtree *data, char *dir)7092{7093 char sig[2048];7094 int i,n;7024 FILE *f = fopen(filename, "rb");7095 FILE *f = stb_p_fopen(filename, "rb");70967097 if (!f) return;70987099 data->string_pool = stb_malloc(0,1);
48 unmodified lines
71487149 has_slash = (path[0] && path[strlen(path)-1] == '/'); 71507151 // @TODO: do this concatenation without using swprintf to avoid this mess:7081#if defined(_MSC_VER) && _MSC_VER < 14007152#if (defined(_MSC_VER) && _MSC_VER < 1400) // || (defined(__clang__))7153 // confusingly, Windows Kits\10 goes down this path?!?7154 if (has_slash)7155 swprintf(full_path, L"%s*", stb__from_utf8(path));7156 else7157 swprintf(full_path, L"%s/*", stb__from_utf8(path));
18 unmodified lines
7176 stb__dirtree_add_dir(path, last_time, active);7177 n = stb_arr_lastn(active->dirs);71787179 if (stb__showfile) printf("[");7108 if( (hFile = _wfindfirsti64( (wchar_t *) full_path, &c_file )) != -1L ) {7180 if( (hFile = (long) _wfindfirsti64( (wchar_t *) full_path, &c_file )) != -1L ) {7181 do {7182 if (stb__showfile) printf(")");7183 if (c_file.attrib & _A_SUBDIR) {7184 // ignore subdirectories starting with '.', e.g. "." and ".."
1 unmodified line
7186 char *new_path = (char *) full_path;7187 char *temp = stb__to_utf8((stb__wchar *) c_file.name);71887189 if (has_slash)7118 sprintf(new_path, "%s%s", path, temp);7190 stb_p_sprintf(new_path stb_p_size(sizeof(full_path)), "%s%s", path, temp);7191 else7120 sprintf(new_path, "%s/%s", path, temp);7192 stb_p_sprintf(new_path stb_p_size(sizeof(full_path)), "%s/%s", path, temp);71937194 if (stb__dircount_mask) {7195 ++stb__dircount;7196 if (!(stb__dircount & stb__dircount_mask)) {7197 char dummy_path[128], *pad;7198 stb_strncpy(dummy_path, new_path, sizeof(dummy_path)-1);7199 if (strlen(dummy_path) > 96) {7128 strcpy(dummy_path+96/2-1, "...");7129 strcpy(dummy_path+96/2+2, new_path + strlen(new_path)-96/2+2);7200 stb_p_strcpy_s(dummy_path+96/2-1,128, "...");7201 stb_p_strcpy_s(dummy_path+96/2+2,128, new_path + strlen(new_path)-96/2+2);7202 }7203 pad = dummy_path + strlen(dummy_path);7204 while (pad < dummy_path+98)7205 *pad++ = ' ';7206 *pad = 0;7207 printf("%s\r", dummy_path);7208 #if 07209 if (hlog == 0) {7138 hlog = fopen("c:/x/temp.log", "w");7210 hlog = stb_p_fopen("c:/x/temp.log", "w");7211 fprintf(hlog, "%s\n", dummy_path);7212 }7213 #endif7214 }
113 unmodified lines
7328 db.string_pool = NULL;7329 db.files = NULL;7330 db.dirs = NULL;73317260 stripped_dir = stb_strip_final_slash(strdup(dir));7332 stripped_dir = stb_strip_final_slash(stb_p_strdup(dir));73337334 if (cache_file != NULL)7335 stb__dirtree_load_db(cache_file, &db, stripped_dir);7336 else if (stb__showfile)
37 unmodified lines
7374 char dir_lower[1024];7375 char cache_file[1024],*s;7376 if (cache_dir == NULL)7377 return stb_dirtree_get_with_file(dir, NULL);7306 strcpy(dir_lower, dir);7378 stb_p_strcpy_s(dir_lower, sizeof(dir_lower), dir);7379 stb_tolower(dir_lower);7308 stb_sha1(sha, (unsigned char *) dir_lower, strlen(dir_lower));7309 strcpy(cache_file, cache_dir);7380 stb_sha1(sha, (unsigned char *) dir_lower, (unsigned int) strlen(dir_lower));7381 stb_p_strcpy_s(cache_file, sizeof(cache_file), cache_dir);7382 s = cache_file + strlen(cache_file);7311 if (s[-1] != '//' && s[-1] != '\\') *s++ = '/';7312 strcpy(s, "dirtree_");7383 if (s[-1] != '/' && s[-1] != '\\') *s++ = '/';7384 stb_p_strcpy_s(s, sizeof(cache_file), "dirtree_");7385 s += strlen(s);7386 for (i=0; i < 8; ++i) {7315 char *hex = "0123456789abcdef";7387 char *hex = (char*)"0123456789abcdef";7388 stb_uint z = sha[i];7389 *s++ = hex[z >> 4];7390 *s++ = hex[z & 15];7391 }7320 strcpy(s, ".bin");7392 stb_p_strcpy_s(s, sizeof(cache_file), ".bin");7393 return stb_dirtree_get_with_file(dir, cache_file);7394}73957396stb_dirtree *stb_dirtree_get(char *dir)7397{7398 char cache_dir[256];7327 strcpy(cache_dir, "c:/bindata");7399 stb_p_strcpy_s(cache_dir, sizeof(cache_dir), "c:/bindata");7400 #ifdef STB_HAS_REGISTRY7401 {7402 void *reg = stb_reg_open("rHKLM", "Software\\SilverSpaceship\\stb");7403 if (reg) {
22 unmodified lines
7426}74277428void stb_dirtree_db_read(stb_dirtree *target, char *filename, char *dir)7429{7358 char *s = stb_strip_final_slash(strdup(dir));7430 char *s = stb_strip_final_slash(stb_p_strdup(dir));7431 target->dirs = 0;7432 target->files = 0;7433 target->string_pool = 0;7434 stb__dirtree_load_db(filename, target, s);
26 unmodified lines
7461{7462 void *p;7463 char *file;7464 int line;7393 int size;7465 size_t size;7466} stb_malloc_record;74677468#ifndef STB_MALLOC_HISTORY_COUNT7469#define STB_MALLOC_HISTORY_COUNT 50 // 800 bytes
21 unmodified lines
7491 return n;7492 }7493}74947423int stb_wrapper_allocsize(void *p)7495size_t stb_wrapper_allocsize(void *p)7496{7497 int n = stb__hashfind(p);7498 if (n < 0) return 0;7499 return stb__allocations[n].size;
10 unmodified lines
7510 }7511 return -1;7512}75137442static void stb__add_alloc(void *p, int sz, char *file, int line);7514static void stb__add_alloc(void *p, size_t sz, char *file, int line);7515static void stb__grow_alloc(void)7516{7517 int i,old_num = stb__alloc_size;7518 stb_malloc_record *old = stb__allocations;
21 unmodified lines
7540 assert(stb__hashfind(old[i].p) >= 0);7541 stb__realloc_raw(old, 0);7542}75437472static void stb__add_alloc(void *p, int sz, char *file, int line)7544static void stb__add_alloc(void *p, size_t sz, char *file, int line)7545{7546 stb_uint32 h;7547 int n;7548 if (stb__alloc_count >= stb__alloc_limit)
24 unmodified lines
7573 stb__allocations[n].p = STB_DEL;7574 --stb__alloc_count;7575}75767505void stb_wrapper_malloc(void *p, int sz, char *file, int line)7577void stb_wrapper_malloc(void *p, size_t sz, char *file, int line)7578{7579 if (!p) return;7580 stb__add_alloc(p,sz,file,line);7581}
44 unmodified lines
7626 stb__alloc_history[n].file, stb__alloc_history[n].line);7627 stb_fatal("Checked unknown block %p");7628}76297558void stb_wrapper_realloc(void *p, void *q, int sz, char *file, int line)7630void stb_wrapper_realloc(void *p, void *q, size_t sz, char *file, int line)7631{7632 int n;7633 if (p == NULL) { stb_wrapper_malloc(q, sz, file, line); return; }7634 if (q == NULL) return; // nothing happened
22 unmodified lines
7657 }7658 }7659}76607589void stb_wrapper_listall(void (*func)(void *ptr, int sz, char *file, int line))7661void stb_wrapper_listall(void (*func)(void *ptr, size_t sz, char *file, int line))7662{7663 int i;7664 for (i=0; i < stb__alloc_size; ++i)7665 if (stb__allocations[i].p > STB_DEL)
3 unmodified lines
76697670void stb_wrapper_dump(char *filename)7671{7672 int i;7601 FILE *f = fopen(filename, "w");7673 FILE *f = stb_p_fopen(filename, "w");7674 if (!f) return;7675 for (i=0; i < stb__alloc_size; ++i)7676 if (stb__allocations[i].p > STB_DEL)7677 fprintf(f, "%p %7d - %4d %s\n",7606 stb__allocations[i].p , stb__allocations[i].size,7678 stb__allocations[i].p , (int) stb__allocations[i].size,7679 stb__allocations[i].line, stb__allocations[i].file);7680}7681#endif // STB_DEFINE7682
717 unmodified lines
8400 if (seed)8401 old_seed = stb_srandLCG(seed);8402 a = (char *) p + (n-1) * sz;84038332 for (i=n; i > 1; --i) {8404 for (i=(int) n; i > 1; --i) {8405 int j = stb_randLCG() % i;8406 stb_swap(a, (char *) p + j * sz, sz);8407 a -= sz;8408 }
2 unmodified lines
8411}84128413void stb_reverse(void *p, size_t n, size_t sz)8414{8343 int i,j = n-1;8415 size_t i,j = n-1;8416 for (i=0; i < j; ++i,--j) {8417 stb_swap((char *) p + i * sz, (char *) p + j * sz, sz);8418 }8419}
653 unmodified lines
9073STB_EXTERN int stb_matcher_find(stb_matcher *m, char *str);9074STB_EXTERN void stb_matcher_free(stb_matcher *f);90759076STB_EXTERN stb_matcher *stb_lex_matcher(void);9005STB_EXTERN int stb_lex_item(stb_matcher *m, char *str, int result);9006STB_EXTERN int stb_lex_item_wild(stb_matcher *matcher, char *regex, int result);9077STB_EXTERN int stb_lex_item(stb_matcher *m, const char *str, int result);9078STB_EXTERN int stb_lex_item_wild(stb_matcher *matcher, const char *regex, int result);9079STB_EXTERN int stb_lex(stb_matcher *m, char *str, int *len);908090819082
144 unmodified lines
9227 while (s) {9228 int z;9229 // need to allow for non-writeable strings... assume they're small9230 if (s - last < 256) {9159 stb_strncpy(buffer, last, s-last+1);9231 stb_strncpy(buffer, last, (int) (s-last+1));9232 z = stb__wildmatch_raw2(buffer, candidate, search, insensitive);9233 } else {9234 *s = 0;9235 z = stb__wildmatch_raw2(last, candidate, search, insensitive);
195 unmodified lines
9431 ++regex, invert = 1;94329433 // leading ] is special9434 if (*regex == ']') {9363 flags[']'] = 1;9435 flags[(int) ']'] = 1;9436 ++regex;9437 }9438 while (*regex != ']') {9439 stb_uint a;
230 unmodified lines
96709671 return matcher;9672}96739602int stb_lex_item(stb_matcher *matcher, char *regex, int result)9674int stb_lex_item(stb_matcher *matcher, const char *regex, int result)9675{9676 char *z;9677 stb_uint16 end;96789607 z = stb__reg_parse_alt(matcher, matcher->start_node, regex, &end);9679 z = stb__reg_parse_alt(matcher, matcher->start_node, (char*) regex, &end);96809681 if (z == NULL)9682 return 0;9683
2 unmodified lines
9686 matcher->nodes[(int) end].goal = result;9687 return 1;9688}96899618int stb_lex_item_wild(stb_matcher *matcher, char *regex, int result)9690int stb_lex_item_wild(stb_matcher *matcher, const char *regex, int result)9691{9692 char *z;9693 stb_uint16 end;96949623 z = stb__wild_parse(matcher, matcher->start_node, regex, &end);9695 z = stb__wild_parse(matcher, matcher->start_node, (char*) regex, &end);96969697 if (z == NULL)9698 return 0;9699
228 unmodified lines
99289929 // special case for lex: need _longest_ match, so notice goal9930 // state without stopping9931 if (node <= STB__DFA_MGOAL) {9860 match_length = str - (stb_uint8 *) str_c;9932 match_length = (int) (str - (stb_uint8 *) str_c);9933 node = -(node - STB__DFA_MGOAL);9934 match_result = node;9935 continue;9936 }
50 unmodified lines
9987 newstates = stb__eps_closure(m, newstates);9988 // if it's a goal state, then that's all there is to it9989 if (stb__clear_goalcheck(m, newstates)) {9990 if (m->does_lex) {9919 match_length = str - (stb_uint8 *) str_c;9991 match_length = (int) (str - (stb_uint8 *) str_c);9992 node = stb__get_dfa_node(m,newstates);9993 match_result = node;9994 node = -node + STB__DFA_MGOAL;9995 trans = m->dfa; // could have gotten realloc()ed
54 unmodified lines
10050 int i = mapping[z];10051 stb_matcher_free(matchers[i]);10052 free(regexp_cache[i]);10053 regexps[i] = regex;9982 regexp_cache[i] = strdup(regex);10054 regexp_cache[i] = stb_p_strdup(regex);10055 matchers[i] = stb_regex_matcher(regex);10056 }10057 } else {10058 int i,n;
9 unmodified lines
10068 free(mapping); mapping = NULL;10069 return -1;10070 }10071 stb_arr_push(regexps, regex);10000 stb_arr_push(regexp_cache, strdup(regex));10072 stb_arr_push(regexp_cache, stb_p_strdup(regex));10073 stb_arr_push(matchers, stb_regex_matcher(regex));10074 stb_perfect_destroy(&p);10075 n = stb_perfect_create(&p, (unsigned int *) (char **) regexps, stb_arr_len(regexps));10076 mapping = (unsigned short *) realloc(mapping, n * sizeof(*mapping));
71 unmodified lines
1014810149static void stb__introspect_filename(char *buffer, char *path)10150{10151 #if STB_INTROSPECT_CPP10080 sprintf(buffer, "%s/stb_introspect.cpp", path);10152 stb_p_sprintf(buffer stb_p_size(9999), "%s/stb_introspect.cpp", path);10153 #else10082 sprintf(buffer, "%s/stb_introspect.c", path);10154 stb_p_sprintf(buffer stb_p_size(9999), "%s/stb_introspect.c", path);10155 #endif10156}1015710158static void stb__introspect_compute(char *path, char *file)
1 unmodified line
10160 int i;10161 char ** include_list = NULL;10162 char ** introspect_list = NULL;10163 FILE *f;10092 f = fopen(file, "w");10164 f = stb_p_fopen(file, "w");10165 if (!f) return;1016610167 fputs("// if you get compiler errors, change the following 0 to a 1:\n", f);10168 fputs("#define STB_INTROSPECT_INVALID 0\n\n", f);
90 unmodified lines
10259 break;10260 }10261 }10262 if (found)10191 stb_arr_push(introspect_h, strdup(all[i]));10263 stb_arr_push(introspect_h, stb_p_strdup(all[i]));10264 free(z);10265 }10266 }10267 stb_readdir_free(all);
195 unmodified lines
10463{10464 unsigned int n;10465 char *q;10466 unsigned char *p;10395 FILE *f = fopen(filename, "rb"); if (f == NULL) return NULL;10467 FILE *f = stb_p_fopen(filename, "rb"); if (f == NULL) return NULL;10468 fseek(f, 0, SEEK_END);10469 n = ftell(f);10470 fseek(f, 0, SEEK_SET);10471 p = (unsigned char * ) malloc(n); if (p == NULL) return NULL;
109 unmodified lines
10581static void stb_out3(stb_uint v) { stb_out(v >> 16); stb_out(v >> 8); stb_out(v); }10582static void stb_out4(stb_uint v) { stb_out(v >> 24); stb_out(v >> 16);10583 stb_out(v >> 8 ); stb_out(v); }1058410513static void outliterals(stb_uchar *in, int numlit)10585static void outliterals(stb_uchar *in, ptrdiff_t numlit)10586{10587 while (numlit > 65536) {10588 outliterals(in,65536);10589 in += 65536;10590 numlit -= 65536;10591 }1059210593 if (numlit == 0) ;10522 else if (numlit <= 32) stb_out (0x000020 + numlit-1);10523 else if (numlit <= 2048) stb_out2(0x000800 + numlit-1);10524 else /* numlit <= 65536) */ stb_out3(0x070000 + numlit-1);10594 else if (numlit <= 32) stb_out (0x000020 + (stb_uint) numlit-1);10595 else if (numlit <= 2048) stb_out2(0x000800 + (stb_uint) numlit-1);10596 else /* numlit <= 65536) */ stb_out3(0x070000 + (stb_uint) numlit-1);1059710598 if (stb__out) {10599 memcpy(stb__out,in,numlit);10600 stb__out += numlit;
56 unmodified lines
10657 stb_uchar *t;10658 int best = 2, dist=0;1065910660 if (q+65536 > end)10589 match_max = end-q;10661 match_max = (stb_uint) (end-q);10662 else10591 match_max = 65536;10663 match_max = 65536u;1066410665 #define stb__nc(b,d) ((d) <= window && ((b) > 9 || stb_not_crap(b,d)))1066610667 #define STB__TRY(t,p) /* avoid retrying a match we already tried */ \10596 if (p ? dist != q-t : 1) \10597 if ((m = stb_matchlen(t, q, match_max)) > best) \10598 if (stb__nc(m,q-(t))) \10599 best = m, dist = q - (t)10668 if (p ? dist != (int) (q-t) : 1) \10669 if ((m = (int) stb_matchlen(t, q, match_max)) > best)\10670 if (stb__nc(m,(int) (q-(t)))) \10671 best = m, dist = (int) (q - (t))1067210673 // rather than search for all matches, only try 4 candidate locations,10674 // chosen based on 4 different hash functions of different lengths.10675 // this strategy is inspired by LZO; hashing is unrolled here using the
54 unmodified lines
10730 if (q-start < length)10731 q = start+length;1073210733 // the literals are everything from lit_start to q10662 *pending_literals = (q - lit_start);10734 *pending_literals = (int) (q - lit_start);1073510664 stb__running_adler = stb_adler32(stb__running_adler, start, q - start);10665 return q - start;10736 stb__running_adler = stb_adler32(stb__running_adler, start, (int) (q - start));10737 return (int) (q - start);10738}1073910740static int stb_compress_inner(stb_uchar *input, stb_uint length)10741{
36 unmodified lines
10778 stb__outfile = NULL;1077910780 stb_compress_inner(input, length);1078110710 return stb__out - out;10782 return (stb_uint) (stb__out - out);10783}1078410785int stb_compress_tofile(char *filename, char *input, unsigned int length)10786{
1 unmodified line
10788 //char *buffer = (char *) malloc(maxlen);10789 //int blen = stb_compress((stb_uchar*)buffer, (stb_uchar*)input, length);10790 10791 stb__out = NULL;10720 stb__outfile = fopen(filename, "wb");10792 stb__outfile = stb_p_fopen(filename, "wb");10793 if (!stb__outfile) return 0;1079410795 stb__outbytes = 0;10796
35 unmodified lines
10832}1083310834static void stb_out_backpatch(size_t id, stb_uint value)10835{10764 10765 stb_uchar data[4] = { (stb_uchar)(value >> 24), (stb_uchar)(value >> 16), (stb_uchar)(value >> 8), (stb_uchar)(value) };10836 stb_uchar data[4] = { (stb_uchar)(value >> 24), (stb_uchar)(value >> 16), (stb_uchar)(value >> 8), (stb_uchar)(value) };10837 if (stb__out) {10838 memcpy((void *) id, data, 4);10839 } else {10840 stb_uint where = ftell(stb__outfile);10770 fseek(stb__outfile, id, SEEK_SET);10841 fseek(stb__outfile, (long) id, SEEK_SET);10842 fwrite(data, 4, 1, stb__outfile);10843 fseek(stb__outfile, where, SEEK_SET);10844 }10845}
51 unmodified lines
10897 stb_out(0x57); stb_out(0xbc); stb_out2(0);1089810899 stb_out4(0); // 64-bit length requires 32-bit leading 01090010830 xtb.length_id = stb_out_backpatch_id();10901 xtb.length_id = (int) stb_out_backpatch_id();10902 stb_out4(0); // we don't know the output length yet1090310904 stb_out4(stb__window);10905
177 unmodified lines
1108311084// FILE * implementation11085static int stb__fgetbyte(stbfile *f) { return fgetc(f->f); }11086static int stb__fputbyte(stbfile *f, int ch) { return fputc(ch, f->f)==0; }11016static unsigned int stb__fgetdata(stbfile *f, void *buffer, unsigned int len) { return fread(buffer,1,len,f->f); }11017static unsigned int stb__fputdata(stbfile *f, void *buffer, unsigned int len) { return fwrite(buffer,1,len,f->f); }11018static unsigned int stb__fsize(stbfile *f) { return stb_filelen(f->f); }11019static unsigned int stb__ftell(stbfile *f) { return ftell(f->f); }11087static unsigned int stb__fgetdata(stbfile *f, void *buffer, unsigned int len) { return (unsigned int) fread(buffer,1,len,f->f); }11088static unsigned int stb__fputdata(stbfile *f, void *buffer, unsigned int len) { return (unsigned int) fwrite(buffer,1,len,f->f); }11089static unsigned int stb__fsize(stbfile *f) { return (unsigned int) stb_filelen(f->f); }11090static unsigned int stb__ftell(stbfile *f) { return (unsigned int) ftell(f->f); }11091static void stb__fbackpatch(stbfile *f, unsigned int where, void *buffer, unsigned int len)11092{11093 fseek(f->f, where, SEEK_SET);11094 fwrite(buffer, 1, len, f->f);
31 unmodified lines
1112611127static unsigned int stb__bgetdata(stbfile *s, void *buffer, unsigned int len)11128{11129 if (s->indata + len > s->inend)11059 len = s->inend - s->indata;11130 len = (unsigned int) (s->inend - s->indata);11131 memcpy(buffer, s->indata, len);11132 s->indata += len;11133 return len;11134}11064static unsigned int stb__bsize(stbfile *s) { return s->inend - s->buffer; }11065static unsigned int stb__btell(stbfile *s) { return s->indata - s->buffer; }11135static unsigned int stb__bsize(stbfile *s) { return (unsigned int) (s->inend - s->buffer); }11136static unsigned int stb__btell(stbfile *s) { return (unsigned int) (s->indata - s->buffer); }1113711138static void stb__bclose(stbfile *s)11139{11140 if (s->various)
32 unmodified lines
11173}1117411175stbfile *stb_open(char *filename, char *mode)11176{11106 FILE *f = fopen(filename, mode);11177 FILE *f = stb_p_fopen(filename, mode);11178 stbfile *s;11179 if (f == NULL) return NULL;11180 s = stb_openf(f);11181 if (s)
243 unmodified lines
11425stbfile *stb_arith_decode_close(stb_arith *a)11426{11427 return a->output;11428}1135811359// this is a simple power-of-two based model -- using11360// power of two means we need one divide per decode,11361// not two.11362#define POW2_LIMIT 1211363stb_arith_symstate *stb_arith_state_create(int num_sym)11364{11365 stb_arith_symstate *s = (stb_arith_symstate *) malloc(sizeof(*s) + (num_sym-1) * sizeof(s->data[0])); 11366 if (s) {11367 int i, cf, cf_next, next;11368 int start_freq, extra;11369 s->num_sym = num_sym;11370 s->pow2 = 4;11371 while (s->pow2 < 15 && (1 << s->pow2) < 3*num_sym) {11372 ++s->pow2;11373 }11374 start_freq = (1 << s->pow2) / num_sym;11375 assert(start_freq >= 1);11376 extra = (1 << s->pow2) % num_sym;11377 // now set up the initial stats1137811379 if (s->pow2 < POW2_LIMIT)11380 next = 0;11381 else11382 next = 1;1138311384 cf = cf_next = 0;11385 for (i=0; i < extra; ++i) {11386 s->data[i].cumfreq = cf;11387 s->data[i].samples = next;11388 cf += start_freq+1;11389 cf_next += next;11390 }11391 for (; i < num_sym; ++i) {11392 s->data[i].cumfreq = cf;11393 s->data[i].samples = next;11394 cf += start_freq;11395 cf_next += next;11396 }11397 assert(cf == (1 << s->pow2));11398 // now, how long should we go until we have 2 << s->pow2 samples?11399 s->countdown = (2 << s->pow2) - cf - cf_next;11400 }11401 return s;11402}1140311404static void stb_arith_state_rescale(stb_arith_symstate *s)11405{11406 if (s->pow2 < POW2_LIMIT) {11407 int pcf, cf, cf_next, next, i;11408 ++s->pow2;11409 if (s->pow2 < POW2_LIMIT)11410 next = 0;11411 else11412 next = 1;11413 cf = cf_next = 0;11414 pcf = 0;11415 for (i=0; i < s->num_sym; ++i) {11416 int sample = s->data[i].cumfreq - pcf + s->data[i].samples;11417 s->data[i].cumfreq = cf;11418 cf += sample;11419 s->data[i].samples = next;11420 cf_next += next;11421 }11422 assert(cf == (1 << s->pow2));11423 s->countdown = (2 << s->pow2) - cf - cf_next;11424 } else {11425 int pcf, cf, cf_next, i;11426 cf = cf_next = 0;11427 pcf = 0;11428 for (i=0; i < s->num_sym; ++i) {11429 int sample = (s->data[i].cumfreq - pcf + s->data[i].samples) >> 1;11430 s->data[i].cumfreq = cf;11431 cf += sample;11432 s->data[i].samples = 1;11433 cf_next += 1;11434 }11435 assert(cf == (1 << s->pow2)); // this isn't necessarily true, due to rounding down!11436 s->countdown = (2 << s->pow2) - cf - cf_next;11437 }11438}1143911440void stb_arith_encode_byte(stb_arith *a, int byte)11441{11442}1144311444int stb_arith_decode_byte(stb_arith *a)11445{11446 return -1;11447}11429#endif1143011431//////////////////////////////////////////////////////////////////////////////11432//
948 unmodified lines
12381{12382 int res;12383 stb__io_init();12384 // do memory allocation outside of mutex12404 if (fname) fname = strdup(fname);12385 if (fname) fname = stb_p_strdup(fname);12386 stb_mutex_begin(stb__diskio_mutex);12387 {12388 stb__disk_command *dc = &stb__dc_queue[stb__dc_offset];12389 dc->filename = fname;
437 unmodified lines
12827char *stb_sstrdup(char *s)12828{12829 int n = strlen(s);12830 char *p = (char *) stb_smalloc(n+1);12850 if (p) strcpy(p,s);12831 if (p) stb_p_strcpy_s(p,n+1,s);12832 return p;12833}12834#endif // STB_DEFINE12835
37 unmodified lines
12873char *stb__get_sourcefile_path(char *file)12874{12875 static char filebuf[512];12876 if (stb__source_path) {12896 sprintf(filebuf, "%s/%s", stb__source_path, file);12877 stb_p_sprintf(filebuf stb_p_size(sizeof(filebuf)), "%s/%s", stb__source_path, file);12878 if (stb_fexists(filebuf)) return filebuf;12879 }1288012881 if (stb_fexists(file)) return file;1288212902 sprintf(filebuf, "../%s", file);12883 stb_p_sprintf(filebuf stb_p_size(sizeof(filebuf)), "../%s", file);12884 if (!stb_fexists(filebuf)) return filebuf;1288512886 return file; 12887}
110 unmodified lines
12998 if (s == NULL || !stb_fexists(s)) return 0;12999 f = (stb__FileEntry *) malloc(sizeof(*f));13000 f->timestamp = stb_ftimestamp(s);13001 f->file_data = stb_stringfile(s, &f->file_len);13021 f->filename = strdup(s); // cache the full path13002 f->filename = stb_p_strdup(s); // cache the full path13003 f->entries = NULL;13004 f->line_index = 0;13005 stb_arr_setlen(f->line_index, f->file_len);13006 memset(f->line_index, 0xff, stb_arr_storage(f->line_index));
455 unmodified lines
13462{13463 stua_obj a;13464 char temp[4096], *x;13465 va_list v; va_start(v,z); vsprintf(temp, z, v); va_end(v);13485 x = strdup(temp);13466 x = stb_p_strdup(temp);13467 a = stua_box(STU___error, x, strlen(x));13468 stu__flow = FLOW_error;13469 stu__flow_val = a;13470 return stua_nil;
982 unmodified lines