Пример #1
0
int main(int argc, char **argv)
{
    struct icon icon;
    int32_t bpl = 0;
    int i;
    unsigned char *maskp, bm, *pp;

    if (argc<2) {
        Bfprintf(stderr, "generateicon <picture file>\n");
        return 1;
    }

    memset(&icon, 0, sizeof(icon));

    kpzload(argv[1], (intptr_t*)&icon.pixels, (int32_t*)&bpl, (int32_t*)&icon.width, (int32_t*)&icon.height);
    if (!icon.pixels) {
        Bfprintf(stderr, "Failure loading %s\n", argv[1]);
        return 1;
    }

    if (bpl != icon.width * 4) {
        Bfprintf(stderr, "bpl != icon.width * 4\n");
        Bfree(icon.pixels);
        return 1;
    }

    icon.mask = (unsigned char *)Bcalloc(icon.height, (icon.width+7)/8);
    if (!icon.mask) {
        Bfprintf(stderr, "Out of memory\n");
        Bfree(icon.pixels);
        return 1;
    }

    maskp = icon.mask;
    bm = 1;
    pp = (unsigned char *)icon.pixels;
    for (i=0; i<icon.height*icon.width; i++) {
        if (bm == 0) {
            bm = 1;
            maskp++;
        }

        {
            unsigned char c = pp[0];
            pp[0] = pp[2];
            pp[2] = c;
        }
        if (pp[3] > 0) *maskp |= bm;

        bm <<= 1;
        pp += 4;
    }

    writeicon(stdout, &icon);

    Bfree(icon.pixels);
    Bfree(icon.mask);

    return 0;
}
Пример #2
0
void RemoveGroup(int32_t crcval)
{
    struct grpfile *grp;

    for (grp = foundgrps; grp; grp=grp->next)
    {
        if (grp->crcval == crcval)
        {
            if (grp == foundgrps)
                foundgrps = grp->next;
            else
            {
                struct grpfile *fg;

                for (fg = foundgrps; fg; fg=fg->next)
                {
                    if (fg->next == grp)
                    {
                        fg->next = grp->next;
                        break;
                    }
                }
            }

            Bfree((char *)grp->name);
            Bfree(grp);

            RemoveGroup(crcval);

            break;
        }
    }
}
Пример #3
0
strtoIxL(CONST char *s, char **sp, void *a, void *b)
#endif
{
	static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
	Long exp[2];
	Bigint *B[2];
	int k, rv[2];
	ULong *L = (ULong *)a, *M = (ULong *)b;

	B[0] = Balloc(1);
	B[0]->wds = 2;
	k = strtoIg(s, sp, &fpi, exp, B, rv);
	ULtoxL(L, B[0]->x, exp[0], rv[0]);
	Bfree(B[0]);
	if (B[1]) {
		ULtoxL(M, B[1]->x, exp[1], rv[1]);
		Bfree(B[1]);
		}
	else {
		M[0] = L[0];
		M[1] = L[1];
		M[2] = L[2];
		}
	return k;
	}
Пример #4
0
int32_t SCRIPT_Load(char * filename)
{
    int32_t s,h,l;
    char *b;

    h = SafeOpenRead(filename, filetype_binary);
    l = SafeFileLength(h)+1;
    b = (char *)Bmalloc(l);
    SafeRead(h,b,l-1);
    b[l-1] = '\n';	// JBF 20040111: evil nasty hack to trick my evil nasty parser
    SafeClose(h);

    s = SCRIPT_Init(filename);
    if (s<0)
    {
        Bfree(b);
        return -1;
    }

    SCRIPT_ParseBuffer(s,b,l);

    Bfree(b);

    return s;
}
Пример #5
0
strtoId(CONST char *s, char **sp, double *f0, double *f1)
#endif
{
	static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
	Long exp[2];
	Bigint *B[2];
	int k, rv[2];

	B[0] = Balloc(1);
	if (B[0] == NULL)
		return STRTOG_NoMemory;
	B[0]->wds = 2;
	k = strtoIg(s, sp, &fpi, exp, B, rv);
	if (k == STRTOG_NoMemory)
		return k;
	ULtod((ULong*)f0, B[0]->x, exp[0], rv[0]);
	Bfree(B[0]);
	if (B[1]) {
		ULtod((ULong*)f1, B[1]->x, exp[1], rv[1]);
		Bfree(B[1]);
		}
	else {
		((ULong*)f1)[0] = ((ULong*)f0)[0];
		((ULong*)f1)[1] = ((ULong*)f0)[1];
		}
	return k;
	}
Пример #6
0
void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.cfg
{
    int32_t i;
    BFILE *fp;
    char *ptr = Xstrdup(setupfilename);
    char tempbuf[128];

    if (!Bstrcmp(setupfilename, SETUPFILENAME))
        Bsprintf(tempbuf, "settings.cfg");
    else Bsprintf(tempbuf, "%s_settings.cfg", strtok(ptr, "."));

    fp = Bfopen(tempbuf, "wt");

    if (fp)
    {
        Bfprintf(fp,"// this file is automatically generated by EDuke32\n");
        Bfprintf(fp,"// these settings take precedence over your main cfg file\n");
        Bfprintf(fp,"// do not modify if you lack common sense\n");

        Bfprintf(fp,"unbindall\n");

        for (i=0; i<MAXBOUNDKEYS; i++)
            if (CONTROL_KeyIsBound(i))
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_KeyBinds[i].key,
                CONTROL_KeyBinds[i].repeat?"":" norepeat",CONTROL_KeyBinds[i].cmdstr);

        for (i=0; i<MAXMOUSEBUTTONS; i++)
            if (CONTROL_MouseIsBound(i))
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_MouseBinds[i].key,
                CONTROL_MouseBinds[i].repeat?"":" norepeat",CONTROL_MouseBinds[i].cmdstr);

        OSD_WriteAliases(fp);

        if (g_crosshairSum && g_crosshairSum != DefaultCrosshairColors.r+(DefaultCrosshairColors.g<<1)+(DefaultCrosshairColors.b<<2))
            Bfprintf(fp, "crosshaircolor %d %d %d\n", CrosshairColors.r, CrosshairColors.g, CrosshairColors.b);

        OSD_WriteCvars(fp);

        Bfclose(fp);

        if (!Bstrcmp(setupfilename, SETUPFILENAME))
            OSD_Printf("Wrote settings.cfg\n");
        else OSD_Printf("Wrote %s_settings.cfg\n",ptr);

        Bfree(ptr);
        return;
    }

    if (!Bstrcmp(setupfilename, SETUPFILENAME))
        OSD_Printf("Error writing settings.cfg: %s\n", strerror(errno));
    else OSD_Printf("Error writing %s_settings.cfg: %s\n",ptr,strerror(errno));

    Bfree(ptr);
}
Пример #7
0
void FreeGroups(void)
{
    while (foundgrps)
    {
        Bfree((char *)foundgrps->filename);
        grpfile_t * const fg = foundgrps->next;
        Bfree(foundgrps);
        foundgrps = fg;
    }

    FreeGameList();
}
Пример #8
0
static void FreeGameList(void)
{
    while (listgrps)
    {
        Bfree(listgrps->name);
        Bfree(listgrps->scriptname);
        Bfree(listgrps->defname);

        grpinfo_t * const fg = listgrps->next;
        Bfree(listgrps);
        listgrps = fg;
    }
}
Пример #9
0
BDIR *Bopendir(const char *name)
{
    BDIR_real *dirr;
#ifdef _MSC_VER
    char *t, *tt;
    t = (char *)Bmalloc(Bstrlen(name) + 1 + 4);
    if (!t)
        return NULL;
#endif

    dirr = (BDIR_real *)Bmalloc(sizeof(BDIR_real) + Bstrlen(name));
    if (!dirr)
    {
#ifdef _MSC_VER
        Bfree(t);
#endif
        return NULL;
    }

#ifdef _MSC_VER
    Bstrcpy(t, name);
    tt = t + Bstrlen(name) - 1;
    while (*tt == ' ' && tt > t) tt--;
    if (*tt != '/' && *tt != '\\')
        *(++tt) = '/';
    *(++tt) = '*';
    *(++tt) = '.';
    *(++tt) = '*';
    *(++tt) = 0;

    dirr->dir = _findfirst(t, &dirr->fid);
    Bfree(t);
    if (dirr->dir == -1)
    {
        Bfree(dirr);
        return NULL;
    }
#else
    dirr->dir = opendir(name);
    if (dirr->dir == NULL)
    {
        Bfree(dirr);
        return NULL;
    }
#endif

    dirr->status = 0;
    Bstrcpy(dirr->name, name);

    return (BDIR *)dirr;
}
Пример #10
0
void FreeGroups(void)
{
    struct grpfile *fg;

    while (foundgrps)
    {
        fg = foundgrps->next;
        Bfree((char *)foundgrps->name);
        Bfree(foundgrps);
        foundgrps = fg;
    }

    FreeGameList();
}
Пример #11
0
//
// multiply by m and add a
//
static Bigint * multadd(AllocatedBlock ** aBlocks, Bigint ** freelist, Bigint *b, int m, int a)
{
	int i, wds;

	UINT_32 *x;
	UINT_64 carry, y;
	Bigint *b1;

	wds = b->wds;
	x = b->x;
	i = 0;
	carry = a;
	do
	{
		y = *x * (UINT_64)m + carry;
		carry = y >> 32;
		*x++ = (UINT_32)y & FFFFFFFF;
	}
	while(++i < wds);

	if (carry)
	{
		if (wds >= b->maxwds)
		{
			b1 = Balloc(aBlocks, freelist, b->k+1);
			Bcopy(b1, b);
			Bfree(freelist, b);
			b = b1;
		}
		b->x[wds++] = (UINT_32)carry;
		b->wds = wds;
	}

return b;
}
Пример #12
0
void SCRIPT_PutString
   (
   int32 scripthandle,
   const char * sectionname,
   const char * entryname,
   const char * string
   )
{
	char *raw,*p;
    const char *q;
	int len = 3;
	if (!string) string = "";

	for (q=string; *q; q++) {
		if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;
		else if (*q >= ' ') len++;
	}
	p = raw = Bmalloc(len);
	*(p++) = '"';
	for (q=string; *q; q++) {
		if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; }
		else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; }
		else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; }
		else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; }
		else if (*q >= ' ') *(p++) = *q;
	}
	*(p++) = '"';
	*p=0;
	
	SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw);
	Bfree(raw);
}
Пример #13
0
static Bigint *multadd(Bigint *b, int m, int a, Stack_alloc *alloc)
{
  int i, wds;
  ULong *x;
  ULLong carry, y;
  Bigint *b1;

  wds= b->wds;
  x= b->p.x;
  i= 0;
  carry= a;
  do
  {
    y= *x * (ULLong)m + carry;
    carry= y >> 32;
    *x++= (ULong)(y & FFFFFFFF);
  }
  while (++i < wds);
  if (carry)
  {
    if (wds >= b->maxwds)
    {
      b1= Balloc(b->k+1, alloc);
      Bcopy(b1, b);
      Bfree(b, alloc);
      b= b1;
    }
    b->p.x[wds++]= (ULong) carry;
    b->wds= wds;
  }
  return b;
}
Пример #14
0
/**
 * Basic test for reallocation
 */
void test_Brealloc(void)
{
    UBFH *p_ub = NULL;

    p_ub=Balloc(1, 30);
    assert_not_equal(p_ub, NULL);

    assert_equal(Badd(p_ub, T_STRING_FLD, BIG_TEST_STRING, 0), FAIL);
    assert_equal(Berror, BNOSPACE);

    /* Now reallocate, space should be bigger! */
    p_ub=Brealloc(p_ub, 1, strlen(BIG_TEST_STRING)+1+2/* align */);
    assert_not_equal(p_ub, NULL);
    assert_equal(Badd(p_ub, T_STRING_FLD, BIG_TEST_STRING, 0), SUCCEED);
    
    /* should not allow to reallocate to 0! */
    assert_equal(Brealloc(p_ub, 1, 0), NULL);
    assert_equal(Berror, BEINVAL);

    /* should be bigger than existing. */
    assert_equal(Brealloc(p_ub, 1, strlen(BIG_TEST_STRING)+1), NULL);
    assert_equal(Berror, BEINVAL);

    assert_equal(SUCCEED, Bfree(p_ub));

}
Пример #15
0
int32_t ScanGroups(void)
{
    CACHE1D_FIND_REC *srch;
    struct grpcache *fg, *fgg;

    initprintf("Searching for game data...\n");

    LoadGameList();
    LoadGroupsCache();

    srch = klistpath("/", "*.grp", CACHE1D_FIND_FILE);
    ProcessGroups(srch);
    klistfree(srch);

    srch = klistpath("/", "*.ssi", CACHE1D_FIND_FILE);
    ProcessGroups(srch);
    klistfree(srch);

    FreeGroupsCache();

    for (grpfile_t *grp = foundgrps; grp; grp=grp->next)
    {
        if (grp->type->dependency)
        {
            if (FindGroup(grp->type->dependency) == NULL) // couldn't find dependency
            {
                //initprintf("removing %s\n", grp->name);
                RemoveGroup(grp);
                grp = foundgrps;
                // start from the beginning so we can remove anything that depended on this grp
                continue;
            }
        }
    }

    if (usedgrpcache)
    {
        int32_t i = 0;
        FILE *fp;
        fp = fopen(GRPCACHEFILE, "wt");
        if (fp)
        {
            for (fg = usedgrpcache; fg; fg=fgg)
            {
                fgg = fg->next;
                fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval);
                Bfree(fg);
                i++;
            }
            fclose(fp);
        }
//        initprintf("Found %d recognized GRP %s.\n",i,i>1?"files":"file");

        return 0;
    }

    initprintf("Found no recognized game data!\n");

    return 0;
}
Пример #16
0
static int32_t read_whole_file(const char *fn, char **retbufptr)
{
    int32_t fid, flen, i;
    char *buf;

    *retbufptr = NULL;

    fid = kopen4load(fn, 0);  // TODO: g_loadFromGroupOnly, kopen4loadfrommod ?

    if (fid < 0)
        return 1;

    flen = kfilelength(fid);
    if (flen == 0)
        return 5;

    buf = (char *)Xmalloc(flen+1);

    i = kread(fid, buf, flen);
    kclose(fid);

    if (i != flen)
    {
        Bfree(buf);
        return 2;
    }

    buf[flen] = 0;
    *retbufptr = buf;

    return 0;
}
Пример #17
0
/*
= RTS_AddFile
=
= All files are optional, but at least one file must be found
= Files with a .rts extension are wadlink files with multiple lumps
= Other files are single lumps with the base filename for the lump name
*/
static int32_t RTS_AddFile(const char *filename)
{
    wadinfo_t  header;
    int32_t i, handle, length, startlump;
    filelump_t *fileinfo, *fileinfoo;

    // read the entire file in
    //      FIXME: shared opens

    handle = kopen4loadfrommod(filename, 0);
    if (handle < 0)
    {
        initprintf("RTS file \"%s\" was not found\n",filename);
        return -1;
    }

    startlump = rts_numlumps;

    // WAD file
    i = kread(handle, &header, sizeof(header));
    if (i != sizeof(header) || Bmemcmp(header.identification, "IWAD", 4))
    {
        initprintf("RTS file \"%s\" too short or doesn't have IWAD id\n", filename);
        kclose(handle);
        return -1;
    }

    header.numlumps = B_LITTLE32(header.numlumps);
    header.infotableofs = B_LITTLE32(header.infotableofs);

    length = header.numlumps*sizeof(filelump_t);
    fileinfo = fileinfoo = (filelump_t *)Xmalloc(length);

    klseek(handle, header.infotableofs, SEEK_SET);
    kread(handle, fileinfo, length);

    {
        lumpinfo_t *lump_p = (lumpinfo_t *)Xrealloc(
            rts_lumpinfo, (rts_numlumps + header.numlumps)*sizeof(lumpinfo_t));

        rts_lumpinfo = lump_p;
    }

    rts_numlumps += header.numlumps;

    for (i=startlump; i<rts_numlumps; i++, fileinfo++)
    {
        lumpinfo_t *lump = &rts_lumpinfo[i];

        lump->handle = handle;  // NOTE: cache1d-file is not closed!
        lump->position = B_LITTLE32(fileinfo->filepos);
        lump->size = B_LITTLE32(fileinfo->size);

        Bstrncpy(lump->name, fileinfo->name, 8);
    }

    Bfree(fileinfoo);

    return 0;
}
Пример #18
0
void SCRIPT_FreeSection(ScriptSectionType * section)
{
    ScriptEntryType *e;

    if (!section) return;
    if (!section->entries) return;

    while (section->entries->nextentry != section->entries)
    {
        e = section->entries->nextentry;
        Bfree(section->entries);
        section->entries = e;
    }

    Bfree(section->entries);
    Bfree(section->name);
}
Пример #19
0
 // load the color palette
 for (i = 0; i < 768; i += 3)
 {
     anim->pal[i+2] = (*buffer++)>>2;
     anim->pal[i+1] = (*buffer++)>>2;
     anim->pal[i] = (*buffer++)>>2;
     buffer++;
 }
Пример #20
0
static int osdcmd_glinfo(const osdfuncparm_t *parm)
{
	char *s,*t,*u,i;
	
	if (bpp == 8) {
		OSD_Printf("glinfo: Not in OpenGL mode.\n");
		return OSDCMD_OK;
	}
	
	OSD_Printf("OpenGL Information:\n"
	           " Version:  %s\n"
		   " Vendor:   %s\n"
		   " Renderer: %s\n"
		   " Maximum anisotropy:      %.1f%s\n"
		   " BGRA textures:           %s\n"
		   " Non-x^2 textures:        %s\n"
		   " Texure compression:      %s\n"
		   " Clamp-to-edge:           %s\n"
		   " Multisampling:           %s\n"
		   " Nvidia multisample hint: %s\n"
		   " Multitexturing:          %s\n"
		   " Env combine extension:   %s\n"
		   " Extensions:\n",
		   	glinfo.version,
			glinfo.vendor,
			glinfo.renderer,
			glinfo.maxanisotropy, glinfo.maxanisotropy>1.0?"":" (no anisotropic filtering)",
			glinfo.bgra ? "supported": "not supported",
			glinfo.texnpot ? "supported": "not supported",
			glinfo.texcompr ? "supported": "not supported",
			glinfo.clamptoedge ? "supported": "not supported",
			glinfo.multisample ? "supported": "not supported",
			glinfo.nvmultisamplehint ? "supported": "not supported",
			glinfo.multitex ? "supported": "not supported",
			glinfo.envcombine ? "supported": "not supported"
		);

	s = Bstrdup(glinfo.extensions);
	if (!s) OSD_Printf(glinfo.extensions);
	else {
		i = 0; t = u = s;
		while (*t) {
			if (*t == ' ') {
				if (i&1) {
					*t = 0;
					OSD_Printf("   %s\n",u);
					u = t+1;
				}
				i++;
			}
			t++;
		}
		if (i&1) OSD_Printf("   %s\n",u);
		Bfree(s);
	}
	
	return OSDCMD_OK;
}
Пример #21
0
static void FreeGroupsCache(void)
{
    while (grpcache)
    {
        struct grpcache * const fg = grpcache->next;
        Bfree(grpcache);
        grpcache = fg;
    }
}
Пример #22
0
void loadwaves(void)
{
	long fil, dawaversionum, i, tmp;
	long wavleng[MAXWAVES], repstart[MAXWAVES], repleng[MAXWAVES], finetune[MAXWAVES];
	char *p;

	fil = kopen4load("WAVES.KWV", 0);

	if (fil != -1) {
		kread(fil, &dawaversionum, 4); dawaversionum = B_LITTLE32(dawaversionum);
		if (dawaversionum != 0) { kclose(fil); return; }

		kread(fil, &numwaves, 4); numwaves = B_LITTLE32(numwaves);
		for (i=0; i<numwaves; i++) {
			kread(fil, &instname[i][0], 16);
			kread(fil, &wavleng[i], 4);  wavleng[i]  = B_LITTLE32(wavleng[i]);
			kread(fil, &repstart[i], 4); repstart[i] = B_LITTLE32(repstart[i]);
			kread(fil, &repleng[i], 4);  repleng[i]  = B_LITTLE32(repleng[i]);
			kread(fil, &finetune[i], 4); finetune[i] = B_LITTLE32(finetune[i]);
		}
	} else {
		dawaversionum = 0;
		numwaves = 0;
	}

	for (i=numwaves; i<MAXWAVES; i++) {
		memset(&instname[i][0], 0, 16);
		wavleng[i] = 0;
		repstart[i] = 0;
		repleng[i] = 0;
		finetune[i] = 0;
		samples[i] = NULL;
	}

	if (fil == -1) return;

#if 0
	for (i=0; i<numwaves; i++) {
		if (repleng[i]) tmp = FSOUND_LOOP_NORMAL;
		else tmp = FSOUND_LOOP_OFF;
		samples[i] = FSOUND_Sample_Alloc(FSOUND_FREE, wavleng[i], tmp, 11025, 255, 128, 1);
		if (!samples[i]) continue;

		p = (char*)Bmalloc(wavleng[i]);
		kread(fil,p,wavleng[i]);
		FSOUND_Sample_Upload(samples[i], p, FSOUND_8BITS | FSOUND_MONO | FSOUND_UNSIGNED);
		Bfree(p);

		if (repleng[i]) FSOUND_Sample_SetLoopPoints(samples[i], repstart[i], repstart[i]+repleng[i]);
	}
#endif

	kclose(fil);

	printOSD("Loaded %d waves\n", numwaves);
}
Пример #23
0
static void FreeGameList(void)
{
    struct grpfile *fg;

    while (listgrps)
    {
        fg = listgrps->next;
        Bfree(listgrps->name);

        if (listgrps->scriptname)
            Bfree(listgrps->scriptname);

        if (listgrps->defname)
            Bfree(listgrps->defname);

        Bfree(listgrps);
        listgrps = fg;
    }
}
Пример #24
0
static void RemoveGroup(grpfile_t *igrp)
{
    for (grpfile_t *prev = NULL, *grp = foundgrps; grp; grp=grp->next)
    {
        if (grp == igrp)
        {
            if (grp == foundgrps)
                foundgrps = grp->next;
            else
                prev->next = grp->next;

            Bfree((char *)grp->filename);
            Bfree(grp);

            return;
        }

        prev = grp;
    }
}
Пример #25
0
freedtoa(char *s)
#endif
{
	Bigint *b = (Bigint *)((int *)s - 1);
	b->maxwds = 1 << (b->k = *(int*)b);
	Bfree(b);
#ifndef MULTIPLE_THREADS
	if (s == dtoa_result)
		dtoa_result = 0;
#endif
	}
Пример #26
0
//
// OSD_Cleanup() -- Cleans up the on-screen display
//
void OSD_Cleanup(void)
{
	symbol_t *s;

	for (; symbols; symbols=s) {
		s=symbols->next;
		Bfree(symbols);
	}

	osdinited=0;
}
Пример #27
0
strtoIf(CONST char *s, char **sp, float *f0, float *f1)
#endif
{
	static FPI fpi = { 24, 1-127-24+1,  254-127-24+1, 1, SI };
	Long exp[2];
	Bigint *B[2];
	int k, rv[2];

	B[0] = Balloc(0);
	B[0]->wds = 1;
	k = strtoIg(s, sp, &fpi, exp, B, rv);
	ULtof((ULong*)f0, B[0]->x, exp[0], rv[0]);
	Bfree(B[0]);
	if (B[1]) {
		ULtof((ULong*)f1, B[1]->x, exp[1], rv[1]);
		Bfree(B[1]);
		}
	else
		*(ULong*)f1 = *(ULong*)f0;
	return k;
	}
Пример #28
0
// -1: alloc failure
// 0: success
// 1: didn't find file
// 2: couldn't read whole file
// 3: syntax error in lua file
// 4: runtime error while executing lua file
// 5: empty file
int L_RunOnce(L_State *estate, const char *fn)
{
    char *buf;
    int32_t i = read_whole_file(fn, &buf);

    if (i != 0)
        return i;

    int const retval = L_RunString(estate, buf, -1, fn);
    Bfree(buf);
    return retval;
}
Пример #29
0
int32_t Bclosedir(BDIR *dir)
{
    BDIR_real *dirr = (BDIR_real *)dir;

#ifdef _MSC_VER
    _findclose(dirr->dir);
#else
    closedir(dirr->dir);
#endif
    Bfree(dirr);

    return 0;
}
Пример #30
0
void SCRIPT_PutDoubleString
(
    int32_t scripthandle,
    char * sectionname,
    char * entryname,
    char * string1,
    char * string2
)
{
    char *raw,*q,*p;
    int32_t len = 6;
    if (!string1) string1 = "";
    if (!string2) string2 = "";

    for (q=string1; *q; q++)
    {
        if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;
        else if (*q >= ' ') len++;
    }
    for (q=string2; *q; q++)
    {
        if (*q == '\r' || *q == '\n' || *q == '\t' || *q == '\\' || *q == '"') len+=2;
        else if (*q >= ' ') len++;
    }
    p = raw = Bmalloc(len);
    *(p++) = '"';
    for (q=string1; *q; q++)
    {
        if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; }
        else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; }
        else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; }
        else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; }
        else if (*q >= ' ') *(p++) = *q;
    }
    *(p++) = '"';
    *(p++) = ' ';
    *(p++) = '"';
    for (q=string2; *q; q++)
    {
        if (*q == '\r') { *(p++) = '\\'; *(p++) = 'r'; }
        else if (*q == '\n') { *(p++) = '\\'; *(p++) = 'n'; }
        else if (*q == '\t') { *(p++) = '\\'; *(p++) = 't'; }
        else if (*q == '\\' || *q == '"') { *(p++) = '\\'; *(p++) = *q; }
        else if (*q >= ' ') *(p++) = *q;
    }
    *(p++) = '"';
    *p=0;

    SCRIPT_AddEntry(scripthandle, sectionname, entryname, raw);
    Bfree(raw);
}