Exemplo n.º 1
0
mlx_name()
{
	int nblocks,block;
	GLOBRECORD *blockptr[MAXNBLOCKS+1];
	long addr[32],leng[32];	/* oversized */

	/* load multi-block file containing block to be renamed */
	Dsetdrv(mlt_drive); dsetpath(mlt_path);
	if (!readdatafile(MLXNAMTITL,mlxfile,mlxpath,MLX_EXT,0)) return;
	mlt_drive= Dgetdrv(); Dgetpath(mlt_path,mlt_drive+1);
	mlx_mem= tempmem;

	/* choose block from it */
	nblocks= scan_blocks(heap[mlx_mem].start,blockptr);
	if (!nblocks) return;	/* can't happen? */
	block= select_block(BLOCK2NAM,nblocks,blockptr);
	if ( (block<0) || (block>=nblocks) ) return;

	/* edit the comment field in the selected block, and replace file
		without warning */
	if (_mlx_name(blockptr[block]->comment))
	{
		addr[0]= heap[mlx_mem].start;
		leng[0]= heap[mlx_mem].nbytes;
		save_file(mlxfile,mlxpath,-1,addr,leng);
	}

}	/* end mlx_name() */
Exemplo n.º 2
0
mlx_extract()
{
	char filename[13],pathname[80];
	char *ext;
	int nblocks,block;
	register int i;
	long blockptr[MAXNBLOCKS+1];
	long addr[32],leng[32];	/* oversized */
	long end_record= idEND;
	GLOBRECORD *ptr;

	/* load multi-block file containing block to be extracted */
	Dsetdrv(mlt_drive); dsetpath(mlt_path);
	if (!readdatafile(MLXEXTTITL,mlxfile,mlxpath,MLX_EXT,0)) return;
	mlt_drive= Dgetdrv(); Dgetpath(mlt_path,mlt_drive+1);
	mlx_mem= tempmem;

	/* choose block from it */
	nblocks= scan_blocks(heap[mlx_mem].start,blockptr);
	if (!nblocks) return;	/* can't happen? */
	block= select_block(BLOCK2EXT,nblocks,blockptr);
	if ( (block<0) || (block>=nblocks) ) return;

	/* name of data file defaults to block comment */
	Dsetdrv(data_drive); dsetpath(data_path);
	ptr= (GLOBRECORD*)(blockptr[block]);
	copy_bytes(ptr->comment,filename,12L);
	filename[12]=0;
	ext=filename;
	for (i=0; i<9; i++) if (ext[i]=='.') break;
	if (i<9)
		ext+=(i+1);
	else
		ext= ALL_EXT;
	if (getfile(pathname,filename,ext,MLXXDATTITL)<=0) return;
	data_drive= Dgetdrv(); Dgetpath(data_path,data_drive+1);

	/* build file -- */
	i=0;

	/* -- header */
	addr[i]= (long)(&dataheader);
	leng[i++]= sizeof(dataheader);

	/* -- the selected block */
	addr[i]= blockptr[block];
	leng[i++]= blockptr[block+1] - blockptr[block] ;

	/* -- end record */
	addr[i]= (long)(&end_record);
	leng[i++]= 4;

	save_file(filename,pathname,i,addr,leng);

}	/* end mlx_extract() */
Exemplo n.º 3
0
mlx_delete()
{
	int nblocks,block;
	register int i;
	long blockptr[MAXNBLOCKS+1];
	long addr[32],leng[32];	/* oversized */
	long end_record= idEND;

	/* load multi-block file containing block to be deleted */
	Dsetdrv(mlt_drive); dsetpath(mlt_path);
	if (!readdatafile(MLXDELTITL,mlxfile,mlxpath,MLX_EXT,0)) return;
	mlt_drive= Dgetdrv(); Dgetpath(mlt_path,mlt_drive+1);
	mlx_mem= tempmem;

	/* choose block from it */
	nblocks= scan_blocks(heap[mlx_mem].start,blockptr);
	if (!nblocks) return;	/* can't happen? */
	if (nblocks==1)
	{
		form_alert(1,BADMLXDEL);
		return;
	}
	block= select_block(BLOCK2DEL,nblocks,blockptr);
	if ( (block<0) || (block>=nblocks) ) return;

	/* build file -- */
	i=0;

	/* -- header */
	addr[i]= (long)(&dataheader);
	leng[i++]= sizeof(dataheader);

	/* -- blocks before the selected block */
	if (block>0)
	{
		addr[i]= blockptr[0];
		leng[i++]= blockptr[block] - blockptr[0] ;
	}

	/* -- blocks after the selected block */
	if (block<(nblocks-1))
	{
		addr[i]= blockptr[block+1];
		leng[i++]= blockptr[nblocks] - blockptr[block+1] ;
	}

	/* -- end record */
	addr[i]= (long)(&end_record);
	leng[i++]= 4;

	save_file(mlxfile,mlxpath,-i,addr,leng);	/* replace without warning */

}	/* end mlx_delete() */
Exemplo n.º 4
0
Arquivo: atsread.c Projeto: bion/ats
void *atsread_new(t_symbol *s, int argc, t_atom *argv){
	t_symbol * temp;
	int i;
	
	t_atsread *x = (t_atsread *)pd_new(atsread_class);
  	
	// initalize
	x->berrflg = 1;
	x->data = NULL;
	x->nzdata = NULL;
	x->atshead.magic = 0;
	x->outpartials = NULL;
	x->amplist = NULL;
	x->freqlist = NULL;
	x->outnz = 1;
	x->outsines = 1;
	
	//outlets
	x->freq_out = outlet_new(&x->x_obj, &s_float);
	x->amp_out = outlet_new(&x->x_obj, &s_float);
	x->nz_out = outlet_new(&x->x_obj, &s_float);

	/* deal with creation time arguments */
	for(i = 0; i < argc; i++){
		temp = atom_getsymbol(&argv[i]);
		if(strcmp(temp->s_name, "noise") == 0){
			x->outnz = 1;
			post("ATSREAD: outputing noise, if there is any");
		}
		else if(strcmp(temp->s_name, "nonoise") == 0){
			x->outnz = 0;
			post("ATSREAD: not outputing noise");
		}
		else if(strcmp(temp->s_name, "sines") == 0){
			x->outsines = 1;
			post("ATSREAD: outputing sines");
		}
		else if(strcmp(temp->s_name, "nosines") == 0){
			x->outsines = 0;
			post("ATSREAD: not outputing sines");
		}
		else{
			//open data file
			if(temp == NULL){
				post("ATSREAD: not a valid filename");
			}
			else
				readdatafile(x, temp->s_name);
		}
	}
	return (void *)x;
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
  Table formt;
  Vector stats;
  gdImagePtr im;
  int black,white,blue;
  char *user, *formdata;
  int size,pos,x;
  float searchscore,searchincrement;
  double thisscore,score,lineheight;
  char label[5];
  int labellen;
  float variance;
  int height,width,labelheight,horizpad;
  int scoremark;
  char *votelabel;
  int lightblue;

  /**********************************
    HTTP header
    ********************************/
  /* use image/png if possible */
  printf("content-type: image/gif\n\n");
  
  /**********************************
    get info about request
    ********************************/
  formt=cgiparse();
  
  formdata=Table_gets(formt,"WIDTH");
  if (formdata!=NULL)
    width=atoi(formdata);
  else
    width=DEFAULTWIDTH;
  
  formdata=Table_gets(formt,"HEIGHT");
  if (formdata!=NULL)
    height=atoi(formdata);
  else
    height=DEFAULTHEIGHT;
 
  formdata=Table_gets(formt,"LABELHEIGHT");
  if (formdata!=NULL)
    labelheight=atoi(formdata);
  else
    labelheight=DEFAULTLABELHEIGHT;

  formdata=Table_gets(formt,"HORIZPADDING");
  if (formdata!=NULL)
    horizpad=atoi(formdata);
  else
    horizpad=DEFAULTHORIZPADDING;
 
  formdata=Table_gets(formt,"VARIANCE");
  if (formdata!=NULL)
    variance=atof(formdata);
  else
    variance=DEFAULTVARIANCE;
 
  stats=Vector_create(0);
  user=Table_gets(formt,"USER");

  if (user!=NULL)
    {
      readdatafile(stats,user);
    }

  size=Vector_getSize(stats);
  
  /**********************************
    create the image object and set it up
    ********************************/
  
  im=gdImageCreate(width+2*horizpad,height+labelheight);

  black=gdImageColorAllocate(im,0,0,0);
  white=gdImageColorAllocate(im,255,255,255);
  blue=gdImageColorAllocate(im,0,0,200);
  lightblue=gdImageColorAllocate(im,80,80,255);

  /**********************************
    perform the search. awfully inefficient.
    ********************************/
  searchincrement=(HIGHESTSCORE-LOWESTSCORE)/width;
  
  searchscore=LOWESTSCORE;
  x=0;

  while (searchscore<=HIGHESTSCORE)
    {
      score=0;

      for (pos=0;pos<size;pos++)
	{
	  thisscore= *((double*) Vector_elementAt(stats,pos));

	  score+=exp(-fabs(pow(thisscore-searchscore,2)/variance));
	}

      if (size>0)
	lineheight=score*height/size;
      else
	lineheight=0;

      gdImageLine(im,x+horizpad,height,x+horizpad,height-lineheight,white);

      searchscore+=searchincrement;
      x++;
    }

  /**********************************
    Label the x axis
    ********************************/

  for (scoremark=LOWESTSCORE;scoremark<=HIGHESTSCORE;scoremark++)
    {
      x=(scoremark-LOWESTSCORE)*(width/(HIGHESTSCORE-LOWESTSCORE));

      snprintf(label,5,"%i",scoremark);
      labellen=strlen(label);

      gdImageLine(im,x+horizpad,0,x+horizpad,height,blue);
      gdImageString(im,gdFontLarge, x+horizpad-(gdFontLarge->w/2)*labellen,height+2,label,white);
    }

  /**********************************
    Outline the actual data
    ********************************/
  gdImageRectangle(im,horizpad,1,width+horizpad,height,white);
  
  votelabel=sprintfalloc("%i samples",Vector_getSize(stats));
  gdImageString(im,gdFontLarge,width+horizpad-(gdFontLarge->w)*strlen(votelabel)-2,2,votelabel,lightblue);
  free(votelabel);

  /**********************************
    Output the data 
    ********************************/

  /* use gdImagePng if possible */
  gdImageGif(im,stdout);

  gdImageDestroy(im);

  return 0;
}
Exemplo n.º 6
0
int main( int argc, char **argv )
{
  struct pb_TimerSet timers;
  struct pb_Parameters *params;
  int rf, k, nbins, npd, * npr;
  float *binb, w;
  long long *DD, *RRS, *DRS;
  size_t memsize;
  struct cartesian *data, *random;
  FILE *outfile;
  int offset = 0;

  Triolet_init(&argc, &argv);

  pb_InitializeTimerSet( &timers );
  params = pb_ReadParameters( &argc, argv );
  options args;
  parse_args( argc, argv, &args );

  pb_SwitchToTimer( &timers, pb_TimerID_COMPUTE );
  nbins = (int)floor(bins_per_dec * (log10(max_arcmin) -
					 log10(min_arcmin)));
  memsize = (nbins+2)*sizeof(long long);

  // memory for bin boundaries
  binb = (float *)malloc((nbins+1)*sizeof(float));
  if (binb == NULL)
    {
      fprintf(stderr, "Unable to allocate memory\n");
      exit(-1);
    }
  for (k = 0; k < nbins+1; k++)
    {
      binb[k] = cos(pow(10, log10(min_arcmin) +
			k*1.0/bins_per_dec) / 60.0*D2R);
      printf("%.10f\n", binb[k]);
    }

  // memory for DD
  DD = (long long*)malloc(memsize);
  if (DD == NULL)
    {
      fprintf(stderr, "Unable to allocate memory\n");
      exit(-1);
    }
  bzero(DD, memsize);

  // memory for RR
  RRS = (long long*)malloc(memsize);
  if (RRS == NULL)
    {
      fprintf(stderr, "Unable to allocate memory\n");
      exit(-1);
    }
  bzero(RRS, memsize);

  // memory for DR
  DRS = (long long*)malloc(memsize);
  if (DRS == NULL)
    {
      fprintf(stderr, "Unable to allocate memory\n");
      exit(-1);
    }
  bzero(DRS, memsize);

  // memory for input data
  data = (struct cartesian*)malloc
    (args.npoints* sizeof(struct cartesian));
  if (data == NULL)
    {
      fprintf(stderr,
	      "Unable to allocate memory for % data points (#1)\n",
	      args.npoints);
      return(0);
    }

  random = (struct cartesian*)malloc
    (args.npoints*sizeof(struct cartesian));
  if (random == NULL)
    {
      fprintf(stderr,
	      "Unable to allocate memory for % data points (#2)\n",
	      args.npoints);
      return(0);
    }

  printf("Min distance: %f arcmin\n", min_arcmin);
  printf("Max distance: %f arcmin\n", max_arcmin);
  printf("Bins per dec: %i\n", bins_per_dec);
  printf("Total bins  : %i\n", nbins);

  // read data file
  pb_SwitchToTimer( &timers, pb_TimerID_IO );
  npd = readdatafile(params->inpFiles[0], data, args.npoints);
  pb_SwitchToTimer( &timers, pb_TimerID_COMPUTE );
  if (npd != args.npoints)
    {
      fprintf(stderr,
	      "Error: read %i data points out of %i\n",
	      npd, args.npoints);
      return(0);
    }

  // Marshal to Pyon
  tri_cartesian_dataset pyon_data = cartesian_to_arrays(data, npd, 1);

  // compute DD
  doComputeSelf(pyon_data, DD, nbins, 1, binb, &timers);

  npr = (int *) malloc(sizeof(int) * args.npoints);
  assert(npr != NULL);

  free(random);
  random = (struct cartesian *) malloc(sizeof(struct cartesian) * args.npoints * args.random_count);

  // loop through random data files
  for (rf = 0; rf < args.random_count; rf++)
    {
      // read random file
      pb_SwitchToTimer( &timers, pb_TimerID_IO );
      npr[rf] = readdatafile(params->inpFiles[rf+1], &random[offset], args.npoints);
      pb_SwitchToTimer( &timers, pb_TimerID_COMPUTE );
      offset += npr[rf];
      if (npr[rf] != args.npoints)
        {
	  fprintf(stderr,
		  "Error: read %i random points out of %i in file %s\n",
		  npr[rf], args.npoints, params->inpFiles[rf+1]);
	  return(0);
        }

    }
  // compute RR
  tri_cartesian_dataset pyon_random = cartesian_to_arrays(random, npr[0], args.random_count);
  doComputeSelf(pyon_random, RRS, nbins, args.random_count, binb, &timers);

  // compute DR
  doComputeCross(pyon_data, pyon_random, DRS, nbins, args.random_count, binb, &timers);

  // compute and output results
  if ((outfile = fopen(params->outFile, "w")) == NULL)
    {
      fprintf(stderr,
	      "Unable to open output file %s for writing, assuming stdout\n",
	      params->outFile);
      outfile = stdout;
    }

  pb_SwitchToTimer( &timers, pb_TimerID_IO );
  for (k = 1; k < nbins+1; k++)
    {
      fprintf(outfile, "%lld\n%lld\n%lld\n", DD[k], DRS[k], RRS[k]);
    }

  if(outfile != stdout)
    fclose(outfile);

  // free memory
  free(data);
  free(random);
  free(binb);
  free(DD);
  free(RRS);
  free(DRS);
  free(npr);

  pb_SwitchToTimer( &timers, pb_TimerID_NONE );
  pb_PrintTimerSet( &timers );
  pb_FreeParameters( params );
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
	int datafd;

	/* FIXME: the facility should be configurable */
	openlog("daydream", LOG_PID, LOG_LOCAL2);

	if (!(origdir = getenv("DAYDREAM"))) {
		syslog(LOG_ERR, "environment variable DAYDREAM not set");
		fputs("Environment variable DAYDREAM is not set.\n", stderr);
		exit(1);
	}
	if (chdir(origdir) == -1) {
		syslog(LOG_ERR, "cannot chdir to home directory");
		fputs("Cannot chdir to BBS home directory.\n", stderr);
		exit(1);
	}

	umask(007);

	datafd = open("data/daydream.dat", O_RDONLY);
	if (datafd == -1) {
		syslog(LOG_WARNING, "cannot open \"daydream.dat\": %s",
			strerror(errno));
		fprintf(stderr, "cannot open \"daydream.dat\": %s\n", 
			strerror(errno));
		exit(1);
	}
	if (read(datafd, &maincfg, sizeof(struct DayDream_MainConfig)) !=
		sizeof(struct DayDream_MainConfig)) {
		syslog(LOG_WARNING, "bad \"daydream.dat\": %s", 
			strerror(errno));
		fprintf(stderr, "bad \"daydream.dat\": %s\n", strerror(errno));
		exit(1);
	}
	close(datafd);
	
	if (create_directory(DDTMP, maincfg.CFG_BBSUID, 
		maincfg.CFG_BBSGID, 0770) == -1)  {
		syslog(LOG_ERR, "cannot create temporary directory: %m");
		fputs("Cannot create temporary directory.\n", stderr);
		exit(1);
	}

	initstringspace();
	srand(time(NULL));

	serhandle = 0;
	protocol = 0;
	onlinestat = 0;
	userinput = 1;
	lrp = lsp = oldlrp = oldlsp = 0;
	lrpdatname[0] = 0;
	ffilestagged = filestagged = bytestagged = fbytestagged = 0;
	*reason = 0;
	memset(&clog, 0, sizeof(struct callerslog));

	if (!getcmdline(argc, argv))
		return 0;
	

	read_conference_data();
	readdatafile((void **) &nodes, "data/multinode.dat", 0);
	readdatafile((void **) &presets, "data/access.dat", 0);
	readdatafile((void **) &secs, "data/security.dat", 0);
	readdatafile((void **) &displays, "data/display.dat", 0);
	readdatafile((void **) &exts, "data/externalcommands.dat", 0);
	readdatafile((void **) &arcs, "data/archivers.dat", 255);
	readdatafile((void **) &protocols, "data/protocols.dat", 0);

	display = 0;

	/* Check if we know which TTY we're using.. */

	olms = NewList();

	if (ul_user != -1) {
		cmdlineupload();
		return 0;
	}

	initterm();
	/* Initialize carrier loss handler */

	if (mkdir(currnode->MULTI_TEMPORARY, 0770) == -1 && errno != EEXIST) {
		syslog(LOG_ERR, "cannot create temporary directory %s (%d)",
			currnode->MULTI_TEMPORARY, errno);
		fprintf(stderr, "cannot create temporary directory %s (%d)\r\n",
			currnode->MULTI_TEMPORARY, errno);
		return 0;
	}

	signal(SIGHUP, carrieroff);
	if (!fnode) {
		signal(SIGTERM, carrieroff);
		signal(SIGINT, carrieroff);
	}


	if (fnode) {
		int ir = 0;
		while (waitforcall(ir++) != -1) {			
			visitbbs(0);
			if (forcebps)
				break;
		}
		tcflush(serhandle, TCIOFLUSH);
	} else 
		visitbbs(0);
		
	fini_keyboard();
	return 0;
}
Exemplo n.º 8
0
Arquivo: atsread.c Projeto: bion/ats
void atsread_any(t_atsread *x, t_symbol *s, int argc, t_atom *argv){
	char * filename;
	int i, j, from, to;
	t_symbol * temp;

	if(strcmp(s->s_name, "open") == 0){
		//open data file
		if(argc < 1){
			post("ATSREAD: you need to specify a file name");
			return;
		}
		
		temp = atom_getsymbol(&argv[0]);
		
		if(temp == NULL){
			post("ATSREAD: not a valid filename");
			return;
		}
		readdatafile(x, temp->s_name);
		x->berrflg = 1;
		return;
	}
	if(strcmp(s->s_name, "noise") == 0){
		x->outnz = 1;
		post("ATSREAD: outputing noise, if there is any");
		return;
	}
	if(strcmp(s->s_name, "nonoise") == 0){
		x->outnz = 0;
		post("ATSREAD: not outputing noise");
		return;
	}
	if(strcmp(s->s_name, "sines") == 0){
		x->outsines = 1;
		post("ATSREAD: outputing sines");
		return;
	}
	if(strcmp(s->s_name, "nosines") == 0){
		x->outsines = 0;
		post("ATSREAD: not outputing sines");
		return;
	}
	
	/* BELOW HERE WE DEAL WITH PARTIAL and BAND ADDING/SETTING/REMOVING */
	
	if(x->atshead.magic != 123){
		post("ATSREAD: you must open a file before setting up the partials");
		return;
	}
	if(argc < 1){
		post("ATSREAD: you need to specify at least 1 partial/band to set/add/remove");
		return;
	}
	
	if(strcmp(s->s_name, "set") == 0 || strcmp(s->s_name, "add") == 0){
		//set or add partials to output
		if(strcmp(s->s_name, "set") == 0){
			//clear the data table
			for(i = 0; i < (int)x->atshead.npartials; i++)
				x->outpartials[i] = 0;
		}
		
		for(i = 0; i < argc; i++){
			temp = atom_getsymbol(&argv[i]);
			if(strcmp(temp->s_name, "float") == 0){
				j = (int)atom_getfloat(&argv[i]);
				if(j < 1)
					j = 1;
				else if(j >= (int)x->atshead.npartials)
					j = (int)x->atshead.npartials;
				x->outpartials[j - 1] = 1;
			}
			else{
				if(sscanf(temp->s_name, "%i..%i", &from, &to) == 2){
					if(from > to){
						j = from;
						from = to;
						to = j;
					}
					if(from < 1)
						from = 1;
					if(to > (int)x->atshead.npartials)
						to = (int)x->atshead.npartials;
					for(j = from; j <= to; j++)
						x->outpartials[j-1] = 1;
				}
				else
					post("ATSREAD: %s is not a valid range (ie 1..42) or partial number (ie 12)", temp->s_name);
			}
		}
		return;
	}
	if(strcmp(s->s_name, "remove") == 0){
		//remove partials
		for(i = 0; i < argc; i++){
			temp = atom_getsymbol(&argv[i]);
			if(strcmp(temp->s_name, "float") == 0){
				j = (int)atom_getfloat(&argv[i]);
				if(j < 1)
					j = 1;
				else if(j >= (int)x->atshead.npartials)
					j = (int)x->atshead.npartials;
				x->outpartials[j - 1] = 0;
			}
			else{
				if(sscanf(temp->s_name, "%i..%i", &from, &to) == 2){
					if(from > to){
						j = from;
						from = to;
						to = j;
					}
					if(from < 1)
						from = 1;
					if(to > (int)x->atshead.npartials)
						to = (int)x->atshead.npartials;
					for(j = from; j <= to; j++)
						x->outpartials[j-1] = 0;
				}
				else
					post("ATSREAD: %s is not a valid range (ie 1..42) or partial number (ie 12)", temp->s_name);
			}
		}
		return;
	}
	if(strcmp(s->s_name, "setnz") == 0 || strcmp(s->s_name, "addnz") == 0){
		//set or add bands to output
		if(strcmp(s->s_name, "setnz") == 0){
			//clear the data table
			for(i = 0; i < 25; i++)
				x->outnzbands[i] = 0;
		}
		
		for(i = 0; i < argc; i++){
			temp = atom_getsymbol(&argv[i]);
			if(strcmp(temp->s_name, "float") == 0){
				j = (int)atom_getfloat(&argv[i]);
				if(j < 1)
					j = 1;
				else if(j >= 25)
					j = 25;
				x->outnzbands[j - 1] = 1;
			}
			else{
				if(sscanf(temp->s_name, "%i..%i", &from, &to) == 2){
					if(from > to){
						j = from;
						from = to;
						to = j;
					}
					if(from < 1)
						from = 1;
					if(to > 25)
						to = 25;
					for(j = from; j <= to; j++)
						x->outnzbands[j-1] = 1;
				}
				else
					post("ATSREAD: %s is not a valid range (ie 1..25) or band number (ie 2)", temp->s_name);
			}
		}
		return;
	}
	if(strcmp(s->s_name, "removenz") == 0){
		//remove bands
		for(i = 0; i < argc; i++){
			temp = atom_getsymbol(&argv[i]);
			if(strcmp(temp->s_name, "float") == 0){
				j = (int)atom_getfloat(&argv[i]);
				if(j < 1)
					j = 1;
				else if(j >= 25)
					j = 25;
				x->outnzbands[j - 1] = 0;
			}
			else{
				if(sscanf(temp->s_name, "%i..%i", &from, &to) == 2){
					if(from > to){
						j = from;
						from = to;
						to = j;
					}
					if(from < 1)
						from = 1;
					if(to > 25)
						to = 25;
					for(j = from; j <= to; j++)
						x->outnzbands[j-1] = 0;
				}
				else
					post("ATSREAD: %s is not a valid range (ie 1..25) or band number (ie 12)", temp->s_name);
			}
		}
		return;
	}
}
Exemplo n.º 9
0
mlx_replace()
{
	char filename[13],pathname[80];
	int mlxnblocks,mlxblock;
	int datnblocks,datblock;
	long mlxblockptr[MAXNBLOCKS+1];
	long datblockptr[MAXNBLOCKS+1];
	register int i;
	long addr[32],leng[32];	/* oversized */
	long end_record= idEND;

	/* load data file containing block to be added */
	Dsetdrv(data_drive); dsetpath(data_path);
	filename[0]=0;
	if (!readdatafile(MLXRDATTITL,filename,pathname,ALL_EXT,0)) return;
	data_drive= Dgetdrv(); Dgetpath(data_path,data_drive+1);
	data_mem= tempmem;

	/* choose block from it */
	datnblocks= scan_blocks(heap[data_mem].start,datblockptr);
	if (!datnblocks) return;	/* can't happen? */
	datblock= select_block(BLOCK2REP,datnblocks,datblockptr);
	if ( (datblock<0) || (datblock>=datnblocks) ) return;

	/* load multi-block file to receive block */
	Dsetdrv(mlt_drive); dsetpath(mlt_path);
	if (!readdatafile(MLXREPTITL,mlxfile,mlxpath,MLX_EXT,0)) return;
	mlt_drive= Dgetdrv(); Dgetpath(mlt_path,mlt_drive+1);
	mlx_mem= tempmem;

	/* choose block from it */
	mlxnblocks= scan_blocks(heap[mlx_mem].start,mlxblockptr);
	if (!mlxnblocks) return;	/* can't happen? */
	mlxblock= select_block(BLOCK2BRP,mlxnblocks,mlxblockptr);
	if ( (mlxblock<0) || (mlxblock>=mlxnblocks) ) return;

	/* because data_mem may have moved */
	scan_blocks(heap[data_mem].start,datblockptr);

	/* build file -- */
	i=0;

	/* -- header */
	addr[i]= (long)(&dataheader);
	leng[i++]= sizeof(dataheader);

	/* -- blocks before the selected block */
	if (mlxblock>0)
	{
		addr[i]= mlxblockptr[0];
		leng[i++]= mlxblockptr[mlxblock] - mlxblockptr[0] ;
	}

	/* -- new block */
	addr[i]= datblockptr[datblock];
	leng[i++]= datblockptr[datblock+1] - datblockptr[datblock] ;

	/* -- blocks after the selected block */
	if (mlxblock<(mlxnblocks-1))
	{
		addr[i]= mlxblockptr[mlxblock+1];
		leng[i++]= mlxblockptr[mlxnblocks] - mlxblockptr[mlxblock+1] ;
	}

	/* -- end record */
	addr[i]= (long)(&end_record);
	leng[i++]= 4;

	save_file(mlxfile,mlxpath,-i,addr,leng);	/* replace without warning */

}	/* end mlx_replace() */
Exemplo n.º 10
0
mlx_add()
{
	long blockptr[MAXNBLOCKS+1];
	char filename[13],pathname[80];
	int block,nblocks,create_it;
	register int i;
	long addr[32],leng[32];	/* oversized */
	long end_record= idEND;

	/* load data file containing block to be added */
	Dsetdrv(data_drive); dsetpath(data_path);
	filename[0]=0;
	if (!readdatafile(MLXDATTITL,filename,pathname,ALL_EXT,0)) return;
	data_drive= Dgetdrv(); Dgetpath(data_path,data_drive+1);
	data_mem= tempmem;

	/* choose block from it */
	nblocks= scan_blocks(heap[data_mem].start,blockptr);
	if (!nblocks) return;	/* can't happen? */
	block= select_block(BLOCK2ADD,nblocks,blockptr);
	if ( (block<0) || (block>=nblocks) ) return;

	/* load multi-block file to receive block */
	Dsetdrv(mlt_drive); dsetpath(mlt_path);
	create_it= readdatafile(MLXADDTITL,mlxfile,mlxpath,MLX_EXT,1);
	if (!create_it) return;
	if (create_it<0)
	{
		if (form_alert(1,CHEKCREMLX)!=1) return;
		create_it=1;
	}
	else
		create_it=0;
	mlt_drive= Dgetdrv(); Dgetpath(mlt_path,mlt_drive+1);
	mlx_mem= tempmem;

	/* because data_mem may have moved */
	scan_blocks(heap[data_mem].start,blockptr);

	/* build file -- */
	i=0;

	/* -- header */
	addr[i]= (long)(&dataheader);
	leng[i++]= sizeof(dataheader);

	/* -- if file already exists, chop header off start, end_record off end */
	if (!create_it)
	{
		addr[i]= heap[mlx_mem].start + sizeof(dataheader);
		leng[i++]= heap[mlx_mem].nbytes - 4 - sizeof(dataheader);
	}

	/* -- the new block */
	addr[i]= blockptr[block];
	leng[i++]= blockptr[block+1] - blockptr[block];

	/* -- end_record */
	addr[i]= (long)(&end_record);
	leng[i++]= 4;

	save_file(mlxfile,mlxpath,-i,addr,leng); /* replace without warning */

}	/* end mlx_add() */