static void console_execute_file_real(const char *filename)
{
	IOHANDLE file;
	file = engine_openfile(filename, IOFLAG_READ);
	
	if(file)
	{
		//VOTEOPTION *current = voteoption_first;
		//while(current)
		//{
		//	current = current->next;
		//	current->prev=0;
		//}
		//int i=0;
		//for(i;i<MAX_CLIENTS;i++)
		//	if (game.players[i]->authed==0)
		//		server_kick(i, "Server settings reload");

		char *line;
		LINEREADER lr;
		
		dbg_msg("console", "executing '%s'", filename);
		linereader_init(&lr, file);

		while((line = linereader_get(&lr)))
			console_execute_line(line,-1);

		io_close(file);
	}
	else
		dbg_msg("console", "failed to open '%s'", filename);
}
Exemplo n.º 2
0
static int
is_srt(const char *buf, size_t len)
{
  linereader_t lr;

  int n;
  int64_t start, stop;

  srt_skip_preamble(&buf, &len);

  linereader_init(&lr, buf, len);

  if(linereader_next(&lr) < 0)
    return 0;
  if(get_int(&lr, &n))
    return 0;
  if(linereader_next(&lr) < 0)
    return 0;
  if(get_srt_timestamp(&lr, &start, &stop))
    return 0;

  if(stop < start)
    return 0;

  return 1;
}
Exemplo n.º 3
0
static ext_subtitles_t *
load_srt(const char *url, const char *buf, size_t len)
{
  int n;
  size_t tlen = 0;
  int64_t start, stop, pstart = -1, pstop = -1;
  linereader_t lr;
  ext_subtitles_t *es = calloc(1, sizeof(ext_subtitles_t));
  char *txt = NULL;
  size_t txtoff = 0;

  const int tag_flags = TEXT_PARSE_HTML_TAGS | TEXT_PARSE_HTML_ENTITIES |
    TEXT_PARSE_SLOPPY_TAGS | TEXT_PARSE_SUB_TAGS;

  srt_skip_preamble(&buf, &len);

  TAILQ_INIT(&es->es_entries);
  linereader_init(&lr, buf, len);
  while(1) {
    if((n = linereader_next(&lr)) < 0)
      break;

    if(get_srt_timestamp(&lr, &start, &stop) == 0) {
      if(txt != NULL && pstart != -1 && pstop != -1) {
	txt[txtoff] = 0;
	es_insert_text(es, txt, pstart, pstop, tag_flags);
	free(txt);
	txt = NULL;
	tlen = 0;
	txtoff = 0;
      }
      pstart = start;
      pstop  = stop;
      continue;
    }
    if(pstart == -1)
      continue;

    txt = realloc(txt, tlen + lr.ll + 1);
    memcpy(txt + tlen, lr.buf, lr.ll);
    txt[tlen + lr.ll] = 0x0a;
    if(lr.ll == 0 && tlen > 0)
      txtoff = tlen - 1;
    tlen += lr.ll + 1;
  }

  if(txt != NULL && pstart != -1 && pstop != -1) {
    txt[txtoff] = 0;
    es_insert_text(es, txt, pstart, pstop, tag_flags);
  }
  free(txt);
  return es;
}
Exemplo n.º 4
0
bool LOCALIZATIONDATABASE::load(const char *filename)
{
	// empty string means unload
	if(filename[0] == 0)
	{
		strings.clear();
		return true;
	}
	
	LINEREADER lr;
	IOHANDLE io = io_open(filename, IOFLAG_READ);
	if(!io)
		return false;
	
	dbg_msg("localization", "loaded '%s'", filename);
	strings.clear();
	
	linereader_init(&lr, io);
	char *line;
	while((line = linereader_get(&lr)))
	{
		if(!str_length(line))
			continue;
			
		if(line[0] == '#') // skip comments
			continue;
			
		char *replacement = linereader_get(&lr);
		if(!replacement)
		{
			dbg_msg("", "unexpected end of file");
			break;
		}
		
		if(replacement[0] != '=' || replacement[1] != '=' || replacement[2] != ' ')
		{
			dbg_msg("", "malform replacement line for '%s'", line);
			continue;
		}

		replacement += 3;
		localization.add_string(line, replacement);
	}
	
	current_version++;
	return true;
}
Exemplo n.º 5
0
int mastersrv_load()
{
	LINEREADER lr;
	IOHANDLE file;
	int count = 0;
	
	/* try to open file */
	file = engine_openfile("masters.cfg", IOFLAG_READ);
	if(!file)
		return -1;
	
	linereader_init(&lr, file);
	while(1)
	{
		MASTER_INFO info = {{0}};
		int ip[4];
		const char *line = linereader_get(&lr);
		if(!line)
			break;

		/* parse line */		
		if(sscanf(line, "%s %d.%d.%d.%d", info.hostname, &ip[0], &ip[1], &ip[2], &ip[3]) == 5)
		{
			info.addr.ip[0] = (unsigned char)ip[0];
			info.addr.ip[1] = (unsigned char)ip[1];
			info.addr.ip[2] = (unsigned char)ip[2];
			info.addr.ip[3] = (unsigned char)ip[3];
			info.addr.port = 8300;
			if(count != MAX_MASTERSERVERS)
			{
				master_servers[count] = info;
				count++;
			}
			else
				dbg_msg("engine/mastersrv", "warning: skipped master server '%s' due to limit of %d", line, MAX_MASTERSERVERS);
		}
		else
			dbg_msg("engine/mastersrv", "warning: couldn't parse master server '%s'", line);
	}
	
	io_close(file);
	return 0;
}
Exemplo n.º 6
0
static void console_execute_file_real(const char *filename)
{
	IOHANDLE file;
	file = engine_openfile(filename, IOFLAG_READ);
	
	if(file)
	{
		char *line;
		LINEREADER lr;
		
		dbg_msg("console", "executing '%s'", filename);
		linereader_init(&lr, file);

		while((line = linereader_get(&lr)))
			console_execute_line(line);

		io_close(file);
	}
	else
		dbg_msg("console", "failed to open '%s'", filename);
}
Exemplo n.º 7
0
int
main( int argc, char *argv[] )
{
   FILE       *out_a, *out_b;
   char       *h1, *h2, *s, *q;
   char       *id = NULL;
   char       *outname_a = NULL, *outname_b = NULL, *outdirname = NULL;
   int         i;
   struct options *o = options_new(  );
   struct tokenset *t = tokenset_new(  );
   struct fqreader *fq = fqreader_new( NULL );

   /* Get the command line options */
   options_cmdline( o, argc, argv );

   if ( _IS_NULL( o->outname ) || strlen( o->outname ) == 0 ) {
      o->outname = realloc( o->outname, 4 * sizeof ( char ) );
      strcpy( o->outname, "FQU" );
   }

   /* Create the output directory if necessary */
   outdirname = realloc( outdirname, sizeof ( char ) * ( 2 + strlen( o->outname ) ) );
   strcpy( outdirname, o->outname );
   if ( strchr( outdirname, '/' ) ) {            /* not the current directory */
      dirname( outdirname );
      mkdirp( outdirname, S_IRWXU | S_IRWXG | S_IRWXO );
   }


   /* Read the id files */
   for ( i = o->optind; i < argc; i++ ) {

      char       *line;
      struct linereader *z = linereader_new(  );

      linereader_init( z, argv[i] );

      if ( _IS_NULL( z ) ) {
         fprintf( stderr, "[ERROR] %s: Cannot open input file \"%s\"\n", _I_AM, argv[i] );
         exit( 1 );
      }

      while ( ( line = ( char * ) linereader_next( z ) ) ) {
         unsigned    len;

         stru_trim( line );

         if ( line[0] == '#' || stru_is_ws( line ) )
            continue;

         len = strcspn( line, "\f\n\r\t\v " );
         line[len] = '\0';

         tokenset_add( t, line );
      }

      linereader_free( z );
   }

   outname_a = realloc( outname_a, sizeof ( char ) * ( 6 + strlen( o->outname ) ) );
   strcpy( outname_a, o->outname );
   strcat( outname_a, "_A.fq" );
   out_a = fopen( outname_a, "wb" );
   if ( _IS_NULL( out_a ) ) {
      fprintf( stderr, "Could not open first output file \"%s\"\n", outname_a );
      exit( 1 );
   }

   outname_b = realloc( outname_b, sizeof ( char ) * ( 6 + strlen( o->outname ) ) );
   strcpy( outname_b, o->outname );
   strcat( outname_b, "_B.fq" );
   out_b = fopen( outname_b, "wb" );
   if ( _IS_NULL( out_b ) ) {
      fprintf( stderr, "Could not open second output file \"%s\"\n", outname_b );
      exit( 1 );
   }


   while ( fqreader_next( fq, &h1, &h2, &s, &q ) ) {

      utils_extract_id( &id, h1 );               /* get the identifier from header 1 */

      if ( tokenset_exists( t, id ) )
         fprintf( out_a, "@%s\n%s\n+%s\n%s\n", h1, s, h2, q );

      else
         fprintf( out_b, "@%s\n%s\n+%s\n%s\n", h1, s, h2, q );
   }

   fclose( out_a );
   fclose( out_b );

   _FREE( id );
   _FREE( outname_a );
   _FREE( outname_b );
   fqreader_free( fq );
   options_free( o );
   tokenset_free( t );

   return 0;
}