static void AddToBlock(struct block *block,char *mapname, char *dir) {
    int i, val, j;
    int len = strlen(mapname);

    if ( mapname[len-7]=='.' ) len -= 7;
    for ( i=0; i<block->cur; ++i ) {
        if ( (val=strncmp(block->maps[i],mapname,len))==0 )
            return;		/* Duplicate */
        else if ( val>0 )
            break;
    }
    if ( block->tot==0 ) {
        block->tot = 10;
        block->maps = galloc(10*sizeof(char *));
        block->dirs = galloc(10*sizeof(char *));
    } else if ( block->cur>=block->tot ) {
        block->tot += 10;
        block->maps = grealloc(block->maps,block->tot*sizeof(char *));
        block->dirs = grealloc(block->dirs,block->tot*sizeof(char *));
    }
    for ( j=block->cur; j>=i; --j ) {
        block->maps[j+1] = block->maps[j];
        block->dirs[j+1] = block->dirs[j];
    }
    block->maps[i] = copyn(mapname,len);
    block->dirs[i] = dir;
    ++block->cur;
}
Example #2
0
/* addtree: add a node with w, at or below p */
struct tnode *addtree(struct tnode *p, char *w)
{
	int cond;
	struct tgroup *newgroup;

	if (p == NULL) {
		p = talloc();
		p->stub = _strdup(w, firstn);
		p->left = p->right = NULL;

		p->group = galloc();
		p->group->word = _strdup(w, -1);
		p->group->next = NULL;
	} else if ((cond = strncmp(w, p->stub, firstn)) == 0) {
		for (newgroup = p->group; newgroup != NULL && strcmp(newgroup->word, w); newgroup = newgroup->next);
		if (newgroup == NULL) {
			newgroup = galloc();
			newgroup->word = _strdup(w, -1);
			newgroup->next = p->group;
			p->group = newgroup;
		}
	} else if (cond < 0)
		p->left = addtree(p->left, w);
	else
		p->right = addtree(p->right, w);
	return p;
}
int pdb_parse(char* pdb_filename, char* itp_filename) {
  /*
   * This is the main parsing routine, which is visible to the outside
   * through the header electrokinetics_pdb_parse.h. It doesn't contain any logic and just
   * deploys the input to the subroutines.
   */

  /* BEGIN DEPLOY */
  galloc( (void**) &pdb_charge_lattice, ek_parameters.dim_x * ek_parameters.dim_y * ek_parameters.dim_z * sizeof(float));
  galloc( (void**) &pdb_boundary_lattice, ek_parameters.dim_x * ek_parameters.dim_y * ek_parameters.dim_z * sizeof(int));
  for ( unsigned int i = 0; i < ek_parameters.dim_x * ek_parameters.dim_y * ek_parameters.dim_z; i++ ) {
    pdb_charge_lattice[i] = 0.0;
    pdb_boundary_lattice[i] = 0;
  }

  particle_data atom_data;
  atom_data.pdb_n_particles = 0;
  atom_data.pdb_array_ATOM = NULL;
  atom_data.itp_n_particles = 0;
  atom_data.itp_array_atoms = NULL;
  atom_data.itp_n_parameters = 0;
  atom_data.itp_array_atomtypes = NULL;

  pdb_parse_files(pdb_filename, itp_filename, &atom_data);

  populate_lattice(&atom_data);

  return pdb_SUCCESS;
}
Example #4
0
static void find_fonts_callback(GtkFileChooser *dialog) {
    GSList *files = gtk_file_chooser_get_filenames(dialog);
    GSList *test;
    int len, cnt, i;
    char ***fonts, *pt, *text;

    if ( files==NULL || (cnt = g_slist_length(files))==0 )
	gtk_widget_set_tooltip_text(GTK_WIDGET(dialog),"");
    else {
	fonts = gcalloc(cnt,sizeof(char **));
	cnt = len = 0;
	for ( test=files; test!=NULL; test=test->next, ++cnt) {
	    fonts[cnt] = GetFontNames((char *) (test->data));
	    if ( fonts[cnt]!=NULL ) {
		len += 4*strlen((char *) (test->data))+1;	/* allow space for utf8 conversion */
		for ( i=0; fonts[cnt][i]!=NULL; ++i )
		    len += strlen( fonts[cnt][i])+2;
	    }
	}
	pt = text = galloc(len+10);
	cnt = 0;
	for ( test=files; test!=NULL; test=test->next, ++cnt) {
	    if ( fonts[cnt]!=NULL ) {
		/* If there is only one file selected, don't bother to name it */
		if ( cnt!=0 || test->next!=NULL ) {
		    gsize junk;
		    char *temp = g_filename_to_utf8(GFileNameTail( (char *) (test->data) ),
			    -1, &junk, &junk, NULL);
		    strcpy(pt,temp);
		    g_free(temp);
		    pt += strlen(pt);
		    *pt++ = '\n';
		}
		for ( i=0; fonts[cnt][i]!=NULL; ++i ) {
		    *pt++ = ' ';
		    strcpy(pt,fonts[cnt][i]);
		    free(fonts[cnt][i]);
		    pt += strlen(pt);
		    *pt ++ = '\n';
		}
		free(fonts[cnt]);
	    }
	}
	if ( pt>text && pt[-1]=='\n' )
	    pt[-1]='\0';
	else
	    *pt = '\0';
	free(fonts);
	if ( *text=='\0' )
	    gtk_widget_set_tooltip_text(GTK_WIDGET(dialog), "???");
	else {
	    gtk_widget_set_tooltip_text(GTK_WIDGET(dialog), text);
	}
	free(text);
    }

    for ( test=files; test!=NULL; test=test->next)
	g_free(test->data);
    g_slist_free(files);
}
Example #5
0
static void AddR(char *prog, char *name, char *val ) {
    char *full = galloc(strlen(name)+strlen(val)+4);
    strcpy(full,name);
    strcat(full,": ");
    strcat(full,val);
    GResourceAddResourceString(full,prog);
}
Example #6
0
File: gaexpr.c Project: cjg/grads
struct gagrid *gagrvl (gadouble val) {
struct gagrid *pgr;
gaint i;
gaint size;

  /* Allocate memory */ 
  size = sizeof(struct gagrid);
  pgr = (struct gagrid *)galloc(size,"pgr1");
  if (pgr==NULL) {
    gaprnt (0,"Unable to allocate memory for grid structure \n");
    return (NULL);
  }
  /* Fill in gagrid variables */
  pgr->pfile = NULL;
  pgr->undef = -9.99E33;
  pgr->pvar  = NULL;
  pgr->idim  = -1;
  pgr->jdim  = -1;
  pgr->alocf = 0;
  for (i=0;i<5;i++) {
    pgr->dimmin[i]=0;
    pgr->dimmax[i]=0;
  }
  pgr->rmin = val;
  pgr->rmax = val;
  pgr->grid = &pgr->rmin;
  pgr->umin = 1;
  pgr->umask = &pgr->umin;
  pgr->isiz = 1;
  pgr->jsiz = 1;
  pgr->exprsn = NULL;
  return (pgr);
}
Example #7
0
static int JSTF_Glyph_OK(GGadget *g, GEvent *e) {

    if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
	struct glyph_list_dlg *gld = GDrawGetUserData(GGadgetGetWindow(g));
	int rows, i, len;
	struct matrix_data *strings = GMatrixEditGet(GWidgetGetControl(gld->gw,CID_Glyphs), &rows);
	char *ret;

	if ( rows==0 )
	    gld->ret = NULL;
	else {
	    len = 0;
	    for ( i=0; i<rows; ++i )
		len += strlen(strings[1*i+0].u.md_str) +1;
	    ret = galloc(len+1);
	    for ( i=0; i<rows; ++i ) {
		strcpy(ret,strings[1*i+0].u.md_str);
		strcat(ret," ");
		ret += strlen(ret);
	    }
	    if ( ret>gld->ret && ret[-1] == ' ' )
		ret[-1] = '\0';
	    gld->ret = GlyphNameListDeUnicode(ret);
	    free(ret);
	}
	gld->done = true;
    }
return( true );
}
Example #8
0
static void parse_KernData_line(struct temp_font *tf, char *line) {
    int ch, ch2, kern;
    char name[200], name2[200];
    struct kern_info *ki;

    while ( isspace(*line)) ++line;
    if ( *line=='\0' )
return;
    if ( sscanf(line,"KPX %s %s %d", name, name2, &kern )!= 3 ) {
	if ( sscanf(line,"KP %s %s %d", name, name2, &kern )!= 3 ) {
	    fprintf( stderr, "Bad afm kern line <%s>\n", line );
return;
	}
    }
    if ( (ch = find_char(tf,name))== -1 ) {
	if ( tf->is_8859_1 )
	    fprintf( stderr, "Unknown character name <%s>\n", name );
return;
    }
    if ( (ch2 = find_char(tf,name2))== -1 ) {
	if ( tf->is_8859_1 )
	    fprintf( stderr, "Unknown character name <%s>\n", name2 );
return;
    }
    tf->per_char[ch].attributes |= AFM_KERN;
    ki = galloc(sizeof(struct kern_info));
    ki->next = tf->kerns[ch];
    tf->kerns[ch] = ki;
    ki->following = ch2;
    ki->kern = kern;
}
Example #9
0
gww_iconv_t gww_iconv_open(const char *toenc,const char *fromenc) {
    struct gww_iconv_t stuff, *ret;

    if ( endian==end_unknown )
	endian_detector();

    stuff.from = name_to_enc(fromenc);
    stuff.to = name_to_enc(toenc);
    if ( stuff.from==(enum encoding) -1 || stuff.to==(enum encoding) -1 ) {
	/*fprintf( stderr, "Unknown encoding\n" );*/
return( (iconv_t)(-1) );
#ifdef UNICHAR_16
    } else if ( stuff.from!=e_unicode && stuff.to!=e_unicode ) {
	fprintf( stderr, "Bad call to gww_iconv_open, neither arg is UCS2\n" );
return( (iconv_t)(-1) );
#else
    } else if ( stuff.from!=e_ucs4 && stuff.to!=e_ucs4 ) {
	fprintf( stderr, "Bad call to gww_iconv_open, neither arg is UCS4\n" );
return( (iconv_t)(-1) );
#endif
    }

    ret = galloc(sizeof(struct gww_iconv_t));
    *ret = stuff;
return( ret );
}
Example #10
0
static int AddProtocol(unichar_t *prefix,int len) {

    if ( plen>=pmax ) {
	pmax += 20;		/* We're never going to support 20 protocols? */
	if ( plen==0 ) {
	    protocols = (struct protocols *) galloc(pmax*sizeof(struct protocols));
	} else {
	    protocols = (struct protocols *) grealloc(protocols,pmax*sizeof(struct protocols));
	}
    }
    memset(protocols+plen,0,sizeof(struct protocols));
    if ( uc_strncmp(prefix,"file",len)==0 ) {
	protocols[plen].handle = NULL;
	protocols[plen].dispatcher = _GIO_fileDispatch;
	protocols[plen].cancel = NULL;
	protocols[plen].term = NULL;
	protocols[plen].dothread = false;
    } else {
return( false );
    }
    protocols[plen].index = plen;
    protocols[plen].proto = u_copyn(prefix,len);
    ++plen;
return( true );
}
Example #11
0
static int Filter_OK(GGadget *g, GEvent *e) {
    struct filter_d *d;
    struct matrix_data *md;
    int rows,i,cnt;

    if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
	if ( user_font_filters!=NULL ) {
	    for ( i=0; user_font_filters[i].name!=NULL; ++i ) {
		free(user_font_filters[i].name);
		free(user_font_filters[i].filter);
	    }
	    free(user_font_filters);
	    user_font_filters = NULL;
	}
	d = GDrawGetUserData(GGadgetGetWindow(g));
	md = GMatrixEditGet(d->gme,&rows);
	for ( i=cnt=0; i<rows; ++i )
	    if ( !md[2*i].frozen )
		++cnt;
	if ( cnt!=0 ) {
	    user_font_filters = galloc((cnt+1)*sizeof(struct openfilefilters));
	    for ( i=cnt=0; i<rows; ++i ) if ( !md[2*i].frozen ) {
		user_font_filters[cnt].name = copy(md[2*i].u.md_str);
		user_font_filters[cnt].filter = copy(md[2*i+1].u.md_str);
		++cnt;
	    }
	    user_font_filters[cnt].name = user_font_filters[cnt].filter = NULL;
	}
	SavePrefs(true);
	d->done = true;
    }
return( true );
}
Example #12
0
void SCOrderAP(SplineChar *sc) {
    int lc=0, cnt=0, out=false, i,j;
    AnchorPoint *ap, **array;
    /* Order so that first ligature index comes first */

    for ( ap=sc->anchor; ap!=NULL; ap=ap->next ) {
	if ( ap->lig_index<lc ) out = true;
	if ( ap->lig_index>lc ) lc = ap->lig_index;
	++cnt;
    }
    if ( !out )
return;

    array = galloc(cnt*sizeof(AnchorPoint *));
    for ( i=0, ap=sc->anchor; ap!=NULL; ++i, ap=ap->next )
	array[i] = ap;
    for ( i=0; i<cnt-1; ++i ) {
	for ( j=i+1; j<cnt; ++j ) {
	    if ( array[i]->lig_index>array[j]->lig_index ) {
		ap = array[i];
		array[i] = array[j];
		array[j] = ap;
	    }
	}
    }
    sc->anchor = array[0];
    for ( i=0; i<cnt-1; ++i )
	array[i]->next = array[i+1];
    array[cnt-1]->next = NULL;
    free( array );
}
Example #13
0
static void SplitSpirosAndAddAndCut(SplineSet *spl,SplineSet *spl2,int spiro_index) {
    /* OK, spl was an open contour and we just cut it at spiro_index */
    /* We don't need to rotate the spiros */
    /* The first half of spl remains in it. (We'll leave all spiros up to and including spiro_index) */
    /* If spl->spiros[spiro_index] != spl->first->me we must add spl->first here */
    /* In the spl2 we either start out with spl->spiros[spiro_index] or with spl->first */
    /* then add all spiros after spiro_index */

    spl2->spiros = galloc((spl->spiro_cnt-spiro_index+2) * sizeof(spiro_cp));
    spl2->spiro_max = spl->spiro_cnt-spiro_index+2;
    if ( spl2->first->me.x == spl->spiros[spiro_index].x &&
            spl2->first->me.y == spl->spiros[spiro_index].y ) {
        memcpy(spl2->spiros,spl->spiros+spiro_index,(spl->spiro_cnt-spiro_index)*sizeof(spiro_cp));
        spl2->spiros[0].ty = SPIRO_OPEN_CONTOUR;
        memcpy(spl->spiros+spiro_index+1,spl->spiros+spl->spiro_cnt-1,sizeof(spiro_cp));
        spl2->spiro_cnt = spl->spiro_cnt-spiro_index;
        spl->spiro_cnt = spiro_index+2;
    } else {
        spl2->spiros[0].x = spl2->first->me.x;
        spl2->spiros[0].y = spl2->first->me.y;
        spl2->spiros[0].ty = SPIRO_OPEN_CONTOUR;
        memcpy(spl2->spiros+1,spl->spiros+spiro_index+1,(spl->spiro_cnt-(spiro_index+1))*sizeof(spiro_cp));
        spl2->spiro_cnt = spl->spiro_cnt-spiro_index;
        if ( spiro_index+3>spl->spiro_max )
            spl->spiros = grealloc(spl->spiros,(spl->spiro_max=spiro_index+3)*sizeof(spiro_cp));
        memcpy(spl->spiros+spiro_index+1,spl2->spiros,sizeof(spiro_cp));
        spl->spiros[spiro_index+1].ty = SPIRO_G4;
        memcpy(spl->spiros+spiro_index+2,spl->spiros+spl->spiro_cnt-1,sizeof(spiro_cp));
        spl->spiro_cnt = spiro_index+3;
    }
}
Example #14
0
static void find_scanline(FILE *fp,struct sgiheader *header,int cur,
	unsigned long *starttab,unsigned char **ptrtab) {
    extern int fgetc(FILE *);
    int (*getthingamy)(FILE *) = header->bpc==1?fgetc:getshort;
    int ch,i,cnt,val;
    unsigned char *pt;

    for ( i=0; i<cur; ++i )
	if ( starttab[i]==starttab[cur] ) {
	    ptrtab[cur] = ptrtab[i];
return;
	}
    pt = ptrtab[cur] = galloc(header->width);
    fseek(fp,starttab[cur],0);
    while (1) {
	ch = getthingamy(fp);
	if (( cnt = (ch&0x7f))==0 )
return;
	if ( ch&0x80 ) {
	    while ( --cnt>=0 )
		*pt++ = getthingamy(fp)*255L/header->pixmax;
	} else {
	    val = getthingamy(fp)*255L/header->pixmax;
	    while ( --cnt>= 0 )
		*pt++ = val;
	}
    }
}
Example #15
0
static int JSTF_Lookup_OK(GGadget *g, GEvent *e) {

    if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
	struct glyph_list_dlg *gld = GDrawGetUserData(GGadgetGetWindow(g));
	int rows, i, len;
	struct matrix_data *strings = GMatrixEditGet(GWidgetGetControl(gld->gw,CID_Lookups), &rows);
	char *ret;

	if ( rows==0 )
	    gld->ret = NULL;
	else {
	    len = 0;
	    for ( i=0; i<rows; ++i ) {
		OTLookup *otl = (OTLookup *) strings[1*i+0].u.md_ival;
		len += strlen(otl->lookup_name) +2;
	    }
	    gld->ret = ret = galloc(len+1);
	    for ( i=0; i<rows; ++i ) {
		OTLookup *otl = (OTLookup *) strings[1*i+0].u.md_ival;
		strcpy(ret,otl->lookup_name);
		strcat(ret,", ");
		ret += strlen(ret);
	    }
	    if ( ret>gld->ret && ret[-1] == ' ' )
		*--ret = '\0';
	    if ( ret>gld->ret && ret[-1] == ',' )
		*--ret = '\0';
	}
	gld->done = true;
    }
return( true );
}
Example #16
0
char *copy(const char *str) {
    char *ret;

    if ( str==NULL )
return( NULL );
    ret = galloc(strlen(str)+1);
    strcpy(ret,str);
return( ret );
}
Example #17
0
SplineSet *SpiroCP2SplineSet(spiro_cp *spiros) {
    int n;
    int any = 0;
    spiro_cp *nspiros;
    SplineSet *ss;
    int lastty = 0;

    if ( spiros==NULL )
return( NULL );
    for ( n=0; spiros[n].ty!=SPIRO_END; ++n )
	if ( SPIRO_SELECTED(&spiros[n]) )
	    ++any;
    if ( n==0 )
return( NULL );
    if ( n==1 ) {
	ss = chunkalloc(sizeof(SplineSet));
	ss->first = ss->last = SplinePointCreate(spiros[0].x,spiros[0].y);
    } else {
	bezctx *bc = new_bezctx_ff();
	if ( (spiros[0].ty&0x7f)=='{' ) {
	    lastty = spiros[n-1].ty;
	    spiros[n-1].ty = '}';
	}

	if ( !any ) {
#if _LIBSPIRO_FUN
	    if ( TaggedSpiroCPsToBezier0(spiros,bc)==0 ) {
		return( NULL );
	    }
#else
	    TaggedSpiroCPsToBezier(spiros,bc);
#endif
	} else {
	    nspiros = galloc((n+1)*sizeof(spiro_cp));
	    memcpy(nspiros,spiros,(n+1)*sizeof(spiro_cp));
	    for ( n=0; nspiros[n].ty!=SPIRO_END; ++n )
		nspiros[n].ty &= ~0x80;
#if _LIBSPIRO_FUN
	    if ( TaggedSpiroCPsToBezier0(nspiros,bc)==0 ) {
		free(nspiros);
		return( NULL );
	    }
#else
	    TaggedSpiroCPsToBezier(nspiros,bc);
#endif
	    free(nspiros);
	}
	ss = bezctx_ff_close(bc);

	if ( (spiros[0].ty&0x7f)=='{' )
	    spiros[n-1].ty = lastty;
    }
    ss->spiros = spiros;
    ss->spiro_cnt = ss->spiro_max = n+1;
    SPLCatagorizePoints(ss);
return( ss );
}
Example #18
0
char *copyn(const char *str,long n) {
    char *ret;

    if ( str==NULL )
return( NULL );
    ret = galloc(n+1);
    memcpy(ret,str,n);
    ret[n]='\0';
return( ret );
}
Example #19
0
void
st_memory(void)
{
  enum { P = N/2/sizeof(void*) };
  static OBJ arr[P];
  useclass(Counter, AutoRelease);
  OBJ ar = gnew(AutoRelease);
  size_t sz = gsize(Counter);
  size_t i;
  int lvl;

  // allocator warm up
  for (i = 0; i < P; i++)
    arr[i++] = malloc(sz);

  for (i = 0; i < P; i++)
    free(arr[i++]);

  i = 0;
  STEST( "malloc", P, arr[i++] = malloc(sz) );

  i = 0;
  STEST( "free", P, free(arr[i++]) );

  i = 0;
  STEST( "alloc + init", P, arr[i++] = ginit(galloc(Counter)) );

  i = 0;
  STEST( "retain", P, gretain(arr[i++]) );

  i = 0;
  lvl = cos_logmsg_setLevel(COS_LOGMSG_WARN);
  STEST( "autoRelease", P, gautoRelease(arr[i++]) );
  cos_logmsg_setLevel(lvl);

  i = 0;
  STEST( "release", P, grelease(arr[i++]) );

  STEST( "alloc + init + release", P, grelease(ginit(galloc(Counter))) );

  grelease(ar);
}
Example #20
0
static void ReorderSpirosAndAddAndCut(SplineSet *spl,int spiro_index) {
    /* We just cut a closed contour. It is now open. */
    /* If spl->spiros[spiro_index] == spl->first->me then they cut on top of */
    /*  a point which already existed */
    /*   If so, move that point to the head of the list */
    /*   copy it so that it's at the end of the list too */
    /*   mark the start as SPIRO_OPEN */
    /* Otherwise they cut between spiro_cps */
    /*  Insert 2 copies of spl->first->me after spiro_index */
    /*  rotate so that one of these is at the end of the list and the other at the start */
    /*  mark start as SPIRO_OPEN */
    spiro_cp *newspiros;

    if ( spiro_index!=spl->spiro_cnt-1 &&
            spl->first->me.x == spl->spiros[spiro_index].x &&
            spl->first->me.y == spl->spiros[spiro_index].y ) {
        newspiros = galloc((spl->spiro_cnt+1) * sizeof(spiro_cp));
        memcpy(newspiros,spl->spiros+spiro_index,(spl->spiro_cnt-1-spiro_index)*sizeof(spiro_cp));
        memcpy(newspiros+(spl->spiro_cnt-1-spiro_index),spl->spiros,spiro_index*sizeof(spiro_cp));
        memcpy(newspiros+spl->spiro_cnt-1,newspiros,sizeof(spiro_cp));
        memcpy(newspiros+spl->spiro_cnt,spl->spiros+spl->spiro_cnt-1,sizeof(spiro_cp));
        newspiros[0].ty = SPIRO_OPEN_CONTOUR;
        free(spl->spiros);
        spl->spiros = newspiros;
        ++(spl->spiro_cnt);
        spl->spiro_max = spl->spiro_cnt;
    } else {
        newspiros = galloc((spl->spiro_cnt+2) * sizeof(spiro_cp));
        newspiros[0].x = spl->first->me.x;
        newspiros[0].y = spl->first->me.y;
        newspiros[0].ty = SPIRO_OPEN_CONTOUR;
        memcpy(newspiros+1,spl->spiros+spiro_index+1,(spl->spiro_cnt-1-(spiro_index+1))*sizeof(spiro_cp));
        memcpy(newspiros+1+(spl->spiro_cnt-1-(spiro_index+1)),spl->spiros,(spiro_index+1)*sizeof(spiro_cp));
        memcpy(newspiros+spl->spiro_cnt,newspiros,sizeof(spiro_cp));
        memcpy(newspiros+spl->spiro_cnt+1,spl->spiros+spl->spiro_cnt-1,sizeof(spiro_cp));
        newspiros[spl->spiro_cnt].ty = SPIRO_G4;
        free(spl->spiros);
        spl->spiros = newspiros;
        spl->spiro_cnt += 2;
        spl->spiro_max = spl->spiro_cnt;
    }
}
Example #21
0
static int WithinList(struct gfc_data *d,GEvent *event) {
    GRect size;
    GGadget *list;
    int32 pos;
    unichar_t *ufile;
    char *file, **fontnames;
    int cnt, len;
    unichar_t *msg;

    if ( event->type!=et_mousemove )
return( false );

    GFileChooserGetChildren(d->gfc,NULL, &list, NULL);
    if ( list==NULL )
return( false );
    GGadgetGetSize(list,&size);
    if ( event->u.mouse.x < size.x || event->u.mouse.y <size.y ||
	    event->u.mouse.x >= size.x+size.width ||
	    event->u.mouse.y >= size.y+size.height )
return( false );
    pos = GListIndexFromY(list,event->u.mouse.y);
    if ( pos == d->filename_popup_pos )
return( pos!=-1 );
    if ( pos==-1 || GFileChooserPosIsDir(d->gfc,pos)) {
	d->filename_popup_pos = -1;
return( pos!=-1 );
    }
    ufile = GFileChooserFileNameOfPos(d->gfc,pos);
    if ( ufile==NULL )
return( true );
    file = u2def_copy(ufile);

    fontnames = GetFontNames(file);
    if ( fontnames==NULL || fontnames[0]==NULL )
	msg = uc_copy( "???" );
    else {
	len = 0;
	for ( cnt=0; fontnames[cnt]!=NULL; ++cnt )
	    len += strlen(fontnames[cnt])+1;
	msg = galloc((len+2)*sizeof(unichar_t));
	len = 0;
	for ( cnt=0; fontnames[cnt]!=NULL; ++cnt ) {
	    uc_strcpy(msg+len,fontnames[cnt]);
	    len += strlen(fontnames[cnt]);
	    msg[len++] = '\n';
	}
	msg[len-1] = '\0';
    }
    GGadgetPreparePopup(GGadgetGetWindow(d->gfc),msg);
    free(file);
    free(d->lastpopupfontname);
    d->lastpopupfontname = msg;
return( true );
}
Example #22
0
static void buildXFont(struct temp_font *tf,struct font_data *fd) {
    XFontStruct *info;
    int i;
    
    fd->info = info = galloc(sizeof(XFontStruct));
    /* Where do I get the ascent and descent out of a postscript font???? */
    if ( tf->font_as!=0 && tf->font_ds!=0 ) {
	info->ascent = tf->font_as + (1000-tf->font_as+tf->font_ds)/2;
    } else
	info->ascent = tf->ury + (1000-tf->ury+tf->lly)/2;
    info->descent = 1000-info->ascent;
    info->min_bounds = tf->min_b;
    info->max_bounds = tf->max_b;
    if ( tf->x_h!=0 || tf->cap_h!=0 ) {
	info->n_properties = (tf->x_h!=0)+(tf->cap_h!=0);
	info->properties = galloc( info->n_properties*sizeof( XFontProp));
	i=0;
	if ( tf->x_h!=0 ) {
	    info->properties[i].name = XA_X_HEIGHT;
	    info->properties[i++].card32 = tf->x_h;
	}
	if ( tf->cap_h!=0 ) {
	    info->properties[i].name = XA_CAP_HEIGHT;
	    info->properties[i++].card32 = tf->cap_h;
	}
    }
    if ( tf->max_ch>=256 ) {
	int i,row;
	info->min_byte1 = tf->min_ch>>8;
	info->max_byte1 = tf->max_ch>>8;
	info->min_char_or_byte2 = tf->min_ch2;
	info->max_char_or_byte2 = tf->max_ch2;
	row = (info->max_char_or_byte2-info->min_char_or_byte2+1);
 	info->per_char = galloc((info->max_byte1-info->min_byte1+1)*
 		row*sizeof(XCharStruct));
 	for ( i=info->min_byte1; i<info->max_byte1; ++i )
	    memcpy(info->per_char+(i-info->min_byte1)*row,
		    tf->per_char+i*256+info->min_char_or_byte2,
		    row*sizeof(XCharStruct));
	/* Don't support kerns here */
   } else {
Example #23
0
spiro_cp *SpiroCPCopy(spiro_cp *spiros,uint16 *_cnt) {
    int n;
    spiro_cp *nspiros;

    if ( spiros==NULL )
return( NULL );
    for ( n=0; spiros[n].ty!='z'; ++n );
    nspiros = galloc((n+1)*sizeof(spiro_cp));
    memcpy(nspiros,spiros,(n+1)*sizeof(spiro_cp));
    if ( _cnt != NULL ) *_cnt = n+1;
return( nspiros );
}
Example #24
0
static struct cidmap *MakeDummyMap(char *registry,char *ordering,int supplement) {
    struct cidmap *ret = galloc(sizeof(struct cidmap));

    ret->registry = copy(registry);
    ret->ordering = copy(ordering);
    ret->supplement = ret->maxsupple = supplement;
    ret->cidmax = ret->namemax = 0;
    ret->unicode = NULL; ret->name = NULL;
    ret->next = cidmaps;
    cidmaps = ret;
return( ret );
}
int pdb_parse(char* pdb_filename, char* itp_filename, double scale) {
  /*
   * This is the main parsing routine, which is visible to the outside
   * through the header electrokinetics_pdb_parse.h. It doesn't contain any logic and just
   * deploys the input to the subroutines.
   */

  /* BEGIN DEPLOY */
  galloc( (void**) &pdb_charge_lattice, ek_parameters.dim_x * ek_parameters.dim_y * ek_parameters.dim_z * sizeof(float));
  galloc( (void**) &pdb_boundary_lattice, ek_parameters.dim_x * ek_parameters.dim_y * ek_parameters.dim_z * sizeof(int));
  for ( unsigned int i = 0; i < ek_parameters.dim_x * ek_parameters.dim_y * ek_parameters.dim_z; i++ ) {
    pdb_charge_lattice[i] = 0.0;
    pdb_boundary_lattice[i] = 0;
  }

  PdbParser::PdbParser parser;
  if(!parser.parse_file(pdb_filename, itp_filename))
    return pdb_ERROR;

  return populate_lattice(parser, scale);
}
Example #26
0
static char *getLocaleDir(void) {
    static char *sharedir=NULL;
    static int set=false;
    char *pt;
    int len;

    if ( set )
return( sharedir );

    set = true;

#if defined(__MINGW32__)

    len = strlen(GResourceProgramDir) + strlen("/share/locale") +1;
    sharedir = galloc(len);
    strcpy(sharedir, GResourceProgramDir);
    strcat(sharedir, "/share/locale");
    return sharedir;

#else

    pt = strstr(GResourceProgramDir,"/bin");
    if ( pt==NULL ) {
#if defined(SHAREDIR)
return( sharedir = SHAREDIR "/../locale" );
#elif defined( PREFIX )
return( sharedir = PREFIX "/share/locale" );
#else
	pt = GResourceProgramDir + strlen(GResourceProgramDir);
#endif
    }
    len = (pt-GResourceProgramDir)+strlen("/share/locale")+1;
    sharedir = galloc(len);
    strncpy(sharedir,GResourceProgramDir,pt-GResourceProgramDir);
    strcpy(sharedir+(pt-GResourceProgramDir),"/share/locale");
return( sharedir );

#endif
}
Example #27
0
static void do_windows_browser(char *fullspec) {
    char *format, *start, *pt, ch, *temp, *cmd;

    format = win_program_from_extension(".html");
    if ( format==NULL )
	format = win_program_from_extension(".htm");
    if ( format==NULL ) {
	gwwv_post_error(_("No Browser"),_("Could not find a browser. Set the BROWSER environment variable to point to one"));
return;
    }

    if ( format[0]=='"' || format[0]=='\'' ) {
	start = format+1;
	pt = strchr(start,format[0]);
    } else {
	start = format;
	pt = strchr(start,' ');
    }
    if ( pt==NULL ) pt = start+strlen(start);
    ch = *pt; *pt='\0';

    temp = galloc(strlen(start)+300+ (ch==0?0:strlen(pt+1)));
    cygwin_conv_to_full_posix_path(start,temp+1);
    temp[0]='"'; strcat(temp,"\" ");
    if ( ch!='\0' )
	strcat(temp,pt+1);
    cmd = galloc(strlen(temp)+strlen(fullspec)+8);
    if ( strstr("%s",temp)!=NULL )
	sprintf( cmd, temp, fullspec );
    else {
	strcpy(cmd,temp);
	strcat(cmd, " ");
	strcat(cmd,fullspec);
    }
    strcat(cmd," &" );
    system(cmd);
    free( cmd ); free( temp ); free( format );
}
Example #28
0
void *gwwv_dlopen(char *name,int flags) {
#undef dlopen
    void *lib = dlopen(name,flags);
    char *temp;

    if (( lib!=NULL && lib!=(void *) -1) || name==NULL || *name=='/' )
return( lib );

    temp = galloc( strlen("/sw/lib/") + strlen(name) +1 );
    strcpy(temp,"/sw/lib/");
    strcat(temp,name);
    lib = dlopen(temp,flags);
    free(temp);
    if ( lib!=NULL && lib!=(void *) -1 )
return( lib );

    temp = galloc( strlen("/opt/local/lib/") + strlen(name) +1 );
    strcpy(temp,"/opt/local/lib/");
    strcat(temp,name);
    lib = dlopen(temp,flags);
    free(temp);
return( lib );
}
Example #29
0
const void *gwwv_NSAddImage(char *name,uint32_t options) {
    const void *lib = NSAddImage(name,options);
    char *temp;

    if (( lib!=NULL && lib!=(void *) -1) || name==NULL || *name=='/' )
return( lib );

    temp = galloc( strlen("/sw/lib/") + strlen(name) +1 );
    strcpy(temp,"/sw/lib/");
    strcat(temp,name);
    lib = NSAddImage(temp,options);
    free(temp);
return( lib );
}
Example #30
0
void *memAlloc(MEMBLK **arena, int size)
{
    MEMBLK *selected = *arena;
    void *rv;
    if (!selected || selected->left < size)
    {
        selected = galloc(arena, size);
    }
    rv = (void *)(selected->m + selected->size -selected->left);
#ifdef DEBUG
    memset(rv, 0, size);
#endif
    selected->left = selected->left - ((size + MALIGN - 1) & -MALIGN);
    return rv;
}