示例#1
0
static unsigned int stepdirectory(struct service_backend *backend, unsigned int id, unsigned int current)
{

    struct cpio_header eheader;

    if (!readheader(backend, &eheader, current))
        return 0;

    while ((current = cpio_next(&eheader, current)))
    {

        if (current == id)
            break;

        if (!readheader(backend, &eheader, current))
            break;

        if (parent(backend, &eheader, current) == id)
            return current;

    }

    return 0;

}
示例#2
0
static unsigned int protocol_child(struct service_backend *backend, struct service_state *state, char *path, unsigned int length)
{

    struct cpio_header header;
    struct cpio_header eheader;
    unsigned char name[1024];
    unsigned int id = 0;

    if (!length)
        return 1;

    if (!readheader(backend, &header, state->id))
        return 0;

    if (!readname(backend, &header, state->id, name, 1024))
        return 0;

    if (path[length - 1] == '/')
        length--;

    do
    {

        unsigned char cname[1024];

        if (id == state->id)
            break;

        if (!readheader(backend, &eheader, id))
            break;

        if (eheader.namesize - header.namesize != length + 1)
            continue;

        if (!readname(backend, &eheader, id, cname, 1024))
            break;

        if (memory_match(cname + header.namesize, path, length))
        {

            state->id = id;

            return 1;

        }

    } while ((id = cpio_next(&eheader, id)));

    return 0;

}
示例#3
0
int
readrequest(Request *r)
{
	int i, clen, nhdr;
	
	clen = 0;

	zerorequest(r);
	if(!findfirstline(r))
		return 0;

	nhdr = sizeof(r->headers)/sizeof(r->headers[0]);
	for(i=0; i < nhdr && readheader(&r->headers[i]); i++){
		if(strcasecmp(r->headers[i].key, "content-length"))
			continue;

		r->nbody = atoi(r->headers[i].value);
	}
	r->nheader = i;

/*
	for(i=0; i<2; i++){
		line = readline();
		if(line == nil || *line != '\0'){
			say("sad");
			return 0;
		}
	}
*/

	return 1;
}
示例#4
0
文件: dsp.cpp 项目: FREEWING-JP/ekho
wav_file_giver::wav_file_giver(const char * name)
{ reader=new ifstream(name,ios::in | ios::binary);
  if (reader->fail())
  { cerr << "***** ERROR *****" << endl
         << "WAV file giver at " << this << " failed to open WAV file \""
         << name << "\"." << endl;
    delete reader;
    reader=0;
    return;
  }
  wavhdr w;
  bool gotheader=readheader(*reader,w);
  if ((!gotheader) || reader->fail() /*|| (w.channels!=1)*/)
  { cerr << "***** ERROR *****" << endl
         << "WAV file giver at " << this << " failed to read a" << endl
      << "  valid WAV file header from the file \"" << name << "\"." << endl;
    /*
    if (w.channels!=1)
     cerr << name << ": expected 1 channel, got " << w.channels << endl;
    */
    delete reader;
    reader=0;
    return;
  }
  int start=reader->tellg();
  end_offset=start+w.datalength;
  mrate=w.samplerate;
  mbits=w.samplebits;
  mchans=w.channels;
};
示例#5
0
static unsigned int readdirectory(struct service_backend *backend, void *buffer, unsigned int count, unsigned int current, struct cpio_header *header)
{

    struct record *record = buffer;
    struct cpio_header eheader;
    unsigned char name[1024];

    if (!current)
        return 0;

    if (!readheader(backend, &eheader, current))
        return 0;

    if (!readname(backend, &eheader, current, name, 1024))
        return 0;

    record->id = current;
    record->size = cpio_filesize(&eheader);
    record->length = memory_read(record->name, RECORD_NAMESIZE, name, eheader.namesize - 1, header->namesize);

    switch (eheader.mode & 0xF000)
    {

    case 0x4000:
        record->length += memory_write(record->name, RECORD_NAMESIZE, "/", 1, record->length);

        break;

    }

    return sizeof (struct record);

}
示例#6
0
static unsigned int parent(struct service_backend *backend, struct cpio_header *header, unsigned int id)
{

    struct cpio_header eheader;
    unsigned char name[1024];
    unsigned int length;

    if (!readname(backend, header, id, name, 1024))
        return 0;

    for (length = header->namesize - 1; length && name[length] != '/'; length--);

    do
    {

        if (!readheader(backend, &eheader, id))
            break;

        if ((eheader.mode & 0xF000) != 0x4000)
            continue;

        if (eheader.namesize == length + 1)
            return id;

    } while ((id = cpio_next(&eheader, id)));

    return 0;

}
示例#7
0
static unsigned int protocol_match(struct service_backend *backend)
{

    struct cpio_header header;

    return readheader(backend, &header, 0);

}
示例#8
0
文件: midifile.c 项目: asmCode/rw2014
DECLSPEC void mfread(void)  /* The only non-static function in this file. */
{
    if ( Mf_getc == NULLFUNC )
        mferror("mfread() called without setting Mf_getc"); 

    readheader();
    while (readtrack());
}
示例#9
0
static unsigned long protocol_map(struct service_backend *backend, struct service_state *state)
{

    struct cpio_header header;

    if (!readheader(backend, &header, state->id))
        return 0;

    return backend->map(cpio_filedata(&header, state->id), cpio_filesize(&header));

}
示例#10
0
static unsigned int protocol_parent(struct service_backend *backend, struct service_state *state)
{

    struct cpio_header header;
    struct cpio_header eheader;
    unsigned char name[1024];
    unsigned int id = state->id;

    if (!readheader(backend, &header, state->id))
        return 0;

    if (!readname(backend, &header, state->id, name, 1024))
        return 0;

    while (name[header.namesize] != '/')
        header.namesize--;

    do
    {

        if (!readheader(backend, &eheader, id))
            break;

        if ((eheader.mode & 0xF000) != 0x4000)
            continue;

        if (eheader.namesize == header.namesize + 1)
        {

            state->id = id;

            return 1;

        }

    } while ((id = cpio_next(&eheader, id)));

    return 0;

}
示例#11
0
void mfread()     /* The only non-static function in this file. */
{
  int track;
  if ( Mf_getc == NULLFUNC )
    mferror("mfread() called without setting Mf_getc"); 

  readheader();
  track =1;
  while (readtrack()) 
    {track++;
     if(track>ntrks) break;
    }
}
示例#12
0
static unsigned int resolve(unsigned int id)
{

    struct elf_header header;
    unsigned int i;

    if (!readheader(id, &header))
        return 0;

    if (!elf_validate(&header))
        return 0;

    for (i = 0; i < header.shcount; i++)
    {

        struct elf_sectionheader relocationheader;
        struct elf_sectionheader dataheader;
        struct elf_sectionheader symbolheader;
        struct elf_sectionheader stringheader;
        char strings[FUDGE_BSIZE];

        if (!readsectionheader(id, &header, i, &relocationheader))
            return 0;

        if (relocationheader.type != ELF_SECTION_TYPE_REL)
            continue;

        if (!readsectionheader(id, &header, relocationheader.info, &dataheader))
            return 0;

        if (!readsectionheader(id, &header, relocationheader.link, &symbolheader))
            return 0;

        if (!readsectionheader(id, &header, symbolheader.link, &stringheader))
            return 0;

        if (stringheader.size > FUDGE_BSIZE)
            return 0;

        if (!file_seekreadall(id, strings, stringheader.size, stringheader.offset))
            return 0;

        if (!resolvesymbols(id, &relocationheader, &symbolheader, strings, dataheader.offset))
            return 0;

    }

    return 1;

}
示例#13
0
void mfreadtrk(itrack)     /* The only non-static function in this file. */
{
  int track,ok;
  if ( Mf_getc == NULLFUNC )
    mferror("mfprocess() called without setting Mf_getc");

  readheader();
  track =1;
  ok = 1;
  for (track=1;track<=ntrks && ok == 1;track++)
   {if (track == itrack)
     ok = readtrack();
    else
     ok = skiptrack();
   }
}
示例#14
0
// midifile::midifile - create, initialize the file
MidiFile::MidiFile( const char *filename, const char *access ) 
{
	if( strchr( access, 'r' ) )
	{
		accessmode = 0;
		midiin = fopen( filename, "r" );
		if( !midiin )
		{
			fprintf(stderr, "error opening midifile %s for input\n", filename );
			exit(1);
		}
	}	
	else if( strchr( access, 'w' ) ) 
	{
		accessmode = 1;
		midiout = fopen( filename, "w");
		if( !midiout  ) 
		{
			fprintf(stderr, "error opening midifile %s for output\n", filename );
			exit(2);
		}
	}
	else 
	{
		fprintf(stderr, "invalid accessmode %s\n", access );
		exit(2);
	}
				
	if( accessmode )
	{	
		// initialize the actual header storage with defaults
		hdrbytes[0] = hdrbytes[2] = hdrbytes[4] = 0; // upper byte zeroed
		// presently, only do midi type 1
		hdrbytes[1] = hdrbytes[3] = 1; 	// type 1, 1 track */
		//hdrbytes[5] = 0x78;  /* = 120 ppqn */
		hdrbytes[5] = 0x60;    /* = 96 ppqn */
	}
	else 
	{
		readheader();
#if DEBUG
		fprintf(stderr,"Header is read: type=%x tracks=%x timing=%x\n",
			type(), tracks(), timing() );
#endif			
	}	
}
示例#15
0
static
void
disk_open(struct disk_data *dd, const char *filename, uint32_t configsectors)
{
    int create = 0;
    struct stat st;

    dd->dd_fd = open(filename, O_RDWR);
    if (dd->dd_fd<0 && errno==ENOENT) {
        create = 1;
        dd->dd_fd = open(filename, O_RDWR|O_CREAT|O_EXCL, 0664);
    }
    if (dd->dd_fd<0) {
        msg("disk: slot %d: %s: %s",
            dd->dd_slot, filename, strerror(errno));
        die();
    }
    disk_lock(dd, filename);
    if (create) {
        writeheader(dd, filename, configsectors);
    }
    else {
        readheader(dd, filename);
    }

    if (fstat(dd->dd_fd, &st) == -1) {
        msg("disk: slot %d: %s: fstat: %s",
            dd->dd_slot, filename, strerror(errno));
        die();
    }
    if (st.st_size < HEADERSIZE) {
        msg("disk: slot %d: %s: No header block",
            dd->dd_slot, filename);
        die();
    }
    st.st_size -= HEADERSIZE;
    if (st.st_size > 0xffffffff) {
        msg("disk: slot %d: %s: Image too large; using first 4G",
            dd->dd_slot, filename);
        dd->dd_totsectors = 0x100000000ULL / SECTSIZE;
    }
    else {
        dd->dd_totsectors = st.st_size / SECTSIZE;
    }
}
示例#16
0
static unsigned int findsymbol(unsigned int id, unsigned int count, char *symbolname)
{

    struct elf_header header;
    unsigned int i;

    if (!readheader(id, &header))
        return 0;

    if (!elf_validate(&header))
        return 0;

    for (i = 0; i < header.shcount; i++)
    {

        struct elf_sectionheader symbolheader;
        struct elf_sectionheader stringheader;
        char strings[FUDGE_BSIZE];
        unsigned int value;

        if (!readsectionheader(id, &header, i, &symbolheader))
            return 0;

        if (symbolheader.type != ELF_SECTION_TYPE_SYMTAB)
            continue;

        if (!readsectionheader(id, &header, symbolheader.link, &stringheader))
            return 0;

        if (stringheader.size > FUDGE_BSIZE)
            return 0;

        if (!file_seekreadall(id, strings, stringheader.size, stringheader.offset))
            return 0;

        value = findvalue(id, &header, &symbolheader, strings, count, symbolname);

        if (value)
            return value;

    }

    return 0;

}
示例#17
0
static unsigned int protocol_write(struct service_backend *backend, struct service_state *state, void *buffer, unsigned int count)
{

    struct cpio_header header;

    if (!readheader(backend, &header, state->id))
        return 0;

    switch (header.mode & 0xF000)
    {

    case 0x8000:
        return writefile(backend, buffer, count, state->offset, state->id, &header);

    }

    return 0;

}
示例#18
0
static unsigned int protocol_step(struct service_backend *backend, struct service_state *state)
{

    struct cpio_header header;

    if (!readheader(backend, &header, state->id))
        return 0;

    switch (header.mode & 0xF000)
    {

    case 0x4000:
        return stepdirectory(backend, state->id, state->current);

    }

    return 0;

}
示例#19
0
文件: rebind.c 项目: unanao/Elfdbs
/* rebind() does most of the grunt work. After checking over the ELF
 * headers, the function iterates through the sections, looking for
 * symbol tables containing non-local symbol. When it finds one, it
 * loads the non-local part of the table and the associated string
 * table into memory, and calls changesymbols(). If changesymbols()
 * actually changes anything, the altered symbol table is written back
 * out to the object file.
 */
static int rebind(void)
{
    Elf32_Shdr *shdrs;
    Elf32_Sym  *symtab;
    char       *strtab;
    unsigned	offset, count;
    int		i;

    if (!readheader())
	return FALSE;
    if (!(shdrs = getarea(ehdr.e_shoff, ehdr.e_shnum * sizeof(Elf32_Shdr))))
	return err("invalid section header table.");

    for (i = 0 ; i < ehdr.e_shnum ; ++i) {
	if (shdrs[i].sh_type != SHT_SYMTAB && shdrs[i].sh_type != SHT_DYNSYM)
	    continue;
	if (shdrs[i].sh_entsize != sizeof *symtab) {
	    err("symbol table of unrecognized structure ignored.");
	    continue;
	}
	offset = shdrs[i].sh_offset + shdrs[i].sh_info * sizeof *symtab;
	count = shdrs[i].sh_size / sizeof *symtab - shdrs[i].sh_info;
	if (!count)
	    continue;

	if (!(symtab = getarea(offset, count * sizeof *symtab)))
	    return err("invalid symbol table");
	if (!(strtab = getarea(shdrs[shdrs[i].sh_link].sh_offset,
			       shdrs[shdrs[i].sh_link].sh_size)))
	    return err("invalid associated string table");
	if (changesymbols(symtab, strtab, count)) {
	    if (fseek(thefile, offset, SEEK_SET)
		    || fwrite(symtab, sizeof *symtab, count, thefile) != count)
		return err("unable to write to the object file");
	}
	free(symtab);
	free(strtab);
    }

    free(shdrs);
    return TRUE;
}
示例#20
0
int main()
{
	while (readheader())
	{
		while (1)
		{
			int length = readcode(3);
			if (length == 0) break;
			int key = 0;
			while (1)
			{
				key = readcode(length);
				if (key == (1 << length) - 1)
					break;
				else
					printf("%c", header[length-1][key]);
			}
		}
		printf("\n");
	}
	return 0;
}
示例#21
0
static unsigned int protocol_root(struct service_backend *backend)
{

    struct cpio_header header;
    unsigned int id = 0;
    unsigned int last = id;

    do
    {

        if (!readheader(backend, &header, id))
            break;

        if ((header.mode & 0xF000) != 0x4000)
            continue;

        last = id;

    } while ((id = cpio_next(&header, id)));

    return last;

}
示例#22
0
void
midifile()              /* The only non-static function in this file. */
{
        int ntrks;
        midifile_error = 0;

        if ( Mf_getc == 0 ) {
                mferror("mf.h() called without setting Mf_getc"); 
                return;
        }
        ntrks = readheader();
        if (midifile_error) return;
        if ( ntrks <= 0 ) {
                mferror("No tracks!");
                /* no need to return since midifile_error is set */
        }
        while ( ntrks-- > 0 && !midifile_error && !check_aborted())
                readtrack();
        if (check_aborted()) {
                mferror("Midifile read aborted\n\
\tthe rest of your file will be ignored.\n");
            if (abort_flag == BREAK_LEVEL) abort_flag = 0;
        }
}
示例#23
0
change_world(char* oldworld_name, FILE *oldworld, FILE *redefine,
		struct	flow_struct *flow_table, int num_patches) {
/* Read a initialworld file which guides us as to what data
   to export 
*/
  struct tlevelstruct *tlevel;
  struct headerstruct *header;
  int level, ID[5], i, j, n, itmp;
  char ch;
  char name[MAXNAME], line[MAXTEMPLATELINE];
  char header_filename[MAXS];
  FILE *header_file;
  int legacy_worldfile = 0;

  /* Determine where to read worldfile header information from.
  	 * The two options, in order of precedence are:
  		2. ${WORLDFILE_NAME}.hdr
  		3. From legacy world file (deprecated)
  	 */
  // Set up file name for Option 2. ${WORLDFILE_NAME}.hdr
  if ( snprintf(header_filename, MAXS, "%s.hdr", oldworld_name) >= MAXS ) {
	fprintf(stderr,
			"Couldn't read world file header as filename would have been longer than the limit of %d\n", MAXS);
	exit(EXIT_FAILURE);
  }

  if ( access(header_filename, R_OK) == 0 ) {
	// Option 2. ${WORLDFILE_NAME}.hdr
	header_file = fopen(header_filename, "r");
	if ( header_file == NULL ) {
		fprintf(stderr,"FATAL ERROR:  Cannot open world header file %s\n",
				header_filename);
		exit(EXIT_FAILURE);
	}
	printf("Found world file header %s\n", header_filename);
  } else {
	// Option 3. From legacy world file (deprecated)
	header_file = oldworld;
	legacy_worldfile = 1;
	printf("\nWARNING\nReading world file header from legacy world file.\nThis feature will be removed from a future release.\nPlease re-run g2w to generate a separate world file header.\nWARNING\n\n");
  }

	header = (struct headerstruct *)malloc(sizeof(struct headerstruct));

	/* ******************************************************* */
	/* read and write the header information */
	/* ******************************************************* */
	readheader( header_file, header, legacy_worldfile);

    if ( !legacy_worldfile ) {
		// If we're dealing with a new-style worldfile
		// (i.e. one with a separate header file) then
		// we need to close the header file
		fclose(header_file);
	}

    /* outputheader(redefine, header); */
	/* ******************************************************* */
	/*  read in worldfile into data structure				  */
	/* ******************************************************* */
    level=0;

    if(fgets(line,MAXTEMPLATELINE,oldworld)==NULL) error("Reading initialworld file.");
    sscanf(line,"%d %s", &itmp,name);

    if ( (tlevel = (struct tlevelstruct*)malloc(sizeof(struct tlevelstruct)) ) == NULL) {
			fprintf(stderr,"ERROR: Could not allocate level structure for level %d id %d \n",
			level, itmp );
			exit(1);
			}
    if(fgets(line,MAXTEMPLATELINE,oldworld)==NULL) error("Reading initialworld file.");
    sscanf(line,"%d %s", &tlevel[0].nchildren,name);
    tlevel[0].ID = itmp;
    tlevel[0].namelist = NULL;
    tlevel[0].valuelist = NULL;
    tlevel[0].level = level;
    if ( (tlevel[0].children = (struct tlevelstruct **)calloc(tlevel[0].nchildren , sizeof(struct tlevelstruct *)) ) == NULL) {
			fprintf(stderr,"ERROR: Could not allocate level structure for level %d id %d \n",
			level, itmp );
			exit(1);
			}

   	for(n=0; n< tlevel[0].nchildren; n++) {

		tlevel[0].children[n] = readnextlevel(level+1, oldworld);
	}

	printf("\n finished reading worldfile");

	/* ******************************************************* */
	/* ******************************************************* */

	for (i=1; i <= num_patches; i++) {

		ID[1] = 1;
		ID[2] = flow_table[i].hillID;
		ID[3] = flow_table[i].zoneID;
		ID[4] = flow_table[i].patchID;
		ID[5] = flow_table[i].patchID;

		printf("\n processing patchID %d", flow_table[i].patchID);
		flow_table[i].worldlink = find_tlevel(tlevel[0].children[0], ID, 1);

		if ((flow_table[i].worldlink != NULL)  && (flow_table[i].veglink != NULL) ) {
			if ((flow_table[i].veglink[0].sla > 0.0001) && (flow_table[i].lai > -0.000)) {


			if (flow_table[i].lai < 1.0) {
				flow_table[i].worldlink[0].valuelist[7] = 1.0/flow_table[i].veglink[0].sla;
			} else {
				flow_table[i].worldlink[0].valuelist[7] = flow_table[i].lai/flow_table[i].veglink[0].sla;
			}
					
			flow_table[i].worldlink[0].valuelist[4] = 0.0;
			flow_table[i].worldlink[0].valuelist[5] = 0.0;
			flow_table[i].worldlink[0].valuelist[6] = 0.0;
			flow_table[i].worldlink[0].valuelist[8] = 0.0;
			flow_table[i].worldlink[0].valuelist[9] = 0.0;
			flow_table[i].worldlink[0].valuelist[10] = 0.0;

			if (flow_table[i].veglink[0].ls > ZERO) {

				if (flow_table[i].lai > 1.0) 
					flow_table[i].worldlink[0].valuelist[11] =  pow(flow_table[i].worldlink[0].valuelist[7],4/3)*
								flow_table[i].veglink[0].ls *
								(flow_table[i].veglink[0].lived/(1+flow_table[i].veglink[0].lived));
				else
					flow_table[i].worldlink[0].valuelist[11] = flow_table[i].worldlink[0].valuelist[7];
			}

			else
			flow_table[i].worldlink[0].valuelist[11] = 0.0;
			
			flow_table[i].worldlink[0].valuelist[12] = 0.0;
			flow_table[i].worldlink[0].valuelist[13] = 0.0;

			if (flow_table[i].veglink[0].ls > ZERO) 
			flow_table[i].worldlink[0].valuelist[14] =  flow_table[i].worldlink[0].valuelist[11]/flow_table[i].veglink[0].lived;
			else
			flow_table[i].worldlink[0].valuelist[14] = 0.0;

			flow_table[i].worldlink[0].valuelist[15] = 0.0;
			flow_table[i].worldlink[0].valuelist[16] = 0.0;
			if (flow_table[i].veglink[0].ls > ZERO) 
			flow_table[i].worldlink[0].valuelist[17] =  flow_table[i].worldlink[0].valuelist[11]/
								flow_table[i].veglink[0].sc *
								(flow_table[i].veglink[0].lived/(1+flow_table[i].veglink[0].lived));
			else
			flow_table[i].worldlink[0].valuelist[17] = 0.0;

			flow_table[i].worldlink[0].valuelist[18] = 0.0;
			flow_table[i].worldlink[0].valuelist[19] = 0.0;
			if (flow_table[i].veglink[0].ls > ZERO) 
			flow_table[i].worldlink[0].valuelist[20] =  flow_table[i].worldlink[0].valuelist[17]/flow_table[i].veglink[0].lived;
			else
			flow_table[i].worldlink[0].valuelist[20] = 0.0;

			flow_table[i].worldlink[0].valuelist[21] = 0.0;
			flow_table[i].worldlink[0].valuelist[22] = 0.0;
			flow_table[i].worldlink[0].valuelist[23] =  flow_table[i].worldlink[0].valuelist[7]/flow_table[i].veglink[0].lr;
			flow_table[i].worldlink[0].valuelist[24] = 0.0;
			flow_table[i].worldlink[0].valuelist[25] = 0.0;
			
			flow_table[i].worldlink[0].valuelist[27] = 0.05* flow_table[i].worldlink[0].valuelist[7];


			flow_table[i].worldlink[0].valuelist[28] = 0.0;
			flow_table[i].worldlink[0].valuelist[29] =  flow_table[i].worldlink[0].valuelist[7]/flow_table[i].veglink[0].cnl;
			flow_table[i].worldlink[0].valuelist[30] = 0.0;
			flow_table[i].worldlink[0].valuelist[31] = 0.0;
			flow_table[i].worldlink[0].valuelist[32] = 0.0;

			if (flow_table[i].veglink[0].ls > ZERO) 
			flow_table[i].worldlink[0].valuelist[33] =  flow_table[i].worldlink[0].valuelist[11]/flow_table[i].veglink[0].cnlw;
			else
			flow_table[i].worldlink[0].valuelist[33] = 0.0;

			flow_table[i].worldlink[0].valuelist[34] = 0.0;
			flow_table[i].worldlink[0].valuelist[35] = 0.0;

			if (flow_table[i].veglink[0].ls > ZERO) 
			flow_table[i].worldlink[0].valuelist[36] =  flow_table[i].worldlink[0].valuelist[14]/flow_table[i].veglink[0].cndw;
			else flow_table[i].worldlink[0].valuelist[36] = 0.0;

			flow_table[i].worldlink[0].valuelist[37] = 0.0;
			flow_table[i].worldlink[0].valuelist[38] = 0.0;

			if (flow_table[i].veglink[0].ls > ZERO) 
			flow_table[i].worldlink[0].valuelist[39] =  flow_table[i].worldlink[0].valuelist[17]/flow_table[i].veglink[0].cnlw;
			else flow_table[i].worldlink[0].valuelist[39] = 0.0;

			flow_table[i].worldlink[0].valuelist[40] = 0.0;
			flow_table[i].worldlink[0].valuelist[41] = 0.0;

			if (flow_table[i].veglink[0].ls > ZERO) 
			flow_table[i].worldlink[0].valuelist[42] =  flow_table[i].worldlink[0].valuelist[20]/flow_table[i].veglink[0].cndw;
			else 	flow_table[i].worldlink[0].valuelist[42] = 0.0;

			flow_table[i].worldlink[0].valuelist[43] = 0.0;
			flow_table[i].worldlink[0].valuelist[44] = 0.0;

			flow_table[i].worldlink[0].valuelist[45] =  flow_table[i].worldlink[0].valuelist[23]/flow_table[i].veglink[0].cnr;
			flow_table[i].worldlink[0].valuelist[46] = 0.0;
			flow_table[i].worldlink[0].valuelist[47] = 0.0;
			flow_table[i].worldlink[0].valuelist[48] = 0.0;
			} 
		else  {
				printf("\n Inappropriate SLA values for stratum ID %d of vegtype %d setting carbon stores to 0",
				flow_table[i].patchID, flow_table[i].vegid);
				for (j=4; j < 49; j++)
					flow_table[i].worldlink[0].valuelist[j] = 0.0;
			}
		}

		else  { 
			if (flow_table[i].worldlink == NULL)
				printf("\n Could not find hill %d  zone %d  patch %d in worldfile", 
				flow_table[i].hillID, flow_table[i].zoneID, flow_table[i].patchID);
			else
				printf("\n For patch %d Could not find vegtype of %d",
				flow_table[i].patchID, flow_table[i].vegid);

			}



	}


	/* ******************************************************* */
	/*  write out the new worldfile				  */
	/* ******************************************************* */

	printf("\n Finished making changes to worldfile  now write");

	level=0;
    	fprintf(redefine,"%d %s\n", tlevel[0].ID, LEVELNAME[level]);
    	fprintf(redefine,"%d num_%s", tlevel[0].nchildren, LEVELNAME[level+1]);
   	for(n=0;n<tlevel[0].nchildren; n++) {
		writenextlevel(tlevel[0].children[n], level+1, redefine);
	}

	fclose(redefine);
	fclose(oldworld);

}
示例#24
0
void DreamGenContext::startloading(const Room *room) {
	data.byte(kCombatcount) = 0;
	data.byte(kRoomssample) = room->roomsSample;
	data.byte(kMapx) = room->mapX;
	data.byte(kMapy) = room->mapY;
	data.byte(kLiftflag) = room->liftFlag;
	data.byte(kManspath) = room->b21;
	data.byte(kDestination) = room->b21;
	data.byte(kFinaldest) = room->b21;
	data.byte(kFacing) = room->b22;
	data.byte(kTurntoface) = room->b22;
	data.byte(kCounttoopen) = room->countToOpen;
	data.byte(kLiftpath) = room->liftPath;
	data.byte(kDoorpath) = room->doorPath;
	data.byte(kLastweapon) = -1;
	al = room->b27;
	push(ax);
	al = room->b31;
	ah = data.byte(kReallocation);
	data.byte(kReallocation) = al;
	dx = bx;
	Common::String name = getFilename(*this);
	engine->openFile(name);
	cs.word(kHandle) = 1; //only one handle
	flags._c = false;
	readheader();
	allocateload();
	ds = ax;
	data.word(kBackdrop) = ax;
	dx = (0);
	loadseg();
	ds = data.word(kWorkspace);
	dx = (0);
	cx = 132*66;
	al = 0;
	fillspace();
	loadseg();
	sortoutmap();
	allocateload();
	data.word(kSetframes) = ax;
	ds = ax;
	dx = (0);
	loadseg();
	ds = data.word(kSetdat);
	dx = 0;
	cx = (64*128);
	al = 255;
	fillspace();
	loadseg();
	allocateload();
	data.word(kReel1) = ax;
	ds = ax;
	dx = 0;
	loadseg();
	allocateload();
	data.word(kReel2) = ax;
	ds = ax;
	dx = 0;
	loadseg();
	allocateload();
	data.word(kReel3) = ax;
	ds = ax;
	dx = 0;
	loadseg();
	allocateload();
	data.word(kReels) = ax;
	ds = ax;
	dx = 0;
	loadseg();
	allocateload();
	data.word(kPeople) = ax;
	ds = ax;
	dx = 0;
	loadseg();
	allocateload();
	data.word(kSetdesc) = ax;
	ds = ax;
	dx = 0;
	loadseg();
	allocateload();
	data.word(kBlockdesc) = ax;
	ds = ax;
	dx = 0;
	loadseg();
	allocateload();
	data.word(kRoomdesc) = ax;
	ds = ax;
	dx = 0;
	loadseg();
	allocateload();
	data.word(kFreeframes) = ax;
	ds = ax;
	dx = 0;
	loadseg();
	ds = data.word(kFreedat);
	dx = 0;
	cx = (16*80);
	al = 255;
	fillspace();
	loadseg();
	allocateload();
	data.word(kFreedesc) = ax;
	ds = ax;
	dx = (0);
	loadseg();
	closefile();
	findroominloc();
	deletetaken();
	setallchanges();
	autoappear();
	al = data.byte(kNewlocation);
	getroomdata();
	data.byte(kLastweapon) = -1;
	data.byte(kMandead) = 0;
	data.word(kLookcounter) = 160;
	data.byte(kNewlocation) = 255;
	data.byte(kLinepointer) = 254;
	ax = pop();
	if (al != 255) {
		data.byte(kManspath) = al;
		push(bx);
		autosetwalk();
		bx = pop();
	}
	findxyfrompath();
}
示例#25
0
文件: main.c 项目: Tingles/Project2
int main(int argc, char * argv[]){
  
  extern Storage array_ops;
  extern Storage bst_ops;
  FILE *input;
  char buff[linemax];
  Meta header = {0,0,0};
  
  if((input = fopen("../backup.bin","rb+")) == NULL){
    printf("Problem opening data file.\n");
    exit(EXIT_FAILURE);
  }
  /*read header record for file meta data.*/
  header = readheader(input);
  
  /*specify backend storage/index methods.*/
  CountryIndex.ops = bst_ops;
  ActualDataStorage.ops = array_ops;

  /*initalize data structures*/
  initialize_env(&ActualDataStorage, &CountryIndex, &header);
  /*
   *read datastructures from binary backup.  Index must be read first because thats
   * how it was written out.
   */
  (CountryIndex.ops.load) (&CountryIndex, input);
  (ActualDataStorage.ops.load) (&ActualDataStorage, input);
  
  /*Done loding data from backup, open stream for transaction.*/
  fclose(input);
  if ((input = fopen(argv[1], "r")) == 0){
    printf("Problem opening data file.\n%m\n");
    exit(EXIT_FAILURE);
  }
  while(fgets(buff,linemax,input) != 0){
    char *target, *action;
    ActionCode AC;
    struct query thisquery;
    
    printf("%s", buff);
    
    target = strip(parsetransrec(buff));
    action = buff;
    AC = action2enum(action);
    
    switch(AC){
    case Query_name:{
      /*sequential search through ActualDataStorage.*/
      thisquery = (ActualDataStorage.ops.transact) (&ActualDataStorage, &AC, target);
      printf(">> %d probes.\n", thisquery.ncomparisons);
    }break;
    case Query_keyid:{
      /*
       *Direct address in ActualDataStorage, record is either there or it's not.
       */
      thisquery = (ActualDataStorage.ops.transact) (&ActualDataStorage, &AC, (void *) atoi(target));
      printf(">> %d probes.\n", thisquery.ncomparisons);

    }break;
    case Query_code:{
      /*
       *BST walk, through CountryIndex., at worst case the # of comparisons is 
       * the height of the tree.
       */
      int drp;
      struct query extraquery = {-1,0};
      thisquery = (CountryIndex.ops.transact) (&CountryIndex, &AC, target);
      if ((drp = thisquery.success) > 0){
	ActionCode tmp = Query_keyid;
	extraquery = (ActualDataStorage.ops.transact) (&ActualDataStorage,&tmp,(void *) drp);
	printf(">> %d + %d probes.\n", thisquery.ncomparisons, extraquery.ncomparisons);
      }
      else{
	printf(">> %d + %d probes.\n",thisquery.ncomparisons, extraquery.ncomparisons);
      }
    }break;
    case List_name:{
      /*
       *What is this?
       */
	printf("List by name is not implemented.\n");
    }break;
    case List_keyid:{
      /*
       *List all countries by Id. This could be a sequential traversal over 
       * ActualDataStorage.
       */
      (ActualDataStorage.ops.transact) (&ActualDataStorage, &AC, target);
    }break;
    case List_code:{
      /*
       *List all countries by Code. Implementation is an *inorder* traversal of
       *  our BST.
       */
      (CountryIndex.ops.transact) (&CountryIndex, &AC, &CountryIndex.root);
    }break;
    default:break;
    }
  }
  exit(EXIT_SUCCESS);
}
示例#26
0
int main(int argc, char* argv[])
{
	unsigned short wanted_fsType;
	 filename = argv[1];

	printf("\n\nTTFPATCH v1.0 - (C) by Wolfram Esser [[email protected]] 2001-02-23\n");


	if (argc != 2 && argc != 3)	// usage
	{
		printf("Provides an easy way for font designers to set the 'embeddable' flags\n");
		printf("of their own true type fonts. If you want to prohibit embedding of your\n");
		printf("font e.g. in Acrobat PDF files, simply run: 'ttfpatch myfont.ttf 2'\n\n");
		printf ("Usage: ttfpatch TrueTypeFontFile [NewFsTypeValue]\n");
		printf ("\n");
		printf ("fsType values:\n");
		printf ("       0: embedding for permanent installation\n");
		printf ("       1: reserved - do not use!\n");
		printf ("       2: embedding restricted (not allowed!)\n");
		printf ("       4: embedding for preview & printing allowed\n");
		printf ("       8: embedding for editing allowed\n");

		pause();
		return 1;
	}


	fontfile = fopen(filename, "rb");	// open font for analysis
	if(! fontfile)
	{
		printf ("\nError: Could not open fontfile '%s' for reading\n", filename);
		pause();
		return 1;
	}

	printf ("\n");
	printf ("- Opened: '%s'\n", filename);
	if (readheader())							// now read the header and find value and position of fsType
	{
		fclose(fontfile);
		pause();
		return 1;	
	}

	if(argc == 3)	//  user wants to change fsType
	{
		wanted_fsType = atoi(argv[2]);
		printf ("- Wanted fsType: hex:'%04x'\n", wanted_fsType);
		printlicencebits((unsigned short)wanted_fsType);

		if(wanted_fsType & 0x0001)	// allowed bit combination?
		{
			printf ("\nError: fsType & 0x0001 bit is reserved. must be zero!\n");
			fclose(fontfile);
			pause();
			return 1;
		}

		// allowed bit combination?
		if((wanted_fsType & 0x0002) && ((wanted_fsType & 0x0004) || (wanted_fsType & 0x0008)))
		{
			printf ("\nError: fsType & 0x0002 bit set, and (embedding allowed 0x0004 or 0x0008)\n");
			fclose(fontfile);
			pause();
			return 1;
		}

		// anything to change???
		if(wanted_fsType == tab_fsType)
		{
			printf ("\nNothing to do... wanted fsType %d already stored in TTF file!\n", wanted_fsType);
			fclose(fontfile);
			pause();
			return 1;
		}


		// OK - now read the WHOLE TTF file into memory
		printf ("- TTF filesize: '%d' bytes\n", ttf_filesize);

		fseek(fontfile, 0, SEEK_SET);				// rewind
		ttf_allbytes = new char[ttf_filesize];		// get memory to hold the fonts bytes
		if(! ttf_allbytes)
		{
			printf("\nError: Internal error: could not get enough memory for file\n");
			fclose(fontfile);
			pause();
			return 1;
		}

		// now read all the bytes
		unsigned long bytesread = fread(ttf_allbytes, 1, ttf_filesize, fontfile);

		if(bytesread != ttf_filesize)
		{
			printf ("\nError: Could not read %d bytes from fontfile (read: %d)\n", ttf_filesize, bytesread);
			fclose(fontfile);
			pause();
			return 1;
		}
		printf("- OK: read: '%d' bytes from file\n", bytesread);

		// now store the new value
		char* Pwanted_fsType = (char*) (&wanted_fsType);
		ttf_allbytes[tab_fsType_pos+1] = *Pwanted_fsType;	// swap bytes for big-endian!
		ttf_allbytes[tab_fsType_pos] = *(Pwanted_fsType+1);

		// reopen file - now for writing!!!
		fclose(fontfile);
		fontfile = fopen(filename, "wb");
		if(! fontfile)
		{
			printf ("\nError: Could not open fontfile '%s' for reading\n", filename);
			pause();
			return 1;
		}
		unsigned long byteswritten = fwrite(ttf_allbytes, 1, ttf_filesize, fontfile);

		if(byteswritten != ttf_filesize)
		{
			printf ("\nError: Could not write %d bytes to fontfile (written: %d)\n", ttf_filesize, byteswritten);
			fclose(fontfile);
			pause();
			return 1;
		}
		printf("- OK: written: '%d' bytes to file\n", byteswritten);
	}
	else
	{
		printf("\nNothing changed! - No new fsType value specified\n");
		printf("Run program without any arguments to get usage hints\n");
	}


	pause();
	return 0;
}
示例#27
0
// This method reads a stack from the given stream. The stack is set to
// have parent MCDispatch, and filename MCcmd. It is designed to be used
// for embedded stacks/deployed stacks/revlet stacks.
IO_stat MCDispatch::readstartupstack(IO_handle stream, MCStack*& r_stack)
{
	char version[8];
	uint1 charset, type;
	char *newsf;
	if (readheader(stream, version) != IO_NORMAL
	        || IO_read_uint1(&charset, stream) != IO_NORMAL
	        || IO_read_uint1(&type, stream) != IO_NORMAL
	        || IO_read_string(newsf, stream) != IO_NORMAL)
		return IO_ERROR;

	// MW-2008-10-20: [[ ParentScripts ]] Set the boolean flag that tells us whether
	//   parentscript resolution is required to false.
	s_loaded_parent_script_reference = false;

	MCtranslatechars = charset != CHARSET;
	delete newsf; // stackfiles is obsolete

	MCStack *t_stack = nil;
	/* UNCHECKED */ MCStackSecurityCreateStack(t_stack);
	t_stack -> setparent(this);
	
	// MM-2013-10-30: [[ Bug 11333 ]] Set the filename of android mainstack to apk/mainstack (previously was just apk).
	//   This solves relative file path referencing issues.
#ifdef TARGET_SUBPLATFORM_ANDROID
    char *t_filename;
    /* UNCHECKED */ MCMemoryNewArray(MCCStringLength(MCcmd) + 11, t_filename);
    MCCStringFormat(t_filename, "%s/mainstack", MCcmd);
	t_stack -> setfilename(t_filename);
#else
   	t_stack -> setfilename(strclone(MCcmd));
#endif
	
	
	if (IO_read_uint1(&type, stream) != IO_NORMAL
	        || type != OT_STACK && type != OT_ENCRYPT_STACK
	        || t_stack->load(stream, version, type) != IO_NORMAL)
	{
		delete t_stack;
		return IO_ERROR;
	}

	if (t_stack->load_substacks(stream, version) != IO_NORMAL
	        || IO_read_uint1(&type, stream) != IO_NORMAL
	        || type != OT_END)
	{
		delete t_stack;
		return IO_ERROR;
	}

	// We are reading the startup stack, so this becomes the root of the
	// stack list.
	stacks = t_stack;

	r_stack = t_stack;

#ifndef _MOBILE
	// Make sure parent script references are up to date.
	if (s_loaded_parent_script_reference)
		t_stack -> resolveparentscripts();
#else
	// Mark the stack as needed parentscript resolution. This is done after
	// aux stacks have been loaded.
	if (s_loaded_parent_script_reference)
		t_stack -> setextendedstate(True, ECS_USES_PARENTSCRIPTS);
#endif

	return IO_NORMAL;
}
示例#28
0
// MW-2012-02-17: [[ LogFonts ]] Actually load the stack file (wrapped by readfile
//   to handle font table cleanup).
IO_stat MCDispatch::doreadfile(const char *openpath, const char *inname, IO_handle &stream, MCStack *&sptr)
{
	Boolean loadhome = False;
	char version[8];

	if (readheader(stream, version) == IO_NORMAL)
	{
		if (strcmp(version, MCversionstring) > 0)
		{
			MCresult->sets("stack was produced by a newer version");
			return IO_ERROR;
		}

		// MW-2008-10-20: [[ ParentScripts ]] Set the boolean flag that tells us whether
		//   parentscript resolution is required to false.
		s_loaded_parent_script_reference = false;

		uint1 charset, type;
		char *newsf;
		if (IO_read_uint1(&charset, stream) != IO_NORMAL
		        || IO_read_uint1(&type, stream) != IO_NORMAL
		        || IO_read_string(newsf, stream) != IO_NORMAL)
		{
			MCresult->sets("stack is corrupted, check for ~ backup file");
			return IO_ERROR;
		}
		delete newsf; // stackfiles is obsolete
		MCtranslatechars = charset != CHARSET;
		sptr = nil;
		/* UNCHECKED */ MCStackSecurityCreateStack(sptr);
		if (stacks == NULL)
			sptr->setparent(this);
		else
			sptr->setparent(stacks);
		sptr->setfilename(strclone(openpath));

		if (MCModeCanLoadHome() && type == OT_HOME)
		{
			char *lstring = NULL;
			char *cstring = NULL;
			IO_read_string(lstring, stream);
			IO_read_string(cstring, stream);
			delete lstring;
			delete cstring;
		}

		MCresult -> clear();

		if (IO_read_uint1(&type, stream) != IO_NORMAL
		    || type != OT_STACK && type != OT_ENCRYPT_STACK
		    || sptr->load(stream, version, type) != IO_NORMAL)
		{
			if (MCresult -> isclear())
				MCresult->sets("stack is corrupted, check for ~ backup file");
			destroystack(sptr, False);
			sptr = NULL;
			return IO_ERROR;
		}
		
		// MW-2011-08-09: [[ Groups ]] Make sure F_GROUP_SHARED is set
		//   appropriately.
		sptr -> checksharedgroups();
		
		if (sptr->load_substacks(stream, version) != IO_NORMAL
		        || IO_read_uint1(&type, stream) != IO_NORMAL
		        || type != OT_END)
		{
			if (MCresult -> isclear())
				MCresult->sets("stack is corrupted, check for ~ backup file");
			destroystack(sptr, False);
			sptr = NULL;
			return IO_ERROR;
		}

		if (stacks != NULL)
		{
			MCStack *tstk = stacks;
			do
			{
				if (sptr->hasname(tstk->getname()))
				{
					MCAutoNameRef t_stack_name;
					/* UNCHECKED */ t_stack_name . Clone(sptr -> getname());

					delete sptr;
					sptr = NULL;

					if (strequal(tstk->getfilename(), openpath))
						sptr = tstk;
					else
					{
						MCdefaultstackptr->getcard()->message_with_args(MCM_reload_stack, MCNameGetOldString(tstk->getname()), openpath);
						tstk = stacks;
						do
						{
							if (MCNameIsEqualTo(t_stack_name, tstk->getname(), kMCCompareCaseless))
							{
								sptr = tstk;
								break;
							}
							tstk = (MCStack *)tstk->next();
						}
						while (tstk != stacks);
					}

					return IO_NORMAL;
				}
				tstk = (MCStack *)tstk->next();
			}
			while (tstk != stacks);
		}
		
		appendstack(sptr);
		
		sptr->extraopen(false);

		// MW-2008-10-28: [[ ParentScript ]]
		// We just loaded a stackfile, so check to see if parentScript resolution
		// is required and if so do it.
		// MW-2009-01-28: [[ Inherited parentScripts ]]
		// Resolving parentScripts may allocate memory, so 'resolveparentscripts'
		// will return false if it fails to allocate what it needs. At some point
		// this needs to be dealt with by deleting the stack and returning an error,
		// *However* at the time of writing, 'readfile' isn't designed to handle
		// this - so we just ignore the result for now (note that all the 'load'
		// methods *fail* to check for no-memory errors!).
		if (s_loaded_parent_script_reference)
			sptr -> resolveparentscripts();
		
	}
	else
	{
		MCS_seek_set(stream, 0);
		if (stacks == NULL)
		{
			MCnoui = True;
			MCscreen = new MCUIDC;
			/* UNCHECKED */ MCStackSecurityCreateStack(stacks);
			MCdefaultstackptr = MCstaticdefaultstackptr = stacks;
			stacks->setparent(this);
			stacks->setname_cstring("revScript");
			uint4 size = (uint4)MCS_fsize(stream);
			char *script = new char[size + 2];
			script[size] = '\n';
			script[size + 1] = '\0';
			if (IO_read(script, sizeof(char), size, stream) != IO_NORMAL
			        || !stacks->setscript(script))
			{
				delete script;
				return IO_ERROR;
			}
		}
		else
		{
			char *tname = strclone(inname);
			
			// MW-2008-06-12: [[ Bug 6476 ]] Media won't open HC stacks
			if (!MCdispatcher->cut(True) || hc_import(tname, stream, sptr) != IO_NORMAL)
			{
				MCresult->sets("file is not a stack");
				delete tname;
				return IO_ERROR;
			}
		}
	}
	return IO_NORMAL;
}
示例#29
0
int main (int argc, char **argv)
{
    int idx;
    register char *progname;

    atexit (cleanup);
    signal (SIGINT, (void (*)(int))abnormal);
    progname = getcwd (orgdir, _MAX_PATH - 1);  /* keeps the compiler happy */


    if (argc == 1)
    {
        copyright("ICMAKE Binary Makefile Executor", version, release);
        progname = program_name(argv[0]);
        printf ("This program is run as a child process of icmake.\n"
                "Usage: %s [-t] bimfile\n"
                "where: -t      - option indicating that 'bimfile' must be\n"
                "                 removed on exit.\n"
                "       bimfile - binary makefile to execute.\n\n"
            , progname);
        return 1;
    }

    if (!strcmp(argv[1], "-t"))           /* -t option found */
    {
        argv[1] = argv[0];                /* remove the -t argument */
        argv++; 
        argc--; 
        bimname = argv[1];              /* define temporary name */
    }

    if (!(infile = fopen (argv [1], READBINARY)))
        error("cannot open bimfile '%s' to read", argv[1]);

    headerp = readheader(infile, (size_t)version[0]);

                                        /* return array of global vars */
    if ((INT16)(nvar = getvar(infile, headerp, &var)) == -1)
        error("invalid macro file, cannot read variable section");

        /* global strings haven't been initialized by the compiler yet, */
        /* so that's icm-exec's job                                     */
    for (idx = 0; idx < nvar; ++idx)
    {
        if (typeValue(var + idx) == e_str)
            var[idx] = *stringConstructor();
    }

    fseek(infile, headerp->offset[3], SEEK_SET);

    {
        LISTVAR_ env = *listConstructor();

        environ2list(&env);
        push(&env);             /* envp: 3rd arg of main() */
        listDestructor(&env);
    }

    {
        LISTVAR_ args = *listConstructor_s_cPP((size_t)argc, argv);
        push(&args);            /* argv: 2nd arg of main() */
        listDestructor(&args);
    }

    {
        INTVAR_ nArgs = *intConstructor_i(argc - 1);
        push(&nArgs);           /* argc: 1st arg of main() */
    }

    process();

    return retval;
}