コード例 #1
0
ファイル: imInt.c プロジェクト: SvenDowideit/clearlinux
static Bool
_XimSetIMStructureList(
    Xim		  im)
{
    register int  i;
    Xim		 *xim;

    if(!(_XimCurrentIMlist)) {
	if(!(_XimCurrentIMlist = Xmalloc(sizeof(Xim))))
	    return False;
	_XimCurrentIMlist[0] = im;
	_XimCurrentIMcount   = 1;
    }
    else {
	for(i = 0; i < _XimCurrentIMcount; i++) {
	    if(!( _XimCurrentIMlist[i])) {
		_XimCurrentIMlist[i] = im;
		break;
	    }
	}
	if(i >= _XimCurrentIMcount) {
	    if(!(xim = Xrealloc(_XimCurrentIMlist,
					 ((i + 1) * sizeof(Xim)))))
		return False;
	    _XimCurrentIMlist			  = xim;
	    _XimCurrentIMlist[_XimCurrentIMcount] = im;
	    _XimCurrentIMcount++;
	}
    }
    return True;
}
コード例 #2
0
ファイル: rts.c プロジェクト: SilkyPantsDan/eduke32
/*
= 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;
}
コード例 #3
0
ファイル: xalloc.c プロジェクト: narenas/nx-libs
void *
XNFrealloc (pointer ptr, unsigned long amount)
{
    if (( ptr = (pointer)Xrealloc( ptr, amount ) ) == NULL)
    {
        FatalError( "Out of memory" );
    }
    return ptr;
}
コード例 #4
0
ファイル: animlib.c プロジェクト: dahlor/Duke3DS
// <length> is the file size, for consistency checking.
int32_t ANIM_LoadAnim(const uint8_t *buffer, int32_t length)
{
    int32_t i;

    length -= sizeof(lpfileheader)+128+768;
    if (length < 0)
        return -1;

    anim = (anim_t *)Xrealloc(anim, sizeof(anim_t));

    anim->curlpnum = 0xffff;
    anim->currentframe = -1;

    // this just modifies the data in-place instead of copying it elsewhere now
    anim->lpheader = (lpfileheader *)(anim->buffer = (uint8_t *)buffer);

    anim->lpheader->id              = B_LITTLE32(anim->lpheader->id);
    anim->lpheader->maxLps          = B_LITTLE16(anim->lpheader->maxLps);
    anim->lpheader->nLps            = B_LITTLE16(anim->lpheader->nLps);
    anim->lpheader->nRecords        = B_LITTLE32(anim->lpheader->nRecords);
    anim->lpheader->maxRecsPerLp    = B_LITTLE16(anim->lpheader->maxRecsPerLp);
    anim->lpheader->lpfTableOffset  = B_LITTLE16(anim->lpheader->lpfTableOffset);
    anim->lpheader->contentType     = B_LITTLE32(anim->lpheader->contentType);
    anim->lpheader->width           = B_LITTLE16(anim->lpheader->width);
    anim->lpheader->height          = B_LITTLE16(anim->lpheader->height);
    anim->lpheader->nFrames         = B_LITTLE32(anim->lpheader->nFrames);
    anim->lpheader->framesPerSecond = B_LITTLE16(anim->lpheader->framesPerSecond);

    length -= anim->lpheader->nLps * sizeof(lp_descriptor);
    if (length < 0)
        return -2;

    buffer += sizeof(lpfileheader)+128;

    // load the color palette
    for (i = 0; i < 768; i += 3)
    {
        anim->pal[i+2] = *buffer++;
        anim->pal[i+1] = *buffer++;
        anim->pal[i] = *buffer++;
        buffer++;
    }

    // set up large page descriptors
    anim->LpArray = (lp_descriptor *)buffer;

    // theoretically we should be able to play files with more than 256 frames now
    // assuming the utilities to create them can make them that way
    for (i = 0; i < anim->lpheader->nLps; i++)
    {
        anim->LpArray[i].baseRecord = B_LITTLE16(anim->LpArray[i].baseRecord);
        anim->LpArray[i].nRecords   = B_LITTLE16(anim->LpArray[i].nRecords);
        anim->LpArray[i].nBytes     = B_LITTLE16(anim->LpArray[i].nBytes);
    }

    return 0;
}
コード例 #5
0
ファイル: xalloc.c プロジェクト: BackupTheBerlios/dri-ex-svn
pointer
XNFrealloc(pointer p, unsigned long n)
{
    pointer r;

    r = Xrealloc(p, n);
    if (!r)
	FatalError("XNFrealloc failed\n");
    return r;
   
}
コード例 #6
0
ファイル: array.c プロジェクト: triplekill/orchids
void
array_add(array_t *array, void *element)
{
  if (array->length == array->size)
    {
      array->size += array->grow;
      array->array = Xrealloc(array->array, array->size * sizeof (void *));
    }

  array->array[ array->length++ ] = element;
}
コード例 #7
0
ファイル: Quarks.c プロジェクト: scriptum/cppcheck-libs
static XrmAllocMoreQuartToAtomTable()
{
    unsigned	size;

    maxQuarks += QUARKQUANTUM;
    size = (unsigned) maxQuarks * sizeof(XrmAtom);
    if (quarkToAtomTable == (XrmAtom *)NULL)
	quarkToAtomTable = (XrmAtom *) Xmalloc(size);
    else
	quarkToAtomTable =
		(XrmAtom *) Xrealloc((char *) quarkToAtomTable, size);
}
コード例 #8
0
ファイル: RaA32.c プロジェクト: Magister/x11rdp_xorg71
int
XdmcpReallocARRAY32 (ARRAY32Ptr array, int length)
{
    CARD32Ptr	newData;

    newData = (CARD32Ptr) Xrealloc (array->data, length * sizeof (CARD32));
    if (!newData)
	return FALSE;
    array->length = length;
    array->data = newData;
    return TRUE;
}
コード例 #9
0
ファイル: lcDB.c プロジェクト: thekeenant/libx11-android
static Bool
realloc_parse_info(
    int len)
{
    char *p;

    parse_info.bufMaxSize = BUFSIZE * ((parse_info.bufsize + len)/BUFSIZE + 1);
    p = (char *)Xrealloc(parse_info.buf, parse_info.bufMaxSize);
    if (p == NULL)
        return False;
    parse_info.buf = p;

    return True;
}
コード例 #10
0
ファイル: voxmodel.c プロジェクト: SilkyPantsDan/eduke32
static void putvox(int32_t x, int32_t y, int32_t z, int32_t col)
{
    if (vnum >= vmax)
    {
        vmax = max(vmax<<1, 4096);
        vcol = (voxcol_t *)Xrealloc(vcol, vmax*sizeof(voxcol_t));
    }

    z += x*yzsiz + y*voxsiz.z;

    vcol[vnum].p = z; z = (z*214013)&vcolhashsizm1;
    vcol[vnum].c = col;
    vcol[vnum].n = vcolhashead[z]; vcolhashead[z] = vnum++;
}
コード例 #11
0
ファイル: mgquery.c プロジェクト: plbogen/CSDL
static void 
Add_Stats (S_Type typ, char *name, char *fmt,...)
{
  char buf[1024];
  va_list args;
  va_start (args, fmt);
  vsprintf (buf, fmt, args);
  if (Stats)
    Stats = Xrealloc (Stats, (++NumStats) * sizeof (*Stats));
  else
    Stats = Xmalloc ((++NumStats) * sizeof (*Stats));
  Stats[NumStats - 1].typ = typ;
  Stats[NumStats - 1].name = Xstrdup (name);
  Stats[NumStats - 1].text = Xstrdup (buf);
}
コード例 #12
0
ファイル: texcache.c プロジェクト: clobber/eduke32
int32_t texcache_loadoffsets(void)
{
    int32_t foffset, fsize, i;
    char *fname;

    scriptfile *script;

    Bstrcpy(ptempbuf,TEXCACHEFILE);
    Bstrcat(ptempbuf,".cache");
    script = scriptfile_fromfile(ptempbuf);

    if (!script) return -1;

    while (!scriptfile_eof(script))
    {
        if (scriptfile_getstring(script, &fname)) break;	// hashed filename
        if (scriptfile_getnumber(script, &foffset)) break;	// offset in cache
        if (scriptfile_getnumber(script, &fsize)) break;	// size

        i = hash_find(&texcache.hashes,fname);
        if (i > -1)
        {
            // update an existing entry
            texcacheindex *t = texcache.iptrs[i];
            t->offset = foffset;
            t->len = fsize;
            /*initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, fname,foffset);*/
        }
        else
        {
            Bstrncpyz(texcache.currentindex->name, fname, BMAX_PATH);
            texcache.currentindex->offset = foffset;
            texcache.currentindex->len = fsize;
            texcache.currentindex->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));
            hash_add(&texcache.hashes, fname, texcache.numentries, 1);
            if (++texcache.numentries > texcache.iptrcnt)
            {
                texcache.iptrcnt += 512;
                texcache.iptrs = (texcacheindex **) Xrealloc(texcache.iptrs, sizeof(intptr_t) * texcache.iptrcnt);
            }
            texcache.iptrs[texcache.numentries-1] = texcache.currentindex;
            texcache.currentindex = texcache.currentindex->next;
        }
    }

    scriptfile_close(script);
    return 0;
}
コード例 #13
0
ファイル: util.c プロジェクト: juddy/edcde
void xp_add_argv( char ***argv, char *str )
{
    int i;

    if ( *argv ) {
	for ( i = 0; (*argv)[i]; i++ );
	*argv = (char **) Xrealloc( (char *) *argv, sizeof(char *) * (i + 2) );
    }
    else {
	i = 0;
	*argv = (char **) Xmalloc( sizeof(char *) * 2 );
    }

    (*argv)[i] = str;
    (*argv)[i+1] = (char *) NULL;
}
コード例 #14
0
ファイル: mod_period.c プロジェクト: triplekill/orchids
static int
period_htmloutput(orchids_t *ctx, mod_entry_t *mod, FILE *menufp, html_output_cfg_t *htmlcfg)
{
  FILE *fp;
  int i;
  strhash_elmt_t *helmt;
  size_t ctx_array_sz;
  char **ctx_array;

  fprintf(menufp,
	  "<a href=\"orchids-period.html\" "
          "target=\"main\">Periods</a><br/>\n");

  fp = create_html_file(htmlcfg, "orchids-period.html", NO_CACHE);
  fprintf_html_header(fp, "Orchids frequencies / phases tables");

  fprintf(fp, "<center><h1>Orchids frequencies / phases tables</h1></center>\n");

  ctx_array = NULL;
  ctx_array_sz = 0;
  for (i = 0; i < ctx->temporal->size; i++) {
    for (helmt = ctx->temporal->htable[i]; helmt; helmt = helmt->next) {
      ctx_array_sz++;
      ctx_array = Xrealloc(ctx_array, ctx_array_sz * sizeof (char *));
      ctx_array[ ctx_array_sz - 1 ] = helmt->key;
/*       period_output_gnuplot(); */
    }
  }
  qsort(ctx_array, ctx_array_sz, sizeof (char *), qsort_strcmp);

  fprintf(fp, "%zd context%s<br/><br/><br/>\n",
          ctx_array_sz, ctx_array_sz > 1 ? "s" : "");

  for (i = 0; i < ctx_array_sz; i++)
    fprintf(fp, "%i: %s<br/>\n", i, ctx_array[i]);

  if (ctx_array_sz > 0)
    Xfree(ctx_array);

  fprintf_html_trailer(fp);
  Xfclose(fp);

  return (0);
}
コード例 #15
0
ファイル: term_lists.c プロジェクト: plbogen/CSDL
static void
ResizeTermList (TermList ** term_list)
{
  TermList *tl = *term_list;

  if (tl->num > tl->list_size)
    {
      if (tl->list_size)
	tl->list_size *= GROWTH_FACTOR;
      else
	tl->list_size = MIN_SIZE;
    }
  tl = Xrealloc (tl, sizeof (TermList) + (tl->list_size - 1) * sizeof (TermEntry));

  if (!tl)
    FatalError (1, "Unable to resize term list");

  *term_list = tl;
}
コード例 #16
0
ファイル: lcDB.c プロジェクト: thekeenant/libx11-android
static int
realloc_line(
    Line *line,
    int size)
{
    char *str = line->str;

    if (str != NULL) {
        str = (char *)Xrealloc(str, size);
    } else {
        str = (char *)Xmalloc(size);
    }
    if (str == NULL) {
        /* malloc error */
        if (line->str != NULL) {
            Xfree(line->str);
        }
        bzero(line, sizeof(Line));
        return 0;
    }
    line->str = str;
    line->maxsize = size;
    return 1;
}
コード例 #17
0
ファイル: libmavis_external.c プロジェクト: hydrix1/tacacs
static int mavis_parse_in(mavis_ctx * mcx, struct sym *sym)
{
    u_int line;
    char *env_name;
    size_t len;
    struct stat st;

    while (1) {
	switch (sym->code) {
	case S_script:
	    mavis_script_parse(mcx, sym);
	    continue;
	case S_userid:
	    parse_userid(sym, &mcx->uid, &mcx->gid);
	    continue;
	case S_groupid:
	    parse_groupid(sym, &mcx->gid);
	    continue;
	case S_home:
	    sym_get(sym);
	    parse(sym, S_equal);
	    strset(&mcx->home, sym->buf);
	    sym_get(sym);
	    continue;
	case S_childs:
	    sym_get(sym);
	    switch (sym->code) {
	    case S_min:
		sym_get(sym);
		parse(sym, S_equal);
		mcx->child_min = parse_int(sym);
		continue;
	    case S_max:
		sym_get(sym);
		parse(sym, S_equal);
		mcx->child_max = parse_int(sym);
		continue;
	    default:
		parse_error_expect(sym, S_min, S_max, S_unknown);
	    }

	case S_setenv:
	    sym_get(sym);
	    env_name = alloca(strlen(sym->buf) + 1);
	    strcpy(env_name, sym->buf);
	    sym_get(sym);
	    parse(sym, S_equal);
	    len = strlen(env_name) + strlen(sym->buf) + 2;
	    mcx->env = Xrealloc(mcx->env, (mcx->envcount + 2) * sizeof(char *));
	    mcx->env[mcx->envcount] = Xcalloc(1, len);
	    snprintf(mcx->env[mcx->envcount++], len, "%s=%s", env_name, sym->buf);
	    mcx->env[mcx->envcount] = NULL;
	    sym_get(sym);
	    continue;

	case S_exec:{
		char buf[MAX_INPUT_LINE_LEN];
		sym_get(sym);
		parse(sym, S_equal);
		mcx->argv = calloc(1, sizeof(char *));
		line = sym->line;
		ostypef(sym->buf, buf, sizeof(buf));
		if (stat(buf, &st))
		    parse_error(sym, "%s: %s", buf, strerror(errno));
		strset(&mcx->path, buf);
		sym_get(sym);
		while (sym->line == line) {
		    mcx->argv = realloc(mcx->argv, (mcx->argc + 2) * sizeof(char *));
		    mcx->argv[mcx->argc] = strdup(sym->buf);
		    mcx->argc++;
		    mcx->argv[mcx->argc] = NULL;
		    sym_get(sym);
		}
		if (!mcx->argv[0]) {
		    mcx->argv = realloc(mcx->argv, 2 * sizeof(char *));
		    mcx->argv[0] = strdup(mcx->path);
		    mcx->argv[1] = NULL;
		}
		continue;
	    }
	case S_eof:
	case S_closebra:
	    if (!mcx->argv)
		parse_error(sym, "Missing \"exec\" declaration.");
	    return MAVIS_CONF_OK;
	default:
	    parse_error_expect(sym, S_script, S_userid, S_groupid, S_home, S_childs, S_setenv, S_exec, S_closebra, S_unknown);
	}
    }
}
コード例 #18
0
ファイル: lcFile.c プロジェクト: SvenDowideit/clearlinux
int
_XlcResolveLocaleName(
    const char* lc_name,
    XLCdPublicPart* pub)
{
    char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
    char *dst;
    int i, n, sinamelen;
    char *args[NUM_LOCALEDIR];
    static const char locale_alias[] = LOCALE_ALIAS;
    char *tmp_siname;
    char *nlc_name = NULL;

    xlocaledir (dir, PATH_MAX);
    n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
    for (i = 0; i < n; ++i) {
	if (args[i] == NULL)
	    continue;

	if (snprintf (buf, PATH_MAX, "%s/%s", args[i], locale_alias)
	    < PATH_MAX) {
	    name = resolve_name (lc_name, buf, LtoR);
	    if (!name) {
		if (!nlc_name)
		    nlc_name = normalize_lcname(lc_name);
		if (nlc_name)
		    name = resolve_name (nlc_name, buf, LtoR);
	    }
	}
	if (name != NULL) {
	    break;
	}
    }
    Xfree(nlc_name);

    if (name == NULL) {
	/* vendor locale name == Xlocale name, no expansion of alias */
	pub->siname = strdup (lc_name);
    } else {
	pub->siname = name;
    }

    sinamelen = strlen (pub->siname);
    if (sinamelen == 1 && pub->siname[0] == 'C') {
	pub->language = pub->siname;
	pub->territory = pub->codeset = NULL;
	return 1;
    }

    /*
     * pub->siname is in the format <lang>_<terr>.<codeset>, typical would
     * be "en_US.ISO8859-1", "en_US.utf8", "ru_RU.KOI-8", or ja_JP.SJIS,
     * although it could be ja.SJIS too.
     */
    tmp_siname = Xrealloc (pub->siname, 2 * (sinamelen + 1));
    if (tmp_siname == NULL) {
	return 0;
    }
    pub->siname = tmp_siname;

    /* language */
    dst = &pub->siname[sinamelen + 1];
    strcpy (dst, pub->siname);
    pub->language = dst;

    /* territory */
    dst = strchr (dst, '_');
    if (dst) {
	*dst = '\0';
	pub->territory = ++dst;
    } else
	dst = &pub->siname[sinamelen + 1];

    /* codeset */
    dst = strchr (dst, '.');
    if (dst) {
	*dst = '\0';
	pub->codeset = ++dst;
    }

    return (pub->siname[0] != '\0') ? 1 : 0;
}
コード例 #19
0
ファイル: manager.c プロジェクト: osen/cdesktopenv
/********************************************************************
 *
 * message_pipe_handler()
 *
 * Takes stderr from the child, via a pipe, and stores the output
 * in the client tracking record.
 * 
 */
static void message_pipe_handler( XtPointer w, int *source, XtInputId *id)
{
    int    i, inc;
    struct stat statBuffer;
    int    delt_with;
    int    n, keepon;

    /*
     * Find out who is generating output.
     */
    delt_with = False;

    for ( i = 0; i < g.serviceRecNum; i++ ) {
	if ( g.serviceRecs[i]->message_pipe[0] == *source ) {
	    delt_with = True;
	    /*
	     * Fetch size and grow message_string to hold more.
	     */
	    if ( fstat(*source, &statBuffer) ) {
		/* unable to get size */
		statBuffer.st_size = 0;		/* bail out below */
	    }

	    if ( statBuffer.st_size > 0 ) {
		if ( g.serviceRecs[i]->message_string ) {
		    inc = strlen( g.serviceRecs[i]->message_string );

		    g.serviceRecs[i]->message_string = Xrealloc(
				(char *) g.serviceRecs[i]->message_string,
				statBuffer.st_size + inc + 1 );
		}
		else {
		    inc = 0;

		    g.serviceRecs[i]->message_string = Xmalloc(
				statBuffer.st_size + 1 );
		}

		/*
		 * Read off what we know is there.
		 */
		keepon = True;
		while (keepon) {
		    n = read( *source, &(g.serviceRecs[i]->message_string[inc]),
				statBuffer.st_size );

		    if ( n == statBuffer.st_size ) {
			/* read all there is (per the previous stat) */
			keepon = False;
		    }
		    else if (( n == -1 ) && ( errno == EINTR )) {
			/* an interrupt came in before the read could start */
			keepon = True;
		    }
		    else if (( n == -1 ) || ( n == 0 )) {
			/* problems - bail out */
			g.serviceRecs[i]->message_pipe[0] = -1;
			close(*source);
			XtRemoveInput(*id);
			keepon = False;
		    }
		    else {
			/* only a partial read, probably a sig, try for more */
			inc += n;
			statBuffer.st_size -= n;
			keepon = True;
		    }
		}

		/*
		 * NULL terminate what we have so far to make it look
		 * like a string.
		 */
		g.serviceRecs[i]->message_string[statBuffer.st_size+inc] = '\0';
	    }
	    else {
		/*
		 * No more to read - this really means the pipe is
		 * going down.
		 */
		g.serviceRecs[i]->message_pipe[0] = -1;
		close (*source);
		XtRemoveInput(*id);
	    }
	}
    }

    if (!delt_with) {
	/*
	 * Some stray pipe that we no longer have information on.
	 */
	close(*source);
	XtRemoveInput(*id);
    }

    /*
     * Scan client records and see who is ready to be
     * shut down.
     */
    mgr_shutdown_scan();
}
コード例 #20
0
ファイル: common.c プロジェクト: dahlor/Duke3DS
void G_AddClipMap(const char *buffer)
{
    g_clipMapFiles = (char **) Xrealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *));
    g_clipMapFiles[g_clipMapFilesNum] = Xstrdup(buffer);
    ++g_clipMapFilesNum;
}
コード例 #21
0
ファイル: PolyReg.c プロジェクト: MisPresident/libX11
/*
 *     Create an array of rectangles from a list of points.
 *     If indeed these things (POINTS, RECTS) are the same,
 *     then this proc is still needed, because it allocates
 *     storage for the array, which was allocated on the
 *     stack by the calling procedure.
 *
 */
static int PtsToRegion(
    register int numFullPtBlocks,
    register int iCurPtBlock,
    POINTBLOCK *FirstPtBlock,
    REGION *reg)
{
    register BOX  *rects;
    register XPoint *pts;
    register POINTBLOCK *CurPtBlock;
    register int i;
    register BOX *extents;
    register int numRects;
    BOX *prevRects = reg->rects;

    extents = &reg->extents;

    numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1;

    if (!(reg->rects = Xrealloc(reg->rects, sizeof(BOX) * numRects))) {
	Xfree(prevRects);
	return(0);
    }

    reg->size = numRects;
    CurPtBlock = FirstPtBlock;
    rects = reg->rects - 1;
    numRects = 0;
    extents->x1 = MAXSHORT,  extents->x2 = MINSHORT;

    for ( ; numFullPtBlocks >= 0; numFullPtBlocks--) {
	/* the loop uses 2 points per iteration */
	i = NUMPTSTOBUFFER >> 1;
	if (!numFullPtBlocks)
	    i = iCurPtBlock >> 1;
	for (pts = CurPtBlock->pts; i--; pts += 2) {
	    if (pts->x == pts[1].x)
		continue;
	    if (numRects && pts->x == rects->x1 && pts->y == rects->y2 &&
		pts[1].x == rects->x2 &&
		(numRects == 1 || rects[-1].y1 != rects->y1) &&
		(i && pts[2].y > pts[1].y)) {
		rects->y2 = pts[1].y + 1;
		continue;
	    }
	    numRects++;
	    rects++;
	    rects->x1 = pts->x;  rects->y1 = pts->y;
	    rects->x2 = pts[1].x;  rects->y2 = pts[1].y + 1;
	    if (rects->x1 < extents->x1)
		extents->x1 = rects->x1;
	    if (rects->x2 > extents->x2)
		extents->x2 = rects->x2;
        }
	CurPtBlock = CurPtBlock->next;
    }

    if (numRects) {
	extents->y1 = reg->rects->y1;
	extents->y2 = rects->y2;
    } else {
	extents->x1 = 0;
	extents->y1 = 0;
	extents->x2 = 0;
	extents->y2 = 0;
    }
    reg->numRects = numRects;

    return(TRUE);
}
コード例 #22
0
ファイル: msgfmt.c プロジェクト: stormos-next/illumos-stormos
/*
 * read one line from *mbuf,
 * skip preceding whitespaces,
 * convert the line to wide characters,
 * place the wide characters into *bufhead, and
 * return the number of wide characters placed.
 *
 * INPUT:
 *		**bufhead - address of a variable that is the pointer
 *			to wchar_t.
 *			The variable should been initialized to NULL.
 *		**mbuf - address of a variable that is the pointer
 *			to char.
 *			The pointer should point to the memory mmapped to
 *			the file to input.
 *		**fsize - address of a size_t variable that contains
 *			the size of unread bytes in the file to input.
 * OUTPUT:
 *		return - the number of wide characters placed.
 *		**bufhead - _mbsntowcs allocates the buffer to store
 *			one line in wchar_t from *mbuf and sets the address
 *			to *bufhead.
 *		**mbuf - _mbsntowcs reads one line from *mbuf and sets *mbuf
 *			to the beginning of the next line.
 *		**fsize - *fsize will be set to the size of the unread
 *			bytes in the file.
 */
static size_t
_mbsntowcs(wchar_t **bufhead, char **mbuf, size_t *fsize)
{
	wchar_t	*tp, *th;
	wchar_t	wc;
	size_t	tbufsize = LINE_SIZE;
	size_t	ttbufsize, nc;
	char	*pc = *mbuf;
	int	nb;

	if (*fsize == 0) {
		/* eof */
		return (0);
	}

	th = (wchar_t *)Xmalloc(sizeof (wchar_t) * tbufsize);
	nc = tbufsize;

	/* skip preceding whitespaces */
	while ((*pc != '\0')) {
		if ((*pc == ' ') || (*pc == '\t')) {
			pc++;
			(*fsize)--;
		} else {
			break;
		}
	}

	tp = th;
	while (*fsize > 0) {
		nb = mbtowc(&wc, pc, mbcurmax);
		if (nb == -1) {
			return ((size_t)-1);
		}

		if (*pc == '\n') {
			/* found eol */
			if (nc <= 1) {
				/*
				 * not enough buffer
				 * at least 2 more bytes are required for
				 * L'\n' and L'\0'
				 */
				ttbufsize = tbufsize + 2;
				th = (wchar_t *)Xrealloc(th,
					sizeof (wchar_t) * ttbufsize);
				tp = th + tbufsize - nc;
				tbufsize = ttbufsize;
			}
			*tp++ = L'\n';
			*tp++ = L'\0';
			pc += nb;
			*fsize -= nb;
			*mbuf = pc;
			*bufhead = th;
			return ((size_t)(tp - th));
		}
		if (nc == 0) {
			ttbufsize = tbufsize + LINE_SIZE;
			th = (wchar_t *)Xrealloc(th,
				sizeof (wchar_t) * ttbufsize);
			tp = th + tbufsize;
			nc = LINE_SIZE;
			tbufsize = ttbufsize;
		}
		*tp++ = wc;
		nc--;
		pc += nb;
		*fsize -= nb;
	}	/* while */

	/*
	 * At this point, the input file has been consumed,
	 * but there is no ending '\n'; we add it to
	 * the output file.
	 */
	if (nc <= 1) {
		/*
		 * not enough buffer
		 * at least 2 more bytes are required for
		 * L'\n' and L'\0'
		 */
		ttbufsize = tbufsize + 2;
		th = (wchar_t *)Xrealloc(th,
			sizeof (wchar_t) * ttbufsize);
		tp = th + tbufsize - nc;
		tbufsize = ttbufsize;
	}
	*tp++ = L'\n';
	*tp++ = L'\0';
	*mbuf = pc;
	*bufhead = th;
	return ((size_t)(tp - th));
}
コード例 #23
0
ファイル: XlcDL.c プロジェクト: iquiw/xsrc
static void
resolve_object(char *path, const char *lc_name)
{
    char filename[BUFSIZ];
    FILE *fp;
    char buf[BUFSIZ];

    if (lc_len == 0) { /* True only for the 1st time */
        lc_len = OBJECT_INIT_LEN;
        xi18n_objects_list = Xmalloc(sizeof(XI18NObjectsListRec) * lc_len);
        if (!xi18n_objects_list) return;
    }
    snprintf(filename, sizeof(filename), "%s/%s", path, "XI18N_OBJS");
    fp = fopen(filename, "r");
    if (fp == (FILE *)NULL) {
        return;
    }

    while (fgets(buf, BUFSIZ, fp) != NULL) {
        char *p = buf;
        int n;
        char *args[6];
        while (isspace(*p)) {
            ++p;
        }
        if (iscomment(*p)) {
            continue;
        }

        if (lc_count == lc_len) {
            int new_len = lc_len + OBJECT_INC_LEN;
            XI18NObjectsListRec *tmp = Xrealloc(xi18n_objects_list,
                                                sizeof(XI18NObjectsListRec) * new_len);
            if (tmp == NULL)
                goto done;
            xi18n_objects_list = tmp;
            lc_len = new_len;
        }
        n = parse_line(p, args, 6);

        if (n == 3 || n == 5) {
            if (!strcmp(args[0], "XLC")) {
                xi18n_objects_list[lc_count].type = XLC_OBJECT;
            } else if (!strcmp(args[0], "XOM")) {
                xi18n_objects_list[lc_count].type = XOM_OBJECT;
            } else if (!strcmp(args[0], "XIM")) {
                xi18n_objects_list[lc_count].type = XIM_OBJECT;
            }
            xi18n_objects_list[lc_count].dl_name = strdup(args[1]);
            xi18n_objects_list[lc_count].open = strdup(args[2]);
            xi18n_objects_list[lc_count].dl_release = XI18N_DLREL;
            xi18n_objects_list[lc_count].locale_name = strdup(lc_name);
            xi18n_objects_list[lc_count].refcount = 0;
            xi18n_objects_list[lc_count].dl_module = (void*)NULL;
            if (n == 5) {
                xi18n_objects_list[lc_count].im_register = strdup(args[3]);
                xi18n_objects_list[lc_count].im_unregister = strdup(args[4]);
            } else {
                xi18n_objects_list[lc_count].im_register = NULL;
                xi18n_objects_list[lc_count].im_unregister = NULL;
            }
            lc_count++;
        }
    }
done:
    fclose(fp);
}
コード例 #24
0
ファイル: msgfmt.c プロジェクト: stormos-next/illumos-stormos
static void
read_psffm(char *file)
{
	int	fd;
	static char	msgfile[MAXPATHLEN];
	wchar_t	*linebufptr, *p;
	char	*bufptr = 0;
	int	quotefound;	/* double quote was seen */
	int	inmsgid = 0;	/* indicates "msgid" was seen */
	int	inmsgstr = 0;	/* indicates "msgstr" was seen */
	int	indomain = 0;	/* indicates "domain" was seen */
	wchar_t	wc;
	char	mb;
	int	n;
	char	token_found;	/* Boolean value */
	unsigned int	bufptr_index = 0; /* current index of bufptr */
	char	*mbuf, *addr;
	size_t	fsize, ln_size, ll;
	wchar_t	*linebufhead = NULL;
	struct stat64	statbuf;
	char	*filename;

	/*
	 * For each po file to be read,
	 * 1) set domain to default and
	 * 2) set linenumer to 0.
	 */
	(void) strcpy(gcurrent_domain, DEFAULT_DOMAIN);
	linenum = 0;

	if (!inputdir) {
		filename = Xstrdup(file);
	} else {
		size_t	dirlen, filelen, len;

		dirlen = strlen(inputdir);
		filelen = strlen(file);
		len = dirlen + 1 + filelen + 1;
		filename = (char *)Xmalloc(len);
		(void) memcpy(filename, inputdir, dirlen);
		*(filename + dirlen) = '/';
		(void) memcpy(filename + dirlen + 1, file, filelen);
		*(filename + dirlen + 1 + filelen) = '\0';
	}

	fd = open(filename, O_RDONLY);
	if (fd == -1) {
		error(gettext(ERR_OPEN_FAILED), filename);
		/* NOTREACHED */
	}
	if (fstat64(fd, &statbuf) == -1) {
		error(gettext(ERR_STAT_FAILED), filename);
		/* NOTREACHED */
	}
	fsize = (size_t)statbuf.st_size;
	if (fsize == 0) {
		/*
		 * The size of the specified po file is 0.
		 * In Solaris 8 and earlier, msgfmt was silent
		 * for the null po file.  So, just returns
		 * without generating an error message.
		 */
		(void) close(fd);
		free(filename);
		return;
	}
	addr = mmap(NULL, fsize, PROT_READ, MAP_SHARED, fd, 0);
	if (addr == MAP_FAILED) {
		error(gettext(ERR_MMAP_FAILED), filename);
		/* NOTREACHED */
	}
	(void) close(fd);

	if (!sun_p)
		check_gnu(addr, fsize);

	mbuf = addr;
	for (;;) {
		if (linebufhead) {
			free(linebufhead);
			linebufhead = NULL;
		}
		ln_size = _mbsntowcs(&linebufhead, &mbuf, &fsize);
		if (ln_size == (size_t)-1) {
			error(gettext(ERR_READ_FAILED), filename);
			/* NOTREACHED */
		} else if (ln_size == 0) {
			break;	/* End of File. */
		}
		linenum++;

		linebufptr = linebufhead;
		quotefound = 0;

		switch (*linebufptr) {
			case L'#':	/* comment    */
			case L'\n':	/* empty line */
				continue;
			case L'\"': /* multiple lines of msgid and msgstr */
				quotefound = 1;
				break;
		}

		/*
		 * Process MSGID Tokens.
		 */
		token_found = (wcsncmp(MSGID_TOKEN, linebufptr,
				MSGID_LEN) == 0) ? 1 : 0;

		if (token_found || (quotefound && inmsgid)) {

			if (token_found) {
				if (!CK_NXT_CH(linebufptr, MSGID_LEN+1)) {
					diag(gettext(ERR_NOSPC), linenum);
					error(gettext(ERR_EXITING));
					/* NOTREACHED */
				}
			}

			if (inmsgid && !quotefound) {
				warning(gettext(WARN_NO_MSGSTR), msgid_linenum);
				continue;
			}
			if (inmsgstr) {
				sortit(gmsgid, gmsgstr);
				(void) memset(gmsgid, 0, gmsgid_size);
				(void) memset(gmsgstr, 0, gmsgstr_size);
			}

			if (inmsgid) {
				/* multiple lines of msgid */
				/* cancel the previous null termination */
				bufptr_index--;
			} else {
				/*
				 * The first line of msgid.
				 * Save linenum of msgid to be used when
				 * printing warning or error message.
				 */
				msgid_linenum = linenum;
				p = linebufptr;
				linebufptr = consume_whitespace(
					linebufptr + MSGID_LEN);
				ln_size -= linebufptr - p;
				bufptr = gmsgid;
				bufptr_index = 0;
			}

			inmsgid = 1;
			inmsgstr = 0;
			indomain = 0;
			goto load_buffer;
		}

		/*
		 * Process MSGSTR Tokens.
		 */
		token_found = (wcsncmp(MSGSTR_TOKEN, linebufptr,
			MSGSTR_LEN) == 0) ? 1 : 0;
		if (token_found || (quotefound && inmsgstr)) {

			if (token_found) {
				if (!CK_NXT_CH(linebufptr, MSGSTR_LEN+1)) {
					diag(gettext(ERR_NOSPC), linenum);
					error(gettext(ERR_EXITING));
					/* NOTREACHED */
				}
			}


			if (inmsgstr && !quotefound) {
				warning(gettext(WARN_NO_MSGID), msgstr_linenum);
				continue;
			}
			if (inmsgstr) {
				/* multiple lines of msgstr */
				/* cancel the previous null termination */
				bufptr_index--;
			} else {
				/*
				 * The first line of msgstr.
				 * Save linenum of msgid to be used when
				 * printing warning or error message.
				 */
				msgstr_linenum = linenum;
				p = linebufptr;
				linebufptr = consume_whitespace(
					linebufptr + MSGSTR_LEN);
				ln_size -= linebufptr - p;
				bufptr = gmsgstr;
				bufptr_index = 0;
			}

			inmsgstr = 1;
			inmsgid = 0;
			indomain = 0;
			goto load_buffer;
		}

		/*
		 * Process DOMAIN Tokens.
		 * Add message id and message string to sorted list
		 * if msgstr was processed last time.
		 */
		token_found = (wcsncmp(DOMAIN_TOKEN, linebufptr,
			DOMAIN_LEN) == 0) ? 1 : 0;
		if ((token_found) || (quotefound && indomain)) {
			if (token_found) {
				if (!CK_NXT_CH(linebufptr, DOMAIN_LEN+1)) {
					diag(gettext(ERR_NOSPC), linenum);
					error(gettext(ERR_EXITING));
					/* NOTREACHED */
				}
			}


			/*
			 * process msgid and msgstr pair for previous domain
			 */
			if (inmsgstr) {
				sortit(gmsgid, gmsgstr);
			}

			/* refresh msgid and msgstr buffer */
			if (inmsgstr || inmsgid) {
				(void) memset(gmsgid, 0, gmsgid_size);
				(void) memset(gmsgstr, 0, gmsgstr_size);
			}

			if (indomain) {
				/* multiple lines of domain */
				/* cancel the previous null termination */
				bufptr_index--;
			} else {
				p = linebufptr;
				linebufptr = consume_whitespace(
					linebufptr + DOMAIN_LEN);
				(void) memset(gcurrent_domain, 0,
						sizeof (gcurrent_domain));
				ln_size -= linebufptr - p;
				bufptr = gcurrent_domain;
				bufptr_index = 0;
			}

			indomain = 1;
			inmsgid = 0;
			inmsgstr = 0;
		} /* if */

load_buffer:
		/*
		 * Now, fill up the buffer pointed by bufptr.
		 * At this point bufptr should point to one of
		 * msgid, msgptr, or current_domain.
		 * Otherwise, the entire line is ignored.
		 */

		if (!bufptr) {
			warning(gettext(WARN_SYNTAX_ERR), linenum);
			continue;
		}

		if (*linebufptr++ != L'\"') {
			warning(gettext(WARN_MISSING_QUOTE), linenum);
			--linebufptr;
		}
		quotefound = 0;

		/*
		 * If there is not enough space in the buffer,
		 * increase buffer by ln_size by realloc.
		 */
		ll = ln_size * mbcurmax;
		if (bufptr == gmsgid) {
			if (gmsgid_size < (bufptr_index + ll)) {
				gmsgid = (char *)Xrealloc(gmsgid,
					bufptr_index + ll);
				bufptr = gmsgid;
				gmsgid_size = bufptr_index + ll;
			}
		} else if (bufptr == gmsgstr) {
			if (gmsgstr_size < (bufptr_index + ll)) {
				gmsgstr = (char *)Xrealloc(gmsgstr,
					bufptr_index + ll);
				bufptr = gmsgstr;
				gmsgstr_size = bufptr_index + ll;
			}
		}

		while (wc = *linebufptr++) {
			switch (wc) {
			case L'\n':
				if (!quotefound) {
warning(gettext(WARN_MISSING_QUOTE_AT_EOL), linenum);
				}
				break;

			case L'\"':
				quotefound = 1;
				break;

			case L'\\':
				if ((mb = expand_meta(&linebufptr)) != NULL)
					bufptr[bufptr_index++] = mb;
				break;

			default:
				if ((n = wctomb(&bufptr[bufptr_index], wc)) > 0)
					bufptr_index += n;
			} /* switch */
			if (quotefound) {
				/*
				 * Check if any remaining characters
				 * after closing quote.
				 */
				linebufptr = consume_whitespace(linebufptr);
				if (*linebufptr != L'\n') {
					warning(gettext(WARN_INVALID_STRING),
						linenum);
				}
				break;
			}
		} /* while */

		bufptr[bufptr_index++] = '\0';

		(void) strcpy(msgfile, gcurrent_domain);
		(void) strcat(msgfile, ".mo");
	} /* for(;;) */

	if (inmsgstr) {
		sortit(gmsgid, gmsgstr);
	}

	if (linebufhead)
		free(linebufhead);
	if (munmap(addr, statbuf.st_size) == -1) {
		error(gettext(ERR_MUNMAP_FAILED), filename);
		/* NOTREACHED */
	}

	free(filename);
	return;

} /* read_psffm */
コード例 #25
0
ファイル: texcache.c プロジェクト: clobber/eduke32
static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr, int32_t *xsiz, int32_t *ysiz)
{
    int32_t level;
    texcachepicture pict;
    char *pic = NULL, *packbuf = NULL;
    void *midbuf = NULL;
    int32_t alloclen=0;

    for (level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++)
    {
        GLint format;

        if (texcache_readdata(&pict, sizeof(texcachepicture)))
        {
            TEXCACHE_FREEBUFS();
            return TEXCACHERR_BUFFERUNDERRUN;
        }

        // external (little endian) -> native
        pict.size = B_LITTLE32(pict.size);
        pict.format = B_LITTLE32(pict.format);
        pict.xdim = B_LITTLE32(pict.xdim);
        pict.ydim = B_LITTLE32(pict.ydim);
        pict.border = B_LITTLE32(pict.border);
        pict.depth = B_LITTLE32(pict.depth);

        if (level == 0)
        { 
            if (xsiz) *xsiz = pict.xdim;
            if (ysiz) *ysiz = pict.ydim;
        }

        if (alloclen < pict.size)
        {
            pic = (char *)Xrealloc(pic, pict.size);
            alloclen = pict.size;
            packbuf = (char *)Xrealloc(packbuf, alloclen+16);
            midbuf = (void *)Xrealloc(midbuf, pict.size);
        }

        if (dedxtfilter(texcache.filehandle, &pict, pic, midbuf, packbuf,
                        (head->flags & CACHEAD_COMPRESSED)!=0))
        {
            TEXCACHE_FREEBUFS();
            return TEXCACHERR_DEDXT;
        }

        bglCompressedTexImage2DARB(GL_TEXTURE_2D,level,pict.format,pict.xdim,pict.ydim,pict.border,pict.size,pic);
        if ((*glerr=bglGetError()) != GL_NO_ERROR)
        {
            TEXCACHE_FREEBUFS();
            return TEXCACHERR_COMPTEX;
        }

        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &format);
        if ((*glerr = bglGetError()) != GL_NO_ERROR)
        {
            TEXCACHE_FREEBUFS();
            return TEXCACHERR_GETTEXLEVEL;
        }

        if (pict.format != format)
        {
            OSD_Printf("gloadtile_cached: invalid texture cache file format %d %d\n", pict.format, format);
            TEXCACHE_FREEBUFS();
            return -1;
        }
    }

    TEXCACHE_FREEBUFS();
    return 0;
}
コード例 #26
0
ファイル: texcache.c プロジェクト: clobber/eduke32
void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect, texcacheheader *head)
{
    static GLint glGetTexLevelParameterivOK = GL_TRUE;
    char cachefn[BMAX_PATH];
    char *pic = NULL, *packbuf = NULL;
    void *midbuf = NULL;
    uint32_t alloclen=0, level;
    uint32_t padx=0, pady=0;
    GLint gi;
    int32_t offset = 0;

    if (!texcache_enabled()) return;

    gi = GL_FALSE;
    bglGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &gi);
    if (gi != GL_TRUE)
    {
        if (glGetTexLevelParameterivOK == GL_TRUE)
        {
            OSD_Printf("Error: glGetTexLevelParameteriv returned GL_FALSE!\n");
            glGetTexLevelParameterivOK = GL_FALSE;
        }
        return;
    }

    Blseek(texcache.filehandle, 0, BSEEK_END);

    offset = Blseek(texcache.filehandle, 0, BSEEK_CUR);
    //    OSD_Printf("Caching %s, offset 0x%x\n", cachefn, offset);

    Bmemcpy(head->magic, TEXCACHEMAGIC, 4);   // sizes are set by caller

    if (glusetexcache == 2)
        head->flags |= CACHEAD_COMPRESSED;

    // native -> external (little-endian)
    head->xdim = B_LITTLE32(head->xdim);
    head->ydim = B_LITTLE32(head->ydim);
    head->flags = B_LITTLE32(head->flags);
    head->quality = B_LITTLE32(head->quality);

    if (Bwrite(texcache.filehandle, head, sizeof(texcacheheader)) != sizeof(texcacheheader)) goto failure;

    CLEAR_GL_ERRORS();

    for (level = 0; level==0 || (padx > 1 || pady > 1); level++)
    {
        uint32_t miplen;
        texcachepicture pict;

        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_ARB, &gi); WRITEX_FAIL_ON_ERROR();
        if (gi != GL_TRUE) goto failure;   // an uncompressed mipmap
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_INTERNAL_FORMAT, &gi); WRITEX_FAIL_ON_ERROR();

#ifdef __APPLE__
        if (pr_ati_textureformat_one && gi == 1) gi = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
#endif
        // native -> external (little endian)
        pict.format = B_LITTLE32(gi);
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_WIDTH, &gi); WRITEX_FAIL_ON_ERROR();
        padx = gi; pict.xdim = B_LITTLE32(gi);
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_HEIGHT, &gi); WRITEX_FAIL_ON_ERROR();
        pady = gi; pict.ydim = B_LITTLE32(gi);
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_BORDER, &gi); WRITEX_FAIL_ON_ERROR();
        pict.border = B_LITTLE32(gi);
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_DEPTH, &gi); WRITEX_FAIL_ON_ERROR();
        pict.depth = B_LITTLE32(gi);
        bglGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &gi); WRITEX_FAIL_ON_ERROR();
        miplen = gi; pict.size = B_LITTLE32(gi);

        if (alloclen < miplen)
        {
            pic = (char *)Xrealloc(pic, miplen);
            alloclen = miplen;
            packbuf = (char *)Xrealloc(packbuf, alloclen);
            midbuf = (void *)Xrealloc(midbuf, miplen);
        }

        bglGetCompressedTexImageARB(GL_TEXTURE_2D, level, pic); WRITEX_FAIL_ON_ERROR();

        if (Bwrite(texcache.filehandle, &pict, sizeof(texcachepicture)) != sizeof(texcachepicture)) goto failure;
        if (dxtfilter(texcache.filehandle, &pict, pic, midbuf, packbuf, miplen)) goto failure;
    }

    {
        texcacheindex *t;
        int32_t i = hash_find(&texcache.hashes, texcache_calcid(cachefn, fn, len, dameth, effect));
        if (i > -1)
        {
            // update an existing entry
            t = texcache.iptrs[i];
            t->offset = offset;
            t->len = Blseek(texcache.filehandle, 0, BSEEK_CUR) - t->offset;
            /*initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, cachefn,offset);*/
        }
        else
        {
            t = texcache.currentindex;
            Bstrcpy(t->name, cachefn);
            t->offset = offset;
            t->len = Blseek(texcache.filehandle, 0, BSEEK_CUR) - t->offset;
            t->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));

            hash_add(&texcache.hashes, cachefn, texcache.numentries, 0);
            if (++texcache.numentries > texcache.iptrcnt)
            {
                texcache.iptrcnt += 512;
                texcache.iptrs = (texcacheindex **) Xrealloc(texcache.iptrs, sizeof(intptr_t) * texcache.iptrcnt);
            }
            texcache.iptrs[texcache.numentries-1] = t;
            texcache.currentindex = t->next;
        }

        if (texcache.index)
        {
            fseek(texcache.index, 0, BSEEK_END);
            Bfprintf(texcache.index, "%s %d %d\n", t->name, t->offset, t->len);
        }
        else OSD_Printf("wtf?\n");
    }

    goto success;

failure:
    initprintf("ERROR: cache failure!\n");
    texcache.currentindex->offset = 0;
    Bmemset(texcache.currentindex->name,0,sizeof(texcache.currentindex->name));

success:
    TEXCACHE_FREEBUFS();
}
コード例 #27
0
ファイル: lcDB.c プロジェクト: thekeenant/libx11-android
static int
append_value_list (void)
{
    char **value_list = parse_info.value;
    char *value;
    int value_num = parse_info.value_num;
    int value_len = parse_info.value_len;
    char *str = parse_info.buf;
    int len = parse_info.bufsize;
    char *p;

    if (len < 1) {
        return 1; /* return with no error */
    }

    if (value_list == (char **)NULL) {
        value_list = (char **)Xmalloc(sizeof(char *) * 2);
        *value_list = NULL;
    } else {
        char **prev_list = value_list;

        value_list = (char **)
                     Xrealloc(value_list, sizeof(char *) * (value_num + 2));
        if (value_list == NULL) {
            Xfree(prev_list);
        }
    }
    if (value_list == (char **)NULL)
        goto err2;

    value = *value_list;
    if (value == NULL) {
        value = (char *)Xmalloc(value_len + len + 1);
    } else {
        char *prev_value = value;

        value = (char *)Xrealloc(value, value_len + len + 1);
        if (value == NULL) {
            Xfree(prev_value);
        }
    }
    if (value == NULL) {
        goto err1;
    }
    if (value != *value_list) {
        int i;
        ssize_t delta;
        delta = value - *value_list;
        *value_list = value;
        for (i = 1; i < value_num; ++i) {
            value_list[i] += delta;
        }
    }

    value_list[value_num] = p = &value[value_len];
    value_list[value_num + 1] = NULL;
    strncpy(p, str, len);
    p[len] = 0;

    parse_info.value = value_list;
    parse_info.value_num = value_num + 1;
    parse_info.value_len = value_len + len + 1;
    parse_info.bufsize = 0;
    return 1;

err1:
    if (value_list) {
        Xfree((char **)value_list);
    }
    if (value) {
        Xfree(value);
    }
err2:
    parse_info.value = (char **)NULL;
    parse_info.value_num = 0;
    parse_info.value_len = 0;
    parse_info.bufsize = 0;
    return 0;
}
コード例 #28
0
ファイル: common.c プロジェクト: dahlor/Duke3DS
void G_AddDefModule(const char *buffer)
{
    g_defModules = (char **) Xrealloc (g_defModules, (g_defModulesNum+1) * sizeof(char *));
    g_defModules[g_defModulesNum] = Xstrdup(buffer);
    ++g_defModulesNum;
}
コード例 #29
0
ファイル: check_header.c プロジェクト: andreiw/polaris
void
check_gnu(char *addr, size_t fsize)
{
	int	i;
	char	c, mc;
	char	*linebuf;
	char	*mbuf, *p, *buf;
	unsigned int	n;
	size_t	ln_size;
	size_t	bufsize, index;
	size_t	size = fsize;
	int	quotefound = 0;
	const char	*field;

	buf = NULL;
	linebuf = NULL;
	mbuf = addr;

loop:
	ln_size = get_one_line(&linebuf, &mbuf, &size);
	if ((ln_size == (size_t)-1) ||
		(ln_size == 0)) {
		goto no_gnu;
	}
	p = linebuf;

	while ((*p == '#') || (*p == '\n')) {
		ln_size = get_one_line(&linebuf, &mbuf, &size);
		if ((ln_size == (size_t)-1) ||
			(ln_size == 0)) {
			goto no_gnu;
		}
		p = linebuf;
	}

	if (strncmp(p, "domain", 6) == 0)
		goto loop;

	if (strncmp(p, "msgid", 5) != 0) {
		/* error */
		goto no_gnu;
	}

	p += 5;
	if ((*p != ' ') && (*p != '\t') &&
		(*p != '\n') && (*p != '\0')) {
		/* no space after msgid */
		goto no_gnu;
	}
	/* skip spaces */
	while ((*p == ' ') || (*p == '\t'))
		p++;

	/* check if this entry is an empty string */
	if ((*p != '\"') || (*(p + 1) != '\"')) {
		/* this is not an empty string */
		goto no_gnu;
	}
	p += 2;
	while (*p && ((*p == ' ') || (*p == '\t'))) {
		p++;
	}
	if ((*p != '\n') && (*p != '\0')) {
		/* other characters than '\n' and '\0' found */
		goto no_gnu;
	}

	for (; ; ) {
		ln_size = get_one_line(&linebuf, &mbuf, &size);
		if ((ln_size == (size_t)-1) ||
			(ln_size == 0)) {
			goto no_gnu;
		}
		p = linebuf;
		/* skip leading spaces */
		while ((*p == ' ') || (*p == '\t'))
			p++;

		if (*p != '\"') {
			if (strncmp(p, "msgstr", 6) == 0) {
				break;
			}
			/* not a valid entry */
			goto no_gnu;
		}
		if (*(p + 1) != '\"') {
			/* not an empty string */
			goto no_gnu;
		}
		p += 2;
		while ((*p == ' ') || (*p == '\t'))
			p++;

		if ((*p != '\n') && (*p != '\0')) {
			/* other characters than '\n' and '\0' found */
			goto no_gnu;
		}
	}

	/*
	 * msgid for the header entry found
	 * Now p points to "msgstr"
	 */
	p += 6;
	if ((*p != ' ') && (*p != '\t') &&
		(*p != '\n') && (*p != '\0')) {
		/* no space after msgid */
		goto no_gnu;
	}

	/* skip spaces */
	while ((*p == ' ') || (*p == '\t'))
		p++;

	if (*p != '\"') {
		/* no quote */
		goto no_gnu;
	}

	bufsize = ln_size + 1;
	index = 0;
	buf = (char *)Xmalloc(bufsize);

	for (; ; ) {
		if (*p != '\"') {
			/* msgstr entry ends */
			buf[index] = '\0';
			break;
		}

		if (*p++ != '\"') {
			/* no beginning quote */
			goto no_gnu;
		}
		while (*p) {
			switch (mc = *p++) {
			case '\n':
				if (!quotefound) {
					/* error */
					goto no_gnu;
				}
				break;
			case '\"':
				quotefound = 1;
				break;
			case '\\':
				if (!*p)
					break;
				switch (c = *p++) {
				case 'b':
					buf[index++] = '\b';
					break;
				case 'f':
					buf[index++] = '\f';
					break;
				case 'n':
					buf[index++] = '\n';
					break;
				case 'r':
					buf[index++] = '\r';
					break;
				case 't':
					buf[index++] = '\t';
					break;
				case 'v':
					buf[index++] = '\v';
					break;
				case 'a':
					buf[index++] = '\a';
					break;
				case '\"':
				case '\\':
				case '\'':
				case '?':
					buf[index++] = c;
					break;
				default:
					if (isdigit((unsigned char)c)) {
						unsigned int	x;
						unsigned char	*up =
							(unsigned char *)p;
						n = c - '0';
						if (isdigit(*up)) {
							x = *up++ - '0';
							n = 8 * n + x;
							if (isdigit(*up)) {
								x = *up++ - '0';
								n = 8 * n + x;
							}
						}
						p = (char *)up;
						buf[index++] = n;
					}
					break;
				}
				break;
			default:
				buf[index++] = mc;
				break;
			}
			if (quotefound) {
				while (*p && ((*p == ' ') || (*p == '\t'))) {
					p++;
				}
				if ((*p != '\n') && (*p != '\0')) {
					goto no_gnu;
				}
				quotefound = 0;
				break;
			}
		}
		ln_size = get_one_line(&linebuf, &mbuf, &size);
		if ((ln_size == (size_t)-1) ||
			(ln_size == 0)) {
			goto no_gnu;
		}
		p = linebuf;
		/* skip spaces */
		while ((*p == ' ') || (*p == '\t'))
			p++;
		bufsize += ln_size;
		buf = (char *)Xrealloc(buf, bufsize);
	}

	for (i = 0; (field = mandatory_fields[i]) != NULL; i++) {
		if (strstr(buf, field) == NULL)
			continue;
		/* one of mandatory fields found */
		free(linebuf);
		free(buf);
		(void) munmap(addr, fsize);
		if (verbose)
			diag(gettext(DIAG_GNU_FOUND));
		invoke_gnu_msgfmt();
		/* NOTREACHED */
	}
	for (i = 0; (field = mandatory_fields_new[i]) != NULL; i++) {
		if (strstr(buf, field) == NULL)
			continue;
		/* one of mandatory fields found */
		free(linebuf);
		free(buf);
		(void) munmap(addr, fsize);
		if (verbose)
			diag(gettext(DIAG_GNU_FOUND));
		invoke_gnu_msgfmt();
		/* NOTREACHED */
	}

no_gnu:
	free(linebuf);
	if (buf)
		free(buf);
}
コード例 #30
0
ファイル: array.c プロジェクト: triplekill/orchids
void
array_shrink(array_t *array)
{
  array->size = array->length - (array->length % array->grow) + array->grow;
  array->array = Xrealloc(array->array, array->size * sizeof (void *));
}