Beispiel #1
0
void
rco_fwrite (rRCOFile_writehelper * rcoH, void *buffer, uint32_t len)
{
  // memory writing
  if (rcoH->tables) {
    uint32_t len4 = ALIGN_TO_4 (len);

    if (rcoH->memPos + len4 > rcoH->tablesBuffered) {
      rcoH->tablesBuffered = rcoH->memPos + len4 + RCO_WRITE_MEM_BUFFER;
      rcoH->tables = realloc (rcoH->tables, rcoH->tablesBuffered);
    }

    memcpy ((uint8_t *) rcoH->tables + rcoH->memPos, buffer, len);
    if (len % 4) {
      memset ((uint8_t *) rcoH->tables + rcoH->memPos + len, 0, 4 - (len % 4));
    }
    rcoH->memPos += len4;
    if (rcoH->memPos > rcoH->tablesSize)
      rcoH->tablesSize = rcoH->memPos;

  } else {
    filewrite (rcoH->fp, buffer, len);

    // always add 4 byte padding (should add an argument, but will always be
    // TRUE anyway, so I cbf)
    if (len % 4) {
      uint32_t zero = 0;

      filewrite (rcoH->fp, &zero, 4 - (len % 4));
    }
  }
}
Beispiel #2
0
/* Write the name of the level set to the given solution file.
 */
static int writesolutionsetname(fileinfo *file, char const *setname)
{
    char	zeroes[16] = "";
    int		n;

    n = strlen(setname) + 1;
    return filewriteint32(file, n + 16, NULL)
	&& filewrite(file, zeroes, 16, NULL)
	&& filewrite(file, setname, n, NULL);
}
Beispiel #3
0
int
filewrjobfull(File *f, job j)
{
    int nl;

    fileaddjob(f, j);
    nl = strlen(j->tube->name);
    return
        filewrite(f, j, &nl, sizeof nl) &&
        filewrite(f, j, j->tube->name, nl) &&
        filewrite(f, j, &j->r, sizeof j->r) &&
        filewrite(f, j, j->body, j->r.body_size);
}
static void stgopt(char *start, char *end) {
    char symbols[_maxoptvars][_aliasmax + 1];
    int seq, match_length, repl_length;

    assert(sequences != NULL);
    while (start < end) {
        if ((sc_debug & sNOOPTIMIZE) != 0 || sc_status != statWRITE) {
            /* do not match anything if debug-level is maximum */
            filewrite(start);
        } else {
            seq = 0;
            while (sequences[seq].find) {
                assert(seq >= 0);
                if (matchsequence(start, end, sequences[seq].find, symbols,
                                  &match_length)) {
                    char *replace = replacesequence(sequences[seq].replace,
                                                    symbols, &repl_length);
                    /* If the replacement is bigger than the original section, we may need
                     * to "grow" the staging buffer. This is quite complex, due to the
                     * re-ordering of expressions that can also happen in the staging
                     * buffer. In addition, it should not happen: the peephole optimizer
                     * must replace sequences with *shorter* sequences, not longer ones.
                     * So, I simply forbid sequences that are longer than the ones they
                     * are meant to replace.
                     */
                    assert(match_length >= repl_length);
                    if (match_length >= repl_length) {
                        strreplace(start, replace, match_length, repl_length,
                                   (int) (end - start));
                        end -= match_length - repl_length;
                        free(replace);
                        code_idx -= sequences[seq].savesize;
                        seq = 0; /* restart search for matches */
                    } else {
                        /* actually, we should never get here (match_length<repl_length) */
                        assert(0);
                        seq++;
                    } /* if */
                } else {
                    seq++;
                } /* if */
            } /* while */
            assert(sequences[seq].find == NULL);
            filewrite(start);
        } /* if */
        assert(start < end);
        start += strlen(start) + 1; /* to next string */
    } /* while (start<end) */
}
Beispiel #5
0
/*
 *  read a remote file
 */
int
readfile1(Node *node)
{
	Biobuf *bp;
	char buf[4*1024];
	long off;
	int n;
	int tries;

	if(changedir(node->parent) < 0)
		return -1;

	for(tries = 0; tries < 4; tries++){
		switch(data(OREAD, &bp, "RETR", s_to_c(node->remname))){
		case Extra:
			break;
		case TempFail:
			continue;
		default:
			return seterr(nosuchfile);
		}
		off = 0;
		while((n = read(Bfildes(bp), buf, sizeof buf)) > 0){
			if(filewrite(node, buf, off, n) != n){
				off = -1;
				break;
			}
			off += n;
		}
		if(off < 0)
			return -1;

		/* make sure a file gets created even for a zero length file */
		if(off == 0)
			filewrite(node, buf, 0, 0);

		close(Bfildes(bp));
		switch(getreply(&ctlin, msg, sizeof(msg), 0)){
		case Success:
			return off;
		case TempFail:
			continue;
		default:
			return seterr(nosuchfile);
		}
	}
	return seterr(nosuchfile);
}
Beispiel #6
0
int
filewrjobshort(File *f, job j)
{
    int r, nl;

    nl = 0; // name len 0 indicates short record
    r = filewrite(f, j, &nl, sizeof nl) &&
        filewrite(f, j, &j->r, sizeof j->r);
    if (!r) return 0;

    if (j->r.state == Invalid) {
        filermjob(j->file, j);
    }

    return r;
}
Beispiel #7
0
int
do_write(int fd, void *dst, u32 cnt)
{
    if (fd < 0 || fd >= NOFILE || !fs_current->ofile[fd])
        return -1;
    return filewrite(fs_current->ofile[fd], dst, cnt);
}
Beispiel #8
0
/*  stgwrite
 *
 *  Writes the string "st" to the staging buffer or to the output file. In the
 *  case of writing to the staging buffer, the terminating byte of zero is
 *  copied too, but... the optimizer can only work on complete lines (not on
 *  fractions of it. Therefore if the string is staged, if the last character
 *  written to the buffer is a '\0' and the previous-to-last is not a '\n',
 *  the string is concatenated to the last string in the buffer (the '\0' is
 *  overwritten). This also means an '\n' used in the middle of a string isn't
 *  recognized and could give wrong results with the optimizer.
 *  Even when writing to the output file directly, all strings are buffered
 *  until a whole line is complete.
 *
 *  Global references: stgidx  (altered)
 *                     stgbuf  (altered)
 *                     staging (referred to only)
 */
SC_FUNC void stgwrite(const char *st)
{
  int len;

  if (staging) {
    assert(stgidx==0 || stgbuf!=NULL);  /* staging buffer must be valid if there is (apparently) something in it */
    if (stgidx>=2 && stgbuf[stgidx-1]=='\0' && stgbuf[stgidx-2]!='\n')
      stgidx-=1;                       /* overwrite last '\0' */
    while (*st!='\0') {                /* copy to staging buffer */
      CHECK_STGBUFFER(stgidx);
      stgbuf[stgidx++]=*st++;
    } /* while */
    CHECK_STGBUFFER(stgidx);
    stgbuf[stgidx++]='\0';
  } else {
    len=(stgbuf!=NULL) ? strlen(stgbuf) : 0;
    CHECK_STGBUFFER(len+strlen(st)+1);
    strcat(stgbuf,st);
    len=strlen(stgbuf);
    if (len>0 && stgbuf[len-1]=='\n') {
      filewrite(stgbuf);
      stgbuf[0]='\0';
    } /* if */
  } /* if */
}
Beispiel #9
0
/*  stgout
 *
 *  Writes the staging buffer to the output file via stgstring() (for
 *  reversing expressions in the buffer) and stgopt() (for optimizing). It
 *  resets "stgidx".
 *
 *  Global references: stgidx  (altered)
 *                     stgbuf  (referred to only)
 *                     staging (referred to only)
 */
SC_FUNC void stgout(int index)
{
  int reordered=0;
  int idx;

  if (!staging)
    return;
  assert(pipeidx==0);

  /* first pass: sub-expressions */
  if (sc_status==statWRITE)
    reordered=stgstring(&stgbuf[index],&stgbuf[stgidx]);
  stgidx=index;

  /* second pass: optimize the buffer created in the first pass */
  if (sc_status==statWRITE) {
    if (reordered) {
      stgopt(stgpipe,stgpipe+pipeidx,filewrite);
    } else {
      /* there is no sense in re-optimizing if the order of the sub-expressions
       * did not change; so output directly
       */
      for (idx=0; idx<pipeidx; idx+=strlen(stgpipe+idx)+1)
        filewrite(stgpipe+idx);
    } /* if */
  } /* if */
  pipeidx=0;  /* reset second pipe */
}
Beispiel #10
0
int
sys_write(struct file *f, char *p, int n)
{
  if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0)
    return -1;
  return filewrite(f, p, n);
}
/********************************************************
* num_simulation *
* *
* Purpose: Simulate numerical solution for Thermal Entry
* *
* Parameters *
* FILE *f - file pointer
* i,j,iter - loop counters for nodes horizontal, vertical, 
*          and iteration number *
* W,H - horizontal and vertical nodes calculated 
*       from input data *
* *
* Returns *
* None (void) *
********************************************************/
void num_simulation(PROGRAMDATA pd)
{
   int i;
	FILE *f;
	PLATEPOINT *Hold;

	f=filewrite(pd);

	// error checking
	if(f==NULL)
	{
		printf("File can be read but not writen to.\n");
		getchar();
		exit (1);
	}  

   fprintf(f,"iter,pos");
   for(i=0;i<pd.Ny;i++){
      fprintf(f,",%le",pd.pp[i].r);
   }
   fprintf(f,"\n0,0");
   for(i=0;i<pd.Ny;i++){
      fprintf(f,",%le",pd.pp[i].Temp);
   }
   fprintf(f,"\n");

   pd.iter=0;

	//This loop will look through every core temperature node
	/*The loop will continue as long as the Maximum residual of the
	current iteration is larger than the defined maximum residual*/
	do
	{
		pd.iter++;
		//Need to reset or else MaxRes will always > abs(Res) after the first iteration

		//Simulates the innerbody, then the boundaries. Writes to pd.pp2
		pd=num_sim_body(pd);

		//swap the addresses
		//The addresses will be swapped so that the latest timestep (pp2) will take the place of the old data (pp),
		//the old data will be overwriten with even newer data.
		//pp is only ever written to durring initialization. During simulation, it is only read.
		Hold = pd.pp;
		pd.pp = pd.pp2;
		pd.pp2 = Hold;

		//Print off the maximum residual and root mean squared for each iteration
		fprintf(f,"%d,%d",pd.iter, (double)pd.iter*pd.dx);
      for(i=0;i<pd.Ny;i++){
         fprintf(f,",%le",pd.pp[i].Temp);
      }
      fprintf(f,"\n");

	}
	while(pd.iter<=MAX_ITER ); //|| iter<=MAX_ITER

	fclose(f);
}
Beispiel #12
0
Datei: file.c Projekt: sctb/em
/* ARGSUSED */
int
filesave(int f, int n)
{
	if (curbp->b_fname[0] == '\0')
		return (filewrite(f, n));
	else
		return (buffsave(curbp));
}
Beispiel #13
0
//Done
int
sys_write(int fd,char *p,int n)
{
  struct file *f;

  f = fdlookup(fd);
  return filewrite(f, p, n);
}
Beispiel #14
0
/* Write the header bytes to the given solution file.
 */
static int writesolutionheader(fileinfo *file, int ruleset, int flags,
			       int extrasize, unsigned char const *extra)
{
    return filewriteint32(file, CSSIG, NULL)
	&& filewriteint8(file, ruleset, NULL)
	&& filewriteint16(file, flags, NULL)
	&& filewriteint8(file, extrasize, NULL)
	&& filewrite(file, extra, extrasize, NULL);
}
int init_module()
{
  char *filename="/root/test1.c";

  printk("<1>read file from kernel.\n");
  fileread(filename);
  filewrite(filename, "kernel write test\n");
  return 0;
}
Beispiel #16
0
void 
swapOut(struct proc* p)
{
  //write to file
  char filename[9];
    struct file* f;
    uint i;
    pte_t* pte=0;
    getSwapFileName(p, filename);

    //cprintf("swapout %s %d\n", p->name, p->pid);
    //release(&inswapper_lk);
    //acquire(&inswapper_lk);
    release(&ptable.lock);
    f = openKernelFile(filename, O_CREATE | O_WRONLY);
    acquire(&ptable.lock);
    //cprintf("sfff\n");
    //release(&inswapper_lk);
    if(f == 0)
      panic("swapout: file open error\n");

    //cprintf("swapout: before write\n");
    int freed = 0;
    for (i = 0; i < p->sz; i += PGSIZE) {
         if (!(pte = walkpgdir(p->pgdir, (void *) i, 0)))
             panic("swapout: pte should exist\n");
         //cprintf("walkpgdir: ok\n");
        if (!(*pte & PTE_P))
            panic("swapout: page not present\n");
        if((*pte & PTE_SHR) || !(*pte & PTE_U))
          continue;
        char *addr=(char*)p2v(PTE_ADDR(*pte));
        //acquire(&inswapper_lk);
        release(&ptable.lock);
        filewrite(f, addr, PGSIZE);
        acquire(&ptable.lock);
       // release(&inswapper_lk);
        //cprintf("(w=%s)", addr);
        kfree(addr);
        *pte = 0;
        freed++;
        //cprintf("swapout: wrote %d\n",i/PGSIZE);
    }
    //cprintf("swapout freed %d\n", freed);
    //kfree((char*) p->pgdir);
    //cprintf("swapout: after write\n");
    //freevm(p->pgdir);
   // acquire(&inswapper_lk);
    release(&ptable.lock);
    fileclose(f);
    acquire(&ptable.lock);
   // release(&inswapper_lk);
}
/*  stgset
 *
 *  Sets staging on or off. If it's turned off, the staging buffer must be
 *  initialized to an empty string. If it's turned on, the routine makes sure
 *  the index ("stgidx") is set to 0 (it should already be 0).
 *
 *  Global references: staging  (altered)
 *                     stgidx   (altered)
 *                     stgbuf   (contents altered)
 */
void stgset(int onoff) {
    staging = onoff;
    if (staging) {
        assert(stgidx == 0);
        stgidx = 0;
        CHECK_STGBUFFER(stgidx);
        /* write any contents that may be put in the buffer by stgwrite()
         * when "staging" was 0
         */
        if (stgbuf[0] != '\0')
            filewrite(stgbuf);
    } /* if */
    stgbuf[0] = '\0';
}
/********************************************************
* printLabPlates *
* *
* Purpose: prints the simulation results to the appropriate file
* *
* Parameters *
* f - File stream, from filewrite
* W,H - horizontal and vertical nodes calculated 
*       from input data *
* i,j - horizontal and vertical nodes calculated 
*       from input data *
* *
********************************************************/
void printLabPlates(PROGRAMDATA pd)
{
	FILE *f;
	int i;

	f = filewrite(pd);//get file stream
	if (f == NULL) return;//if something went wrong, exit and continue

	//header
	fprintf(f, "VARIABLES = ""X"", ""T""\n");
	fprintf(f, "ZONE I=%hd, F=POINT\n", pd.Ny);

	//loop heights, starting from the bottom
	
		for (i = 0; i<pd.Ny; i++)//loop width, starting from the left
		{
			//All if the values, in order, in scientific notation. See header for order
			fprintf(f, "%+12.7lg %+12.7lg\n"
				, pd.pp[i].r, 1-pd.pp[i].Temp);
		}
	fclose(f);//close the file stream
	return;
}
Beispiel #19
0
void swapOut(struct proc* p){
  //create flie
  char id_as_str[3]; // need to pre determine number of digits in p->pid
  itoa(p->pid,id_as_str);
  char path[strlen(id_as_str) + 5];
  strcat(path,0,id_as_str,".swap");
  p->swapped_file = kernel_open(path,O_CREATE | O_WRONLY);
  
  pte_t *pte;
  int i;
  uint pa;
  for(i = 0; i < p->sz; i += PGSIZE){
    if((pte = walkpgdir(p->pgdir, (void *) i, 0)) == 0)
      panic("copyuvm: pte should exist");
    if(!(*pte & PTE_P))
      panic("copyuvm: page not present");
    pa = PTE_ADDR(*pte);
    //cprintf("p->swapped_file %d\n",p->swapped_file);
    if(filewrite(p->swapped_file,p2v(pa),PGSIZE) < 0)
      panic("filewrite: error in swapOut");
  }
      
  int fd;
  for(fd = 0; fd < NOFILE; fd++){
    if(p->ofile[fd] && p->ofile[fd] == p->swapped_file){
     fileclose(p->ofile[fd]);
     p->ofile[fd] = 0;
     break;
    }
  }
  p->swapped_file = 0;
  p->swapped = 1;
  
  deallocuvm(p->pgdir,p->sz,0);
  p->state = SLEEPING_SUSPENDED;
  
}
Beispiel #20
0
/*  stgwrite
 *
 *  Writes the string "st" to the staging buffer or to the output file. In the
 *  case of writing to the staging buffer, the terminating byte of zero is
 *  copied too, but... the optimizer can only work on complete lines (not on
 *  fractions of it. Therefore if the string is staged, if the last character
 *  written to the buffer is a '\0' and the previous-to-last is not a '\n',
 *  the string is concatenated to the last string in the buffer (the '\0' is
 *  overwritten). This also means an '\n' used in the middle of a string isn't
 *  recognized and could give wrong results with the optimizer.
 *  Even when writing to the output file directly, all strings are buffered
 *  until a whole line is complete.
 *
 *  Global references: stgidx  (altered)
 *                     stgbuf  (altered)
 *                     staging (referred to only)
 */
void stgwrite(const char *st)
{
  int len;
  int st_len = strlen(st);

  if (staging) {
    assert(stgidx==0 || stgbuf!=NULL);  /* staging buffer must be valid if there is (apparently) something in it */
    if (stgidx>=2 && stgbuf[stgidx-1]=='\0' && stgbuf[stgidx-2]!='\n')
      stgidx-=1;                       /* overwrite last '\0' */

    CHECK_STGBUFFER(stgidx+st_len+1);
    memcpy(stgbuf+stgidx, st, st_len+1);
    stgidx+=st_len+1;
  } else {
    len=(stgbuf!=NULL) ? strlen(stgbuf) : 0;
    CHECK_STGBUFFER(len+st_len+1);
    memcpy(stgbuf+len, st, st_len+1);
    len+=st_len;
    if (len>0 && stgbuf[len-1]=='\n') {
      filewrite(stgbuf);
      stgbuf[0]='\0';
    } /* if */
  } /* if */
}
Beispiel #21
0
/*  stgwrite
 *
 *  Writes the string "st" to the staging buffer or to the output file. In the
 *  case of writing to the staging buffer, the terminating byte of zero is
 *  copied too, but... the optimizer can only work on complete lines (not on
 *  fractions of it. Therefore if the string is staged, if the last character
 *  written to the buffer is a '\0' and the previous-to-last is not a '\n',
 *  the string is concatenated to the last string in the buffer (the '\0' is
 *  overwritten). This also means an '\n' used in the middle of a string isn't
 *  recognized and could give wrong results with the optimizer.
 *  Even when writing to the output file directly, all strings are buffered
 *  until a whole line is complete.
 *
 *  Global references: stgidx  (altered)
 *                     stgbuf  (altered)
 *                     staging (referred to only)
 */
SC_FUNC void stgwrite(const char *st)
{
  int len;

  CHECK_STGBUFFER(0);
  if (staging) {
    if (stgidx>=2 && stgbuf[stgidx-1]=='\0' && stgbuf[stgidx-2]!='\n')
      stgidx-=1;                       /* overwrite last '\0' */
    while (*st!='\0') {                /* copy to staging buffer */
      CHECK_STGBUFFER(stgidx);
      stgbuf[stgidx++]=*st++;
    } /* while */
    CHECK_STGBUFFER(stgidx);
    stgbuf[stgidx++]='\0';
  } else {
    CHECK_STGBUFFER(strlen(stgbuf)+strlen(st)+1);
    strcat(stgbuf,st);
    len=strlen(stgbuf);
    if (len>0 && stgbuf[len-1]=='\n') {
      filewrite(stgbuf);
      stgbuf[0]='\0';
    } /* if */
  } /* if */
}
void interface::on_actionSave_triggered()
{
    QString filename;
    QString filesave=QFileDialog::getSaveFileName(this,"save data","","Gea Tuning data (*.gea)");

    if(filesave.isEmpty()){return;}

    QStringList filenameparse = filesave.split(".");

    if(filenameparse.count()==2){
        filename=filenameparse[0];
    }
    else if(filenameparse.count()==1){
        filename=filesave;
    }

    filename += ".gea";

    QFile filestream(filename);
    if(!filestream.open(QFile::WriteOnly|QFile::Text|QFile::Truncate)){
        QMessageBox::critical(this,"Failed","File failed to save");
        return;
    }

    QTextStream filewrite(&filestream);

    filewrite<<ui->txtTPSOff->text()<<","<<ui->txtTPSFull->text()<<endl;
    filestream.flush();

    filewrite<<ui->txtBaseMs->text()<<","<<ui->txtOpenMs->text()<<endl;
    filestream.flush();

    int i;

    for(i=0;i<cdata;i++){
        filewrite<<ui->tblInj->item(i,0)->text()<<",";
        filewrite<<ui->tblInj->item(i,1)->text()<<",";
        filewrite<<ui->tblInj->item(i,2)->text()<<",";
        filewrite<<ui->tblInj->item(i,3)->text()<<",";
        filewrite<<ui->tblInj->item(i,4)->text()<<",";
        filewrite<<ui->tblInj->item(i,5)->text()<<",";
        filewrite<<ui->tblInj->item(i,6)->text()<<",";
        filewrite<<ui->tblInj->item(i,7)->text()<<",";
        filewrite<<ui->tblInj->item(i,8)->text()<<",";
        filewrite<<ui->tblInj->item(i,9)->text()<<",";
        filewrite<<ui->tblInj->item(i,10)->text()<<",";
        filewrite<<ui->tblInj->item(i,11)->text()<<endl;
        filestream.flush();
    }

    for(i=0;i<cdata;i++){
        filewrite<<ui->tblIgn->item(i,0)->text()<<",";
        filewrite<<ui->tblIgn->item(i,1)->text()<<",";
        filewrite<<ui->tblIgn->item(i,2)->text()<<",";
        filewrite<<ui->tblIgn->item(i,3)->text()<<",";
        filewrite<<ui->tblIgn->item(i,4)->text()<<",";
        filewrite<<ui->tblIgn->item(i,5)->text()<<",";
        filewrite<<ui->tblIgn->item(i,6)->text()<<",";
        filewrite<<ui->tblIgn->item(i,7)->text()<<",";
        filewrite<<ui->tblIgn->item(i,8)->text()<<",";
        filewrite<<ui->tblIgn->item(i,9)->text()<<",";
        filewrite<<ui->tblIgn->item(i,10)->text()<<",";
        filewrite<<ui->tblIgn->item(i,11)->text()<<endl;
        filestream.flush();
    }

    filestream.close();
}
Beispiel #23
0
// packing: use RCO_DATA_COMPRESSION_* constants
uint8_t
write_rco (rRCOFile * rco, char *fn, writerco_options opts)
{
  uint32_t i;
  rRCOFile_writehelper rcoH;

  // delete file if exists
  if (file_exists (fn)) {
    if (remove (fn)) {
      error ("Unable to write to file %s", fn);
      return FALSE;
    }
  }

  rcoH.rco = rco;
  rcoH.fp = fopen (fn, "wb");
  if (!rcoH.fp) {
    error ("Unable to open file %s", fn);
    return FALSE;
  }

  PRFHeader header;

  header.signature = RCO_SIGNATURE;
  header.version =
      (opts.packHeader == RCO_DATA_COMPRESSION_RLZ ? 0x95 : opts.packHeader ==
      RCO_DATA_COMPRESSION_ZLIB ? 0x90 : 0x71);
  if (rco->verId) {		// we won't actually use specified value,
    // rather, we'll require using the minimum
    // version from above
    if (rco->verId > header.version)
      header.version = rco->verId;
  }
  header.null = 0;
  header.compression = (opts.packHeader << 4) | (rco->umdFlag & 0xF);

  header.pMainTable = 0xA4;	// pretty much always the case
  // set other sections to nothing for now
  header.pVSMXTable = header.pTextTable = header.pSoundTable =
      header.pModelTable = header.pImgTable = header.pObjTable =
      header.pAnimTable = RCO_NULL_PTR;
  header.pUnknown = header.pFontTable = RCO_NULL_PTR;

  // don't know positions of text/label/event data too, but we do know the
  // lengths for label/events
  // header.pTextData = header.pLabelData = header.pEventData = 0;
  header.lLabelData = rco->labelsLen;
  header.lEventData = rco->eventsLen;
  header.lTextData = 0;

  // set pointer sections to blank too
  header.pTextPtrs = header.pImgPtrs = header.pModelPtrs = header.pSoundPtrs =
      header.pObjPtrs = header.pAnimPtrs = RCO_NULL_PTR;

  header.lTextPtrs = header.lImgPtrs = header.lModelPtrs = header.lSoundPtrs =
      header.lObjPtrs = header.lAnimPtrs = 0;

  // also blank...
  header.pImgData = header.pSoundData = header.pModelData = RCO_NULL_PTR;
  header.lImgData = header.lSoundData = header.lModelData = 0;

  header.unknown[0] = header.unknown[1] = header.unknown[2] = 0xFFFFFFFF;

  // write resources to a separate file to get around the issue of unknown
  // packed size when writing the header (and you can't change it backed after
  // the header is packed...)
  FILE *fTmp = NULL;

  if ((rco->tblImage && rco->tblImage->numSubentries)
      || (rco->tblSound && rco->tblSound->numSubentries)
      || (rco->tblModel && rco->tblModel->numSubentries)) {
    uint32_t totalPackedLen = 0;
    rRCOEntry *rcoNode;

    fTmp = tmpfile ();

    if (rco->tblImage && rco->tblImage->numSubentries) {
      for (rcoNode = rco->tblImage->firstChild; rcoNode;
	  rcoNode = rcoNode->next) {
	// our compression decision thing
	uint32_t c = ((rRCOImgModelEntry *) (rcoNode->extra))->compression;

	if (((rRCOImgModelEntry *) (rcoNode->extra))->format < RCO_IMG_BMP) {
	  if (opts.packImgCompr != -1)
	    c = opts.packImgCompr;
	} else {
	  if (opts.packImg != -1)
	    c = opts.packImg;
	}

	if (rcoNode->srcLenUnpacked) {
	  rcoNode->srcLen = rco_write_resource (fTmp, rcoNode, c, &opts, rco);
	  if (!rcoNode->srcLen && rcoNode->labelOffset != RCO_NULL_PTR)
	    warning ("[resource] Can't write image resource '%s'!",
		rco->labels + rcoNode->labelOffset);
	}
	rcoNode->srcCompression = c;
	rcoNode->srcAddr = totalPackedLen;

	totalPackedLen +=
	    (rcoNode->srcLen % 4 ? (rcoNode->srcLen / 4) * 4 +
	    4 : rcoNode->srcLen);
      }
      header.lImgData = totalPackedLen;
    }

    totalPackedLen = 0;
    if (rco->tblSound && rco->tblSound->numSubentries) {
      for (rcoNode = rco->tblSound->firstChild; rcoNode;
	  rcoNode = rcoNode->next) {
	if (rcoNode->srcLenUnpacked) {
	  uint32_t packedLen = rco_write_resource (fTmp, rcoNode,
	      RCO_DATA_COMPRESSION_NONE,
	      &opts,
	      rco);

	  if (!packedLen && rcoNode->labelOffset != RCO_NULL_PTR)
	    warning ("[resource] Can't write sound resource '%s'!",
		rco->labels + rcoNode->labelOffset);
	  totalPackedLen += ALIGN_TO_4 (packedLen);
	  // if(totalPackedLen %4) totalPackedLen += 4-(totalPackedLen%4);
	}
      }
      header.lSoundData = totalPackedLen;
    }

    totalPackedLen = 0;
    if (rco->tblModel && rco->tblModel->numSubentries) {
      for (rcoNode = rco->tblModel->firstChild; rcoNode;
	  rcoNode = rcoNode->next) {
	uint32_t c = ((rRCOImgModelEntry *) (rcoNode->extra))->compression;

	if (opts.packModel != -1)
	  c = opts.packModel;

	if (rcoNode->srcLenUnpacked) {
	  rcoNode->srcLen = rco_write_resource (fTmp, rcoNode, c, &opts, rco);
	  if (!rcoNode->srcLen && rcoNode->labelOffset != RCO_NULL_PTR)
	    warning ("[resource] Can't write model resource '%s'!",
		rco->labels + rcoNode->labelOffset);
	}
	rcoNode->srcCompression = c;
	rcoNode->srcAddr = totalPackedLen;

	totalPackedLen +=
	    (rcoNode->srcLen % 4 ? (rcoNode->srcLen / 4) * 4 +
	    4 : rcoNode->srcLen);
      }
      header.lModelData = totalPackedLen;
    }

    rewind (fTmp);
  }

  filewrite (rcoH.fp, &header, sizeof (header));

  rcoH.tables = 0;

  // if compressing, write to memory
  if (opts.packHeader) {
    rcoH.tables = malloc (RCO_WRITE_MEM_BUFFER);
    rcoH.memPos = rcoH.tablesSize = 0;
    rcoH.tablesBuffered = RCO_WRITE_MEM_BUFFER;
    rcoH.memOffset = ftell (rcoH.fp);
  }

  rcoH.sizeImg = rcoH.sizeModel = rcoH.sizeSound = rcoH.sizeText = 0;
  rcoH.longestLangData = 0;

  write_entry (&rcoH, &(rco->tblMain), 0xA4	/* typically where the main
						 * table is written to */ , 0,
      TRUE);

  // fix up object/anim extra data
  {
    if (rco->tblObj)
      rco_write_fix_refs (rco->tblObj, &rcoH, rco, RCO_OBJ_EXTRA_LEN,
	  RCO_OBJ_EXTRA_LEN_NUM, TRUE);
    if (rco->tblAnim)
      rco_write_fix_refs (rco->tblAnim, &rcoH, rco, RCO_ANIM_EXTRA_LEN,
	  RCO_ANIM_EXTRA_LEN_NUM, FALSE);
  }

  {				// write hashtable data

    /* { // special case for text hashes if(rco->numPtrText) { header.pTextPtrs
     * = rcowrite_ftell(&rcoH); for(i=0; i<rco->numPtrText; i++) { uint32_t
     * writePtr = 0; if(rco->ptrText[i].textEntry && rco->ptrText[i].index)
     * writePtr = rco->ptrText[i].textEntry->offset + sizeof(RCOEntry) +
     * sizeof(RCOTextEntry) + (rco->ptrText[i].index -
     * ((rRCOTextEntry*)(rco->ptrText[i].textEntry->extra))->indexes)*sizeof(RCOTextIndex);
     * rco_fwrite(&rcoH, &writePtr, sizeof(uint32_t)); } } } */
    if (rco->tblText) {
      header.pTextPtrs = rcowrite_ftell (&rcoH);
      header.lTextPtrs = 0;

      // generate sorted list of text entries, sorted by languageID
      rRCOEntry **sList = make_sorted_list_of_subentries (rco->tblText,
	  text_hash_table_qsort);

      for (i = 0; i < rco->tblText->numSubentries; i++)
	header.lTextPtrs += write_text_hash_table (&rcoH, sList[i], rco);
      free (sList);

      header.lTextPtrs *= sizeof (uint32_t);
    }

    if (rco->tblImage) {
      header.pImgPtrs = rcowrite_ftell (&rcoH);
      header.lImgPtrs =
	  write_hash_table (&rcoH, rco->tblImage, rco) * sizeof (uint32_t);
    }
    if (rco->tblModel) {
      header.pModelPtrs = rcowrite_ftell (&rcoH);
      header.lModelPtrs =
	  write_hash_table (&rcoH, rco->tblModel, rco) * sizeof (uint32_t);
    }
    if (rco->tblSound) {
      header.pSoundPtrs = rcowrite_ftell (&rcoH);
      header.lSoundPtrs =
	  write_hash_table (&rcoH, rco->tblSound, rco) * sizeof (uint32_t);
    }
    if (rco->tblObj) {
      header.pObjPtrs = rcowrite_ftell (&rcoH);
      header.lObjPtrs =
	  write_hash_table (&rcoH, rco->tblObj, rco) * sizeof (uint32_t);
    }
    if (rco->tblAnim) {
      header.pAnimPtrs = rcowrite_ftell (&rcoH);
      header.lAnimPtrs =
	  write_hash_table (&rcoH, rco->tblAnim, rco) * sizeof (uint32_t);
    }
    /*
     * #define RCO_WRITERCO_WRITE_PTR_SECT(pd, pl, hp) { \ if(pl) { \ hp =
     * rcowrite_ftell(&rcoH); \ for(i=0; i<pl; i++) { \ if(pd[i]) \
     * rco_fwrite(&rcoH, &(((rRCOEntry*)(pd[i]))->offset), sizeof(uint32_t)); \
     * else { \ uint32_t zero = 0; \ rco_fwrite(&rcoH, &zero, sizeof(uint32_t)); \
     * } \ } \ } \ } //RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrText,
     * rco->numPtrText, header.pTextPtrs);
     * RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrImg, rco->numPtrImg,
     * header.pImgPtrs); RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrModel,
     * rco->numPtrModel, header.pModelPtrs);
     * RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrSound, rco->numPtrSound,
     * header.pSoundPtrs); RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrObj,
     * rco->numPtrObj, header.pObjPtrs);
     * RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrAnim, rco->numPtrAnim,
     * header.pAnimPtrs); */
  }

  {				// write label/event data (and text if
    // applicable)

    // write text (note, old behaviour - newer RCOs have text written in a
    // different location)
    if (!opts.packText && rco->tblText && rco->tblText->numSubentries) {
      rRCOEntry *rcoNode;

      header.pTextData = rcowrite_ftell (&rcoH);
      header.lTextData = rcoH.sizeText;
      for (rcoNode = rco->tblText->firstChild; rcoNode; rcoNode = rcoNode->next) {
	rco_write_text_resource (&rcoH, rcoNode, RCO_DATA_COMPRESSION_NONE,
	    &opts, ((rRCOTextEntry *) (rcoNode->extra))->lang,
	    (rco->tblText->lastChild == rcoNode));
      }
    }
    // write label+event data
    header.pLabelData = rcowrite_ftell (&rcoH);
    if (rco->labelsLen)
      rco_fwrite (&rcoH, rco->labels, rco->labelsLen);
    header.pEventData = rcowrite_ftell (&rcoH);
    if (rco->eventsLen)
      rco_fwrite (&rcoH, rco->events, rco->eventsLen);
    else if (rco->tblObj || rco->tblAnim) {	// weird case: if there's
      // object entries, there will
      // be 4 bytes for events; I'll
      // assume this covers anim as
      // well (although there isn't
      // an RCO with anim that
      // doesn't have objects)
      uint32_t zero = 0;

      rco_fwrite (&rcoH, &zero, sizeof (zero));
      header.lEventData = sizeof (zero);
    }
    // the text pointer is weird in that if there's no text, it's set equal to
    // the label pointer; even weirder, some RCOs have a null pointer (for
    // FW5.00 all except lftv_* RCOs have null pointers for pTextData if
    // there's no text)
    // my theory: if compressing, it will be RCO_NULL_PTR, otherwise it'll =
    // header.pLabelData
    // if(!header.lTextData) header.pTextData = RCO_NULL_PTR;
    // if(!header.lTextData) header.pTextData = header.pLabelData;
    if (!header.lTextData)
      header.pTextData = (opts.packHeader ? RCO_NULL_PTR : header.pLabelData);
  }

  // flush compression stuff here
  HeaderComprInfo ci;

  if (opts.packHeader) {
    uint8_t *bufferOut = NULL;

    ci.lenLongestText = rcoH.longestLangData;
    ci.lenUnpacked = rcoH.tablesSize;
    ci.lenPacked = 0;

    if (opts.packHeader == RCO_DATA_COMPRESSION_ZLIB) {
      uint32_t bound = compressBound (rcoH.tablesSize);

      bufferOut = (uint8_t *) malloc (bound);
      ci.lenPacked =
	  zlib_compress (rcoH.tables, rcoH.tablesSize, bufferOut, bound,
	  opts.zlibLevel, opts.zlibMethod);
    } else if (opts.packHeader == RCO_DATA_COMPRESSION_RLZ) {
      bufferOut = (uint8_t *) malloc (rcoH.tablesSize);
      ci.lenPacked =
	  rlz_compress (rcoH.tables, rcoH.tablesSize, bufferOut,
	  rcoH.tablesSize, opts.rlzMode);
    } else {
      error ("lulwut?");
      exit (1);
    }
    int comprMisalign = ci.lenPacked % 4;
    uint32_t packedLen = ci.lenPacked;

    if (rco->eSwap)
      es_headerComprInfo (&ci);
    filewrite (rcoH.fp, &ci, sizeof (ci));
    filewrite (rcoH.fp, bufferOut, packedLen);
    free (bufferOut);

    if (comprMisalign) {	// 4 byte align
      uint32_t zero = 0;

      filewrite (rcoH.fp, &zero, 4 - comprMisalign);
    }
  }
  // write text if packing header
  if (opts.packText && rco->tblText && rco->tblText->numSubentries) {
    rRCOEntry *rcoNode;

    // header.pTextData = rcowrite_ftell(&rcoH);
    header.pTextData = ftell (rcoH.fp);
    header.lTextData = 0;	// rcoH.sizeText;
    for (rcoNode = rco->tblText->firstChild; rcoNode; rcoNode = rcoNode->next) {
      header.lTextData +=
	  rco_write_text_resource (&rcoH, rcoNode, opts.packHeader, &opts,
	  ((rRCOTextEntry *) (rcoNode->extra))->lang,
	  (rco->tblText->lastChild == rcoNode));
    }
  }
  // write resources
  /* { uint32_t totalPackedLen = 0; if(rco->tblImage) { header.pImgData =
   * rcowrite_ftell(&rcoH); header.lImgData = rcoH.sizeImg; // TOxDO: this
   * model actually won't work - we have to update the offsets of ALL the
   * entries after packing... for(i=0; i<rco->tblImage->numSubentries; i++) {
   * uint32_t packedSize = rco_write_resource(&rcoH,
   * &(rco->tblImage->subentries[i]), RCO_DATA_COMPRESSION_NONE); // TOxDO:
   * change this // TOxDO: update packed size value uint32_t curFpos =
   * rcowrite_ftell(rcoH.fp); totalPackedLen += (packedSize % 4 ?
   * (packedSize/4)*4+4 : packedSize); } header.lImgData = totalPackedLen; }
   * totalPackedLen = 0; if(rco->tblSound) { header.pSoundData =
   * rcowrite_ftell(&rcoH); header.lSoundData = rcoH.sizeSound; for(i=0;
   * i<rco->tblSound->numSubentries; i++) { totalPackedLen +=
   * rco_write_resource(&rcoH, &(rco->tblSound->subentries[i]),
   * RCO_DATA_COMPRESSION_NONE); if(totalPackedLen %4) totalPackedLen +=
   * 4-(totalPackedLen%4); } header.lSoundData = totalPackedLen; } // TOxDO:
   * write model resources } */

  if ((rco->tblImage && rco->tblImage->numSubentries)
      || (rco->tblSound && rco->tblSound->numSubentries)
      || (rco->tblModel && rco->tblModel->numSubentries)) {
    // update data pointers
    uint32_t pos = ftell (rcoH.fp);

    if (rco->tblImage && rco->tblImage->numSubentries) {
      header.pImgData = pos;
      pos += header.lImgData;
    }
    if (rco->tblSound && rco->tblSound->numSubentries) {
      header.pSoundData = pos;
      pos += header.lSoundData;
    }
    if (rco->tblModel && rco->tblModel->numSubentries) {
      header.pModelData = pos;
      pos += header.lModelData;
    }
    // copy contents of fTmp across (uses a simple buffered copy)
    uint32_t len = header.lImgData + header.lSoundData + header.lModelData;
    uint8_t buffer[65536];

    while (len) {
      uint32_t readAmt = (len > 65536 ? 65536 : len);

      fileread (fTmp, buffer, readAmt);
      filewrite (rcoH.fp, buffer, readAmt);
      len -= readAmt;
    }

    fclose (fTmp);		// this deletes our temp file
  }
  // fix header
  if (rco->tblVSMX)
    header.pVSMXTable = rco->tblVSMX->offset;
  if (rco->tblText)
    header.pTextTable = rco->tblText->offset;
  if (rco->tblSound)
    header.pSoundTable = rco->tblSound->offset;
  if (rco->tblModel)
    header.pModelTable = rco->tblModel->offset;
  if (rco->tblImage)
    header.pImgTable = rco->tblImage->offset;
  if (rco->tblFont)
    header.pFontTable = rco->tblFont->offset;
  if (rco->tblObj)
    header.pObjTable = rco->tblObj->offset;
  if (rco->tblAnim)
    header.pAnimTable = rco->tblAnim->offset;

  rewind (rcoH.fp);
  if (rco->eSwap)
    es_rcoHeader (&header);
  filewrite (rcoH.fp, &header, sizeof (header));

  // TODO: fix resource pointers?
  // TODO: tie things up etc??

  fclose (rcoH.fp);

  return TRUE;
}
Beispiel #24
0
uint32_t
rco_write_text_resource (rRCOFile_writehelper * rcoH, rRCOEntry * entry,
    uint32_t destCompression, writerco_options * opts, uint32_t lang,
    uint8_t isLast)
{

  uint32_t len = 0;
  uint8_t *bufferMid = (uint8_t *) read_resource (entry, &len);

  if (!bufferMid)
    return 0;

  if (len != entry->srcLenUnpacked) {
    free (bufferMid);
    return 0;
  }

  rRCOTextEntry *extra = (rRCOTextEntry *) (entry->extra);

  TextComprInfo tci;
  char *textBuffer = NULL;
  uint32_t textBufferPos = 0;

  if (destCompression) {
    tci.lang = lang;
    tci.unknown = 1;
    tci.unpackedLen = 0;
    // textBuffer = (char*)malloc(1);
  }

  uint32_t i;

  for (i = 0; i < extra->numIndexes; i++) {
    uint32_t len = extra->indexes[i].length;

    if (!len)
      continue;

    if (destCompression) {
      tci.unpackedLen += ALIGN_TO_4 (len);
      textBuffer = (char *) realloc (textBuffer, tci.unpackedLen);
      memcpy (textBuffer + textBufferPos, bufferMid + extra->indexes[i].offset,
	  len);

      if (len % 4) {
	memset (textBuffer + textBufferPos + len, 0, 4 - (len % 4));
      }
      textBufferPos += ALIGN_TO_4 (len);
    } else {
      rco_fwrite (rcoH, bufferMid + extra->indexes[i].offset, len);
    }
  }

  free (bufferMid);

  if (destCompression) {
    uint8_t success = TRUE;
    uint8_t *bufferOut = NULL;

    if (destCompression == RCO_DATA_COMPRESSION_ZLIB) {
      uint32_t compSize = compressBound (tci.unpackedLen);

      bufferOut = (uint8_t *) malloc (compSize);
      tci.packedLen =
	  zlib_compress (textBuffer, tci.unpackedLen, bufferOut, compSize,
	  opts->zlibLevel, opts->zlibMethod);
    } else if (destCompression == RCO_DATA_COMPRESSION_RLZ) {
#ifdef DISABLE_RLZ
      error ("RLZ compression not supported.");
      exit (1);
#endif
      bufferOut = (uint8_t *) malloc (tci.unpackedLen);
      tci.packedLen =
	  rlz_compress (textBuffer, tci.unpackedLen, bufferOut, tci.unpackedLen,
	  opts->rlzMode);
    }

    if (!tci.packedLen) {	// compression failed
      free (bufferOut);
      bufferOut = NULL;
      success = FALSE;
    } else if (bufferOut) {
      if (isLast)
	tci.nextOffset = 0;
      else {
	tci.nextOffset = sizeof (tci) + tci.packedLen;
	tci.nextOffset = ALIGN_TO_4 (tci.nextOffset);
      }
      if (entry->rco->eSwap)
	es_textComprInfo (&tci);
      filewrite (rcoH->fp, &tci, sizeof (tci));
      if (entry->rco->eSwap)
	es_textComprInfo (&tci);

      filewrite (rcoH->fp, bufferOut, tci.packedLen);
      free (bufferOut);

      if (tci.packedLen % 4) {
	uint32_t zero = 0;

	filewrite (rcoH->fp, &zero, 4 - (tci.packedLen % 4));
      }
    } else
      success = FALSE;

    free (textBuffer);
    if (!success)
      return 0;
    return ALIGN_TO_4 (tci.packedLen) + sizeof (tci);
  }

  return 1;
}
Beispiel #25
0
// returns the length of the packed data
// TBH, I really can't be stuffed writing a buffered copy/compress/decompressor
//
// (and anyway, it may not work with future compression routines, so meh)
uint32_t
rco_write_resource (FILE * dest, rRCOEntry * entry, uint32_t destCompression,
    writerco_options * opts, rRCOFile * rco)
{

  uint32_t len = 0;
  uint8_t *bufferMid = (uint8_t *) read_resource (entry, &len);

  if (!bufferMid) {
    if (entry->labelOffset)
      warning ("Failed to read resource '%s'.",
	  rco->labels + entry->labelOffset);
    return 0;
  }

  if (len != entry->srcLenUnpacked) {
    free (bufferMid);
    return 0;
  }

  uint8_t *bufferOut;
  uint32_t packedSize = 0;

  if (destCompression == RCO_DATA_COMPRESSION_ZLIB) {
    uint32_t compSize = compressBound (entry->srcLenUnpacked);

    bufferOut = (uint8_t *) malloc (compSize);
    packedSize =
	zlib_compress (bufferMid, entry->srcLenUnpacked, bufferOut, compSize,
	opts->zlibLevel, opts->zlibMethod);
    if (!packedSize) {
      if (entry->labelOffset)
	warning ("Failed to compress resource '%s'.",
	    rco->labels + entry->labelOffset);
      return 0;
    }

    free (bufferMid);
  } else if (destCompression == RCO_DATA_COMPRESSION_RLZ) {
#ifdef DISABLE_RLZ
    error ("RLZ compression not supported.");
    exit (1);
#endif
    bufferOut = (uint8_t *) malloc (entry->srcLenUnpacked);
    packedSize =
	rlz_compress (bufferMid, entry->srcLenUnpacked, bufferOut,
	entry->srcLenUnpacked, opts->rlzMode);
    if (!packedSize) {
      if (entry->labelOffset)
	warning ("Failed to compress resource '%s'.",
	    rco->labels + entry->labelOffset);
      return 0;
    }

    free (bufferMid);
  } else {
    bufferOut = bufferMid;
    packedSize = entry->srcLenUnpacked;
  }

  filewrite (dest, bufferOut, packedSize);
  free (bufferOut);

  /*
   * char buffer[65536], outBuffer[65536]; uint32_t len=entry->srcLen; z_stream
   * out; if(destStream == RCO_DATA_COMPRESSION_ZLIB) { ZLIB_INIT_DEFLATE(out,
   * 9, Z_DEFAULT_STRATEGY); out.next_in = buffer; out.avail_in = 65536;
   * out.next_out = outBuffer; out.avail_out = 65536; }
   *
   * // copy with buffer while(len) { uint32_t readAmt = (len < 65536 ? len :
   * 65536); if(!fileread(src, &buffer, readAmt)) { fclose(src); return FALSE;
   * }
   *
   * if(destCompression == RCO_DATA_COMPRESSION_NONE) filewrite(dest, &buffer,
   * readAmt); else if(destCompression == RCO_DATA_COMPRESSION_ZLIB) {
   *
   * }
   *
   * len -= readAmt; }
   *
   * // TOxDO: also don't forget to check lenUnpacked
   *
   * fclose(src);
   *
   * if(destStream == RCO_DATA_COMPRESSION_ZLIB) deflateEnd(&out); */

  // 4byte alignment
  if (packedSize % 4) {
    uint32_t zero = 0;

    filewrite (dest, &zero, 4 - (packedSize % 4));
  }

  return packedSize;
}
Beispiel #26
0
/* *********************************************************************** */
edit_out()
{
	int		i,j;
	int		rdl;
	int		totins;			/* get total inserts */
	int		totdel;			/* get total deletes */
	unsigned char fmtwk[9];
	unsigned char timebuf[9];
	unsigned char *pnmwk;

	/* make sure we read the beginning */
	fileseek( Infile, (long)0 ) ;

	/* read into fci struct */
	if ( (rdl = fileread(Infile,&Fm,FCINSIZE) ) <=0)
	{
		disperr("COULD NOT READ %s",Pathbuf);
		return(-1);
	}
	
	charfill(&Bi,sizeof (Bi),' ');
	strncpy_s(Bi.drtdir, sizeof(Bi.drtdir), Fm.fc_drtdir, FILENMSZ);
	strncpy_s(Bi.dname, sizeof(Bi.dname), Fm.fc_dname, FILENMSZ);
	strncpy_s(Bi.dbtch, sizeof(Bi.dbtch), Fm.fc_dbtch, FILENMSZ);
	strncpy_s(Bi.frtdir, sizeof(Bi.frtdir), Fm.fc_frtdir, FILENMSZ);
	strncpy_s(Bi.fname, sizeof(Bi.fname), Fm.fc_fname, FILENMSZ);

	for( i=0 ; i < MAXMODES ; i++ )
	{
		Bi.stat[i] = Status[Fm.fc_stat[i]] ;
		Bi.dopen[i] = Fm.fc_dopen[i] ;
	}

	for( i=0 ; i < MAXIO ; i++ )
	{
		fmtstr(fmtwk,"%02d",Fm.fc_ioiter[i]);
		strncpy_s(Bi.ioiter[i], sizeof(Bi.ioiter[i]), fmtwk, 2);

		if( Fm.fc_iouid[i] > 0 )
		{
			fmtstr( fmtwk, "%03d", Fm.fc_iouid[i] ) ;
			strncpy_s(Bi.iouid[i], sizeof(Bi.iouid[i]), fmtwk, 3);
			if( ( pnmwk = getusrnam( Fm.fc_iouid[i] ) ) != (char *)ERRCODE )
			{
				strncpy_s(Bi.iouname[i], sizeof(Bi.iouname[i]), pnmwk, NMSZ);
			}
			else
			{
				charfill(Bi.iouname[i],NMSZ,'*');
			}
		}
		else
		{
			charfill(Bi.iouid[i],3,'*');
			charfill(Bi.iouname[i],NMSZ,'*');
		}
		Bi.iostatus[i] = Fm.fc_iostatus[i];
	}

	for (i=0; i< MAXMODES;i++)
	{
		fmtstr(fmtwk,"%05d",Fm.fc_rcntt[i]);
		strncpy_s(Bi.rcntt[i], sizeof(Bi.rcntt[i]), fmtwk, 5);

		fmtstr(fmtwk,"%05d",Fm.fc_dcntt[i]);
		strncpy_s(Bi.dcntt[i], sizeof(Bi.dcntt[i]), fmtwk, 5);

		fmtstr(fmtwk,"%08d",Fm.fc_kscntt[i]);
		strncpy_s(Bi.kscntt[i], sizeof(Bi.kscntt[i]), fmtwk, 8);

		fmtstr(fmtwk,"%08d",Fm.fc_kscnttf[i]);
		strncpy_s(Bi.kscnttf[i], sizeof(Bi.kscnttf[i]), fmtwk, 8);

		fmtstr(fmtwk,"%05d",Fm.fc_ercntt[i]);
		strncpy_s(Bi.ercntt[i], sizeof(Bi.ercntt[i]), fmtwk, 5);

		fmtstr(fmtwk,"%08d",Fm.fc_ekscntt[i]);
		strncpy_s(Bi.ekscntt[i],sizeof(Bi.ekscntt[i]) , fmtwk, 8);

		/* error k.s.count of function key */
		fmtstr(fmtwk,"%08d",Fm.fc_ekscnttf[i]);
		strncpy_s(Bi.ekscnttf[i], sizeof(Bi.ekscnttf[i]), fmtwk, 8);

		/* total flag count */
		fmtstr(fmtwk,"%05d",Fm.fc_flgcntt[i]);
		strncpy_s(Bi.flgcntt[i], sizeof(Bi.flgcntt[i]), fmtwk, 5);

		if (Fm.fc_fstime[i] == 0)
			charfill(Bi.fstime[i],24,'*');
		else
			timetostr(Fm.fc_fstime[i],Bi.fstime[i]);

		if (Fm.fc_strtime[i] == 0)
			charfill(Bi.strtime[i],24,'*');
		else
			timetostr(Fm.fc_strtime[i],Bi.strtime[i]);

		if (Fm.fc_lstime[i] == 0)
			charfill(Bi.lstime[i],24,'*');
		else
			timetostr(Fm.fc_lstime[i],Bi.lstime[i]);

		if (elapsed_time(i,timebuf) )   /* calculate total elapsed time */
			strncpy_s(Bi.eltimet[i], sizeof(Bi.eltimet[i]), timebuf, 8);
		else
			charfill(Bi.eltimet[i],8,'*');
	}

	/* # inserts, # deletes */
	totins = Fm.fc_mins[0] + Fm.fc_mins[1];	/* total inserts */
	totdel = Fm.fc_mdel[0] + Fm.fc_mdel[1];	/* total deletes */
	fmtstr(Bi.mins,"%05d",totins);
	fmtstr(Bi.mdel,"%05d",totdel);

	totins = Fm.fc_mdins[0] + Fm.fc_mdins[1];	/* total doc inserts */
	totdel = Fm.fc_mddel[0] + Fm.fc_mddel[1];	/* total doc deletes */
	fmtstr(Bi.mdins,"%05d",totins);
	fmtstr(Bi.mddel,"%05d",totdel);

	for (i=0; i< MAXMODES;i++)
	{
		for (j=0 ;j < MAXUSER;j++)
		{
			if (Fm.fc_muid[j][i] > 0)
		   {
			   fmtstr(fmtwk,"%03d",Fm.fc_muid[j][i]);
			   strncpy_s(Bi.muid[j][i], sizeof(Bi.muid[j][i]), fmtwk, 3);
			   if ( (pnmwk=getusrnam(Fm.fc_muid[j][i]) ) != (char *)ERRCODE)
				{
					strncpy_s(Bi.muidname[j][i], sizeof(Bi.muidname[j][i]), pnmwk, NMSZ);
				}
			     else
				{
					charfill(Bi.muidname[j][i],NMSZ,'*');
				}
			}
			else
			{
				charfill(Bi.muid[j][i],3,'*');
				charfill(Bi.muidname[j][i],NMSZ,'*');
			}
		}
	}

	Bi.sysfile = Fm.fc_sysfile;

	for (i=0; i< MAXMODES;i++)
	{
		fmtstr(fmtwk,"%05d",Fm.fc_iter[i]);
		strncpy_s(Bi.iter[i], sizeof(Bi.iter[i]), fmtwk, 5);
	}

	for (i=0; i< MAXIO;i++)
	{
		fmtstr(fmtwk,"%05d",Fm.fc_iositer[i]);
		strncpy_s(Bi.iositer[i], sizeof(Bi.iositer[i]), fmtwk, 5);

		fmtstr(fmtwk,"%05d",Fm.fc_iorcnt[i]);
		strncpy_s(Bi.iorcnt[i], sizeof(Bi.iorcnt[i]), fmtwk, 5);

		fmtstr(fmtwk,"%05d",Fm.fc_iodcnt[i]);
		strncpy_s(Bi.iodcnt[i], sizeof(Bi.iodcnt[i]), fmtwk, 5);

		if ( Fm.fc_iostime[i] == 0)
			charfill(Bi.iostime[i],24,'*');
		else
			timetostr(Fm.fc_iostime[i],Bi.iostime[i]);

		if (Fm.fc_ioetime[i] == 0)
			charfill(Bi.ioetime[i],24,'*');
		else
			timetostr(Fm.fc_ioetime[i],Bi.ioetime[i]);

		fmtstr(fmtwk,"%05d",Fm.fc_iopen[i]);
		strncpy_s(Bi.iopen[i], sizeof(Bi.iopen[i]), fmtwk, 5);
	}

	Bi.endmark= ' ';
	filewrite(BATCH_infof,&Bi,sizeof (Bi));
	filewrite(BATCH_infof,"\n",1);
	return( 0 ) ;
}
Beispiel #27
0
/*
 * Quit command. If an argument, always quit. Otherwise confirm if a buffer
 * has been changed and not written out. Normally bound to "C-X C-C".
 */
int
wquit(int f, int n)
{
    register int    s;

    if(Pmaster){
	char *result = NULL;
	int   ret;

	/* First, make sure there are no outstanding problems */ 
	if(AttachError()){
	    emlwrite(_("\007Problem with attachments!  Fix errors or delete attachments."), NULL);
	    return(FALSE);
	}

#ifdef	SPELLER
	if(Pmaster->always_spell_check)
	  if(spell(0, 0) == -1)
	    sleep(3);    /* problem, show error */
#endif
	/*
	 * if we're not in header, show some of it as we verify sending...
	 */
	display_for_send();
	packheader();
	Pmaster->arm_winch_cleanup++;
	if((!(Pmaster->pine_flags & MDHDRONLY) || any_header_changes())
	   && (ret = (*Pmaster->exittest)(Pmaster->headents,
					     redraw_pico_for_callback,
					     Pmaster->allow_flowed_text,
					     &result))){
	    Pmaster->arm_winch_cleanup--;

	    if(ret == -1){
		pico_all_done = COMP_CANCEL;
	    }
	    else{
		if(sgarbf)
		  update();

		lchange(WFHARD);			/* set update flags... */
		curwp->w_flag |= WFMODE;		/* and modeline so we  */
		sgarbk = TRUE;			/* redraw the keymenu  */
		pclear(term.t_nrow-2, term.t_nrow);
	    }

	    if(result && *result)
	      emlwrite(result, NULL);
	}
	else{
	    Pmaster->arm_winch_cleanup--;
	    pico_all_done = COMP_EXIT;
	    return(TRUE);
	}
    }
    else{
        if (f != FALSE                          /* Argument forces it.  */
        || anycb() == FALSE                     /* All buffers clean.   */
						/* User says it's OK.   */
	/* TRANSLATORS: buffer is the in-memory copy of a file */
        || (s=mlyesno_utf8(_("Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES)"), -1)) == FALSE) {
                vttidy();
#if     defined(USE_TERMCAP) || defined(USE_TERMINFO) || defined(VMS)
		kbdestroy(kbesc);
#endif
                exit(0);
        }

	if(s == TRUE){
	    if(filewrite(0,1) == TRUE)
	      wquit(1, 0);
	}
	else if(s == ABORT){
	    emlwrite(_("Exit cancelled"), NULL);
	    if(term.t_mrow == 0)
	      curwp->w_flag |= WFHARD;	/* cause bottom 3 lines to paint */
	}
        return(s);
    }

    return(FALSE);
}
Beispiel #28
0
int CHttpCurl::Download(LPCTSTR szUrl, LPCTSTR szOutputFileName , int nRectime, ICurlDownProgress *pProgress/* = NULL*/)
{
    int nRetCode = CURLE_FAILED_INIT;
    int nStatusCode = 0;
    std::string strURL = CW2A(szUrl, CP_UTF8);
    CWriteCurlFile filewrite(szOutputFileName);

    CURL *pCurl = curl_easy_init();
    if (pCurl == NULL) goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_POST, 0L);
    if (nRetCode != CURLE_OK)   goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_URL, strURL.c_str());
    if (nRetCode != CURLE_OK)   goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_FORBID_REUSE, 1);
    if (nRetCode != CURLE_OK)   goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, nRectime);
    if (nRetCode != CURLE_OK)   goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_CONNECTTIMEOUT, 5000);
    if (nRetCode != CURLE_OK)   goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, CWriteCurlFile::WriteCallBack);
    if (nRetCode != CURLE_OK)   goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, &filewrite);
    if (nRetCode != CURLE_OK)   goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    if (nRetCode != CURLE_OK)   goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_PROGRESSFUNCTION, ProgressFun);
    if (nRetCode != CURLE_OK) goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_PROGRESSDATA, (void*)pProgress); 
    if (nRetCode != CURLE_OK) goto Exit0;

    nRetCode = curl_easy_setopt(pCurl, CURLOPT_NOPROGRESS, 0); 
    if (nRetCode != CURLE_OK) goto Exit0;

    if (pProgress) pProgress->OnEvent(CurlDownEventBegin, CurlDownStatusSuc);
    nRetCode = curl_easy_perform(pCurl);
    if (nRetCode != CURLE_OK) goto Exit0;

    curl_easy_getinfo(pCurl, CURLINFO_RESPONSE_CODE, &nStatusCode);
    if (nStatusCode != 200) 
        nRetCode = nStatusCode;

Exit0:
    if (pCurl)
        curl_easy_cleanup(pCurl);
    if (nStatusCode != CURLE_OK)
    {
        if (pProgress) pProgress->OnEvent(CurlDownEventEnd, CurlDownStatusErr);
    } 
    else
    {
        if (pProgress) pProgress->OnEvent(CurlDownEventEnd, CurlDownStatusSuc);
    }
    return nRetCode;
}
Beispiel #29
0
int main()
{
    int i,j;
    
    float src1[N*N],src2[N*N];
	
    float out_fdct1[N*N],out_fdct2[N*N], out_idct[N*N];
	int *matrix1=filehand("/home/dhyandeepak/Desktop/input1.bmp");
	int in1[128][128],in2[128][128];
	for(i=0;i<LENGTH;i++)
	{
			
			for(j=0;j<LENGTH;j++)
			{
				
				in1[i][j]=mat[i][j];//store the returned matrix in in1
				printf("matrix %d",in1[i][j]);
			}
				
	}
	int *matrix2=filehand("/home/dhyandeepak/Desktop/input2.bmp");
	for(i=0;i<LENGTH;i++)
	{
			
			for(j=0;j<LENGTH;j++)
			{
					
				in2[i][j]=(mat[i][j]);//store the returned matrix in in2
			}
				
	}

	
	int l=0,k,res=0,p;
	init_dct();
	for(j=0;j<LENGTH/N;j++)
	{
	   for(i=0;i<LENGTH/N;i++)
	   {
			for(k=0;k<N;k++)
			{
				for(l=0;l<N;l++)
				{
					src1[l+N*k]=in1[(N*j+k)][(l+N*i)];//store 8X8 image block into an array
					src2[l+N*k]=in2[(N*j+k)][(l+N*i)];
					printf("src:%f ",src1[l+N*k]);
				}
				printf("\n");
			}
			printf("\n");
			
			fdct_ref(out_fdct1, src1);//find fast dct for each 8X8 blocks
			fdct_ref(out_fdct2, src2);
			int med;
			for(med=0;med<64;med++)
			{
				out_fdct1[med]=(out_fdct1[med]+out_fdct2[med])/2;
			}
			
			idct_ref(out_idct, out_fdct1);
			for(k=0;k<N;k++)
			{
			
				for(l=0;l<N;l++)
				{
					
					mat[(N*j+k)][(l+N*i)]=out_idct[l+N*k];//store 8X8  block's compressed values into the matrix itself
				}
				
			}
	   }
	   
	}
    filewrite("/home/dhyandeepak/Desktop/out.pgm");//write the matrix into file
    
    return 0;
}
Beispiel #30
0
int main(){
	filewrite();
	// fileread();

}