Exemplo n.º 1
0
void external_execute(char run_cmd, ...) {
	char cmd[128];
	va_list args;
	va_start(args, run_cmd);

	switch(run_cmd){
	case COMPILER_ICARUS: { /* Execute Icarus compiler */
		string filename = string(va_arg(args, char*));
		int skip_verilog_src = va_arg(args, int);

		if(filename == "(stdio)" || skip_verilog_src) {
			/* Generate temporary file and compile that file: */
			string source_code = string(va_arg(args, char*));
			int compile_and_run = va_arg(args, int);

			/* Prepare temporary (.v) file: */
			ofstream f;
			string tmp_filename = filename == "(stdio)" ? TMP_FILE : strip_extension(filename);
			f.open((tmp_filename + ".v").c_str());
			f << source_code;
			f.close();

			/* Prepare command and build that .v file: */
			sprintf(cmd, "iverilog -o %s.o %s.v", tmp_filename.c_str(), tmp_filename.c_str());
			exec_cmd(cmd);

			if(compile_and_run) {
				sprintf(cmd, "vvp %s.o", tmp_filename.c_str());
				exec_cmd(cmd);
			}

			/* Cleanup .v temporary files: */
			remove((tmp_filename + ".v").c_str());
			temp_objfiles.push_back(tmp_filename + ".o");
		} else {
			/* Skip variadic arguments: */
			va_arg(args, char*);
			int compile_and_run = va_arg(args, int);
			/* Compile given file */
			char* output_filename = (char*)strip_extension(filename).c_str();
			sprintf(cmd, "iverilog -o %s.o %s", output_filename, filename.c_str());
			exec_cmd(cmd);

			if(compile_and_run) {
				sprintf(cmd, "vvp %s.o", output_filename);
				exec_cmd(cmd);
			}
		}

		break;
	}
Exemplo n.º 2
0
void ui_menu_image_info::image_info_astring(running_machine &machine, astring &string)
{
	string.printf("%s\n\n", machine.system().description);

#if 0
	if (mess_ram_size > 0)
	{
		char buf2[RAM_STRING_BUFLEN];
		string.catprintf("RAM: %s\n\n", ram_string(buf2, mess_ram_size));
	}
#endif

	image_interface_iterator iter(machine.root_device());
	for (device_image_interface *image = iter.first(); image != NULL; image = iter.next())
	{
		const char *name = image->filename();
		if (name != NULL)
		{
			const char *base_filename;
			const char *info;
			char *base_filename_noextension;

			base_filename = image->basename();
			base_filename_noextension = strip_extension(base_filename);

			// display device type and filename
			string.catprintf("%s: %s\n", image->device().name(), base_filename);

			// display long filename, if present and doesn't correspond to name
			info = image->longname();
			if (info && (!base_filename_noextension || core_stricmp(info, base_filename_noextension)))
				string.catprintf("%s\n", info);

			// display manufacturer, if available
			info = image->manufacturer();
			if (info != NULL)
			{
				string.catprintf("%s", info);
				info = stripspace(image->year());
				if (info && *info)
					string.catprintf(", %s", info);
				string.catprintf("\n");
			}

			// display supported information, if available
			switch(image->supported()) {
				case SOFTWARE_SUPPORTED_NO : string.catprintf("Not supported\n"); break;
				case SOFTWARE_SUPPORTED_PARTIAL : string.catprintf("Partially supported\n"); break;
				default : break;
			}

			if (base_filename_noextension != NULL)
				free(base_filename_noextension);
		}
		else
		{
			string.catprintf("%s: ---\n", image->device().name());
		}
	}
}
Exemplo n.º 3
0
/**
 * cinnamon_app_system_lookup_desktop_wmclass:
 * @system: a #CinnamonAppSystem
 * @wmclass: (allow-none): A WM_CLASS value
 *
 * Find a valid application whose .desktop file, without the extension
 * and properly canonicalized, matches @wmclass.
 *
 * Returns: (transfer none): A #CinnamonApp for @wmclass
 */
CinnamonApp *
cinnamon_app_system_lookup_desktop_wmclass (CinnamonAppSystem *system,
                                            const char        *wmclass)
{
  char *canonicalized;
  char *desktop_file;
  char *stripped_name;
  CinnamonApp *app;

  if (wmclass == NULL)
    return NULL;

  canonicalized = g_ascii_strdown (wmclass, -1);

  stripped_name = strip_extension(canonicalized);

  /* This handles "Fedora Eclipse", probably others.
   * Note g_strdelimit is modify-in-place. */
  g_strdelimit (stripped_name, " ", '-');

  desktop_file = g_strconcat (stripped_name, ".desktop", NULL);

  app = cinnamon_app_system_lookup_heuristic_basename (system, desktop_file);

  g_free (canonicalized);
  g_free (stripped_name);
  g_free (desktop_file);

  return app;
}
Exemplo n.º 4
0
astring *image_info_astring(running_machine *machine, astring *string)
{
	device_image_interface *image = NULL;

	astring_printf(string, "%s\n\n", machine->gamedrv->description);

#if 0
	if (mess_ram_size > 0)
	{
		char buf2[RAM_STRING_BUFLEN];
		astring_catprintf(string, "RAM: %s\n\n", ram_string(buf2, mess_ram_size));
	}
#endif

	for (bool gotone = machine->m_devicelist.first(image); gotone; gotone = image->next(image))
	{
		const char *name = image->filename();
		if (name != NULL)
		{
			const char *base_filename;
			const char *info;
			char *base_filename_noextension;

			base_filename = image->basename();
			base_filename_noextension = strip_extension(base_filename);

			/* display device type and filename */
			astring_catprintf(string, "%s: %s\n", image->image_config().devconfig().name(), base_filename);

			/* display long filename, if present and doesn't correspond to name */
			info = image->longname();
			if (info && (!base_filename_noextension || mame_stricmp(info, base_filename_noextension)))
				astring_catprintf(string, "%s\n", info);

			/* display manufacturer, if available */
			info = image->manufacturer();
			if (info != NULL)
			{
				astring_catprintf(string, "%s", info);
				info = stripspace(image->year());
				if (info && *info)
					astring_catprintf(string, ", %s", info);
				astring_catprintf(string,"\n");
			}

			/* display playable information, if available */
			info = image->playable();
			if (info != NULL)
				astring_catprintf(string, "%s\n", info);

			if (base_filename_noextension != NULL)
				free(base_filename_noextension);
		}
		else
		{
			astring_catprintf(string, "%s: ---\n", image->image_config().devconfig().name());
		}
	}
	return string;
}
Exemplo n.º 5
0
Arquivo: git.c Projeto: benpeart/git
static void handle_builtin(int argc, const char **argv)
{
	struct argv_array args = ARGV_ARRAY_INIT;
	const char *cmd;
	struct cmd_struct *builtin;

	strip_extension(argv);
	cmd = argv[0];

	/* Turn "git cmd --help" into "git help --exclude-guides cmd" */
	if (argc > 1 && !strcmp(argv[1], "--help")) {
		int i;

		argv[1] = argv[0];
		argv[0] = cmd = "help";

		for (i = 0; i < argc; i++) {
			argv_array_push(&args, argv[i]);
			if (!i)
				argv_array_push(&args, "--exclude-guides");
		}

		argc++;
		argv = args.argv;
	}

	builtin = get_builtin(cmd);
	if (builtin)
		exit(run_builtin(builtin, argc, argv));
	argv_array_clear(&args);
}
Exemplo n.º 6
0
char* replace_extension(char *filename, char *ext)
{
    char *base = strip_extension(filename);
    char *newname = malloc(strlen(base) + strlen(ext) + 1);
    strcpy(newname, base);
    strcat(newname, ext);
    return newname;
}
Exemplo n.º 7
0
static const char* tree_get_filename(int selected_item, void *data,
                                     char *buffer, size_t buffer_len)
{
    struct tree_context * local_tc=(struct tree_context *)data;
    char *name;
    int attr=0;
    bool stripit = false;
#ifdef HAVE_TAGCACHE
    bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;

    if (id3db)
    {
        return tagtree_get_entry(&tc, selected_item)->name;
    }
    else 
#endif
    {
        struct entry* dc = local_tc->dircache;
        struct entry* e = &dc[selected_item];
        name = e->name;
        attr = e->attr;
    }
    
    if(!(attr & ATTR_DIRECTORY))
    {
        switch(global_settings.show_filename_ext)
        {
            case 0:
                /* show file extension: off */
                stripit = true;
                break;
            case 1:
                /* show file extension: on */
                break;
            case 2:
                /* show file extension: only unknown types */
                stripit = filetype_supported(attr);
                break;
            case 3:
            default:
                /* show file extension: only when viewing all */
                stripit = (*(local_tc->dirfilter) != SHOW_ID3DB) &&
                          (*(local_tc->dirfilter) != SHOW_ALL);
                break;
        }
    }

    if(stripit)
    {
        return(strip_extension(buffer, buffer_len, name));
    }
    return(name);
}
Exemplo n.º 8
0
static mame_file_error open_battery_file(mess_image *image, UINT32 openflags, mame_file **file)
{
	mame_file_error filerr;
	char *basename_noext;
	char *fname;

	basename_noext = strip_extension(image_basename(image));
	if (!basename_noext)
		return FILERR_OUT_OF_MEMORY;
	fname = assemble_4_strings(Machine->gamedrv->name, PATH_SEPARATOR, basename_noext, ".nv");
	filerr = mame_fopen(SEARCHPATH_NVRAM, fname, openflags, file);
	free(fname);
	free(basename_noext);
	return filerr;
}
Exemplo n.º 9
0
Arquivo: git.c Projeto: felipec/git
static void handle_builtin(int argc, const char **argv)
{
	const char *cmd;
	struct cmd_struct *builtin;

	strip_extension(argv);
	cmd = argv[0];

	/* Turn "git cmd --help" into "git help cmd" */
	if (argc > 1 && !strcmp(argv[1], "--help")) {
		argv[1] = argv[0];
		argv[0] = cmd = "help";
	}

	builtin = get_builtin(cmd);
	if (builtin)
		exit(run_builtin(builtin, argc, argv));
}
Exemplo n.º 10
0
static char*
format_name_for_display (NautilusCustomizationData *data, const char* name)
{
	char *formatted_str, *mapped_name;

	if (!eel_strcmp(name, RESET_IMAGE_NAME)) {
		return g_strdup (_("Reset"));
	}

	/* map file names to display names using the mappings defined in the hash table */
	
	formatted_str = strip_extension (name);
	if (data->name_map_hash != NULL) {
		mapped_name = g_hash_table_lookup (data->name_map_hash, formatted_str);
		if (mapped_name) {
			g_free (formatted_str);
			formatted_str = g_strdup (mapped_name);
		}	
	}
			
	return formatted_str;	
}
/**
 * get_app_from_window_wmclass:
 *
 * Looks only at the given window, and attempts to determine
 * an application based on WM_CLASS.  If one can't be determined,
 * return %NULL.
 *
 * Return value: (transfer full): A newly-referenced #CinnamonApp, or %NULL
 */
static CinnamonApp *
get_app_from_window_wmclass (MetaWindow  *window)
{
  CinnamonApp *app;
  CinnamonAppSystem *appsys;
  char *wmclass;
  char *with_desktop;

  appsys = cinnamon_app_system_get_default ();
  wmclass = strip_extension(get_appid_from_window (window));

  if (!wmclass)
    return NULL;

  with_desktop = g_strjoin (NULL, wmclass, ".desktop", NULL);
  g_free (wmclass);

  app = cinnamon_app_system_lookup_heuristic_basename (appsys, with_desktop);
  if (app != NULL)
    g_object_ref (app);
  g_free (with_desktop);

  return app;
}
Exemplo n.º 12
0
void
scan_itunes_itml(const char *file, time_t mtime, int dir_id)
{
  struct playlist_info *pli;
  struct stat sb;
  char buf[PATH_MAX];
  char *itml_xml;
  plist_t itml;
  plist_t node;
  int fd;
  int ret;

  // This is special playlist that is disabled and only used for saving a timestamp
  pli = db_pl_fetch_bytitlepath(file, file);
  if (pli)
    {
      // mtime == db_timestamp is also treated as a modification because some editors do
      // stuff like 1) close the file with no changes (leading us to update db_timestamp),
      // 2) copy over a modified version from a tmp file (which may result in a mtime that
      // is equal to the newly updated db_timestamp)
      if (mtime && (pli->db_timestamp > mtime))
	{
	  DPRINTF(E_LOG, L_SCAN, "Unchanged iTunes XML found, not processing '%s'\n", file);

	  // TODO Protect the radio stations from purge after scan
	  db_pl_ping_bymatch(file, 0);
	  free_pli(pli, 0);
	  return;
	}

      DPRINTF(E_LOG, L_SCAN, "Modified iTunes XML found, processing '%s'\n", file);

      // Clear out everything, we will recreate
      db_pl_delete_bypath(file);
      free_pli(pli, 0);
    }
  else
    {
      DPRINTF(E_LOG, L_SCAN, "New iTunes XML found, processing: '%s'\n", file);
    }

  CHECK_NULL(L_SCAN, pli = calloc(1, sizeof(struct playlist_info)));

  pli->type = PL_PLAIN;
  pli->title = strdup(file);
  pli->path = strdup(file);
  snprintf(buf, sizeof(buf), "/file:%s", file);
  pli->virtual_path = strip_extension(buf);
  pli->directory_id = dir_id;

  ret = db_pl_add(pli, (int *)&pli->id);
  if (ret < 0)
    {
      DPRINTF(E_LOG, L_SCAN, "Error adding iTunes XML meta playlist '%s'\n", file);

      free_pli(pli, 0);
      return;
    }

  // Disable, only used for saving timestamp
  db_pl_disable_bypath(file, STRIP_NONE, 0);

  free_pli(pli, 0);

  fd = open(file, O_RDONLY);
  if (fd < 0)
    {
      DPRINTF(E_LOG, L_SCAN, "Could not open iTunes library '%s': %s\n", file, strerror(errno));

      return;
    }

  ret = fstat(fd, &sb);
  if (ret < 0)
    {
      DPRINTF(E_LOG, L_SCAN, "Could not stat iTunes library '%s': %s\n", file, strerror(errno));

      close(fd);
      return;
    }

  itml_xml = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
  if (itml_xml == MAP_FAILED)
    {
      DPRINTF(E_LOG, L_SCAN, "Could not map iTunes library '%s': %s\n", file, strerror(errno));

      close(fd);
      return;
    }

  itml = NULL;
  plist_from_xml(itml_xml, sb.st_size, &itml);

  ret = munmap(itml_xml, sb.st_size);
  if (ret < 0)
    DPRINTF(E_LOG, L_SCAN, "Could not unmap iTunes library '%s': %s\n", file, strerror(errno));

  close(fd);

  if (!itml)
    {
      DPRINTF(E_LOG, L_SCAN, "iTunes XML playlist '%s' failed to parse\n", file);

      return;
    }

  if (plist_get_node_type(itml) != PLIST_DICT)
    {
      DPRINTF(E_LOG, L_SCAN, "Malformed iTunes XML playlist '%s'\n", file);

      plist_free(itml);
      return;
    }

  /* Meta data */
  ret = check_meta(itml);
  if (ret < 0)
    {
      plist_free(itml);
      return;
    }

  /* Tracks */
  ret = get_dictval_dict_from_key(itml, "Tracks", &node);
  if (ret < 0)
    {
      DPRINTF(E_LOG, L_SCAN, "Could not find Tracks dict in '%s'\n", file);

      plist_free(itml);
      return;
    }

  id_map = calloc(ID_MAP_SIZE, sizeof(struct itml_to_db_map *));
  if (!id_map)
    {
      DPRINTF(E_FATAL, L_SCAN, "iTunes library parser could not allocate ID map\n");

      plist_free(itml);
      return;
    }

  ret = process_tracks(node);
  if (ret <= 0)
    {
      DPRINTF(E_LOG, L_SCAN, "No tracks loaded from iTunes XML '%s'\n", file);

      id_map_free();
      plist_free(itml);
      return;
    }

  DPRINTF(E_LOG, L_SCAN, "Loaded %d tracks from iTunes XML '%s'\n", ret, file);

  /* Playlists */
  ret = get_dictval_array_from_key(itml, "Playlists", &node);
  if (ret < 0)
    {
      DPRINTF(E_LOG, L_SCAN, "Could not find Playlists dict in '%s'\n", file);

      id_map_free();
      plist_free(itml);
      return;
    }

  process_pls(node, file);

  id_map_free();
  plist_free(itml);
}
Exemplo n.º 13
0
int ui_sprintf_image_info(char *buf)
{
    char *dst = buf;
    const struct IODevice *dev;
    int id;

    dst += sprintf(dst, "%s\n\n", Machine->gamedrv->description);

    if (options.ram)
    {
        char buf2[RAM_STRING_BUFLEN];
        dst += sprintf(dst, "RAM: %s\n\n", ram_string(buf2, options.ram));
    }

    for (dev = Machine->devices; dev->type < IO_COUNT; dev++)
    {
        for (id = 0; id < dev->count; id++)
        {
            mess_image *img = image_from_device_and_index(dev, id);
            const char *name = image_filename(img);
            if( name )
            {
                const char *base_filename;
                const char *info;
                char *base_filename_noextension;

                base_filename = image_basename(img);
                base_filename_noextension = strip_extension((char *) base_filename);

                /* display device type and filename */
                dst += sprintf(dst,"%s: %s\n", image_typename_id(img), base_filename);

                /* display long filename, if present and doesn't correspond to name */
                info = image_longname(img);
                if (info && (!base_filename_noextension || mame_stricmp(info, base_filename_noextension)))
                    dst += sprintf(dst,"%s\n", info);

                /* display manufacturer, if available */
                info = image_manufacturer(img);
                if (info)
                {
                    dst += sprintf(dst,"%s", info);
                    info = stripspace(image_year(img));
                    if (info && *info)
                        dst += sprintf(dst,", %s", info);
                    dst += sprintf(dst,"\n");
                }

                /* display playable information, if available */
                info = image_playable(img);
                if (info)
                    dst += sprintf(dst,"%s\n", info);

                if (base_filename_noextension)
                    free(base_filename_noextension);
            }
            else
            {
                dst += sprintf(dst,"%s: ---\n", image_typename_id(img));
            }
        }
    }
    return dst - buf;
}
Exemplo n.º 14
0
int main(int argc, char **argv)
{
    int i;
    const char *filename;
    const char *indexname = NULL;
    char name[256], *p;
    FILE *f;

    printf("/* This file was generated automatically by cptoqe */\n");

    printf("\n" "/*"
           "\n" " * More Charsets and Tables for QEmacs"
           "\n" " *"
           "\n" " * Copyright (c) 2002 Fabrice Bellard."
           "\n" " * Copyright (c) 2002-2008 Charlie Gordon."
           "\n" " *"
           "\n" " * This library is free software; you can redistribute it and/or"
           "\n" " * modify it under the terms of the GNU Lesser General Public"
           "\n" " * License as published by the Free Software Foundation; either"
           "\n" " * version 2 of the License, or (at your option) any later version."
           "\n" " *"
           "\n" " * This library is distributed in the hope that it will be useful,"
           "\n" " * but WITHOUT ANY WARRANTY; without even the implied warranty of"
           "\n" " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU"
           "\n" " * Lesser General Public License for more details."
           "\n" " *"
           "\n" " * You should have received a copy of the GNU Lesser General Public"
           "\n" " * License along with this library; if not, write to the Free Software"
           "\n" " * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA"
           "\n" " */"
           "\n" ""
           "\n" "#include \"qe.h\""
           "\n" "");

    add_init("int charset_more_init(void)\n{\n");

    for (i = 1; i < argc; i++) {
        filename = argv[i];

        if (!strcmp(filename, "-i")) {
            if (++i >= argc) {
                fprintf(stderr, "cptoqe: missing index name after -i\n");
                exit(2);
            }
            indexname = argv[i];
            continue;
        }

        pstrcpy(name, sizeof(name), get_basename(filename));
        strip_extension(name);
        for (p = name; *p; p++) {
            if (*p == '_')
                *p = '-';
            else
                *p = tolower((unsigned char)*p);
        }

        f = open_index(indexname, name);
        if (!f) {
            f = fopen(filename, "r");
            if (!f) {
                perror(filename);
                exit(1);
            }
        }

        handle_cp(f, name, filename);

        fclose(f);
    }

    add_init("\n    return 0;\n}\n\n"
             "qe_module_init(charset_more_init);\n");

    printf("%s", module_init);

    return 0;
}
Exemplo n.º 15
0
int do_file_sorting(dataptr dz)
{
	int exit_status;
	int  n;
	int a_srate = 0;
	double sum;
	int  infilecnt = dz->all_words-1;
	int  fileno = 0, namestoresize = 0;
	char *filename = dz->wordstor[infilecnt];	/* name of input list file */
	char *monofile=NULL,     *stereofile = NULL, *analfile = NULL, *quadfile = NULL;
	char *pitchfile = NULL,  *transfile = NULL,  *formantfile = NULL;
	char *envfile = NULL,    *otherfile  = NULL, *namestore  = NULL;
	int  *posstore   = NULL;
	int  *lcnt       = NULL;
	char ***lstore   = NULL;
 	double *lenstore = NULL;
 	double *sortlens = NULL;
	char *file48 = ENDOFSTR, *file44 = ENDOFSTR, *file32 = ENDOFSTR;
	char *file24 = ENDOFSTR, *file22 = ENDOFSTR, *file16 = ENDOFSTR;
	int is_file48=FALSE, is_file44=FALSE, is_file32=FALSE, is_file24=FALSE, is_file22=FALSE, is_file16=FALSE;
	int is_mono_list=FALSE,  is_stereo_list=FALSE,is_quad_list=FALSE, is_anal_list=FALSE,is_pitch_list=FALSE;
	int is_trans_list=FALSE, is_fmnt_list=FALSE,  is_env_list=FALSE, is_other_list=FALSE;
	FILE *fp48 = NULL, *fp44 = NULL, *fp32 = NULL, *fp24 = NULL, *fp22 = NULL, *fp16 = NULL, 
	    *fpm = NULL, *fps = NULL, *fpa = NULL, *fpp = NULL, *fpt = NULL, *fpf = NULL, *fpe = NULL, *fpo = NULL, *fpq = NULL;
	char *p;
	int done_errmsg = 0;

	switch(dz->mode) {
	case(BY_DURATION):	
	case(BY_LOG_DUR):	
		if((lcnt = (int *)malloc((dz->iparam[SORT_LENCNT]+1) * sizeof(int)))==NULL) {
			sprintf(errstr,"INSUFFICIENT MEMORY for lcnt store.\n");
			return(MEMORY_ERROR);
		}
		if((sortlens  = (double *)malloc(dz->iparam[SORT_LENCNT] * sizeof(double)))==NULL) {
			sprintf(errstr,"INSUFFICIENT MEMORY for lens store.\n");
			return(MEMORY_ERROR);
		}
		sum = dz->param[SORT_SMALL];
		for(n=0;n<dz->iparam[SORT_LENCNT];n++) {
			lcnt[n] = 0;				
			sortlens[n] = sum;
			if(dz->mode==BY_LOG_DUR)
				sum *= dz->param[SORT_STEP];
			else
				sum += dz->param[SORT_STEP];
		}
		lcnt[dz->iparam[SORT_LENCNT]] = 0;
		sortlens[dz->iparam[SORT_LENCNT]-1] = dz->param[SORT_LARGE];
		dz->iparam[SORT_LENCNT]++;
		/* fall thro */
	case(IN_DUR_ORDER):	
	   	if((lstore = (char ***)malloc((dz->iparam[SORT_LENCNT]+1) * sizeof(char **)))==NULL) {
			sprintf(errstr,"INSUFFICIENT MEMORY for length store.\n");
			return(MEMORY_ERROR);
		}
		for(n=0;n<dz->iparam[SORT_LENCNT]+1;n++) {
// AVOID realloc
			if((lstore[n] = (char **)malloc(infilecnt * sizeof(char *)))==NULL) {
				sprintf(errstr,"INSUFFICIENT MEMORY for length store %d.\n",n+1);
				return(MEMORY_ERROR);
			}
		}
		break;
	}
	strip_extension(filename);
	if(sloom && (dz->mode == BY_FILETYPE || dz->mode == BY_SRATE)) {
		p = filename + strlen(filename) - 1;		/* Strip trailing zero from generic tempfilename */
		*p = ENDOFSTR;
	}
	for(n=0;n<infilecnt;n++) {
		if(!strcmp(dz->wordstor[infilecnt],dz->wordstor[n])) {
			sprintf(errstr,"The name of the listfile cannot be included in the listing!!\n");
			return(DATA_ERROR);
		}
	}
// AVOID realloc
	for(n=0;n<infilecnt;n++)
		namestoresize += strlen(dz->wordstor[n]) + 1;
	if((namestore = (char *)malloc(namestoresize * sizeof(char)))==NULL) {
		sprintf(errstr,"INSUFFICIENT MEMORY for name store.\n");
		return(MEMORY_ERROR);
	}
	namestoresize = 0;
	for(n=0;n<infilecnt;n++) {
	    if((dz->ifd[0] = sndopenEx(dz->wordstor[n],0,CDP_OPEN_RDONLY)) < 0) 	{
			if(dz->mode!=BY_FILETYPE)  {
				if(!done_errmsg) {
					sprintf(errstr,"Some files are NOT soundfiles.\n");
					print_outmessage_flush(errstr);
					done_errmsg = 1;
				}
			}
			dz->ifd[0] = -1;
			continue;
		} else if((dz->mode!=BY_FILETYPE) && filename_extension_is_not_sound(dz->wordstor[n])) {
			if(!done_errmsg) {
				sprintf(errstr,"Some files are NOT soundfiles.\n");
				print_outmessage_flush(errstr);
				done_errmsg = 1;
			}
			continue;
		}
		switch(dz->mode) {
		case(BY_SRATE):		
			if((exit_status = do_srates(filename,dz->wordstor[n],&file48,&file44,&file32,&file24,&file22,&file16,
			&is_file48,&is_file44,&is_file32,&is_file24,&is_file22,&is_file16,
			&fp48,&fp44,&fp32,&fp24,&fp22,&fp16,dz))<0)
				return(exit_status);
			break;
		case(BY_DURATION):	
		case(BY_LOG_DUR):	
			if((exit_status = do_lenths(filename,dz->wordstor[n],&namestore,lstore,&namestoresize,lcnt,sortlens,dz))<0)
				return(exit_status);
			break;
		case(IN_DUR_ORDER):	
			if((exit_status = do_order
			(filename,dz->wordstor[n],&namestore,&lenstore,&posstore,&lstore,&fileno,&namestoresize,dz))<0)
				return(exit_status);
			break;
		case(BY_FILETYPE):	
			if((exit_status = do_types(filename,dz->wordstor[n],
			&monofile,&stereofile,&quadfile,&analfile,&pitchfile,&transfile,&formantfile,&envfile,&otherfile,
			&is_mono_list,&is_stereo_list,&is_quad_list,&is_anal_list,
			&is_pitch_list,&is_trans_list,&is_fmnt_list,&is_env_list,&is_other_list,
			&fpm,&fps,&fpa,&fpp,&fpt,&fpf,&fpe,&fpo,&fpq,dz))<0)
				return(exit_status);
			break;
		case(FIND_ROGUES):	
			do_rogues(dz->wordstor[n],&a_srate,dz);
			break;
		}

		if(dz->ifd[0]!=-1 && sndcloseEx(dz->ifd[0])<0)
			fprintf(stdout,"WARNING: Failed to close sndfile %s.\n",dz->wordstor[n]);
		dz->ifd[0] = -1;
	}
	switch(dz->mode) {
	case(BY_LOG_DUR):
	case(BY_DURATION):	
		if((exit_status = output_lenths(filename,&otherfile,lstore,sortlens,lcnt,dz))<0)
			return(exit_status);
		break;
 	case(BY_SRATE):		
 		output_srates(is_file48,is_file44,is_file32,is_file24,is_file22,is_file16,
		file48,	file44,file32,file24,file22,file16);						
		break;
 	case(IN_DUR_ORDER):	
 		if((exit_status = output_order(filename,&otherfile,posstore,lenstore,lstore,fileno,dz))<0)
			return(exit_status);
 		break;
	case(BY_FILETYPE):	
		output_types(filename,is_mono_list,is_stereo_list,is_quad_list,
		is_anal_list,is_pitch_list,is_trans_list,is_fmnt_list,is_env_list,
		is_other_list,monofile,stereofile,quadfile,analfile,pitchfile,
		transfile,formantfile,envfile,otherfile);							
		break;

	}
	fflush(stdout);
	return(FINISHED);
}
Exemplo n.º 16
0
void run(std::string tree_filename, std::string fasta_filename, std::string model_name) {
  Model Mod;                 // The model
  Counts data;               // the counts
  Parameters Par;            // the parameters
  std::vector<double> br;    // branch lengths
  double eps = 1e-8;         // The threshold for the EM algorithm.

  Parameters Parsim;         // used for simulating data.
  std::vector<double> brsim; // branch lengths of simulated data.

  std::vector<std::vector<double> > Cov;  // Covariance matrix
  std::vector<double> variances;          // The variances


  bool simulate;
  bool nonident;
  std::string parameters_filename;
  std::string covariances_filename;

  // initialize random number generator with time(0).
  random_initialize();

  parameters_filename = strip_extension(fasta_filename) + ".dat";
  covariances_filename = strip_extension(fasta_filename) + ".cov";

  // Creates the pointers to the model-specific functions.
  Mod = create_model(model_name);
  std::cout << "Model: " << Mod.name << std::endl;

  // Reads the tree.
  Tree T = read_tree(tree_filename);

  // Prints the Tree
  std::cout << "Tree:" << std::endl;
  print_tree(T);

  // Check for possible nonidentifiability issues.
  nonident = nonident_warning(T);

  // Initialize the parameters for simulation of K81 data for testing
  Parsim = create_parameters(T);

  if (fasta_filename == ":test") {      // if fasta file is :test generate random data.
    simulate = true;

    // Warn
    std::cout << "WARNING: Using simulated data " << std::endl << std::endl;

    // Generate random parameters
    random_parameters_length(T, Mod, Parsim);

    // Simulate the data
    data = random_fake_counts(T, 1000, Parsim);

    // Prints branch-lengths for future check.
    branch_lengths(Parsim, brsim);
    std::cout << "Simulated branch lengths:" << std::endl;
    print_vector(brsim);

  } else {                                  // otherwise read the data
    simulate = false;

    // Read the counts.
    std::cout << "Reading fasta file:" << std::endl;
    read_counts(T, data, fasta_filename);
    add_pseudocounts(0.01, data);
    std::cout << std::endl;
  }

  // Check whether the data and the tree match.
  if (T.nalpha != data.nalpha || T.nleaves != data.nspecies) {
    throw std::invalid_argument("The order of the sequences or their number and the phylogenetic tree do not match.");
  }

  //Par = create_parameters(T);
  //print_parameters(Par);
  //print_vector(Par.r);

  //clock_t
  long start_time, end_time;

  // Runs the EM algorithm. Par is used as initial parameters.
  // After execution, Par contains the MLE computed by the algorithm.

 // for local max over multiple iterations
  Parameters Parmax = Par;
  Model Modmax = Mod;

  float likelL = 0.0;
  float likelMax = -1000000.0;
  float timerec;
  float timemax;

  int outfiles; //whether to save output
  std::cout << "Starting the EM algorithm: " << std::endl;

  int s;
  int S = 0; //count of cases with neg branches

  int iter;
  int iterMax;

  for (int it_runs = 0; it_runs < 10; it_runs++) {
      Par = create_parameters(T);
      Mod = create_model(model_name);
      std::cout << it_runs << ", " ;

      start_time = clock();

      std::tie(likelL, iter) = EMalgorithm(T, Mod, Par, data, eps);

      end_time = clock();
      //print_parameters(Par);

      // Choses the best permutation.
      guess_permutation(T, Mod, Par);

      branch_lengths(Par, br);

      //print_vector(br);
      s = find_negative(br);
      S +=s;
      timerec = ((float)end_time - start_time) / CLOCKS_PER_SEC;

      //assign the 1st iter time value, inc ase it's the best
      if (it_runs == 0){
        timemax = timerec;
        iterMax = iter;
      }

      if (likelL > likelMax){
        Parmax = Par;
        Modmax = Mod;
        timemax = timerec;
        likelMax = likelL;
        iterMax = iter;
      }

  }


  // If parameters are not identifiable, the computation of the covariance matrix will
  // fail as the Fisher info matrix will not be invertible.
  if (!nonident) {
    // Compute the covariance matrix using observed Fisher.
    full_MLE_observed_covariance_matrix(T, Modmax, Parmax, data, Cov);
    variances.resize(Cov.size());
    for(unsigned int i=0; i < Cov.size(); i++) {
      variances[i] = Cov[i][i];
    }

    // OUTPUT Save the sigmas into a file
    //save_sigmas_to(covariances_filename, Cov);
  }

  std::cout << std::endl;
  std::cout << "Finished." << std::endl;
  std::cout << "Likelihood: " << log_likelihood(T, Parmax, data) << std::endl ;
  std::cout << "Time: " << timemax << std::endl << std::endl;
  std::cout << "negative branches: "  << S << std::endl;
  std::cout << "Iter: "  << iterMax << std::endl;

  //std::cout << "Branch lengths: " << std::endl;
  //print_vector(br);
  outfiles = 0;
  if (!nonident && outfiles) {
    std::cout << "Parameter variances: " << std::endl;
    print_vector(variances);
  }

  std::cout << "Newick Tree:" << std::endl;
  print_newick_tree(T, br);

  // if is a simulation, print the L2 distance !
  if (simulate) {
    std::cout << "L2 distance:   " << parameters_distance(Par, Parsim) << std::endl;
    std::cout << "KL divergence: " << KL_divergence(T, Par, Parsim) << std::endl;
    std::cout << std::endl;
  }

  // if it is not a simulation, store the parameters in a file !
  if (!simulate && outfiles) {
    std::fstream st;
    st.precision(15);
    st.setf(std::ios::fixed,std::ios::floatfield);
    st.open(parameters_filename.c_str(), std::ios::out);
    print_parameters(Par, st);
  }
}
Exemplo n.º 17
0
void
scan_playlist(const char *file, time_t mtime, int dir_id)
{
  FILE *fp;
  struct media_file_info mfi;
  struct playlist_info *pli;
  struct stat sb;
  char buf[PATH_MAX];
  char *path;
  const char *filename;
  char *ptr;
  size_t len;
  int extinf;
  int pl_id;
  int pl_format;
  int ntracks;
  int nadded;
  int ret;

  ptr = strrchr(file, '.');
  if (!ptr)
    return;

  if (strcasecmp(ptr, ".m3u") == 0)
    pl_format = PLAYLIST_M3U;
  else if (strcasecmp(ptr, ".pls") == 0)
    pl_format = PLAYLIST_PLS;
  else
    return;

  filename = filename_from_path(file);

  /* Fetch or create playlist */
  pli = db_pl_fetch_bypath(file);
  if (pli)
    {
      db_pl_ping(pli->id);

      if (mtime && (pli->db_timestamp >= mtime))
	{
	  DPRINTF(E_LOG, L_SCAN, "Unchanged playlist found, not processing '%s'\n", file);

	  // Protect this playlist's radio stations from purge after scan
	  db_pl_ping_items_bymatch("http://", pli->id);
	  free_pli(pli, 0);
	  return;
	}

      DPRINTF(E_LOG, L_SCAN, "Modified playlist found, processing '%s'\n", file);

      pl_id = pli->id;
      db_pl_clear_items(pl_id);
    }
  else
    {
      DPRINTF(E_LOG, L_SCAN, "New playlist found, processing '%s'\n", file);

      CHECK_NULL(L_SCAN, pli = calloc(1, sizeof(struct playlist_info)));

      pli->type = PL_PLAIN;

      /* Get only the basename, to be used as the playlist title */
      pli->title = strip_extension(filename);

      pli->path = strdup(file);
      snprintf(buf, sizeof(buf), "/file:%s", file);
      pli->virtual_path = strip_extension(buf);

      pli->directory_id = dir_id;

      ret = db_pl_add(pli, &pl_id);
      if (ret < 0)
	{
	  DPRINTF(E_LOG, L_SCAN, "Error adding playlist '%s'\n", file);

	  free_pli(pli, 0);
	  return;
	}

      DPRINTF(E_INFO, L_SCAN, "Added new playlist as id %d\n", pl_id);
    }

  free_pli(pli, 0);

  ret = stat(file, &sb);
  if (ret < 0)
    {
      DPRINTF(E_LOG, L_SCAN, "Could not stat() '%s': %s\n", file, strerror(errno));
      return;
    }

  fp = fopen(file, "r");
  if (!fp)
    {
      DPRINTF(E_LOG, L_SCAN, "Could not open playlist '%s': %s\n", file, strerror(errno));
      return;
    }

  db_transaction_begin();

  extinf = 0;
  memset(&mfi, 0, sizeof(struct media_file_info));
  ntracks = 0;
  nadded = 0;

  while (fgets(buf, sizeof(buf), fp) != NULL)
    {
      len = strlen(buf);

      /* rtrim and check that length is sane (ignore blank lines) */
      while ((len > 0) && isspace(buf[len - 1]))
	{
	  len--;
	  buf[len] = '\0';
	}
      if (len < 1)
	continue;

      /* Saves metadata in mfi if EXTINF metadata line */
      if ((pl_format == PLAYLIST_M3U) && extinf_get(buf, &mfi, &extinf))
	continue;

      /* For pls files we are only interested in the part after the FileX= entry */
      path = NULL;
      if ((pl_format == PLAYLIST_PLS) && (strncasecmp(buf, "file", strlen("file")) == 0))
	path = strchr(buf, '=') + 1;
      else if (pl_format == PLAYLIST_M3U)
	path = buf;

      if (!path)
	continue;

      /* Check that first char is sane for a path */
      if ((!isalnum(path[0])) && (path[0] != '/') && (path[0] != '.'))
	continue;

      /* Check if line is an URL, will be added to library, otherwise it should already be there */
      if (strncasecmp(path, "http://", 7) == 0)
	ret = process_url(pl_id, path, sb.st_mtime, extinf, &mfi);
      else
	ret = process_regular_file(pl_id, path);

      ntracks++;
      if (ntracks % 200 == 0)
	{
	  DPRINTF(E_LOG, L_SCAN, "Processed %d items...\n", ntracks);
	  db_transaction_end();
	  db_transaction_begin();
	}

      if (ret == 0)
	nadded++;

      /* Clean up in preparation for next item */
      extinf = 0;
      free_mfi(&mfi, 1);
    }

  db_transaction_end();

  /* We had some extinf that we never got to use, free it now */
  if (extinf)
    free_mfi(&mfi, 1);

  if (!feof(fp))
    DPRINTF(E_LOG, L_SCAN, "Error reading playlist '%s' (only added %d tracks): %s\n", file, nadded, strerror(errno));
  else
    DPRINTF(E_LOG, L_SCAN, "Done processing playlist, added/modified %d items\n", nadded);

  fclose(fp);
}
Exemplo n.º 18
0
astring *image_info_astring(running_machine &machine, astring *string)
{
	device_image_interface *image = NULL;

	astring_printf(string, "%s\n\n", machine.system().description);

#if 0
	if (mess_ram_size > 0)
	{
		char buf2[RAM_STRING_BUFLEN];
		astring_catprintf(string, "RAM: %s\n\n", ram_string(buf2, mess_ram_size));
	}
#endif

	for (bool gotone = machine.devicelist().first(image); gotone; gotone = image->next(image))
	{
		const char *name = image->filename();
		if (name != NULL)
		{
			const char *base_filename;
			const char *info;
			char *base_filename_noextension;

			base_filename = image->basename();
			base_filename_noextension = strip_extension(base_filename);

			/* display device type and filename */
			astring_catprintf(string, "%s: %s\n", image->device().name(), base_filename);

			/* display long filename, if present and doesn't correspond to name */
			info = image->longname();
			if (info && (!base_filename_noextension || mame_stricmp(info, base_filename_noextension)))
				astring_catprintf(string, "%s\n", info);

			/* display manufacturer, if available */
			info = image->manufacturer();
			if (info != NULL)
			{
				astring_catprintf(string, "%s", info);
				info = stripspace(image->year());
				if (info && *info)
					astring_catprintf(string, ", %s", info);
				astring_catprintf(string,"\n");
			}

			/* display supported information, if available */
			switch(image->supported()) {
				case SOFTWARE_SUPPORTED_NO : astring_catprintf(string, "Not supported\n"); break;
				case SOFTWARE_SUPPORTED_PARTIAL : astring_catprintf(string, "Partialy supported\n"); break;
				default : break;
			}

			if (base_filename_noextension != NULL)
				free(base_filename_noextension);
		}
		else
		{
			astring_catprintf(string, "%s: ---\n", image->device().name());
		}
	}
	return string;
}
Exemplo n.º 19
0
static int
traverse(const char *path, const struct stat *s, int flag)
{
	int ret = 0;
	char *path_no_ext = NULL;
	FILE *out = NULL;
	char *out_path = NULL;
	char *header = NULL;
	size_t header_len;
	char *footer = NULL;
	size_t footer_len;
	char *sed_args[16] = {NULL};
	struct page *page = NULL;
	const char *date_ext = path;

	while ((date_ext = strstr(date_ext, ".date")) != NULL) {
		if (*(date_ext + sizeof(".date") - 1) == '\0') {
			return 0;
		}
	}

	/* Strip the first part of the path to get the HTTP path */

	path += sizeof("./src") - 1;
	if (path[0] == '\0') return 0;
	++path;

	if (S_ISDIR(s->st_mode)) {
		puts(path);

		xasprintf(&out_path, "./build/%s", path);

		if (mkdir(out_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) {
			if (errno != EEXIST) {
				perror("mkdir");
				goto error;
			}
		}
	} else {
		time_t secs = time(NULL);
		struct tm now;

		if (gmtime_r(&secs, &now) == NULL) {
			perror("gmtime_r");
			goto error;
		}

		if ((page = create_page(path, s)) == NULL) {
			goto error;
		}

		path_no_ext = strip_extension(xstrdup(path));
		xasprintf(&out_path, "./build/%s.html", path_no_ext);

		page->htpath = xstrdup(out_path + sizeof("./build") - 1);

		printf("%s -> %s (%s)\n", path, page->title, out_path);

		/* Make header */

		sed_args[0] = xstrdup("sed");

		xasprintf(&sed_args[1], "-e s|${base_url}|%s|g",
		    x.base_url);
		xasprintf(&sed_args[2], "-e s|${year}|%d|g",
		    now.tm_year + 1900);
		xasprintf(&sed_args[3], "-e s|${created}|%s|g",
		    page->created_iso);
		xasprintf(&sed_args[4], "-e s|${created_readable}|%s|g",
		    page->created_readable);
		xasprintf(&sed_args[5], "-e s|${modified}|%s|g",
		    page->modified_iso);
		xasprintf(&sed_args[6], "-e s|${modified_readable}|%s|g",
		    page->modified_readable);
		xasprintf(&sed_args[7], "-e s|${owner}|%s|g", page->user);
		xasprintf(&sed_args[8], "-e s|${title}|%s|g", page->title);

		sed_args[9] = xstrdup("header.html");

		if ((header = read_pipe(sed_args, &header_len)) == NULL) {
			goto error;
		}

		free(sed_args[9]);
		sed_args[9] = xstrdup("footer.html");
		if ((footer = read_pipe(sed_args, &footer_len)) == NULL) {
			goto error;
		}

		out = fopen(out_path, "w");
		if (out == NULL) {
			perror("fopen");
			goto error;
		}
		if (fwrite(header, 1, header_len, out) < header_len) {
			perror("fwrite");
			goto error;
		}
		if (fwrite(page->body, 1, page->body_len, out) < page->body_len) {
			perror("fwrite");
			goto error;
		}
		if (fwrite(footer, 1, footer_len, out) < footer_len) {
			perror("fwrite");
			goto error;
		}
	}

end:
	if (out != NULL) {
		fclose(out);
	}
	free(out_path);
	free(header);
	free(footer);
	free(path_no_ext);
	for (size_t i = 0; i < (sizeof(sed_args) / sizeof(char *)); ++i) {
		free(sed_args[i]);
	}
	return ret;
error:
	ret = -1;
	goto end;
}
Exemplo n.º 20
0
/* Look for the first matching album art bitmap in the following list:
 *  ./<trackname><size>.{jpeg,jpg,bmp}
 *  ./<albumname><size>.{jpeg,jpg,bmp}
 *  ./cover<size>.bmp
 *  ../<albumname><size>.{jpeg,jpg,bmp}
 *  ../cover<size>.{jpeg,jpg,bmp}
 *  ROCKBOX_DIR/albumart/<artist>-<albumname><size>.{jpeg,jpg,bmp}
 * <size> is the value of the size_string parameter, <trackname> and
 * <albumname> are read from the ID3 metadata.
 * If a matching bitmap is found, its filename is stored in buf.
 * Return value is true if a bitmap was found, false otherwise.
 *
 * If the first symbol in size_string is a colon (e.g. ":100x100")
 * then the colon is skipped ("100x100" will be used) and the track
 * specific image (./<trackname><size>.bmp) is tried last instead of first.
 */
bool search_albumart_files(const struct mp3entry *id3, const char *size_string,
                           char *buf, int buflen)
{
    char path[MAX_PATH + 1];
    char dir[MAX_PATH + 1];
    bool found = false;
    int track_first = 1;
    int pass;
    const char *trackname;
    const char *artist;
    int dirlen;
    int albumlen;
    int pathlen;

    if (!id3 || !buf)
        return false;

    trackname = id3->path;

    if (strcmp(trackname, "No file!") == 0)
        return false;

    if (*size_string == ':')
    {
        size_string++;
        track_first = 0;
    }

    strip_filename(dir, sizeof(dir), trackname);
    dirlen = strlen(dir);
    albumlen = id3->album ? strlen(id3->album) : 0;

    for(pass = 0; pass < 2 - track_first; pass++)
    {
        if (track_first || pass)
        {
            /* the first file we look for is one specific to the
               current track */
            strip_extension(path, sizeof(path) - strlen(size_string) - 4,
                            trackname);
            strcat(path, size_string);
            strcat(path, "." EXT);
#ifdef USE_JPEG_COVER
            pathlen = strlen(path);
#endif
            found = try_exts(path, pathlen);
        }
        if (pass)
            break;
        if (!found && albumlen > 0)
        {
            /* if it doesn't exist,
            * we look for a file specific to the track's album name */
            pathlen = snprintf(path, sizeof(path),
                               "%s%s%s." EXT, dir, id3->album, size_string);
            fix_path_part(path, dirlen, albumlen);
            found = try_exts(path, pathlen);
        }

        if (!found)
        {
            /* if it still doesn't exist, we look for a generic file */
            pathlen = snprintf(path, sizeof(path),
                               "%scover%s." EXT, dir, size_string);
            found = try_exts(path, pathlen);
        }

#ifdef USE_JPEG_COVER
        if (!found && !*size_string)
        {
            snprintf (path, sizeof(path), "%sfolder.jpg", dir);
            found = file_exists(path);
        }
#endif

        artist = id3->albumartist != NULL ? id3->albumartist : id3->artist;

        if (!found && artist && id3->album)
        {
            /* look in the albumart subdir of .rockbox */
            pathlen = snprintf(path, sizeof(path),
                               ROCKBOX_DIR "/albumart/%s-%s%s." EXT,
                               artist,
                               id3->album,
                               size_string);
            fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH);
            found = try_exts(path, pathlen);
        }

        if (!found)
        {
            /* if it still doesn't exist,
            * we continue to search in the parent directory */
            strcpy(path, dir);
            path[dirlen - 1] = 0;
            strip_filename(dir, sizeof(dir), path);
            dirlen = strlen(dir);
        }

        /* only try parent if there is one */
        if (dirlen > 0)
        {
            if (!found && albumlen > 0)
            {
                /* we look in the parent directory
                * for a file specific to the track's album name */
                pathlen = snprintf(path, sizeof(path),
                                   "%s%s%s." EXT, dir, id3->album, size_string);
                fix_path_part(path, dirlen, albumlen);
                found = try_exts(path, pathlen);
            }

            if (!found)
            {
                /* if it still doesn't exist, we look in the parent directory
                * for a generic file */
                pathlen = snprintf(path, sizeof(path),
                                   "%scover%s." EXT, dir, size_string);
                found = try_exts(path, pathlen);
            }
        }
        if (found)
            break;
    }

    if (!found)
        return false;

    strlcpy(buf, path, buflen);
    logf("Album art found: %s", path);
    return true;
}
Exemplo n.º 21
0
void
dirtree_merge (dirtree_t * tree)
{
	dirtree_t    *t;
	ASSERT_TREE(tree);
	
	/* PASS1: merge all the subdirs of the current dir */
	for (t = tree->child; t != NULL; t = t->next)
	{
		if( t->stripped_name == NULL )
		{
			t->stripped_name = tree->extension?strip_extension( t->name, tree->extension ):t->name;
			if( t->stripped_name == t->name && tree->minipixmap_extension )
			{
				t->stripped_name = strip_extension( t->name, tree->minipixmap_extension );
				if( t->stripped_name != t->name )
					set_flags( t->flags, DIRTREE_MINIPIXMAP );
			}
		}
		if (t->flags & DIRTREE_DIR)
		{
			dirtree_t    *t2;

			for (t2 = t->next; t2 != NULL;)
			{
				if ((t2->flags & DIRTREE_DIR) && !strcmp (t->name, t2->name))
				{
					if (t2->order != -1)
						t->order = t2->order;
					if( t2->base_order < t->base_order ) 
						t->base_order = t2->base_order ; 
					dirtree_remove (t2);
					dirtree_move_children (t, t2);
					dirtree_delete (t2);
					t2 = t->next;
				} else
					t2 = t2->next;
			}
		}
	}
	/* PASS2: attach all the minipixmaps : */
	for (t = tree->child; t != NULL; t = t->next)
		if( get_flags( t->flags, DIRTREE_MINIPIXMAP ))
		{	/* let us try and find matching filename */
			dirtree_t    *t2;

			for (t2 = tree->child; t2 != NULL; t2 = t2->next )
			{
				if ( t2 != t && !strcmp(t2->stripped_name, t->stripped_name ) )
				{
					if( t2->icon )
						free( t2->icon );
					t2->icon = mystrdup( t->path );
				}
			}
		}

	/* PASS3: merge all the subdirs : */
	for (t = tree->child; t != NULL; t = t->next)
		dirtree_merge (t);
}
Exemplo n.º 22
0
static char *battery_nvramfilename(mess_image *img)
{
	const char *filename;
	filename = image_filename(img);
	return strip_extension(osd_basename((char *) filename));
}
Exemplo n.º 23
0
int main(int argc, char* const* argv)
{
   Prog*         prog;
   Set*          set;
   void*         lp;
   const char*   extension = "";
   char*         filter    = strdup("%s");
   char*         outfile;
   char*         tblfile;
   char*         ordfile;
   char*         mstfile;
   char*         basefile = NULL;
   char*         inppipe  = NULL;
   char*         outpipe;
   LpFormat      format   = LP_FORM_LPF;
   FILE*         fp;
   Bool          write_order = FALSE;
   Bool          write_mst   = FALSE;
   Bool          presolve    = FALSE;
   int           name_length = 0;
   char*         prog_text;
   unsigned long seed = 13021967UL;
   char**        param_table;
   int           param_count = 0;
   int           c;
   int           i;
   FILE*         (*openfile)(const char*, const char*) = fopen;
   int           (*closefile)(FILE*)                   = fclose;

   stkchk_init();
   
   yydebug       = 0;
   yy_flex_debug = 0;
   verbose       = VERB_NORMAL;
   param_table   = malloc(sizeof(*param_table));
   
   while((c = getopt(argc, argv, options)) != -1)
   {
      switch(c)
      {
      case 'b' :
         yydebug = 1;
         break;
      case 'D' :
         param_table =
            realloc(param_table, ((unsigned int)param_count + 1) * sizeof(*param_table));
         param_table[param_count] = strdup(optarg);
         param_count++;
         break;
      case 'h' :
         zpl_print_banner(stdout, TRUE);
         printf(usage, argv[0]);
         puts(help);
         exit(0);
      case 'f' :
         yy_flex_debug = 1;
         break;
      case 'F' :
         free(filter);
         
         filter    = strdup(optarg);
         openfile  = popen;
         closefile = pclose;
         break;
      case 'l' :
         name_length = atoi(optarg);
         break;
      case 'm' :
         write_mst = TRUE;
         break;
      case 'n' :
         if (*optarg != 'c')
         {
            fprintf(stderr, usage, argv[0]);
            exit(0);
         }
         switch(optarg[1])
         {
         case 'm' :
            conname_format(CON_FORM_MAKE);
            break;
         case 'n' :
            conname_format(CON_FORM_NAME);
            break;
         case 'f' :
            conname_format(CON_FORM_FULL);
            break;
         default :
            fprintf(stderr, usage, argv[0]);
            exit(0);
         }
         break;
      case 'o' :
         basefile = strdup(optarg);
         break;
      case 'O' :
         presolve = TRUE;
         break;
      case 'P' :
         inppipe = strdup(optarg);
         break;
      case 's' :
         seed = (unsigned long)atol(optarg);
         break;
      case 'r' :
         write_order = TRUE;
         break;
      case 't' :
         switch(tolower(*optarg))
         {
         case 'h' :
            format = LP_FORM_HUM;
            break;
         case 'm' :
            format = LP_FORM_MPS;
            break;
         case 'l' :
            format = LP_FORM_LPF;
            break;
         case 'p' :
            format = LP_FORM_PIP;
            break;
         case 'r' :
            format = LP_FORM_RLP;
            break;
         default :
            if (verbose > VERB_QUIET)
               fprintf(stderr,
                  "--- Warning 103: Output format \"%s\" not supported, using LP format\n",
                  optarg);
            format = LP_FORM_LPF;
            break;
         }
         break;
      case 'v' :
         verbose = atoi(optarg);
         break;
      case 'V' :
         printf("%s\n", VERSION);
         exit(0);
      case '?':
         fprintf(stderr, usage, argv[0]);
         exit(0);
      default :
         abort();
      }
   }
   if ((argc - optind) < 1)
   {
      fprintf(stderr, usage, argv[0]);      
      exit(0);
   }

   zpl_print_banner(stdout, TRUE);
   
   if (basefile == NULL)
      basefile = strip_extension(strdup(strip_path(argv[optind])));

   switch(format)
   {
   case LP_FORM_LPF :
      extension = ".lp";
      break;
   case LP_FORM_MPS :
      extension = ".mps";
      break;
   case LP_FORM_HUM :
      extension = ".hum";
      break;
   case LP_FORM_RLP :
      extension = ".rlp";
      break;
   case LP_FORM_PIP :
      extension = ".pip";
      break;
   default :
      abort();
   }
   assert(extension != NULL);

   outfile = add_extention(basefile, extension);
   tblfile = add_extention(basefile, ".tbl");
   ordfile = add_extention(basefile, ".ord");
   mstfile = add_extention(basefile, ".mst");
   
   outpipe = malloc(strlen(basefile) + strlen(filter) + 256);

   assert(outpipe != NULL);

   blk_init();
   str_init();
   rand_init(seed);
   numb_init(TRUE);
   elem_init();
   set_init();
   mio_init();
   interns_init();
   local_init();
   
   /* Make symbol to hold entries of internal variables
    */
   set = set_pseudo_new();
   (void)symbol_new(SYMBOL_NAME_INTERNAL, SYM_VAR, set, 100, NULL);
   set_free(set);
   
   /* Now store the param defines
    */
   for(i = 0; i < param_count; i++)
      zpl_add_parameter(param_table[i]);

   /* Next we read in the zpl program(s)
    */
   prog = prog_new();

   for(i = optind; i < argc; i++)
      prog_load(prog, inppipe, argv[i]);

   if (prog_is_empty(prog))
   {
      fprintf(stderr, "*** Error 168: No program statements to execute\n");
      exit(EXIT_FAILURE);
   }
   if (verbose >= VERB_DEBUG)
      prog_print(stderr, prog);
   
   lp = xlp_alloc(argv[optind], write_mst || write_order, NULL);
   zlp_setnamelen(lp, name_length);
   
   prog_execute(prog, lp);

   /* Presolve
    */
   if (presolve)
      fprintf(stderr, "--- Warning: Presolve no longer support. If you need it, send me an email\n");
#if 0 
      if (!zlp_presolve())
         exit(EXIT_SUCCESS);
#endif
   if (verbose >= VERB_NORMAL)
      zlp_stat(lp);
   
   /* Write order file 
    */
   if (write_order)
   {
      sprintf(outpipe, filter, ordfile, "ord");

      if (verbose >= VERB_NORMAL)
         printf("Writing [%s]\n", outpipe);

      if (NULL == (fp = (*openfile)(outpipe, "w")))
      {
         fprintf(stderr, "*** Error 104: File open failed ");
         perror(ordfile);
         exit(EXIT_FAILURE);
      }
      zlp_orderfile(lp, fp, format);
         
      check_write_ok(fp, ordfile);
         
      (void)(*closefile)(fp);
   }
   /* Write MST file 
    */
   if (write_mst)
   {
      sprintf(outpipe, filter, mstfile, "mst");

      if (verbose >= VERB_NORMAL)
         printf("Writing [%s]\n", outpipe);

      if (NULL == (fp = (*openfile)(outpipe, "w")))
      {
         fprintf(stderr, "*** Error 104: File open failed ");
         perror(mstfile);
         exit(EXIT_FAILURE);
      }
      zlp_mstfile(lp, fp, format);
         
      check_write_ok(fp, mstfile);
         
      (void)(*closefile)(fp);
   }
   /* Write Output
    */
   sprintf(outpipe, filter, outfile, "lp");

   if (verbose >= VERB_NORMAL)
      printf("Writing [%s]\n", outpipe);

   if (NULL == (fp = (*openfile)(outpipe, "w")))
   {
      fprintf(stderr, "*** Error 104: File open failed ");
      perror(outfile);
      exit(EXIT_FAILURE);
   }
   if (format != LP_FORM_RLP)
      prog_text = prog_tostr(prog, format == LP_FORM_MPS ? "* " : "\\ ", title, 128);
   else
   {
      prog_text = malloc(strlen(title) + 4);
      
      assert(prog_text != NULL);

      sprintf(prog_text, "\\%s\n", title);
   }
   zlp_write(lp, fp, format, prog_text);

   check_write_ok(fp, outfile);

   (void)(*closefile)(fp);

   /* We do not need the translation table for human readable format
    * Has to be written after the LP file, so the scaling has been done.
    */
   if (format != LP_FORM_HUM)
   {
      /* Write translation table
       */
      sprintf(outpipe, filter, tblfile, "tbl");

      if (verbose >= VERB_NORMAL)
         printf("Writing [%s]\n", outpipe);

      if (NULL == (fp = (*openfile)(outpipe, "w")))
      {
         fprintf(stderr, "*** Error 104: File open failed");
         perror(tblfile);
         exit(EXIT_FAILURE);
      }
      zlp_transtable(lp, fp, format);

      check_write_ok(fp, tblfile);

      (void)(*closefile)(fp);
   }




   free(prog_text);
   
   if (verbose >= VERB_DEBUG) 
      symbol_print_all(stderr);

#if defined(__INSURE__) || !defined(NDEBUG) || defined(FREEMEM)
   
   /* Now clean up. 
    */
   if (inppipe != NULL)
      free(inppipe);
   
   for(i = 0; i < param_count; i++)
      free(param_table[i]);
   free(param_table);
   
   prog_free(prog);

   local_exit();
   interns_exit();
   xlp_free(lp);
   mio_exit();
   symbol_exit();
   define_exit();
   set_exit();
   elem_exit();
   numb_exit();
   str_exit();
   blk_exit();
   
   free(mstfile);
   free(ordfile);
   free(outfile);
   free(tblfile);
   free(basefile);
   free(filter);
   free(outpipe);

   if (verbose >= VERB_NORMAL)
   {
      mem_display(stdout);
      stkchk_maximum(stdout);
   }
#endif /* __INSURE__ || !NDEBUG || FREEMEM */
   return 0;
}