Exemple #1
0
GAppInfo *
problem_create_app_from_cmdline (const char *cmdline)
{
    GAppInfo *app;
    GList *apps, *l;
    GList *shortlist;
    char *binary;
    char **cmdargs;

    binary = problem_get_argv0(cmdline);

    apps = g_app_info_get_all ();
    shortlist = NULL;
    app = NULL;
    for (l = apps; l != NULL; l = l->next)
    {
        GAppInfo *a = l->data;

        if (!g_app_info_should_show(a))
            continue;

        if (!compare_binaries (binary, g_app_info_get_executable (a)))
            continue;

        shortlist = g_list_prepend (shortlist, a);
    }

    if (shortlist == NULL)
    {
        g_list_free_full (apps, g_object_unref);
        return NULL;
    }

    cmdargs = g_strsplit (cmdline, " ", -1);
    remove_quotes (cmdargs);

    for (l = shortlist; l != NULL; l = l->next)
    {
        GAppInfo *a = l->data;
        char **dcmdargs;

        const char *commandline = g_app_info_get_commandline (a);
        if (commandline == NULL)
            continue;

        dcmdargs = g_strsplit (commandline, " ", -1);
        remove_quotes (dcmdargs);

        if (compare_args (cmdargs, dcmdargs))
            app = g_object_ref (a);

        g_strfreev (dcmdargs);
        if (app != NULL)
            break;
    }

    g_list_free (shortlist);
    g_list_free_full (apps, g_object_unref);
    return app;
}
Exemple #2
0
bool ::conditional::check(vector<string> condition, int line_number, string filename, string command)
{
    // check to see if the command is "if [arg] is defined" ...
    if (((condition[1]=="is") && (condition[2]=="defined")) || ((condition[1]=="is") && (condition[2]=="not") && (condition[3]=="defined")))
    {
        if(condition.size()!=3) {
            if(condition.size()!=4) {
                parse_error("Wrong number of arguments to function in '"+command+"'!\
                \nExpected 3 or 4 arguments, got "+IntToString(condition.size()),line_number,filename);
            }
        }

        if (!parse_is_quoted(condition[0]))
        {
            parse_error("Error: Expected a quoted string!",line_number,filename);
        }
        condition[0]=remove_quotes(condition[0]);

        if (condition[2]=="not")
        {
            if (!varmap.exists(condition[0]))
            {
                return true;
            }
        }
        else
        {
            if (varmap.exists(condition[0]))
            {
                return true;
            }
        }
    }
static int realm_match(const char *realm1, const char *realm2){
	if (realm1==NULL && realm2==NULL) return TRUE;
	if (realm1!=NULL && realm2!=NULL){
		if (strcmp(realm1,realm2)==0) return TRUE;
		else{
			char tmp1[128];
			char tmp2[128];
			char *p1,*p2;
			strncpy(tmp1,realm1,sizeof(tmp1)-1);
			strncpy(tmp2,realm2,sizeof(tmp2)-1);
			p1=remove_quotes(tmp1);
			p2=remove_quotes(tmp2);
			return strcmp(p1,p2)==0;
		}
	}
	return FALSE;
}
Exemple #4
0
// Get field and value pair.
int conf_get_pair(char buf[], char **f, char **v)
{
	char *cp=NULL;
	char *eq=NULL;

	// strip leading space
	for(cp=buf; *cp && isspace(*cp); cp++) { }
	if(!*cp || *cp=='#')
	{
		*f=NULL;
		*v=NULL;
		return 0;
	}
	*f=cp;
	if(!(eq=strchr(*f, '='))) return -1;
	*eq='\0';

	// Strip white space from before the equals sign.
	for(cp=eq-1; *cp && isspace(*cp); cp--) *cp='\0';
	// Skip white space after the equals sign.
	for(cp=eq+1; *cp && isspace(*cp); cp++) { }
	*v=cp;
	// Strip white space at the end of the line.
	for(cp+=strlen(cp)-1; *cp && isspace(*cp); cp--) { *cp='\0'; }

	// FIX THIS: Make this more sophisticated - it should understand
	// escapes, for example.

	switch(remove_quotes(*f, v, '\''))
	{
		case -1: return -1;
		case 1: break;
		default:
			// If single quotes were not removed, try to remove
			// double quotes.
			if(remove_quotes(*f, v, '\"')<0) return -1;
			break;
	}

	if(!*f || !**f || !*v || !**v) return -1;

	return 0;
}
Exemple #5
0
Alias *read_alias_table( char *alias_file )
{
    FILE *f;
    char *line = NULL;
    size_t buffer_size = 0;
    ssize_t n;
    Alias *result = NULL;
    List *words;
    char *lhs;
    char *rhs;

    f = fopen( alias_file, "r" );
    if ( f != NULL ) {
        while ( (n = getline( &line, &buffer_size, f )) > 0 ) {

            /* When reading a file using getline, we are given the '\n' characters, 
               but in this case we're not interested in them. */

            if ( (n > 0) && (line[n-1] == '\n') ) {
                line[n-1] = '\0';
            }

            /* Splitting the line between the first and second words, gives us the 
               alias and what it should expand to. */

            words = split_after_first_word( line );

            if ( list_length( words ) == 2 ) {
                lhs = get_nth_word( words, 0 );
                rhs = get_nth_word( words, 1 );

                /* What the alias expands to is often enclosed in
                   "()", but we don't need the brackets. Similary we
                   can strip out any unescaped quotes, i.e. '"'.*/

                rhs = get_string_in_brackets( rhs );
                rhs = remove_quotes( rhs );

                result = new_alias( result, lhs, rhs );
            } else {
                fprintf( stderr, "Ignoring unexpected entry in alias table: %s\n", line );
            }

            free_list( words );
        }

        free( line );
        fclose( f );
    } else {
        warn( "Unable to open file %s", alias_file );
    }

    return result;
}
/**
 * Attempts to retrieve an integer with the given key from chirp
 *
 * Attempts to retrieve an integer with the given key via chirp. 
 * The output value is placed in ``value''. If an error occurs, 
 * value is left unchanged and the function returns a nonzero 
 * value.
 *
 * @param chirp A connected chirp structure
 * @param key The key to look for
 * @param value (output) The resulting value
 * @return 0 on success, otherwise failure
 */
int get_chirp_integer(struct chirp_client *chirp, const char *key, int *value)
{
	if (chirp == (struct chirp_client *)NULL)
	{
		return 1;
	}
	if (key == (char *)NULL)
	{
		return 2;
	}
	char *char_value = NULL;
	char *next = NULL;
	int str_len = chirp_client_get_job_attr(chirp, key, &char_value);
	if (char_value == NULL)
	{
		return 3;
	}	
	if (str_len <= 0)
	{
		return 4;
	}
	char *new_string = (char *) calloc(str_len + 5, sizeof(char));
	if (new_string == (char *)NULL)
	{
		return 5;
	}
	int i;
	for (i = 0; i < str_len; i++)
	{
		new_string[i] = char_value[i];
	}

	/* Replace any quotation marks */
	remove_quotes(new_string);
	trim(new_string);

	/* Attempt to convert the result into an int */
	errno = 0;
	int new_value = (int) strtol(new_string, &next, 10); /* Base 10 */
	if (errno != 0 || next == new_string || next == NULL)
	{
		free(new_string);
		return 5;
	}
	/* Successfully parsed */
	*value = new_value;
	free(new_string);
	return 0;
}
/**
 * Attempts to retrieve a character string with the given key from chirp
 *
 * Attempts to retrieve a character string with the given key via chirp. 
 * The output value is placed in ``value''. If an error occurs, 
 * value is left unchanged and the function returns a nonzero 
 * value.
 *
 * @param chirp A connected chirp structure
 * @param key The key to look for
 * @return the allocated string on success, otherwise failure
 */
char * get_chirp_string(struct chirp_client *chirp, const char *key)
{
	if (chirp == (struct chirp_client *)NULL)
	{
		return NULL;
	}
	if (key == (char *)NULL)
	{
		return NULL;
	}
	char *char_value = NULL;
	int str_len = chirp_client_get_job_attr(chirp, key, &char_value);
	if (char_value == NULL)
	{
		return NULL;
	}	
	if (str_len <= 0)
	{
		return NULL;
	}
	/* Create a string that is at least 5 characters more than the length of this string */
	char *new_string = (char *) calloc(str_len + 5, sizeof(char));
	if (new_string == (char *)NULL)
	{
		return NULL;
	}
	int i;
	for (i = 0; i < str_len; i++)
	{
		new_string[i] = char_value[i];
	}
	
	/* Replace any quotation marks */
	remove_quotes(new_string);
	trim(new_string);
	/* Check if the value is undefined */
	if (! strncmp("UNDEFINED", new_string, str_len) || 
			! strncmp("undefined", new_string, str_len))
	{
		free(new_string);
		return NULL;
	}
	/* Return the value */
	return new_string;
}
Exemple #8
0
// Handle the MAP message. Store the map name, send the MDF, then pass on
void BaseBot::process_map( TokenMessage &incoming_message )
{
	TokenMessage mdf_message( TOKEN_COMMAND_MDF );
	TokenMessage name_submessage;

	// Store the map name
	name_submessage = incoming_message.get_submessage( 1 );
	m_map_and_units->map_name = name_submessage.get_message_as_text().c_str();
	remove_quotes( m_map_and_units->map_name );

	// Send an MDF
	send_message_to_server( mdf_message );

	// Store the map message
	m_map_message = incoming_message;

	// Call the users handler function
	process_map_message( incoming_message );
}
// return an error message or NULL
//
const char* SCHEDULER_REQUEST::parse(FILE* fin) {
    char buf[256];
    RESULT result;
    int retval;

    strcpy(authenticator, "");
    strcpy(platform.name, "");
    strcpy(cross_project_id, "");
    hostid = 0;
    core_client_major_version = 0;
    core_client_minor_version = 0;
    core_client_release = 0;
    rpc_seqno = 0;
    work_req_seconds = 0;
    cpu_req_secs = 0;
    cpu_req_instances = 0;
    resource_share_fraction = 1.0;
    rrs_fraction = 1.0;
    prrs_fraction = 1.0;
    cpu_estimated_delay = 0;
    strcpy(global_prefs_xml, "");
    strcpy(working_global_prefs_xml, "");
    strcpy(code_sign_key, "");
    memset(&global_prefs, 0, sizeof(global_prefs));
    memset(&host, 0, sizeof(host));
    have_other_results_list = false;
    have_ip_results_list = false;
    have_time_stats_log = false;
    client_cap_plan_class = false;
    sandbox = -1;
    coproc_cuda = 0;
    coproc_ati = 0;

    fgets(buf, sizeof(buf), fin);
    if (!match_tag(buf, "<scheduler_request>")) return "no start tag";
    while (fgets(buf, sizeof(buf), fin)) {
        // If a line is too long, ignore it.
        // This can happen e.g. if the client has bad global_prefs.xml
        // This won't be necessary if we rewrite this using XML_PARSER
        //
        if (!strchr(buf, '\n')) {
            while (fgets(buf, sizeof(buf), fin)) {
                if (strchr(buf, '\n')) break;
            }
            continue;
        }

        if (match_tag(buf, "</scheduler_request>")) {
            core_client_version = 10000*core_client_major_version + 100*core_client_minor_version + core_client_release;
            return NULL;
        }
        if (parse_str(buf, "<authenticator>", authenticator, sizeof(authenticator))) {
            remove_quotes(authenticator);
            continue;
        }
        if (parse_str(buf, "<cross_project_id>", cross_project_id, sizeof(cross_project_id))) continue;
        if (parse_int(buf, "<hostid>", hostid)) continue;
        if (parse_int(buf, "<rpc_seqno>", rpc_seqno)) continue;
        if (parse_str(buf, "<platform_name>", platform.name, sizeof(platform.name))) continue;
        if (match_tag(buf, "<alt_platform>")) {
            CLIENT_PLATFORM cp;
            retval = cp.parse(fin);
            if (!retval) {
                alt_platforms.push_back(cp);
            }
            continue;
        }
        if (match_tag(buf, "<app_versions>")) {
            while (fgets(buf, sizeof(buf), fin)) {
                if (match_tag(buf, "</app_versions>")) break;
                if (match_tag(buf, "<app_version>")) {
                    CLIENT_APP_VERSION cav;
                    retval = cav.parse(fin);
                    if (retval) {
                        g_reply->insert_message(
                            "Invalid app version description", "high"
                        );
                    } else {
                        client_app_versions.push_back(cav);
                    }
                }
            }
            continue;
        }
        if (parse_int(buf, "<core_client_major_version>", core_client_major_version)) continue;
        if (parse_int(buf, "<core_client_minor_version>", core_client_minor_version)) continue;
        if (parse_int(buf, "<core_client_release>", core_client_release)) continue;
        if (parse_double(buf, "<work_req_seconds>", work_req_seconds)) continue;
        if (parse_double(buf, "<cpu_req_secs>", cpu_req_secs)) continue;
        if (parse_double(buf, "<cpu_req_instances>", cpu_req_instances)) continue;
        if (parse_double(buf, "<resource_share_fraction>", resource_share_fraction)) continue;
        if (parse_double(buf, "<rrs_fraction>", rrs_fraction)) continue;
        if (parse_double(buf, "<prrs_fraction>", prrs_fraction)) continue;
        if (parse_double(buf, "<estimated_delay>", cpu_estimated_delay)) continue;
        if (parse_double(buf, "<duration_correction_factor>", host.duration_correction_factor)) continue;
        if (match_tag(buf, "<global_preferences>")) {
            strcpy(global_prefs_xml, "<global_preferences>\n");
            while (fgets(buf, sizeof(buf), fin)) {
                if (strstr(buf, "</global_preferences>")) break;
                safe_strcat(global_prefs_xml, buf);
            }
            safe_strcat(global_prefs_xml, "</global_preferences>\n");
            continue;
        }
        if (match_tag(buf, "<working_global_preferences>")) {
            while (fgets(buf, sizeof(buf), fin)) {
                if (strstr(buf, "</working_global_preferences>")) break;
                safe_strcat(working_global_prefs_xml, buf);
            }
            continue;
        }
        if (parse_str(buf, "<global_prefs_source_email_hash>", global_prefs_source_email_hash, sizeof(global_prefs_source_email_hash))) continue;
        if (match_tag(buf, "<host_info>")) {
            host.parse(fin);
            continue;
        }
        if (match_tag(buf, "<time_stats>")) {
            host.parse_time_stats(fin);
            continue;
        }
        if (match_tag(buf, "<time_stats_log>")) {
            handle_time_stats_log(fin);
            have_time_stats_log = true;
            continue;
        }
        if (match_tag(buf, "<net_stats>")) {
            host.parse_net_stats(fin);
            continue;
        }
        if (match_tag(buf, "<disk_usage>")) {
            host.parse_disk_usage(fin);
            continue;
        }
        if (match_tag(buf, "<result>")) {
            result.parse_from_client(fin);
            static int max_results = 200;
            --max_results;
            if (max_results >= 0)
            results.push_back(result);
            continue;
        }
        if (match_tag(buf, "<code_sign_key>")) {
            copy_element_contents(fin, "</code_sign_key>", code_sign_key, sizeof(code_sign_key));
            continue;
        }
        if (match_tag(buf, "<msg_from_host>")) {
            MSG_FROM_HOST_DESC md;
            retval = md.parse(fin);
            if (!retval) {
                msgs_from_host.push_back(md);
            }
            continue;
        }
        if (match_tag(buf, "<file_info>")) {
            FILE_INFO fi;
            retval = fi.parse(fin);
            if (!retval) {
                file_infos.push_back(fi);
            }
            continue;
        }
        if (match_tag(buf, "<host_venue>")) {
            continue;
        }
        if (match_tag(buf, "<other_results>")) {
            have_other_results_list = true;
            while (fgets(buf, sizeof(buf), fin)) {
                if (match_tag(buf, "</other_results>")) break;
                if (match_tag(buf, "<other_result>")) {
                    OTHER_RESULT o_r;
                    retval = o_r.parse(fin);
                    if (!retval) {
                        other_results.push_back(o_r);
                    }
                }
            }
            continue;
        }
        if (match_tag(buf, "<in_progress_results>")) {
            have_ip_results_list = true;
            int i = 0;
            double now = time(0);
            while (fgets(buf, sizeof(buf), fin)) {
                if (match_tag(buf, "</in_progress_results>")) break;
                if (match_tag(buf, "<ip_result>")) {
                    IP_RESULT ir;
                    retval = ir.parse(fin);
                    if (!retval) {
                        if (!strlen(ir.name)) {
                            sprintf(ir.name, "ip%d", i++);
                        }
                        ir.report_deadline -= now;
                        ip_results.push_back(ir);
                    }
                }
            }
            continue;
        }
        if (match_tag(buf, "coprocs")) {
            MIOFILE mf;
            mf.init_file(fin);
            coprocs.parse(mf);
            coproc_cuda = (COPROC_CUDA*)coprocs.lookup("CUDA");
            coproc_ati = (COPROC_ATI*)coprocs.lookup("ATI");
            continue;
        }
        if (parse_bool(buf, "client_cap_plan_class", client_cap_plan_class)) continue;
        if (parse_int(buf, "<sandbox>", sandbox)) continue;

        if (match_tag(buf, "<active_task_set>")) continue;
        if (match_tag(buf, "<app>")) continue;
        if (match_tag(buf, "<app_version>")) continue;
        if (match_tag(buf, "<duration_variability>")) continue;
        if (match_tag(buf, "<new_version_check_time>")) continue;
        if (match_tag(buf, "<newer_version>")) continue;
        if (match_tag(buf, "<project>")) continue;
        if (match_tag(buf, "<project_files>")) continue;
        if (match_tag(buf, "<proxy_info>")) continue;
        if (match_tag(buf, "<user_network_request>")) continue;
        if (match_tag(buf, "<user_run_request>")) continue;
        if (match_tag(buf, "<master_url>")) continue;
        if (match_tag(buf, "<project_name>")) continue;
        if (match_tag(buf, "<user_name>")) continue;
        if (match_tag(buf, "<team_name>")) continue;
        if (match_tag(buf, "<email_hash>")) continue;
        if (match_tag(buf, "<user_total_credit>")) continue;
        if (match_tag(buf, "<user_expavg_credit>")) continue;
        if (match_tag(buf, "<user_create_time>")) continue;
        if (match_tag(buf, "<host_total_credit>")) continue;
        if (match_tag(buf, "<host_expavg_credit>")) continue;
        if (match_tag(buf, "<host_create_time>")) continue;
        if (match_tag(buf, "<nrpc_failures>")) continue;
        if (match_tag(buf, "<master_fetch_failures>")) continue;
        if (match_tag(buf, "<min_rpc_time>")) continue;
        if (match_tag(buf, "<short_term_debt>")) continue;
        if (match_tag(buf, "<long_term_debt>")) continue;
        if (match_tag(buf, "<resource_share>")) continue;
        if (match_tag(buf, "<scheduler_url>")) continue;
        if (match_tag(buf, "</project>")) continue;
        if (match_tag(buf, "<?xml")) continue;
        strip_whitespace(buf);
        if (!strlen(buf)) continue;

        log_messages.printf(MSG_NORMAL,
            "SCHEDULER_REQUEST::parse(): unrecognized: %s\n", buf
        );
        MIOFILE mf;
        mf.init_file(fin);
        retval = skip_unrecognized(buf, mf);
        if (retval) return "unterminated unrecognized XML";
    }
    return "no end tag";
}
Exemple #10
0
int makeargv( char *string, char ***argv )
{
	enum {
		READ_ARG_CHAR,
		READ_STR_CHAR,
		READ_DELIMITER
	} state = READ_ARG_CHAR;

	char *current_argv[ PARSER_MAX_ARGS ];
	unsigned int current_token = 0;
	char *current_token_start = string;
	char *current_char = string;
	int i;


	while ( *current_char != '\0' ) {
		switch ( state ) {
		case READ_ARG_CHAR:
			switch ( *current_char ) {
			case '\n':
			case '\t':
			case ' ':
				*current_char = '\0';
				state = READ_DELIMITER;
				current_argv[ current_token ] = current_token_start;
				current_token++;
				break;

			case '"':
				/* String coming, probably. */
				state = READ_STR_CHAR;
				break;
			default:
				break;
			}
			break;

		case READ_STR_CHAR:
			switch (*current_char) {
			case '"':
				state = READ_ARG_CHAR;
				break;
			default:
				break;
			}
			break;
		case READ_DELIMITER:
			switch (*current_char) {
			case '\n':
			case '\t':
			case ' ':
				*current_char = '\0';
				break;
			case '"':
				state = READ_STR_CHAR;
				current_token_start = current_char;
				break;
			default:
				state = READ_ARG_CHAR;
				current_token_start = current_char;
				break;
			}
		}
		current_char++;
	}

	/* Remaining */

	if ( *current_token_start ) {
		current_argv[current_token++] = current_token_start;
	}

	/* Allocate */
	if (current_token==0) {
		*argv = NULL;
		return 0;
	}

	*argv = (char**)malloc((current_token+1)*sizeof(char *));

	for (i=0; i<current_token; i++) {
		remove_quotes( current_argv[i] );
		*(*argv+i) = strdup(current_argv[i]);
	}

	*(*argv+i) = NULL;

	return current_token;
}
Exemple #11
0
int main( int argc, char *argv[] )
{
    Alias *aliases;
    char *cmd;
    int i;
    char *result;

    if ( argc > 1 ) {

        /* The first argument on the command line is usually the name
           of the file containing the aliases, which we read into
           memory. If however it is the string "-noalias", then we
           operate without any alias definitions.  */

        if ( strcmp( argv[1], "-noalias" ) == 0 ) {
            aliases = NULL;
        } else {
            aliases = read_alias_table( argv[1] );
        }

        // print_aliases( aliases );

        /* Gather up all the rest of the args into a single string as
           they form our command */

        cmd = strdup( "" );
        for ( i = 2; i < argc; i++ ) {
            cmd = append_dup_string( cmd, argv[i] );
            cmd = append_dup_string( cmd, " " );
        }

        /* If the command is enclosed in double quotes then remove
           the double quote from both ends. */

        cmd = get_string_in_quotes( trim( cmd ) );

        // fprintf( stderr, "Command is: %s\n", cmd );

        result = dealias_command( cmd, aliases );

        /* Any sub commands (contained in back ticks) may themselves
           contain aliases which need to be expanded. */

        result = process_back_ticks( result, aliases );

        /* Remove any quotes (") from the string, unless they are escaped 
           with a backslash (\") */

        result = remove_quotes( result );

        /* Convert any occurence of "\!" into "!". */
        result = remove_backslash( result, '!' );

        printf( "%s\n", result );
        free( result );

        free( cmd );
    } else {
        fprintf( stderr, "\nTake a tcsh alias table and a tcsh command and print the command after\n" );
        fprintf( stderr, "alias substitution. The alias table can be created from within tcsh by:\n" );
        fprintf( stderr, "  alias > alias.txt\n\n" );

        fprintf( stderr, "usage: %s <alias-table> <cmd args ...>\n", argv[0] );
    }

    return 0;
}
static void read_sensor_labels(gchar * driver)
{
    FILE *conf;
    gchar buf[256], *line, *p;
    gboolean lock = FALSE;
    gint i;

    sensor_labels = g_hash_table_new_full(g_str_hash, g_str_equal,
					  g_free, g_free);
    sensor_compute = g_hash_table_new(g_str_hash, g_str_equal);

    /* Try to open lm-sensors config file sensors3.conf */
    conf = fopen("/etc/sensors3.conf", "r");

    /* If it fails, try to open sensors.conf */
    if (!conf) conf = fopen("/etc/sensors.conf", "r");

    if (!conf) {
        /* Cannot open config file. */
        return;
    }

    while (fgets(buf, 256, conf)) {
	line = buf;

	remove_linefeed(line);
	strend(line, '#');

	if (*line == '\0') {
	    continue;
	} else if (lock && strstr(line, "label")) {	/* label lines */
	    gchar **names = g_strsplit(strstr(line, "label") + 5, " ", 0);
	    gchar *name = NULL, *value = NULL;

	    for (i = 0; names[i]; i++) {
		if (names[i][0] == '\0')
		    continue;

		if (!name)
		    name = g_strdup(names[i]);
		else if (!value)
		    value = g_strdup(names[i]);
		else
		    value = g_strconcat(value, " ", names[i], NULL);
	    }

	    remove_quotes(value);
	    g_hash_table_insert(sensor_labels, name, value);

	    g_strfreev(names);
	} else if (lock && strstr(line, "ignore")) {	/* ignore lines */
	    p = strstr(line, "ignore") + 6;
	    if (!strchr(p, ' '))
		continue;

	    while (*p == ' ')
		p++;
	    g_hash_table_insert(sensor_labels, g_strdup(p), "ignore");
	} else if (lock && strstr(line, "compute")) {	/* compute lines */
	    gchar **formulas =
		g_strsplit(strstr(line, "compute") + 7, " ", 0);
	    gchar *name = NULL, *formula = NULL;

	    for (i = 0; formulas[i]; i++) {
		if (formulas[i][0] == '\0')
		    continue;
		if (formulas[i][0] == ',')
		    break;

		if (!name)
		    name = g_strdup(formulas[i]);
		else if (!formula)
		    formula = g_strdup(formulas[i]);
		else
		    formula = g_strconcat(formula, formulas[i], NULL);
	    }

	    g_strfreev(formulas);
	    g_hash_table_insert(sensor_compute, name,
				math_string_to_postfix(formula));
	} else if (g_str_has_prefix(line, "chip")) {	/* chip lines (delimiter) */
	    if (lock == FALSE) {
		gchar **chips = g_strsplit(line, " ", 0);

		for (i = 1; chips[i]; i++) {
		    strend(chips[i], '*');

                     if (g_str_has_prefix(chips[i] + 1, driver)) {
			lock = TRUE;
			break;
		    }
		}

		g_strfreev(chips);
	    } else {
		break;
	    }
	}
    }

    fclose(conf);
}
static void send_file_to_mail(DocInfo *newdoc,
			      char *content_base,
			      char *content_location)
{
    static BOOLEAN first_mail_preparsed = TRUE;

#if USE_VMS_MAILER
    BOOLEAN isPMDF = LYMailPMDF();
    FILE *hfd;
    char hdrfile[LY_MAXPATH];
#endif
    BOOL use_mime;

#if !CAN_PIPE_TO_MAILER
    char my_temp[LY_MAXPATH];
#endif

    BOOL use_cte;
    BOOL use_type;
    const char *disp_charset;
    FILE *outfile_fp;
    char *buffer = NULL;
    char *subject = NULL;
    bstring *user_response = NULL;

    if (!LYSystemMail())
	return;

    if (LYPreparsedSource && first_mail_preparsed &&
	HTisDocumentSource()) {
	if (HTConfirmDefault(CONFIRM_MAIL_SOURCE_PREPARSED, NO) == YES) {
	    LYaddstr("   Ok...");
	    first_mail_preparsed = FALSE;
	} else {
	    CancelPrint(MAIL_REQUEST_CANCELLED);
	}
    }

    _statusline(MAIL_ADDRESS_PROMPT);
    BStrCopy0(user_response, NonNull(personal_mail_address));
    if (LYgetBString(&user_response, FALSE, 0, RECALL_MAIL) < 0 ||
	isBEmpty(user_response)) {
	CancelPrint(MAIL_REQUEST_CANCELLED);
    }

    /*
     * Determine which mail headers should be sent.  Use Content-Type and
     * MIME-Version headers only if needed.  We need them if we are mailing
     * HTML source, or if we have 8-bit characters and will be sending
     * Content-Transfer-Encoding to indicate this.  We will append a charset
     * parameter to the Content-Type if we do not have an "x-" charset, and we
     * will include the Content-Transfer-Encoding only if we are appending the
     * charset parameter, because indicating an 8-bit transfer without also
     * indicating the charset can cause problems with many mailers.  - FM & KW
     */
    disp_charset = LYCharSet_UC[current_char_set].MIMEname;
    use_cte = HTLoadedDocumentEightbit();
    if (!(use_cte && strncasecomp(disp_charset, "x-", 2))) {
	disp_charset = NULL;
#if USE_VMS_MAILER
	use_cte = FALSE;
#endif
    }
#if USE_VMS_MAILER
    use_type = (BOOL) (disp_charset || HTisDocumentSource());
#endif

    /*
     * Use newdoc->title as a subject instead of sug_filename:  MORE readable
     * and 8-bit letters shouldn't be a problem - LP
     */
    /* change_sug_filename(sug_filename); */
    subject = subject_translate8bit(newdoc->title);

    if (newdoc->isHEAD) {
	/*
	 * Special case for mailing HEAD responce:  this is rather technical
	 * information, show URL.
	 */
	FREE(subject);
	StrAllocCopy(subject, "HEAD  ");
	StrAllocCat(subject, newdoc->address);
    }
#if USE_VMS_MAILER
    if (StrChr(user_response->str, '@') &&
	!StrChr(user_response->str, ':') &&
	!StrChr(user_response->str, '%') &&
	!StrChr(user_response->str, '"')) {
	char *temp = 0;

	HTSprintf0(&temp, mail_adrs, user_response->str);
	BStrCopy0(user_response, temp);
	FREE(temp);
    }

    outfile_fp = LYOpenTemp(my_temp,
			    (HTisDocumentSource())
			    ? HTML_SUFFIX
			    : TEXT_SUFFIX,
			    "w");
    if (outfile_fp == NULL) {
	CannotPrint(UNABLE_TO_OPEN_TEMPFILE);
    }

    if (isPMDF) {
	if ((hfd = LYOpenTemp(hdrfile, TEXT_SUFFIX, "w")) == NULL) {
	    CannotPrint(UNABLE_TO_OPEN_TEMPFILE);
	}
	if (use_type) {
	    fprintf(hfd, "Mime-Version: 1.0\n");
	    if (use_cte) {
		fprintf(hfd, "Content-Transfer-Encoding: 8bit\n");
	    }
	}
	if (HTisDocumentSource()) {
	    /*
	     * Add Content-Type, Content-Location, and Content-Base headers for
	     * HTML source.  - FM
	     */
	    fprintf(hfd, "Content-Type: text/html");
	    if (disp_charset != NULL) {
		fprintf(hfd, "; charset=%s\n", disp_charset);
	    } else {
		fprintf(hfd, "\n");
	    }
	    fprintf(hfd, "Content-Base: %s\n", content_base);
	    fprintf(hfd, "Content-Location: %s\n", content_location);
	} else {
	    /*
	     * Add Content-Type:  text/plain if we have 8-bit characters and a
	     * valid charset for non-source documents.  - FM
	     */
	    if (disp_charset != NULL) {
		fprintf(hfd,
			"Content-Type: text/plain; charset=%s\n",
			disp_charset);
	    }
	}
	/*
	 * X-URL header.  - FM
	 */
	fprintf(hfd, "X-URL: %s\n", newdoc->address);
	/*
	 * For PMDF, put the subject in the header file and close it.  - FM
	 */
	fprintf(hfd, "Subject: %.70s\n\n", subject);
	LYCloseTempFP(hfd);
    }

    /*
     * Write the contents to a temp file.
     */
    if (LYPrependBaseToSource && HTisDocumentSource()) {
	/*
	 * Added the document's base as a BASE tag to the top of the message
	 * body.  May create technically invalid HTML, but will help get any
	 * partial or relative URLs resolved properly if no BASE tag is present
	 * to replace it.  - FM
	 */
	fprintf(outfile_fp,
		"<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n",
		newdoc->address, content_base);
    } else if (!isPMDF) {
	fprintf(outfile_fp, "X-URL: %s\n\n", newdoc->address);
    }
    print_wwwfile_to_fd(outfile_fp, TRUE, FALSE);	/* MAIL */
    if (keypad_mode)
	printlist(outfile_fp, FALSE);
    LYCloseTempFP(outfile_fp);

    buffer = NULL;
    if (isPMDF) {
	/*
	 * Now set up the command.  - FM
	 */
	HTSprintf0(&buffer,
		   "%s %s %s,%s %s",
		   system_mail,
		   system_mail_flags,
		   hdrfile,
		   my_temp,
		   user_response->str);
    } else {
	/*
	 * For "generic" VMS MAIL, include the subject in the command.  - FM
	 */
	remove_quotes(subject);
	HTSprintf0(&buffer,
		   "%s %s/subject=\"%.70s\" %s %s",
		   system_mail,
		   system_mail_flags,
		   subject,
		   my_temp,
		   user_response->str);
    }

    stop_curses();
    SetOutputMode(O_TEXT);
    printf(MAILING_FILE);
    LYSystem(buffer);
    LYSleepAlert();
    start_curses();
    SetOutputMode(O_BINARY);

    if (isPMDF)
	(void) LYRemoveTemp(hdrfile);
    (void) LYRemoveTemp(my_temp);
#else /* !VMS (Unix or DOS) */

#if CAN_PIPE_TO_MAILER
    outfile_fp = LYPipeToMailer();
#else
    outfile_fp = LYOpenTemp(my_temp, TEXT_SUFFIX, "w");
#endif
    if (outfile_fp == NULL) {
	CannotPrint(MAIL_REQUEST_FAILED);
    }

    /*
     * Determine which mail headers should be sent.  Use Content-Type and
     * MIME-Version headers only if needed.  We need them if we are mailing
     * HTML source, or if we have 8-bit characters and will be sending
     * Content-Transfer-Encoding to indicate this.
     *
     * Send Content-Transfer-Encoding only if the document has 8-bit
     * characters.  Send a charset parameter only if the document has 8-bit
     * characters and we seem to have a valid charset.  - kw
     */
    use_cte = HTLoadedDocumentEightbit();
    disp_charset = LYCharSet_UC[current_char_set].MIMEname;
    /*
     * Don't send a charset if we have a CJK character set selected, since it
     * may not be appropriate for mail...  Also don't use an unofficial "x-"
     * charset.  - kw
     */
    if (!use_cte || LYHaveCJKCharacterSet ||
	strncasecomp(disp_charset, "x-", 2) == 0) {
	disp_charset = NULL;
    }
#ifdef NOTDEFINED
    /* Enable this if indicating an 8-bit transfer without also indicating the
     * charset causes problems.  - kw */
    if (use_cte && !disp_charset)
	use_cte = FALSE;
#endif /* NOTDEFINED */
    use_type = (BOOL) (disp_charset || HTisDocumentSource());
    use_mime = (BOOL) (use_cte || use_type);

    if (use_mime) {
	fprintf(outfile_fp, "Mime-Version: 1.0\n");
	if (use_cte) {
	    fprintf(outfile_fp, "Content-Transfer-Encoding: 8bit\n");
	}
    }

    if (HTisDocumentSource()) {
	/*
	 * Add Content-Type, Content-Location, and Content-Base headers for
	 * HTML source.  - FM
	 */
	fprintf(outfile_fp, "Content-Type: text/html");
	if (disp_charset != NULL) {
	    fprintf(outfile_fp, "; charset=%s\n", disp_charset);
	} else {
	    fprintf(outfile_fp, "\n");
	}
    } else {
	/*
	 * Add Content-Type:  text/plain if we have 8-bit characters and a
	 * valid charset for non-source documents.  - KW
	 */
	if (disp_charset != NULL) {
	    fprintf(outfile_fp,
		    "Content-Type: text/plain; charset=%s\n",
		    disp_charset);
	}
    }
    /*
     * If we are using MIME headers, add content-base and content-location if
     * we have them.  This will always be the case if the document is source.
     * - kw
     */
    if (use_mime) {
	if (content_base)
	    fprintf(outfile_fp, "Content-Base: %s\n", content_base);
	if (content_location)
	    fprintf(outfile_fp, "Content-Location: %s\n", content_location);
    }

    /*
     * Add the To, Subject, and X-URL headers.  - FM
     */
    fprintf(outfile_fp, "To: %s\nSubject: %s\n", user_response->str, subject);
    fprintf(outfile_fp, "X-URL: %s\n\n", newdoc->address);

    if (LYPrependBaseToSource && HTisDocumentSource()) {
	/*
	 * Added the document's base as a BASE tag to the top of the message
	 * body.  May create technically invalid HTML, but will help get any
	 * partial or relative URLs resolved properly if no BASE tag is present
	 * to replace it.  - FM
	 */
	fprintf(outfile_fp,
		"<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n",
		newdoc->address, content_base);
    }
    print_wwwfile_to_fd(outfile_fp, TRUE, FALSE);	/* MAIL */
    if (keypad_mode)
	printlist(outfile_fp, FALSE);

#if CAN_PIPE_TO_MAILER
    pclose(outfile_fp);
#else
    LYCloseOutput(outfile_fp);
    LYSendMailFile(user_response->str,
		   my_temp,
		   subject,
		   "",
		   "");
    (void) LYRemoveTemp(my_temp);	/* Delete the tmpfile. */
#endif /* CAN_PIPE_TO_MAILER */
#endif /* USE_VMS_MAILER */

  done:			/* send_file_to_mail() */
    BStrFree(user_response);
    FREE(buffer);
    FREE(subject);
    return;
}