Exemplo n.º 1
0
void old_state()
{
    if(!state || !state->old)
        syntaxerror("invalid nesting");
    state_t*leaving = state;
    
    state = state->old;

    if(as3_pass>1 && leaving->method && leaving->method != state->method && !leaving->method->inner) {
        methodstate_destroy(leaving->method);leaving->method=0;
    }
    if(as3_pass>1 && leaving->cls && leaving->cls != state->cls) {
        free(leaving->cls);
        leaving->cls=0;
    }

    state_destroy(leaving);
}
Exemplo n.º 2
0
void finish_file()
{
    if(!state || state->level!=1) {
        syntaxerror("unexpected end of file in pass %d", as3_pass);
    }
    
    if(as3_pass==2) {
        dict_del(global->file2token2info, current_filename);
        code_t*header = method_header(state->method);
        //if(global->init->method->body->code || global->init->traits) {
        if(global->init) {
            code_t*c = wrap_function(header, 0, global->init->method->body->code);
            global->init->method->body->code = abc_returnvoid(c);
            free(state->method);state->method=0;
        }
    }

    //free(state->package);state->package=0; // used in registry
    state_destroy(state);state=0;
}
Exemplo n.º 3
0
Arquivo: ur-cmd.c Projeto: spolu/ur
int
cmd_add (const char *path, bool recursive)
{
  char *prt_dir = NULL, *fname = NULL, *dname = NULL;
  struct stat64 st_buf;
  state_t ur = STATE_INITIALIZER;
  struct index index = INDEX_INITIALIZER; 
  int status;

  if (lstat64 (path, &st_buf) != 0) fail("%s does not exist", path);

  prt_dir = (char *) malloc (strlen (path) + 4);
  parent_dir (path, prt_dir);

  if (st_buf.st_mode & S_IFREG) {

    fname = (char *) malloc (strlen (path) + 4);
    filename (path, fname);	

    if (ur_check (prt_dir) == 0) 
      {
	if (state_init (&ur, prt_dir) != 0) fail ("fail reading state of %s", prt_dir);
	if (index_read (&ur, &index) != 0) fail ("fail reading index of %s", prt_dir);
	
	status = index_entry_get_status (&index, fname);
	status |= S_IADD;
	if (!(status & S_IPST))
	  status |= S_IPST;
	index_entry_set_status (&index, fname, status);

	if (index_write (&ur, &index) != 0) fail ("fail writing index of %s", prt_dir);

	index_destroy (&index);
	state_destroy (&ur);
      }
    else
      fail ("%s initialization failed", prt_dir);	

    free (fname); fname = NULL;    
  }

  if (st_buf.st_mode & S_IFDIR) 
    {
      dname = (char *) malloc (strlen (path) + 4);
      dirname (path, dname);	

      if (ur_check (path) == 0) {
	if (ur_check (prt_dir) == 0) 
	  {
	    if (state_init (&ur, prt_dir) != 0) fail ("fail reading state of %s", prt_dir);
	    if (index_read (&ur, &index) != 0) fail ("fail reading index of %s", prt_dir);
	    
	    status = index_entry_get_status (&index, dname);
	    status |= S_IADD;
	    if (!(status & S_IPST))
	      status |= S_IPST;	
	    index_entry_set_status (&index, dname, status);

	    if (index_write (&ur, &index) != 0) fail ("fail writing index of %s", prt_dir);
	    index_destroy (&index);
	    state_destroy (&ur);
	}
      }
      else {

	if (ur_create (path) != 0) fail ("%s initialization failed", path);	
	output ("init: %s", path);
	
	if (ur_check (prt_dir) == 0) {
	    if (state_init (&ur, prt_dir) != 0) fail ("fail reading state of %s", prt_dir);
	    if (index_read (&ur, &index) != 0) fail ("fail reading index of %s", prt_dir);
	    
	    status = index_entry_get_status (&index, dname);
	    status |= S_IADD;
	    if (!(status & S_IPST))
	      status |= S_IPST;	
	    index_entry_set_status (&index, dname, status);

	    if (index_write (&ur, &index) != 0) fail ("fail writing index of %s", prt_dir);
	    index_destroy (&index);
	    state_destroy (&ur);
	}
      }

      free (dname); dname = NULL;    
    }
  
  free (prt_dir); prt_dir = NULL;

  /*
   * recursion
   */
  if ((st_buf.st_mode & S_IFDIR) && recursive) 
    {
      DIR *dp;
      struct dirent *ep;
      
      dp = opendir (path);
      if (dp != NULL)
	{
	  while ((ep = readdir (dp))) {
	    if (ep->d_name[0] != '.') 
	      {		
		char *npath;
		npath = (char *) malloc (strlen (path) +
					 strlen (ep->d_name) + 2);
		if (path[strlen (path) -1] == '/')
		  sprintf (npath, "%s%s", path, ep->d_name);
		else
		  sprintf (npath, "%s/%s", path, ep->d_name);
		cmd_add (npath, recursive);
		free (npath);
	      }	    
	  }
	  (void) closedir (dp);
	}
      else
	fail ("could not open directory %s", path);      
    }
  
  return 0;
}
Exemplo n.º 4
0
Arquivo: ur-cmd.c Projeto: spolu/ur
int
cmd_status (const char *path, bool recursive)
{
  state_t ur = STATE_INITIALIZER;
  struct index index = INDEX_INITIALIZER; 
  struct stat64 st_buf;
  DIR *dp;
  struct dirent *ep;
  struct list_elem *e;
  char *branchname = NULL;
      
  if (lstat64 (path, &st_buf) != 0) fail("%s does not exist", path);
  ASSERT (st_buf.st_mode & S_IFDIR);

  if (ur_check (path) == 0) 
    {
      
      if (state_init (&ur, path) != 0) fail ("fail reading state of %s", path);
      if (index_read (&ur, &index) != 0) fail ("fail reading index of %s", path);

      index_update (&ur, &index);

      branchname = branch_get_head_name (&ur);
      printf ("*** %s \n    (branch: %s)\n", ur.path, branchname);
      free (branchname); branchname = NULL;

      // reading added dirty files
      for (e = list_begin (&index.entries); e != list_end (&index.entries);
	   e = list_next (e))
	{
	  struct index_entry *en = list_entry (e, struct index_entry, elem);	
	  if ((en->status & S_IPST) &&
	      (en->status & S_IADD) && 
	      (en->status & S_IDRT)) {
	    printf ("#  added     : %s/%s\n", path, en->name);
	  }
	}

      // reading dirty but not added
      for (e = list_begin (&index.entries); e != list_end (&index.entries);
	   e = list_next (e))
	{
	  struct index_entry *en = list_entry (e, struct index_entry, elem);	
	  if ((en->status & S_IPST) &&
	      !(en->status & S_IADD) && 
	      (en->status & S_IDRT) && 
	      (en->status & S_ITRK)) {
	    printf ("#  dirty     : %s/%s\n", path, en->name);
	  }
	}

      // reading untracked files
      for (e = list_begin (&index.entries); e != list_end (&index.entries);
	   e = list_next (e))
	{
	  struct index_entry *en = list_entry (e, struct index_entry, elem);	
	  if ((en->status & S_IPST) &&
	      !(en->status & S_ITRK) && 
	      !(en->status & S_IADD)) {
	    printf ("#  untracked : %s/%s\n", path, en->name);
	  }
	}
      
      index_destroy (&index);
      state_destroy (&ur);    
    }
  else {
Exemplo n.º 5
0
void vx_gtk_display_destroy(vx_display_t * disp)
{
    state_destroy((state_t*)disp->impl);
    free(disp);
}
Exemplo n.º 6
0
Arquivo: vx_demo.c Projeto: DH-std/A3
int main(int argc, char ** argv)
{
    getopt_t *gopt = getopt_create();
    getopt_add_bool   (gopt, 'h', "help", 0, "Show help");
    getopt_add_bool (gopt, '\0', "no-gtk", 0, "Don't show gtk window, only advertise remote connection");
    getopt_add_string (gopt, '\0', "pnm", "", "Path for pnm file to render as texture (.e.g BlockM.pnm)");
    getopt_add_bool (gopt, '\0', "stay-open", 0, "Stay open after gtk exits to continue handling remote connections");

    // parse and print help
    if (!getopt_parse(gopt, argc, argv, 1) || getopt_get_bool(gopt,"help")) {
        printf ("Usage: %s [options]\n\n", argv[0]);
        getopt_do_usage (gopt);
        exit (1);
    }

    vx_global_init(); // Call this to initialize the vx-wide lock. Required to start the GL thread or to use the program library

    state_t * state = state_create();

    // Load a pnm from file, and repack the data so that it's understandable by vx
    if (strcmp(getopt_get_string(gopt,"pnm"),"")) {
        state->img = image_u32_create_from_pnm(getopt_get_string(gopt, "pnm"));

        printf("Loaded image %d x %d from %s\n",
               state->img->width, state->img->height,
               getopt_get_string(gopt, "pnm"));
    }

    draw(state, state->world);

    vx_remote_display_source_attr_t remote_attr;
    vx_remote_display_source_attr_init(&remote_attr);
    remote_attr.advertise_name = "Vx Demo";
    vx_remote_display_source_t * cxn = vx_remote_display_source_create_attr(&state->app, &remote_attr);
    pthread_create(&state->animate_thread, NULL, render_loop, state);

    if (!getopt_get_bool(gopt,"no-gtk")) {
        gdk_threads_init ();
        gdk_threads_enter ();

        gtk_init (&argc, &argv);

        vx_gtk_display_source_t * appwrap = vx_gtk_display_source_create(&state->app);
        GtkWidget * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        GtkWidget * canvas = vx_gtk_display_source_get_widget(appwrap);
        gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
        gtk_container_add(GTK_CONTAINER(window), canvas);
        gtk_widget_show (window);
        gtk_widget_show (canvas); // XXX Show all causes errors!

        g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

        gtk_main (); // Blocks as long as GTK window is open
        gdk_threads_leave ();

        vx_gtk_display_source_destroy(appwrap);

        // quit when gtk closes? Or wait for remote displays/Ctrl-C
        if (!getopt_get_bool(gopt, "stay-open"))
            state->running = 0;
    }

    pthread_join(state->animate_thread, NULL);
    vx_remote_display_source_destroy(cxn);

    state_destroy(state);
    vx_global_destroy();
    getopt_destroy(gopt);
}
Exemplo n.º 7
0
int main(int argc, char ** argv)
{
    getopt_t *gopt = getopt_create();
    getopt_add_bool   (gopt, 'h', "help", 0, "Show help");
    getopt_add_bool (gopt, '\0', "no-gtk", 0, "Don't show gtk window, only advertise remote connection");
    getopt_add_int (gopt, 'l', "limitKBs", "-1", "Remote display bandwidth limit. < 0: unlimited.");
    getopt_add_string (gopt, '\0', "pnm", "", "Path for pnm file to render as texture (.e.g BlockM.pnm)");
    getopt_add_bool (gopt, '\0', "stay-open", 0, "Stay open after gtk exits to continue handling remote connections");

    // parse and print help
    if (!getopt_parse(gopt, argc, argv, 1) || getopt_get_bool(gopt,"help")) {
        printf ("Usage: %s [options]\n\n", argv[0]);
        getopt_do_usage (gopt);
        exit (1);
    }

    signal(SIGPIPE, SIG_IGN); // potential fix for Valgrind "Killed" on
    // remote viewer exit

    state_t * state = state_create();

    // Load a pnm from file, and repack the data so that it's understandable by vx
    if (strcmp(getopt_get_string(gopt,"pnm"),"")) {
        image_u8_t * img2 = image_u8_create_from_pnm(getopt_get_string(gopt, "pnm"));
        state->img = image_util_convert_rgb_to_rgba (img2);
        image_u8_destroy (img2);
    }

    vx_global_init(); // Call this to initialize the vx-wide lock. Required to start the GL thread or to use the program library

    vx_application_t app = {.impl=state, .display_started=display_started, .display_finished=display_finished};

    vx_remote_display_source_attr_t remote_attr;
    vx_remote_display_source_attr_init(&remote_attr);
    remote_attr.max_bandwidth_KBs = getopt_get_int(gopt, "limitKBs");
    remote_attr.advertise_name = "Vx Stress Test";

    vx_remote_display_source_t * cxn = vx_remote_display_source_create_attr(&app, &remote_attr);
    for (int i = 0; i < NRENDER; i++) {
        tinfo_t * tinfo = calloc(1,sizeof(tinfo_t));
        tinfo->state = state;
        tinfo->id = i;
        pthread_create(&state->render_threads[i], NULL, render_loop, tinfo);
    }

    pthread_create(&state->camera_thread, NULL, camera_loop, state);

    if (!getopt_get_bool(gopt,"no-gtk")) {
        gdk_threads_init ();
        gdk_threads_enter ();

        gtk_init (&argc, &argv);

        vx_gtk_display_source_t * appwrap = vx_gtk_display_source_create(&app);
        GtkWidget * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        GtkWidget * canvas = vx_gtk_display_source_get_widget(appwrap);
        gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
        gtk_container_add(GTK_CONTAINER(window), canvas);
        gtk_widget_show (window);
        gtk_widget_show (canvas); // XXX Show all causes errors!

        g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

        gtk_main (); // Blocks as long as GTK window is open
        gdk_threads_leave ();

        vx_gtk_display_source_destroy(appwrap);

        // quit when gtk closes? Or wait for remote displays/Ctrl-C
        if (!getopt_get_bool(gopt, "stay-open"))
            state->running = 0;
    }

    for (int i = 0; i < NRENDER; i++)
        pthread_join(state->render_threads[i], NULL);
    vx_remote_display_source_destroy(cxn);

    state_destroy(state);
    vx_global_destroy();
    getopt_destroy(gopt);
}
Exemplo n.º 8
0
/*------------------------------------------------------------*/
void
state_init (void)
{
  while (current_state) current_state = state_destroy (current_state);
  while (current_stack) current_stack = state_destroy (current_stack);

  current_state = malloc (sizeof (state));
  current_state->prev = NULL;

  current_state->bonddistance = 1.9;
  current_state->bondcross = 0.4;
  current_state->coilradius = 0.2;
  current_state->colourparts = FALSE;
  current_state->cylinderradius = 2.3;
  current_state->depthcue = 0.75;
  current_state->emissivecolour = black_colour;
  current_state->helixthickness = 0.3;
  current_state->helixwidth = 2.4;
  current_state->hsbramp = TRUE;
  current_state->hsbrampreverse = FALSE;
  current_state->labelbackground = 0.0;
  current_state->labelcentre = TRUE;
  current_state->labelclip = FALSE;
  current_state->labelmask = NULL;
  current_state->labelmasklength = 0;
  v3_initialize (&(current_state->labeloffset), 0.0, 0.0, 0.0);
  current_state->labelrotation = FALSE;
  current_state->labelsize = 20.0;
  current_state->lightambientintensity = 0.0;
  v3_initialize (&(current_state->lightattenuation), 1.0, 0.0, 0.0);
  current_state->lightcolour = white_colour;
  current_state->lightintensity = 1.0;
  current_state->lightradius = 100.0;
  if (output_mode == POSTSCRIPT_MODE) {
    current_state->linecolour = black_colour;
  } else {
    current_state->linecolour = white_colour;
  }
  current_state->linedash = 0.0;
  current_state->linewidth = 1.0;
  current_state->objecttransform = TRUE;
  current_state->planecolour = white_colour;
  current_state->plane2colour = grey_colour;
  current_state->regularexpression = FALSE;
  if (output_mode == POSTSCRIPT_MODE || output_mode == RASTER3D_MODE) {
    current_state->segments = 6;
  } else {
    current_state->segments = 3;
  }
  current_state->segmentsize = 2.0;
  current_state->shading = 0.5;
  current_state->shadingexponent = 1.5;
  current_state->shininess = 0.2;
  current_state->smoothsteps = 2;
  if (output_mode == RASTER3D_MODE) {
    current_state->specularcolour = white_colour;
  } else {
    current_state->specularcolour = black_colour;
  }
  current_state->splinefactor = 1.0;
  current_state->stickradius = 0.2;
  current_state->sticktaper = 0.75;
  current_state->strandthickness = 0.6;
  current_state->strandwidth = 2.0;
  current_state->transparency = 0.0;
}