Example #1
0
File: jx.c Project: Baguage/cctools
struct jx  *jx_copy( struct jx *j )
{
	if(!j) return 0;

	switch(j->type) {
		case JX_NULL:
			return jx_null();
		case JX_DOUBLE:
			return jx_double(j->u.double_value);
		case JX_BOOLEAN:
			return jx_boolean(j->u.boolean_value);
		case JX_INTEGER:
			return jx_integer(j->u.integer_value);
		case JX_SYMBOL:
			return jx_symbol(j->u.symbol_name);
		case JX_STRING:
			return jx_string(j->u.string_value);
		case JX_ARRAY:
			return jx_array(jx_item_copy(j->u.items));
		case JX_OBJECT:
			return jx_object(jx_pair_copy(j->u.pairs));
		case JX_OPERATOR:
			return jx_operator(j->u.oper.type,jx_copy(j->u.oper.left),jx_copy(j->u.oper.right));
		case JX_FUNCTION:
			return jx_function(j->u.func.function, jx_copy(j->u.func.arguments));
		case JX_ERROR:
			return jx_error(jx_copy(j->u.err));
	}

	/* not reachable, but some compilers complain. */
	return 0;
}
Example #2
0
struct jx * jx_parse( struct jx_parser *s )
{
	jx_token_t t = jx_scan(s);

	switch(t) {
	case JX_TOKEN_EOF:
		return 0;
	case JX_TOKEN_LBRACE:
		return jx_object(jx_parse_pair_list(s));
	case JX_TOKEN_LBRACKET:
		return jx_array(jx_parse_item_list(s));
	case JX_TOKEN_STRING:
		return jx_string(s->token);
	case JX_TOKEN_INTEGER:
		return jx_integer(s->integer_value);
	case JX_TOKEN_DOUBLE:
		return jx_double(s->double_value);
	case JX_TOKEN_TRUE:
		return jx_boolean(1);
	case JX_TOKEN_FALSE:
		return jx_boolean(0);
	case JX_TOKEN_NULL:
		return jx_null();
	case JX_TOKEN_SYMBOL:
		if(s->strict_mode) {
			jx_parse_error(s,"symbols are not allowed in strict parsing mode");
			return 0;
		} else {
			return jx_symbol(s->token);
		}
	case JX_TOKEN_RBRACE:
	case JX_TOKEN_RBRACKET:
	case JX_TOKEN_COMMA:
	case JX_TOKEN_COLON:
	case JX_TOKEN_ERROR:
		jx_parse_error(s,"unexpected token");
		return 0;
	}

	/*
	We shouldn't get here, since all the token types
	should be handled above.  But just in case...
	*/

	jx_parse_error(s,"parse error");
	return 0;
}
Example #3
0
/*
 * Obtains information from the Catalog, format it, and make return it to user.
 */
int main(int argc, char** argv) {

    static const struct option long_options[] = {
        {"help", no_argument, 0, 'h'},
        {"project", required_argument, 0, 'N'},
        {"server", required_argument, 0, 's'},
        {"timeout", required_argument, 0, 't'},
        {"username", required_argument, 0, 'u'},
        {0, 0, 0, 0}
    };

    struct catalog_query *q;
    struct jx *j;
    int c;
    unsigned int i;
    time_t timeout = 60;
    char* catalog_host = NULL;
    
    char* username = NULL;
    char* project = NULL;
    
    char* server = NULL;
    
    while ((c = getopt_long(argc, argv, "N:t:u:w:s:h", long_options, NULL)) > -1) {
        switch (c) {
            case 'N':
                project = xxstrdup(optarg);
                break;
            case 't':
                timeout = string_time_parse(optarg);
                break;
            case 'u':
                username = xxstrdup(optarg);
                break;
            case 's':
                server = xxstrdup(optarg);
                break;
            case 'h':
            default:
                show_help(argv[0]);
                return 1;
        }
    }
    
    //setup address
    if(server==NULL){
        catalog_host = CATALOG_HOST;
    }

    //make query
    struct jx *jexpr = jx_operator(
        JX_OP_EQ,
        jx_symbol("type"),
        jx_string("makeflow")
    );

    if (project) {
        jexpr = jx_operator(
            JX_OP_AND,
            jexpr,
            jx_operator(
                JX_OP_EQ,
                jx_symbol("project"),
                jx_string(project)
            )
        );
    }

    if (username) {
        jexpr = jx_operator(
            JX_OP_AND,
            jexpr,
            jx_operator(
                JX_OP_EQ,
                jx_symbol("username"),
                jx_string(username)
            )
        );
    }

    time_t stoptime = time(0) + timeout;
    unsigned int count = 0;
    
    //create catalog_query from jx
    q = catalog_query_create(catalog_host, jexpr, stoptime);
    if (!q) {
        fprintf(stderr, "couldn't query catalog: %s\n", strerror(errno));
        return 1;
    }


    while ((j = catalog_query_read(q, stoptime))) {
        table[count++] = j;
    }
    
    catalog_query_delete(q);//all done with connection

    //sort
    qsort(table, count, sizeof(*table), (int (*)(const void *, const void *)) compare_entries);
    
    //print them out
    printf("%-10s %-18s %6s %6s %6s %6s %6s %6s %6s\n",
	   "OWNER", "PROJECT", "JOBS", "WAIT", "RUN", "COMP", "ABRT", "FAIL", "TYPE");
    for(i=0; i<count; i++){
        printf("%-10s %-18s %6" PRId64 " %6" PRId64 " %6" PRId64 " %6" PRId64 " %6" PRId64 " %6" PRId64 " %6s\n",
		jx_lookup_string(table[i], "owner"),
		jx_lookup_string(table[i], "project"),
		jx_lookup_integer(table[i], "total"),
		jx_lookup_integer(table[i], "waiting"),
		jx_lookup_integer(table[i], "running"),
		jx_lookup_integer(table[i], "completed"),
		jx_lookup_integer(table[i], "aborted"),
		jx_lookup_integer(table[i], "failed"),
		jx_lookup_string(table[i], "batch_type")
	);
    }
    printf("\n");//be polite
    
    //cleanup
    for(i=0;i<count;i++) {
	jx_delete(table[i]);
    }

    //done
    return (EXIT_SUCCESS);
}