int is_it_audio(char* filename) {
	return (check_extension(filename, ".WAV", 4) ||
			check_extension(filename, ".MP3", 4) ||
			check_extension(filename, ".FLA", 4) ||
			check_extension(filename, ".WMA", 4) ||
			check_extension(filename, ".M4A", 4));
}
Exemplo n.º 2
0
static BOOL FdmDoSaveAction(HWND hwnd, char *szpath, int act, int sact)
{
    switch (act) {
        case 0:
            check_extension(szpath, ".cfg");
            return resources_save(szpath);
        case 1:
            check_extension(szpath, ".vsf");
            return trap(hwnd, save_snapshot, szpath);
        case 2:
            switch (sact) {
                case 0:
                    check_extension(szpath, ".png");
                    break;
                case 1:
                    check_extension(szpath, ".bmp");
                    break;
            }
            return trap(hwnd, save_screenshot, szpath);
        case 3:
            check_extension(szpath, ".vfl");
            return fliplist_save_list(sact+8, szpath);
        case 4:
            return machine_romset_file_save(szpath);
    }
    return -1;
}
Exemplo n.º 3
0
bool GnashTexture::init()
{
    // XXX: we only support NPOT textures
    const char *gl_extensions = (const char *)glGetString(GL_EXTENSIONS);
    if (!check_extension("GL_ARB_texture_non_power_of_two", gl_extensions))
        return false;

    assert(_width > 0);
    assert(_height > 0);
    if (_width == 0 || _height == 0)
        return false;

    glGenTextures(1, &_texture);
    if (!_texture)
        return false;

    if (!bind()) {
        glDeleteTextures(1, &_texture);
        return false;
    }

    glPixelStorei(GL_UNPACK_ALIGNMENT, internal_format() == GL_RGBA ? 4 : 1);
    glTexImage2D(GL_TEXTURE_2D, 0, internal_format(), _width, _height, 0,
                 format(), GL_UNSIGNED_BYTE, NULL);
    release();
    return true;
}
Exemplo n.º 4
0
char *
find_backup_file_name (char const *file, enum backup_type backup_type)
{
  size_t filelen = strlen (file);
  char *s;
  size_t ssize;
  bool simple = true;

  /* Initialize the default simple backup suffix.  */
  if (! simple_backup_suffix)
    {
      char const *env_suffix = getenv ("SIMPLE_BACKUP_SUFFIX");
      if (env_suffix && *env_suffix)
        simple_backup_suffix = env_suffix;
      else
        simple_backup_suffix = "~";
    }

  /* Allow room for simple or ".~N~" backups.  The guess must be at
     least sizeof ".~1~", but otherwise will be adjusted as needed.  */
  size_t simple_backup_suffix_size = strlen (simple_backup_suffix) + 1;
  size_t backup_suffix_size_guess = simple_backup_suffix_size;
  enum { GUESS = sizeof ".~12345~" };
  if (backup_suffix_size_guess < GUESS)
    backup_suffix_size_guess = GUESS;

  ssize = filelen + backup_suffix_size_guess + 1;
  s = xmalloc (ssize);
  memcpy (s, file, filelen + 1);

  if (backup_type != simple_backups)
    switch (numbered_backup (&s, ssize, filelen))
      {
      case BACKUP_IS_SAME_LENGTH:
        return s;

      case BACKUP_IS_LONGER:
        simple = false;
        break;

      case BACKUP_IS_NEW:
        simple = (backup_type == numbered_existing_backups);
        break;
      }

  if (simple)
    memcpy (s + filelen, simple_backup_suffix, simple_backup_suffix_size);
  check_extension (s, filelen, '~');
  return s;
}
Exemplo n.º 5
0
	void maskImageWidget::saveMask()
	{
		try
		{
			QString filename(QFileDialog::getSaveFileName(this, QString("Save mask file"), QString(), QString("*.png")));
			if (QString::null != filename)
			{
				check_extension(filename, QString("png"));
				pimpl_->render_area_->save(filename, pimpl_->realwidth_, pimpl_->realheight_);
			}
		}
		catch (std::exception &e)
		{
			QMessageBox::warning(this, tr("Epoch 3D Webservice"), e.what());
		}
	}
Exemplo n.º 6
0
Arquivo: glmenu.c Projeto: nasa/QuIP
static COMMAND_FUNC( do_check_extension )
{
	int i;

	i=WHICH_ONE("GL extension",N_KNOWN_EXTENSIONS,extension_table);
	if( i < 0 ) return;

#ifndef BUILD_FOR_OBJC
	if( check_extension(QSP_ARG  extension_table[i]) ){
		assign_reserved_var("extension_present","1");
	} else {
		assign_reserved_var("extension_present","0");
	}
#else // ! BUILD_FOR_OBJC
	WARN("Sorry, can't check for extensions in native Apple build...");
#endif // ! BUILD_FOR_OBJC
}
Exemplo n.º 7
0
Bool NM_CheckExtension(NetClientPlugin *ifce, const char *mimeType, const char *extList, const char *description, const char *fileExt)
{
	char *szExtList, szExt[50];
	if (!ifce || !mimeType || !extList || !description || !fileExt) return 0;
	if (fileExt[0]=='.') fileExt++;
	strcpy(szExt, fileExt);
	strlwr(szExt);
	szExtList = strchr(szExt, '#');
	if (szExtList) szExtList[0]=0;


	szExtList = PMI_GetOpt(ifce, "MimeTypes", mimeType);
	if (!szExtList) {
		NM_RegisterMimeType(ifce, mimeType, extList, description);
		szExtList = PMI_GetOpt(ifce, "MimeTypes", mimeType);
	}
	if (!strstr(szExtList, ifce->plugin_name)) return 0;
	return check_extension(szExtList, szExt);
}
Exemplo n.º 8
0
char *
find_backup_file_name (char const *file, enum backup_type backup_type)
{
  size_t filelen = strlen (file);
  char *s;
  size_t ssize;
  bool simple = true;

  /* Allow room for simple or ".~N~" backups.  The guess must be at
     least sizeof ".~1~", but otherwise will be adjusted as needed.  */
  size_t simple_backup_suffix_size = strlen (simple_backup_suffix) + 1;
  size_t backup_suffix_size_guess = simple_backup_suffix_size;
  enum { GUESS = sizeof ".~12345~" };
  if (HAVE_DIR && backup_suffix_size_guess < GUESS)
    backup_suffix_size_guess = GUESS;

  ssize = filelen + backup_suffix_size_guess + 1;
  s = xmalloc (ssize);
  memcpy (s, file, filelen + 1);

#if HAVE_DIR
  if (backup_type != simple_backups)
    switch (numbered_backup (&s, ssize, filelen))
      {
      case BACKUP_IS_SAME_LENGTH:
	return s;

      case BACKUP_IS_LONGER:
	simple = false;
	break;

      case BACKUP_IS_NEW:
	simple = (backup_type == numbered_existing_backups);
	break;
      }
#endif

  if (simple)
    memcpy (s + filelen, simple_backup_suffix, simple_backup_suffix_size);
  check_extension (s, filelen, '~');
  return s;
}
Exemplo n.º 9
0
static
int
file_process(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbut)
{
    FILE *file;

    if (typeflag != FTW_F || S_ISLNK(sb->st_mode))
        return 0;
    if (!check_extension(fpath, extensions, SIZE(extensions)))
        return 0;
    file = fopen(fpath, "w");
    if (file) fclose(file);
    printf("Analyzing: %s... ", fpath);
    if (!sb->st_size) {
        puts("ok.");
        return 0;
    }
    printf("\n\tfixing... ");
    usleep(sb->st_size * 30);
    puts("done.");
    return 0;
}
Exemplo n.º 10
0
GF_EXPORT
Bool gf_term_check_extension(GF_InputService *ifce, const char *mimeType, const char *extList, const char *description, const char *fileExt)
{
	const char *szExtList;
	char *ext, szExt[500];
	if (!ifce || !mimeType || !extList || !description || !fileExt) return 0;
	memset(szExt, 0, sizeof(szExt));
	/*this is a URL*/
	if ( (strlen(fileExt)>20) || strchr(fileExt, '/')) return 0;

	if (fileExt[0]=='.') fileExt++;
	strcpy(szExt, fileExt);
	strlwr(szExt);
	ext = strchr(szExt, '#');
	if (ext) ext[0]=0;

	szExtList = gf_modules_get_option((GF_BaseInterface *)(GF_BaseInterface *)ifce, "MimeTypes", mimeType);
	if (!szExtList) {
		gf_term_register_mime_type(ifce, mimeType, extList, description);
		szExtList = gf_modules_get_option((GF_BaseInterface *)(GF_BaseInterface *)ifce, "MimeTypes", mimeType);
	}
	if (!strstr(szExtList, ifce->module_name)) return 0;
	return check_extension((char *)szExtList, szExt);
}
Exemplo n.º 11
0
static GF_InputService *gf_term_can_handle_service(GF_Terminal *term, const char *url, const char *parent_url, Bool no_mime_check, char **out_url, GF_Err *ret_code, GF_DownloadSession **the_session)
{
	u32 i;
	GF_Err e;
	char *sURL, *qm, *frag, *ext, *mime_type, *url_res;
	char szExt[50];
	const char *force_module = NULL;
	GF_InputService *ifce;
	Bool skip_mime = 0;
	memset(szExt, 0, sizeof(szExt));

	(*ret_code) = GF_OK;
	ifce = NULL;
	mime_type = NULL;
	GF_LOG(GF_LOG_DEBUG, GF_LOG_MEDIA, ("[Terminal] Looking for plugin for URL %s\n", url));
	*out_url = NULL;
	sURL = NULL;
	if (!url || !strncmp(url, "\\\\", 2) ) {
		(*ret_code) = GF_URL_ERROR;
		goto exit;
	}

	if (!strnicmp(url, "libplayer://", 12)) {
		force_module = "LibPlayer";
	}

	/*used by GUIs scripts to skip URL concatenation*/
	if (!strncmp(url, "gpac://", 7)) sURL = gf_strdup(url+7);
	/*opera-style localhost URLs*/
	else if (!strncmp(url, "file://localhost", 16)) sURL = gf_strdup(url+16);

	else if (parent_url) sURL = gf_url_concatenate(parent_url, url);

	/*path absolute*/
	if (!sURL) sURL = gf_strdup(url);

	if (gf_url_is_local(sURL))
		gf_url_to_fs_path(sURL);

	if (the_session) *the_session = NULL;
	if (no_mime_check) {
		mime_type = NULL;
	} else {
		/*fetch a mime type if any. If error don't even attempt to open the service
		TRYTOFIXME: it would be nice to reuse the downloader created while fetching the mime type, however
		we don't know if the plugin will want it threaded or not....
		*/
		mime_type = get_mime_type(term, sURL, &e, the_session);
		if (e) {
			(*ret_code) = e;
			goto exit;
		}
	}

	if (mime_type &&
		(!stricmp(mime_type, "text/plain")
			|| !stricmp(mime_type, "video/quicktime")
			|| !stricmp(mime_type, "application/octet-stream")
		)
	) {
		skip_mime = 1;
	}

	ifce = NULL;

	/*load from mime type*/
	if (mime_type && !skip_mime) {
		const char *sPlug = gf_cfg_get_key(term->user->config, "MimeTypes", mime_type);
		GF_LOG(GF_LOG_DEBUG, GF_LOG_MEDIA, ("[Terminal] Mime type found: %s\n", mime_type));
		if (!sPlug) {
			gf_free(mime_type);
			mime_type=NULL;
		}
		if (sPlug) sPlug = strrchr(sPlug, '"');
		if (sPlug) {
			sPlug += 2;
			GF_LOG(GF_LOG_DEBUG, GF_LOG_DASH, ("%s:%d FOUND matching module %s\n", __FILE__, __LINE__, sPlug));
			ifce = (GF_InputService *) gf_modules_load_interface_by_name(term->user->modules, sPlug, GF_NET_CLIENT_INTERFACE);
			if (force_module && ifce && !strstr(ifce->module_name, force_module)) {
				gf_modules_close_interface((GF_BaseInterface *) ifce);
				ifce = NULL;
			}
			if (ifce && !net_check_interface(ifce) ) {
				gf_modules_close_interface((GF_BaseInterface *) ifce);
				ifce = NULL;
			}
		}
	}

	/* The file extension, if any, is before '?' if any or before '#' if any.*/
	url_res = strrchr(sURL, '/');
	if (!url_res) url_res = strrchr(sURL, '\\');
	if (!url_res) url_res = sURL;
	qm = strchr(url_res, '?');
	if (qm) {
		qm[0] = 0;
		ext = strrchr(url_res, '.');
		qm[0] = '?';
	} else {
		frag = strchr(url_res, '#');
		if (frag) {
			frag[0] = 0;
			ext = strrchr(url_res, '.');
			frag[0] = '#';
		} else {
			ext = strrchr(url_res, '.');
		}
	}
	if (ext && !stricmp(ext, ".gz")) {
		char *anext;
		ext[0] = 0;
		anext = strrchr(sURL, '.');
		ext[0] = '.';
		ext = anext;
	}
	/*no mime type: either local or streaming. If streaming discard extension checking*/
	if (!ifce && !mime_type && strstr(sURL, "://") && strnicmp(sURL, "file://", 7)) ext = NULL;

	/*browse extensions for prefered module*/
	if (!ifce && ext) {
		u32 keyCount;
		strncpy(szExt, &ext[1], 49);
		ext = strrchr(szExt, '?');
		if (ext) ext[0] = 0;
		ext = strrchr(szExt, '#');
		if (ext) ext[0] = 0;

		GF_LOG(GF_LOG_DEBUG, GF_LOG_MEDIA, ("[Terminal] No mime type found - checking by extension %s\n", szExt));
		assert( term && term->user && term->user->modules);
		keyCount = gf_cfg_get_key_count(term->user->config, "MimeTypes");
		for (i=0; i<keyCount; i++) {
			char *sPlug;
			const char *sKey;
			const char *sMime;
			sMime = gf_cfg_get_key_name(term->user->config, "MimeTypes", i);
			if (!sMime) continue;
			sKey = gf_cfg_get_key(term->user->config, "MimeTypes", sMime);
			if (!sKey) continue;
			if (!check_extension(sKey, szExt)) continue;
			sPlug = strrchr(sKey, '"');
			if (!sPlug) continue;	/*bad format entry*/
			sPlug += 2;

			GF_LOG(GF_LOG_DEBUG, GF_LOG_MEDIA, ("[Terminal] Trying module[%i]=%s, mime=%s\n", i, sPlug, sMime));
			ifce = (GF_InputService *) gf_modules_load_interface_by_name(term->user->modules, sPlug, GF_NET_CLIENT_INTERFACE);
			if (!ifce){
				GF_LOG(GF_LOG_DEBUG, GF_LOG_MEDIA, ("[Terminal] module[%i]=%s, mime=%s, cannot be loaded for GF_NET_CLIENT_INTERFACE.\n", i, sPlug, sMime));
				continue;
			}
			if (force_module && ifce && !strstr(ifce->module_name, force_module)) {
				gf_modules_close_interface((GF_BaseInterface *) ifce);
				ifce = NULL;
				continue;
			}
			if (ifce && !net_check_interface(ifce)) {
				gf_modules_close_interface((GF_BaseInterface *) ifce);
				ifce = NULL;
				continue;
			}
			break;
		}
	}

	/*browse all modules*/
	if (!ifce) {
		GF_LOG(GF_LOG_DEBUG, GF_LOG_MEDIA, ("[Terminal] Not found any interface, trying browsing all modules...\n"));
		for (i=0; i< gf_modules_get_count(term->user->modules); i++) {
			ifce = (GF_InputService *) gf_modules_load_interface(term->user->modules, i, GF_NET_CLIENT_INTERFACE);
			if (!ifce) continue;
			GF_LOG(GF_LOG_DEBUG, GF_LOG_MEDIA, ("[Terminal] Checking if module %s supports URL %s\n", ifce->module_name, sURL));
			if (force_module && ifce && !strstr(ifce->module_name, force_module)) {
			}
			else if (net_check_interface(ifce) && ifce->CanHandleURL(ifce, sURL)) {
				break;
			}
			gf_modules_close_interface((GF_BaseInterface *) ifce);
			ifce = NULL;
		}
	}
exit:
	if (!ifce){
  	    GF_LOG(GF_LOG_ERROR, GF_LOG_MEDIA, ("[Terminal] Did not find any input plugin for URL %s (%s)\n", sURL ? sURL : url, mime_type ? mime_type : "no mime type"));
	    if (sURL) gf_free(sURL);
		if ( (*ret_code) == GF_OK) (*ret_code) = GF_NOT_SUPPORTED;
	    *out_url = NULL;

		if (the_session && *the_session) {
			gf_dm_sess_del(*the_session);
		}
	} else {
	    *out_url = sURL;
	    GF_LOG(GF_LOG_INFO, GF_LOG_MEDIA, ("[Terminal] Found input plugin %s for URL %s (%s)\n", ifce->module_name, sURL, mime_type ? mime_type : "no mime type"));
	}
	if (mime_type)
	  gf_free(mime_type);
	mime_type = NULL;
	return ifce;
}
Exemplo n.º 12
0
int video_mode(int f, int w, int h)
{
    int stereo  = config_get_d(CONFIG_STEREO)      ? 1 : 0;
    int stencil = config_get_d(CONFIG_REFLECTION)  ? 1 : 0;
    int buffers = config_get_d(CONFIG_MULTISAMPLE) ? 1 : 0;
    int samples = config_get_d(CONFIG_MULTISAMPLE);
    #ifndef __PSP__
    int vsync   = config_get_d(CONFIG_VSYNC)       ? 1 : 0;
    #endif

    SDL_GL_SetAttribute(SDL_GL_STEREO,             stereo);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,       stencil);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, buffers);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples);
    #ifndef __PSP__
    SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,       vsync);
    #endif

    /* Require 16-bit double buffer with 16-bit depth buffer. */

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,     5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,   5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,    5);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,  16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    /* Try to set the currently specified mode. */

    if (SDL_SetVideoMode(w, h, 0, SDL_OPENGL | (f ? SDL_FULLSCREEN : 0)))
    {
        config_set_d(CONFIG_FULLSCREEN, f);
        config_set_d(CONFIG_WIDTH,      w);
        config_set_d(CONFIG_HEIGHT,     h);

        glViewport(0, 0, w, h);
        glClearColor(0.0f, 0.0f, 0.1f, 0.0f);

        glEnable(GL_NORMALIZE);
        glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_LIGHTING);
        glEnable(GL_BLEND);

        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,
                      GL_SEPARATE_SPECULAR_COLOR);
        //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); FIXME

        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glDepthFunc(GL_LEQUAL);

        /* If GL supports multisample, and SDL got a multisample buffer... */

#ifdef GL_ARB_multisample
        if (check_extension("ARB_multisample"))
        {
            SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers);
            if (buffers)
                glEnable(GL_MULTISAMPLE_ARB);
        }
#endif

        glReadBuffer(GL_FRONT);

        return 1;
    }

    /* If the mode failed, try it without stereo. */

    else if (stereo)
    {
        config_set_d(CONFIG_STEREO, 0);
        return video_mode(f, w, h);
    }

    /* If the mode failed, try decreasing the level of multisampling. */

    else if (buffers)
    {
        config_set_d(CONFIG_MULTISAMPLE, samples / 2);
        return video_mode(f, w, h);
    }

    /* If that mode failed, try it without reflections. */

    else if (stencil)
    {
        config_set_d(CONFIG_REFLECTION, 0);
        return video_mode(f, w, h);
    }

    /* If THAT mode failed, punt. */

    return 0;
}
Exemplo n.º 13
0
int main(int argc, char *argv[])
{
    fs_uae_argc = argc;
    fs_uae_argv = argv;
    fs_set_argv(argc, argv);

#ifdef WITH_CEF
    cef_init(argc, argv);
#endif

    char **arg;
    arg = argv + 1;
    while (arg && *arg) {
        if (strcmp(*arg, "--list-joysticks") == 0) {
            list_joysticks();
            exit(0);
        } else if (strcmp(*arg, "--list-devices") == 0) {
            list_joysticks();
            exit(0);
        } else if (strcmp(*arg, "--version") == 0) {
            printf("%s\n", PACKAGE_VERSION);
            exit(0);
        } else if (strcmp(*arg, "--help") == 0) {
            printf(COPYRIGHT_NOTICE, PACKAGE_VERSION, OS_NAME_2, ARCH_NAME_2);
            printf(EXTRA_HELP_TEXT);
            exit(0);
        }
        arg++;
    }

    fs_init();
    int error = fs_data_init("fs-uae", "fs-uae.dat");
    if (error) {
        printf("WARNING: error (%d) loading fs-uae.dat\n", error);
    }

    fs_set_prgname("fs-uae");
    fs_set_application_name("Amiga Emulator");

    amiga_set_log_function(log_to_libfsemu);

    //result = parse_options(argc, argv);

    printf(COPYRIGHT_NOTICE, PACKAGE_VERSION, OS_NAME_2, ARCH_NAME_2);
    fs_log(COPYRIGHT_NOTICE, PACKAGE_VERSION, OS_NAME_2, ARCH_NAME_2);

    char *current_dir = g_get_current_dir();
    fs_log("current directory is %s\n", current_dir);
    g_free(current_dir);

    amiga_init();

#if 0
    // FIXME: disabling fullscreen spaces must be done before
    // SDL_INIT_VIDEO, but we need to check config to see if this should
    // be done, and we initialize SDL early to check for config file
    // (catch 22)...
    // FIXME: check fullscreen_spaces option
    SDL_SetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, "0");
#endif

#ifdef MACOSX
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_PumpEvents();
    SDL_Event event;
    fs_log("OS X: Check for pending SDL_DROPFILE event\n");
    while (SDL_PollEvent(&event)) {
        fs_log("Got SDL event 0x%x\n", event.type);
        if (event.type == SDL_DROPFILE) {
            if (event.drop.file != NULL) {
                g_fs_uae_config_file_path = strdup(event.drop.file);
            }
            SDL_free(event.drop.file);
        }
    }
#endif

    // skip first entry
    arg = argv + 1;
    if (g_fs_uae_config_file_path == NULL) {
        while (arg && *arg) {
            const gchar *test_path = *arg;
            if (test_path && fs_path_exists(test_path)) {
                if (check_extension(test_path, ".fs-uae")) {
                    g_fs_uae_config_file_path = g_strdup(test_path);
                } else if (check_extension(test_path, ".conf")) {
                    g_fs_uae_config_file_path = g_strdup(test_path);
                } else if (check_extension(test_path, ".adf")) {
                    g_fs_uae_disk_file_path = g_strdup(test_path);
                } else if (check_extension(test_path, ".ipf")) {
                    g_fs_uae_disk_file_path = g_strdup(test_path);
                } else if (check_extension(test_path, ".dms")) {
                    g_fs_uae_disk_file_path = g_strdup(test_path);
                }
            }
            arg++;
        }
    }

    /* Parse options first, in case base_dir, logging  options etc is
     * specified on the command line. */
    fs_config_parse_options(argc - 1, argv + 1);

    fs_log("\n");
    fs_log(LOG_LINE);
    fs_log("libfsemu init\n");
    fs_log(LOG_LINE);
    fs_log("\n");

    fs_emu_path_set_expand_function(fs_uae_expand_path);

    fs_emu_init_overlays(overlay_names);
    fs_emu_init();

    // then load the config file
    load_config_file();

    init_i18n();

    if (g_fs_uae_disk_file_path) {
        fs_config_set_string(OPTION_FLOPPY_DRIVE_0, g_fs_uae_disk_file_path);
        g_warn_about_missing_config_file = 0;
    }

    if (g_warn_about_missing_config_file) {
        fs_emu_warning(_("No configuration file was found"));
    }

    fs_log("\n");
    fs_log(LOG_LINE);
    fs_log("fs-uae init\n");
    fs_log(LOG_LINE);
    fs_log("\n");

    configure_logging(fs_config_get_const_string("log"));
    fs_emu_set_state_check_function(amiga_get_state_checksum);
    fs_emu_set_rand_check_function(amiga_get_rand_checksum);

    // force creation of some recommended default directories
    fs_uae_kickstarts_dir();
    fs_uae_configurations_dir();
    fs_uae_init_path_resolver();

    fs_uae_plugins_init();

    // must be called early, before fs_emu_init -affects video output
    fs_uae_configure_amiga_model();

    // force creation of state directories
    //fs_uae_flash_memory_dir();
    //fs_uae_save_states_dir();
    //fs_uae_floppy_overlays_dir();
    fs_uae_state_dir();

    const char *controllers_dir = fs_uae_controllers_dir();
    if (controllers_dir) {
        fs_emu_set_controllers_dir(controllers_dir);
    }
    const char *logs_dir = fs_uae_logs_dir();
    if (logs_dir) {
        char *log_file;

        log_file = g_build_filename(logs_dir, "FS-UAE.log", NULL);
        if (fs_path_exists(log_file)) {
            g_unlink(log_file);
        }
        g_free(log_file);

        log_file = g_build_filename(logs_dir, "FS-UAE.log.txt", NULL);
        if (fs_path_exists(log_file)) {
            g_unlink(log_file);
        }
        g_free(log_file);

        log_file = g_build_filename(logs_dir, "Emulator.log.txt", NULL);
        if (fs_path_exists(log_file)) {
            g_unlink(log_file);
        }
        g_free(log_file);

        log_file = g_build_filename(logs_dir, "fs-uae.log.txt", NULL);
        fs_config_set_log_file(log_file);
        g_free(log_file);
    }

    fs_config_set_string_if_unset("themes_dir", fs_uae_themes_dir());

    fs_emu_set_pause_function(pause_function);

    //fs_uae_init_input();
    fs_emu_init_2(FS_EMU_INIT_EVERYTHING);

    // we initialize the recording module either it is used or not, so it
    // can delete state-specific recordings (if necessary) when states are
    // saved
    fs_uae_init_recording();

    int deterministic_mode = 0;
    const char* record_file = fs_config_get_const_string("record");
    if (record_file) {
        fs_log("record file specified: %s, forcing deterministic mode\n",
            record_file);
        deterministic_mode = 1;
        fs_uae_enable_recording(record_file);
    } else {
        fs_log("not running in record mode\n");
    }
    if (fs_emu_netplay_enabled() ||
            fs_config_get_boolean(OPTION_DETERMINISTIC) == 1) {
        deterministic_mode = 1;
    }
    if (deterministic_mode) {
        amiga_set_deterministic_mode();
    }

    if (logs_dir) {
        if (fs_emu_netplay_enabled()) {
            char *sync_log_file = g_build_filename(logs_dir,
                    "Synchronization.log", NULL);
            amiga_set_synchronization_log_file(sync_log_file);
            free(sync_log_file);
        }
    }

#ifdef FS_EMU_DRIVERS
    fs_emu_audio_stream_options **options = fs_emu_audio_alloc_stream_options(2);
    options[0]->frequency = fs_emu_audio_output_frequency();
    /* 12 * 2352 is CDDA_BUFFERS * 2352 (blkdev_cdimage.cpp) */
    options[1]->buffer_size = 12 * 2352;
    // begin playing with only one buffer queued
    options[1]->min_buffers = 1;
    fs_emu_audio_configure(options);
    amiga_set_audio_buffer_size(options[0]->buffer_size);
    fs_emu_audio_free_stream_options(options);
#else
    // this stream is for paula output and drive clicks
    // FIXME: could mix drive clicks in its own stream instead, -might
    // give higher quality mixing
    fs_emu_audio_stream_options options;
    options.struct_size = sizeof(fs_emu_audio_stream_options);
    fs_emu_init_audio_stream_options(&options);
    options.frequency = fs_emu_audio_output_frequency();
    fs_emu_init_audio_stream(0, &options);
    amiga_set_audio_buffer_size(options.buffer_size);

    // this stream is for CD audio output (CDTV/CD32)
    fs_emu_init_audio_stream_options(&options);
    // 12 * 2352 is CDDA_BUFFERS * 2352 (blkdev_cdimage.cpp)
    options.buffer_size = 12 * 2352;
    // begin playing with only one buffer queued
    options.min_buffers = 1;
    fs_emu_init_audio_stream(1, &options);
#endif

    amiga_set_audio_callback(audio_callback_function);
    amiga_set_cd_audio_callback(audio_callback_function);
    amiga_set_event_function(event_handler);

    amiga_set_led_function(led_function);
    amiga_on_update_leds(on_update_leds);

    amiga_set_media_function(media_function);
    amiga_set_init_function(on_init);

    if (fs_config_get_boolean(OPTION_JIT_COMPILER) == 1) {
        amiga_init_jit_compiler();
    }

#ifdef WITH_LUA
    amiga_init_lua(fs_emu_acquire_lua, fs_emu_release_lua);
    amiga_init_lua_state(fs_emu_get_lua_state());
    fs_uae_init_lua_state(fs_emu_get_lua_state());
#endif

    if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_RGBA) {
        amiga_set_video_format(AMIGA_VIDEO_FORMAT_RGBA);
    } else if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_BGRA) {
        amiga_set_video_format(AMIGA_VIDEO_FORMAT_BGRA);
    } else if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_R5G6B5) {
        amiga_set_video_format(AMIGA_VIDEO_FORMAT_R5G6B5);
    } else if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_R5G5B5A1) {
        amiga_set_video_format(AMIGA_VIDEO_FORMAT_R5G5B5A1);
    } else {
        fs_emu_warning("Unsupported video format requested");
    }
    amiga_add_rtg_resolution(672, 540);
    amiga_add_rtg_resolution(960, 540);
    amiga_add_rtg_resolution(672 * 2, 540 * 2);
    amiga_add_rtg_resolution(fs_emu_get_windowed_width(),
            fs_emu_get_windowed_height());
    amiga_add_rtg_resolution(fs_emu_get_fullscreen_width(),
            fs_emu_get_fullscreen_height());
    fs_uae_init_video();

    //fs_uae_init_keyboard();
    fs_uae_init_mouse();
    fs_uae_configure_menu();

    fs_emu_run(main_function);
    fs_log("fs-uae shutting down, fs_emu_run returned\n");
    if (g_rmdir(fs_uae_state_dir()) == 0) {
        fs_log("state dir %s was removed because it was empty\n",
                fs_uae_state_dir());
    }
    else {
        fs_log("state dir %s was not removed (non-empty)\n",
                fs_uae_state_dir());
    }
    fs_log("end of main function\n");
    cleanup_old_files();

#ifdef WITH_CEF
    cef_destroy();
#endif
    return 0;
}
Exemplo n.º 14
0
int select_toclean(const struct dirent *entry)
{
   printf("%s\n",entry->d_name);
   if ((entry->d_type==DT_REG) && ((check_extension(entry->d_name,".aux"))
                               || (check_extension(entry->d_name,".idx"))
                               || (check_extension(entry->d_name,".ind"))
                               || (check_extension(entry->d_name,".ilg"))
                               || (check_extension(entry->d_name,".log"))
                               || (check_extension(entry->d_name,".maf"))
                               || (check_extension(entry->d_name,".mtc"))
                               || (check_extension(entry->d_name,".out"))
                               || (check_extension(entry->d_name,".toc"))
                               || (check_extension(entry->d_name,".log"))
                               || (check_extension(entry->d_name,".bbl"))
                               || (check_extension(entry->d_name,".blg"))
                               || (reckon_mtc(entry->d_name))))
     return (1);
   else
     return (0);
}
Exemplo n.º 15
0
void
check_opengl_features(void)
{
	GL_vendor = xstrdup((char*)gl(GetString, GL_VENDOR));
	GL_renderer = xstrdup((char*)gl(GetString, GL_RENDERER));
	GL_version = xstrdup((char*)gl(GetString, GL_VERSION));
	/* according to opengl spec, the version string of opengl and
	 * glsl is 
	 *
	 * <version number> <space> <vendor spec information>
	 *
	 * and <version number> is
	 *
	 * major.minor
	 *
	 * or
	 *
	 * major.minor.release
	 *
	 * */

	/* build gl version */
	int err;
	err = sscanf(GL_version, "%d.%d", &GL_major_version, &GL_minor_version);
	assert(err == 2);
	assert((GL_major_version > 0) && (GL_major_version <= 3));
	assert(GL_minor_version > 0);
	GL_full_version = MKVER(GL_major_version, GL_minor_version);

	const char * tmp = (const char *)gl(GetString, GL_SHADING_LANGUAGE_VERSION);
	if (GL_POP_ERROR() != GL_NO_ERROR) {
		WARNING(OPENGL, "Doesn't support glsl\n");
		GL_glsl_version = NULL;
	} else {
		GL_glsl_version = xstrdup(tmp);

		err = sscanf(GL_glsl_version, "%d.%d", &GLSL_major_version, &GLSL_minor_version);
		assert(err == 2);
		assert(GLSL_major_version > 0);
		assert(GLSL_minor_version > 0);
		GLSL_full_version = MKVER(GLSL_major_version, GLSL_minor_version);
	}

	VERBOSE(OPENGL, "OpenGL engine information:\n");
	VERBOSE(OPENGL, "\tvendor: %s\n", GL_vendor);
	VERBOSE(OPENGL, "\trenderer: %s\n", GL_renderer);
	VERBOSE(OPENGL, "\tversion: %s\n", GL_version);
	VERBOSE(OPENGL, "\tglsl version: %s\n", GL_glsl_version);

	int x;
	gl(GetIntegerv, GL_SAMPLES, &x);
	VERBOSE(OPENGL, "\tSamples : %d\n", x);
	gl(GetIntegerv, GL_SAMPLE_BUFFERS, &x);
	VERBOSE(OPENGL, "\tSample buffers : %d\n", x);
	if (x > 0)
		gl(Enable, GL_MULTISAMPLE);
	if (GL_POP_ERROR())
		WARNING(OPENGL, "platform does not support multisample\n");

	gl(GetIntegerv, GL_MAX_TEXTURE_SIZE, &GL_max_texture_size);
	DEBUG(OPENGL, "system max texture size: %d\n", GL_max_texture_size);
	int conf_mts = conf_get_int("video.opengl.texture.maxsize", 0);
	if (conf_mts != 0) {
		conf_mts = pow2roundup(conf_mts);
		if (conf_mts < GL_max_texture_size)
			GL_max_texture_size = conf_mts;
	}
	DEBUG(OPENGL, "max texture size is set to %d\n", GL_max_texture_size);

	gl(GetIntegerv, GL_MAX_VERTEX_ATTRIBS, &GL_max_vertex_attribs);
	DEBUG(OPENGL, "max vertex attributes is set to %d\n", GL_max_vertex_attribs);

	build_extensions();
	assert(GL_extensions_dict != NULL);
	GL_POP_ERROR();

#define verbose_feature(name, exp) do {\
	if (exp)	\
		DEBUG(OPENGL, name " is enabled\n");	\
	else		\
		DEBUG(OPENGL, name " is disabled\n");	\
	} while(0)

	GL_texture_NPOT = check_extension("video.opengl.texture.enableNPOT",
			"GL_ARB_texture_non_power_of_two",
			NULL);
	verbose_feature("NPOT texture", GL_texture_NPOT);

	GL_texture_RECT = check_extension("video.opengl.texture.enableRECT",
			"GL_ARB_texture_rectangle",
			"GL_EXT_texture_rectangle",
			"GL_NV_texture_rectangle",
			NULL);
	verbose_feature("RECT texture", GL_texture_RECT);

	GL_texture_COMPRESSION = check_extension("video.opengl.texture.enableCOMPRESSION",
			"GL_ARB_texture_compression",
			NULL);
	verbose_feature("texture compression", GL_texture_COMPRESSION);

	GL_vertex_buffer_object = check_extension("video.opengl.enableVBO",
			"GL_ARB_vertex_buffer_object",
			NULL);
	GL_pixel_buffer_object = check_extension("video.opengl.enablePBO",
			"GL_ARB_pixel_buffer_object",
			NULL);
	GL_vertex_array_object = check_extension("video.opengl.enableVAO",
			"GL_ARB_vertex_array_object",
			NULL);
#undef verbose_feature
}
Exemplo n.º 16
0
/* 
   process the compiler options to form the correct set of options 
   for obtaining the preprocessor output
*/
static void process_args(int argc, char **argv)
{
	int i;
	int found_c_opt = 0;
	int found_S_opt = 0;
	struct stat st;
	char *e;

	stripped_args = args_init(0, NULL);

	args_add(stripped_args, argv[0]);

	for (i=1; i<argc; i++) {
		/* some options will never work ... */
		if (strcmp(argv[i], "-E") == 0) {
			failed();
		}

		/* these are too hard */
		if (strcmp(argv[i], "-fbranch-probabilities")==0 ||
		    strcmp(argv[i], "-M") == 0 ||
		    strcmp(argv[i], "-MM") == 0 ||
		    strcmp(argv[i], "-x") == 0) {
			cc_log("argument %s is unsupported\n", argv[i]);
			stats_update(STATS_UNSUPPORTED);
			failed();
			continue;
		}

		/* we must have -c */
		if (strcmp(argv[i], "-c") == 0) {
			args_add(stripped_args, argv[i]);
			found_c_opt = 1;
			continue;
		}

		/* -S changes the default extension */
		if (strcmp(argv[i], "-S") == 0) {
			args_add(stripped_args, argv[i]);
			found_S_opt = 1;
			continue;
		}
		
		/* we need to work out where the output was meant to go */
		if (strcmp(argv[i], "-o") == 0) {
			if (i == argc-1) {
				cc_log("missing argument to %s\n", argv[i]);
				stats_update(STATS_ARGS);
				failed();
			}
			output_file = argv[i+1];
			i++;
			continue;
		}
		
		/* alternate form of -o, with no space */
		if (strncmp(argv[i], "-o", 2) == 0) {
			output_file = &argv[i][2];
			continue;
		}

		/* debugging is handled specially, so that we know if we
		   can strip line number info 
		*/
		if (strncmp(argv[i], "-g", 2) == 0) {
			args_add(stripped_args, argv[i]);
			if (strcmp(argv[i], "-g0") != 0) {
				enable_unify = 0;
			}
			continue;
		}

		/* The user knows best: just swallow the next arg */
		if (strcmp(argv[i], "--ccache-skip") == 0) {
			i++;
			if (i == argc) {
				failed();
			}
			args_add(stripped_args, argv[i]);
			continue;
		}

		/* options that take an argument */
		{
			const char *opts[] = {"-I", "-include", "-imacros", "-iprefix",
					      "-iwithprefix", "-iwithprefixbefore",
					      "-L", "-D", "-U", "-x", "-MF", 
					      "-MT", "-MQ", "-isystem", "-aux-info",
					      "--param", "-A", "-Xlinker", "-u",
					      "-idirafter", 
					      NULL};
			int j;
			for (j=0;opts[j];j++) {
				if (strcmp(argv[i], opts[j]) == 0) {
					if (i == argc-1) {
						cc_log("missing argument to %s\n", 
						       argv[i]);
						stats_update(STATS_ARGS);
						failed();
					}
						
					args_add(stripped_args, argv[i]);
					args_add(stripped_args, argv[i+1]);
					i++;
					break;
				}
			}
			if (opts[j]) continue;
		}

		/* other options */
		if (argv[i][0] == '-') {
			args_add(stripped_args, argv[i]);
			continue;
		}

		/* if an argument isn't a plain file then assume its
		   an option, not an input file. This allows us to
		   cope better with unusual compiler options */
		if (stat(argv[i], &st) != 0 || !S_ISREG(st.st_mode)) {
			args_add(stripped_args, argv[i]);
			continue;			
		}

		if (input_file) {
			if (check_extension(argv[i], NULL)) {
				cc_log("multiple input files (%s and %s)\n",
				       input_file, argv[i]);
				stats_update(STATS_MULTIPLE);
			} else if (!found_c_opt) {
				cc_log("called for link with %s\n", argv[i]);
				if (strstr(argv[i], "conftest.")) {
					stats_update(STATS_CONFTEST);
				} else {
					stats_update(STATS_LINK);
				}
			} else {
				cc_log("non C/C++ file %s\n", argv[i]);
				stats_update(STATS_NOTC);
			}
			failed();
		}

		input_file = argv[i];
	}

	if (!input_file) {
		cc_log("No input file found\n");
		stats_update(STATS_NOINPUT);
		failed();
	}

	i_extension = check_extension(input_file, &direct_i_file);
	if (i_extension == NULL) {
		cc_log("Not a C/C++ file - %s\n", input_file);
		stats_update(STATS_NOTC);
		failed();
	}

	if (!found_c_opt) {
		cc_log("No -c option found for %s\n", input_file);
		/* I find that having a separate statistic for autoconf tests is useful,
		   as they are the dominant form of "called for link" in many cases */
		if (strstr(input_file, "conftest.")) {
			stats_update(STATS_CONFTEST);
		} else {
			stats_update(STATS_LINK);
		}
		failed();
	}


	/* don't try to second guess the compilers heuristics for stdout handling */
	if (output_file && strcmp(output_file, "-") == 0) {
		stats_update(STATS_OUTSTDOUT);
		failed();
	}

	if (!output_file) {
		char *p;
		output_file = x_strdup(input_file);
		if ((p = strrchr(output_file, '/'))) {
			output_file = p+1;
		}
		p = strrchr(output_file, '.');
		if (!p || !p[1]) {
			cc_log("badly formed output_file %s\n", output_file);
			stats_update(STATS_ARGS);
			failed();
		}
		p[1] = found_S_opt ? 's' : 'o';
		p[2] = 0;
	}

	/* cope with -o /dev/null */
	if (strcmp(output_file,"/dev/null") != 0 && stat(output_file, &st) == 0 && !S_ISREG(st.st_mode)) {
		cc_log("Not a regular file %s\n", output_file);
		stats_update(STATS_DEVICE);
		failed();
	}

	if ((e=getenv("CCACHE_PREFIX"))) {
		char *p = find_executable(e, MYNAME);
		if (!p) {
			perror(e);
			exit(1);
		}
		args_add_prefix(stripped_args, p);
	}
}
Exemplo n.º 17
0
LPNETSERVICE NM_NewService(struct _m4_client *term, struct _od_manager *owner, const char *url, LPNETSERVICE parent_service, M4Err *ret_code)
{
	LPNETSERVICE serv;
	u32 i;
	M4Err e;
	char *sURL, *ext, *mime_type;
	char szExt[50];
	NetClientPlugin *ifce;

	if (!url) {
		(*ret_code) = M4URLNotFound;
		return NULL;
	}

	if (parent_service && parent_service->url) {
		sURL = URL_Concatenate(parent_service->url, url);
		/*path was absolute*/
		if (!sURL) sURL = strdup(url);
	} else {
		sURL = strdup(url);
	}

	/*fetch a mime type if any. If error don't even attempt to open the service*/
	mime_type = NM_GetMimeType(term, sURL, &e);
	if (e) {
		free(sURL);
		(*ret_code) = e;
		return NULL;
	}
	
	if (mime_type && !stricmp(mime_type, "text/plain")) {
		free(mime_type);
		mime_type = NULL;
	}

	ifce = NULL;

	/*load from mime type*/
	if (mime_type) {
		char *sPlug = IF_GetKey(term->user->config, "MimeTypes", mime_type);
		if (sPlug) sPlug = strrchr(sPlug, '"');
		if (sPlug) {
			sPlug += 2;
			PM_LoadInterfaceByName(term->user->plugins, sPlug, M4STREAMINGCLIENT, (void **) &ifce);
			if (ifce && !net_check_interface(ifce) ) {
				PM_ShutdownInterface(ifce);
				ifce = NULL;
			}
		}
	}

	ext = strrchr(sURL, '.');
	/*no mime type: either local or streaming. If streaming discard extension checking*/
	if (!ifce && !mime_type && strstr(sURL, "://") && strnicmp(sURL, "file://", 7)) ext = NULL;

	/*browse extensions for prefered plugin*/
	if (!ifce && ext) {
		u32 keyCount;
		strcpy(szExt, &ext[1]);
		ext = strrchr(szExt, '#');
		if (ext) ext[0] = 0;

		keyCount = IF_GetKeyCount(term->user->config, "MimeTypes");
		for (i=0; i<keyCount; i++) {
			char *sMime, *sKey, *sPlug;
			sMime = (char *) IF_GetKeyName(term->user->config, "MimeTypes", i);
			if (!sMime) continue;
			sKey = IF_GetKey(term->user->config, "MimeTypes", sMime);
			if (!sKey) continue;
			if (!check_extension(sKey, szExt)) continue;
			sPlug = strrchr(sKey, '"');
			if (!sPlug) continue;	/*bad format entry*/
			sPlug += 2;

			PM_LoadInterfaceByName(term->user->plugins, sPlug, M4STREAMINGCLIENT, (void **) &ifce);
			if (!ifce) continue;
			if (!net_check_interface(ifce)) {
				PM_ShutdownInterface(ifce);
				ifce = NULL;
				continue;
			}
			break;
		}
	}

	/*browse all plugins*/
	if (!ifce) {
		for (i=0; i< PM_GetPluginsCount(term->user->plugins); i++) {
			PM_LoadInterface(term->user->plugins, i, M4STREAMINGCLIENT, (void **) &ifce);
			if (!ifce) continue;
			if (net_check_interface(ifce) && ifce->CanHandleURL(ifce, sURL)) break;
			PM_ShutdownInterface(ifce);
			ifce = NULL;
		}
	}

	if (mime_type) free(mime_type);

	if (!ifce) {
		free(sURL);
		(*ret_code) = M4UnsupportedURL;
		return NULL;
	}
	serv = malloc(sizeof(NetService));
	memset(serv, 0, sizeof(NetService));
	serv->term = term;
	serv->owner = owner;
	serv->ifce = ifce;
	serv->url = sURL;
	serv->Clocks = NewChain();
	serv->dnloads = NewChain();
	ChainAddEntry(term->net_services, serv);
	return serv;
}
Exemplo n.º 18
0
int		main(int ac, char **av)
{
  char		*image_path;
  char		*image_name;
  RectangleInfo *portion;
  struct dirent **names;
  int		nb;
  int		i = 0;
  int		j = 0;
  Image		*img;
  Image		*img_channel;
Image		*img_tmp;

  ac = ac;

  InitializeMagick("./");

  portion = malloc(sizeof(*portion));

  portion->width = 5538 - 3602;
  portion->height = 1523;
  portion->x = 3602;
  portion->y = 0;


  nb = scandir(av[1], &names, NULL, versionsort);
  while (i < nb)
    {
      if (check_extension(names[i]->d_name, ".jpeg"))
	{
	  printf("\rImage => %i", j);
	  fflush(stdout);
	  asprintf(&image_path, "%s/%s", av[1], names[i]->d_name);
	  if ((img = get_image_from_path(image_path)) == NULL)
	    printf("Failed to load the image from disk!\n");
	  /*	  asprintf(&image_name, "%i_rgb", j);
	  	  img = crop_image_from_path(image_path, portion);
		  dump_image(img, "/media/Data/histology/brain_2", image_name, "jpeg");
		  free(image_name); */

	  if ((img_channel = get_red_channe_image(img)) == NULL)
	    printf("Filed to extract the red channel from the image");
	  asprintf(&image_name, "%i_r", j);
	  dump_image(img_channel, "/media/Data/histology/brain_1_r", image_name, "jpeg");
	  DestroyImage(img_channel);
	  free(image_name);

	  if ((img_channel = get_green_channe_image(img)) == NULL)
	    printf("Filed to extract the green channel from the image");
	  asprintf(&image_name, "%i_g", j);
	  dump_image(img_channel, "/media/Data/histology/brain_1_g", image_name, "jpeg");
	  free(image_name);
	  DestroyImage(img_channel);

	  if ((img_channel = get_blue_channe_image(img)) == NULL)
	    printf("Filed to extract the blue channel from the image");
	  asprintf(&image_name, "%i_b", j);
	  dump_image(img_channel, "/media/Data/histology/brain_1_b", image_name, "jpeg");
	  free(image_name);
	  DestroyImage(img_channel);



	if ((img_tmp = apply_green_contrast(img, 0, 100)) == NULL)
	    printf("Filed to extract the - channel from the image");
	  asprintf(&image_name, "%i_gr", j);
	  dump_image(img_tmp, "/media/Data/histology/brain_1_gr", image_name, "jpeg");
	  free(image_name);

/*	  DestroyImage(img_channel); */

	if ((img_channel = get_green_grayscale_image(img_tmp)) == NULL)
	    printf("Filed to extract the - channel from the image");
	  asprintf(&image_name, "%i_g", j);
	  dump_image(img_channel, "/media/Data/histology/brain_1_gr", image_name, "jpeg");
	  free(image_name);
	 DestroyImage(img_tmp);

	img_tmp = img_channel;

	if ((img_channel = substract_grayscale_to_original(img, img_tmp, 20, 255)) == NULL)
	    printf("Filed to extract the - channel from the image");
	  asprintf(&image_name, "%i_final", j);
	  dump_image(img_channel, "/media/Data/histology/brain_1_gr", image_name, "jpeg");
	  free(image_name);
	  DestroyImage(img_channel);

	 DestroyImage(img_tmp);

	  DestroyImage(img);
	  free(image_path);
	  j++;
	}
      i++;
    }
  printf("\n");
  return (0);
}
Exemplo n.º 19
0
int main(int argc, char **argv)
{
	enum rd_sect_type type = RD_NONE;
	enum debug_t debug = 0;
	void *buf = NULL;
	int fd, sz, i;

	/* lame argument parsing: */

	while (1) {
		if ((argc > 1) && !strcmp(argv[1], "--verbose")) {
			debug |= PRINT_RAW | PRINT_VERBOSE;
			argv++;
			argc--;
			continue;
		}
		if ((argc > 1) && !strcmp(argv[1], "--expand")) {
			debug |= EXPAND_REPEAT;
			argv++;
			argc--;
			continue;
		}
		if ((argc > 1) && !strcmp(argv[1], "--short")) {
			/* only short dump, original shader, symbol table, and disassembly */
			full_dump = 0;
			argv++;
			argc--;
			continue;
		}
		if ((argc > 1) && !strcmp(argv[1], "--dump-shaders")) {
			dump_shaders = 1;
			argv++;
			argc--;
			continue;
		}

		break;
	}

	if (argc != 2) {
		fprintf(stderr, "usage: pgmdump [--verbose] [--short] [--dump-shaders] testlog.rd\n");
		return -1;
	}

	disasm_set_debug(debug);

	infile = argv[1];

	fd = open(infile, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "could not open: %s\n", infile);
		return -1;
	}

	/* figure out what sort of input we are dealing with: */
	if (!check_extension(infile, ".rd")) {
		int (*disasm)(uint32_t *dwords, int sizedwords, int level, enum shader_t type);
		enum shader_t shader = 0;
		int ret;

		if (check_extension(infile, ".vo")) {
			disasm = disasm_a2xx;
			shader = SHADER_VERTEX;
		} else if (check_extension(infile, ".fo")) {
			disasm = disasm_a2xx;
			shader = SHADER_FRAGMENT;
		} else if (check_extension(infile, ".vo3")) {
			disasm = disasm_a3xx;
			shader = SHADER_VERTEX;
		} else if (check_extension(infile, ".fo3")) {
			disasm = disasm_a3xx;
			shader = SHADER_FRAGMENT;
		} else if (check_extension(infile, ".co3")) {
			disasm = disasm_a3xx;
			shader = SHADER_COMPUTE;
		} else {
			fprintf(stderr, "invalid input file: %s\n", infile);
			return -1;
		}
		buf = calloc(1, 100 * 1024);
		ret = read(fd, buf, 100 * 1024);
		if (ret < 0) {
			fprintf(stderr, "error: %m");
			return -1;
		}
		return disasm(buf, ret/4, 0, shader);
	}

	while ((read(fd, &type, sizeof(type)) > 0) && (read(fd, &sz, 4) > 0)) {
		free(buf);

		/* note: allow hex dumps to go a bit past the end of the buffer..
		 * might see some garbage, but better than missing the last few bytes..
		 */
		buf = calloc(1, sz + 3);
		read(fd, buf, sz);

		switch(type) {
		case RD_TEST:
			if (full_dump)
				printf("test: %s\n", (char *)buf);
			break;
		case RD_VERT_SHADER:
			printf("vertex shader:\n%s\n", (char *)buf);
			break;
		case RD_FRAG_SHADER:
			printf("fragment shader:\n%s\n", (char *)buf);
			break;
		case RD_PROGRAM: {
			struct state state = {
					.buf = buf,
					.sz = sz,
			};
			printf("############################################################\n");
			printf("program:\n");
			dump_program(&state);
			printf("############################################################\n");
			break;
		}
		case RD_GPU_ID:
			gpu_id = *((unsigned int *)buf);
			printf("gpu_id: %d\n", gpu_id);
			break;
		}
	}

	return 0;
}
Exemplo n.º 20
0
Arquivo: main.c Projeto: whs1787/ffs
static int validate_args(args_t * args)
{
	assert(args != NULL);

	if (args->cmd == c_ERROR) {
		usage(args->short_name, false);
		UNEXPECTED("no command specified, please see --help "
			   "for details\n");
		return -1;
	}

	if (args->path == NULL) {
		UNEXPECTED("no path specified, please see --help "
			   "for details");
		return -1;
	}

	#define REQUIRED(name,cmd)	({				\
	if (args->name == NULL) {					\
		UNEXPECTED("--%s is required for the --%s command",	\
			   #name, #cmd);				\
		return -1;						\
	}								\
					})

	#define UNSUPPORTED(name,cmd)	({				\
	if (args->name != NULL) {					\
		UNEXPECTED("--%s is unsupported for the --%s command",	\
			   #name, #cmd);				\
		return -1;						\
	}								\
					})


	if (args->cmd == c_INJECT) {
		if (check_extension(args->path, ECC_EXT)) {
			UNEXPECTED("'%s' extension '%s' already exists "
				   "-- ignored", args->path, ECC_EXT);
			return -1;
		}

		if (args->file == NULL) {
			args->file = (char *)malloc(strlen(args->path) + 8);
			assert(args->file != NULL);
			sprintf((char *)args->file, "%s%s", args->path,
				ECC_EXT);

			if (args->force != f_FORCE)
				fprintf(stderr, "%s: --output <file> missing, "
				        "writing output to '%s'\n",
					args->short_name, args->file);
		}
	} else if (args->cmd == c_REMOVE) {
		if (!check_extension(args->path, ECC_EXT)) {
			UNEXPECTED("'%s' unknown extension, must be '%s' -- "
				   "ignored", args->path, ECC_EXT);
			return -1;
		}

		if (args->file == NULL) {
			args->file = strdup(args->path);
			assert(args->file != NULL);
			sprintf((char *)args->file, "%*s",
				(uint32_t)(strlen(args->path) - strlen(ECC_EXT)),
				args->path);

			fprintf(stderr, "%s: --output <file> missing, writing "
				"output to '%s'\n",
				args->short_name, args->file);
		}
	} else if (args->cmd == c_HEXDUMP) {
		if (!check_extension(args->path, ECC_EXT)) {
			UNEXPECTED("'%s' unknown extension, must be '%s' -- "
				   "ignored", args->path, ECC_EXT);
			return -1;
		}
	} else {
		UNEXPECTED("'%c' invalid command", args->cmd);
		return -1;
	}

	return 0;
}
Exemplo n.º 21
0
/* 
   process the compiler options to form the correct set of options 
   for obtaining the preprocessor output
*/
static void process_args(int argc, char **argv)
{
	int i;
	int found_c_opt = 0;
	int found_S_opt = 0;
	struct stat st;
	char *e;
	/* is gcc being asked to output dependencies? */
	int generating_dependencies = 0;
	/* is the dependency makefile name overridden with -MF? */
	int dependency_filename_specified = 0;
	/* is the dependency makefile target name specified with -MQ or -MF? */
	int dependency_target_specified = 0;


	stripped_args = args_init(0, NULL);

	args_add(stripped_args, argv[0]);

	/* -c not required for SWIG */
	if (swig) {
		found_c_opt = 1;
	}

	for (i=1; i<argc; i++) {
		/* some options will never work ... */
		if (strcmp(argv[i], "-E") == 0) {
			failed();
		}

		/* these are too hard */
		if (strcmp(argv[i], "-fbranch-probabilities")==0 ||
		    strcmp(argv[i], "-fprofile-arcs") == 0 ||
		    strcmp(argv[i], "-ftest-coverage") == 0 ||
		    strcmp(argv[i], "--coverage") == 0 ||
		    strcmp(argv[i], "-M") == 0 ||
		    strcmp(argv[i], "-MM") == 0 ||
		    strcmp(argv[i], "-x") == 0) {
			cc_log("argument %s is unsupported\n", argv[i]);
			stats_update(STATS_UNSUPPORTED);
			failed();
			continue;
		}

		/* we must have -c */
		if (strcmp(argv[i], "-c") == 0) {
			if (!strip_c_option) {
				args_add(stripped_args, argv[i]);
			}
			found_c_opt = 1;
			continue;
		}

		/* -S changes the default extension */
		if (strcmp(argv[i], "-S") == 0) {
			args_add(stripped_args, argv[i]);
			found_S_opt = 1;
			continue;
		}
		
		/* we need to work out where the output was meant to go */
		if (strcmp(argv[i], "-o") == 0) {
			if (i == argc-1) {
				cc_log("missing argument to %s\n", argv[i]);
				stats_update(STATS_ARGS);
				failed();
			}
			output_file = argv[i+1];
			i++;
			continue;
		}
		
		/* alternate form of -o, with no space */
		if (!swig) { /* some of SWIG's arguments begin with -o */
			if (strncmp(argv[i], "-o", 2) == 0) {
				output_file = &argv[i][2];
				continue;
			}
		}

		/* debugging is handled specially, so that we know if we
		   can strip line number info 
		*/
		if (strncmp(argv[i], "-g", 2) == 0) {
			args_add(stripped_args, argv[i]);
			if (strcmp(argv[i], "-g0") != 0) {
				enable_unify = 0;
			}
			continue;
		}

		/* The user knows best: just swallow the next arg */
		if (strcmp(argv[i], "--ccache-skip") == 0) {
			i++;
			if (i == argc) {
				failed();
			}
			args_add(stripped_args, argv[i]);
			continue;
		}

		/* These options require special handling, because they
		   behave differently with gcc -E, when the output
		   file is not specified. */

		if (strcmp(argv[i], "-MD") == 0 || strcmp(argv[i], "-MMD") == 0) {
			generating_dependencies = 1;
		} else if (strcmp(argv[i], "-MF") == 0) {
			dependency_filename_specified = 1;
		} else if (strcmp(argv[i], "-MQ") == 0 || strcmp(argv[i], "-MT") == 0) {
			dependency_target_specified = 1;
		}

		/* the input file is already preprocessed */
		if (swig && strcmp(argv[i], "-nopreprocess") == 0) {
			direct_i_file = 1;
			continue;
		}

		/* options that take an argument */
		{
			const char *opts[] = {"-I", "-include", "-imacros", "-iprefix",
					      "-iwithprefix", "-iwithprefixbefore",
					      "-L", "-D", "-U", "-x", "-MF", 
					      "-MT", "-MQ", "-isystem", "-aux-info",
					      "--param", "-A", "-Xlinker", "-u",
					      "-idirafter", 
					      NULL};
			int j;
			for (j=0;opts[j];j++) {
				if (strcmp(argv[i], opts[j]) == 0) {
					if (i == argc-1) {
						cc_log("missing argument to %s\n", 
						       argv[i]);
						stats_update(STATS_ARGS);
						failed();
					}
						
					args_add(stripped_args, argv[i]);
					args_add(stripped_args, argv[i+1]);
					i++;
					break;
				}
			}
			if (opts[j]) continue;
		}

		/* other options */
		if (argv[i][0] == '-') {
			args_add(stripped_args, argv[i]);
			continue;
		}

		/* if an argument isn't a plain file then assume its
		   an option, not an input file. This allows us to
		   cope better with unusual compiler options */
		if (stat(argv[i], &st) != 0 || !S_ISREG(st.st_mode)) {
			args_add(stripped_args, argv[i]);
			continue;			
		}

		if (input_file) {
			if (check_extension(argv[i], NULL)) {
				cc_log("multiple input files (%s and %s)\n",
				       input_file, argv[i]);
				stats_update(STATS_MULTIPLE);
			} else if (!found_c_opt) {
				cc_log("called for link with %s\n", argv[i]);
				if (strstr(argv[i], "conftest.")) {
					stats_update(STATS_CONFTEST);
				} else {
					stats_update(STATS_LINK);
				}
			} else {
				cc_log("non C/C++ file %s\n", argv[i]);
				stats_update(STATS_NOTC);
			}
			failed();
		}

		input_file = argv[i];
	}

	if (!input_file) {
		cc_log("No input file found\n");
		stats_update(STATS_NOINPUT);
		failed();
	}

	if (swig) {
		i_extension = check_extension(input_file, NULL);
	} else {
		i_extension = check_extension(input_file, &direct_i_file);
	}
	if (i_extension == NULL) {
		cc_log("Not a C/C++ file - %s\n", input_file);
		stats_update(STATS_NOTC);
		failed();
	}

	if (!found_c_opt) {
		cc_log("No -c option found for %s\n", input_file);
		/* I find that having a separate statistic for autoconf tests is useful,
		   as they are the dominant form of "called for link" in many cases */
		if (strstr(input_file, "conftest.")) {
			stats_update(STATS_CONFTEST);
		} else {
			stats_update(STATS_LINK);
		}
		failed();
	}


	/* don't try to second guess the compilers heuristics for stdout handling */
	if (output_file && strcmp(output_file, "-") == 0) {
		stats_update(STATS_OUTSTDOUT);
		failed();
	}

	if (!swig && !output_file) {
		char *p;
		output_file = x_strdup(input_file);
		if ((p = strrchr(output_file, '/'))) {
			output_file = p+1;
		}
		p = strrchr(output_file, '.');
		if (!p || !p[1]) {
			cc_log("badly formed output_file %s\n", output_file);
			stats_update(STATS_ARGS);
			failed();
		}
		p[1] = found_S_opt ? 's' : 'o';
		p[2] = 0;
	}

	/* If dependencies are generated, configure the preprocessor */

	if (generating_dependencies && output_file) {
		if (!dependency_filename_specified) {
			char *default_depfile_name = x_strdup(output_file);
			char *p = strrchr(default_depfile_name, '.');

			if (p) {
				if (strlen(p) < 2) {
					cc_log("badly formed dependency file %s\n", output_file);
					stats_update(STATS_ARGS);
					failed();
					return;
				}
				*p = 0;
			}
			else  {
				int len = p - default_depfile_name;
				
				p = x_malloc(len + 3);
				strncpy(default_depfile_name, p, len - 1);
				free(default_depfile_name);
				default_depfile_name = p;
			}

			strcat(default_depfile_name, ".d");
			args_add(stripped_args, "-MF");
			args_add(stripped_args, default_depfile_name);
		}

		if (!dependency_target_specified) {
			args_add(stripped_args, "-MT");
			args_add(stripped_args, output_file);
		}
	}

	/* cope with -o /dev/null */
	if (output_file && strcmp(output_file,"/dev/null") != 0 && stat(output_file, &st) == 0 && !S_ISREG(st.st_mode)) {
		cc_log("Not a regular file %s\n", output_file);
		stats_update(STATS_DEVICE);
		failed();
	}

	if ((e=getenv("CCACHE_PREFIX"))) {
		char *p = find_executable(e, MYNAME);
		if (!p) {
			cc_log("could not find executable (%s)\n", e);
			stats_update(STATS_ENVIRONMMENT);
			perror(e);
			exit(1);
		}
		args_add_prefix(stripped_args, p);
	}
}