示例#1
0
static dlna_container_type_t
mov_find_container_type (const char *filename)
{
  if (!filename)
    return CT_UNKNOWN;

  if (!strcasecmp (get_file_extension (filename), "3gp") ||
      !strcasecmp (get_file_extension (filename), "3gpp") ||
      !strcasecmp (get_file_extension (filename), "3g2"))
    return CT_3GP;

  return CT_MP4;
}
示例#2
0
int load_pixels(const std::string& filename, unsigned char **pixel_buf, img_info_t *img_info) {

	memset(img_info, 0x0, sizeof(*img_info));

	std::string ext = get_file_extension(filename);
	if (ext == ".jpg" || ext == ".jpeg") {
		if (!loadJPEG(filename, pixel_buf, img_info)) {
			fprintf(stderr, "[load_pixels]: fatal error: loading file %s failed.\n", filename.c_str());
			return 0;
		}
	
	}
	else if (ext == ".png") {
		if(!loadPNG(filename, pixel_buf, img_info)) {
			fprintf(stderr, "[load_pixels]: fatal error: loading file %s failed.\n", filename.c_str());
			return 0;
		}
	} else {
		fprintf(stderr, "[load_pixels]: fatal error: unsupported image file extension \"%s\" (only .png, .jpg, .jpeg are supported)\n", ext.c_str());
		return 0;
	}

	return 1;

}
示例#3
0
const std::string LangMap::getMappedFileNameFromFileName(
        const std::string &fileName) {
    // make sure the lang map file is parsed
    open();

    string mappedFile;

    // try with the file extension
    const string ext = get_file_extension(fileName);
    if (ext != "") {
        mappedFile = getFileName(ext);
        if (mappedFile != "")
            return mappedFile;
        else {
            mappedFile = getFileName(Utils::tolower(ext));
            if (mappedFile != "")
                return mappedFile;
        }
    }

    string fileNameNoPath = strip_file_path(fileName);

    // try with the file name
    mappedFile = getFileName(fileNameNoPath);
    if (mappedFile != "")
        return mappedFile;

    // try with the lower case file name (as our last chance)
    return getFileName(Utils::tolower(fileNameNoPath));
}
void switch_output_file(struct lib_ccx_ctx *ctx, struct encoder_ctx *enc_ctx, int track_id) {
	if (enc_ctx->out->filename != NULL) { // Close and release the previous handle
		free(enc_ctx->out->filename);
		close(enc_ctx->out->fh);
	}
	char *ext = get_file_extension(ctx->write_format);
	char suffix[32];
	sprintf(suffix, "_%d", track_id);
	enc_ctx->out->filename = create_outfilename(get_basename(enc_ctx->first_input_file), suffix, ext);
	enc_ctx->out->fh = open(enc_ctx->out->filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE);

	// Reset counters as we switch output file.
	enc_ctx->cea_708_counter = 0;
	enc_ctx->srt_counter = 0;
}
示例#5
0
bool has_file_extension(const std::string& filename, const std::string& csv_extensions)
{
  if (!filename.empty()) {
    std::string ext = base::string_to_lower(get_file_extension(filename));

    int extsz = ext.size();
    std::string::const_iterator p =
      std::search(csv_extensions.begin(),
                  csv_extensions.end(),
                  ext.begin(), ext.end());

    if ((p != csv_extensions.end()) &&
        ((p+extsz) == csv_extensions.end() || *(p+extsz) == ',') &&
        (p == csv_extensions.begin() || *(p-1) == ','))
      return true;
  }
  return false;
}
示例#6
0
int decoder_backend_open(struct decoder_handle_struct *handle, char *fname)
{
	struct decoder_backend_struct *bhandle;
	char ext[5];
	get_file_extension(ext, fname);

	handle->acc_data = NULL;
	handle->acc_len = 0;
	handle->last_frate = 0;

	bhandle = lookup(ext);
	if(!bhandle || !bhandle->ops ||!bhandle->ops->open) {
		return -1;
	}
	
	handle->backend_info = bhandle;
	return bhandle->ops->open((void **)&handle->backend_handle, handle, fname);
}
示例#7
0
struct lib_hardsubx_ctx* _init_hardsubx(struct ccx_s_options *options)
{
	// Initialize HardsubX data structures
	struct lib_hardsubx_ctx *ctx = (struct lib_hardsubx_ctx *)malloc(sizeof(struct lib_hardsubx_ctx));
	if(!ctx)
		fatal(EXIT_NOT_ENOUGH_MEMORY, "lib_hardsubx_ctx");
	memset(ctx, 0, sizeof(struct lib_hardsubx_ctx));
	
	ctx->tess_handle = TessBaseAPICreate();
	if(TessBaseAPIInit3(ctx->tess_handle, NULL, "eng") != 0)
	{
		fatal(EXIT_NOT_ENOUGH_MEMORY, "Not enough memory to initialize Tesseract!");
	}

	//Initialize attributes common to lib_ccx context
	ctx->basefilename = get_basename(options->output_filename);//TODO: Check validity, add stdin, network
	ctx->current_file = -1;
	ctx->inputfile = options->inputfile;
	ctx->num_input_files = options->num_input_files;
	ctx->extension = get_file_extension(options->write_format);
	ctx->write_format = options->write_format;
	ctx->subs_delay = options->subs_delay;
	ctx->cc_to_stdout = options->cc_to_stdout;

	//Initialize subtitle text parameters
	ctx->cur_conf = 0.0;
	ctx->prev_conf = 0.0;
	ctx->ocr_mode = options->hardsubx_ocr_mode;
	ctx->subcolor = options->hardsubx_subcolor;
	ctx->min_sub_duration = options->hardsubx_min_sub_duration;
	ctx->detect_italics = options->hardsubx_detect_italics;
	ctx->conf_thresh = options->hardsubx_conf_thresh;
	ctx->hue = options->hardsubx_hue;
	ctx->lum_thresh = options->hardsubx_lum_thresh;

	//Initialize subtitle structure memory
	ctx->dec_sub = (struct cc_subtitle *)malloc(sizeof(struct cc_subtitle));
	memset (ctx->dec_sub, 0,sizeof(struct cc_subtitle));

	return ctx;
}
const char *
get_archive_filename_extension (const char *filename)
{
	const char *ext;
	int         i;

	if (filename == NULL)
		return NULL;

	ext = get_file_extension (filename);
	if (ext == NULL)
		return NULL;

	for (i = G_N_ELEMENTS (file_ext_type) - 1; i >= 0; i--) {
		if (file_ext_type[i].ext == NULL)
			continue;
		if (strcasecmp (ext, file_ext_type[i].ext) == 0)
			return ext;
	}

	return NULL;
}
StringSet SourceHighlightUtils::getFileNames(const std::string path,
        const std::string fileExtension) {
    StringSet strings;

    DIR *dp;
    struct dirent *ep;

    dp = opendir(path.c_str());
    if (dp != NULL) {
        while ((ep = readdir(dp))) {
            const string name(ep->d_name);
            if (get_file_extension(name) == fileExtension) {
                strings.insert(name);
            }
        }
        (void) closedir(dp);
    } else {
        throw IOException("Couldn't open the directory", path);
    }

    return strings;
}
示例#10
0
int send_file(int fd, const char* path) {
    if (path == NULL) {
        return -1;
    }

    struct stat st;
    if (lstat(path, &st) == -1) {
        if (errno == EACCES) {
            return -2;
        }
        return -1;
    }

    send(fd, HTTP_OK, strlen(HTTP_OK), 0);
    send(fd, HTTP_FILE_CONTENT_TYPE_BEGIN, strlen(HTTP_FILE_CONTENT_TYPE_BEGIN), 0);
    char* file_extension = get_file_extension(path);
    send(fd, file_extension, strlen(file_extension), 0);
    free(file_extension);
    send(fd, HTTP_FILE_CONTENT_TYPE_END, strlen(HTTP_FILE_CONTENT_TYPE_END), 0);
    send(fd, HTTP_CONTENT_ENCODING, strlen(HTTP_CONTENT_ENCODING), 0);
    send(fd, HTTP_CONTENT_LENGHT_BEGIN, strlen(HTTP_CONTENT_LENGHT_BEGIN), 0);
    char file_size[MAX_NUM_STR_LENGTH];
    snprintf(file_size, MAX_NUM_STR_LENGTH, "%d", (int)st.st_size);
    send(fd, file_size, strlen(file_size), 0);
    send(fd, HTTP_CONTENT_LENGHT_END, strlen(HTTP_CONTENT_LENGHT_END), 0);
    send(fd, HTTP_END, strlen(HTTP_END), 0);

    int file_d = open(path, O_RDONLY);
    if (file_d == -1) {
        if (errno == EACCES) {
            return -2;
        }
        return -1;
    }
    sendfile(fd, file_d, NULL, st.st_size);
    close(file_d);

    return 0;
}
示例#11
0
static int init_output_ctx(struct encoder_ctx *ctx, struct encoder_cfg *cfg)
{
	int ret = EXIT_OK;
	int nb_lang;
	char *basefilename = NULL; // Input filename without the extension
	char *extension = NULL; // Input filename without the extension


#define check_ret(filename) 	if (ret != EXIT_OK)							\
				{									\
					print_error(cfg->gui_mode_reports,"Failed %s\n", filename);	\
					return ret;							\
				}

	if (cfg->cc_to_stdout == CCX_FALSE && cfg->send_to_srv == CCX_FALSE && cfg->extract == 12)
		nb_lang = 2;
	else
		nb_lang = 1;

	ctx->out = malloc(sizeof(struct ccx_s_write) * nb_lang);
	if(!ctx->out)
		return -1;
	ctx->nb_out = nb_lang;

	if(cfg->cc_to_stdout == CCX_FALSE && cfg->send_to_srv == CCX_FALSE)
	{
		if (cfg->output_filename != NULL)
		{
			// Use the given output file name for the field specified by
			// the -1, -2 switch. If -12 is used, the filename is used for
			// field 1.
			if (cfg->extract == 12)
			{
				basefilename = get_basename(cfg->output_filename);
				extension = get_file_extension(cfg->write_format);

				ret = init_write(&ctx->out[0], strdup(cfg->output_filename));
				check_ret(cfg->output_filename);
				ret = init_write(&ctx->out[1], create_outfilename(basefilename, "_2", extension));
				check_ret(ctx->out[1].filename);
			}
			else if (cfg->extract == 1)
			{
				ret = init_write(ctx->out, strdup(cfg->output_filename));
				check_ret(cfg->output_filename);
			}
			else
			{
				ret = init_write(ctx->out, strdup(cfg->output_filename));
				check_ret(cfg->output_filename);
			}
		}
		else if (cfg->write_format != CCX_OF_NULL)
		{
			basefilename = get_basename(ctx->first_input_file);
			extension = get_file_extension(cfg->write_format);

			if (cfg->extract == 12)
			{
				ret = init_write(&ctx->out[0], create_outfilename(basefilename, "_1", extension));
				check_ret(ctx->out[0].filename);
				ret = init_write(&ctx->out[1], create_outfilename(basefilename, "_2", extension));
				check_ret(ctx->out[1].filename);
			}
			else if (cfg->extract == 1)
			{
				ret = init_write(ctx->out, create_outfilename(basefilename, NULL, extension));
				check_ret(ctx->out->filename);
			}
			else
			{
				ret = init_write(ctx->out, create_outfilename(basefilename, NULL, extension));
				check_ret(ctx->out->filename);
			}
		}

		freep(&basefilename);
		freep(&extension);
	}

	if (cfg->cc_to_stdout == CCX_TRUE)
	{
		ctx->out[0].fh = STDOUT_FILENO;
		ctx->out[0].filename = NULL;
		mprint ("Sending captions to stdout.\n");
	}

	if (cfg->send_to_srv == CCX_TRUE)
	{
		ctx->out[0].fh = -1;
		ctx->out[0].filename = NULL;

		connect_to_srv(ccx_options.srv_addr, ccx_options.srv_port, ccx_options.tcp_desc, ccx_options.tcp_password);
	}

	if (cfg->dtvcc_extract)
	{
		for (int i = 0; i < CCX_DTVCC_MAX_SERVICES; i++)
		{
			if (!cfg->services_enabled[i])
			{
				ctx->dtvcc_writers[i].fd = -1;
				ctx->dtvcc_writers[i].filename = NULL;
				ctx->dtvcc_writers[i].cd = (iconv_t) -1;
				continue;
			}

			if (cfg->cc_to_stdout)
			{
				ctx->dtvcc_writers[i].fd = STDOUT_FILENO;
				ctx->dtvcc_writers[i].filename = NULL;
				ctx->dtvcc_writers[i].cd = (iconv_t) -1;
			}
			else
			{
				if (cfg->output_filename)
					basefilename = get_basename(cfg->output_filename);
				else
					basefilename = get_basename(ctx->first_input_file);

				ccx_dtvcc_writer_init(&ctx->dtvcc_writers[i], basefilename,
									  ctx->program_number, i + 1, cfg->write_format, cfg);
				free(basefilename);
			}
		}
	}

	if(ret)
	{
		print_error(cfg->gui_mode_reports,
			"Output filename is same as one of input filenames. Check output parameters.\n");
		return CCX_COMMON_EXIT_FILE_CREATION_FAILED;
	}

	return EXIT_OK;
}
/* respond for a file GET request */
int do_http_get(struct tcp_pcb *pcb, char *req, int rlen)
{
	int BUFSIZE = 1400;
	char filename[MAX_FILENAME];
	char buf[BUFSIZE];
	int fsize, hlen, n;
	int fd;
	char *fext;
	err_t err;

	/* determine file name */
	extract_file_name(filename, req, rlen, MAX_FILENAME);

	/* respond with 404 if not present */
	if (mfs_exists_file(filename) != 1) {
		xil_printf("requested file %s not found, returning 404\r\n", filename);
		do_404(pcb, req, rlen);
		return -1;
	}

	/* respond with correct file */

	/* debug statement on UART */
        xil_printf("http GET: %s\r\n", filename);

	/* get a pointer to file extension */
	fext = get_file_extension(filename);

	fd = mfs_file_open(filename, MFS_MODE_READ);

	/* obtain file size,
	 * note that lseek with offset 0, MFS_SEEK_END does not move file pointer */
	fsize = mfs_file_lseek(fd, 0, MFS_SEEK_END);

	/* write the http headers */
	hlen = generate_http_header(buf, fext, fsize);
	if ((err = tcp_write(pcb, buf, hlen, 1)) != ERR_OK) {
		xil_printf("error (%d) writing http header to socket\r\n", err);
		xil_printf("attempted to write #bytes = %d, tcp_sndbuf = %d\r\n", hlen, tcp_sndbuf(pcb));
		xil_printf("http header = %s\r\n", buf);
		return -1;
	}

	/* now write the file */
	while (fsize) {
		int sndbuf;
		sndbuf = tcp_sndbuf(pcb);

		if (sndbuf < BUFSIZE) {
			/* not enough space in sndbuf, so send remaining bytes when there is space */
			/* this is done by storing the fd in as part of the tcp_arg, so that the sent
			   callback handler knows to send data */
			http_arg *a = (http_arg *)pcb->callback_arg;
			a->fd = fd;
			a->fsize = fsize;
			return 0;
		}

		n = mfs_file_read(fd, buf, BUFSIZE);

		if ((err = tcp_write(pcb, buf, n, 1)) != ERR_OK) {
			xil_printf("error writing file (%s) to socket, remaining unwritten bytes = %d\r\n",
					filename, fsize - n);
			xil_printf("attempted to lwip_write %d bytes, tcp write error = %d\r\n", n, err);
			break;
		}

		fsize -= n;
	}

	mfs_file_close(fd);

	return 0;
}
示例#13
0
struct lib_ccx_ctx* init_libraries(struct ccx_s_options *opt)
{
	int ret = 0;

	struct lib_ccx_ctx *ctx = malloc(sizeof(struct lib_ccx_ctx));
	if(!ctx)
		ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "init_libraries: Not enough memory allocating lib_ccx_ctx context.");
	memset(ctx, 0, sizeof(struct lib_ccx_ctx));

	if(opt->xmltv)
	{
		ctx->epg_inited = 1;
		ctx->epg_buffers = (struct PSI_buffer *)malloc(sizeof(struct PSI_buffer)*(0xfff+1));
		ctx->eit_programs = (struct EIT_program *)malloc(sizeof(struct EIT_program)*(TS_PMT_MAP_SIZE+1));
		ctx->eit_current_events = (int32_t *)malloc(sizeof(int32_t)*(TS_PMT_MAP_SIZE+1));
		ctx->ATSC_source_pg_map = (int16_t *)malloc(sizeof(int16_t)*(0xffff));
		memset(ctx->epg_buffers, 0, sizeof(struct PSI_buffer)*(0xfff+1));
		memset(ctx->eit_programs, 0, sizeof(struct EIT_program)*(TS_PMT_MAP_SIZE+1));
		memset(ctx->eit_current_events, 0, sizeof(int32_t)*(TS_PMT_MAP_SIZE+1));
		memset(ctx->ATSC_source_pg_map, 0, sizeof(int16_t)*(0xffff));
		if(!ctx->epg_buffers || !ctx->eit_programs || !ctx->eit_current_events || !ctx->ATSC_source_pg_map)
			ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "lib_ccx_ctx");
	}
	else
	{
		ctx->epg_inited = 0;
		ctx->epg_buffers = NULL;
		ctx->eit_programs = NULL;
		ctx->eit_current_events = NULL;
		ctx->ATSC_source_pg_map = NULL;
	}

	struct ccx_decoder_608_report *report_608 = malloc(sizeof(struct ccx_decoder_608_report));
	if (!report_608)
		ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "init_libraries: Not enough memory allocating report_608");
	memset(report_608, 0, sizeof(struct ccx_decoder_608_report));

	ccx_decoder_dtvcc_report *report_dtvcc = (ccx_decoder_dtvcc_report *)
			malloc(sizeof(ccx_decoder_dtvcc_report));
	if (!report_dtvcc)
		ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "init_libraries: Not enough memory allocating report_dtvcc");
	memset(report_dtvcc, 0, sizeof(ccx_decoder_dtvcc_report));

	// Initialize some constants
	ctx->screens_to_process = -1;
	ctx->current_file = -1;

	// Set logging functions for libraries
	ccx_common_logging.debug_ftn = &dbg_print;
	ccx_common_logging.debug_mask = opt->debug_mask;
	ccx_common_logging.fatal_ftn = &fatal;
	ccx_common_logging.log_ftn = &mprint;
	ccx_common_logging.gui_ftn = &activity_library_process;

	// Init shared decoder settings
	ctx->dec_global_setting = init_decoder_setting(opt);
	if (!ctx->dec_global_setting){
		free(report_dtvcc);
		return NULL;
    }

	// Need to set the 608 data for the report to the correct variable.
	ctx->freport.data_from_608 = report_608;
	ctx->dec_global_setting->settings_608->report = report_608;
	ctx->freport.data_from_708 = report_dtvcc;
	ctx->dec_global_setting->settings_dtvcc->report = report_dtvcc;
	ctx->mp4_cfg.mp4vidtrack = opt->mp4vidtrack;
	//Initialize input files
	ctx->inputfile = opt->inputfile;
	ctx->num_input_files = opt->num_input_files;

	ret = init_ctx_outbase(opt, ctx);
	if (ret < 0) {
		goto end;
	}
	ctx->extension = get_file_extension(opt->write_format);

	ctx->subs_delay = opt->subs_delay;

	ctx->pesheaderbuf = (unsigned char *) malloc (188); // Never larger anyway

	ctx->cc_to_stdout = opt->cc_to_stdout;
	ctx->pes_header_to_stdout = opt->pes_header_to_stdout;
	ctx->ignore_pts_jumps = opt->ignore_pts_jumps;

	ctx->hauppauge_mode = opt->hauppauge_mode;
	ctx->live_stream = opt->live_stream;
	ctx->binary_concat = opt->binary_concat;
	build_parity_table();

	ctx->demux_ctx = init_demuxer(ctx, &opt->demux_cfg);
	INIT_LIST_HEAD(&ctx->dec_ctx_head);
	INIT_LIST_HEAD(&ctx->enc_ctx_head);

	// Init timing
	ccx_common_timing_init(&ctx->demux_ctx->past,opt->nosync);
	ctx->multiprogram = opt->multiprogram;
	ctx->write_format = opt->write_format;
	ctx->out_interval = opt->out_interval;
	ctx->segment_on_key_frames_only = opt->segment_on_key_frames_only;
	ctx->segment_counter = 0;
	ctx->system_start_time = -1;

end:
	if (ret != EXIT_OK)
	{
		free(ctx);
		return NULL;
	}
	return ctx;
}
示例#14
0
// Hier geht die Post ab
void import_file (const gchar *import_path)
{
	TagLib_File *file;
	TagLib_Tag *tag;
	gchar *export_path;
	gchar *filename;
	gchar *artist;
	gchar *album;
	
	// Prüfen ob die Datei gültig ist
	file = taglib_file_new (import_path);
	if (file == NULL) {
		return;
	}
	
	// Prüfen ob wir Tags haben
	tag = taglib_file_tag (file);
	if (tag == NULL) {
		return;
	}
	
	// Falls Tags unvollständig sind -> Nicht importieren
	if (!check_tags (tag)) {
		gchar *text;
		text = g_strdup_printf ("Nicht importieren! (Tags unvollstaendig) -> %s", import_path);
		settings_import_messages_add (text);
		return;
	}
	
	// Dateiname holen
	filename = g_path_get_basename (import_path);
	
	// Die einzelnen Tags holen
	artist = taglib_tag_artist(tag);
	album = taglib_tag_album (tag);
	
	// Artist & Album Ordner erstellen
	create_artist_dir (artist);
	create_album_dir (album, artist);
	
	// Export Pfad bestimmen
	export_path = get_song_path (tag, get_file_extension (filename));
	
	// Prüfen, ob schon vorhanden
	if (exist_target (export_path, import_path)) {
		gchar *text;
		text = g_strdup_printf ("Überspringe: %s", filename);
		settings_import_messages_add (text);
		return;
	}
	
	// Datei kopieren
	if (!copy_file (import_path, export_path)) {
		gchar *text;
		text = g_strdup_printf ("Import fehlgeschlagen! -> %s", filename);
		settings_import_messages_add (text);
		return;
	}
	
	// File in Datenbank eintragen
	if (!register_file (export_path)) {
		gchar *text;
		text = g_strdup_printf ("Datei '%s' konnte nicht in der Datenbank registriert werden!", filename);
		settings_import_messages_add (text);
		return;
	}
	
	// Speicher wieder freigeben
	taglib_tag_free_strings ();
	taglib_file_free (file);
}
void print_universal_indent_cfg(FILE *pfile)
{
   const group_map_value *p_grp;
   const char            *p_name;

   /* Dump the header and the categories */
   fprintf(pfile, "[header]\n");

   /* Add all the categories */
   char ch = '=';
   int  idx;

   fprintf(pfile, "categories");
   for (idx = 0; idx < UG_group_count; idx++)
   {
      p_grp = get_group_name(idx);
      if (p_grp != NULL)
      {
         fprintf(pfile, "%c%s", ch, p_grp->short_desc);
         ch = '|';
      }
   }
   fprintf(pfile, "\n");

   fprintf(pfile,
           "cfgFileParameterEnding=cr\n"
           "configFilename=TechPlayers.cfg\n");


   /* Add all the recognized file extensions */
   ch  = '=';
   idx = 0;
   fprintf(pfile, "fileTypes");
   while ((p_name = get_file_extension(idx)) != NULL)
   {
      fprintf(pfile, "%c*%s", ch, p_name);
      ch = '|';
   }
   fprintf(pfile, "\n");

   /* Add the rest of the constant file header */
   fprintf(pfile,
           "indenterFileName=TechPlayers\n"
           "indenterName=TechPlayers (C, C++, C#, ObjectiveC, D, Java, Pawn, VALA)\n"
           "inputFileName=indentinput\n"
           "inputFileParameter=\"-f \"\n"
           "manual=http://TechPlayers.sourceforge.net/config.txt\n"
           "outputFileName=indentoutput\n"
           "outputFileParameter=\"-o \"\n"
           "stringparaminquotes=false\n"
           "parameterOrder=ipo\n"
           "showHelpParameter=-h\n"
           "stringparaminquotes=false\n"
           "useCfgFileParameter=\"-c \"\n"
           "version=%s\n",
           TechPlayers_VERSION);

   /* Now add each option */
   for (idx = 0; idx < UG_group_count; idx++)
   {
      p_grp = get_group_name(idx);
      if (p_grp == NULL)
      {
         continue;
      }

      for (option_list_cit it = p_grp->options.begin(); it != p_grp->options.end(); it++)
      {
         const option_map_value *option = get_option_name(*it);

         // Create a better readable name from the options name
         // by replacing '_' by a space and use some upper case characters.
         char *optionNameReadable = new char[strlen(option->name) + 1];
         strcpy(optionNameReadable, option->name);

         bool was_space = true;
         for (char *character = optionNameReadable; *character != 0; character++)
         {
            if (*character == '_')
            {
               *character = ' ';
               was_space  = true;
            }
            else if (was_space)
            {
               *character = unc_toupper(*character);
               was_space  = false;
            }
         }

         fprintf(pfile, "\n[%s]\n", optionNameReadable);
         fprintf(pfile, "Category=%d\n", idx);
         fprintf(pfile, "Description=\"<html>");

         const char *tmp = option->short_desc;
         ch = 0;

         /* Output the decription which may contain forbidden chars */
         while (*tmp != 0)
         {
            switch (*tmp)
            {
            case '<':
               fprintf(pfile, "&lt;");
               break;

            case '>':
               fprintf(pfile, "&gt;");
               break;

            case '&':
               fprintf(pfile, "&amp;");
               break;

            case '\n':
               fprintf(pfile, "<BR>");
               break;

            default:
               fputc(*tmp, pfile);
            }
            tmp++;
         }

         fprintf(pfile, "</html>\"\n");


         // Handle some options independent of their type and most by their type.
         switch (option->id)
         {
         // Indenting with tabs selector becomes a multiple selector and not only a number. Also its default enabled.
         case UO_indent_with_tabs:
            fprintf(pfile, "Enabled=true\n");
            fprintf(pfile, "EditorType=multiple\n");
            fprintf(pfile, "Choices=\"%s=0|%s=1|%s=2\"\n", option->name, option->name, option->name);
            fprintf(pfile, "ChoicesReadable=\"Spaces only|Indent with tabs, align with spaces|Indent and align with tabs\"\n");
            fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n);
            break;

         // All not specially handled options are created only dependent by their type.
         default:
            fprintf(pfile, "Enabled=false\n");
            switch (option->type)
            {
            case AT_BOOL:
               // [align_keep_tabs]
               // Category=3
               // Description=<html>Whether to keep non-indenting tabs</html>
               // Value=0
               // ValueDefault=0
               // EditorType=boolean
               // TrueFalse="align_keep_tabs=true|align_keep_tabs=false"
               fprintf(pfile, "EditorType=boolean\n");
               fprintf(pfile, "TrueFalse=%s=true|%s=false\n", option->name, option->name);
               fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n);
               break;

            case AT_IARF:
               fprintf(pfile, "EditorType=multiple\n");
               fprintf(pfile, "Choices=\"%s=ignore|%s=add|%s=remove|%s=force\"\n",
                       option->name, option->name, option->name, option->name);
               fprintf(pfile, "ChoicesReadable=\"Ignore %s|Add %s|Remove %s|Force %s\"\n",
                       optionNameReadable, optionNameReadable, optionNameReadable, optionNameReadable);
               fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n);
               // [nl_after_switch]
               // Category=4
               // Description=<html>Add or remove newline after 'switch'</html>
               // Value=3
               // ValueDefault=-1
               // Enabled=true
               // EditorType=multiple
               // Choices="nl_after_switch=ignore|nl_after_switch=add|nl_after_switch=remove|nl_after_switch=force"
               break;

            case AT_NUM:
               // [align_assign_span]
               // CallName="align_assign_span="
               // Category=3
               // Description="<html>The span for aligning on '=' in assignments (0=don't align)</html>"
               // EditorType=numeric
               // Enabled=false
               // MaxVal=300
               // MinVal=0
               // Value=0
               // ValueDefault=0
               fprintf(pfile, "EditorType=numeric\n");
               fprintf(pfile, "CallName=\"%s=\"\n", option->name);
               fprintf(pfile, "MinVal=%d\n", option->min_val);
               fprintf(pfile, "MaxVal=%d\n", option->max_val);
               fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n);
               break;

            case AT_LINE:
               // [newlines]
               // Category=0
               // Description=<html>The type of line endings</html>
               // Value=0
               // ValueDefault=-1
               // Enabled=true
               // EditorType=multiple
               // Choices="newlines=auto|newlines=lf|newlines=crlf|newlines=cr"
               fprintf(pfile, "EditorType=multiple\n");
               fprintf(pfile, "Choices=\"%s=lf|%s=crlf|%s=cr|%s=auto\"\n",
                       option->name, option->name, option->name, option->name);
               fprintf(pfile, "ChoicesReadable=\"Newlines Unix|Newlines Win|Newlines Mac|Newlines Auto\"\n");
               fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n);
               break;

            case AT_POS:
               // [pos_bool]
               // Category=5
               // Description=<html>The position of boolean operators in wrapped expressions</html>
               // Enabled=false
               // Value=0
               // ValueDefault=-1
               // EditorType=multiple
               // Choices="pos_bool=ignore|pos_bool=lead|pos_bool=trail"
               fprintf(pfile, "EditorType=multiple\n");
               fprintf(pfile, "Choices=\"%s=ignore|%s=lead|%s=lead_break|%s=lead_force|%s=trail|%s=trail_break|%s=trail_force\"\n",
                       option->name, option->name, option->name, option->name,
                       option->name, option->name, option->name);
               fprintf(pfile, "ChoicesReadable=\"Ignore %s|Lead %s|Lead Break %s|Lead Force %s|Trail %s|Trail Break %s|Trail Force %s\"\n",
                       optionNameReadable, optionNameReadable, optionNameReadable,
                       optionNameReadable, optionNameReadable, optionNameReadable,
                       optionNameReadable);
               fprintf(pfile, "ValueDefault=%d\n", cpd.settings[option->id].n);
               break;

            case AT_STRING:
               {
                  fprintf(pfile, "CallName=%s=\n", option->name);
                  fprintf(pfile, "EditorType=string\n");
                  string     val_string;
                  const char *val_str;
                  val_string = op_val_to_string(option->type, cpd.settings[option->id]);
                  val_str    = val_string.c_str();
                  fprintf(pfile, "ValueDefault=%s\n", val_str);
               }
               break;

            default:
               break;
            }
         }
         delete [] optionNameReadable;
      }
   }
}
示例#16
0
struct encoder_ctx *update_encoder_list_cinfo(struct lib_ccx_ctx *ctx, struct cap_info* cinfo)
{
	struct encoder_ctx *enc_ctx;
	unsigned int pn = 0;
	unsigned char in_format = 1;
	char *extension;


	if (ctx->write_format == CCX_OF_NULL)
		return NULL;

	if(cinfo)
	{
		pn = cinfo->program_number;
		if (cinfo->codec == CCX_CODEC_ISDB_CC)
			in_format = 3;
		else if (cinfo->codec == CCX_CODEC_TELETEXT)
			in_format = 2;
		else
			in_format = 1;
	}
	list_for_each_entry(enc_ctx, &ctx->enc_ctx_head, list, struct encoder_ctx)
	{
		if ( ctx->multiprogram == CCX_FALSE)
			return enc_ctx;

		if (enc_ctx->program_number == pn)
			return enc_ctx;
	}

	extension = get_file_extension(ccx_options.enc_cfg.write_format);
	if (!extension && ccx_options.enc_cfg.write_format != CCX_OF_CURL)
		return NULL;

	if(ctx->multiprogram == CCX_FALSE)
	{
		if(ctx->out_interval != -1)
		{
			int len;

			len = strlen(ctx->basefilename) + 10 + strlen(extension);

			freep(&ccx_options.enc_cfg.output_filename);
			ccx_options.enc_cfg.output_filename = malloc(len);

			sprintf(ccx_options.enc_cfg.output_filename, "%s_%06d%s", ctx->basefilename, ctx->segment_counter+1, extension);
		}
		if (list_empty(&ctx->enc_ctx_head))
		{
			ccx_options.enc_cfg.program_number = pn;
			ccx_options.enc_cfg.in_format = in_format;
			enc_ctx = init_encoder(&ccx_options.enc_cfg);
			if (!enc_ctx)
				return NULL;
			list_add_tail( &(enc_ctx->list), &(ctx->enc_ctx_head) );
		}
	}
	else
	{
		int len;

		len = strlen(ctx->basefilename) + 10 + strlen(extension);

		ccx_options.enc_cfg.program_number = pn;
		ccx_options.enc_cfg.output_filename = malloc(len);
		if (!ccx_options.enc_cfg.output_filename)
		{
			freep(&extension);
			return NULL;
		}

		sprintf(ccx_options.enc_cfg.output_filename, "%s_%d%s", ctx->basefilename, pn, extension);
		enc_ctx = init_encoder(&ccx_options.enc_cfg);
		if (!enc_ctx)
		{
			freep(&extension);
			freep(&ccx_options.enc_cfg.output_filename);
			return NULL;
		}

		list_add_tail( &(enc_ctx->list), &(ctx->enc_ctx_head) );
		freep(&extension);
		freep(&ccx_options.enc_cfg.output_filename);
	}
	// DVB related
	enc_ctx->prev = NULL;
	if (cinfo)
		if (cinfo->codec == CCX_CODEC_DVB)
			enc_ctx->write_previous = 0;
	freep(&extension);
	return enc_ctx;
}
示例#17
0
/* Opens a file and prepares a ftap struct.
   If "do_random" is TRUE, it opens the file twice; the second open
   allows the application to do random-access I/O without moving
   the seek offset for sequential I/O, which is used by Wireshark
   so that it can do sequential I/O to a capture file that's being
   written to as new packets arrive independently of random I/O done
   to display protocol trees for packets when they're selected. */
ftap* ftap_open_offline(const char *filename, int *err, char **err_info,
			gboolean do_random)
{
	int	fd;
	ws_statb64 statb;
	ftap	*fth;
	unsigned int	i;
	gboolean use_stdin = FALSE;
	gchar *extension;

	/* open standard input if filename is '-' */
	if (strcmp(filename, "-") == 0)
		use_stdin = TRUE;

	/* First, make sure the file is valid */
	if (use_stdin) {
		if (ws_fstat64(0, &statb) < 0) {
			*err = errno;
			return NULL;
		}
	} else {
		if (ws_stat64(filename, &statb) < 0) {
			*err = errno;
			return NULL;
		}
	}
	if (S_ISFIFO(statb.st_mode)) {
		/*
		 * Opens of FIFOs are allowed only when not opening
		 * for random access.
		 *
		 * XXX - currently, we do seeking when trying to find
		 * out the file type, so we don't actually support
		 * opening FIFOs.  However, we may eventually
		 * do buffering that allows us to do at least some
		 * file type determination even on pipes, so we
		 * allow FIFO opens and let things fail later when
		 * we try to seek.
		 */
		if (do_random) {
			*err = FTAP_ERR_RANDOM_OPEN_PIPE;
			return NULL;
		}
	} else if (S_ISDIR(statb.st_mode)) {
		/*
		 * Return different errors for "this is a directory"
		 * and "this is some random special file type", so
		 * the user can get a potentially more helpful error.
		 */
		*err = EISDIR;
		return NULL;
	} else if (! S_ISREG(statb.st_mode)) {
		*err = FTAP_ERR_NOT_REGULAR_FILE;
		return NULL;
	}

	/*
	 * We need two independent descriptors for random access, so
	 * they have different file positions.  If we're opening the
	 * standard input, we can only dup it to get additional
	 * descriptors, so we can't have two independent descriptors,
	 * and thus can't do random access.
	 */
	if (use_stdin && do_random) {
		*err = FTAP_ERR_RANDOM_OPEN_STDIN;
		return NULL;
	}

	errno = ENOMEM;
	fth = (ftap *)g_malloc0(sizeof(ftap));

	/* Open the file */
	errno = FTAP_ERR_CANT_OPEN;
	if (use_stdin) {
		/*
		 * We dup FD 0, so that we don't have to worry about
		 * a file_close of wth->fh closing the standard
		 * input of the process.
		 */
		fd = ws_dup(0);
		if (fd < 0) {
			*err = errno;
			g_free(fth);
			return NULL;
		}
#ifdef _WIN32
		if (_setmode(fd, O_BINARY) == -1) {
			/* "Shouldn't happen" */
			*err = errno;
			g_free(fth);
			return NULL;
		}
#endif
		if (!(fth->fh = file_fdopen(fd))) {
			*err = errno;
			ws_close(fd);
			g_free(fth);
			return NULL;
		}
	} else {
		if (!(fth->fh = file_open(filename))) {
			*err = errno;
			g_free(fth);
			return NULL;
		}
	}

	if (do_random) {
		if (!(fth->random_fh = file_open(filename))) {
			*err = errno;
			file_close(fth->fh);
			g_free(fth);
			return NULL;
		}
	} else
		fth->random_fh = NULL;

	/* initialization */
	fth->file_encap = FTAP_ENCAP_UNKNOWN;
	fth->subtype_sequential_close = NULL;
	fth->subtype_close = NULL;
    fth->priv = NULL;

    init_magic_number_open_routines();
	init_heuristic_open_info();
	if (fth->random_fh) {
		fth->fast_seek = g_ptr_array_new();

		file_set_random_access(fth->fh, FALSE, fth->fast_seek);
		file_set_random_access(fth->random_fh, TRUE, fth->fast_seek);
	}

	/* Try all file types that support magic numbers */
	for (i = 0; i < magic_number_open_routines_arr->len; i++) {
		/* Seek back to the beginning of the file; the open routine
		   for the previous file type may have left the file
		   position somewhere other than the beginning, and the
		   open routine for this file type will probably want
		   to start reading at the beginning.

		   Initialize the data offset while we're at it. */
		if (file_seek(fth->fh, 0, SEEK_SET, err) == -1) {
			/* I/O error - give up */
			ftap_close(fth);
			return NULL;
		}

		switch ((*magic_number_open_routines[i])(fth, err, err_info)) {

		case -1:
			/* I/O error - give up */
			ftap_close(fth);
			return NULL;

		case 0:
			/* No I/O error, but not that type of file */
			break;

		case 1:
			/* We found the file type */
			goto success;
		}
	}

	/* Does this file's name have an extension? */
	extension = get_file_extension(filename);
	if (extension != NULL) {
		/* Yes - try the heuristic types that use that extension first. */
		for (i = 0; i < heuristic_open_info_arr->len; i++) {
			/* Does this type use that extension? */
			if (heuristic_uses_extension(i, extension)) {
				/* Yes. */
				if (file_seek(fth->fh, 0, SEEK_SET, err) == -1) {
					/* I/O error - give up */
					g_free(extension);
					ftap_close(fth);
					return NULL;
				}

				switch ((*heuristic_open_info[i].open_routine)(fth,
				    err, err_info)) {

				case -1:
					/* I/O error - give up */
					g_free(extension);
					ftap_close(fth);
					return NULL;

				case 0:
					/* No I/O error, but not that type of file */
					break;

				case 1:
					/* We found the file type */
					g_free(extension);
					goto success;
				}
			}
		}

		/* Now try the ones that don't use it. */
		for (i = 0; i < heuristic_open_info_arr->len; i++) {
			/* Does this type use that extension? */
			if (!heuristic_uses_extension(i, extension)) {
				/* No. */
				if (file_seek(fth->fh, 0, SEEK_SET, err) == -1) {
					/* I/O error - give up */
					g_free(extension);
					ftap_close(fth);
					return NULL;
				}

				switch ((*heuristic_open_info[i].open_routine)(fth,
				    err, err_info)) {

				case -1:
					/* I/O error - give up */
					g_free(extension);
					ftap_close(fth);
					return NULL;

				case 0:
					/* No I/O error, but not that type of file */
					break;

				case 1:
					/* We found the file type */
					g_free(extension);
					goto success;
				}
			}
		}
		g_free(extension);
	} else {
		/* No - try all the heuristics types in order. */
		for (i = 0; i < heuristic_open_info_arr->len; i++) {
			if (file_seek(fth->fh, 0, SEEK_SET, err) == -1) {
				/* I/O error - give up */
				ftap_close(fth);
				return NULL;
			}

			switch ((*heuristic_open_info[i].open_routine)(fth,
			    err, err_info)) {

			case -1:
				/* I/O error - give up */
				ftap_close(fth);
				return NULL;

			case 0:
				/* No I/O error, but not that type of file */
				break;

			case 1:
				/* We found the file type */
				goto success;
			}
		}
	}

    /* Well, it's not one of the types of file we know about. */
	ftap_close(fth);
	*err = FTAP_ERR_FILE_UNKNOWN_FORMAT;
	return NULL;

success:
	fth->frame_buffer = (struct Buffer *)g_malloc(sizeof(struct Buffer));
	buffer_init(fth->frame_buffer, 1500);

	return fth;
}