Пример #1
0
// ---------------------------------------------------------------------
// del_test
// ---------------------------------------------------------------------
void del_test(test_t* test) {

    int i;

    if (test->m) matmat_delete(test->m);

    for (i=0; i<test->n; i++) {
        if (dc_is_reactive(test->A[i])) dc_free(test->A[i]);
        else free(test->A[i]);
        if (dc_is_reactive(test->B[i])) dc_free(test->B[i]);
        else free(test->B[i]);
        if (dc_is_reactive(test->C[i])) dc_free(test->C[i]);
        else free(test->C[i]);
        free(test->cA[i]);
        free(test->cB[i]);
        free(test->cC[i]);
    }

    free(test->A);
    free(test->B);
    free(test->C);
    free(test->cA);
    free(test->cB);
    free(test->cC);

    #if CONV || CHECK
    #endif

    free(test);
}
Пример #2
0
Bool
apc_dbm_create( Handle self, Bool monochrome)
{
   Bool palc = 0;

   objCheck false;
   apcErrClear;
   apt_set( aptBitmap);
   apt_set( aptDeviceBitmap);
   apt_set( aptCompatiblePS);

   if ( !( sys ps = CreateCompatibleDC( 0))) apiErrRet;
   sys lastSize. x = var w;
   sys lastSize. y = var h;

   if ( monochrome)
      sys bm = CreateBitmap( var w, var h, 1, 1, nil);
   else {
      HDC dc;
      if (!( dc = dc_alloc())) {
         DeleteDC( sys ps);
         return false;
      }
      if (( sys pal = palette_create( self))) {
         sys stockPalette = SelectPalette( sys ps, sys pal, 1);
         RealizePalette( sys ps);
         palc = 1;
      }
      sys bm = CreateCompatibleBitmap( dc, var w, var h);
      if ( guts. displayBMInfo. bmiHeader. biBitCount == 8)
         apt_clear( aptCompatiblePS);
   }

   if ( !sys bm) {
      apiErr;
      if ( !monochrome) dc_free();
      if ( palc) {
         SelectPalette( sys ps, sys stockPalette, 1);
         DeleteObject( sys stockPalette);
         sys stockPalette = nil;
      }
      DeleteDC( sys ps);
      return false;
   }
   if ( !monochrome) dc_free();

   sys stockBM = SelectObject( sys ps, sys bm);

   hwnd_enter_paint( self);
   if ( monochrome) sys bpp = 1;

   hash_store( imageMan, &self, sizeof( self), (void*)self);
   return true;
}
Пример #3
0
void *
thread_main_dns(void *arg)
{
	int dnsrequest(const char *name, uint32 *ipaddr);
	int connfd, *number, count, total;
	char  *domain ;
	uint32 *ipptr;
	pthread_mutex_t *mutex;
	printf("dns thread %d starting \n", (int)arg );

	for(;;){

		Pthread_mutex_lock(&dns_array_mutex);

		while(iget == iput)
			Pthread_cond_wait(&dns_array_cond,
					&dns_array_mutex);
		
		printf("thread %d  working \n", pthread_self());

		connfd	= dns_array[iget].sockfd;
		domain  = dns_array[iget].domain;
		number	= dns_array[iget].number;
 		count	= dns_array[iget].count;
		total	= dns_array[iget].total;
		ipptr	= dns_array[iget].ipptr;
		mutex	= dns_array[iget].mutex;
		
		if(++iget == ARRAYSIZE)
			iget = 0;		

		Pthread_mutex_unlock(&dns_array_mutex);

		//do our job 
		if(dnsrequest(domain, ipptr + count) != 0) 
			inet_pton(AF_INET, "127.0.0.1", ipptr+count);
		dc_free(domain);	//dc_free the memory of domain
		Pthread_mutex_lock(mutex);
		(*number)--;
		Pthread_mutex_unlock(mutex);
		if((*number) == 0){
			write(connfd, ipptr, total*sizeof(uint32));
			printf("sended\n");
	//		close(connfd);	//todo
			dc_free(ipptr);
			dc_free(number);
			dc_free(mutex);
		} 


	}

}
Пример #4
0
// ---------------------------------------------------------------------
// del_test
// ---------------------------------------------------------------------
void del_test(test_t* test) {
    int i;

    if (test->m) vecmat_delete(test->m);

    for (i=0; i<test->R; i++) dc_free(test->M[i]);
    free(test->M);
    free(test->V);
    dc_free(test->O);

    #if CONV || CHECK
    #endif

    free(test);
}
Пример #5
0
void
dbm_recreate( Handle self)
{
   HBITMAP bm, stock;
   HDC dc, dca;
   HPALETTE p = nil;
   if ((( PDeviceBitmap) self)-> monochrome) return;

   if ( !( dc = CreateCompatibleDC( 0))) {
      apiErr;
      return;
   }
   if (!( dca = dc_alloc())) {
      DeleteDC( dc);
      return;
   }

   if ( sys pal) {
      p = SelectPalette( dc, sys pal, 1);
      RealizePalette( dc);
   }

   if ( !( bm = CreateCompatibleBitmap( dca, var w, var h))) {
      DeleteDC( dc);
      dc_free();
      apiErr;
      return;
   }
   stock = SelectObject( dc, bm);

   BitBlt( dc, 0, 0, var w, var h, sys ps, 0, 0, SRCCOPY);

   if ( sys pal) {
      SelectPalette( sys ps, sys stockPalette, 1);
      sys stockPalette = p;
   } else
      sys stockPalette = GetCurrentObject( dc, OBJ_PAL);

   if ( sys stockBM)
      SelectObject( sys ps, sys stockBM);
   DeleteObject( sys bm);
   DeleteDC( sys ps);

   sys ps = dc;
   sys bm = bm;
   sys stockBM = stock;
   dc_free();
}
Пример #6
0
HICON
image_make_icon_handle( Handle img, Point size, Point * hotSpot)
{
   PIcon i = ( PIcon) img;
   HICON    r;
   ICONINFO ii;
   int    bpp = i-> type & imBPP;
   Bool  noSZ   = i-> w != size. x || i-> h != size. y;
   Bool  noBPP  = bpp != 1 && bpp != 4 && bpp != 8 && bpp != 24;
   HDC dc;
   XBITMAPINFO bi;
   Bool notAnIcon = !kind_of( img, CIcon);

   ii. fIcon = hotSpot ? false : true;
   ii. xHotspot = hotSpot ? hotSpot-> x : 0;
   ii. yHotspot = hotSpot ? hotSpot-> y : 0;

   if ( noSZ || noBPP) {
      i = ( PIcon)( i-> self-> dup( img));

      if ( noSZ)
         i-> self-> set_size(( Handle) i, size);
      if ( noBPP)
         i-> self-> set_type(( Handle) i,
             ( bpp < 4) ? 1 :
             (( bpp < 8) ? 4 :
             (( bpp < 24) ? 8 : 24))
      );
   }

   if (!( dc = dc_alloc())) {
      if (( Handle) i != img) Object_destroy(( Handle) i);
      return NULL;
   }
   image_get_binfo(( Handle)i, &bi);
   if ( bi. bmiHeader. biClrUsed > 0)
      bi. bmiHeader. biClrUsed = bi. bmiHeader. biClrImportant = i-> palSize;

   if ( !( ii. hbmColor = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT,
       i-> data, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr;
   bi. bmiHeader. biBitCount = bi. bmiHeader. biPlanes = 1;
   bi. bmiColors[ 0]. rgbRed = bi. bmiColors[ 0]. rgbGreen = bi. bmiColors[ 0]. rgbBlue = 0;
   bi. bmiColors[ 1]. rgbRed = bi. bmiColors[ 1]. rgbGreen = bi. bmiColors[ 1]. rgbBlue = 255;

   if ( !( ii. hbmMask  = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT,
      notAnIcon ? NULL : i-> mask, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr;
   
   dc_free();

   if ( !( r = CreateIconIndirect( &ii))) apiErr;

   DeleteObject( ii. hbmColor);
   DeleteObject( ii. hbmMask);
   if (( Handle) i != img) Object_destroy(( Handle) i);
   return r;
}
Пример #7
0
void * dc_realloc(void * ptr, size_t size)
{
	if(!ptr){
		ptr = dc_alloc(size);
		return ptr;
	}
	if(size == 0){
		dc_free(ptr);
		return NULL;
	}
	void * word_before_ptr = (void *)((uint64 *)ptr - 1);
	void * new_ptr;
	uint64 cap = *(uint64 *)word_before_ptr;
	if(size <= POW2(cap)){
		printf("dc_mm : %s","reallocate but return the original pointer.");
		return ptr;
	}
	new_ptr = dc_alloc(size);
	memcpy(new_ptr, ptr, POW2(cap));
	dc_free(ptr);
	printf("dc_mm : %s","reallocation finished");
	return new_ptr;
}
Пример #8
0
int main( int argc, char **argv )
{
	int i, j;
	
    dc_init ();
	
	//allocates vector...
	// max N is 1024...
    v=(int *)dc_malloc (4096);
	
	//allocates MyQGraphicsRectItem vector...
	vr=(MyQGraphicsRectItem **)malloc (N*sizeof (MyQGraphicsRectItem **));
	
	/*generates random seed...*/
	srand((unsigned)time (NULL));
	
	//fills vector with values...
	printf ("Generated vector: \n");
	for (i=0; i<N; i++)
	{
		/*generates random number in (0,1)...*/
		j = rand() % (N*N);
		//without this printf it won't work with -O2...
		//printf ("%d ", j); 
		v[i] = j;
	}
	printf ("\n");
	
	QApplication a( argc, argv );

	w=new MyWidget ();

	w->show();
	
	int ret_value=a.exec();
		
	//frees main page...
    dc_free (v);
	//frees MyQGraphicsRectItem vector...
	free (vr);
	
	//deallocates constraint parameter data structs...
	for (i=0; i<N; i++)
	{
		free (gDataArray[i]);
	}

	return ret_value;
} 
Пример #9
0
void
image_query_bits( Handle self, Bool forceNewImage)
{
   PImage i = ( PImage) self;
   XBITMAPINFO xbi;
   BITMAPINFO * bi;
   int  newBits;
   HDC  ops = nil;
   BITMAP bitmap;

   if ( forceNewImage) {
      ops = sys ps;
      if ( !ops) {
         if ( !( sys ps = dc_alloc())) return;
      }
   }

   if ( !GetObject( sys bm, sizeof( BITMAP), ( LPSTR) &bitmap)) {
      apiErr;
      return;
      // if GetObject fails to get even BITMAP, there will be no good in farther run for sure.
   }

   if (( bitmap. bmPlanes == 1) && (
          ( bitmap. bmBitsPixel == 1) ||
          ( bitmap. bmBitsPixel == 4) ||
          ( bitmap. bmBitsPixel == 8) ||
          ( bitmap. bmBitsPixel == 24)
      ))
      newBits = bitmap. bmBitsPixel;
   else {
      newBits = ( bitmap. bmBitsPixel <= 4) ? 4 :
                (( bitmap. bmBitsPixel <= 8) ? 8 : 24);
   }


   if ( forceNewImage) {
      i-> self-> create_empty( self, bitmap. bmWidth, bitmap. bmHeight, newBits);
   } else {
      if (( newBits != ( i-> type & imBPP)) || (( i-> type & ~imBPP) != 0))
         i-> self-> create_empty( self, i-> w, i-> h, newBits);
   }

   bi = image_get_binfo( self, &xbi);

   if ( !GetDIBits( sys ps, sys bm, 0, i-> h, i-> data, bi, DIB_RGB_COLORS)) apiErr;

   if (( i-> type & imBPP) < 24) {
      int j, nColors = 1 << ( i-> type & imBPP);
      for ( j = 0; j < nColors; j++) {
         i-> palette[ j]. r = xbi. bmiColors[ j]. rgbRed;
         i-> palette[ j]. g = xbi. bmiColors[ j]. rgbGreen;
         i-> palette[ j]. b = xbi. bmiColors[ j]. rgbBlue;
      }
   }

   if ( forceNewImage) {
      if ( !ops) {
         dc_free();
      }
      sys ps = ops;
   }
}
/*
 * The main loop of the player thread, during playback.  This is
 * basically a state machine, which multiplexes data between the
 * decoder thread and the output threads.
 */
static void do_play(struct player_control *pc, struct decoder_control *dc)
{
	struct player player = {
		.pc = pc,
		.dc = dc,
		.buffering = true,
		.decoder_starting = false,
		.paused = false,
		.queued = true,
		.song = NULL,
		.xfade = XFADE_UNKNOWN,
		.cross_fading = false,
		.cross_fade_chunks = 0,
		.cross_fade_tag = NULL,
		.elapsed_time = 0.0,
	};

	player_unlock(pc);

	player.pipe = music_pipe_new();

	player_dc_start(&player, player.pipe);
	if (!player_wait_for_decoder(&player)) {
		player_dc_stop(&player);
		player_command_finished(pc);
		music_pipe_free(player.pipe);
		event_pipe_emit(PIPE_EVENT_PLAYLIST);
		player_lock(pc);
		return;
	}

	player_lock(pc);
	pc->state = PLAYER_STATE_PLAY;
	player_command_finished_locked(pc);

	while (true) {
		player_process_command(&player);
		if (pc->command == PLAYER_COMMAND_STOP ||
		    pc->command == PLAYER_COMMAND_EXIT ||
		    pc->command == PLAYER_COMMAND_CLOSE_AUDIO) {
			player_unlock(pc);
			audio_output_all_cancel();
			break;
		}

		player_unlock(pc);

		if (player.buffering) {
			/* buffering at the start of the song - wait
			   until the buffer is large enough, to
			   prevent stuttering on slow machines */

			if (music_pipe_size(player.pipe) < pc->buffered_before_play &&
			    !decoder_lock_is_idle(dc)) {
				/* not enough decoded buffer space yet */

				if (!player.paused &&
				    audio_format_defined(&player.play_audio_format) &&
				    audio_output_all_check() < 4 &&
				    !player_send_silence(&player))
					break;

				decoder_lock(dc);
				/* XXX race condition: check decoder again */
				player_wait_decoder(pc, dc);
				decoder_unlock(dc);
				player_lock(pc);
				continue;
			} else {
				/* buffering is complete */
				player.buffering = false;
			}
		}

		if (player.decoder_starting) {
			/* wait until the decoder is initialized completely */

			if (!player_check_decoder_startup(&player))
				break;

			player_lock(pc);
			continue;
		}

#ifndef NDEBUG
		/*
		music_pipe_check_format(&play_audio_format,
					player.next_song_chunk,
					&dc->out_audio_format);
		*/
#endif

		if (decoder_lock_is_idle(dc) && player.queued &&
		    dc->pipe == player.pipe) {
			/* the decoder has finished the current song;
			   make it decode the next song */

			assert(dc->pipe == NULL || dc->pipe == player.pipe);

			player_dc_start(&player, music_pipe_new());
		}

		if (player_dc_at_next_song(&player) &&
		    player.xfade == XFADE_UNKNOWN &&
		    !decoder_lock_is_starting(dc)) {
			/* enable cross fading in this song?  if yes,
			   calculate how many chunks will be required
			   for it */
			player.cross_fade_chunks =
				cross_fade_calc(pc->cross_fade_seconds, dc->total_time,
						pc->mixramp_db,
						pc->mixramp_delay_seconds,
						dc->replay_gain_db,
						dc->replay_gain_prev_db,
						dc->mixramp_start,
						dc->mixramp_prev_end,
						&dc->out_audio_format,
						&player.play_audio_format,
						music_buffer_size(player_buffer) -
						pc->buffered_before_play);
			if (player.cross_fade_chunks > 0) {
				player.xfade = XFADE_ENABLED;
				player.cross_fading = false;
			} else
				/* cross fading is disabled or the
				   next song is too short */
				player.xfade = XFADE_DISABLED;
		}

		if (player.paused) {
			player_lock(pc);

			if (pc->command == PLAYER_COMMAND_NONE)
				player_wait(pc);
			continue;
		} else if (!music_pipe_empty(player.pipe)) {
			/* at least one music chunk is ready - send it
			   to the audio output */

			play_next_chunk(&player);
		} else if (audio_output_all_check() > 0) {
			/* not enough data from decoder, but the
			   output thread is still busy, so it's
			   okay */

			/* XXX synchronize in a better way */
			g_usleep(10000);
		} else if (player_dc_at_next_song(&player)) {
			/* at the beginning of a new song */

			if (!player_song_border(&player))
				break;
		} else if (decoder_lock_is_idle(dc)) {
			/* check the size of the pipe again, because
			   the decoder thread may have added something
			   since we last checked */
			if (music_pipe_empty(player.pipe)) {
				/* wait for the hardware to finish
				   playback */
				audio_output_all_drain();
				break;
			}
		} else {
			/* the decoder is too busy and hasn't provided
			   new PCM data in time: send silence (if the
			   output pipe is empty) */
			if (!player_send_silence(&player))
				break;
		}

		player_lock(pc);
	}

	player_dc_stop(&player);

	music_pipe_clear(player.pipe, player_buffer);
	music_pipe_free(player.pipe);

	if (player.cross_fade_tag != NULL)
		tag_free(player.cross_fade_tag);

	player_lock(pc);

	if (player.queued) {
		assert(pc->next_song != NULL);
		pc->next_song = NULL;
	}

	pc->state = PLAYER_STATE_STOP;

	player_unlock(pc);

	event_pipe_emit(PIPE_EVENT_PLAYLIST);

	player_lock(pc);
}

static gpointer
player_task(gpointer arg)
{
	struct player_control *pc = arg;

	struct decoder_control *dc = dc_new(pc->cond);
	decoder_thread_start(dc);

	player_buffer = music_buffer_new(pc->buffer_chunks);

	player_lock(pc);

	while (1) {
		switch (pc->command) {
		case PLAYER_COMMAND_QUEUE:
			assert(pc->next_song != NULL);

			do_play(pc, dc);
			break;

		case PLAYER_COMMAND_STOP:
			player_unlock(pc);
			audio_output_all_cancel();
			player_lock(pc);

			/* fall through */

		case PLAYER_COMMAND_SEEK:
		case PLAYER_COMMAND_PAUSE:
			pc->next_song = NULL;
			player_command_finished_locked(pc);
			break;

		case PLAYER_COMMAND_CLOSE_AUDIO:
			player_unlock(pc);

			audio_output_all_release();

			player_lock(pc);
			player_command_finished_locked(pc);

#ifndef NDEBUG
			/* in the DEBUG build, check for leaked
			   music_chunk objects by freeing the
			   music_buffer */
			music_buffer_free(player_buffer);
			player_buffer = music_buffer_new(pc->buffer_chunks);
#endif

			break;

		case PLAYER_COMMAND_UPDATE_AUDIO:
			player_unlock(pc);
			audio_output_all_enable_disable();
			player_lock(pc);
			player_command_finished_locked(pc);
			break;

		case PLAYER_COMMAND_EXIT:
			player_unlock(pc);

			dc_quit(dc);
			dc_free(dc);
			audio_output_all_close();
			music_buffer_free(player_buffer);

			player_command_finished(pc);
			return NULL;

		case PLAYER_COMMAND_CANCEL:
			pc->next_song = NULL;
			player_command_finished_locked(pc);
			break;

		case PLAYER_COMMAND_REFRESH:
			/* no-op when not playing */
			player_command_finished_locked(pc);
			break;

		case PLAYER_COMMAND_NONE:
			player_wait(pc);
			break;
		}
	}
}

void
player_create(struct player_control *pc)
{
	assert(pc->thread == NULL);

	GError *e = NULL;
	pc->thread = g_thread_create(player_task, pc, true, &e);
	if (pc->thread == NULL)
		MPD_ERROR("Failed to spawn player task: %s", e->message);
}
Пример #11
0
Bool
window_subsystem_init( char * error_buf)
{
   WNDCLASSW wc;
   HDC dc;
   HBITMAP hbm;
   OSVERSIONINFO os = { sizeof( OSVERSIONINFO)};

   guts. version  = GetVersion();
   GetVersionEx( &os);
   guts. alloc_utf8_to_wchar_visual = 
   	(( os.dwMajorVersion > 5) || (os.dwMajorVersion == 5 && os.dwMinorVersion > 1)) ?
		alloc_utf8_to_wchar_visual :
		alloc_utf8_to_wchar;
   guts. mainThreadId = GetCurrentThreadId();
   guts. errorMode = SetErrorMode( SEM_FAILCRITICALERRORS);
   guts. desktopWindow = GetDesktopWindow();

   memset( &wc, 0, sizeof( wc));
   wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
   wc.lpfnWndProc   = ( WNDPROC) generic_app_handler;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = guts. instance;
   wc.hIcon         = LoadIcon( guts. instance, IDI_APPLICATION);
   wc.hCursor       = LoadCursor( NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH)NULL;
   wc.lpszClassName = L"GenericApp";
   RegisterClassW( &wc);

   memset( &wc, 0, sizeof( wc));
   wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
   wc.lpfnWndProc   = ( WNDPROC) generic_frame_handler;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = guts. instance;
   wc.hIcon         = LoadIcon( guts. instance, IDI_APPLICATION);
   wc.hCursor       = LoadCursor( NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH)NULL;
   wc.lpszClassName = L"GenericFrame";
   RegisterClassW( &wc);

   memset( &wc, 0, sizeof( wc));
   wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
   wc.lpfnWndProc   = ( WNDPROC) generic_view_handler;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = guts. instance;
   wc.hIcon         = LoadIcon( guts. instance, IDI_APPLICATION);
   wc.hCursor       = NULL; // LoadCursor( NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH)NULL;
   wc.lpszClassName = L"Generic";
   RegisterClassW( &wc);

   stylusMan  = hash_create();
   fontMan    = hash_create();
   patMan     = hash_create();
   menuMan    = hash_create();
   imageMan   = hash_create();
   regnodeMan = hash_create();
   create_font_hash();
   {
      LOGBRUSH b = { BS_HOLLOW, 0, 0};
      Font f;
      hPenHollow        = CreatePen( PS_NULL, 0, 0);
      hBrushHollow      = CreateBrushIndirect( &b);
      hPatHollow. dotsCount = 0;
      hPatHollow. dotsPtr   = nil;
      FONTSTRUCSIZE    = (char *)(&(f. name)) - (char *)(&f);
   }

   if (!( dc = dc_alloc())) return false; 
   guts. displayResolution. x = GetDeviceCaps( dc, LOGPIXELSX);
   guts. displayResolution. y = GetDeviceCaps( dc, LOGPIXELSY);
   {
      LOGFONT lf;
      HFONT   sfont;

      // getting most common font name
      memset( &lf, 0, sizeof( lf));
      lf. lfCharSet        = OEM_CHARSET;
      lf. lfOutPrecision   = OUT_DEFAULT_PRECIS;
      lf. lfClipPrecision  = CLIP_DEFAULT_PRECIS;
      lf. lfQuality        = PROOF_QUALITY;
      lf. lfPitchAndFamily = DEFAULT_PITCH;
      sfont = SelectObject( dc, CreateFontIndirect( &lf));
      GetTextFace( dc, 256, guts. defaultSystemFont);

      // getting common fixed font name
      lf. lfHeight = 320;
      lf. lfPitchAndFamily = FIXED_PITCH;
      DeleteObject( SelectObject( dc, CreateFontIndirect( &lf)));
      GetTextFace( dc, 256, guts. defaultFixedFont);

      // getting common variable font name
      lf. lfPitchAndFamily = VARIABLE_PITCH;
      DeleteObject( SelectObject( dc, CreateFontIndirect( &lf)));
      GetTextFace( dc, 256, guts. defaultVariableFont);
      DeleteObject( SelectObject( dc, sfont));

      // getting system font presets
      memset( &guts. windowFont, 0, sizeof( Font));
      strcpy( guts. windowFont. name, DEFAULT_WIDGET_FONT);
      guts. windowFont. size  = DEFAULT_WIDGET_FONT_SIZE;
      guts. windowFont. width = guts. windowFont. height = C_NUMERIC_UNDEF;
#ifdef FONT_CHECK
      guts. windowFont. size = 12;
#endif
      apc_font_pick( nilHandle, &guts. windowFont, &guts. windowFont);

      guts. ncmData. cbSize = sizeof( NONCLIENTMETRICS);
      SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( NONCLIENTMETRICS),
         ( PVOID) &guts. ncmData, 0);
      font_logfont2font( &guts. ncmData. lfMenuFont, &guts. menuFont, &guts. displayResolution);
      font_logfont2font( &guts. ncmData. lfMessageFont, &guts. msgFont, &guts. displayResolution);
      font_logfont2font( &guts. ncmData. lfCaptionFont, &guts. capFont, &guts. displayResolution);
   }

   memset( &guts. displayBMInfo, 0, sizeof( guts. displayBMInfo));
   guts. displayBMInfo. bmiHeader. biSize = sizeof( BITMAPINFO);
   if ( !( hbm = GetCurrentObject( dc, OBJ_BITMAP))) {
      apiErr;
      dc_free();
      return false;
   }

   if ( !GetDIBits( dc, hbm, 0, 0, NULL, &guts. displayBMInfo, DIB_PAL_COLORS)) {
      guts. displayBMInfo. bmiHeader. biBitCount = GetDeviceCaps( dc, BITSPIXEL);
      guts. displayBMInfo. bmiHeader. biPlanes   = GetDeviceCaps( dc, PLANES);
   }

   dc_free();
   guts. insertMode = true;
   guts. iconSizeSmall. x = GetSystemMetrics( SM_CXSMICON);
   guts. iconSizeSmall. y = GetSystemMetrics( SM_CYSMICON);
   guts. iconSizeLarge. x = GetSystemMetrics( SM_CXICON);
   guts. iconSizeLarge. y = GetSystemMetrics( SM_CYICON);
   guts. pointerSize. x   = GetSystemMetrics( SM_CXCURSOR);
   guts. pointerSize. y   = GetSystemMetrics( SM_CYCURSOR);
   list_create( &guts. transp, 8, 8);
   list_create( &guts. files, 8, 8);
   list_create( &guts. sockets, 8, 8);

   // selecting locale layout, more or less latin-like

   {
      char buf[ KL_NAMELENGTH * 2] = "";
      HKL current      = GetKeyboardLayout( 0);
      int i, j, size   = GetKeyboardLayoutList( 0, nil);
      HKL * kl         = ( HKL *) malloc( sizeof( HKL) * size);

      guts. keyLayout = nil;
      if ( !GetKeyboardLayoutName( buf)) apiErr;
      for ( j = 0; j < ( sizeof( keyLayouts) / sizeof( char*)); j++) {
         if ( strncmp( buf + 4, keyLayouts[ j], 4) == 0) {
            guts. keyLayout = current;
            goto found_1;
         }
      }

      if ( kl) {
         GetKeyboardLayoutList( size, kl);
         for ( i = 0; i < size; i++) {
            ActivateKeyboardLayout( kl[ i], 0);
            if ( !GetKeyboardLayoutName( buf)) apiErr;
            for ( j = 0; j < ( sizeof( keyLayouts) / sizeof( char*)); j++) {
               if ( strncmp( buf + 4, keyLayouts[ j], 4) == 0) {
                  guts. keyLayout = kl[ i];
                  goto found_2;
               }
            }
         }
      found_2:;
         ActivateKeyboardLayout( current, 0);
      }
   found_1:;
      free( kl);
   }
   guts. currentKeyState = guts. keyState;
   memset( guts. emptyKeyState, 0, sizeof( guts. emptyKeyState));
   guts. smDblClk. x = GetSystemMetrics( SM_CXDOUBLECLK);
   guts. smDblClk. y = GetSystemMetrics( SM_CYDOUBLECLK);

   return true;
}
Пример #12
0
int main( int argc, char **argv )
{
	int i=0;
	int h, k;
	
	/*double avgAct=0.0;
	int maxAct=0;
	double avgFinalAct=0.0;
	int maxFinalAct=0;
	double avgTime=0.0;
	double maxTime=0.0;*/
	
	//initializes ww[][] (pointers to ellipses)...
	for (h=0; h<N; h++)
		for (k=0; k<N; k++)
			ww[h][k]=NULL;
	
    dc_init ();
	
	//allocates vector...
	// max N is 16...
	//v=(int *)LWP_AllocPages (1);
    //v=(int *)dc_malloc (4096);
    v=(int *)dc_malloc (N*N*sizeof (int));
	
	//installs constraints...
	for (h=0; h<N; h++)
		for (k=0; k<N; k++)
		{
			//we are assuming lots of things here...
			int theData=(h<<16)+k;
			
			//LCP_NewCons (GeneralConstraint, NULL, (void *)theData); 
            dc_new_cons (GeneralConstraint, (void *)theData, NULL);
		}
	
	//QApplication a( argc, argv );
    MyApplication a( argc, argv );

    w=new MyWidget ();

	//a.setMainWidget( w );
	w->show();
    
	//sets up board...
	_whiteMove (N/2-1, N/2-1);
	_whiteMove (N/2, N/2);
	_blackMove (N/2-1, N/2);
	_blackMove (N/2, N/2-1);
	gSetup=0;
	
	//just testing...
/*	printf ("\nInitial board:\n");
	_printBoard ();
	while (i<1)
	{
	int a, b;
	printf ("Black move:\ni: ");
	scanf ("%d", &a);
	printf ("j: ");
	scanf ("%d", &b);
	_blackMove (a, b);
	_printBoard ();
		
	printf ("White move:\ni: ");
	scanf ("%d", &a);
	printf ("j: ");
	scanf ("%d", &b);
	_whiteMove (a, b);
	_printBoard ();
	
	i++;
	}*/

    replayThread = new MyThread ();
	
	int ret_value=a.exec();
    
    delete replayThread;
	
	//LCP_CleanUp ();
	
	//frees main page...
	//LWP_FreePages ((void *)v, 1);
    dc_free (v);

	/*debugging...*/
	//printf ("\n[DEBUG] LMemory_GetBlocksCount() says: %u\n", (unsigned int)LMemory_GetBlocksCount ());

    // dump DC profiling info
    if (dc_profile_on()) 
        dc_dump_profile_diff(stdout, 
                             &log_array_prof[0], 
                             &log_array_prof[iter-1]);
    else {

        //computes avg and max resize evt processing time...
        elapsed_time_t avg;
        avg.real=0;
        avg.user=0;
        avg.system=0;
        avg.child_user=0;
        avg.child_system=0;
        
        double max=log_array[0].real;
        for (i=0; i<iter; i++)
        {
            avg.real=avg.real+log_array[i].real;
            avg.user=avg.user+log_array[i].user;
            avg.system=avg.system+log_array[i].system;
            avg.child_user=avg.child_user+log_array[i].child_user;
            avg.child_system=avg.child_system+log_array[i].child_system;
            
            if (log_array[i].real>max)
                max=log_array[i].real;
        }

        divide_elapsed_time_by(&avg, iter);
        printf ("\nTotal times per move:\n");
        printf ("Avg real = %f\n", avg.real);
        printf ("Avg user = %f\n", avg.user);
        printf ("Avg system = %f\n", avg.system);
        printf ("Avg child_user = %f\n", avg.child_user);
        printf ("Avg child_system = %f\n", avg.child_system);
        printf ("Max real = %f\n", max);
        
        avg.real=0;
        avg.user=0;
        avg.system=0;
        avg.child_user=0;
        avg.child_system=0;
        max=inter_array[1].real;
        for (i=0; i<iter; i++)
        {
            avg.real=avg.real+inter_array[i].real;
            avg.user=avg.user+inter_array[i].user;
            avg.system=avg.system+inter_array[i].system;
            avg.child_user=avg.child_user+inter_array[i].child_user;
            avg.child_system=avg.child_system+inter_array[i].child_system;
            
            if (inter_array[i].real>max)
                max=inter_array[i].real;
        }
        
        divide_elapsed_time_by(&avg, iter);
        printf ("\nPropagation times only:\n");
        printf ("Avg real = %f\n", avg.real);
        printf ("Avg user = %f\n", avg.user);
        printf ("Avg system = %f\n", avg.system);
        printf ("Avg child_user = %f\n", avg.child_user);
        printf ("Avg child_system = %f\n", avg.child_system);
        printf ("Max real = %f\n", max);
    }

	return ret_value;
} 
Пример #13
0
int main() {

    dc_init();

    rm_make_dump_file("test02-start-"OPT".log");

    T* p = (T*)dc_malloc(sizeof(T));

    p->x = 1;

    dc_cons* cons_c = dc_new_cons((dc_cons_f)c, p, NULL);

    dc_dump_cons(stdout, cons_c);
    dc_dump_cell(stdout, &p->x);
    dc_dump_cell(stdout, &p->y);
    dc_dump_cell(stdout, &p->z);

    dc_cons* cons_d = dc_new_cons((dc_cons_f)d, p, NULL);

    dc_dump_cons(stdout, cons_c);
    dc_dump_cons(stdout, cons_d);
    dc_dump_cell(stdout, &p->x);
    dc_dump_cell(stdout, &p->y);
    dc_dump_cell(stdout, &p->z);

    dc_begin_at();

    p->x = 10;
    p->y = 7;

    dc_dump_wr_cell_list(stdout);

    dc_dump_cell(stdout, &p->x);
    dc_dump_cell(stdout, &p->y);
    dc_dump_cell(stdout, &p->z);

    dc_end_at();

    dc_dump_cell(stdout, &p->x);
    dc_dump_cell(stdout, &p->y);
    dc_dump_cell(stdout, &p->z);

    dc_dump_cons(stdout, cons_c);
    dc_dump_cons(stdout, cons_d);

    p->x++;

    dc_dump_cell(stdout, &p->x);
    dc_dump_cell(stdout, &p->y);
    dc_dump_cell(stdout, &p->z);

    dc_dump_cons(stdout, cons_c);
    dc_dump_cons(stdout, cons_d);

    p->y-=5;

    dc_dump_cell(stdout, &p->x);
    dc_dump_cell(stdout, &p->y);
    dc_dump_cell(stdout, &p->z);

    dc_dump_cons(stdout, cons_c);
    dc_dump_cons(stdout, cons_d);

    p->x=50;

    dc_dump_cell(stdout, &p->x);
    dc_dump_cell(stdout, &p->y);
    dc_dump_cell(stdout, &p->z);

    dc_dump_cons(stdout, cons_c);
    dc_dump_cons(stdout, cons_d);

    dc_free(p);

    rm_make_dump_file("test02-end-"OPT".log");

    return 0;
}
Пример #14
0
int main() {
    int i,j,k,rows=0;
    FILE *titles_file;
    char str_buf[X_SIZE*2]; 
    char **titles;

    // Allocate reactive strings
    X = (int*)dc_malloc(X_SIZE*sizeof(int));
    if (!X) return -1;

    Y = (int*)dc_malloc(Y_SIZE*sizeof(int));
    if (!Y) return -1;

    // Allocate DP table (dynamic programming table)
    M = (int**)dc_malloc((X_SIZE+1)*sizeof(int*));
    if (!M) return -1;
    for (i=0; i<=X_SIZE; i++) {
        M[i] = (int*)dc_malloc((Y_SIZE+1)*sizeof(int));
        if (!M[i]) return -1;
    }

    // Init DP table
    for (i=0; i<=X_SIZE; i++) M[i][0]=i;
    for (j=0; j<=Y_SIZE; j++) M[0][j]=j;

    // Allocate update table
    #ifdef MONITOR_UPDATES
    updates = (int**)malloc((X_SIZE+1)*sizeof(int*));
    if (!updates) return -1;
    for (i=0; i<=X_SIZE; i++) {
        updates[i] = (int*)malloc((Y_SIZE+1)*sizeof(int));
        if (!updates[i]) return -1;
        for (j=0; j<=Y_SIZE; j++) updates[i][j]=0;
    }
    #endif

    // Alloc and init constraint table
    cons = (T**)malloc((X_SIZE+1)*sizeof(T*));
    if (!cons) return -1;
    for (i=0; i<=X_SIZE; i++) {
        cons[i] = (T*)malloc((Y_SIZE+1)*sizeof(T));
        if (!cons[i]) return -1;
        if (i>0) for (j=1; j<=Y_SIZE; j++) {
            cons[i][j].i = i;
            cons[i][j].j = j;
            M[i][j] = 0;
        }
    }    
 
    // open input file
    if ((titles_file = fopen("../perf/benchmarks/data/titles-sapienza-sample.txt", "r")) == NULL) {
        printf("Cannot open file \"%s\"\n", "titles-sapienza-sample.txt");
        exit(1);
    }
    else printf("\nOpening file \"%s\"\n", "titles-sapienza-sample.txt");
   
    // compute number of rows
    while(fgets(str_buf, X_SIZE*2, titles_file) != NULL) rows++;
    printf("Number of titles = %d\n",rows);
    
    // fill in titles data structure
    fseek(titles_file,0,SEEK_SET);
    titles = (char**)malloc(rows*sizeof(char*));
    if (titles==NULL) {
        printf("Cannot allocate titles memory\n");
        exit(1);
    }
    i=0;
    while(fgets(str_buf, X_SIZE*2, titles_file) != NULL) {
        int l = strlen(str_buf);
        titles[i] = (char*)malloc((l+1)*sizeof(char));
        if (titles[i]==NULL) {
            printf("Cannot allocate titles memory\n");
            exit(1);
        }
        k=0;
        for (j=0;j<l;j++)
            if (isalnum(str_buf[j])) titles[i][k++] = tolower(str_buf[j]);
        titles[i][k] = '\0';            
        i++;
    }
    // print titles
    printf("\n");
    for (j=0; j<i; j++) printf("%s\n",titles[j]);
    printf("\n");

    // compute edit distances
    for (i=0; i<3; i++) {
        int min = 2*X_SIZE+1;
        int min_idx = 0;
        for (j=0; j<3; j++)
            if (i!=j) {
                string_update(titles[i],titles[j]);
                if (M[X_len][Y_len]<min) {
                    min = M[X_len][Y_len];
                    min_idx = j;
                }
            }
        printf("Min edit dist = %-4d  (max overlap = %.2f)\n", min, 100.0 - 100.0*min/X_len);
    }

    // Free constraints and data structures
    for (i=0; i<=X_len; i++) {
        for (j=1; j<=Y_len; j++) 
            if (i>0) dc_del_cons(cons[i][j].cons);
        free(cons[i]);
    }
    free(cons);
    for (i=0; i<=X_SIZE; i++) dc_free(M[i]);
    dc_free(M);
    dc_free(Y);
    dc_free(X);
    return 0;
}
Пример #15
0
int main( int argc, char **argv )
{
	int i, j;
	
	dc_init ();
	
	//allocates main page...
	mainPage=dc_malloc (sizeof (ProtectedData));
	
	//allocates one protected page per button...
	for (i=0; i<NumButtX; i++)
		for (j=0; j<NumButtY; j++)
			page[i][j]=dc_malloc (sizeof (ProtectedData));
	
	//QApplication a( argc, argv );
    MyApplication a( argc, argv );

	w=new MyWidget ();

	w->setGeometry (0, 0, MaxXSize, MaxYSize);
	w->show();

    MyThread *resizeThread = new MyThread ();
    resizeThread->start();

	int ret_value=a.exec();

    delete resizeThread;

	//frees main page...
	dc_free (mainPage);
	
	//frees protected pages...
	for (i=0; i<NumButtX; i++)
		for (j=0; j<NumButtY; j++)
			dc_free (page[i][j]);
	
	//for (i=0; i<LOG_ENTRIES; i++)
		//printf ("%f - %f\n", log_array[i].main_win_resize, log_array[i].last_button_resize);

    // dump DC profiling info
    if (dc_profile_on()) 
        dc_dump_profile_diff(stdout, 
                             &log_array_prof[numIter-4], 
                             &log_array_prof[numIter-3]);
    else {

        //computes avg and max resize evt processing time...
        elapsed_time_t avg;
        avg.real=0;
        avg.user=0;
        avg.system=0;
        avg.child_user=0;
        avg.child_system=0;
        
        double max=log_array[1].real;
        for (i=1; i<numIter-2; i++)
        {
            avg.real=avg.real+log_array[i].real;
            avg.user=avg.user+log_array[i].user;
            avg.system=avg.system+log_array[i].system;
            avg.child_user=avg.child_user+log_array[i].child_user;
            avg.child_system=avg.child_system+log_array[i].child_system;
            
            if (log_array[i].real>max)
                max=log_array[i].real;
        }

        divide_elapsed_time_by(&avg, numIter-2);
        printf ("\nTotal times per resize event:\n");
        printf ("Avg real = %f\n", avg.real);
        printf ("Avg user = %f\n", avg.user);
        printf ("Avg system = %f\n", avg.system);
        printf ("Avg child_user = %f\n", avg.child_user);
        printf ("Avg child_system = %f\n", avg.child_system);
        printf ("Max real = %f\n", max);
        
        avg.real=0;
        avg.user=0;
        avg.system=0;
        avg.child_user=0;
        avg.child_system=0;
        max=inter_array[1].real;
        for (i=1; i<numIter-2; i++)
        {
            avg.real=avg.real+inter_array[i].real;
            avg.user=avg.user+inter_array[i].user;
            avg.system=avg.system+inter_array[i].system;
            avg.child_user=avg.child_user+inter_array[i].child_user;
            avg.child_system=avg.child_system+inter_array[i].child_system;
            
            if (inter_array[i].real>max)
                max=inter_array[i].real;
        }
        
        divide_elapsed_time_by(&avg, numIter-2);
        printf ("\nChange propagation times only:\n");
        printf ("Avg real = %f\n", avg.real);
        printf ("Avg user = %f\n", avg.user);
        printf ("Avg system = %f\n", avg.system);
        printf ("Avg child_user = %f\n", avg.child_user);
        printf ("Avg child_system = %f\n", avg.child_system);
        printf ("Max real = %f\n", max);
    }

	return ret_value;
}