コード例 #1
0
ファイル: fileio.c プロジェクト: ofringer/suntans
/*
 * Function: GetString
 * Usage: GetString(string,"file.dat","ufile",&status);
 * ----------------------------------------------------
 * Obtains the string associated with the key "ufile" from the
 * file "file.dat".
 *
 */
void GetString(char *string, char *filename, char *str, int *status)
{
  int ispace;
  char c, istr[BUFFERLENGTH], ostr[BUFFERLENGTH];
  FILE *ifile = fopen(filename,"r");
  *status = 0;

  while(1) {
    mygetline(ifile,istr,"");
    if(strlen(istr)==0)
      break;
    getchunk(istr,ostr);
    if(!strcmp(ostr,str)) {
      for(ispace=strlen(ostr);ispace<strlen(istr);ispace++) 
	if(!isspace(istr[ispace]))
	  break;
      if(ispace==strlen(istr)-1)
	*status=0;
      else
	*status=1;
      getchunk(&(istr[ispace]),string);
      break;
    }
  }
  fclose(ifile);
}
コード例 #2
0
ファイル: tanglec.c プロジェクト: Drooids/axiom
/* memory map the input file into the global buffer and get the chunk */
int main(int argc, char *argv[]) {
  int fd;
  struct stat filestat;
  if ((argc == 1) || (argc > 3)) { 
    perror("Usage: tangle filename chunkname");
    exit(-1);
  }
  fd = open(argv[1],O_RDONLY);
  if (fd == -1) {
    perror("Error opening file for reading");
    exit(-2);
  }
  if (fstat(fd,&filestat) < 0) {
    perror("Error getting input file size");
    exit(-3);
  }
  bufsize = (int)filestat.st_size;
  buffer = mmap(0,filestat.st_size,PROT_READ,MAP_SHARED,fd,0);
  if (buffer == MAP_FAILED) {
    close(fd);
    perror("Error reading the file");
    exit(-4);
  }
  if (argc == 2) {
    getchunk("*");
  } else {
    getchunk(argv[2]);
  }
  close(fd);
  return(0);
}
コード例 #3
0
ファイル: fileio.c プロジェクト: ofringer/suntans
/*
 * Function: GetValue
 * Usage: Nkmax = (int)GetValue("datafile","Nkmax");
 * --------------------------------------------
 * Returns the value of the specified variable defined in datafile.
 *
 */
double GetValue(char *filename, char *str, int *status)
{
  int ispace;
  char c, istr[BUFFERLENGTH], ostr[BUFFERLENGTH];
  FILE *ifile = MyFOpen(filename,"r","GetValue");
  *status = 0;

  while(1) {
    mygetline(ifile,istr,"");
    if(strlen(istr)==0)
      break;
    getchunk(istr,ostr);
    if(!strcmp(ostr,str)) {
      for(ispace=strlen(ostr);ispace<strlen(istr);ispace++) 
	if(!isspace(istr[ispace]))
	  break;
      if(ispace==strlen(istr)-1)
	*status=0;
      else
	*status=1;
      getchunk(&(istr[ispace]),ostr);
      break;
    }
  }
  fclose(ifile);
  
  if(*status) 
    return strtod(ostr,(char **)NULL);
  else
    return 0;
}
コード例 #4
0
ファイル: tanglec.c プロジェクト: Drooids/axiom
/* print lines in this chunk, possibly recursing into getchunk */
int printchunk(int i, int chunklinelen, char *chunkname) {
  int j;
  int k;
  int linelen;
  char *getname;
  int getlen = 0;
  if (DEBUG==3) { printf("===   \\start{%s}   ===\n",chunkname); }
  for (k=i+chunklinelen+1; ((linelen=nextline(k)) != -1); ) {
    if ((getlen=foundGetchunk(k,linelen)) > 0) {
       getname = getChunkname(k,getlen);
       getchunk(getname);
       free(getname);
       k=k+getlen+12l;
    } else {
      if ((linelen >= 11) && (foundEnd(k,chunkname) == 1)) {
      if (DEBUG==3) { printf("===   \\end{%s}   ===\n",chunkname); }
      return(k+12);
    } else {
      if (DEBUG==2) { 
        printf("======== printchunk else %d %d\n",k,linelen); 
      }
      printline(k,linelen);
      k=k+linelen+1;
    }
  }}
  if (DEBUG==2) {
     printf("=================\\out{%s} %d\n",chunkname,k); 
  }
  return(k);
}
コード例 #5
0
ファイル: fileio.c プロジェクト: ofringer/suntans
/*
 * Function: getelement()
 * Usage: n=getelement(ifile);
 * ---------------------------
 * Returns the first numbers in the line up until the first space.
 */
double getelement(FILE *ifile)
{
  char istr[BUFFERLENGTH], ostr[BUFFERLENGTH];
  int i=0;
  mygetline(ifile,istr,"");
  getchunk(istr,ostr);
  return strtod(ostr,(char **)NULL);
}
コード例 #6
0
main()
{
    int where;
    char *whine;
    void *f;
    char *text;
    int size;

    f = newchunk(stdin, ":");

    while ( (text = getchunk(f, &size)) )
	printf("[%.*s]\n", size, text);

    freechunk(f);
}
コード例 #7
0
ファイル: spherematch.c プロジェクト: MCTwo/DEIMOS
IDL_LONG spherematch
  (int      argc,
   void *   argv[])
{
   IDL_LONG    npoints1;
   double    *  ra1;
   double    *  dec1;
   IDL_LONG    npoints2;
   double    *  ra2;
   double    *  dec2;
   double    matchlength;
   double    minchunksize;
	 IDL_LONG *match1;
	 IDL_LONG *match2;
   double    *  distance12;
	 IDL_LONG *nmatch;

	 double myx1,myy1,myz1;
	 IDL_LONG maxmatch, jmax;
	 double currra,sep;
	 IDL_LONG i,j,k,rachunk,decchunk;
	 IDL_LONG retval=1;

   /* 0. allocate pointers from IDL */
   npoints1 = *((IDL_LONG *)argv[0]);
   ra1 = (double *)argv[1];
   dec1 = (double *)argv[2];
   npoints2 = *((IDL_LONG *)argv[3]);
   ra2 = (double *)argv[4];
   dec2 = (double *)argv[5];
   matchlength = *(double *)argv[6];
   minchunksize = *(double *)argv[7];
   match1 = (IDL_LONG *)argv[8];
   match2 = (IDL_LONG *)argv[9];
   distance12 = (double *)argv[10];
   nmatch = (IDL_LONG *)argv[11];

	 /* 1. define chunks */
	 setchunks(ra1,dec1,npoints1,minchunksize,&rabounds,
						 &decbounds,&nra,&ndec,&raoffset);
	 
	 /* 2. assign targets to chunks, with minFibreSpacing of leeway */
	 assignchunks(ra2,dec2,npoints2,raoffset,matchlength,minchunksize,&nchunk2,
								&chunklist2,rabounds,decbounds,nra,ndec);

	 /* 3. make x, y, z coords -- compute (x,y,z)1 on the fly - DPF */
	 xx2=(double *) IDL_GetScratch(&vxx2,npoints2,sizeof(double));
	 yy2=(double *) IDL_GetScratch(&vyy2,npoints2,sizeof(double));
	 zz2=(double *) IDL_GetScratch(&vzz2,npoints2,sizeof(double));
	 for(i=0;i<npoints2;i++) {
		 xx2[i]=cos(DEG2RAD*ra2[i])*cos(DEG2RAD*dec2[i]);
		 yy2[i]=sin(DEG2RAD*ra2[i])*cos(DEG2RAD*dec2[i]);
		 zz2[i]=sin(DEG2RAD*dec2[i]);
	 } /* end for i */

	 /* 4. run matching */
	 maxmatch = (*nmatch);  /* if nmatch != 0 then fill arrays up to maxmatch */
	 (*nmatch)=0;
	 for(i=0;i<npoints1;i++) {
	   currra=fmod(ra1[i]+raoffset,360.);
	   getchunk(currra,dec1[i],&rachunk,&decchunk,rabounds,decbounds,nra,ndec);
	   jmax=nchunk2[decchunk][rachunk];
	   if(jmax>0) {
	     myx1=cos(DEG2RAD*ra1[i])*cos(DEG2RAD*dec1[i]);
	     myy1=sin(DEG2RAD*ra1[i])*cos(DEG2RAD*dec1[i]);
	     myz1=sin(DEG2RAD*dec1[i]);
	     for(j=0;j<jmax;j++) {
	       k=chunklist2[decchunk][rachunk][j];
	       sep=separation(myx1,myy1,myz1,xx2[k],yy2[k],zz2[k]);
	       if(sep<matchlength) {
					 if(maxmatch>(*nmatch)) {
						 match1[(*nmatch)]=i;
						 match2[(*nmatch)]=k;
						 distance12[(*nmatch)]=sep;
					 } /* end if */
					 (*nmatch)++;
	       } /* end if */
	     } /* end for j */
	   } /* end if jmax>0 */
	 } /* end for i */
	 
	 /* 4. clean up after chunks */
	 unassignchunks(&nchunk2,&chunklist2,nra,ndec);
	 unsetchunks(&rabounds,&decbounds,&nra,&ndec);
	 
	 /* 6. free memory */
	 free_memory();

   return retval;
}
コード例 #8
0
ファイル: uips.c プロジェクト: h16o2u9u/rtoss
int main (int argc, char **argv)
{
 if (argc<3)
 {
  fprintf (stderr,"Universal IPS Patcher - Copyright 2003 Steve Nickolas\n");
  fprintf (stderr,"usage: uips source.ext patch.ips [outfile.ext]\n");
  return -1;
 }
 sourcefile=fopen(argv[1],"r+b");
 if (!sourcefile)
 {
  fprintf (stderr,"Source file ");
  perror(argv[1]);
  return -1;
 }
 if (argc>3)
 {
  f=fopen(argv[3],"wb");
 }
 if(f)
 {
  fcopy(sourcefile, f);
  fclose(f);
  fclose(sourcefile);
  sourcefile=fopen(argv[3],"r+b");
  strcpy(outname,argv[3]);
 }

 patchfile=fopen(argv[2],"rb");
 if (!patchfile)
 {
  fprintf (stderr,"Patch file ");
  perror(argv[2]);
  return -1;
 }

 fseek(patchfile, 0, SEEK_END);
 patchsize = (int) ftell(patchfile);
 fseek(patchfile, 0, SEEK_SET);
 chunkarray = (char*)malloc(patchsize);

 if(!chunkarray)
 {
  fprintf (stderr,"Cannot allocate memory.");
  return -1;
 }

 isitanips();

 printf ("Applying Patch '%s' to file '%s'...\n", argv[2], argv[1]);

 while (!feof(patchfile))
 {
  getaddress();
  getnumbytes();
  if (numbytes) getchunk();
  if (numbytes) applypatch(); else applyrle();
 }
 closefiles();

 /* avert warning */
 return 40;
}