Ejemplo n.º 1
0
/* Take the user's format specification and use it to build build the
 *	format specifications (internalize it to print.c data structures) */
static int
_parse_format( char* format )
{
	int field_size;
	bool right_justify;
	char *prefix = NULL, *suffix = NULL, *token = NULL,
		*tmp_char = NULL, *tmp_format = NULL;
	char field[1];

	if (format == NULL) {
		fprintf( stderr, "Format option lacks specification\n" );
		exit( 1 );
	}

	params.format_list = list_create( NULL );
	if ((prefix = _get_prefix(format)))
		format_add_prefix( params.format_list, 0, 0, prefix);

	tmp_format = xstrdup( format );
	token = strtok_r( tmp_format, "%", &tmp_char);
	if (token && (format[0] != '%'))	/* toss header */
		token = strtok_r( NULL, "%", &tmp_char );
	while (token) {
		_parse_token( token, field, &field_size, &right_justify,
			      &suffix);
		if        (field[0] == 'a') {
			params.match_flags.avail_flag = true;
			format_add_avail( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'A') {
			format_add_nodes_ai( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'c') {
			params.match_flags.cpus_flag = true;
			format_add_cpus( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'C') {
			params.match_flags.cpus_flag = true;
			format_add_cpus_aiot( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'd') {
			params.match_flags.disk_flag = true;
			format_add_disk( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'D') {
			format_add_nodes( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'E') {
			params.match_flags.reason_flag = true;
			format_add_reason( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'f') {
			params.match_flags.features_flag = true;
			format_add_features( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'F') {
			format_add_nodes_aiot( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'g') {
			params.match_flags.groups_flag = true;
			format_add_groups( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'G') {
			params.match_flags.gres_flag = true;
			format_add_gres( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'h') {
			params.match_flags.share_flag = true;
			format_add_share( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'H') {
			params.match_flags.reason_timestamp_flag = true;
			format_add_timestamp( params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		} else if (field[0] == 'l') {
			params.match_flags.max_time_flag = true;
			format_add_time( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'L') {
			params.match_flags.default_time_flag = true;
			format_add_default_time( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'm') {
			params.match_flags.memory_flag = true;
			format_add_memory( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'M') {
			params.match_flags.preempt_mode_flag = true;
			format_add_preempt_mode( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'n') {
			params.match_flags.hostnames_flag = true;
			format_add_node_hostnames( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'N') {
			format_add_node_list( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'o') {
			params.match_flags.node_addr_flag = true;
			format_add_node_address( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'O') {
			params.match_flags.cpu_load_flag = true;
			format_add_cpu_load( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'p') {
			params.match_flags.priority_flag = true;
			format_add_priority( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'P') {
			params.match_flags.partition_flag = true;
			format_add_partition( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'r') {
			params.match_flags.root_flag = true;
			format_add_root( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'R') {
			params.match_flags.partition_flag = true;
			format_add_partition_name( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 's') {
			params.match_flags.job_size_flag = true;
			format_add_size( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (field[0] == 'S') {
			format_add_alloc_nodes( params.format_list,
						field_size,
						right_justify,
						suffix );
		} else if (field[0] == 't') {
			params.match_flags.state_flag = true;
			format_add_state_compact( params.format_list,
						  field_size,
						  right_justify,
						  suffix );
		} else if (field[0] == 'T') {
			params.match_flags.state_flag = true;
			format_add_state_long( params.format_list,
					       field_size,
					       right_justify,
					       suffix );
		} else if (field[0] == 'u') {
			params.match_flags.reason_user_flag = true;
			format_add_user( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'U') {
			params.match_flags.reason_user_flag = true;
			format_add_user_long( params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		} else if (field[0] == 'w') {
			params.match_flags.weight_flag = true;
			format_add_weight( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'X') {
			params.match_flags.sockets_flag = true;
			format_add_sockets( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'Y') {
			params.match_flags.cores_flag = true;
			format_add_cores( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'Z') {
			params.match_flags.threads_flag = true;
			format_add_threads( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (field[0] == 'z') {
			params.match_flags.sct_flag = true;
			format_add_sct( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else {
			prefix = xstrdup("%");
			xstrcat(prefix, token);
			xfree(suffix);
			suffix = prefix;
			format_add_invalid( params.format_list,
					    field_size,
					    right_justify,
					    suffix );
			fprintf(stderr, "Invalid node format specification: %c\n",
				field[0] );
		}
		token = strtok_r( NULL, "%", &tmp_char);
	}

	xfree( tmp_format );
	return SLURM_SUCCESS;
}
Ejemplo n.º 2
0
Archivo: opts.c Proyecto: HPCNow/slurm
static int _parse_long_format (char* format_long)
{
	int field_size;
	bool right_justify, format_all = false;
	char *tmp_format = NULL, *token = NULL, *str_tmp = NULL;
	char *sep = NULL;
	char* suffix = NULL;

	if (format_long == NULL) {
		error("Format long option lacks specification");
		exit( 1 );
	}

	params.format_list = list_create(NULL);
	tmp_format = xstrdup(format_long);
	token = strtok_r(tmp_format, ",",&str_tmp);

	while (token) {
		_parse_long_token( token, sep, &field_size, &right_justify,
				   &suffix);

		if (!xstrcasecmp(token, "all")) {
			_parse_format ("%all");
		} else if (!xstrcasecmp(token, "allocmem")) {
			params.match_flags.alloc_mem_flag = true;
			format_add_alloc_mem( params.format_list,
						field_size,
						right_justify,
						suffix );
		} else if (!xstrcasecmp(token, "allocnodes")) {
			format_add_alloc_nodes( params.format_list,
						field_size,
						right_justify,
						suffix );
		} else if (!xstrcasecmp(token, "available")) {
			params.match_flags.avail_flag = true;
			format_add_avail( params.format_list,
					  field_size,
					  right_justify,
					  suffix );
		} else if (!xstrcasecmp(token, "cluster")) {
			format_add_cluster_name(params.format_list,
						field_size,
						right_justify,
						suffix);
		} else if (!xstrcasecmp(token, "cpus")) {
			params.match_flags.cpus_flag = true;
			format_add_cpus( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (!xstrcasecmp(token, "cpusload")) {
			params.match_flags.cpu_load_flag = true;
			format_add_cpu_load( params.format_list,
					     field_size,
					     right_justify,
					     suffix );
		} else if (!xstrcasecmp(token, "freemem")) {
			params.match_flags.free_mem_flag = true;
			format_add_free_mem( params.format_list,
					     field_size,
					     right_justify,
					     suffix );
		} else if (!xstrcasecmp(token, "cpusstate")) {
			params.match_flags.cpus_flag = true;
			format_add_cpus_aiot( params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		} else if (!xstrcasecmp(token, "cores")) {
			params.match_flags.cores_flag = true;
			format_add_cores( params.format_list,
					  field_size,
					  right_justify,
					  suffix );
		} else if (!xstrcasecmp(token, "defaulttime")) {
			params.match_flags.default_time_flag = true;
			format_add_default_time( params.format_list,
						 field_size,
						 right_justify,
						 suffix );
		} else if (!xstrcasecmp(token, "disk")) {
			params.match_flags.disk_flag = true;
			format_add_disk( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (!xstrcasecmp(token, "features")) {
			params.match_flags.features_flag = true;
			format_add_features( params.format_list,
					     field_size,
					     right_justify,
					     suffix );
		} else if (!xstrcasecmp(token, "features_act")) {
			params.match_flags.features_act_flag = true;
			format_add_features_act( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (!xstrcasecmp(token, "groups")) {
			params.match_flags.groups_flag = true;
			format_add_groups( params.format_list,
					   field_size,
					   right_justify,
					   suffix );
		} else if (!xstrcasecmp(token, "gres")) {
			params.match_flags.gres_flag = true;
			format_add_gres( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (!xstrcasecmp(token, "maxcpuspernode")) {
			params.match_flags.max_cpus_per_node_flag = true;
			format_add_max_cpus_per_node( params.format_list,
						      field_size,
						      right_justify,
						      suffix );
		} else if (!xstrcasecmp(token, "memory")) {
			params.match_flags.memory_flag = true;
			format_add_memory( params.format_list,
					   field_size,
					   right_justify,
					   suffix );
		} else if (!xstrcasecmp(token, "nodes")) {
			format_add_nodes( params.format_list,
					  field_size,
					  right_justify,
					  suffix );
		} else if (!xstrcasecmp(token, "nodeaddr")) {
			params.match_flags.node_addr_flag = true;
			format_add_node_address( params.format_list,
						 field_size,
						 right_justify,
						 suffix );
		} else if (!xstrcasecmp(token, "nodeai")) {
			format_add_nodes_ai( params.format_list,
					     field_size,
					     right_justify,
					     suffix );
		} else if (!xstrcasecmp(token, "nodeaiot")) {
			format_add_nodes_aiot( params.format_list,
					       field_size,
					       right_justify,
					       suffix );
		} else if (!xstrcasecmp(token, "nodehost")) {
			params.match_flags.hostnames_flag = true;
			format_add_node_hostnames( params.format_list,
						   field_size,
						   right_justify,
						   suffix );
		} else if (!xstrcasecmp(token, "nodelist")) {
			format_add_node_list( params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		} else if (!xstrcasecmp(token, "partition")) {
			params.match_flags.partition_flag = true;
			format_add_partition( params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		} else if (!xstrcasecmp(token, "partitionname")) {
			params.match_flags.partition_flag = true;
			format_add_partition_name( params.format_list,
						   field_size,
						   right_justify,
						   suffix );
		} else if (!xstrcasecmp(token, "port")) {
			params.match_flags.port_flag = true;
			format_add_port( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (!xstrcasecmp(token, "preemptmode")) {
			params.match_flags.preempt_mode_flag = true;
			format_add_preempt_mode( params.format_list,
						 field_size,
						 right_justify,
						 suffix );
		} else if (!xstrcasecmp(token, "priorityjobfactor")) {
			params.match_flags.priority_job_factor_flag = true;
			format_add_priority_job_factor(params.format_list,
						       field_size,
						       right_justify,
						       suffix );
		} else if (!xstrcasecmp(token, "prioritytier")) {
			params.match_flags.priority_tier_flag = true;
			format_add_priority_tier(params.format_list,
						 field_size,
						 right_justify,
						 suffix );
		} else if (!xstrcasecmp(token, "reason")) {
			params.match_flags.reason_flag = true;
			format_add_reason( params.format_list,
					   field_size,
					   right_justify,
					   suffix );
		} else if (!xstrcasecmp(token, "root")) {
			params.match_flags.root_flag = true;
			format_add_root( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (!xstrcasecmp(token, "oversubscribe") ||
			   !xstrcasecmp(token, "share")) {
			params.match_flags.oversubscribe_flag = true;
			format_add_oversubscribe( params.format_list,
						  field_size,
						  right_justify,
						  suffix );
		} else if (!xstrcasecmp(token, "size")) {
			params.match_flags.job_size_flag = true;
			format_add_size( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (!xstrcasecmp(token, "statecompact")) {
			params.match_flags.state_flag = true;
			format_add_state_compact( params.format_list,
						  field_size,
						  right_justify,
						  suffix );
		} else if (!xstrcasecmp(token, "statelong")) {
			params.match_flags.state_flag = true;
			format_add_state_long( params.format_list,
					       field_size,
					       right_justify,
					       suffix );
		} else if (!xstrcasecmp(token, "sockets")) {
			params.match_flags.sockets_flag = true;
			format_add_sockets( params.format_list,
					    field_size,
					    right_justify,
					    suffix );
		} else if (!xstrcasecmp(token, "socketcorethread")) {
			params.match_flags.sct_flag = true;
			format_add_sct( params.format_list,
					field_size,
					right_justify,
					suffix );
		} else if (!xstrcasecmp(token, "time")) {
			params.match_flags.max_time_flag = true;
			format_add_time( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (!xstrcasecmp(token, "timestamp")) {
			params.match_flags.reason_timestamp_flag = true;
			format_add_timestamp( params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		} else if (!xstrcasecmp(token, "threads")) {
			params.match_flags.threads_flag = true;
			format_add_threads( params.format_list,
					    field_size,
					    right_justify,
					    suffix );
		} else if (!xstrcasecmp(token, "user")) {
			params.match_flags.reason_user_flag = true;
			format_add_user( params.format_list,
					 field_size,
					 right_justify,
					 suffix );
		} else if (!xstrcasecmp(token, "userlong")) {
			params.match_flags.reason_user_flag = true;
			format_add_user_long( params.format_list,
					      field_size,
					      right_justify,
					      suffix );
		} else if (!xstrcasecmp(token, "version")) {
			params.match_flags.version_flag = true;
			format_add_version( params.format_list,
					    field_size,
					    right_justify,
					    suffix);
		} else if (!xstrcasecmp(token, "weight")) {
			params.match_flags.weight_flag = true;
			format_add_weight( params.format_list,
					   field_size,
					   right_justify,
					   suffix );
		} else if (format_all) {
			/* ignore */
		} else {
			format_add_invalid( params.format_list,
					    field_size,
					    right_justify,
					    suffix );
			error( "Invalid job format specification: %s",
			       token );
		}
		token = strtok_r(NULL, ",", &str_tmp);
	}
	xfree(tmp_format);
	return SLURM_SUCCESS;
}