Пример #1
0
hw_string* create_response_buffer(hw_http_response* response)
{
    http_response* resp = (http_response*)response;
    hw_string* response_string = malloc(sizeof(hw_string));
    hw_string* cached_entry = get_cached_request(resp->status_code.value);
    hw_string content_length;

    int i = 0;
	int length_plus = 3;
	const char *text_lead = "text/html";

    response_string->value = calloc(1024 * 1024, 1);
    response_string->length = 0;
    append_string(response_string, cached_entry);
    
    for (i=0; i< resp->number_of_headers; i++)
    {
        http_header header = resp->headers[i];
        append_string(response_string, &header.name);
        APPENDSTRING(response_string, ": ");
        append_string(response_string, &header.value);
        APPENDSTRING(response_string, CRLF);
    }

	//Check the plus length by checking header<content-type>
	for(i=0; i< resp->number_of_headers; ++i)
	{
		http_header header = resp->headers[i];
		if ( ! strcmp(header.name.value, "Content-Type") )
		{
			//~ A text based page.(content)
			//if ( strncmp(header.value.value, text_lead, strlen(text_lead)))
			if (strcmp(header.value.value, text_lead))
			{
				// Not a text-lead
				length_plus = 0;
			}
			break;
		}
	}
    
    /* Add the body */
    APPENDSTRING(response_string, "Content-Length: ");
    
    string_from_int(&content_length, resp->body.length + length_plus, 10);
    append_string(response_string, &content_length);
    APPENDSTRING(response_string, CRLF CRLF);
    
    if (resp->body.length > 0)
    {
        append_string(response_string, &resp->body);
    }
    APPENDSTRING(response_string, CRLF);
    return response_string;
}
Пример #2
0
hw_string* create_response_buffer(hw_http_response* response)
{
    http_response* resp = (http_response*)response;
    hw_string* response_string = malloc(sizeof(hw_string));
    hw_string* cached_entry = get_cached_request(resp->status_code.value);
    hw_string content_length;

    int i = 0;

    char length_header[] = "Content-Length: ";
    int line_sep_size = sizeof(CRLF);

    int header_buffer_incr = 512;
    int body_size = resp->body.length + line_sep_size;
    int header_size_remaining = header_buffer_incr;
    int response_size = header_size_remaining + sizeof(length_header) + num_chars(resp->body.length) + 2 * line_sep_size + body_size + line_sep_size;

    response_string->value = malloc(response_size);

    response_string->length = 0;
    append_string(response_string, cached_entry);
    
    for (i=0; i< resp->number_of_headers; i++)
    {
        http_header header = resp->headers[i];

        header_size_remaining -= header.name.length + 2 + header.value.length + line_sep_size;
        if (header_size_remaining < 0) {
            header_size_remaining += header_buffer_incr * ((-header_size_remaining/header_buffer_incr) + 1);
            response_size += header_size_remaining;
            response_string->value = realloc(response_string->value, response_size);
        }

        append_string(response_string, &header.name);
        APPENDSTRING(response_string, ": ");
        append_string(response_string, &header.value);
        APPENDSTRING(response_string, CRLF);
    }
    
    /* Add the body */
    APPENDSTRING(response_string, length_header);

    string_from_int(&content_length, body_size, 10);
    append_string(response_string, &content_length);
    APPENDSTRING(response_string, CRLF CRLF);
    
    if (resp->body.length > 0)
    {
        append_string(response_string, &resp->body);
    }
    APPENDSTRING(response_string, CRLF);
    response_string->value[response_string->length] = '\0';
    return response_string;
}
Пример #3
0
hw_string* create_response_buffer(hw_http_response* response)
{
    http_response* resp = (http_response*)response;
    hw_string* response_string = malloc(sizeof(hw_string));
    hw_string* cached_entry = get_cached_request(resp->status_code.value);
    hw_string content_length;

    int i = 0;

    response_string->value = calloc(1024, 1);
    response_string->length = 0;
    append_string(response_string, cached_entry);
    
    for (i=0; i< resp->number_of_headers; i++)
    {
        http_header header = resp->headers[i];
        append_string(response_string, &header.name);
        APPENDSTRING(response_string, ": ");
        append_string(response_string, &header.value);
        APPENDSTRING(response_string, CRLF);
    }
    
    /* Add the body */
    APPENDSTRING(response_string, "Content-Length: ");
    
    string_from_int(&content_length, resp->body.length + 3, 10);
    append_string(response_string, &content_length);
    APPENDSTRING(response_string, CRLF CRLF);
    
    if (resp->body.length > 0)
    {
        append_string(response_string, &resp->body);
    }
    APPENDSTRING(response_string, CRLF);
    return response_string;
}
Пример #4
0
const char* config_string( hash_t section, hash_t key )
{
	config_key_t* key_val = config_key( section, key, false );
	if( !key_val )
		return "";
	//Convert to string
	/*lint --e{788} We use default for remaining enums */
	switch( key_val->type )
	{
		case CONFIGVALUE_BOOL:  return key_val->bval ? "true" : "false";
		case CONFIGVALUE_INT:   if( !key_val->sval ) key_val->sval = string_from_int( key_val->ival, 0, 0 ); return key_val->sval;
		case CONFIGVALUE_REAL:  if( !key_val->sval ) key_val->sval = string_from_real( key_val->rval, 4, 0, '0' ); return key_val->sval;
		default: break;
	}
	//String value of some form
	if( !key_val->sval )
		return "";
	if( key_val->type >= CONFIGVALUE_STRING_VAR )
	{
		_expand_string_val( section, key_val );
		return key_val->expanded;
	}
	return key_val->sval;
}
Пример #5
0
DECLARE_TEST( fs, query )
{
	uint64_t subpathid = random64();
	uint64_t subfileid = random64();
	char* testpath = path_merge( environment_temporary_directory(), string_from_int_static( random64(), 0, 0 ) );
	char* subtestpath = path_merge( testpath, string_from_int_static( subpathid, 0, 0 ) );
	char* filepath[8];
	char** subdirs;
	char** files;
	int ifp = 0;
	char* subfilepath;

	if( fs_is_file( testpath ) )
		fs_remove_file( testpath );
	if( !fs_is_directory( testpath ) )
		fs_make_directory( testpath );
	if( !fs_is_directory( subtestpath ) )
		fs_make_directory( subtestpath );

	for( ifp = 0; ifp < 8; ++ifp )
	{
		filepath[ifp] = path_merge( testpath, string_from_int_static( random64(), 0, 0 ) );
		filepath[ifp] = string_append( string_append( filepath[ifp], "." ), string_from_int_static( ifp, 0, 0 ) );
		stream_deallocate( fs_open_file( filepath[ifp], STREAM_OUT ) );
	}

	subfilepath = path_merge( subtestpath, string_from_int_static( subfileid, 0, 0 ) );
	subfilepath = string_append( subfilepath, ".0" );
	stream_deallocate( fs_open_file( subfilepath, STREAM_OUT ) );

	files = fs_files( filepath[0] );
	EXPECT_EQ( array_size( files ), 0 );
	string_array_deallocate( files );

	subdirs = fs_subdirs( subtestpath );
	EXPECT_EQ( array_size( subdirs ), 0 );
	string_array_deallocate( subdirs );

	files = fs_files( testpath );
	EXPECT_EQ( array_size( files ), 8 );
	string_array_deallocate( files );

	subdirs = fs_subdirs( testpath );
	EXPECT_EQ( array_size( subdirs ), 1 );
	string_array_deallocate( subdirs );

	files = fs_matching_files( testpath, "*", false );
	EXPECT_EQ( array_size( files ), 8 );
	string_array_deallocate( files );

	files = fs_matching_files( testpath, "*", true );
	EXPECT_EQ( array_size( files ), 9 );
	string_array_deallocate( files );

	files = fs_matching_files( testpath, "*.0", false );
	EXPECT_EQ( array_size( files ), 1 );
	string_array_deallocate( files );

	files = fs_matching_files( testpath, "*.0", true );
	EXPECT_EQ( array_size( files ), 2 );
	string_array_deallocate( files );

	files = fs_matching_files( testpath, "*.1", false );
	EXPECT_EQ( array_size( files ), 1 );
	string_array_deallocate( files );

	files = fs_matching_files( testpath, "*.1", true );
	EXPECT_EQ( array_size( files ), 1 );
	string_array_deallocate( files );

	files = fs_matching_files( testpath, "*.?", true );
	EXPECT_EQ( array_size( files ), 9 );
	{
		char* verifypath = string_from_int( subpathid, 0, 0 );
		verifypath = path_append( verifypath, string_from_int_static( subfileid, 0, 0 ) );
		verifypath = string_append( verifypath, ".0" );
		EXPECT_STREQ( files[8], verifypath );
		string_deallocate( verifypath );
	}
	string_array_deallocate( files );

	fs_remove_directory( testpath );

	string_array_deallocate( subdirs );
	string_array_deallocate( files );
	string_deallocate( subfilepath );
	for( ifp = 0; ifp < 8; ++ifp )
		string_deallocate( filepath[ifp] );
	string_deallocate( subtestpath );
	string_deallocate( testpath );
	return 0;
}
Пример #6
0
void get_equivalences(FILE *fp, int *p_line, char *p_line_string, 
                                int *p_num_of_chars)
{
#include "header.h"
int ipoint, iend, itsanum;
int idummy, ref;
int num_digi, sign;

double version;

/**************************************************************/
/****** Ignore titles for parameters                    *******/
/**************************************************************/


   while ( locate_string_in_string(TITLE_LINE,       p_line_string, *p_num_of_chars)
        || locate_string_in_string(ILLUSTRATION_LINE, p_line_string, *p_num_of_chars)
        || *p_num_of_chars == 0)
     {
        *p_num_of_chars=read_line(fp, p_line);
        idummy= string_from_int(p_line, p_line_string);
     }


/**************************************************************/
/****** Stay in the loop till we run out of parameter   *******/
/****** lines                                           *******/
/**************************************************************/

   num_equivalences=-1;
   while(*p_num_of_chars > 0)
     {

        num_equivalences++;
 
        ipoint= 0;

        version = get_doub(p_line, *p_num_of_chars, &ipoint, &itsanum);
        ref=  get_int(p_line, &ipoint, &itsanum, &num_digi,
                                               *p_num_of_chars, &sign);

/***************************************************************/
/******* Read in potential type that is to be checked **********/
/***************************************************************/

        ipoint= next_none_space(p_line, ipoint, *p_num_of_chars);
        iend= next_space(p_line, ipoint, *p_num_of_chars);

        strncpy (equivalence_list[num_equivalences].type, 
                                    p_line_string+ipoint, iend-ipoint);

        ipoint=iend;

/***************************************************************/
/******* Read in Non-bond equivalence **************************/
/***************************************************************/

        ipoint= next_none_space(p_line, ipoint, *p_num_of_chars);
        iend= next_space(p_line, ipoint, *p_num_of_chars);

        strncpy (equivalence_list[num_equivalences].nonbond, 
                                    p_line_string+ipoint, iend-ipoint);

        ipoint=iend;

/***************************************************************/
/******* Read in stretch equivalence ***************************/
/***************************************************************/

        ipoint= next_none_space(p_line, ipoint, *p_num_of_chars);
        iend= next_space(p_line, ipoint, *p_num_of_chars);

        strncpy (equivalence_list[num_equivalences].stretch,
                                    p_line_string+ipoint, iend-ipoint);

        ipoint=iend;

/***************************************************************/
/******* Read in angle equivalence *****************************/
/***************************************************************/

        ipoint= next_none_space(p_line, ipoint, *p_num_of_chars);
        iend= next_space(p_line, ipoint, *p_num_of_chars);

        strncpy (equivalence_list[num_equivalences].angle,
                                    p_line_string+ipoint, iend-ipoint);

        ipoint=iend;

/***************************************************************/
/******* Read in torsion equivalence ***************************/
/***************************************************************/

        ipoint= next_none_space(p_line, ipoint, *p_num_of_chars);
        iend= next_space(p_line, ipoint, *p_num_of_chars);

        strncpy (equivalence_list[num_equivalences].torsion,
                                    p_line_string+ipoint, iend-ipoint);

        ipoint=iend;

/***************************************************************/
/******* Read in oop equivalence *******************************/
/***************************************************************/

        ipoint= next_none_space(p_line, ipoint, *p_num_of_chars);
        iend= next_space(p_line, ipoint, *p_num_of_chars);

        strncpy (equivalence_list[num_equivalences].oop,
                                    p_line_string+ipoint, iend-ipoint);

        ipoint=iend;

/***************************************************************/
/****** Read in next parameter line  ***************************/
/***************************************************************/

        *p_num_of_chars=read_line(fp, p_line);
        idummy= string_from_int(p_line, p_line_string);
     }
return;
}
Пример #7
0
char *hf_generate_graph( int *rc, int cases, float *xdata, float *ydata, char *style, char *title,
  char *xax_title, char *yax_title, struct chart_options *chopt)

{
    int grids, digits, num_grids;
    float dmin, dmax, span;
    char *dataformat, *svg_doc = 0;
    struct svg_model *svg;
    struct milestone *walk, *mstone = 0;
    struct svg_chart_milestone *ckpt;
    struct series_data *series = 0;

    ENTER( "hf_generate_graph" )

    if( *rc == RC_NORMAL)
    {
        svg = svg_make_chart();
        if( !svg) *rc = ERR_MALLOC_FAILED;
    }

    INSUB( "hf_generate_graph", "before-add-data" )
    if( *rc == RC_NORMAL) series = svg_add_float_data( rc, svg, cases, xdata, ydata);

    if( chopt )
    {
        mstone = chopt->mstone;

        for( walk = mstone; *rc == RC_NORMAL && walk; walk = walk->next)
        {
            ckpt = svg_add_xax_checkpoint( svg, walk->offset, walk->label);
            if( !ckpt) *rc = ERR_MALLOC_FAILED;
            else if( walk == mstone && strcmp( style, SVG_STYLE_DARK))
            {
                *rc = svg_set_checkpoint_line_color( ckpt, GR_MST_LINE_COLOR );
                if( *rc == RC_NORMAL) *rc = svg_set_checkpoint_text_color( ckpt, GR_MST_TEXT_COLOR );
            }
	}

        if( chopt->xmin_hard != CH_OPT_NO_VALUE ) (void) svg_set_xmin( svg, chopt->xmin_hard );
        else if( chopt->xmin_soft != CH_OPT_NO_VALUE && chopt->xmin_soft < svg->xmin ) (void) svg_set_xmin( svg, chopt->xmin_soft );

        if( chopt->xmax_hard != CH_OPT_NO_VALUE ) (void) svg_set_xmax( svg, chopt->xmax_hard );
        else if( chopt->xmax_soft != CH_OPT_NO_VALUE && chopt->xmax_soft > svg->xmax ) (void) svg_set_xmax( svg, chopt->xmax_soft );

        if( chopt->ymin_hard != CH_OPT_NO_VALUE ) (void) svg_set_ymin( svg, chopt->ymin_hard );
        else if( chopt->ymin_soft != CH_OPT_NO_VALUE && chopt->ymin_soft < svg->ymin ) (void) svg_set_ymin( svg, chopt->ymin_soft );

        if( chopt->ymax_hard != CH_OPT_NO_VALUE ) (void) svg_set_ymax( svg, chopt->ymax_hard );
        else if( chopt->ymax_soft != CH_OPT_NO_VALUE && chopt->ymax_soft > svg->ymax ) (void) svg_set_ymax( svg, chopt->ymax_soft );
    }

    INSUB( "hf_generate_graph", "before-titles" )

    if( *rc == RC_NORMAL) *rc = svg_set_chart_title( svg, title);
    if( *rc == RC_NORMAL) *rc = svg_set_xax_title( svg, xax_title);
    if( *rc == RC_NORMAL) *rc = svg_set_yax_title( svg, yax_title);
    if( *rc == RC_NORMAL)
    {
        if( cases < GR_ALL_XAX_GRIDS) num_grids = cases;
        else num_grids = GR_ALL_XAX_GRIDS;
        *rc = svg_set_xax_num_grids( svg, num_grids);
    }
    if( *rc == RC_NORMAL)
    {
        if( cases < GR_ALL_YAX_GRIDS) num_grids = cases;
        else num_grids = GR_ALL_YAX_GRIDS;
        *rc = svg_set_yax_num_grids( svg, num_grids);
    }

    INSUB( "hf_generate_graph", "before-finalize" )
    if( *rc == RC_NORMAL) *rc = svg_finalize_model( svg);

    if( *rc == RC_NORMAL)
    {
        dmin = svg_get_xmin( svg);
        dmax = svg_get_xmax( svg);
        grids = svg_get_xax_num_grids( svg);
        span = (dmax - dmin) / grids;
        if( span >= 1.0) digits = 0;
        else if( span == 0.0) digits = 0;
        else digits = (int) (1 - log10( span));
/* printf( "<!-- HFGG: min:%f max:%f span:%f digits:%d patt(%s) -->\n", dmin, dmax, span, digits, GR_DATA_META_FORMAT); */
        dataformat = string_from_int( rc, digits, GR_DATA_META_FORMAT);
/* printf( "<!-- HFGG: rc:%d format(%s)-->\n", *rc, dataformat); */
        if( *rc == RC_NORMAL) *rc = svg_set_xax_disp( svg, dataformat);
        if( dataformat) free( dataformat);
    }

    if( *rc == RC_NORMAL)
    {
        dmin = svg_get_ymin( svg);
        dmax = svg_get_ymax( svg);
        grids = svg_get_yax_num_grids( svg);
        span = (dmax - dmin) / grids;
        if( span >= 1.0) digits = 0;
        else if( span == 0.0) digits = 0;
        else digits = (int) (1 - log10( span));
        dataformat = string_from_int( rc, digits, GR_DATA_META_FORMAT);
        if( *rc == RC_NORMAL) *rc = svg_set_yax_disp( svg, dataformat);
        if( dataformat) free( dataformat);
    }

    INSUB( "hf_generate_graph", "before-styles" )

    if( strcmp( style, SVG_STYLE_DARK))
    {
        if( *rc == RC_NORMAL) *rc = svg_set_circ_line_size( series, GR_ALL_CIRC_LINE_SIZE);
        if( *rc == RC_NORMAL) *rc = svg_set_circ_radius( series, GR_ALL_CIRC_RADIUS);

        if( *rc == RC_NORMAL) *rc = svg_set_text_color( svg, GR_ALL_TEXT_COLOR);
        if( *rc == RC_NORMAL) *rc = svg_set_axis_color( svg, GR_ALL_AXIS_COLOR);
        if( *rc == RC_NORMAL) *rc = svg_set_chart_color( svg, GR_ALL_CHART_COLOR);
        if( *rc == RC_NORMAL) *rc = svg_set_graph_color( svg, GR_ALL_GRAPH_COLOR);
        if( *rc == RC_NORMAL) *rc = svg_set_circ_fill_color( series, GR_ALL_CIRC_FILL_COLOR);
        if( *rc == RC_NORMAL) *rc = svg_set_circ_line_color( series, GR_ALL_CIRC_LINE_COLOR);
        if( *rc == RC_NORMAL) *rc = svg_set_data_fill_color( series, GR_ALL_DATA_FILL_COLOR);
        if( *rc == RC_NORMAL) *rc = svg_set_data_line_color( series, GR_ALL_DATA_LINE_COLOR);
        if( *rc == RC_NORMAL) *rc = svg_set_x_gridline_color( svg, GR_ALL_XGRID_COLOR);
        if( *rc == RC_NORMAL) *rc = svg_set_y_gridline_color( svg, GR_ALL_YGRID_COLOR);

        if( *rc == RC_NORMAL) *rc = svg_set_graph_alpha( svg, GR_ALL_GRAPH_ALPHA);
        if( *rc == RC_NORMAL) *rc = svg_set_circ_fill_alpha( series, GR_ALL_CIRC_FILL_ALPHA);
        if( *rc == RC_NORMAL) *rc = svg_set_circ_line_alpha( series, GR_ALL_CIRC_LINE_ALPHA);
        if( *rc == RC_NORMAL) *rc = svg_set_data_fill_alpha( series, GR_ALL_DATA_FILL_ALPHA);
        if( *rc == RC_NORMAL) *rc = svg_set_data_line_alpha( series, GR_ALL_DATA_LINE_ALPHA);

        if( chopt )
        {
            if( chopt->data_line_alpha != CH_OPT_NO_VALUE ) (void) svg_set_data_line_alpha( series, chopt->data_line_alpha );
            if( chopt->data_line_color ) (void) svg_set_data_line_color( series, chopt->data_line_color );
	}
    }

    INSUB( "hf_generate_graph", "before-render" )
    if( *rc == RC_NORMAL) svg_doc = svg_render( rc, svg);

    INSUB( "hf_generate_graph", "before-free" )
    if( svg) svg_free_model( svg);

    return( svg_doc);
}
Пример #8
0
int
spawn_child( const char *cmd, int singleton_id, int screen, const char *orig_display, Window w, int context, Bool do_fork, Bool pass_args, ... )
{
    int pid = 0;

    if( cmd == NULL )
        return 0;
	if( as_init_singletons )
	{
		register int i ;
		for( i = 0; i < MAX_SINGLETONS_NUM ; i++ )
			as_singletons[i] = 0 ;
		signal (SIGCHLD, as_sigchild_handler);
		as_init_singletons = False ;
	}

	if( singleton_id >= 0 )
	{
		if( singleton_id >= MAX_SINGLETONS_NUM )
			singleton_id = MAX_SINGLETONS_NUM-1;
		if( as_singletons[singleton_id] > 0 )
			check_singleton_child( singleton_id, True );
	}

    if( do_fork )
        pid = fork();

    if( pid != 0 )
	{
		/* there is a possibility of the race condition here
		 * but it really is not worse the trouble to try and avoid it.
		 */
    	if( singleton_id >= 0 )
			as_singletons[singleton_id] = pid ;
  	    return pid;
	}else
    {/* we get here only in child process. We now need to spawn new proggy here: */
        int len;
        char *display = mystrdup(XDisplayString (dpy));
		char **envp ; 
        register char *ptr ;

        char *cmdl;
        char *arg, *screen_str = NULL, *w_str = NULL, *context_str = NULL ;
		int env_s = 0;
		char **envvars = AS_environ ; 
		int font_path_slot = -1, image_path_slot = -1 ;

        va_list ap;
		LOCAL_DEBUG_OUT( "dpy = %p, DisplayString = \"%s\"", dpy, display );
		LOCAL_DEBUG_OUT( "pid(%d), entered child process to spawn ...", pid );

#if HAVE_DECL_ENVIRON
		if( envvars == NULL ) 
		{
			envvars = environ ;
		}	 
#else
/* how the hell could we get environment otherwise ? */
#endif
		if( envvars ) 
		{
			int font_path_len = strlen(ASFONT_PATH_ENVVAR);
			int image_path_len = strlen(ASIMAGE_PATH_ENVVAR);
			for( env_s = 0  ; envvars[env_s] != NULL ; ++env_s )
			{
				if( font_path_slot < 0 && strlen(envvars[env_s]) > font_path_len ) 
					if(strncmp(envvars[env_s], ASFONT_PATH_ENVVAR, font_path_len)==0)
						font_path_slot = env_s ; 
				if( image_path_slot < 0 && strlen(envvars[env_s]) > image_path_len) 
					if(strncmp(envvars[env_s], ASIMAGE_PATH_ENVVAR, image_path_len)==0)
						image_path_slot = env_s ;
			}	
		}
		if( font_path_slot < 0 ) 
			++env_s ;
		if( image_path_slot  < 0 ) 
			++env_s ;
		envp = safecalloc( env_s+2, sizeof(char*));

		/* environment variabless to pass to child process */
		if( envvars ) 
			for( env_s = 0  ; envvars[env_s] != NULL ; ++env_s )
				envp[env_s] = envvars[env_s] ;	
        
		envp[env_s] = safemalloc(8+strlen(orig_display?orig_display:display)+1);
		sprintf( envp[env_s], "DISPLAY=%s", orig_display?orig_display:display );
		++env_s ;
		if( Environment ) 
		{
			if( Environment->pixmap_path != NULL ) 
			{	
				int slot_no = image_path_slot ; 
				if( slot_no < 0 ) 
					slot_no = env_s++ ; 
					
				envp[slot_no] = safemalloc(strlen( ASIMAGE_PATH_ENVVAR ) + 1 + strlen(Environment->pixmap_path)+1) ;
				sprintf( envp[slot_no], "%s=%s", ASIMAGE_PATH_ENVVAR, Environment->pixmap_path );
			}
			if( Environment->font_path ) 
			{	
				int slot_no = font_path_slot ; 
				if( slot_no < 0 ) 
					slot_no = env_s++ ; 
				envp[slot_no] = safemalloc(strlen( ASFONT_PATH_ENVVAR ) + 1 + strlen(Environment->font_path)+1) ;
				sprintf( envp[slot_no], "%s=%s", ASFONT_PATH_ENVVAR, Environment->font_path );
			}
		}	 
			
        len = strlen((char*)cmd);
        if( pass_args )
        {
            register int i = 0 ;

            while( display[i] ) ++i;

            while( i > 0 && isdigit(display[--i]) );
            if( display[i] == '.' )
                display[i+1] = '\0' ;
/*
            This bit of code seems to break AS restarting
            on Fedora 8. causing DISPLAY=":0.0" to
            become DISPLAY=":0.".  -- Jeremy
*/
            if( screen >= 0 )
                screen_str = string_from_int( screen );
            if( w != None )
                w_str = string_from_int( w );
            if( context != C_NO_CONTEXT )
                context_str = string_from_int( context );

            len += 1+2+1+strlen( orig_display?orig_display:display );
            if( screen_str )
                len += strlen(screen_str);
            len += 3 ;                         /* for "-s " */
            if ( get_flags( as_app_args.flags, ASS_Debugging) )
                len += 8 ;
            if ( get_flags( as_app_args.flags, ASS_Restarting) )
                len += 3 ;
            if ( as_app_args.override_config )
                len += 4+strlen(as_app_args.override_config);
            if ( as_app_args.override_home )
                len += 4+strlen(as_app_args.override_home);
            if ( as_app_args.override_share )
                len += 4+strlen(as_app_args.override_share);

			if ( as_app_args.locale )
                len += 4+strlen(as_app_args.locale);

            if( as_app_args.verbosity_level != OUTPUT_DEFAULT_THRESHOLD )
                len += 4+32 ;
#ifdef DEBUG_TRACE_X
            if( as_app_args.trace_calls )
                len += 13+strlen( as_app_args.trace_calls );
#endif
            if( w_str )
                len += 1+8+1+strlen(w_str);
            if( context_str )
                len += 1+9+1+strlen(context_str);
        }
        /* now we want to append arbitrary number of arguments to the end of command line : */
        va_start( ap, pass_args );
        while( (arg = va_arg(ap,char*)) != NULL )
            len += 1+strlen(arg);
        va_end(ap);

        len+=4;

        ptr = cmdl = safemalloc( len );
        strcpy( cmdl, (char*)cmd );
        while(*ptr) ptr++;
        if( pass_args )
        {
			if (orig_display)
    	        ptr += sprintf( ptr, " -d %s -s", orig_display );
			else
	            ptr += sprintf( ptr, " -d %s%s -s", display, screen_str?screen_str:"" );
            if ( get_flags( as_app_args.flags, ASS_Debugging) )
            {
                strcpy( ptr, " --debug");
                ptr+=8 ;
            }
            if ( get_flags( as_app_args.flags, ASS_Restarting) )
            {
                strcpy( ptr, " -r");
                ptr += 3 ;
            }
            if ( as_app_args.override_config )
                ptr += sprintf( ptr, " -f %s", as_app_args.override_config );
            if ( as_app_args.override_home )
                ptr += sprintf( ptr, " -p %s", as_app_args.override_home );
            if ( as_app_args.override_share )
                ptr += sprintf( ptr, " -g %s", as_app_args.override_share );
            if( as_app_args.verbosity_level != OUTPUT_DEFAULT_THRESHOLD )
                ptr += sprintf( ptr, " -V %d", as_app_args.verbosity_level );
LOCAL_DEBUG_OUT( "len = %d, cmdl = \"%s\" strlen = %d, locale = \"%s\", ptr-cmdl = %d", len, cmdl, (int)strlen(cmdl), as_app_args.locale, (int)(ptr-cmdl) );
			if( as_app_args.locale && as_app_args.locale[0] && !isspace(as_app_args.locale[0]))
                ptr += sprintf( ptr, " -L %s", as_app_args.locale );
			
#ifdef DEBUG_TRACE_X
            if( as_app_args.trace_calls )
                ptr += sprintf( ptr, " --trace-func %s", as_app_args.trace_calls );
#endif
            if( w_str )
                ptr += sprintf( ptr, " --window %s", w_str );
            if( context_str )
                ptr += sprintf( ptr, " --context %s", context_str );
        }
        
		va_start( ap, pass_args );
        while( (arg = va_arg(ap,char*)) != NULL )
        {
            *(ptr++) = ' ';
            strcpy( ptr, arg );
            while(*ptr) ptr++;
LOCAL_DEBUG_OUT( "len = %d, cmdl = \"%s\" strlen = %d", len, cmdl, (int)strlen(cmdl) );
        
		}
        va_end(ap);
        if( do_fork )
        {
            int i = ptr-cmdl;
            while( --i >= 0 ) if( !isspace(cmdl[i]) ) break;
            do_fork = ( i < 0 || cmdl[i] != '&' );
        }
		strcpy (ptr, do_fork?" &\n":"\n");

LOCAL_DEBUG_OUT( "len = %d, cmdl = \"%s\" strlen = %d", len, cmdl, (int)strlen(cmdl) );
#if defined(LOCAL_DEBUG) && !defined(NO_DEBUG_OUTPUT)
		{
			FILE *fff = fopen ("/tmp/afterstep.exec.log", "a");
			if( fff ) 
			{
				fprintf( fff, "%s:%ld: [%s]", MyName, time(NULL), cmdl );
				fclose(fff);
			}
		}	
#endif			   
     
        LOCAL_DEBUG_OUT("execle(\"%s\")", cmdl );
        /* fprintf( stderr, "len=%d: execl(\"%s\")", len, cmdl ); */

        /* CYGWIN does not handle close-on-exec gracefully - whave to do it ourselves : */
        if( CloseOnExec )
            CloseOnExec();

		{
			const char     *shell;
			char *argv0 ;

	    	if ((shell = getenv("SHELL")) == NULL || *shell == '\0')
				shell = mystrdup("/bin/sh");

			parse_file_name(shell, NULL, &argv0);
	    	/* argv0 = basename(shell); */

        	execle (shell, argv0 , "-c", cmdl, (char *)0, envp);
		}

        if( screen >= 0 )
            show_error( "failed to start %s on the screen %d", cmd, screen );
        else
            show_error( "failed to start %s", cmd );
        show_system_error( " complete command line: \"%s\"\n", cmdl );
        exit(128);
    }
}