예제 #1
0
void write_point_mesh(const char *filename, int ub, int npts, float *pts,
                      int nvars, int *vardim, const char * const *varnames,
                      float **vars)
{
    int   i;
    char  str[128];
    int  *centering = NULL;

    useBinary = ub;
    open_file(filename);
    write_header();

    write_string("DATASET UNSTRUCTURED_GRID\n");
    sprintf(str, "POINTS %d float\n", npts);
    write_string(str);
    for (i = 0 ; i < 3*npts ; i++)
    {
        write_float(pts[i]);
    }

    new_section();
    sprintf(str, "CELLS %d %d\n", npts, 2*npts);
    write_string(str);
    for (i = 0 ; i < npts ; i++)
    {
        write_int(1);
        write_int(i);
        end_line();
    }

    new_section();
    sprintf(str, "CELL_TYPES %d\n", npts);
    write_string(str);
    for (i = 0 ; i < npts ; i++)
    {
        write_int(VISIT_VERTEX);
        end_line();
    }

    centering = (int *) malloc(nvars*sizeof(int));
    for (i = 0 ; i < nvars ; i++)
        centering[i] = 1;
    write_variables(nvars, vardim, centering, varnames, vars, npts, npts);
    free(centering);

    close_file();
}
예제 #2
0
void
dope(void)
{
	textsect = new_section(".text", textsize, 0);
	textsect->Characteristics = IMAGE_SCN_CNT_CODE|
		IMAGE_SCN_CNT_INITIALIZED_DATA|
		IMAGE_SCN_MEM_EXECUTE|IMAGE_SCN_MEM_READ;

	datsect = new_section(".data", datsize, 0);
	datsect->Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA|
		IMAGE_SCN_MEM_READ|IMAGE_SCN_MEM_WRITE;
	INITDAT = PEBASE+datsect->VirtualAddress;

	bsssect = new_section(".bss", bsssize, 1);
	bsssect->Characteristics = IMAGE_SCN_CNT_UNINITIALIZED_DATA|
		IMAGE_SCN_MEM_READ|IMAGE_SCN_MEM_WRITE;
}
예제 #3
0
파일: syntax.c 프로젝트: ezrec/vasm
static void stab_entry(char *name,int type,int othr,int desc,char *s)
{
  section *stabs;

  if (!(stabs = find_section(stabname,stabattr))) {
    section *str;
    dblock *db;

    stabs = new_section(stabname,stabattr,4);
    if (!(str = find_section(stabstrname,stabstrattr))) {
      str = new_section(stabstrname,stabstrattr,1);
    }
    else {
      if (str->pc != 0)
        ierror(0);
    }
    /* first byte of .stabstr is 0 */
    add_atom(str,new_space_atom(number_expr(1),1,0)); 
    /* compilation unit header has to be patched by output module */
    new_stabstr(getfilename());
    db = new_dblock();
    db->size = 12;
    db->data = mymalloc(12);
    add_atom(stabs,new_data_atom(db,1));
  }

  add_const_datadef(stabs,name?new_stabstr(name):0,32,1);
  add_const_datadef(stabs,type,8,1);
  add_const_datadef(stabs,othr,8,1);
  add_const_datadef(stabs,desc,16,1);
  if (s) {
    operand *op = new_operand();
    int len = oplen(skip_operand(s),s);

    if (parse_operand(s,len,op,DATA_OPERAND(32))) {
      atom *a = new_datadef_atom(32,op);

      a->align = 1;
      add_atom(stabs,a);
    }
    else
      syntax_error(8);
  }
  else
    add_atom(stabs,new_space_atom(number_expr(4),1,0));  /* no value */
}
예제 #4
0
static  void    finish_page_section( doc_section ds, bool eject )
{
    if( eject ) {
        g_skip = 0;                     // ignore remaining skip value
    }
    new_section( ds );
    do_page_out();
}
예제 #5
0
파일: vasm.c 프로젝트: ezrec/vasm
/* returns current_section or the syntax module's default section,
   when undefined */
section *default_section(void)
{
    section *sec = current_section;

    if (!sec && defsectname && defsecttype) {
        sec = new_section(defsectname,defsecttype,1);
        switch_section(defsectname,defsecttype);
    }
    return sec;
}
예제 #6
0
파일: syntax.c 프로젝트: ezrec/vasm
static void new_bss(char *s,int global)
{
  char *name;
  symbol *sym;
  atom *a;
  taddr size;
  section *bss;

  if(!(name=parse_identifier(&s))){
    syntax_error(10);  /* identifier expected */
    return;
  }
  size=comma_constexpr(&s);
  if(size<=sdlimit){
    if(!(bss=find_section(sbssname,sbssattr)))
      bss=new_section(sbssname,sbssattr,1);
  }
  else{
    if(!(bss=find_section(bssname,bssattr)))
      bss=new_section(bssname,bssattr,1);
  }
  sym=new_labsym(bss,name);
  sym->flags|=TYPE_OBJECT;
  if(global) sym->flags|=EXPORT;
  sym->size=number_expr(size);
  myfree(name);
  s=skip(s);
  if(*s==','){
    s=skip(s+1);
    sym->align=parse_constexpr(&s);
  }
  else
    sym->align=(size>=8)?8:4;
  a=new_label_atom(sym);
  if(sym->align)
    a->align=sym->align;
  add_atom(bss,a);
  a=new_space_atom(number_expr(size),1,0);
  if(sym->align)
    a->align=sym->align;
  add_atom(bss,a);
  eol(s);
}
예제 #7
0
void write_rectilinear_mesh(const char *filename, int ub, int *dims,
                            float *x, float *y, float *z,
                            int nvars, int *vardim, int *centering,
                            const char * const *varnames, float **vars)
{
    int   i;
    char  str[128];
    int npts = dims[0]*dims[1]*dims[2];
    int ncX = (dims[0] - 1 < 1 ? 1 : dims[0] - 1);
    int ncY = (dims[1] - 1 < 1 ? 1 : dims[1] - 1);
    int ncZ = (dims[2] - 1 < 1 ? 1 : dims[2] - 1);
    int ncells = ncX*ncY*ncZ;

    useBinary = ub;
    open_file(filename);
    write_header();

    write_string("DATASET RECTILINEAR_GRID\n");
    sprintf(str, "DIMENSIONS %d %d %d\n", dims[0], dims[1], dims[2]);
    write_string(str);
    sprintf(str, "X_COORDINATES %d float\n", dims[0]);
    write_string(str);
    for (i = 0 ; i < dims[0] ; i++)
        write_float(x[i]);
    new_section();
    sprintf(str, "Y_COORDINATES %d float\n", dims[1]);
    write_string(str);
    for (i = 0 ; i < dims[1] ; i++)
        write_float(y[i]);
    new_section();
    sprintf(str, "Z_COORDINATES %d float\n", dims[2]);
    write_string(str);
    for (i = 0 ; i < dims[2] ; i++)
        write_float(z[i]);

    write_variables(nvars, vardim, centering, varnames, vars, npts, ncells);

    close_file();
}
예제 #8
0
파일: vasm.c 프로젝트: ezrec/vasm
/* create a dummy code section for each new ORG directive and
   switches to it */
void new_org(taddr org)
{
    char buf[16];
    section *sec;

    sprintf(buf,"seg%08lx",(unsigned long)org);
    sec = new_section(mystrdup(buf),"acrwx",1);
    sec->org = sec->pc = org;
    current_section = sec;
#ifdef HAVE_CPU_OPTS
    cpu_opts_init(sec);  /* set initial cpu opts before the first atom */
#endif
}
예제 #9
0
void add_entry(char *section_name, char *key, char *value)
{
        section_t *s = get_section(section_name);
        if (s == NULL) {
                s = new_section(section_name);
        }

        s->entry_count++;
        int len = s->entry_count;
        s->entries = realloc(s->entries, sizeof(entry_t) * len);
        s->entries[s->entry_count - 1].key = g_strdup(key);
        s->entries[s->entry_count - 1].value = clean_value(value);
}
static BusDesktopFileSection* 
open_section (BusDesktopFileParser *parser,
              char                 *name)
{  
  BusDesktopFileSection *section;

  section = new_section (parser->desktop_file, name);
  if (section == NULL)
    return NULL;
  
  parser->current_section = parser->desktop_file->n_sections - 1;
  _dbus_assert (&parser->desktop_file->sections[parser->current_section] == section);
  
  return section;
}
예제 #11
0
파일: pe.c 프로젝트: HarryR/sanos
int pe_output_file(TCCState *s1, const char *filename) {
  int ret;
  struct pe_info pe;
  int i;

  memset(&pe, 0, sizeof pe);
  pe.filename = filename;
  pe.s1 = s1;

  // Generate relocation information by default for Sanos.
  if (s1->imagebase == 0xFFFFFFFF) {
    pe.reloc = new_section(s1, ".reloc", SHT_PROGBITS, 0);
    pe.imagebase = pe.type == PE_DLL ? 0x10000000 : 0x00400000;
  } else {
    pe.imagebase = s1->imagebase;
  }

  pe_add_runtime_ex(s1, &pe);
  relocate_common_syms(); // Assign bss adresses
  tcc_add_linker_symbols(s1);

  if (!s1->nofll) pe_eliminate_unused_sections(&pe);

  ret = pe_check_symbols(&pe);
  if (ret != 0) return ret;
  
  pe_assign_addresses(&pe);
  relocate_syms(s1, 0);

  for (i = 1; i < s1->nb_sections; ++i) {
    Section *s = s1->sections[i];
    if (s->reloc) {
      relocate_section(s1, s);
      pe_relocate_rva(&pe, s);
    }
  }

  if (s1->nb_errors) {
    ret = 1;
  } else {
    ret = pe_write(&pe);
  }

  if (s1->mapfile) pe_print_sections(s1, s1->mapfile);

  tcc_free(pe.sec_info);
  return ret;
}
예제 #12
0
파일: tccpe.c 프로젝트: 00shiv/Nimrod
PUB_FN int pe_output_file(TCCState * s1, const char *filename)
{
    int ret;
    struct pe_info pe;
    int i;

    memset(&pe, 0, sizeof pe);
    pe.filename = filename;
    pe.s1 = s1;

    pe_add_runtime_ex(s1, &pe);
    relocate_common_syms(); /* assign bss adresses */
    tcc_add_linker_symbols(s1);

    ret = pe_check_symbols(&pe);
    if (0 == ret) {
        if (PE_DLL == pe.type) {
            pe.reloc = new_section(pe.s1, ".reloc", SHT_PROGBITS, 0);
            pe.imagebase = 0x10000000;
        } else {
            pe.imagebase = 0x00400000;
        }
        pe_assign_addresses(&pe);
        relocate_syms(s1, 0);
        for (i = 1; i < s1->nb_sections; ++i) {
            Section *s = s1->sections[i];
            if (s->reloc) {
                relocate_section(s1, s);
                pe_relocate_rva(&pe, s);
            }
        }
        if (s1->nb_errors)
            ret = 1;
        else
            ret = pe_write(&pe);
        tcc_free(pe.sec_info);
    }

#ifdef PE_PRINT_SECTIONS
    pe_print_sections(s1, "tcc.log");
#endif
    return ret;
}
예제 #13
0
파일: dsplit.c 프로젝트: n-t-roff/DWB3.3
static void
new_page(void)

{

/*
 *
 * Check the page or byte limit before starting a new page. 
 * 
 */

    if ( ++pages > page_break  ||  bytes > byte_break )  {
	pages = 1;
	bytes = 500;			/* to cover section initialization */
	end_section();
	new_section();
    }	/* End if */

}   /* End of new_page */
예제 #14
0
파일: syntax.c 프로젝트: ezrec/vasm
static void handle_section(char *s)
{
  char *name,*attr;
  if(*s!='\"'){
    name=s;
    if(!ISIDSTART(*s)){
      syntax_error(10);
      return;
    }
    while(ISIDCHAR(*s))
      s++;
    name=cnvstr(name,s-name);
    s=skip(s);
  }else{
    s++;
    name=s;
    while(*s&&*s!='\"')
      s++;
    name=cnvstr(name,s-name);
    s=skip(s+1);
  }
  if(*s==','){
    s=skip(s+1);
    attr=s;
    if(*s!='\"')
      syntax_error(7);
    else
      s++;
    attr=s;
    while(*s&&*s!='\"')
      s++;    
    attr=cnvstr(attr,s-attr);
    s=skip(s+1);
  }else
    attr="";
  new_section(name,attr,1);
  switch_section(name,attr);
  eol(s);
}
예제 #15
0
파일: tccpe.c 프로젝트: 00shiv/Nimrod
PUB_FN int pe_load_res_file(TCCState *s1, int fd)
{
    struct pe_rsrc_header hdr;
    Section *rsrc_section;
    int i, ret = -1;
    BYTE *ptr;

    lseek (fd, 0, SEEK_SET);
    if (!read_n(fd, &hdr, sizeof hdr))
        goto quit;
    if (!pe_test_res_file(&hdr, sizeof hdr))
        goto quit;

    rsrc_section = new_section(s1, ".rsrc", SHT_PROGBITS, SHF_ALLOC);
    ptr = section_ptr_add(rsrc_section, hdr.sectionhdr.SizeOfRawData);
    lseek (fd, hdr.sectionhdr.PointerToRawData, SEEK_SET);
    if (!read_n(fd, ptr, hdr.sectionhdr.SizeOfRawData))
        goto quit;

    lseek (fd, hdr.sectionhdr.PointerToRelocations, SEEK_SET);
    for (i = 0; i < hdr.sectionhdr.NumberOfRelocations; ++i)
    {
        struct pe_rsrc_reloc rel;
        if (!read_n(fd, &rel, sizeof rel))
            goto quit;
        // printf("rsrc_reloc: %x %x %x\n", rel.offset, rel.size, rel.type);
        if (rel.type != 7) /* DIR32NB */
            goto quit;
        put_elf_reloc(symtab_section, rsrc_section,
            rel.offset, R_386_RELATIVE, 0);
    }
    ret = 0;
quit:
    if (ret)
        error_noabort("unrecognized resource file format");
    return ret;
}
예제 #16
0
void LayoutParser::parseSection(const TagLayoutPtr &layout)
{
    static const QStringList typeValues(QString::fromLatin1("sloppy,non-sloppy").split(','));

    const QXmlStreamAttributes attributes(m_xml.attributes());
    const QString id(attributes.value(QLatin1String("id")).toString());
    const bool movable(boolValue(attributes.value(QLatin1String("movable")), true));
    const TagSection::SectionType type(enumValue("type", typeValues, TagSection::Sloppy));
    const QString style(attributes.value(QLatin1String("style")).toString());

    if (id.isEmpty()) {
        error("Expected non-empty 'id' attribute in '<section>'.");
        return;
    }


    TagSectionPtr new_section(new TagSection(id, movable, type, style));
    layout->appendSection(new_section);

    bool found_row(false);

    while (m_xml.readNextStartElement()) {
        const QStringRef name(m_xml.name());

        if (name == QLatin1String("row")) {
            parseRow(new_section);
            found_row = true;
        } else {
            error(QString::fromLatin1("Expected '<row>', but got '<%1>'.").arg(name.toString()));
        }
    }

    if (not found_row) {
        error(QString::fromLatin1("Expected '<row>'."));
    }

}
예제 #17
0
void    start_doc_sect( void )
{
    bool            first_section;
    bool            header;
    bool            page_r;
    doc_section     ds;
    font_number     font;
    spacing_line    spacing_ln;
    page_ej         page_e;
    su              *p_sk;
    su              *top_sk;
    uint32_t        ind;
    xx_str          *h_string;

    if( ProcFlags.start_section ) {
        return;                         // once is enough
    }
    if( !ProcFlags.fb_document_done ) { // the very first section/page
        do_layout_end_processing();
    }

    first_section = (ProcFlags.doc_sect == doc_sect_none);

    header = false;                 // no header string (ABSTRACT, ... )  output
    page_r = false;                 // no page number reset
    page_e = ej_no;                 // no page eject
    ProcFlags.start_section = true;
    ProcFlags.keep_left_margin = false;
    ds = ProcFlags.doc_sect_nxt;        // new section

    if( ds == doc_sect_none ) {
        ds = doc_sect_body;      // if text without section start assume body
    }

    /***********************************************************************/
    /*  process special section attributes                                 */
    /***********************************************************************/

    switch( ds ) {
    case   doc_sect_body:
        page_r   = layout_work.body.page_reset;
        page_e   = layout_work.body.page_eject;
        if( layout_work.body.header ) {
            header   = true;
            h_string = layout_work.body.string;
            top_sk   = &layout_work.body.pre_top_skip;
            p_sk     = &layout_work.body.post_skip;
            font     = layout_work.body.font;
            spacing_ln = g_spacing_ln;  // standard spacing
        }
        break;
    case   doc_sect_titlep:             // for preceding :BINCLUDE/:GRAPHIC
        page_e = ej_yes;

        init_nest_cb( true );

        nest_cb->gtag = t_TITLEP;
        nest_cb->p_stack->lineno = titlep_lineno; // correct line number
        break;
    case   doc_sect_abstract:
        page_r   = layout_work.abstract.page_reset;
        page_e   = layout_work.abstract.page_eject;
        if( layout_work.abstract.header ) {
            header = true;
            h_string = layout_work.abstract.string;
            top_sk   = &layout_work.abstract.pre_top_skip;
            p_sk     = &layout_work.abstract.post_skip;
            font     = layout_work.abstract.font;
            spacing_ln = layout_work.abstract.spacing;
        }
        break;
    case   doc_sect_preface:
        page_r   = layout_work.preface.page_reset;
        page_e   = layout_work.preface.page_eject;
        if( layout_work.preface.header ) {
            header = true;
            h_string = layout_work.preface.string;
            top_sk   = &layout_work.preface.pre_top_skip;
            p_sk     = &layout_work.preface.post_skip;
            font     = layout_work.preface.font;
            spacing_ln = layout_work.preface.spacing;
        }
        break;
    case   doc_sect_appendix:
        page_r   = layout_work.appendix.page_reset;
        page_e   = layout_work.appendix.page_eject;
        if( layout_work.appendix.header ) {
            header = true;
            h_string = layout_work.appendix.string;
            top_sk   = &layout_work.appendix.pre_top_skip;
            p_sk     = &layout_work.appendix.post_skip;
            font     = layout_work.appendix.font;
            spacing_ln = layout_work.appendix.spacing;
        }
        break;
    case   doc_sect_backm:
        page_r   = layout_work.backm.page_reset;
        page_e   = layout_work.backm.page_eject;
        if( layout_work.backm.header ) {
            header = true;
            h_string = layout_work.backm.string;
            top_sk   = &layout_work.backm.pre_top_skip;
            p_sk     = &layout_work.backm.post_skip;
            font     = layout_work.backm.font;
            spacing_ln = g_spacing_ln;  // standard spacing
        }
        break;
    case   doc_sect_index:
        page_r   = layout_work.index.page_reset;
        page_e   = layout_work.index.page_eject;
        if( layout_work.index.header ) {
            header = true;
            h_string = layout_work.index.index_string;
            top_sk   = &layout_work.index.pre_top_skip;
            p_sk     = &layout_work.index.post_skip;
            font     = layout_work.index.font;
            spacing_ln = layout_work.index.spacing;
        }
        break;
    default:
        new_section( ds );
        break;
    }

    if( first_section ) {               // nothing precedes the first section
        if( page_e == ej_even ) {
            do_page_out();              // apage of first page is odd
            page = 0;                   // restart page for first text page
        }
        new_section( ds );
        reset_t_page();
        document_new_position();        // first text page ready for content
    } else {
        full_page_out();                // ensure are on last page
        switch( page_e ) {              // page eject requested
        case ej_yes :
            finish_page_section( ds, true );// emit last page in old section
            if( page_r ) {
                page = 0;
            }
            reset_t_page();
            break;
        case ej_odd :
            if( !(apage & 1) ) {        // first page would be even
                do_page_out();          // emit last page in old section
                reset_t_page();
            }
            finish_page_section( ds, true );// emit last page in old section
            if( page_r ) {
                page = 0;
            }
            reset_t_page();
            break;
        case ej_even :
            if( (apage & 1) ) {         // first page will be odd
                do_page_out();          // emit last page in old section
                reset_t_page();
            }
            finish_page_section( ds, true );// emit last page in old section
            if( page_r ) {
                page = 0;
            }
            reset_t_page();
            break;
        default:                        //  ej_no
            new_section( ds );

            /****************************************************/
            /*  set page bottom banner/limit for new section    */
            /****************************************************/

            ind = !(page & 1);
            t_page.bottom_banner = sect_ban_bot[ind];
            if( sect_ban_bot[ind] != NULL ) {
                if( bin_driver->y_positive == 0 ) {
                    g_page_bottom = g_page_bottom_org + sect_ban_bot[ind]->ban_depth;
                } else {
                    g_page_bottom = g_page_bottom_org - sect_ban_bot[ind]->ban_depth;
                }
            } else {
                g_page_bottom = g_page_bottom_org;
            }
            break;
        }
    }
    g_cur_left = g_page_left_org;
    g_cur_h_start = g_page_left_org + g_indent;
    if( header ) {
        doc_header( p_sk, top_sk, h_string, font, spacing_ln, page_e == ej_no );
    }
    ProcFlags.doc_sect = ds;
}
예제 #18
0
static void
add_import_table(void)
{
	IMAGE_IMPORT_DESCRIPTOR ds[2], *d;
	char *dllname = "kernel32.dll";
	struct {
		char *name;
		uint32 thunk;
	} *f, fs[] = {
		{ "GetProcAddress", 0 },
		{ "LoadLibraryExA", 0 },
		{ 0, 0 }
	};

	uint32 size = 0;
	memset(ds, 0, sizeof(ds));
	size += sizeof(ds);
	ds[0].Name = size;
	size += strlen(dllname) + 1;
	for(f=fs; f->name; f++) {
		f->thunk = size;
		size += sizeof(uint16) + strlen(f->name) + 1;
	}
	ds[0].FirstThunk = size;
	for(f=fs; f->name; f++)
		size += sizeof(fs[0].thunk);

	IMAGE_SECTION_HEADER *isect;
	isect = new_section(".idata", size, 0);
	isect->Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA|
		IMAGE_SCN_MEM_READ|IMAGE_SCN_MEM_WRITE;
	
	uint32 va = isect->VirtualAddress;
	oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress = va;
	oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size = isect->VirtualSize;

	ds[0].Name += va;
	ds[0].FirstThunk += va;
	for(f=fs; f->name; f++)
		f->thunk += va;

	vlong off = seek(cout, 0, 1);
	seek(cout, 0, 2);
	for(d=ds; ; d++) {
		lputl(d->OriginalFirstThunk);
		lputl(d->TimeDateStamp);
		lputl(d->ForwarderChain);
		lputl(d->Name);
		lputl(d->FirstThunk);
		if(!d->Name) 
			break;
	}
	strput(dllname);
	for(f=fs; f->name; f++) {
		wputl(0);
		strput(f->name);
	}
	for(f=fs; f->name; f++)
		lputl(f->thunk);
	strnput("", isect->SizeOfRawData - size);
	cflush();
	seek(cout, off, 0);
}
예제 #19
0
파일: syntax.c 프로젝트: kusma/vasm
static void do_section(char *s,char *name,char *type)
{
  try_leave_rorg();  /* works like ending the last RORG-block */
  set_section(new_section(name,type,1));
  eol(s);
}
예제 #20
0
파일: t_prepro.c 프로젝트: dorienh/smmu
char *process_find_char(char *data, char find)
{
  while(*data)
    {
      if(*data==find) return data;
      if(*data=='\"')       // found a quote: ignore stuff in it
	{
	  data++;
	  while(*data && *data != '\"')
	    {
	      // escape sequence ?
	      if(*data=='\\') data++;
	      data++;
	    }
	  // error: end of script in a constant
	  if(!*data) return NULL;
	}

      // comments: blank out

      if(*data=='/' && *(data+1)=='*')        // /* -- */ comment
	{
	  while(*data && (*data != '*' || *(data+1) != '/') )
	    {
	      *data=' '; data++;
	    }
	  if(*data)
	    *data = *(data+1) = ' ';   // blank the last bit
	  else
	    {
	      rover = data;
	      // script terminated in comment
	      script_error("script terminated inside comment\n");
	    }
	}
      if(*data=='/' && *(data+1)=='/')        // // -- comment
	while(*data != '\n')
	  {
	    *data=' '; data++;       // blank out
	  }

      // labels

      if(*data==':'  // ':' -- a label
	 && current_script->scriptnum != -1)   // not levelscript
	{
	  char *labelptr = data-1;
	  
	  while(!isop(*labelptr)) labelptr--;
	  new_label(labelptr+1);
	}
      
      if(*data=='{')  // { -- } sections: add 'em
	{
	  section_t *newsec = new_section(data);
	  
	  newsec->type = st_empty;
	  // find the ending } and save
	  newsec->end = process_find_char(data+1, '}');
	  if(!newsec->end)
	    {                // brace not found
	      rover = data;
	      script_error("section error: no ending brace\n");
	      return NULL;
	    }
	  // continue from the end of the section
	  data = newsec->end;
	}
      data++;
    }

  return NULL;
}
예제 #21
0
void write_variables(int nvars, int *vardim, int *centering, 
                     const char * const * varname, float **vars,
                     int npts, int ncells)
{
    char str[1024];
    int i, j, first_scalar, first_vector;
    int num_scalars, num_vectors;
    int num_field = 0;

    new_section();
    sprintf(str, "CELL_DATA %d\n", ncells);
    write_string(str);

    first_scalar = 0;
    first_vector = 0;
    num_scalars = 0;
    num_vectors = 0;
    /* The field data is where the non-primary scalars and vectors are 
     * stored.  They must all be grouped together at the end of the point
     * data.  So write out the primary scalars and vectors first.
     */
    for (i = 0 ; i < nvars ; i++)
    {
        if (centering[i] == 0)
        {
            int num_to_write = 0;
            int should_write = 0;

            if (vardim[i] == 1)
            {
                if (first_scalar == 0)
                {
                    should_write = 1;
                    sprintf(str, "SCALARS %s float\n", varname[i]);
                    write_string(str);
                    write_string("LOOKUP_TABLE default\n");
                    first_scalar = 1;
                }
                else 
                    num_scalars++;
            }
            else if (vardim[i] == 3)
            {
                if (first_vector == 0)
                {
                    should_write = 1;
                    sprintf(str, "VECTORS %s float\n", varname[i]);
                    write_string(str);
                    first_vector = 1;
                }
                else 
                    num_vectors++;
            }
            else
            {
                printf("Only supported variable dimensions are 1 and 3.\n");
                printf("Ignoring variable %s.\n", varname[i]);
                continue;
            }

            if (should_write)
            {
                num_to_write = ncells*vardim[i];
                for (j = 0 ; j < num_to_write ; j++)
                {
                    write_float(vars[i][j]);
                }
                end_line();
            }
        }
    }

    first_scalar = 0;
    if (num_scalars > 0)
    {
        sprintf(str, "FIELD FieldData %d\n", num_scalars);
        write_string(str);
        for (i = 0 ; i < nvars ; i++)
        {
            int should_write = 0;
            if (centering[i] == 0)
            {
                if (vardim[i] == 1)
                {
                    if (first_scalar == 0)
                    {
                        first_scalar = 1;
                    }
                    else
                    {
                        should_write = 1;
                        sprintf(str, "%s 1 %d float\n", varname[i], ncells);
                        write_string(str);
                    }
                }
            }

            if (should_write)
            {
                int num_to_write = ncells*vardim[i];
                for (j = 0 ; j < num_to_write ; j++)
                {
                    write_float(vars[i][j]);
                }
                end_line();
            }
        }
    }

    first_vector = 0;
    if (num_vectors > 0)
    {
        sprintf(str, "FIELD FieldData %d\n", num_vectors);
        write_string(str);
        for (i = 0 ; i < nvars ; i++)
        {
            int should_write = 0;
            if (centering[i] == 0)
            {
                int num_to_write = 0;
    
                if (vardim[i] == 3)
                {
                    if (first_vector == 0)
                    {
                        first_vector = 1;
                    }
                    else
                    {
                        should_write = 1;
                        sprintf(str, "%s 3 %d float\n", varname[i], ncells);
                        write_string(str);
                    }
                }
            }

            if (should_write)
            {
                int num_to_write = ncells*vardim[i];
                for (j = 0 ; j < num_to_write ; j++)
                {
                    write_float(vars[i][j]);
                }
                end_line();
            }
        }
    }

    new_section();
    sprintf(str, "POINT_DATA %d\n", npts);
    write_string(str);

    first_scalar = 0;
    first_vector = 0;
    num_scalars = 0;
    num_vectors = 0;
    /* The field data is where the non-primary scalars and vectors are 
     * stored.  They must all be grouped together at the end of the point
     * data.  So write out the primary scalars and vectors first.
     */
    for (i = 0 ; i < nvars ; i++)
    {
        if (centering[i] != 0)
        {
            int num_to_write = 0;
            int should_write = 0;

            if (vardim[i] == 1)
            {
                if (first_scalar == 0)
                {
                    should_write = 1;
                    sprintf(str, "SCALARS %s float\n", varname[i]);
                    write_string(str);
                    write_string("LOOKUP_TABLE default\n");
                    first_scalar = 1;
                }
                else 
                    num_scalars++;
            }
            else if (vardim[i] == 3)
            {
                if (first_vector == 0)
                {
                    should_write = 1;
                    sprintf(str, "VECTORS %s float\n", varname[i]);
                    write_string(str);
                    first_vector = 1;
                }
                else 
                    num_vectors++;
            }
            else
            {
                printf("Only supported variable dimensions are 1 and 3.\n");
                printf("Ignoring variable %s.\n", varname[i]);
                continue;
            }

            if (should_write)
            {
                num_to_write = npts*vardim[i];
                for (j = 0 ; j < num_to_write ; j++)
                {
                    write_float(vars[i][j]);
                }
                end_line();
            }
        }
    }

    first_scalar = 0;
    if (num_scalars > 0)
    {
        sprintf(str, "FIELD FieldData %d\n", num_scalars);
        write_string(str);
        for (i = 0 ; i < nvars ; i++)
        {
            int should_write = 0;
            if (centering[i] != 0)
            {
                if (vardim[i] == 1)
                {
                    if (first_scalar == 0)
                    {
                        first_scalar = 1;
                    }
                    else
                    {
                        should_write = 1;
                        sprintf(str, "%s 1 %d float\n", varname[i], npts);
                        write_string(str);
                    }
                }
            }

            if (should_write)
            {
                int num_to_write = npts*vardim[i];
                for (j = 0 ; j < num_to_write ; j++)
                {
                    write_float(vars[i][j]);
                }
                end_line();
            }
        }
    }

    first_vector = 0;
    if (num_vectors > 0)
    {
        sprintf(str, "FIELD FieldData %d\n", num_vectors);
        write_string(str);
        for (i = 0 ; i < nvars ; i++)
        {
            int should_write = 0;
            if (centering[i] != 0)
            {
                int num_to_write = 0;
    
                if (vardim[i] == 3)
                {
                    if (first_vector == 0)
                    {
                        first_vector = 1;
                    }
                    else
                    {
                        should_write = 1;
                        sprintf(str, "%s 3 %d float\n", varname[i], npts);
                        write_string(str);
                    }
                }
            }

            if (should_write)
            {
                int num_to_write = npts*vardim[i];
                for (j = 0 ; j < num_to_write ; j++)
                {
                    write_float(vars[i][j]);
                }
                end_line();
            }
        }
    }
}
예제 #22
0
void
asmbpe(void)
{
	switch(thechar) {
	default:
		diag("unknown PE architecture");
		errorexit();
	case '6':
		fh.Machine = IMAGE_FILE_MACHINE_AMD64;
		break;
	case '8':
		fh.Machine = IMAGE_FILE_MACHINE_I386;
		break;
	}

	if(!debug['s']) {
		IMAGE_SECTION_HEADER *symsect;
		symsect = new_section(".symdat", 8+symsize+lcsize, 0);
		symsect->Characteristics = IMAGE_SCN_MEM_READ|
			IMAGE_SCN_CNT_INITIALIZED_DATA;
	}

	add_import_table();

	fh.NumberOfSections = nsect;
	fh.TimeDateStamp = time(0);
	fh.SizeOfOptionalHeader = sizeof(oh);
	fh.Characteristics = IMAGE_FILE_RELOCS_STRIPPED|
		IMAGE_FILE_EXECUTABLE_IMAGE|IMAGE_FILE_DEBUG_STRIPPED;
	if(thechar == '8')
		fh.Characteristics |= IMAGE_FILE_32BIT_MACHINE;

	oh.Magic = 0x10b;	// PE32
	oh.MajorLinkerVersion = 1;
	oh.MinorLinkerVersion = 0;
	oh.SizeOfCode = textsect->SizeOfRawData;
	oh.SizeOfInitializedData = datsect->SizeOfRawData;
	oh.SizeOfUninitializedData = bsssect->SizeOfRawData;
	oh.AddressOfEntryPoint = entryvalue()-PEBASE;
	oh.BaseOfCode = textsect->VirtualAddress;
	oh.BaseOfData = datsect->VirtualAddress;

	oh.ImageBase = PEBASE;
	oh.SectionAlignment = 0x00001000;
	oh.FileAlignment = PEALIGN;
	oh.MajorOperatingSystemVersion = 4;
	oh.MinorOperatingSystemVersion = 0;
	oh.MajorImageVersion = 1;
	oh.MinorImageVersion = 0;
	oh.MajorSubsystemVersion = 4;
	oh.MinorSubsystemVersion = 0;
	oh.SizeOfImage = sect_virt_begin;
	oh.SizeOfHeaders = PERESERVE;
	oh.Subsystem = 3;	// WINDOWS_CUI
	oh.SizeOfStackReserve = 0x00200000;
	oh.SizeOfStackCommit = 0x00001000;
	oh.SizeOfHeapReserve = 0x00100000;
	oh.SizeOfHeapCommit = 0x00001000;
	oh.NumberOfRvaAndSizes = 16;

	pewrite();
}
예제 #23
0
int load_ini_file(FILE * fp)
{
        char line[BUFSIZ];

        if (!fp)
                return 1;

        int line_num = 0;
        char *current_section = NULL;
        while (fgets(line, sizeof(line), fp) != NULL) {
                line_num++;

                char *start = g_strstrip(line);

                if (*start == ';' || *start == '#' || strlen(start) == 0)
                        continue;

                if (*start == '[') {
                        char *end = strstr(start + 1, "]");
                        if (!end) {
                                printf
                                    ("Warning: invalid config file at line %d\n",
                                     line_num);
                                printf("Missing ']'\n");
                                continue;
                        }

                        *end = '\0';

                        if (current_section)
                                free(current_section);
                        current_section = (g_strdup(start + 1));
                        new_section(current_section);
                        continue;
                }

                char *equal = strstr(start + 1, "=");
                if (!equal) {
                        printf("Warning: invalid config file at line %d\n",
                               line_num);
                        printf("Missing '='\n");
                        continue;
                }

                *equal = '\0';
                char *key = g_strstrip(start);
                char *value = g_strstrip(equal + 1);

                char *quote = strstr(value, "\"");
                if (quote) {
                        char *closing_quote = strstr(quote + 1, "\"");
                        if (!closing_quote) {
                                printf
                                    ("Warning: invalid config file at line %d\n",
                                     line_num);
                                printf("Missing '\"'\n");
                                continue;
                        }

                        closing_quote = '\0';
                } else {
                        char *comment = strstr(value, "#");
                        if (!comment)
                                comment = strstr(value, ";");
                        if (comment)
                                comment = '\0';
                }
                value = g_strstrip(value);

                if (!current_section) {
                        printf("Warning: invalid config file at line: %d\n",
                               line_num);
                        printf("Key value pair without a section\n");
                        continue;
                }

                add_entry(current_section, key, value);
        }
        if (current_section)
                free(current_section);
        return 0;
}