Beispiel #1
0
/**
 * Launch threads and manage the matrix heat.
 */
void process_v3(Matrix* matrix_src, Matrix* matrix_dst, Region ** r_list, int n_threads, int n_iter)
{
    // Creating n_threads references
    pthread_t t[n_threads];

    Argument ** args = malloc(n_threads * sizeof(Argument *));

    if (args == NULL) {
        printf(">> [version3.c] process_v3: inefficient malloc causing abortion...\n");
        return;
    }

    // Launch n_threads threads
    // One threads per region
    for (int i = 0; i < n_threads; i++) {
        // Creating Argument_v3
        Argument * a = create_arg(matrix_src, matrix_dst, r_list[i], n_iter);

        if (a == NULL) {
            printf(">> [version3.c] process_v3: inefficient malloc causing abortion...\n");
            return;
        }

        // Saving Argument_v3
        // (else the next Argument will have the same address
        // and erase the previous Argument values)
        args[i] = a;

        // Launching thread
        pthread_create(&t[i], NULL, thread_func_v3, &args[i]);
    }

    // Ending threads
    for (int i = 0; i < n_threads; ++i)
        pthread_join(t[i], NULL);

    // Free Arguments
    free(*args);
}
Beispiel #2
0
int check_arg(int ac, char **av)
{
	int i;
	int error = -1;

	if(ac == 1)
		return -1;

	for(i = 1;ac > i;i++){
		/* check gui flag */
		if((error == -1) && (strcmp(&(av[i][0]), "--gui") == 0)){
			/* create argv(stamon_arg) for status monitor */
			create_arg(ac, av);
			error = 0; /* "--gui" detect */
			continue;
		}
		/* check parent process */
		if(strcmp(&(av[i][0]), "--noparent") == 0)
			filter_exist = 0;
		else if(strcmp(&(av[i][0]), "--cups") == 0)
			print_system = PRNSYS_CUPS; /* CUPS system detected */

		/* check write size option */
		if(strncmp(&(av[i][0]), WSIZE_OPTION, strlen(WSIZE_OPTION)) == 0){
			total_bytes = atoi(&(av[i+1][0]));
			/*
			sscanf(&(av[i][strlen(WSIZE_OPTION)]), "%d", &total_bytes);
			*/
		}

	}
#ifdef DEBUG_CUPS
	print_system = PRNSYS_CUPS;
#endif

	return error; 
}
Beispiel #3
0
static void
start_element(void *data, const char *element_name, const char **atts)
{
	struct parse_context *ctx = data;
	struct interface *interface;
	struct message *message;
	struct arg *arg;
	struct enumeration *enumeration;
	struct entry *entry;
	struct description *description = NULL;
	const char *name = NULL;
	const char *type = NULL;
	const char *interface_name = NULL;
	const char *value = NULL;
	const char *summary = NULL;
	const char *since = NULL;
	const char *allow_null = NULL;
	const char *enumeration_name = NULL;
	const char *bitfield = NULL;
	int i, version = 0;

	ctx->loc.line_number = XML_GetCurrentLineNumber(ctx->parser);
	for (i = 0; atts[i]; i += 2) {
		if (strcmp(atts[i], "name") == 0)
			name = atts[i + 1];
		if (strcmp(atts[i], "version") == 0) {
			version = strtouint(atts[i + 1]);
			if (version == -1)
				fail(&ctx->loc, "wrong version (%s)", atts[i + 1]);
		}
		if (strcmp(atts[i], "type") == 0)
			type = atts[i + 1];
		if (strcmp(atts[i], "value") == 0)
			value = atts[i + 1];
		if (strcmp(atts[i], "interface") == 0)
			interface_name = atts[i + 1];
		if (strcmp(atts[i], "summary") == 0)
			summary = atts[i + 1];
		if (strcmp(atts[i], "since") == 0)
			since = atts[i + 1];
		if (strcmp(atts[i], "allow-null") == 0)
			allow_null = atts[i + 1];
		if (strcmp(atts[i], "enum") == 0)
			enumeration_name = atts[i + 1];
		if (strcmp(atts[i], "bitfield") == 0)
			bitfield = atts[i + 1];
	}

	ctx->character_data_length = 0;
	if (strcmp(element_name, "protocol") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no protocol name given");

		ctx->protocol->name = xstrdup(name);
		ctx->protocol->uppercase_name = uppercase_dup(name);
	} else if (strcmp(element_name, "copyright") == 0) {

	} else if (strcmp(element_name, "interface") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no interface name given");

		if (version == 0)
			fail(&ctx->loc, "no interface version given");

		interface = create_interface(ctx->loc, name, version);
		ctx->interface = interface;
		wl_list_insert(ctx->protocol->interface_list.prev,
			       &interface->link);
	} else if (strcmp(element_name, "request") == 0 ||
		   strcmp(element_name, "event") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no request name given");

		message = create_message(ctx->loc, name);

		if (strcmp(element_name, "request") == 0)
			wl_list_insert(ctx->interface->request_list.prev,
				       &message->link);
		else
			wl_list_insert(ctx->interface->event_list.prev,
				       &message->link);

		if (type != NULL && strcmp(type, "destructor") == 0)
			message->destructor = 1;

		version = version_from_since(ctx, since);

		if (version < ctx->interface->since)
			warn(&ctx->loc, "since version not increasing\n");
		ctx->interface->since = version;
		message->since = version;

		if (strcmp(name, "destroy") == 0 && !message->destructor)
			fail(&ctx->loc, "destroy request should be destructor type");

		ctx->message = message;
	} else if (strcmp(element_name, "arg") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no argument name given");

		arg = create_arg(name);
		if (!set_arg_type(arg, type))
			fail(&ctx->loc, "unknown type (%s)", type);

		switch (arg->type) {
		case NEW_ID:
			ctx->message->new_id_count++;
			/* fallthrough */
		case OBJECT:
			if (interface_name)
				arg->interface_name = xstrdup(interface_name);
			break;
		default:
			if (interface_name != NULL)
				fail(&ctx->loc, "interface attribute not allowed for type %s", type);
			break;
		}

		if (allow_null) {
			if (strcmp(allow_null, "true") == 0)
				arg->nullable = 1;
			else if (strcmp(allow_null, "false") != 0)
				fail(&ctx->loc,
				     "invalid value for allow-null attribute (%s)",
				     allow_null);

			if (!is_nullable_type(arg))
				fail(&ctx->loc,
				     "allow-null is only valid for objects, strings, and arrays");
		}

		if (enumeration_name == NULL || strcmp(enumeration_name, "") == 0)
			arg->enumeration_name = NULL;
		else
			arg->enumeration_name = xstrdup(enumeration_name);

		if (summary)
			arg->summary = xstrdup(summary);

		wl_list_insert(ctx->message->arg_list.prev, &arg->link);
		ctx->message->arg_count++;
	} else if (strcmp(element_name, "enum") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no enum name given");

		enumeration = create_enumeration(name);

		if (bitfield == NULL || strcmp(bitfield, "false") == 0)
			enumeration->bitfield = false;
		else if (strcmp(bitfield, "true") == 0)
			enumeration->bitfield = true;
		else
			fail(&ctx->loc,
			     "invalid value (%s) for bitfield attribute (only true/false are accepted)",
			     bitfield);

		wl_list_insert(ctx->interface->enumeration_list.prev,
			       &enumeration->link);

		ctx->enumeration = enumeration;
	} else if (strcmp(element_name, "entry") == 0) {
		if (name == NULL)
			fail(&ctx->loc, "no entry name given");

		entry = create_entry(name, value);
		version = version_from_since(ctx, since);

		if (version < ctx->enumeration->since)
			warn(&ctx->loc, "since version not increasing\n");
		ctx->enumeration->since = version;
		entry->since = version;

		if (summary)
			entry->summary = xstrdup(summary);
		else
			entry->summary = NULL;
		wl_list_insert(ctx->enumeration->entry_list.prev,
			       &entry->link);
	} else if (strcmp(element_name, "description") == 0) {
		if (summary == NULL)
			fail(&ctx->loc, "description without summary");

		description = xzalloc(sizeof *description);
		description->summary = xstrdup(summary);

		if (ctx->message)
			ctx->message->description = description;
		else if (ctx->enumeration)
			ctx->enumeration->description = description;
		else if (ctx->interface)
			ctx->interface->description = description;
		else
			ctx->protocol->description = description;
		ctx->description = description;
	}
}
CL_StringFormat::CL_StringFormat(const CL_StringRef &format_string)
: string(format_string)
{
	bool arg_mode = false;
	unsigned int arg_start = 0;
	int arg_value = 0;
	CL_StringRef::size_type index, size;
	size = string.size();
	for (index = 0; index < size; index++)
	{
		if (!arg_mode)
		{
			if (string[index] == '%')
			{
				arg_mode = true;
				arg_value = 0;
				arg_start = index;
			}
		}
		else
		{
			switch (string[index])
			{
			case '%':
				if (arg_start == index-1)
				{
					arg_mode = false;
					string = string.substr(0, index) + string.substr(index + 1);
					index--;
					size--;
				}
				else
				{
					create_arg(arg_value, arg_start, index-arg_start);
					arg_start = index;
					arg_value = 0;
				}
				break;
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				arg_value *= 10;
				arg_value += string[index]-'0';
				break;
			default:
				if (arg_start != index-1)
					create_arg(arg_value, arg_start, index-arg_start);
				arg_mode = false;
				break;
			}
		}
	}
	
	if (arg_mode && arg_start != size-1)
		create_arg(arg_value, arg_start, size-arg_start);
}
Beispiel #5
0
ini_t *ini_load(const char *path)
{
    FILE *fp = fopen(path, "r");
    if (fp == NULL)
        return NULL;

    struct ini_section *head = NULL;
    struct ini_section *prev = NULL;
    struct ini_section *curr = NULL;

    struct ini_arg *arg_curr = NULL;
    struct ini_arg *arg_prev = NULL;

    char *line  = NULL;
    size_t   n  = 0;
    ssize_t len = 0;

    while ((len = _getline(&line, &n, fp)) != -1)
    {
        char *s = line;
        if (is_comment(&s))
            continue;
        len = strlen(s);

        if (len >= 3 && s[0] == '[' && s[len - 1] == ']')
        {
            char *name = s + 1;
            while (isspace(*name))
                ++name;

            char *name_end = s + len - 1;
            *name_end-- = '\0';
            while (isspace(*name_end))
                *name_end-- = '\0';

            if ((curr = find_section(head, name)) == NULL)
            {
                if ((curr = create_section(head, name)) == NULL)
                {
                    free(line);

                    return NULL;
                }

                if (head == NULL)
                    head = curr;
                if (prev != NULL)
                    prev->next = curr;

                prev = curr;
                arg_prev = NULL;
            }
            else
            {
                arg_prev = curr->args;
                while (arg_prev->next != NULL)
                    arg_prev = arg_prev->next;
            }

            continue;
        }

        char *delimiter = strchr(s, '=');
        if (delimiter == NULL)
            continue;
        *delimiter = '\0';

        char *name = s;
        char *name_end = delimiter - 1;
        while (isspace(*name_end))
            *name_end-- = '\0';

        char *value = delimiter + 1;
        while (isspace(*value))
            value++;

        if (curr == NULL)
        {
            if ((curr = create_section(head, "global")) == NULL)
            {
                free(line);

                return NULL;
            }

            if (head == NULL)
                head = curr;
            prev = curr;
            arg_prev = NULL;
        }

        if ((arg_curr = find_arg(curr, name)) == NULL)
        {
            arg_curr = create_arg(head, name, value);
            if (arg_curr == NULL)
            {
                free(line);

                return NULL;
            }

            if (arg_prev)
                arg_prev->next = arg_curr;
            if (curr->args == NULL)
                curr->args = arg_curr;

            arg_prev = arg_curr;
        }
        else
        {
            char *old_value = arg_curr->value;

            if ((arg_curr->value = strdup(value)) == NULL)
            {
                ini_free(head);

                free(line);

                return NULL;
            }

            free(old_value);
        }
    }

    free(line);
    fclose(fp);

    if (head == NULL)
    {
        if ((head = calloc(1, sizeof(struct ini_section))) == NULL)
            return NULL;
    }

    ini_print(head);

    return head;
}