Exemple #1
0
void
set_environment_tool_from_list( ASEnvironment *e, ASToolType type, char ** list, int list_len )
{
	int i ;
	destroy_string( &(e->tool_command[type]) );
	for( i = 0 ; i < list_len ; ++i ) 
		if( list[i] )
		{
			char *tmp = list[i] ;
			char *fullname = NULL ;
			if( tmp[0] == '$' ) 
				tmp = copy_replace_envvar( tmp );
			if( get_executable_in_path( tmp, &fullname ) ) 
			{
				e->tool_command[type] = fullname;
				break;
			}else
				show_warning( "%s command %s is not in the path", _as_tools_name[type], tmp );
			if (tmp != list[i])
				free(tmp);	  
		}	 
	if( e->tool_command[type] == NULL ) 
		e->tool_command[type] = as_get_default_tool(type);
	show_progress( "%s is set to: \"%s\"", _as_tools_name[type], e->tool_command[type]?e->tool_command[type]:"none" );
}
void
LoadBaseConfig(void (*read_base_options_func) (const char *))
{
	if( read_base_options_func == NULL ) 
		return ;

	if( Session == NULL )
	{
		show_error("Session has not been properly initialized. Exiting");
		exit(1);
	}

	if (Session->overriding_file == NULL )
	{
		char *configfile = make_session_file(Session, BASE_FILE, False/* no longer use #bpp in filenames */ );
		if( configfile != NULL )
		{
			read_base_options_func (configfile);
			show_progress("BASE configuration loaded from \"%s\" ...", configfile);
			free( configfile );
		}else
		{
			show_warning("BASE configuration file cannot be found");
		}
	}else
		read_base_options_func (Session->overriding_file);
}
Exemple #3
0
static int
call_show_warning(PyObject *category, PyObject *text, PyObject *message,
                  PyObject *filename, int lineno, PyObject *lineno_obj,
                  PyObject *sourceline, PyObject *source)
{
    PyObject *show_fn, *msg, *res, *warnmsg_cls = NULL;
    _Py_IDENTIFIER(_showwarnmsg);
    _Py_IDENTIFIER(WarningMessage);

    /* If the source parameter is set, try to get the Python implementation.
       The Python implementation is able to log the traceback where the source
       was allocated, whereas the C implementation doesn't. */
    show_fn = get_warnings_attr(&PyId__showwarnmsg, source != NULL);
    if (show_fn == NULL) {
        if (PyErr_Occurred())
            return -1;
        show_warning(filename, lineno, text, category, sourceline);
        return 0;
    }

    if (!PyCallable_Check(show_fn)) {
        PyErr_SetString(PyExc_TypeError,
                "warnings._showwarnmsg() must be set to a callable");
        goto error;
    }

    warnmsg_cls = get_warnings_attr(&PyId_WarningMessage, 0);
    if (warnmsg_cls == NULL) {
        if (!PyErr_Occurred()) {
            PyErr_SetString(PyExc_RuntimeError,
                    "unable to get warnings.WarningMessage");
        }
        goto error;
    }

    msg = PyObject_CallFunctionObjArgs(warnmsg_cls, message, category,
            filename, lineno_obj, Py_None, Py_None, source,
            NULL);
    Py_DECREF(warnmsg_cls);
    if (msg == NULL)
        goto error;

    res = PyObject_CallFunctionObjArgs(show_fn, msg, NULL);
    Py_DECREF(show_fn);
    Py_DECREF(msg);

    if (res == NULL)
        return -1;

    Py_DECREF(res);
    return 0;

error:
    Py_XDECREF(show_fn);
    return -1;
}
Exemple #4
0
void APP_CONFIGS::config_app_versions(PROJECT* p, bool show_warnings) {
    unsigned int i;
    for (i=0; i<app_configs.size(); i++) {
        APP_CONFIG& ac = app_configs[i];
        APP* app = gstate.lookup_app(p, ac.name);
        if (!app) {
            if (show_warnings) show_warning(p, ac.name);
            continue;
        }
        app->max_concurrent = ac.max_concurrent;
        if (!ac.gpu_gpu_usage || !ac.gpu_cpu_usage) continue;
        for (unsigned int j=0; j<gstate.app_versions.size(); j++) {
            APP_VERSION* avp = gstate.app_versions[j];
            if (avp->app != app) continue;
            if (!avp->gpu_usage.rsc_type) continue;
            avp->gpu_usage.usage = ac.gpu_gpu_usage;
            avp->avg_ncpus = ac.gpu_cpu_usage;
        }
    }
    for (i=0; i<app_version_configs.size(); i++) {
        APP_VERSION_CONFIG& avc = app_version_configs[i];
        APP* app = gstate.lookup_app(p, avc.app_name);
        if (!app) {
            if (show_warnings) show_warning(p, avc.app_name);
            continue;
        }
        for (unsigned int j=0; j<gstate.app_versions.size(); j++) {
            APP_VERSION* avp = gstate.app_versions[j];
            if (avp->app != app) continue;
            if (strcmp(avp->plan_class, avc.plan_class)) continue;
            if (strlen(avc.cmdline)) {
                strcpy(avp->cmdline, avc.cmdline);
            }
            if (avc.avg_ncpus) {
                avp->avg_ncpus = avc.avg_ncpus;
            }
            if (avc.ngpus) {
                avp->gpu_usage.usage = avc.ngpus;
            }
        }
    }
}
label_t *add_label (char *name, int value) {
	label_t *new_label;
	define_t *conflict_define;

	if (mode & MODE_CODE_COUNTER) {
		free(name);
		return NULL;
	}

	if (!case_sensitive) {
		char *new_name = strup (name);
		free (name);
		name = new_name;
	}

	if ((conflict_define = search_defines(name))) {
		show_error ("conflicting definition of '%s'", name);
		//if (suppress_errors == false) {
			show_error_prefix (conflict_define->input_file, conflict_define->line_num);
			WORD attr = save_console_attributes();
			set_console_attributes (COLOR_RED);
			printf ("previous definition of '%s' was here\n", name);
			restore_console_attributes(attr);
		//}
		return NULL;
	}
	
	if ((new_label = search_labels (name))) {
		if (value != new_label->value) {
			new_label->value = value;
			show_warning ("redefinition of '%s'", name);
			show_warning_prefix (new_label->input_file, new_label->line_num);
			WORD attr = save_console_attributes();
			set_console_attributes (COLOR_YELLOW);
			printf ("previous definition of '%s' was here\n", name);
			restore_console_attributes(attr);
		}
	} else {
		new_label = (label_t *)malloc (sizeof (label_t));
		
		if (new_label != NULL) {
			new_label->name = name;
			new_label->line_num = line_num;
			new_label->input_file = strdup(curr_input_file);
			new_label->value = value;
			
			hash_insert (label_table, new_label);
		}
		
	}
	return new_label;
}
Exemple #6
0
void buf_msg_show()
{
	if(done)
		return;

	if(triggered)
		show_warning(ttl, buf);

	free(ttl);
	free(buf);
	triggered = 0;
	done = 1;
}
Exemple #7
0
/*
 * Sets up output size and file header based on output options
 * Returns first z section to write, or negative for error.
*/
int set_output_options(ClipOptions *opt, MrcHeader *hout)
{
  int z = 0;

  /* create a new file */
  if (!opt->add2file){
    mrc_head_new(hout, opt->ox, opt->oy, opt->oz, opt->mode);
    if (mrc_head_write(hout->fp, hout))
      return -1;
  } else {
    if ((opt->ox != hout->nx) || (opt->oy != hout->ny)){
      opt->ox = hout->nx;
      opt->oy = hout->ny;
      show_warning("clip - Appended file can't change size.");
    }
    if (opt->mode != hout->mode){
      opt->mode = hout->mode;
      show_warning("clip - Appended file can't change mode.");
    }
    if (IP_APPEND_ADD == opt->add2file){

      /* If appending, scale mean down so complete mean can be computed
         by adding slice mean / new nz */
      z = hout->nz;
      hout->nz += opt->oz;
      hout->amean = z * hout->amean / hout->nz;
    } else{
      z = opt->isec;
      hout->nz = opt->oz + opt->isec;
    }
      
    if (mrc_head_write(hout->fp, hout))
      return -1;

    /* DNM 1/15/05: removed the calculation of data size and file seek */
  }
  return(z);
}
Exemple #8
0
void  handler_set_gravity( char *argv, void *trg, long param )
{
	    register int *i = trg ;
    *i = ForgetGravity ;
	if( argv )
	{

		if( mystrncasecmp( argv, "NorthWest", 9 )== 0 )	  *i = NorthWestGravity ; 
		else if( mystrncasecmp( argv, "SouthWest", 9 )== 0 )	  *i = SouthWestGravity ; 
		else if( mystrncasecmp( argv, "NorthEasth", 10 )== 0 )	*i = NorthEastGravity ; 
		else if( mystrncasecmp( argv, "SouthEast", 9 )== 0 )	  *i = SouthEastGravity ; 
		else if( mystrncasecmp( argv, "Center", 6 )== 0 )	  *i = CenterGravity ; 
		else if( mystrncasecmp( argv, "Static", 6 )== 0 )	  *i = StaticGravity ; 
		else show_warning( "unknown gravity type \"%s\". Use one of: NorthWest, SouthWest, NorthEast, SouthEast, Center, Static", argv );
	}
}
Exemple #9
0
void scroll_up_warning(bool change_direction) {
    text_index -= MAX_CHAR_UNDER_STATUS_BAR;
    if (change_direction) {
        text_index -= MAX_CHAR_UNDER_STATUS_BAR;
    }

    if (text_index <= MAX_CHAR_UNDER_STATUS_BAR) {
        show_warning();
        return;
    }

    gfx_fillRect(0, 8, 128, 56, SSD1306_BLACK);
    gfx_setCursor(0, 8);

    char buffer[MAX_CHAR_UNDER_STATUS_BAR] = {0};
    strncpy(buffer, warning_notice + text_index, MAX_CHAR_UNDER_STATUS_BAR);

    gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK);
    gfx_puts(buffer);
    gfx_update();
}
Exemple #10
0
void
LoadConfig (char *config_file_name,
						void (*read_options_func) (const char *))
{
	if (Session == NULL) {
		show_error ("Session has not been properly initialized. Exiting");
		exit (1);
	}
	if (Session->overriding_file == NULL) {
		char *configfile;
		const char *const_configfile;

		configfile = make_session_file (Session, config_file_name, False);
		if (configfile != NULL) {
			read_options_func (configfile);
			show_progress ("configuration loaded from \"%s\" ...", configfile);
			free (configfile);
		} else {
			show_warning ("configuration file \"%s\" cannot be found",
										config_file_name);
		}

		if ((const_configfile =
				 get_session_file (Session, 0, F_CHANGE_THEME, False)) != NULL) {
			read_options_func (const_configfile);
			show_progress ("THEME configuration loaded from \"%s\" ...",
										 const_configfile);
			if ((configfile =
					 make_session_data_file (Session, False, R_OK,
																	 THEME_OVERRIDE_FILE, NULL)) != NULL) {
				read_options_func (configfile);
				show_progress
						("THEME OVERRIDES configuration loaded from \"%s\" ...",
						 configfile);
				free (configfile);
			}
		}
	} else
		read_options_func (Session->overriding_file);
}
Exemple #11
0
int show_init_seafile_window ()
{
    gchar           *filename;
    gchar           *dir;
    int              response;
    GtkButton       *seafiledir_filechooser;
    GtkLabel        *seafiledir_label;

    filename = ccnet_file_lookup ("init-seafile-window.ui", "gtk");
    builder = gtk_builder_get_all_widgets (
        filename,
        "dialog", &dialog,
        "seafiledir_label", &seafiledir_label,
        "seafiledir_filechooser", &seafiledir_filechooser,
        NULL);
    g_free (filename);
    g_object_unref (builder);

again:
    response = gtk_dialog_run (dialog);
    if (response != 2) {
        gtk_widget_destroy (GTK_WIDGET(dialog));
        return -1;
    }

    dir = gtk_file_chooser_get_filename (
        (GtkFileChooser *)seafiledir_filechooser);
    if (!dir) {
        show_warning (GTK_WINDOW(dialog), NULL,
                      "A directory should be selected");
        goto again;
    } 

    applet->seafile_dir = g_build_filename(dir, "seafile-data", NULL);
    gtk_widget_destroy (GTK_WIDGET(dialog));
    return 0;
}
Exemple #12
0
Bool load_font (const char *name_in, MyFont * font)
#endif
{
	char *name;
	char *clean_name;
	int font_size = asxml_var_get ("font.size");

	if (font == NULL)
		return False;

	if (font_size <= 0)
		font_size = 14;

#if defined(LOG_FONT_CALLS) && defined(DEBUG_ALLOCS)
	log_call (file, line, "load_font", name);
#endif
	if (ASDefaultScr->font_manager == NULL) {
		char *path = getenv ("FONT_PATH");

		if (path == NULL)
			path = getenv ("PATH");
		ASDefaultScr->font_manager = create_font_manager (dpy, path, NULL);
	}

	name = name_in ? (char *)name_in : font->name;

	clean_name = name;
	if (clean_name != NULL) {
		int i = 0;
		register char *ptr = clean_name;

		while (ptr[i])
			++i;
		while (--i >= 0)
			if (!isdigit (ptr[i]))
				break;
		if ((isspace (ptr[i]) || ptr[i] == '-') && ptr[i + 1]) {
			font_size = atoi (&(ptr[i + 1]));
			while (i > 0 && isspace (ptr[i - 1]))
				--i;
			clean_name = mystrndup (name, i);
		}
	}
	if (clean_name != NULL) {
		if ((font->as_font =
				 get_asfont (ASDefaultScr->font_manager, clean_name, 0, font_size,
										 ASF_Freetype)) != NULL)
			show_progress ("Successfully loaded freetype font \"%s\"",
										 clean_name);
	}
	if (font->as_font == NULL && name != NULL) {
		if ((font->as_font =
				 get_asfont (ASDefaultScr->font_manager, name, 0, font_size,
										 ASF_GuessWho)) != NULL)
			show_progress ("Successfully loaded font \"%s\"", name);
	}
	if (font->as_font == NULL) {
		font->as_font =
				get_asfont (ASDefaultScr->font_manager, default_font, 0, font_size,
										ASF_GuessWho);
		show_warning ("failed to load font \"%s\" - using default instead",
									name);
	}

	if (clean_name && clean_name != name)
		free (clean_name);

	if (font->as_font != NULL && name != font->name)
		set_string (&(font->name), mystrdup (name));

	return (font->as_font != NULL);
}
Exemple #13
0
/*
 * Sets up variables for defining the input size and center, and section lists
 * for the 2D processing case, and also sets ox, oy,oz and output mode.
 */
void set_input_options(ClipOptions *opt, MrcHeader *hin)
{
  int i, zst, znd, ozst;

  if (opt->nofsecs == IP_DEFAULT){
    opt->nofsecs = hin->nz;
    opt->secs = (int *)malloc(sizeof(int) * hin->nz);
    for (i = 0; i < hin->nz; i++)
      opt->secs[i] = i;
     
  }
  if (opt->dim == 3){
    if (opt->iz == IP_DEFAULT){
      opt->iz = hin->nz;
    }
    if (opt->cz == IP_DEFAULT){
      opt->cz = hin->nz * 0.5f;
    }

    /* If there is no output entry, make it be same as input; but if there is,
       and it is smaller output, trim input to that size */
    if (opt->oz == IP_DEFAULT)
      opt->oz = opt->iz;
    else if (opt->iz > opt->oz)
      opt->iz = opt->oz;

    /* Set up a section list for the case where something is treated as
       2d without -2d being given */
    if (opt->nofsecs != IP_DEFAULT)
      free(opt->secs);
    zst = (int)floor(opt->cz - opt->iz / 2.);
    znd = B3DMAX(B3DMIN(zst + opt->iz - 1, hin->nz - 1), 0);
    zst = B3DMAX(B3DMIN(zst, hin->nz - 1), 0);
    opt->nofsecs = znd + 1 - zst;
    opt->secs = (int *)malloc(sizeof(int) * opt->nofsecs);
    for (i = zst; i <= znd; i++)
      opt->secs[i - zst] = i;

    /* If requested output is larger than this output set, keep track of 
       blank slices to put out before and after */
    if (opt->oz != IP_DEFAULT && opt->oz > opt->nofsecs) {
      ozst = (int)floor(opt->cz - opt->oz / 2.);
      opt->outBefore = B3DMAX(0, zst - ozst);
      opt->outAfter = opt->oz - opt->nofsecs - opt->outBefore;
      if (opt->outAfter < 0) {
        opt->outBefore += opt->outAfter;
        opt->outAfter = 0;
      }
    }
  } else {

    /* 2D case: use section list size for default output size */
    if (opt->oz == IP_DEFAULT)
      opt->oz = opt->nofsecs;
  }

  /* Convert starting, ending X or Y to ix/cx entries - main routine already
     checked for conflict */
  if (opt->x != IP_DEFAULT) {
    opt->x2 = B3DMAX(opt->x, opt->x2);
    opt->cx = (opt->x + opt->x2 + 1) / 2.;
    opt->ix = opt->x2 + 1 - opt->x;
  }
  if (opt->ix == IP_DEFAULT)
    opt->ix = hin->nx;
  if ((int)opt->cx == IP_DEFAULT)
    opt->cx = hin->nx * 0.5f;
  if (opt->ox == IP_DEFAULT) {
    opt->ox = opt->ix;
    if (opt->process == IP_UNPACK)
      opt->ox *= 2;
  } else {
    if (!opt->ocanresize){
      show_warning("clip - Process can't change output size.");
      opt->ox = opt->ix;
    }
  }

  if (opt->y != IP_DEFAULT) {
    opt->y2 = B3DMAX(opt->y, opt->y2);
    opt->cy = (opt->y + opt->y2 + 1) / 2.;
    opt->iy = opt->y2 + 1 - opt->y;
  }
  if (opt->iy == IP_DEFAULT)
    opt->iy = hin->ny;
  if ((int)opt->cy == IP_DEFAULT)
    opt->cy = hin->ny * 0.5f;
  if (opt->oy == IP_DEFAULT)
    opt->oy = opt->iy;
  else{
    if (!opt->ocanresize){
      show_warning("clip - Process can't change output size.");
      opt->oy = opt->iy;
    }
  }

  if (opt->pad == IP_DEFAULT)
    opt->pad = hin->amean;

  if (opt->mode == IP_DEFAULT)
    opt->mode = hin->mode;
}
Exemple #14
0
Bool
asimage2drawable_gl(	ASVisual *asv, Drawable d, ASImage *im,
                  		int src_x, int src_y, int dest_x, int dest_y,
        		  		int width, int height, int d_width, int d_height, 
						Bool force_direct )
{
	if( im != NULL && get_flags( asv->glx_support, ASGLX_Available ) && d != None )
	{
#ifdef HAVE_GLX
		int glbuf_size = (get_flags( asv->glx_support, ASGLX_RGBA )? 4 : 3 ) * width * height;
		CARD8 *glbuf = NULL;
		ASImageDecoder *imdec  = NULL ;
		GLXPixmap glxp = None;
		
		if ((imdec = start_image_decoding( asv, im, 
									   	get_flags( asv->glx_support, ASGLX_RGBA )?SCL_DO_ALL:SCL_DO_COLOR, 
									   	src_x, src_y, width, height, NULL)) != NULL )
		{	 
			int i, l = glbuf_size;
			glbuf = safemalloc( glbuf_size );
			for (i = 0; i < (int)height; i++)
			{	
				int k = width;
				imdec->decode_image_scanline( imdec ); 
				if( get_flags( asv->glx_support, ASGLX_RGBA ) ) 
				{	  
					while( --k >= 0 ) 
					{
						glbuf[--l] = imdec->buffer.alpha[k] ;
						glbuf[--l] = imdec->buffer.blue[k] ;
						glbuf[--l] = imdec->buffer.green[k] ;
						glbuf[--l] = imdec->buffer.red[k] ;
					}	 
				}else
				{	
					while( --k >= 0 ) 
					{
						glbuf[--l] = imdec->buffer.blue[k] ;
						glbuf[--l] = imdec->buffer.green[k] ;
						glbuf[--l] = imdec->buffer.red[k] ;
					}	 
				}
			}
			stop_image_decoding( &imdec );
		}else
			return False;

		if( !force_direct ) 
		{	
			glxp = glXCreateGLXPixmap( asv->dpy, &(asv->visual_info), d);
			/* d is either invalid drawable or is a window */
			if( glxp == None ) 
				force_direct = True ; 
		}                      
		if( glxp == None ) 
		{
			if( asv->glx_scratch_gc_direct	!= NULL )
				glXMakeCurrent (asv->dpy, d, asv->glx_scratch_gc_direct);
			else
				glXMakeCurrent (asv->dpy, d, asv->glx_scratch_gc_indirect);
		}else
			glXMakeCurrent (asv->dpy, glxp, asv->glx_scratch_gc_indirect);
		
		if( glGetError() != 0 ) 
			return False;

  		if ( get_flags( asv->glx_support, ASGLX_DoubleBuffer ) ) 
   			glDrawBuffer (GL_FRONT);

		glDisable(GL_BLEND);		/* optimize pixel transfer rates */
	  	glDisable (GL_DEPTH_TEST);
	  	glDisable (GL_DITHER);
	  	glDisable (GL_FOG);
	  	glDisable (GL_LIGHTING);

		glViewport( 0, 0, d_width, d_height);
		glMatrixMode (GL_PROJECTION);
		glLoadIdentity ();
		/* gluOrtho2D (0, d_width, 0, d_height); */
		glMatrixMode (GL_MODELVIEW);
		glLoadIdentity ();
		glTranslatef (0.375, 0.375, 0.0);


#if 1
		if( !IS_POWER_OF2(width) || !IS_POWER_OF2(height))
		{
			/* now put pixels on */
			glRasterPos2i( dest_x, d_height - (dest_y+height) );
			glDrawPixels(   width, height, 
							get_flags( asv->glx_support, ASGLX_RGBA )?GL_RGBA:GL_RGB, 
							GL_UNSIGNED_BYTE, glbuf );
		}else
#endif		
		{ /* this stuff might be faster : */
			GLuint texture ;

#define TARGET_TEXTURE_ID GL_TEXTURE_2D

#if TARGET_TEXTURE_ID!=GL_TEXTURE_2D
			glEnable(GL_TEXTURE_2D);
#endif			
			glEnable(TARGET_TEXTURE_ID);
			glGenTextures(1, &texture);

			glBindTexture(TARGET_TEXTURE_ID, texture);
	    	glTexParameteri(TARGET_TEXTURE_ID, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	     	glTexParameteri(TARGET_TEXTURE_ID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexImage2D(TARGET_TEXTURE_ID, 0, get_flags( asv->glx_support, ASGLX_RGBA )?GL_RGBA:GL_RGB, 
					      /* width and height must be the power of 2 !!! */
						  width, height, 
						  0, GL_RGBA, GL_UNSIGNED_BYTE, glbuf);

		 	glBegin(GL_QUADS);
			/* bottom-left */
		   	glTexCoord2d(0., 0.); glVertex2i(dest_x, d_height - (dest_y+height) );
			/* bottom-right */
		   	glTexCoord2d(1.0, 0.0); glVertex2i(dest_x+width, d_height - (dest_y+height));
			/* top-right */
		   	glTexCoord2d(1.0, 1.0); glVertex2i(dest_x+width, d_height - dest_y);    
			/* top-left */ 
		   	glTexCoord2d(0.0, 1.0); glVertex2i(dest_x, d_height - dest_y);
		   	glEnd();

			glBindTexture(TARGET_TEXTURE_ID, 0);
			glFinish();
		}							

		free( glbuf );
		glXMakeCurrent (asv->dpy, None, NULL);	  
		if( glxp ) 
			glXDestroyGLXPixmap( asv->dpy, glxp);
		glFinish(); 				   
		return True;
#endif /* #ifdef HAVE_GLX */
	}
	{
		static Bool warning_shown = False ; 
		if( !warning_shown ) 
		{
			warning_shown = True ;
			show_warning( "Support for GLX is unavailable.");
		}
	}
	return False;
}
Exemple #15
0
static PyObject *
warn_explicit(PyObject *category, PyObject *message,
              PyObject *filename, int lineno,
              PyObject *module, PyObject *registry, PyObject *sourceline)
{
    PyObject *key = NULL, *text = NULL, *result = NULL, *lineno_obj = NULL;
    PyObject *item = Py_None;
    const char *action;
    int rc;

    if (registry && !PyDict_Check(registry) && (registry != Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'registry' must be a dict");
        return NULL;
    }

    /* Normalize module. */
    if (module == NULL) {
        module = normalize_module(filename);
        if (module == NULL)
            return NULL;
    }
    else
        Py_INCREF(module);

    /* Normalize message. */
    Py_INCREF(message);  /* DECREF'ed in cleanup. */
    rc = PyObject_IsInstance(message, PyExc_Warning);
    if (rc == -1) {
        goto cleanup;
    }
    if (rc == 1) {
        text = PyObject_Str(message);
        if (text == NULL)
            goto cleanup;
        category = (PyObject*)message->ob_type;
    }
    else {
        text = message;
        message = PyObject_CallFunction(category, "O", message);
        if (message == NULL)
            goto cleanup;
    }

    lineno_obj = PyInt_FromLong(lineno);
    if (lineno_obj == NULL)
        goto cleanup;

    /* Create key. */
    key = PyTuple_Pack(3, text, category, lineno_obj);
    if (key == NULL)
        goto cleanup;

    if ((registry != NULL) && (registry != Py_None)) {
        rc = already_warned(registry, key, 0);
        if (rc == -1)
            goto cleanup;
        else if (rc == 1)
            goto return_none;
        /* Else this warning hasn't been generated before. */
    }

    action = get_filter(category, text, lineno, module, &item);
    if (action == NULL)
        goto cleanup;

    if (strcmp(action, "error") == 0) {
        PyErr_SetObject(category, message);
        goto cleanup;
    }

    /* Store in the registry that we've been here, *except* when the action
       is "always". */
    rc = 0;
    if (strcmp(action, "always") != 0) {
        if (registry != NULL && registry != Py_None &&
                PyDict_SetItem(registry, key, Py_True) < 0)
            goto cleanup;
        else if (strcmp(action, "ignore") == 0)
            goto return_none;
        else if (strcmp(action, "once") == 0) {
            if (registry == NULL || registry == Py_None) {
                registry = get_once_registry();
                if (registry == NULL)
                    goto cleanup;
            }
            /* _once_registry[(text, category)] = 1 */
            rc = update_registry(registry, text, category, 0);
        }
        else if (strcmp(action, "module") == 0) {
            /* registry[(text, category, 0)] = 1 */
            if (registry != NULL && registry != Py_None)
                rc = update_registry(registry, text, category, 0);
        }
        else if (strcmp(action, "default") != 0) {
            PyObject *to_str = PyObject_Str(item);
            const char *err_str = "???";

            if (to_str != NULL)
                err_str = PyString_AS_STRING(to_str);
            PyErr_Format(PyExc_RuntimeError,
                        "Unrecognized action (%s) in warnings.filters:\n %s",
                        action, err_str);
            Py_XDECREF(to_str);
            goto cleanup;
        }
    }

    if (rc == 1)  /* Already warned for this module. */
        goto return_none;
    if (rc == 0) {
        PyObject *show_fxn = get_warnings_attr("showwarning");
        if (show_fxn == NULL) {
            if (PyErr_Occurred())
                goto cleanup;
            show_warning(filename, lineno, text, category, sourceline);
        }
        else {
              PyObject *res;

              if (!PyMethod_Check(show_fxn) && !PyFunction_Check(show_fxn)) {
                  PyErr_SetString(PyExc_TypeError,
                                  "warnings.showwarning() must be set to a "
                                  "function or method");
                  Py_DECREF(show_fxn);
                  goto cleanup;
              }

              res = PyObject_CallFunctionObjArgs(show_fxn, message, category,
                                                  filename, lineno_obj,
                                                  NULL);
              Py_DECREF(show_fxn);
              Py_XDECREF(res);
              if (res == NULL)
                  goto cleanup;
        }
    }
    else /* if (rc == -1) */
        goto cleanup;

 return_none:
    result = Py_None;
    Py_INCREF(result);

 cleanup:
    Py_XDECREF(key);
    Py_XDECREF(text);
    Py_XDECREF(lineno_obj);
    Py_DECREF(module);
    Py_XDECREF(message);
    return result;  /* Py_None or NULL. */
}
Exemple #16
0
ASWindowBox *
ProcessWindowBoxOptions (FreeStorageElem * options)
{
	ConfigItem    item;
    ASWindowBox  *aswbox = NULL ;

	item.memory = NULL;

	for (; options; options = options->next)
	{
		if (options->term == NULL)
			continue;
        LOCAL_DEBUG_OUT( "WindowBox(%p)->options(%p)->keyword(\"%s\")", aswbox, options, options->term->keyword );
		if (options->term->id < WINDOWBOX_ID_START || options->term->id > WINDOWBOX_ID_END)
			continue;

		if (options->term->type == TT_FLAG)
		{
            if( aswbox != NULL  )
            {
                if( options->term->id == WINDOWBOX_DONE_ID )
                    break;                     /* for loop */
		        if (ReadFlagItem (&(aswbox->set_flags), &(aswbox->flags), options, WindowBoxFlagsXref))
        		    continue;
            }
            continue;
        }

		if (!ReadConfigItem (&item, options))
        {
            LOCAL_DEBUG_OUT( "ReadConfigItem has failed%s","");
			continue;
        }
		if( options->term->id == WINDOWBOX_START_ID )
		{
			if( aswbox != NULL )
			{
				show_error( "Unterminated WindowBox found - will be ignored" );
                destroy_aswindow_box( aswbox, False );
                aswbox = NULL ;
			}
			aswbox = create_aswindow_box( item.data.string );
			item.ok_to_free = 1;
		}else if( aswbox != NULL )
		{
			switch( options->term->id )
			{
				case WINDOWBOX_Area_ID   	  	  :
					aswbox->area = item.data.geometry;
		            set_flags( aswbox->set_flags, ASA_AreaSet);
			    break ;
                case WINDOWBOX_MinWidth_ID        :
                    aswbox->min_width = item.data.integer ;
                    set_flags( aswbox->set_flags, ASA_MinWidthSet);
                    break ;
                case WINDOWBOX_MinHeight_ID      :
                    aswbox->min_height = item.data.integer ;
                    set_flags( aswbox->set_flags, ASA_MinHeightSet);
                    break ;
                case WINDOWBOX_MaxWidth_ID        :
                    aswbox->max_width = item.data.integer ;
                    set_flags( aswbox->set_flags, ASA_MaxWidthSet);
                    break ;
                case WINDOWBOX_MaxHeight_ID      :
                    aswbox->max_height = item.data.integer ;
                    set_flags( aswbox->set_flags, ASA_MaxHeightSet);
                    break ;
                case WINDOWBOX_FirstTry_ID        :
					if( options->sub != NULL && options->sub->term->id >= FEEL_PLACEMENT_START_ID ) 
					{	
                    	aswbox->main_strategy = options->sub->term->id - FEEL_PLACEMENT_START_ID ;
                    	set_flags( aswbox->set_flags, ASA_MainStrategySet);
					}
                    break ;
                case WINDOWBOX_ThenTry_ID         :
					if( options->sub != NULL && options->sub->term->id >= FEEL_PLACEMENT_START_ID ) 
					{	
                    	aswbox->backup_strategy = options->sub->term->id - FEEL_PLACEMENT_START_ID ;
                    	set_flags( aswbox->set_flags, ASA_BackupStrategySet);
					}
                    break ;
                case WINDOWBOX_Desk_ID            :
                    aswbox->desk = item.data.integer ;
                    set_flags( aswbox->set_flags, ASA_DesktopSet);
                    break ;
                case WINDOWBOX_MinLayer_ID        :
                    aswbox->min_layer = item.data.integer ;
                    set_flags( aswbox->set_flags, ASA_MinLayerSet);
                    break ;
                case WINDOWBOX_MaxLayer_ID        :
                    aswbox->max_layer = item.data.integer ;
                    set_flags( aswbox->set_flags, ASA_MaxLayerSet);
                    break ;
                case WINDOWBOX_XSpacing_ID        :
                    aswbox->x_spacing = item.data.integer ;
                    set_flags( aswbox->set_flags, ASA_XSpacingSet);
                    break ;
                case WINDOWBOX_YSpacing_ID        :
                    aswbox->y_spacing = item.data.integer ;
                    set_flags( aswbox->set_flags, ASA_YSpacingSet);
                    break ;
                default:
					item.ok_to_free = 1;
                    show_warning( "Unexpected WindowBox definition keyword \"%s\" . Ignoring.", options->term->keyword );
			}
		}
    }
    LOCAL_DEBUG_OUT("done parsing WindowBox: [%s]", aswbox->name);
    ReadConfigItem (&item, NULL);
	return aswbox;
}
Exemple #17
0
void nsec_warning_show(void) {
    nsec_controls_add_handler(warning_handle_buttons);
    in_warning_page = true;
    show_warning();
}
Exemple #18
0
int main(int argc, char* argv[])
{
	char *image_file = "rose512.jpg" ;
	ASImage *im ;
	ASVisual *asv ;
	int screen = 0, depth = 24;
	Display *dpy = NULL;

	/* see ASView.1 : */
	set_application_name( argv[0] );
#if (HAVE_AFTERBASE_FLAG==1)
	set_output_threshold(OUTPUT_LEVEL_DEBUG);
#ifdef DEBUG_ALLOCS
	fprintf( stderr, "have DEBUG_ALLOCS\n");
#endif
#ifdef AFTERBASE_DEBUG_ALLOCS
	fprintf( stderr, "have AFTERBASE_DEBUG_ALLOCS\n");
#endif
#endif

	if( argc > 1 )
	{
		if( strcmp( argv[1], "-h" ) == 0 )
		{
			usage();
			return 0;
		}
		image_file = argv[1] ;
	}else
	{
		show_warning( 	"Image filename was not specified. "
						"Using default: \"%s\"", image_file );
		usage();
	}
#ifndef X_DISPLAY_MISSING
	dpy = XOpenDisplay(NULL);
	XSynchronize (dpy, True);
	_XA_WM_DELETE_WINDOW = XInternAtom( dpy, "WM_DELETE_WINDOW", 
										False);
	screen = DefaultScreen(dpy);
	depth = DefaultDepth( dpy, screen );
#endif	
	/* see ASView.3 : */
	asv = create_asvisual( dpy, screen, depth, NULL );
	/* asv = create_asvisual_for_id( dpy, screen, depth, 0x28, None, NULL ); */

	/* see ASView.2 : */
	im = file2ASImage( image_file, 0xFFFFFFFF, SCREEN_GAMMA, 0, getenv("IMAGE_PATH"), NULL );

	/* The following could be used to dump JPEG version of the image into
	 * stdout : */
	/* 	ASImage2file( im, NULL, NULL, ASIT_Jpeg, NULL ); 
		ASImage2file( im, NULL, "asview.png", ASIT_Png, NULL );
		ASImage2file( im, NULL, "asview.gif", ASIT_Gif, NULL );
	*/

	if( im != NULL )
	{
#ifndef X_DISPLAY_MISSING
		Window w ;
#if 0
		/* test example for get_asimage_channel_rects() : */
		XRectangle *rects ;	unsigned int rects_count =0; int i ;
		rects = get_asimage_channel_rects( im, IC_ALPHA, 10, 
											&rects_count );
		fprintf( stderr, " %d rectangles generated : \n", rects_count );
		for( i = 0 ; i < rects_count ; ++i )
			fprintf( stderr, "\trect[%d]=%dx%d%+d%+d;\n", 
					 i, rects[i].width, rects[i].height, 
					 rects[i].x, rects[i].y );
#endif


#if 0		 
		/* test example for fill_asimage : */
		fill_asimage(asv, im, 0, 0, 50, 50, 0xFFFF0000);
		fill_asimage(asv, im, 50, 50, 100, 50, 0xFFFF0000);
		fill_asimage(asv, im, 0, 100, 200, 50, 0xFFFF0000);
		fill_asimage(asv, im, 150, 0, 50, 50, 0xFFFF0000);
#endif
#if 0
		/* test example for conversion to argb32 :*/
		{
			ASImage *tmp = tile_asimage( asv, im, 0, 0, im->width, im->height, TINT_NONE, ASA_ARGB32, 
										  0, ASIMAGE_QUALITY_DEFAULT );	 
			destroy_asimage( &im );
			set_flags( tmp->flags, ASIM_DATA_NOT_USEFUL|ASIM_XIMAGE_NOT_USEFUL );
			im = tmp ;
		}		   
#endif		   
		/* see ASView.4 : */
		w = create_top_level_window( asv, DefaultRootWindow(dpy), 32, 32,
			                         im->width, im->height, 1, 0, NULL,
									 "ASView", image_file );
		if( w != None )
		{
			Pixmap p ;
	  		
			XMapRaised   (dpy, w);
			XSync(dpy,False);
			/* see ASView.5 : */
	  		p = create_visual_pixmap( asv, DefaultRootWindow(dpy), im->width, im->height, 0 );
	
			{
				START_TIME(started);
				/* for( int i = 0 ; i < 100 ; ++i )  To test performance! */
				asimage2drawable( asv, p, im, NULL, 0, 0, 0, 0, im->width, im->height, False);
				SHOW_TIME("", started);
			}
			/* print_storage(NULL); */
			destroy_asimage( &im );
			/* see common.c:set_window_background_and_free(): */
			p = set_window_background_and_free( w, p );
		}
		/* see common.c: wait_closedown() : */
		wait_closedown(w);
		dpy = NULL;
		
		/* no longer need this - lets clean it up :*/
		destroy_asvisual( asv, False );
		asv = NULL ;

#else
		/* writing result into the file */
		ASImage2file( im, NULL, "asview.png", ASIT_Png, NULL );
#endif
	}

#ifdef DEBUG_ALLOCS
    /* different cleanups of static memory pools : */
    flush_ashash_memory_pool();
	asxml_var_cleanup();
	custom_color_cleanup();
    build_xpm_colormap( NULL );
	flush_default_asstorage();
	/* requires libAfterBase */
	print_unfreed_mem();
#endif

    return 0 ;
}
Exemple #19
0
void
InitMyApp (  const char *app_class, int argc, char **argv, void (*version_func) (void), void (*custom_usage_func) (void), ASFlagType opt_mask )
{
    /* first of all let's set us some nice signal handlers */
#ifdef HAVE_SIGSEGV_HANDLING
    set_signal_handler (SIGSEGV);
#endif

	set_signal_handler (SIGUSR2);
    signal (SIGPIPE, ASDeadPipe);        /* don't forget DeadPipe should be provided by the app */

    SetMyClass( app_class );
    MyVersionFunc = version_func ;
    MyUsageFunc = custom_usage_func ;

    memset( &as_app_args, 0x00, sizeof(ASProgArgs) );
	as_app_args.locale = mystrdup(AFTER_LOCALE);
	if (as_app_args.locale[0] == '\0')
	{
		free( as_app_args.locale );
		as_app_args.locale = mystrdup(getenv("LANG"));
	}

    as_app_args.mask = opt_mask ;
	as_app_args.gravity = ForgetGravity ;
#ifndef NO_DEBUG_OUTPUT
    as_app_args.verbosity_level = OUTPUT_VERBOSE_THRESHOLD ;
#else
    as_app_args.verbosity_level = OUTPUT_DEFAULT_THRESHOLD ;
#endif

/* Uncomment this to enable cmd line args tracing/debugging :    
 * set_output_threshold(20); */

    ASDefaultScr = safecalloc(1, sizeof(ScreenInfo));
	init_ScreenInfo(ASDefaultScr);
show_debug (__FILE__,__FUNCTION__,__LINE__, "argc = %d", argc);

    if( argc > 0 && argv )
    {
        int i ;

		as_app_args.saved_argc = argc ;
		as_app_args.saved_argv = safecalloc( argc, sizeof(char*));
		for( i = 0 ; i < argc ; ++i )
			as_app_args.saved_argv[i] = mystrdup(argv[i]) ;

        SetMyName( argv[0] );

        for( i = 1 ; i < argc ; i++ )
        {
            register int opt ;
show_debug (__FILE__,__FUNCTION__,__LINE__, "i = %d, argv[i] = 0x%p", i, argv[i]);			
            if( (opt = match_command_line_opt( &(argv[i][0]), as_standard_cmdl_options )) < 0 )
                continue;
            if( get_flags( (0x01<<opt), as_app_args.mask) )
                continue;
            if( get_flags( as_standard_cmdl_options[opt].flags, CMO_HasArgs ) )
            {
				argv[i] = NULL ;
                if( ++i >= argc )
                    continue;
                else
                    as_standard_cmdl_options[opt].handler( argv[i], as_standard_cmdl_options[opt].trg, as_standard_cmdl_options[opt].param );
            }else
                as_standard_cmdl_options[opt].handler( NULL, as_standard_cmdl_options[opt].trg, as_standard_cmdl_options[opt].param );
            argv[i] = NULL ;
        }
    }

    set_output_threshold( as_app_args.verbosity_level );
    if(as_app_args.log_file)
		if( freopen( as_app_args.log_file, /*get_flags( as_app_args.flags, ASS_Restarting)?*/"a"/*:"w"*/, stderr ) == NULL )
	    	show_system_error( "failed to redirect output into file \"%s\"", as_app_args.log_file );


    fd_width = get_fd_width ();

    if (FuncSyntax.term_hash == NULL)
		PrepareSyntax (&FuncSyntax);
	if( as_app_args.locale == NULL ) 
		as_app_args.locale = mystrdup("");
	if( as_app_args.locale && strlen(as_app_args.locale) > 0)
	{
		as_set_charset( parse_charset_name( as_app_args.locale ));
#ifdef I18N
		if (strlen(as_app_args.locale) > 0)
			if (setlocale (LC_CTYPE, as_app_args.locale) == NULL)
			{
  			    show_error ("unable to set locale");
			}
#endif
	}else
	{
#ifdef I18N
	    show_warning ("LANG environment variable is not set - use -L \"locale\" command line option to define locale");
#endif
	}	

#ifdef DEBUG_TRACE_X
    trace_enable_function(as_app_args.trace_calls);
#endif

	asxml_var_insert(ASXMLVAR_IconButtonWidth, 64);
	asxml_var_insert(ASXMLVAR_IconButtonHeight, 64);
	asxml_var_insert(ASXMLVAR_IconWidth, 48);
	asxml_var_insert(ASXMLVAR_IconHeight, 48);
	asxml_var_insert(ASXMLVAR_MinipixmapWidth, 24);
	asxml_var_insert(ASXMLVAR_MinipixmapHeight, 24);
	asxml_var_insert(ASXMLVAR_TitleFontSize, 14);
	asxml_var_insert(ASXMLVAR_MenuFontSize, 16);
	asxml_var_insert(ASXMLVAR_MenuShowMinipixmaps, 1);
	asxml_var_insert(ASXMLVAR_MenuShowUnavailable, 1);

}
Exemple #20
0
Bool
ReloadASEnvironment (ASImageManager ** old_imageman,
										 ASFontManager ** old_fontman,
										 BaseConfig ** config_return, Bool flush_images,
										 Bool support_shared_images)
{
	char *old_pixmap_path = NULL;
	char *old_font_path = NULL;
	char *configfile = NULL;
	BaseConfig *config = NULL;
	ASEnvironment *e = NULL;
	ScreenInfo *scr = get_current_screen ();

	if (Environment != NULL) {
		old_pixmap_path = Environment->pixmap_path;
		Environment->pixmap_path = NULL;
		old_font_path = Environment->font_path;
		Environment->font_path = NULL;
	}

	configfile = Session->overriding_file;
	if (configfile == NULL)
		configfile =
				make_session_file (Session, BASE_FILE,
													 False /* no longer use #bpp in filenames */ );
	if (configfile != NULL) {
		config = ParseBaseOptions (configfile, MyName);
		if (config != NULL)
			show_progress ("BASE configuration loaded from \"%s\" ...",
										 configfile);
		else
			show_progress ("BASE could not be loaded from \"%s\" ...",
										 configfile);
		if (configfile != Session->overriding_file)
			free (configfile);
	} else
		show_warning ("BASE configuration file cannot be found");

	if (config == NULL) {
		if (Environment != NULL) {
			Environment->pixmap_path = old_pixmap_path;
			Environment->font_path = old_font_path;
			return False;
		}
		/* otherwise we should use default values  - Environment should never be NULL */
		Environment = make_default_environment ();
	} else {
		BaseConfig2ASEnvironment (config, &Environment);
		if (config_return)
			*config_return = config;
		else
			DestroyBaseConfig (config);
	}

	e = Environment;
	/* Save base filename to pass to modules */
	if (mystrcmp (old_pixmap_path, e->pixmap_path) == 0 ||
			(e->pixmap_path != NULL && scr->image_manager == NULL)
			|| flush_images) {
		reload_screen_image_manager (scr, old_imageman);
	}
	if (old_pixmap_path && old_pixmap_path != e->pixmap_path)
		free (old_pixmap_path);

	if (mystrcmp (old_font_path, e->font_path) == 0
			|| (e->font_path != NULL && scr->font_manager == NULL)) {
		if (old_fontman) {
			*old_fontman = scr->font_manager;
		} else if (scr->font_manager)
			destroy_font_manager (scr->font_manager, False);

		scr->font_manager = create_font_manager (dpy, e->font_path, NULL);
		set_xml_font_manager (scr->font_manager);
		show_progress ("Font Path changed to \"%s\" ...",
									 e->font_path ? e->font_path : "");
	}
	if (old_font_path && old_font_path != e->font_path)
		free (old_font_path);

	if (e->desk_pages_h > 0) {
		if (e->desk_pages_h <= 100)
			scr->VxMax = (e->desk_pages_h - 1) * scr->MyDisplayWidth;
		else {
			scr->VxMax =
					MAX (e->desk_pages_h, scr->MyDisplayWidth) - scr->MyDisplayWidth;
			e->desk_pages_h =
					(e->desk_pages_h + scr->MyDisplayWidth -
					 1) / scr->MyDisplayWidth;
		}
	} else
		scr->VxMax = 0;
	if (e->desk_pages_v > 0) {
		if (e->desk_pages_v <= 100)
			scr->VyMax = (e->desk_pages_v - 1) * scr->MyDisplayHeight;
		else {
			scr->VyMax =
					MAX (e->desk_pages_v,
							 scr->MyDisplayHeight) - scr->MyDisplayHeight;
			e->desk_pages_v =
					(e->desk_pages_v + scr->MyDisplayHeight -
					 1) / scr->MyDisplayHeight;
		}
	} else
		scr->VyMax = 0;

	scr->VScale = e->desk_scale;
	if (scr->VScale <= 1)
		scr->VScale = 2;
	else if (scr->VScale >= scr->MyDisplayHeight / 2)
		scr->VScale = scr->MyDisplayHeight / 2;

#ifdef XSHMIMAGE
	if (support_shared_images) {
		if (get_flags (e->flags, ASE_NoSharedMemory))
			disable_shmem_images ();
		else
			enable_shmem_images ();
	}
	SHOW_CHECKPOINT;
#endif


	return (config != NULL);
}
Exemple #21
0
static PyObject *
warn_explicit(PyObject *category, PyObject *message,
              PyObject *filename, int lineno,
              PyObject *module, PyObject *registry, PyObject *sourceline)
{
    PyObject *key = NULL, *text = NULL, *result = NULL, *lineno_obj = NULL;
    PyObject *item = Py_None;
    PyObject *action;
    int rc;

    /* module can be None if a warning is emitted late during Python shutdown.
       In this case, the Python warnings module was probably unloaded, filters
       are no more available to choose as action. It is safer to ignore the
       warning and do nothing. */
    if (module == Py_None)
        Py_RETURN_NONE;

    if (registry && !PyDict_Check(registry) && (registry != Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'registry' must be a dict");
        return NULL;
    }

    /* Normalize module. */
    if (module == NULL) {
        module = normalize_module(filename);
        if (module == NULL)
            return NULL;
    }
    else
        Py_INCREF(module);

    /* Normalize message. */
    Py_INCREF(message);  /* DECREF'ed in cleanup. */
    rc = PyObject_IsInstance(message, PyExc_Warning);
    if (rc == -1) {
        goto cleanup;
    }
    if (rc == 1) {
        text = PyObject_Str(message);
        if (text == NULL)
            goto cleanup;
        category = (PyObject*)message->ob_type;
    }
    else {
        text = message;
        message = PyObject_CallFunction(category, "O", message);
        if (message == NULL)
            goto cleanup;
    }

    lineno_obj = PyLong_FromLong(lineno);
    if (lineno_obj == NULL)
        goto cleanup;

    /* Create key. */
    key = PyTuple_Pack(3, text, category, lineno_obj);
    if (key == NULL)
        goto cleanup;

    if ((registry != NULL) && (registry != Py_None)) {
        rc = already_warned(registry, key, 0);
        if (rc == -1)
            goto cleanup;
        else if (rc == 1)
            goto return_none;
        /* Else this warning hasn't been generated before. */
    }

    action = get_filter(category, text, lineno, module, &item);
    if (action == NULL)
        goto cleanup;

    if (PyUnicode_CompareWithASCIIString(action, "error") == 0) {
        PyErr_SetObject(category, message);
        goto cleanup;
    }

    /* Store in the registry that we've been here, *except* when the action
       is "always". */
    rc = 0;
    if (PyUnicode_CompareWithASCIIString(action, "always") != 0) {
        if (registry != NULL && registry != Py_None &&
                PyDict_SetItem(registry, key, Py_True) < 0)
            goto cleanup;
        else if (PyUnicode_CompareWithASCIIString(action, "ignore") == 0)
            goto return_none;
        else if (PyUnicode_CompareWithASCIIString(action, "once") == 0) {
            if (registry == NULL || registry == Py_None) {
                registry = get_once_registry();
                if (registry == NULL)
                    goto cleanup;
            }
            /* _once_registry[(text, category)] = 1 */
            rc = update_registry(registry, text, category, 0);
        }
        else if (PyUnicode_CompareWithASCIIString(action, "module") == 0) {
            /* registry[(text, category, 0)] = 1 */
            if (registry != NULL && registry != Py_None)
                rc = update_registry(registry, text, category, 0);
        }
        else if (PyUnicode_CompareWithASCIIString(action, "default") != 0) {
            PyErr_Format(PyExc_RuntimeError,
                        "Unrecognized action (%R) in warnings.filters:\n %R",
                        action, item);
            goto cleanup;
        }
    }

    if (rc == 1)  /* Already warned for this module. */
        goto return_none;
    if (rc == 0) {
        PyObject *show_fxn = get_warnings_attr("showwarning");
        if (show_fxn == NULL) {
            if (PyErr_Occurred())
                goto cleanup;
            show_warning(filename, lineno, text, category, sourceline);
        }
        else {
            PyObject *res;

            if (!PyCallable_Check(show_fxn)) {
                PyErr_SetString(PyExc_TypeError,
                                "warnings.showwarning() must be set to a "
                                "callable");
                Py_DECREF(show_fxn);
                goto cleanup;
            }

            res = PyObject_CallFunctionObjArgs(show_fxn, message, category,
                                                filename, lineno_obj,
                                                NULL);
            Py_DECREF(show_fxn);
            Py_XDECREF(res);
            if (res == NULL)
                goto cleanup;
        }
    }
    else /* if (rc == -1) */
        goto cleanup;

 return_none:
    result = Py_None;
    Py_INCREF(result);

 cleanup:
    Py_XDECREF(key);
    Py_XDECREF(text);
    Py_XDECREF(lineno_obj);
    Py_DECREF(module);
    Py_XDECREF(message);
    return result;  /* Py_None or NULL. */
}