void indexed_force_tri_3D::save(std::ofstream& out)
{
	// write the label string
	write_label(out, label);
	// write the point cloud indices for each vertex
	for (int t=0; t<3; t++)
		write_int(out, p[t]);
	// write the target index
	write_int(out, ds_index);
	// write the index list - first the length
	write_int(out, grid_indices.size());
	// now write all the indices
	for (std::list<grid_index>::iterator it=grid_indices.begin();
		 it!=grid_indices.end(); it++)
	{
		write_int(out, it->i);
		write_int(out, it->j);
		write_vector(out, it->cart_coord);
	}
	// write the point and edge adjacency list
	for (int a=0; a<2; a++)
	{
		write_int(out, adjacency[a].size());
		for (LABEL_STORE::iterator it=adjacency[a].begin();
			 it!= adjacency[a].end(); it++)
			write_label(out, *it);
	}
}
Esempio n. 2
0
void view_path_list(PATHPTR *path)
{
    PATHPTR p;

    p=*path;
    while (p!=NULL) {
	write_label(p->path);
	p=p->next;
    }
    write_label("\n");
}
Esempio n. 3
0
static void
write_cond(tree *cond)
{
  char *end_label = NULL;

  /* else doesn't have a condition */
  if (cond->value.cond.cond != NULL) {
    end_label = next_label();
    fprintf(state.output.f, ";#CSRC %s %d\n", 
            state.srcfilename,
            cond->value.cond.cond->line_number);
    temp_number = 0;
    write_test(cond->value.cond.cond, end_label);
    if (temp_number > max_temp_number)
      max_temp_number = temp_number;
  }
  
  /* write the body of the code */
  write_statements(cond->value.cond.body);
  
  /* if there is a condition generate a label at the end of the body */
  if (cond->value.cond.cond != NULL) {
    write_label(end_label);
    if (end_label)
      free(end_label);
  }
  
  /* generate next conditional block, if there is one */
  if (cond->value.cond.next != NULL)
    write_cond(cond->value.cond.next);
}
Esempio n. 4
0
static void
edit_label(struct sun_disklabel *sl, const char *disk, const char *bootpath)
{
	char tmpfil[] = _PATH_TMPFILE;
	const char *editor;
	int status;
	FILE *fp;
	pid_t pid;
	pid_t r;
	int fd;
	int c;

	if ((fd = mkstemp(tmpfil)) < 0)
		err(1, "mkstemp");
	if ((fp = fdopen(fd, "w")) == NULL)
		err(1, "fdopen");
	print_label(sl, disk, fp);
	fflush(fp);
	for (;;) {
		if ((pid = fork()) < 0)
			err(1, "fork");
		if (pid == 0) {
			if ((editor = getenv("EDITOR")) == NULL)
				editor = _PATH_VI;
			execlp(editor, editor, tmpfil, (char *)NULL);
			err(1, "execlp %s", editor);
		}
		status = 0;
		while ((r = wait(&status)) > 0 && r != pid)
			;
		if (WIFEXITED(status)) {
			if (parse_label(sl, tmpfil) == 0) {
				fclose(fp);
				unlink(tmpfil);
				write_label(sl, disk, bootpath);
				return;
			}
			printf("re-edit the label? [y]: ");
			fflush(stdout);
			c = getchar();
			if (c != EOF && c != '\n')
				while (getchar() != '\n')
					;
			if  (c == 'n') {
				fclose(fp);
				unlink(tmpfil);
				return;
			}
		}
	}
	fclose(fp);
	unlink(tmpfil);
	return;
}
Esempio n. 5
0
static gboolean update_time (gpointer data)
{

        g_mutex_lock (timer_mutex);
        roundtime_update ();
        g_cond_broadcast (timer_cond);
        g_mutex_unlock (timer_mutex);
	write_label ();

        return TRUE;
}
Esempio n. 6
0
void steering_extremum::save(std::ofstream& out)
{
	// write the extremum out as a binary chunk
	// write the timestep, longitude, latitude, intensity, delta, geostrophic wind u & v
	write_float(out, lon);
	write_float(out, lat);
	write_float(out, intensity);
	write_float(out, delta);
	write_float(out, sv_u);
	write_float(out, sv_v);
	// write number of object labels first
	write_int(out, object_labels.size());
	for (LABEL_STORE::iterator it_obj_lab = object_labels.begin();
		 it_obj_lab != object_labels.end(); it_obj_lab++)
		write_label(out, *it_obj_lab);
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
    DOS_FS fs;
    rw = 0;

    char *device = NULL;
    char *label = NULL;

    check_atari();

    if (argc < 2 || argc > 3)
        usage(1);

    if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
        usage(0);
    else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
        printf( "dosfslabel " VERSION ", " VERSION_DATE ", FAT32, LFN\n" );
        exit(0);
    }

    device = argv[1];
    if (argc == 3) {
        label = argv[2];
        if (strlen(label) > 11) {
            fprintf(stderr,
                    "dosfslabel: labels can be no longer than 11 characters\n");
            exit(1);
        }
        rw = 1;
    }

    fs_open(device, rw);
    read_boot(&fs);
    if (!rw) {
        fprintf(stdout, "%s\n", fs.label);
        exit(0);
    }

    write_label(&fs, label);
    fs_close(rw);
    return 0;
}
Esempio n. 8
0
/*
 * Here so that it can be shared by the 2D and 3D code
 */
void
do_timelabel(unsigned int x, unsigned int y)
{
    char str[MAX_LINE_LEN+1];
    char *save_format = timelabel.text;
    time_t now;
    time(&now);
    /* there is probably no way to find out in advance how many
     * chars strftime() writes */
    strftime(str, MAX_LINE_LEN, save_format, localtime(&now));
    timelabel.text = str;

    /* The only drawback of using write_label() is that there is no way  */
    /* to pass in a request for vertical justification JUST_BOT */
    if (timelabel.rotate == 0 && !timelabel_bottom)
	y -= term->v_char;

    write_label(x, y, &timelabel);
    timelabel.text = save_format;
}
Esempio n. 9
0
static void
write_loop(tree *loop)
{
  char *start_label = NULL;

  /* write out initalization code */
  if (loop->value.loop.init != NULL) {
    write_statements(loop->value.loop.init);
  }
 
  start_label = next_label();
  write_label(start_label);

  /* write the body of the loop */
  if (loop->value.loop.body != NULL)
    write_statements(loop->value.loop.body);

  /* write the increment statements */
  if (loop->value.loop.incr != NULL)
    write_statements(loop->value.loop.incr);

  /* write the exit statements */
  if (loop->value.loop.exit != NULL) {
    fprintf(state.output.f, ";#CSRC %s %d\n", 
            state.srcfilename,
            loop->value.loop.exit->line_number);
    temp_number = 0;
    write_test(loop->value.loop.exit, start_label);
    if (temp_number > max_temp_number)
      max_temp_number = temp_number;
  } else {
    write_asm_line("goto %s", start_label);
  }

  if (start_label)
    free(start_label);
}
int main (int argc, char* argv[])
{
  long correct=0,incorrect=0,no_accuracy=0;
  long i;
  double t1,runtime=0;
  double avgloss=0,l;
  FILE *predfl;
  STRUCTMODEL model; 
  STRUCT_LEARN_PARM sparm;
  STRUCT_TEST_STATS teststats;
  SAMPLE testsample;
  LABEL y;

  svm_struct_classify_api_init(argc,argv);

  read_input_parameters(argc,argv,testfile,modelfile,predictionsfile,&sparm,
			&verbosity,&struct_verbosity);

  if(struct_verbosity>=1) {
    printf("Reading model..."); fflush(stdout);
  }
  model=read_struct_model(modelfile,&sparm);
  if(struct_verbosity>=1) {
    fprintf(stdout, "done.\n");
  }

  if(model.svm_model->kernel_parm.kernel_type == LINEAR) { /* linear kernel */
    /* compute weight vector */
    //add_weight_vector_to_linear_model(model.svm_model);
    //model.w=model.svm_model->lin_weights;
  }
  
  if(struct_verbosity>=1) {
    printf("Reading test examples..."); fflush(stdout);
  }
  testsample=read_struct_examples(testfile,&sparm);
  if(struct_verbosity>=1) {
    printf("done.\n"); fflush(stdout);
  }

  if(struct_verbosity>=1) {
    printf("Classifying test examples..."); fflush(stdout);
  }

  if ((predfl = fopen (predictionsfile, "w")) == NULL)
  { perror (predictionsfile); exit (1); }

  for(i=0;i<testsample.n;i++) {
    t1=get_runtime();
    y=classify_struct_example(testsample.examples[i].x,&model,&sparm);
    runtime+=(get_runtime()-t1);

    write_label(predfl,y);
    l=loss(testsample.examples[i].y,y,&sparm);
    avgloss+=l;
    if(l == 0) 
      correct++;
    else
      incorrect++;
    eval_prediction(i,testsample.examples[i],y,&model,&sparm,&teststats);

    if(empty_label(testsample.examples[i].y)) 
      { no_accuracy=1; } /* test data is not labeled */
    if(struct_verbosity>=2) {
      if((i+1) % 100 == 0) {
	printf("%ld..",i+1); fflush(stdout);
      }
    }
    free_label(y);
  }  
  avgloss/=testsample.n;
  fclose(predfl);

  if(struct_verbosity>=1) {
    printf("done\n");
    printf("Runtime (without IO) in cpu-seconds: %.2f\n",
	   (float)(runtime/100.0));    
  }
  if((!no_accuracy) && (struct_verbosity>=1)) {
    printf("Average loss on test set: %.4f\n",(float)avgloss);
    printf("Zero/one-error on test set: %.2f%% (%ld correct, %ld incorrect, %d total)\n",(float)100.0*incorrect/testsample.n,correct,incorrect,testsample.n);
  }
  print_struct_testing_stats(testsample,&model,&sparm,&teststats);
  free_struct_sample(testsample);
  free_struct_model(model);

  svm_struct_classify_api_exit();

  return(0);
}
Esempio n. 11
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
#endif
{
	long correct=0,incorrect=0,no_accuracy=0;
	long i;
	double t1,runtime=0;
	double avgloss=0,l;
#ifndef COMPILE_MEX_INTERFACE
	FILE *predfl;
#endif
	STRUCTMODEL model; 
	STRUCT_LEARN_PARM sparm;
	STRUCT_TEST_STATS teststats;
	SAMPLE testsample;
	LABEL y;
#ifdef COMPILE_MEX_INTERFACE
	int argc;
	char **argv;
	if (nrhs < 3) {
		print_help();
		return;
	}
	else if (nrhs==3) {
		argc=1;
		argv=(char **)my_malloc(MAX_ARGVS*sizeof(char *));
		argv[0]="OLR";
	}
	else
		create_argc_argv(prhs[3],&argc,&argv);
#endif
	svm_struct_classify_api_init(argc,argv);
	
#ifndef COMPILE_MEX_INTERFACE
	read_input_parameters(argc,argv,testfile,modelfile,predictionsfile,&sparm,
						  &verbosity,&struct_verbosity);
#else
	read_input_parameters(argc,argv,&sparm,&verbosity,&struct_verbosity);
#endif
	
	if(struct_verbosity>=1) {
		printf("Reading model..."); fflush(stdout);
	}
#ifndef COMPILE_MEX_INTERFACE
	model=read_struct_model(modelfile,&sparm);
#else
	model=read_struct_model(prhs[2],&sparm);
#endif
	if(struct_verbosity>=1) {
		fprintf(stdout, "done.\n");
	}
	
	if(model.svm_model->kernel_parm.kernel_type == LINEAR) { /* linear kernel */
		/* compute weight vector */
		add_weight_vector_to_linear_model(model.svm_model);
		model.w=model.svm_model->lin_weights;
	}
	
	if(struct_verbosity>=1) {
		printf("Reading test examples..."); fflush(stdout);
	}
#ifndef COMPILE_MEX_INTERFACE
	testsample=read_struct_examples(testfile,&sparm);
#else
	testsample=read_struct_examples(prhs,&sparm);
#endif
	if(struct_verbosity>=1) {
		printf("done.\n"); fflush(stdout);
	}
	
	if(struct_verbosity>=1) {
		printf("Classifying test examples..."); fflush(stdout);
	}
#ifndef COMPILE_MEX_INTERFACE
	if ((predfl = fopen (predictionsfile, "w")) == NULL)
	{ perror (predictionsfile); exit (1); }
#else
	mwSize rows=mxGetM(prhs[0]);
	mxArray *predictions=mxCreateDoubleMatrix(rows,1,mxREAL);
	double *pred_ptr=mxGetPr(predictions);
#endif
	for(i=0;i<testsample.n;i++) {
		t1=get_runtime();
		y=classify_struct_example(testsample.examples[i].x,&model,&sparm);
		runtime+=(get_runtime()-t1);
#ifndef COMPILE_MEX_INTERFACE
		write_label(predfl,y);
#else
		write_label(&pred_ptr,y);
#endif
		l=loss(testsample.examples[i].y,y,&sparm);
		avgloss+=l;
		if(l == 0) 
			correct++;
		else
			incorrect++;
		eval_prediction(i,testsample.examples[i],y,&model,&sparm,&teststats);
		
		if(empty_label(testsample.examples[i].y)) 
		{ no_accuracy=1; } /* test data is not labeled */
		if(struct_verbosity>=2) {
			if((i+1) % 100 == 0) {
				printf("%ld..",i+1); fflush(stdout);
			}
		}
		free_label(y);
	}
	avgloss/=testsample.n;
#ifndef COMPILE_MEX_INTERFACE
	fclose(predfl);
#endif
	if(struct_verbosity>=1) {
		printf("done\n");
		printf("Runtime (without IO) in cpu-seconds: %.2f\n",
			   (float)(runtime/100.0));    
	}
	if((!no_accuracy) && (struct_verbosity>=1)) {
		printf("Average loss on test set: %.4f\n",(float)avgloss);
		printf("Zero/one-error on test set: %.2f%% (%ld correct, %ld incorrect, %d total)\n",(float)100.0*incorrect/testsample.n,correct,incorrect,testsample.n);
	}
	print_struct_testing_stats(testsample,&model,&sparm,&teststats);
	free_struct_sample(testsample);
	free_struct_model(model);
	
	svm_struct_classify_api_exit();
#ifndef COMPILE_MEX_INTERFACE
	return(0);
#else
	plhs[0]=predictions;
#endif
}
Esempio n. 12
0
void
multiplot_start()
{
    TBOOLEAN set_spacing = FALSE;
    TBOOLEAN set_margins = FALSE;

    c_token++;

    /* Only a few options are possible if we are already in multiplot mode */
    /* So far we have "next".  Maybe also "previous", "clear"? */
    if (multiplot) {
	if (equals(c_token, "next")) {
	    c_token++;
	    if (!mp_layout.auto_layout)
		int_error(c_token, "only valid inside an auto-layout multiplot");
	    multiplot_next();
	    return;
	} else if (almost_equals(c_token, "prev$ious")) {
	    c_token++;
	    if (!mp_layout.auto_layout)
		int_error(c_token, "only valid inside an auto-layout multiplot");
	    multiplot_previous();
	    return;
	} else {
	    term_end_multiplot();
	}
    }

    /* FIXME: more options should be reset/initialized each time */
    mp_layout.auto_layout = FALSE;
    mp_layout.auto_layout_margins = FALSE;
    mp_layout.current_panel = 0;
    mp_layout.title.noenhanced = FALSE;
    free(mp_layout.title.text);
    mp_layout.title.text = NULL;
    free(mp_layout.title.font);
    mp_layout.title.font = NULL;
    mp_layout.title.boxed = 0;

    /* Parse options */
    while (!END_OF_COMMAND) {

	if (almost_equals(c_token, "ti$tle")) {
	    c_token++;
	    mp_layout.title.text = try_to_get_string();
 	    continue;
       }

       if (equals(c_token, "font")) {
	    c_token++;
	    mp_layout.title.font = try_to_get_string();
	    continue;
	}

        if (almost_equals(c_token,"enh$anced")) {
            mp_layout.title.noenhanced = FALSE;
            c_token++;
            continue;
        }

        if (almost_equals(c_token,"noenh$anced")) {
            mp_layout.title.noenhanced = TRUE;
            c_token++;
            continue;
        }
        
	if (equals(c_token,"boxed")) {
            mp_layout.title.boxed = 1;
            c_token++;
            continue;
        }

	if (almost_equals(c_token, "lay$out")) {
	    if (mp_layout.auto_layout)
		int_error(c_token, "too many layout commands");
	    else
		mp_layout.auto_layout = TRUE;

	    c_token++;
	    if (END_OF_COMMAND) {
		int_error(c_token,"expecting '<num_cols>,<num_rows>'");
	    }

	    /* read row,col */
	    mp_layout.num_rows = int_expression();
	    if (END_OF_COMMAND || !equals(c_token,",") )
		int_error(c_token, "expecting ', <num_cols>'");

	    c_token++;
	    if (END_OF_COMMAND)
		int_error(c_token, "expecting <num_cols>");
	    mp_layout.num_cols = int_expression();

	    /* remember current values of the plot size and the margins */
	    mp_layout.prev_xsize = xsize;
	    mp_layout.prev_ysize = ysize;
	    mp_layout.prev_xoffset = xoffset;
	    mp_layout.prev_yoffset = yoffset;
	    mp_layout.prev_lmargin = lmargin;
	    mp_layout.prev_rmargin = rmargin;
	    mp_layout.prev_bmargin = bmargin;
	    mp_layout.prev_tmargin = tmargin;

	    mp_layout.act_row = 0;
	    mp_layout.act_col = 0;

	    continue;
	}

	/* The remaining options are only valid for auto-layout mode */
	if (!mp_layout.auto_layout)
	    int_error(c_token, "only valid in the context of an auto-layout command");

	switch(lookup_table(&set_multiplot_tbl[0],c_token)) {
	    case S_MULTIPLOT_COLUMNSFIRST:
		mp_layout.row_major = TRUE;
		c_token++;
		break;
	    case S_MULTIPLOT_ROWSFIRST:
		mp_layout.row_major = FALSE;
		c_token++;
		break;
	    case S_MULTIPLOT_DOWNWARDS:
		mp_layout.downwards = TRUE;
		c_token++;
		break;
	    case S_MULTIPLOT_UPWARDS:
		mp_layout.downwards = FALSE;
		c_token++;
		break;
	    case S_MULTIPLOT_SCALE:
		c_token++;
		mp_layout.xscale = real_expression();
		mp_layout.yscale = mp_layout.xscale;
		if (!END_OF_COMMAND && equals(c_token,",") ) {
		    c_token++;
		    if (END_OF_COMMAND) {
			int_error(c_token, "expecting <yscale>");
		    }
		    mp_layout.yscale = real_expression();
		}
		break;
	    case S_MULTIPLOT_OFFSET:
		c_token++;
		mp_layout.xoffset = real_expression();
		mp_layout.yoffset = mp_layout.xoffset;
		if (!END_OF_COMMAND && equals(c_token,",") ) {
		    c_token++;
		    if (END_OF_COMMAND) {
			int_error(c_token, "expecting <yoffset>");
		    }
		    mp_layout.yoffset = real_expression();
		}
		break;
	    case S_MULTIPLOT_MARGINS:
		c_token++;
		if (END_OF_COMMAND)
		    int_error(c_token,"expecting '<left>,<right>,<bottom>,<top>'");
		
		mp_layout.lmargin.scalex = screen;
		mp_layout_set_margin_or_spacing(&(mp_layout.lmargin));
		if (!END_OF_COMMAND && equals(c_token,",") ) {
		    c_token++;
		    if (END_OF_COMMAND)
			int_error(c_token, "expecting <right>");

		    mp_layout.rmargin.scalex = mp_layout.lmargin.scalex;
		    mp_layout_set_margin_or_spacing(&(mp_layout.rmargin));
		} else {
		    int_error(c_token, "expecting <right>");
		}
		if (!END_OF_COMMAND && equals(c_token,",") ) {
		    c_token++;
		    if (END_OF_COMMAND)
			int_error(c_token, "expecting <top>");

		    mp_layout.bmargin.scalex = mp_layout.rmargin.scalex;
		    mp_layout_set_margin_or_spacing(&(mp_layout.bmargin));
		} else {
		    int_error(c_token, "expecting <bottom>");
		}
		if (!END_OF_COMMAND && equals(c_token,",") ) {
		    c_token++;
		    if (END_OF_COMMAND)
			int_error(c_token, "expecting <bottom>");

		    mp_layout.tmargin.scalex = mp_layout.bmargin.scalex;
		    mp_layout_set_margin_or_spacing(&(mp_layout.tmargin));
		} else {
		    int_error(c_token, "expection <top>");
		}
		set_margins = TRUE;
		break;
	    case S_MULTIPLOT_SPACING:
		c_token++;
		if (END_OF_COMMAND)
		    int_error(c_token,"expecting '<xspacing>,<yspacing>'");
		mp_layout.xspacing.scalex = screen;
		mp_layout_set_margin_or_spacing(&(mp_layout.xspacing));
		mp_layout.yspacing = mp_layout.xspacing;

		if (!END_OF_COMMAND && equals(c_token, ",")) {
		    c_token++;
		    if (END_OF_COMMAND)
			int_error(c_token, "expecting <yspacing>");
		    mp_layout_set_margin_or_spacing(&(mp_layout.yspacing));
		}
		set_spacing = TRUE;
		break;
	    default:
		int_error(c_token,"invalid or duplicate option");
		break;
	}
    }

    if (set_spacing || set_margins) {
	if (set_spacing && set_margins) {
	    if (mp_layout.lmargin.x >= 0 && mp_layout.rmargin.x >= 0 
	    &&  mp_layout.tmargin.x >= 0 && mp_layout.bmargin.x >= 0 
	    &&  mp_layout.xspacing.x >= 0 && mp_layout.yspacing.x >= 0)
		mp_layout.auto_layout_margins = TRUE;
	    else
		int_error(NO_CARET, "must give positive margin and spacing values");
	} else if (set_margins) {
	    mp_layout.auto_layout_margins = TRUE;
	    mp_layout.xspacing.scalex = screen;
	    mp_layout.xspacing.x = 0.05;
	    mp_layout.yspacing.scalex = screen;
	    mp_layout.yspacing.x = 0.05;
	}
	/* Sanity check that screen tmargin is > screen bmargin */
	if (mp_layout.bmargin.scalex == screen && mp_layout.tmargin.scalex == screen)
	    if (mp_layout.bmargin.x > mp_layout.tmargin.x) {
		double tmp = mp_layout.bmargin.x;
		mp_layout.bmargin.x = mp_layout.tmargin.x;
		mp_layout.tmargin.x = tmp;
	    }
    }

    /* If we reach here, then the command has been successfully parsed.
     * Aug 2013: call term_start_plot() before setting multiplot so that
     * the wxt and qt terminals will reset the plot count to 0 before
     * ignoring subsequent TERM_LAYER_RESET requests. 
     */
    term_start_plot();
    multiplot = TRUE;
    fill_gpval_integer("GPVAL_MULTIPLOT", 1);

    /* Place overall title before doing anything else */
    if (mp_layout.title.text) {
	unsigned int x, y;
	char *p = mp_layout.title.text;

	x = term->xmax  / 2;
	y = term->ymax - term->v_char;

	write_label(x, y, &(mp_layout.title));
	reset_textcolor(&(mp_layout.title.textcolor));

	/* Calculate fractional height of title compared to entire page */
	/* If it would fill the whole page, forget it! */
	for (y=1; *p; p++)
	    if (*p == '\n')
		y++;

	/* Oct 2012 - v_char depends on the font used */
	if (mp_layout.title.font && *mp_layout.title.font)
	    term->set_font(mp_layout.title.font);
	mp_layout.title_height = (double)(y * term->v_char) / (double)term->ymax;
	if (mp_layout.title.font && *mp_layout.title.font)
	    term->set_font("");

	if (mp_layout.title_height > 0.9)
	    mp_layout.title_height = 0.05;
    } else {
	mp_layout.title_height = 0.0;
    }

    if (mp_layout.auto_layout_margins)
	mp_layout_margins_and_spacing();
    else
	mp_layout_size_and_offset();
}
Esempio n. 13
0
/*
 * Disk label editor for sun disklabels.
 */
int
main(int ac, char **av)
{
	struct sun_disklabel sl;
	const char *bootpath;
	const char *proto;
	const char *disk;
	int ch;

	bootpath = _PATH_BOOT; 
	while ((ch = getopt(ac, av, "b:BcehnrRw")) != -1)
		switch (ch) {
		case 'b':
			bflag = 1;
			bootpath = optarg;
			break;
		case 'B':
			Bflag = 1;
			break;
		case 'c':
			cflag = 1;
			break;
		case 'e':
			eflag = 1;
			break;
		case 'h':
			hflag = 1;
			break;
		case 'n':
			nflag = 1;
			break;
		case 'r':
			fprintf(stderr, "Obsolete -r flag ignored\n");
			break;
		case 'R':
			Rflag = 1;
			break;
		case 'w':
			wflag = 1;
			break;
		default:
			usage();
			break;
		}
	if (bflag && !Bflag)
		usage();
	if (nflag && !(Bflag || eflag || Rflag || wflag))
		usage();
	if (eflag && (Rflag || wflag))
		usage();
	if (eflag)
		hflag = 0;
	ac -= optind;
	av += optind;
	if (ac == 0)
		usage();
	bzero(&sl, sizeof(sl));
	disk = av[0];
	if (wflag) {
		if (ac != 2 || strcmp(av[1], "auto") != 0)
			usage();
		read_label(&sl, disk);
		bzero(sl.sl_part, sizeof(sl.sl_part));
		sl.sl_part[SUN_RAWPART].sdkp_cyloffset = 0;
		sl.sl_part[SUN_RAWPART].sdkp_nsectors = sl.sl_ncylinders *
		    sl.sl_ntracks * sl.sl_nsectors;
		write_label(&sl, disk, bootpath);
	} else if (eflag) {
		if (ac != 1)
			usage();
		read_label(&sl, disk);
		if (sl.sl_magic != SUN_DKMAGIC)
			errx(1, "%s%s has no sun disklabel", _PATH_DEV, disk);
		edit_label(&sl, disk, bootpath);
	} else if (Rflag) {
		if (ac != 2)
			usage();
		proto = av[1];
		read_label(&sl, disk);
		if (parse_label(&sl, proto) != 0)
			errx(1, "%s: invalid label", proto);
		write_label(&sl, disk, bootpath);
	} else if (Bflag) {
		read_label(&sl, disk);
		if (sl.sl_magic != SUN_DKMAGIC)
			errx(1, "%s%s has no sun disklabel", _PATH_DEV, disk);
		write_label(&sl, disk, bootpath);
	} else {
		read_label(&sl, disk);
		if (sl.sl_magic != SUN_DKMAGIC)
			errx(1, "%s%s has no sun disklabel", _PATH_DEV, disk);
		print_label(&sl, disk, stdout);
	}
	return (0);
}
Esempio n. 14
0
static void
write_procedure(tree *procedure, int is_func)
{
  tree *head;
  tree *body;
  char *name;
  tree *args;
  tree *decl;
  tree *statements;
  tree *argument;
  int i;
  int storage;

  if (is_func) {
    head = procedure->value.func.head;
    storage = procedure->value.func.storage;
    body = procedure->value.func.body;
  } else {
    head = procedure->value.proc.head;
    storage = procedure->value.proc.storage;
    body = procedure->value.proc.body;
  }

  if (storage == EXTERN_STORAGE)
    return;

  assert(head->tag == node_head);  
  assert(body->tag == node_body); 
  name = head->value.head.name;
  args = head->value.head.args;
  decl = body->value.body.decl;
  statements = body->value.body.statements; 

  if (is_func) {
    fprintf(state.output.f, "; function %s\n", name);
  } else {
    fprintf(state.output.f, "; procedure %s\n", name);
  }

  /* data memory section */
  if ((args != NULL) || (decl != NULL)) {
    fprintf(state.output.f, ".udata_%s udata\n", name);
    /* the procedure or function has arguments */ 
    if (args != NULL) {
      assert(args->tag == node_list);
      for (; args; args = TAIL(args)) {
        argument = HEAD(args);
        assert(argument->tag == node_decl);
        assert(argument->value.decl.type == 0);
        assert(argument->value.decl.storage == 0);
        /* FIXME: only bytes are supported so far */
        assert(argument->value.decl.size == BYTE_SIZE);
        write_decl(argument, name);
      }  
    }
    /* the procedure or function has local variables */ 
    if (decl != NULL) {
      assert(decl->tag == node_list);
      for (; decl; decl = TAIL(decl)) {
        argument = HEAD(decl);
        assert(argument->tag == node_decl);
        assert(argument->value.decl.storage == 0);
        /* FIXME: only bytes are supported so far */
        assert(argument->value.decl.size == BYTE_SIZE);
        if (argument->value.decl.type == VAR_TYPE)
          write_decl(argument, name);

      }  
    }
    
    fprintf(state.output.f, "\n");
  }

  /* program memory section */
  fprintf(state.output.f, ".code_%s code\n", name);
  add_global(name, name, procedure);
  write_label(name);
  if (storage == PUBLIC_STORAGE)
    fprintf(state.output.f, "  global %s\n", name);
  max_temp_number = 0;
  write_statements(statements);
  fprintf(state.output.f, "  return\n");
  fprintf(state.output.f, "\n");

  /* temp data section */
  if (max_temp_number) {
    /* FIXME: overlay this if possible */
    fprintf(state.output.f, ".udata_%s_temp udata\n", name);
    for(i = 0; i < max_temp_number; i++)
      fprintf(state.output.f, "_temp_%d res 1\n", i);
      
    fprintf(state.output.f, "\n");
  }

}
Esempio n. 15
0
ya_result
zdb_query_message_update(message_data* message, zdb_query_ex_answer* answer_set)
{
    /*
     *
     * OPCODE       (16 bits)
     * QUERY            "
     * ANSWER           "
     * AUTHORITY        "
     * ADDITIONAL       "
     *
     */

    /* Insert the query */
    message_header* header = (message_header*)message->buffer;

    u32 count;

    bool fully_written;

    /* Initialize the compression dictionnary with the query */

    packet_writer pc;

#ifndef NDEBUG
    count = ~0;
    memset(&pc, 0xff, sizeof (pc));
#endif

    if(message->edns)
    {
        message->size_limit -= EDNS0_RECORD_SIZE;  /* edns0 opt record */
    }

    packet_writer_init(&pc, message->buffer, message->received, message->size_limit);

    /** @todo If answer has been truncated (check for it) then set tuncated and do NOT update the offset */
    fully_written = write_label(answer_set->answer, &count, &pc);
    header->ancount = htons(count);
    header->nscount = 0;
    header->arcount = 0;

    if(fully_written)
    {
        if((message->process_flags & PROCESS_FL_AUTHORITY_AUTH) != 0)
        {
            fully_written = write_label(answer_set->authority, &count, &pc);
            header->nscount = htons(count);
        }

        if(fully_written && ((message->process_flags & PROCESS_FL_ADDITIONAL_AUTH) != 0))
        {
            /* fully_written = */ write_label(answer_set->additional, &count, &pc);
            header->arcount = htons(count);
        }
    }

    if(message->edns)
    {
        message->size_limit += EDNS0_RECORD_SIZE;  /* edns0 opt record */
        pc.packet_limit += EDNS0_RECORD_SIZE;

        /* 00 00 29 SS SS rr vv 80 00 00 00 */

        memset(&pc.packet[pc.packet_offset], 0, EDNS0_RECORD_SIZE);
        pc.packet_offset += 2;
        pc.packet[pc.packet_offset++] = 0x29;
        packet_writer_add_u16(&pc, htons(edns0_maxsize));
        packet_writer_add_u32(&pc, message->rcode_ext);
        pc.packet_offset += 2;

        header->arcount = htons(ntohs(header->arcount) + 1);
    }

    u16 hi;

    if(fully_written)
    {
         hi = QR_BITS;
    }
    else
    {
        /* TC ! */

        hi = QR_BITS|TC_BITS;
    }

    MESSAGE_FLAGS_OR(message->buffer, hi, message->status);

    return pc.packet_offset;
}