Exemple #1
0
static void
display_cache_file(struct display *dp, const char *filename)
   /* Does the initial cache of the file. */
{
   FILE *fp;
   int ret;

   dp->filename = filename;

   if (filename != NULL)
   {
      fp = fopen(filename, "rb");
      if (fp == NULL)
         display_log(dp, USER_ERROR, "open failed: %s", strerror(errno));
   }

   else
      fp = stdin;

   ret = buffer_from_file(&dp->original_file, fp);

   fclose(fp);

   if (ret != 0)
      display_log(dp, APP_ERROR, "read failed: %s", strerror(ret));
}
Exemple #2
0
static void
read_png(struct display *dp, struct buffer *bp, const char *operation,
   int transforms)
{
   png_structp pp;
   png_infop   ip;

   /* This cleans out any previous read and sets operation and transforms to
    * empty.
    */
   display_clean_read(dp);

   if (operation != NULL) /* else this is a verify and do not overwrite info */
   {
      dp->operation = operation;
      dp->transforms = transforms;
   }

   dp->read_pp = pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, dp,
      display_error, display_warning);
   if (pp == NULL)
      display_log(dp, LIBPNG_ERROR, "failed to create read struct");

   /* The png_read_png API requires us to make the info struct, but it does the
    * call to png_read_info.
    */
   dp->read_ip = ip = png_create_info_struct(pp);
   if (ip == NULL)
      display_log(dp, LIBPNG_ERROR, "failed to create info struct");

#  ifdef PNG_SET_USER_LIMITS_SUPPORTED
      /* Remove the user limits, if any */
      png_set_user_limits(pp, 0x7fffffff, 0x7fffffff);
#  endif

   /* Set the IO handling */
   buffer_start_read(bp);
   png_set_read_fn(pp, bp, read_function);

   png_read_png(pp, ip, transforms, NULL/*params*/);

#if 0 /* crazy debugging */
   {
      png_bytep pr = png_get_rows(pp, ip)[0];
      size_t rb = png_get_rowbytes(pp, ip);
      size_t cb;
      char c = ' ';

      fprintf(stderr, "%.4x %2d (%3lu bytes):", transforms, png_get_bit_depth(pp,ip), (unsigned long)rb);

      for (cb=0; cb<rb; ++cb)
         fputc(c, stderr), fprintf(stderr, "%.2x", pr[cb]), c='.';

      fputc('\n', stderr);
   }
#endif
}
Exemple #3
0
static void
buffer_read(struct display *dp, struct buffer *bp, png_bytep data,
   png_size_t size)
{
   struct buffer_list *last = bp->current;
   size_t read_count = bp->read_count;

   while (size > 0)
   {
      size_t avail;

      if (last == NULL ||
         (last == bp->last && read_count >= bp->end_count))
      {
         display_log(dp, USER_ERROR, "file truncated (%lu bytes)",
            (unsigned long)size);
         /*NOTREACHED*/
         break;
      }

      else if (read_count >= sizeof last->buffer)
      {
         /* Move to the next buffer: */
         last = last->next;
         read_count = 0;
         bp->current = last; /* Avoid update outside the loop */

         /* And do a sanity check (the EOF case is caught above) */
         if (last == NULL)
         {
            display_log(dp, INTERNAL_ERROR, "damaged buffer list");
            /*NOTREACHED*/
            break;
         }
      }

      avail = (sizeof last->buffer) - read_count;
      if (avail > size)
         avail = size;

      memcpy(data, last->buffer + read_count, avail);
      read_count += avail;
      size -= avail;
      data += avail;
   }

   bp->read_count = read_count;
}
Exemple #4
0
static void PNGCBAPI
display_error(png_structp pp, png_const_charp error)
{
   struct display *dp = get_dp(pp);

   display_log(dp, LIBPNG_ERROR, "%s", error);
}
int mlx_shaders_pixel(glsl_info_t *glsl)
{
  char  *source;
  int	length;
  GLint action_ok;

  glsl->pixel_vshader = glCreateShader(GL_VERTEX_SHADER);
  /*
  source = strdup("#version 110 \n"
		  "attribute vec2 position;"
		  "uniform vec2 winhalfsize;"
		  "varying vec2 texcoord;"
		  "void main()"
		  "{"
		  " vec2 pos = position - winhalfsize;"
		  " pos = pos / winhalfsize;"
		  " gl_Position = vec4( pos, 0.0, 1.0);"
		  " texcoord = position / (2.0*winhalfsize);"
		  "}");
  */
  source = strdup("#version 110 \n"
		  "attribute vec2 position;"
		  //"uniform vec2 winhalfsize;"
		  "varying vec2 texcoord;"
		  "void main()"
		  "{"
		  //" vec2 pos = position - winhalfsize;"
		  //" pos = pos / winhalfsize;"
		  " gl_Position = vec4( position, 0.0, 1.0);"
		  " texcoord = (position + vec2(1.0, 1.0)) / 2.0;"
		  "}");
  length = strlen(source);
  glShaderSource(glsl->pixel_vshader, 1, (const GLchar**)&source, &length);
  glCompileShader(glsl->pixel_vshader);

  glGetShaderiv(glsl->pixel_vshader, GL_COMPILE_STATUS, &action_ok);
  if (!action_ok) {
    fprintf(stderr, "Failed to compile pixel vshader :\n");
    display_log(glsl->pixel_vshader, glGetShaderiv, glGetShaderInfoLog);
    return (1);
  }

  glsl->pixel_fshader = glCreateShader(GL_FRAGMENT_SHADER);
  source = strdup("#version 110 \n"
		  "uniform sampler2D texture;"
		  "varying vec2 texcoord;"
		  "void main()"
		  "{"
		  // " gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);"
		  " gl_FragColor = texture2D(texture, texcoord);"
		  "}");
  length = strlen(source);
  glShaderSource(glsl->pixel_fshader, 1, (const GLchar**)&source, &length);
  glCompileShader(glsl->pixel_fshader);

  glGetShaderiv(glsl->pixel_fshader, GL_COMPILE_STATUS, &action_ok);
  if (!action_ok) {
    fprintf(stderr, "Failed to compile pixel fshader :\n");
    display_log(glsl->pixel_fshader, glGetShaderiv, glGetShaderInfoLog);
    return (1);
  }

  glsl->pixel_program = glCreateProgram();
  glAttachShader(glsl->pixel_program, glsl->pixel_vshader);
  glAttachShader(glsl->pixel_program, glsl->pixel_fshader);
  glLinkProgram(glsl->pixel_program);

  glGetProgramiv(glsl->pixel_program, GL_LINK_STATUS, &action_ok);
  if (!action_ok) {
    fprintf(stderr, "Failed to link pixel shader program:\n");
    display_log(glsl->pixel_program, glGetProgramiv, glGetProgramInfoLog);
    return (1);
  }

  glFlush();

  return (0);
}
Exemple #6
0
/**
 * Main function of the server application. It does a infinite loop unless a user exits the program.
 * @param[in] listener_socket File descriptor of the socket listening incoming connections.
 * @param[in] fifo            File descriptor of a temporary FIFO file.
 */
void
doServer(int listener_socket, int fifo) {
	int i, fdmax, newfd;
	players_list_s *players_list = NULL;
	games_list_s *games_list = NULL;
	threads_list_s *threads_list = NULL;
	pthread_mutex_t players_list_mutex = PTHREAD_MUTEX_INITIALIZER;
	pthread_mutex_t games_list_mutex = PTHREAD_MUTEX_INITIALIZER;
	pthread_mutex_t threads_list_mutex = PTHREAD_MUTEX_INITIALIZER;
	fd_set base_rdfs, rdfs;
	sigset_t mask, oldmask;
	FD_ZERO(&base_rdfs);
	FD_SET(listener_socket, &base_rdfs);
	fdmax = max(listener_socket, fifo);
	sigemptyset(&mask);
	sigaddset(&mask, SIGINT);
	sigprocmask(SIG_BLOCK, &mask, &oldmask);
	initialize_structures(&players_list, &games_list, &threads_list);
	printf("Four-in-a-line server started\n");
	while (work) {
		rdfs = base_rdfs;
		if (pselect(fdmax + 1, &rdfs, NULL, NULL, NULL, &oldmask) > 0) {
			for (i = 0; i <= fdmax; i++) {
				newfd = -1;
				if (FD_ISSET(i, &rdfs)) {
					if (i == listener_socket) {
						/* request from newly connected client */
						newfd = add_new_client(listener_socket);
						if (newfd > 0) {
							FD_SET(newfd, &base_rdfs);
							if (newfd > fdmax) {
								fdmax = newfd;
							}
							display_log(newfd);
							communicate(newfd, &base_rdfs, &players_list,
									&games_list, &threads_list,
									&players_list_mutex, &games_list_mutex,
									&threads_list_mutex);
						} else if (i == fifo) {
							/* trick to update base_rdfs set */
							char temp[1];
							bulk_read(fifo, temp, 1);
						}
					} else {
						/* request from already connected client */
						communicate(i, &base_rdfs, &players_list, &games_list,
								&threads_list, &players_list_mutex,
								&games_list_mutex, &threads_list_mutex);
					}
				}
			}
		} else {
			if (EINTR == errno)
				continue;
			ERR("pselect");
		}
	}
	pthread_mutex_destroy(&players_list_mutex);
	pthread_mutex_destroy(&games_list_mutex);
	pthread_mutex_destroy(&threads_list_mutex);
	destroy_players(players_list);
	destroy_games(games_list);
	destroy_threads(threads_list);
	sigprocmask(SIG_UNBLOCK, &mask, NULL);
}
Exemple #7
0
int main(void) {
	int result = OK;
	char temp_buffer[MAX_INPUT_BUFFER];


	/* get the CGI variables passed in the URL */
	process_cgivars();

	/* reset internal variables */
	reset_cgi_vars();

	/* read the CGI configuration file */
	result = read_cgi_config_file(get_cgi_config_location());
	if(result == ERROR) {
		document_header(FALSE);
		cgi_config_file_error(get_cgi_config_location());
		document_footer();
		return ERROR;
		}

	/* read the main configuration file */
	result = read_main_config_file(main_config_file);
	if(result == ERROR) {
		document_header(FALSE);
		main_config_file_error(main_config_file);
		document_footer();
		return ERROR;
		}

	/* read all object configuration data */
	result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
	if(result == ERROR) {
		document_header(FALSE);
		object_data_error();
		document_footer();
		return ERROR;
		}


	document_header(TRUE);

	/* get authentication information */
	get_authentication_information(&current_authdata);

	/* determine what log file we should be using */
	get_log_archive_to_use(log_archive, log_file_to_use, (int)sizeof(log_file_to_use));

	if(display_header == TRUE) {

		/* begin top table */
		printf("<table border=0 width=100%% cellpadding=0 cellspacing=0>\n");
		printf("<tr>\n");

		/* left column of top table - info box */
		printf("<td align=left valign=top width=33%%>\n");
		display_info_table((log_rotation_method == LOG_ROTATION_NONE || log_archive == 0) ? "Current Event Log" : "Archived Event Log", FALSE, &current_authdata);
		printf("</td>\n");

		/* middle column of top table - log file navigation options */
		printf("<td align=center valign=top width=33%%>\n");
		snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s?%s", SHOWLOG_CGI, (use_lifo == FALSE) ? "oldestfirst&" : "");
		temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
		display_nav_table(temp_buffer, log_archive);
		printf("</td>\n");

		/* right hand column of top row */
		printf("<td align=right valign=top width=33%%>\n");

		printf("<form method='GET' action='%s'>\n", SHOWLOG_CGI);
		printf("<input type='hidden' name='archive' value='%d'>\n", log_archive);
		printf("<table border=0 cellspacing=0 cellpadding=0 CLASS='optBox'>\n");
		printf("<tr>");
		printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='oldestfirst' %s> Older Entries First:</td>", (use_lifo == FALSE) ? "checked" : "");
		printf("</tr>\n");
		printf("<tr>");
		printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='submit' value='Update'></td>\n");
		printf("</tr>\n");

		/* display context-sensitive help */
		printf("<tr>\n");
		printf("<td align=right>\n");
		display_context_help(CONTEXTHELP_LOG);
		printf("</td>\n");
		printf("</tr>\n");

		printf("</table>\n");
		printf("</form>\n");

		printf("</td>\n");

		/* end of top table */
		printf("</tr>\n");
		printf("</table>\n");
		printf("</p>\n");

		}


	/* display the contents of the log file */
	display_log();

	document_footer();

	/* free allocated memory */
	free_memory();

	return OK;
	}
Exemple #8
0
static int
compare_read(struct display *dp, int applied_transforms)
{
   /* Compare the png_info from read_ip with original_info */
   size_t rowbytes;
   png_uint_32 width, height;
   int bit_depth, color_type;
   int interlace_method, compression_method, filter_method;
   const char *e = NULL;

   png_get_IHDR(dp->read_pp, dp->read_ip, &width, &height, &bit_depth,
      &color_type, &interlace_method, &compression_method, &filter_method);

#  define C(item) if (item != dp->item) \
      display_log(dp, APP_WARNING, "IHDR " #item "(%lu) changed to %lu",\
         (unsigned long)dp->item, (unsigned long)item), e = #item

   /* The IHDR should be identical: */
   C(width);
   C(height);
   C(bit_depth);
   C(color_type);
   C(interlace_method);
   C(compression_method);
   C(filter_method);

   /* 'e' remains set to the name of the last thing changed: */
   if (e)
      display_log(dp, APP_ERROR, "IHDR changed (%s)", e);

   /* All the chunks from the original PNG should be preserved in the output PNG
    * because the PNG format has not been changed.
    */
   {
      unsigned long chunks =
         png_get_valid(dp->read_pp, dp->read_ip, 0xffffffff);
      
      if (chunks != dp->chunks)
         display_log(dp, APP_FAIL, "PNG chunks changed from 0x%lx to 0x%lx",
            (unsigned long)dp->chunks, chunks);
   }

   /* rowbytes should be the same */
   rowbytes = png_get_rowbytes(dp->read_pp, dp->read_ip);

   /* NOTE: on 64-bit systems this may trash the top bits of rowbytes,
    * which could lead to weird error messages.
    */
   if (rowbytes != dp->original_rowbytes)
      display_log(dp, APP_ERROR, "PNG rowbytes changed from %lu to %lu",
         (unsigned long)dp->original_rowbytes, (unsigned long)rowbytes);

   /* The rows should be the same too, unless the applied transforms includes
    * the shift transform, in which case low bits may have been lost.
    */
   {
      png_bytepp rows = png_get_rows(dp->read_pp, dp->read_ip);
      unsigned int mask;  /* mask (if not zero) for the final byte */

      if (bit_depth < 8)
      {
         /* Need the stray bits at the end, this depends only on the low bits
          * of the image width; overflow does not matter.  If the width is an
          * exact multiple of 8 bits this gives a mask of 0, not 0xff.
          */
         mask = 0xff & (0xff00 >> ((bit_depth * width) & 7));
      }

      else
Exemple #9
0
static void
update_display(struct display *dp)
   /* called once after the first read to update all the info, original_pp and
    * original_ip must have been filled in.
    */
{
   png_structp pp;
   png_infop   ip;

   /* Now perform the initial read with a 0 tranform. */
   read_png(dp, &dp->original_file, "original read", 0/*no transform*/);

   /* Move the result to the 'original' fields */
   dp->original_pp = pp = dp->read_pp, dp->read_pp = NULL;
   dp->original_ip = ip = dp->read_ip, dp->read_ip = NULL;

   dp->original_rowbytes = png_get_rowbytes(pp, ip);
   if (dp->original_rowbytes == 0)
      display_log(dp, LIBPNG_BUG, "png_get_rowbytes returned 0");

   dp->chunks = png_get_valid(pp, ip, 0xffffffff);
   if ((dp->chunks & PNG_INFO_IDAT) == 0) /* set by png_read_png */
      display_log(dp, LIBPNG_BUG, "png_read_png did not set IDAT flag");

   dp->original_rows = png_get_rows(pp, ip);
   if (dp->original_rows == NULL)
      display_log(dp, LIBPNG_BUG, "png_read_png did not create row buffers");

   if (!png_get_IHDR(pp, ip,
      &dp->width, &dp->height, &dp->bit_depth, &dp->color_type,
      &dp->interlace_method, &dp->compression_method, &dp->filter_method))
      display_log(dp, LIBPNG_BUG, "png_get_IHDR failed");

   /* 'active' transforms are discovered based on the original image format;
    * running one active transform can activate others.  At present the code
    * does not attempt to determine the closure.
    */
   {
      png_uint_32 chunks = dp->chunks;
      int active = 0, inactive = 0;
      int ct = dp->color_type;
      int bd = dp->bit_depth;
      unsigned int i;

      for (i=0; i<TTABLE_SIZE; ++i)
      {
         int transform = transform_info[i].transform;

         if ((transform_info[i].valid_chunks == 0 ||
               (transform_info[i].valid_chunks & chunks) != 0) &&
            (transform_info[i].color_mask_required & ct) == 
               transform_info[i].color_mask_required &&
            (transform_info[i].color_mask_absent & ct) == 0 &&
            (transform_info[i].bit_depths & bd) != 0 &&
            (transform_info[i].when & TRANSFORM_R) != 0)
            active |= transform;

         else if ((transform_info[i].when & TRANSFORM_R) != 0)
            inactive |= transform;
      }

      /* Some transforms appear multiple times in the table; the 'active' status
       * is the logical OR of these and the inactive status must be adjusted to
       * take this into account.
       */
      inactive &= ~active;

      dp->active_transforms = active;
      dp->ignored_transforms = inactive; /* excluding write-only transforms */

      if (active == 0)
         display_log(dp, INTERNAL_ERROR, "bad transform table");
   }
}
Exemple #10
0
/* error handler callbacks for libpng */
static void PNGCBAPI
display_warning(png_structp pp, png_const_charp warning)
{
   display_log(get_dp(pp), LIBPNG_WARNING, "%s", warning);
}
Exemple #11
0
void display_sysmenu(void)
{
#ifdef USING_SYSMENU
// al_set_target_bitmap(sysmstate.bmp);
// al_set_target_bitmap(al_get_backbuffer(display));
 al_set_clipping_rectangle(editor.panel_x, editor.panel_y, editor.panel_w, editor.panel_h);

 al_clear_to_color(colours.base [COL_BLUE] [SHADE_MIN]);

 reset_i_buttons();

 al_draw_textf(font[FONT_SQUARE_BOLD].fnt, colours.base [COL_GREY] [SHADE_MAX], 5, 2, ALLEGRO_ALIGN_LEFT, "System Menu");

 int i;

#define BUTTON_TEXT_LENGTH 30
 char button_text [BUTTON_TEXT_LENGTH] = "";
 int button_colour;
 int button_base_shade; // is increased by 1 if button highlighted, so don't set this to SHADE_MAX
 int button_selectable; // note that setting this to 0 just means the button doesn't look selectable
 int hide_button; // button completely hidden

// sysmenu buttons are a bit complicated because their appearance depends on various game state things
 for (i = 0; i < SYSMENU_BUTTONS; i ++)
 {
  button_colour = COL_BLUE;
  button_base_shade = SHADE_LOW;
  button_selectable = 1;
  hide_button = 0;

  switch(i)
  {
/*   case SYSMENU_NEXT_TURN:
    switch(game.phase)
    {
     case GAME_PHASE_TURN:
      if (game.current_turn == 0)
       strcpy(button_text, "Start execution!");
        else
         strcpy(button_text, "Next turn");
      button_colour = COL_GREEN;
      break;
     case GAME_PHASE_OVER:
      strcpy(button_text, "Game over");
//      button_colour = COL_GREEN;
      button_base_shade = SHADE_MIN;
      button_selectable = 0;
      break;
     default:
      strcpy(button_text, "Executing...");
      if (game.pause_soft)
       strcpy(button_text, "Partial execution");
      if (game.pause_hard)
       strcpy(button_text, "Halted");
      button_base_shade = SHADE_MIN;
      button_selectable = 0;
      break;
    }
    break;*/
   case SYSMENU_PAUSE:
    if (game.pause_soft == 0)
     strcpy(button_text, "Pause");
      else
      {
       strcpy(button_text, "Unpause");
       button_colour = COL_GREEN;
      }
    break;
   case SYSMENU_HALT:
    if (game.pause_hard == 0)
     strcpy(button_text, "Halt execution");
      else
      {
       strcpy(button_text, "Restart execution");
       button_colour = COL_GREEN;
      }
    break;
/*   case SYSMENU_FF:
    if (game.fast_forward == FAST_FORWARD_OFF)
     strcpy(button_text, "Fast forward");
      else
      {
       strcpy(button_text, "Stop fast forward");
       button_colour = COL_GREEN;
      }
    break;*/
   case SYSMENU_SAVE:
    strcpy(button_text, "Save game");
    break;
//   case SYSMENU_LOAD:
//    strcpy(button_text, "Load game");
//    break;
   case SYSMENU_QUIT:
    if (game.phase == GAME_PHASE_OVER)
    {
     strcpy(button_text, "Return to main menu");
     button_colour = COL_GREEN;
    }
     else
      strcpy(button_text, "Quit game");
    break;
   case SYSMENU_QUIT_CONFIRM:
    if (sysmstate.quit_confirm == 1)
    {
     strcpy(button_text, "Really quit?");
     button_colour = COL_RED;
    }
     else
     {
      button_selectable = 0;
      hide_button = 1;
     }
    break;
  }

 if (hide_button == 1)
  continue;

  if (sysmstate.button_highlight == i
   && button_selectable == 1)
//   al_draw_filled_rectangle(editor.panel_x + sysmenu_button[i].x1, editor.panel_y + sysmenu_button[i].y1, editor.panel_x + sysmenu_button[i].x2, editor.panel_y + sysmenu_button[i].y2, colours.base [button_colour] [button_base_shade + 1]);
   add_menu_button(editor.panel_x + sysmenu_button[i].x1, editor.panel_y + sysmenu_button[i].y1, editor.panel_x + sysmenu_button[i].x2, editor.panel_y + sysmenu_button[i].y2, colours.base [button_colour] [button_base_shade + 1], MBUTTON_TYPE_MENU);
    else
     add_menu_button(editor.panel_x + sysmenu_button[i].x1, editor.panel_y + sysmenu_button[i].y1, editor.panel_x + sysmenu_button[i].x2, editor.panel_y + sysmenu_button[i].y2, colours.base [button_colour] [button_base_shade], MBUTTON_TYPE_MENU);
//     al_draw_filled_rectangle(editor.panel_x + sysmenu_button[i].x1, editor.panel_y + sysmenu_button[i].y1, editor.panel_x + sysmenu_button[i].x2, editor.panel_y + sysmenu_button[i].y2, colours.base [button_colour] [button_base_shade]);

   add_menu_string(editor.panel_x + sysmenu_button[i].x1 + 15, editor.panel_y + sysmenu_button[i].y1 + 20, &colours.base [COL_GREY] [SHADE_HIGH], 0, FONT_SQUARE_BOLD, button_text);
//   al_draw_textf(font[FONT_SQUARE_BOLD].fnt, colours.base [COL_GREY] [SHADE_HIGH], editor.panel_x + sysmenu_button[i].x1 + 15, editor.panel_y + sysmenu_button[i].y1 + 20, 0, "%s", button_text);

 }

 draw_menu_buttons();
// mode buttons should be drawn in i_display.c

 display_log(editor.panel_x + EDIT_WINDOW_X, editor.panel_y + editor.mlog_window_y);
// al_set_target_bitmap(sysmstate.bmp);
 al_set_clipping_rectangle(editor.panel_x, editor.panel_y, editor.panel_w, editor.panel_h);

 draw_scrollbar(&mlog.scrollbar_v, 0, 0);

 if (ex_control.panel_drag_ready == 1
		|| ex_control.mouse_dragging_panel == 1)
		draw_panel_drag_ready_line();

// al_set_target_bitmap(al_get_backbuffer(display));
// al_draw_bitmap(sysmstate.bmp, sysmstate.panel_x, sysmstate.panel_y, 0); // TO DO!!!!: need to treat the sysmenu bitmap as a subbitmap of the display backbuffer, which would let us save this drawing operation

#endif


}