示例#1
0
void journal_read(const char *path, GQueue *queue)
{
	FILE *file;
	char line[1024];
	struct record record;

	journal_file_empty = true;

	file = fopen(path, "r");
	if (file == NULL) {
		if (errno != ENOENT)
			/* ENOENT is ignored silently, because the
			 * user might be starting mpdcron for the
			 * first time */
			g_warning("Failed to load %s: %s",
					path, g_strerror(errno));
		return;
	}

	record_clear(&record);

	while (fgets(line, sizeof(line), file) != NULL) {
		char *key, *value;

		key = g_strchug(line);
		if (*key == 0 || *key == '#')
			continue;

		value = strchr(key, '=');
		if (value == NULL || value == key)
			continue;

		*value++ = 0;

		key = g_strchomp(key);
		value = g_strstrip(value);

		if (!strcmp("a", key)) {
			journal_commit_record(queue, &record);
			record.artist = g_strdup(value);
		} else if (!strcmp("t", key))
			record.track = g_strdup(value);
		else if (!strcmp("b", key))
			record.album = g_strdup(value);
		else if (!strcmp("n", key))
			record.number = g_strdup(value);
		else if (!strcmp("m", key))
			record.mbid = g_strdup(value);
		else if (!strcmp("i", key))
			record.time = parse_timestamp(value);
		else if (!strcmp("l", key))
			record.length = atoi(value);
		else if (strcmp("o", key) == 0 && value[0] == 'R')
			record.source = "R";
	}

	fclose(file);

	journal_commit_record(queue, &record);
}
示例#2
0
void library_clear(struct library *li)
{
    int n;

    /* This object is responsible for all the record pointers */

    for (n = 0; n < li->all.by_artist.entries; n++) {
        struct record *re;

        re = li->all.by_artist.record[n];
        record_clear(re);
        free(re);
    }

    /* Clear crates */

    for (n = 1; n < li->crates; n++) { /* skip the 'all' crate */
        struct crate *crate;

        crate = li->crate[n];
        crate_clear(crate);
        free(crate);
    }
    free(li->crate);

    crate_clear(&li->all);
}
示例#3
0
文件: record.C 项目: Zirkon/dyninst
bool record_create(record_t *record, const char *prog, int argc, char **argv)
{
    char hash_buf[SHA1_STRING_LEN];
    const char *prog_bin = prog;
    unsigned i;

    record_clear(record);

    if (strrchr(prog, '/'))
	prog_bin = strrchr(prog, '/') + 1;

    if (!sha1_file(prog, hash_buf)) return false;
    strlist_push_back(&record->prog_line, prog_bin);
    strlist_push_back(&record->prog_line, sha1_file(prog, hash_buf));
    for (i = 0; i < (unsigned)argc; ++i)
	strlist_push_back(&record->prog_line, argv[i]);

    strlist lib_list = STRLIST_INITIALIZER;
    get_libs(&lib_list, prog);
    for (i = 0; i < lib_list.count; ++i) {
	const char *lib_path = strlist_get(&lib_list, i);

	if (!sha1_file(lib_path, hash_buf)) continue;
	strlist_push_back(&record->lib_line, lib_path);
	strlist_push_back(&record->lib_line, sha1_file(lib_path, hash_buf));
    }

    record->enabled = true;
    return true;
}
示例#4
0
文件: addr.c 项目: dnozay/CEnsemble
addr_id_t addr_udp(inet_t inet, net_port_t port) {
    addr_id_t id ;
    record_clear(&id) ;
    id.kind = ADDR_UDP ;
    id.u.udp.inet = inet ;
    id.u.udp.port = port ;
    return id ;
}
示例#5
0
文件: app.c 项目: joe3501/BlueRing
//清除脱机存储的条码
int setcode_MEM_CLEAR_proc(void)
{
	hw_platform_start_led_blink(LED_GREEN,6);
	record_clear();
	hw_platform_stop_led_blink(LED_GREEN);
	if ((device_current_state == STATE_Memory_Mode)||(device_current_state == STATE_Memory_Mode_BT_Connect)||(device_current_state == STATE_Memory_Mode_BT_WaitPair))
	{
		hw_platform_led_ctrl(LED_GREEN,1);
	}
	return 0;
}
示例#6
0
static void journal_commit_record(GQueue *queue, struct record *record)
{
	if (record->artist != NULL && record->track != NULL) {
		/* append record to the queue; reuse allocated strings */

		g_queue_push_tail(queue, g_memdup(record, sizeof(*record)));

		journal_file_empty = false;
	} else {
		/* free and clear the record, it was not used */

		record_deinit(record);
	}

	record_clear(record);
}
示例#7
0
文件: addr.c 项目: dnozay/CEnsemble
void unmarsh_addr_id(unmarsh_t m, addr_id_t *ret) {
    addr_id_t id ;
    record_clear(&id) ;
    id.kind = unmarsh_enum_ret(m, ADDR_MAX) ;
    switch(id.kind) {
    case ADDR_UDP:
	unmarsh_net_port(m, &id.u.udp.port) ;
	unmarsh_inet(m, &id.u.udp.inet) ;
	break ;
    case ADDR_NETSIM:
	unmarsh_mux(m, &id.u.netsim) ;
	break ;

    OTHERWISE_ABORT() ;
    }
    *ret = id ;
}
示例#8
0
文件: alarm.c 项目: dnozay/CEnsemble
alarm_t alarm_create(
	name_t name,
	alarm_gettime_t gettime,
	alarm_schedule_t schedule,
	alarm_check_t check,
	alarm_min_t min,
	alarm_add_sock_recv_t add_sock_recv,
	alarm_rmv_sock_recv_t rmv_sock_recv,
	alarm_add_sock_xmit_t add_sock_xmit,
	alarm_rmv_sock_xmit_t rmv_sock_xmit, 
	alarm_add_poll_t add_poll,
	alarm_rmv_poll_t rmv_poll,
	alarm_block_t block,
	alarm_block_extern_t block_extern,
	alarm_poll_t poll,
	env_t env
) {
    alarm_t a = record_create(alarm_t, a) ;
    record_clear(a) ;
    a->last_time = time_zero() ;
    a->name = name ;
    a->env = env ;
    a->gettime = gettime ;
    a->schedule = schedule ;
    a->check = check ;
    a->min = min ;
    a->add_sock_recv = add_sock_recv ;
    a->rmv_sock_recv = rmv_sock_recv ;
    a->add_sock_xmit = add_sock_xmit ;
    a->rmv_sock_xmit = rmv_sock_xmit ;
    a->add_poll = add_poll ;
    a->rmv_poll = rmv_poll ;
    a->block = block ;
    a->block_extern = block_extern ;
    a->poll = poll ;
    return a ;
}
示例#9
0
int library_import(struct library *li, const char *scan, const char *path)
{
    int fd, status;
    char *cratename, *pathname;
    pid_t pid;
    FILE *fp;
    struct crate *crate;

    fprintf(stderr, "Scanning '%s'...\n", path);

    pathname = strdupa(path);
    cratename = basename(pathname); /* POSIX version, see basename(3) */
    assert(cratename != NULL);
    crate = use_crate(li, cratename);
    if (crate == NULL)
        return -1;

    pid = fork_pipe(&fd, scan, "scan", path, NULL);
    if (pid == -1)
        return -1;

    fp = fdopen(fd, "r");
    if (fp == NULL) {
        perror("fdopen");
        abort(); /* recovery not implemented */
    }

    for (;;) {
        struct record *d, *x;

        if (get_record(fp, &d) == -1)
            return -1;

        if (d == NULL)
            break;

        /* Add to the crate of all records */

        x = crate_add(&li->all, d);
        if (x == NULL)
            return -1;

        /* If there is an existing entry, use it instead */

        if (x != d) {
            record_clear(d);
            free(d);
            d = x;
        }

        /* Insert into the user's crate */

        if (crate_add(crate, d) == NULL)
            return -1;
    }

    if (fclose(fp) == -1) {
        perror("close");
        abort(); /* assumption fclose() can't on read-only descriptor */
    }

    if (waitpid(pid, &status, 0) == -1) {
        perror("waitpid");
        return -1;
    }

    if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS) {
        fputs("Library scan exited reporting failure.\n", stderr);
        return -1;
    }

    return 0;
}