Exemplo n.º 1
0
static void hlist_del_pos(HList* hlist, int pos, int clear) {
  HNode* n = &hlist->data[pos];
  --hlist->ulen;
  if (clear) {
    header_destroy(n->header);
    plist_destroy(n->values);
  }
  int j;
  for (j = pos; j < hlist->ulen; ++j) {
    hlist->data[j] = hlist->data[j+1];
  }
}
Exemplo n.º 2
0
Bool
prima_gtk_done(void)
{
	if ( gtk_filters) {
		int i;
		for ( i = 0; i < gtk_filters-> count; i++) 
			g_object_unref(( GObject*) gtk_filters-> items[i]);
		plist_destroy( gtk_filters);
		gtk_filters = NULL;
	}
	gtk_initialized = 0;
	return true;
}
Exemplo n.º 3
0
// TODO: perhaps we should leave hlist as empty but not delete the chunks we
// already allocated for it...
void hlist_clear(HList* hlist) {
  if (!hlist) {
    return;
  }

  int j;
  for (j = 0; j < hlist->ulen; ++j) {
    HNode* n = &hlist->data[j];
    header_destroy(n->header);
    plist_destroy(n->values);
  }
  GMEM_DELARR(hlist->data, HNode*, hlist->alen, sizeof(HNode));
  hlist_init(hlist);
}
Exemplo n.º 4
0
static void
clear_font_abc_caches( Handle self)
{
   PList u;
   if (( u = var-> font_abc_unicode)) {
      int i;
      for ( i = 0; i < u-> count; i += 2) 
         free(( void*) u-> items[ i + 1]);
      plist_destroy( u);
      var-> font_abc_unicode = nil;
   } 
   if ( var-> font_abc_ascii) {
      free( var-> font_abc_ascii);
      var-> font_abc_ascii = nil;
   }
}
Exemplo n.º 5
0
/* Done with a game structure: */
void game_free(GameData *gd) {
	if(!gd) return;
	
	if(gd->is_active) {
		/* Debug if we need to: */
		if(gd->is_debug)
			level_dump_bmp(gd->data.active.lvl, "debug_end.bmp");
		
		drawbuffer_destroy(gd->data.active.b);
		plist_destroy     (gd->data.active.pl);
		tanklist_destroy  (gd->data.active.tl);
		level_destroy     (gd->data.active.lvl);
		screen_destroy    (gd->data.active.s);
	}
	
	free_mem(gd);	
}
Exemplo n.º 6
0
void
window_subsystem_done( void)
{
	if ( !DISP) return;

	if ( guts. hostname. value) {
		XFree( guts. hostname. value);
		guts. hostname. value = nil;
	}

	prima_end_menu();

	free_gc_pool(&guts.bitmap_gc_pool);
	free_gc_pool(&guts.screen_gc_pool);
	free_gc_pool(&guts.argb_gc_pool);
	prima_done_color_subsystem();
	free( guts. clipboard_formats);

	XFreeGC( DISP, guts. menugc);
	prima_gc_ximages();          /* verrry dangerous, very quiet please */
	if ( guts.pointer_font) {
		XFreeFont( DISP, guts.pointer_font);
		guts.pointer_font = nil;
	}
	XCloseDisplay( DISP);
	DISP = nil;
	
	plist_destroy( guts. files);
	guts. files = nil;

	XrmDestroyDatabase( guts.db);
	if (guts.ximages)            hash_destroy( guts.ximages, false);
	if (guts.menu_windows)       hash_destroy( guts.menu_windows, false);
	if (guts.windows)            hash_destroy( guts.windows, false);
	if (guts.clipboards)         hash_destroy( guts.clipboards, false);
	if (guts.clipboard_xfers)    hash_destroy( guts.clipboard_xfers, false);
	prima_cleanup_font_subsystem();
}
Exemplo n.º 7
0
char *
prima_gtk_openfile( char * params)
{
	if ( strncmp( params, "version", 7) == 0)
		return duplicate_string( GTK_VERSION);

	if ( !DISP) 
		return NULL;
	if( !prima_gtk_init()) 
		return NULL;

	if ( strncmp( params, "directory", 9) == 0) {
		params += 9;
		if ( *params == '=') {
			params++;
			if ( *params == 0) {
				gtk_current_folder_ptr = NULL;
			} else {
				gtk_current_folder_ptr = gtk_current_folder;
				strncpy( gtk_current_folder, params, MAXPATHLEN);
				gtk_current_folder[MAXPATHLEN] = 0;
			}
		} else
			return duplicate_string( gtk_current_folder_ptr);
	} else if ( strncmp( params, "filters=", 8) == 0) {
		params += 8;
		if ( gtk_filters) {
			int i;
			for ( i = 0; i < gtk_filters-> count; i++) 
				g_object_unref(( GObject*) gtk_filters-> items[i]);
			plist_destroy( gtk_filters);
			gtk_filters = NULL;
		}
		if ( *params != 0) {
			gtk_filters = plist_create(8, 8);

			/* copy \0\0-terminated string */
			while ( *params) {
				char * pattern;
				GtkFileFilter * f = gtk_file_filter_new();

				/* name */
				gtk_file_filter_set_name( f, params);
				while ( *params) params++;
				params++;

				/* semicolon-separated shell globs */
				pattern = ( char *) params;
				while ( *params) {
					if ( *params == ';') {
						*params = 0;
						gtk_file_filter_add_pattern( f, pattern);
						pattern = params + 1;
					}
					params++;
				}
				gtk_file_filter_add_pattern( f, pattern);

				list_add( gtk_filters, (Handle) f);

				params++;
			}
		}
	} else if ( strncmp( params, "filterindex", 11) == 0) {
		params += 11;
		if ( *params == '=') {
			int fi = 0;
			sscanf( params + 1, "%d", &fi);
			gtk_filter_index = fi;
		} else {
			char buf[25];
			sprintf( buf, "%d", gtk_filter_index);
			return duplicate_string( buf);
		}
	} else if ( strncmp( params, "multi_select=", 13) == 0) {
		params += 13;
		gtk_select_multiple = (*params != '0');
	} else if ( strncmp( params, "overwrite_prompt=", 17) == 0) {
		params += 17;
		gtk_overwrite_prompt = (*params != '0');
	} else if (
		( strncmp( params, "open", 4) == 0) || 
		( strncmp( params, "save", 4) == 0)
	) {
		return gtk_openfile( strncmp( params, "open", 4) == 0);
	} else if ( strncmp( params, "show_hidden=", 12) == 0) {
		params += 12;
		gtk_show_hidden_files = (*params != '0');
	} else if ( strncmp( params, "title=", 6) == 0) {
		params += 6;
		if ( *params == 0) {
			gtk_dialog_title_ptr = NULL;
		} else {
			gtk_dialog_title_ptr = gtk_dialog_title;
			strncpy( gtk_dialog_title, params, 255);
			gtk_dialog_title[255] = 0;
		}
	} else {
		warn("gtk2.OpenFile: Unknown function %s", params);
	}

	return NULL;
}
Exemplo n.º 8
0
static char *
gtk_openfile( Bool open)
{

	char *result = NULL;
   	struct MsgDlg message_dlg, **storage;

	if ( gtk_dialog) return NULL; /* we're not reentrant */

	gtk_dialog = gtk_file_chooser_dialog_new (
		gtk_dialog_title_ptr ? 
			gtk_dialog_title_ptr :
			( open ? "Open File" : "Save File"),
		NULL,
		open ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE,
		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
		GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
		NULL);

	gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER (gtk_dialog), TRUE);
	if (open)
		gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER (gtk_dialog), gtk_select_multiple);

#if GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 8
	gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER (gtk_dialog), gtk_overwrite_prompt);
	gtk_file_chooser_set_show_hidden( GTK_FILE_CHOOSER (gtk_dialog), gtk_show_hidden_files);
#endif
	if ( gtk_current_folder_ptr)
		gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER (gtk_dialog), gtk_current_folder_ptr);

	if ( gtk_filters) {
		int i;
		for ( i = 0; i < gtk_filters-> count; i++) {
			gtk_file_chooser_add_filter( 
				GTK_FILE_CHOOSER (gtk_dialog), 
				GTK_FILE_FILTER (gtk_filters-> items[i])
			);
			if ( i == gtk_filter_index)
				gtk_file_chooser_set_filter( 
					GTK_FILE_CHOOSER (gtk_dialog), 
					GTK_FILE_FILTER (gtk_filters-> items[i])
				);
		}
	}

	/* lock prima interactions */
	bzero( &message_dlg, sizeof(message_dlg));
	storage = &guts. message_boxes;
	while ( *storage) storage = &((*storage)-> next);
	*storage = &message_dlg;

	g_idle_add( do_events, NULL);

	if (gtk_dialog_run (GTK_DIALOG (gtk_dialog)) == GTK_RESPONSE_ACCEPT) {

		/* files */
		if ( gtk_select_multiple) {
			int size;
			char * ptr;
			GSList *names, *iter;

			names = gtk_file_chooser_get_filenames ( GTK_FILE_CHOOSER (gtk_dialog));

			/* count total length with escaped spaces and backslashes */
			size = 1;
			iter = names;
			while ( iter) {
				char * c = (char*) iter-> data;
				while ( *c) {
					if ( *c == ' ' || *c == '\\') 
						size++;
					size++;
					c++;
				}
				size++;
				iter = iter-> next;
			}

			if (( result = ptr = malloc( size))) {
				/* copy and encode */
				iter = names;
				while ( iter) {
					char * c = (char*) iter-> data;
					while ( *c) {
						if ( *c == ' ' || *c == '\\')
							*(ptr++) = '\\';
						*(ptr++) = *c;
						c++;
					}
					iter = iter-> next;
					*(ptr++) = ' ';
				}
				*(ptr - 1) = 0;
			} else {
				warn("gtk_openfile: cannot allocate %d bytes of memory", size);
			}

			/* free */
			iter = names;
			while ( iter) {
				g_free( iter-> data);
				iter = iter-> next;
			}
			g_slist_free( names);
		} else {
			char * filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (gtk_dialog));
			result = duplicate_string( filename);
			g_free (filename);
		}

		/* directory */
		{
			char * d = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER (gtk_dialog));
			if ( d) {
				strncpy( gtk_current_folder, d, MAXPATHLEN);
				gtk_current_folder_ptr = gtk_current_folder;
				g_free( d);
			} else {
				gtk_current_folder_ptr = NULL;
			}
		}

		/* filter index */
		gtk_filter_index = 0;
		if ( gtk_filters) {
			int i;
			Handle f = ( Handle) gtk_file_chooser_get_filter( GTK_FILE_CHOOSER (gtk_dialog));
			for ( i = 0; i < gtk_filters-> count; i++)
				if ( gtk_filters-> items[i] == f) {
					gtk_filter_index = i;
					break;
				}
			
		} 
	}
		
	if ( gtk_filters) {
		plist_destroy( gtk_filters);
		gtk_filters = NULL;
	}

	*storage = message_dlg. next; /* unlock */

	gtk_widget_destroy (gtk_dialog);
	gtk_dialog = NULL;

	while ( gtk_events_pending()) gtk_main_iteration();

	return result;
}
Exemplo n.º 9
0
/** Server code. Server manages a queue of tasks to be executed in
this phase. Each task in the queue is scheduled to be executed
once. When all the tasks complete execution, the server populates the
queue again and repeats the process. The server terminates when all
populating a task queue returns an empty queue. */
void server_code() {
  task_list_t tlist;
  proc_list_t plist;
  req_list_t rlist;
  task_t *ptr;
  const char *pname = "server_code";
  const int world_me = GA_Nodeid();
  double e1, e2, e3, e4, f1, f2, f3, f4, f5, f6, f7;
  double t_pop_task=0, t_sig_start=0, t_poll=0, t_loop=0, t_loop1=0, t_poll2=0; 
  proc_t *procs;
  int default_grp;
/*   double util_wallsec_(); */
  t_ptask = 0.0;

  default_grp = GA_Pgroup_get_default();
/*   fprintf(stderr, "%d: 1 %s\n", world_me, pname); */

  e1 = util_wallsec_();
  plist_init(&plist);
/*   fprintf(stderr, "%d: 2 %s\n", world_me, pname); */
  task_list_init(&tlist);
/*   fprintf(stderr, "%d: 3 %s\n", world_me, pname); */
  
  e2 = util_wallsec_();
  while(1) {
    f1 = util_wallsec_();
    task_list_reset(&tlist);  
/*     fprintf(stderr, "%d: 4 %s\n", world_me, pname); */
    populate_tasks_((Integer *)&tlist);
/*     fprintf(stderr, "%d: 5. ntodo=%d nrunning=%d ndone=%d %s\n", */
/* 	    world_me, tlist.ntodo, tlist.nrunning, tlist.ndone, pname); */
    req_list_init(&rlist, &tlist);
    f2 = util_wallsec_();
    t_pop_task += (f2-f1);

    if(tlist.ntodo == 0) break;

    f2 = util_wallsec_();
    while(tlist.ntodo>0) {
#warning "Simple server implementation. To be optimized"
      
/*       int nproc = tlist.todo->nproc; */

      f3 = util_wallsec_();
      if(1 /*(tlist.nrunning==0)*/) {
	while(tlist.ntodo>0 &&
	      (procs=plist_assign_procs(&plist, tlist.todo->nproc))!=NULL) {
/* 	  	  fprintf(stderr, "%d:: Signalling start of a task\n", GA_Nodeid()); */
	  signal_task_start(tlist.todo, tlist.todo->nproc, procs, &rlist);
	  tlist.todo->proc_list = procs;
	  task_mark_running(&tlist, tlist.todo);

/* 	  	  fprintf(stderr, "%d: Started a task. ntodo=%d nrunning=%d ndone=%d %s\n", */
/* 	  		  world_me, tlist.ntodo, tlist.nrunning, tlist.ndone, pname); */
	}
      }
      f4 = util_wallsec_();
      t_sig_start += (f4-f3);
      /*       fprintf(stderr, "Polling for task completion notifies\n"); */

      if((ptr = wait_completion(&tlist,&plist,&rlist))!=NULL) {
	plist_reclaim_procs(&plist, ptr->nproc, ptr->proc_list);
	ptr->proc_list = NULL;
	task_mark_done(&tlist, ptr);
/* 	fprintf(stderr, "%d: Completed a task. ntodo=%d nrunning=%d ndone=%d %s\n", */
/* 		world_me, tlist.ntodo, tlist.nrunning, tlist.ndone, pname); */
      }
      f5 = util_wallsec_();
      t_poll += (f5-f3);
    }

    f6 = util_wallsec_();
    t_loop1 += (f6-f1);
    while(tlist.nrunning > 0) {
      if((ptr = wait_completion(&tlist, &plist,&rlist)) != NULL) {
	plist_reclaim_procs(&plist, ptr->nproc, ptr->proc_list);
	ptr->proc_list = NULL;
	task_mark_done(&tlist, ptr);
/*         fprintf(stderr, "%d: Completed a task. ntodo=%d nrunning=%d ndone=%d %s\n", */
/*                 world_me, tlist.ntodo, tlist.nrunning, tlist.ndone, pname); */
      }
    }
    req_list_destroy(&rlist);
    f7 = util_wallsec_();
    t_poll2 += (f7-f6);
    t_loop += (f7-f2);
  }
  e3 = util_wallsec_();
  plist_destroy(&plist);
  task_list_destroy(&tlist);
  /*  req_list_destroy(&rlist);*/
/*   fprintf(stderr, "%d:: Signalling termination\n", GA_Nodeid());  */
  signal_termination(SVR,GA_Pgroup_absolute_id(default_grp,SVR));
/*   fprintf(stderr, "%d:: Done signalling termination\n", GA_Nodeid());  */
  e4 = util_wallsec_();

/*   fprintf(stderr, "%d:: SERVER TOTAL time=%lf\n", ga_nodeid_(), e4-e1); */
/*   fprintf(stderr, "%d:: SERVER INIT time=%lf\n", ga_nodeid_(), e2-e1); */
/*   fprintf(stderr, "%d:: SERVER LOOP time=%lf\n", ga_nodeid_(), e3-e2); */
/*   fprintf(stderr, "%d:: SERVER TLOOP time=%lf\n", ga_nodeid_(), t_loop); */
/*   fprintf(stderr, "%d:: SERVER TLOOP1 time=%lf\n", ga_nodeid_(), t_loop1); */
/*   fprintf(stderr, "%d:: SERVER CLEANUP time=%lf\n", ga_nodeid_(), e4-e3); */
/*   fprintf(stderr, "%d:: SERVER POLLING time=%lf\n", ga_nodeid_(), t_poll); */
/*   fprintf(stderr, "%d:: SERVER POLLING2 time=%lf\n", ga_nodeid_(), t_poll2); */
/*   fprintf(stderr, "%d:: SERVER SIG_START time=%lf\n", ga_nodeid_(), t_sig_start); */
/*   fprintf(stderr, "%d:: SERVER POP_TASK time=%lf\n", ga_nodeid_(), t_pop_task); */
/*   fflush(stdout); */
}