X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=aft.c;h=d88be97e4c175cfb588291ae2a34f2f7571275bf;hp=ac7d9a1a34c69412242bef6631841238f07d8aea;hb=29335f03c2a0581cb3c88295cf9f09100048cb8d;hpb=f51c95fa0edaaf651387456e716899433a0c579c diff --git a/aft.c b/aft.c index ac7d9a1a..d88be97e 100644 --- a/aft.c +++ b/aft.c @@ -351,7 +351,6 @@ int aft_get_row_of_path(char *path, struct osl_row **row) { struct osl_object obj = {.data = path, .size = strlen(path) + 1}; - PARA_NOTICE_LOG("audio_file_table: %p\n", audio_file_table); return osl_get_row(audio_file_table, AFTCOL_PATH, &obj, row); } @@ -601,25 +600,27 @@ static int get_local_time(uint64_t *seconds, char *buf, size_t size) } \ } -static short unsigned get_duration(int seconds_total, char *buf, short unsigned max_width) +static short unsigned get_duration_width(int seconds) { short unsigned width; - int s = seconds_total; - unsigned hours = s / 3600, mins = (s % 3600) / 60, secs = s % 60; - - if (s < 3600) { /* less than one hour => m:ss or mm:ss */ - GET_NUM_DIGITS(mins, &width); /* 1 or 2 */ - width += 3; /* 4 or 5 */ - if (buf) - sprintf(buf, "%*u:%02u", max_width - width + 1, mins, secs); - return width; - } + unsigned hours = seconds / 3600, mins = (seconds % 3600) / 60; + + if (!hours) /* less than one hour => m:ss or mm:ss => 4 or 5 digits */ + return 4 + (mins > 9); /* more than one hour => h:mm:ss, hh:mm:ss, hhh:mm:ss, ... */ GET_NUM_DIGITS(hours, &width); - width += 6; - if (buf) - sprintf(buf, "%*u:%02u:%02u", max_width - width + 1, hours, mins, secs); - return width; + return width + 6; +} + +static void get_duration_buf(int seconds, char *buf, short unsigned max_width) +{ + unsigned hours = seconds / 3600, mins = (seconds % 3600) / 60; + + if (!hours) /* m:ss or mm:ss */ + sprintf(buf, "%*u:%02u", max_width - 3, mins, seconds % 60); + else /* more than one hour => h:mm:ss, hh:mm:ss, hhh:mm:ss, ... */ + sprintf(buf, "%*u:%02u:%02u", max_width - 6, hours, mins, + seconds % 60); } static char *make_attribute_line(const char *att_bitmap, struct afs_info *afsi) @@ -674,7 +675,7 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts, sizeof(last_played_time)); if (ret < 0) return ret; - get_duration(afhi->seconds_total, duration_buf, w->duration_width); + get_duration_buf(afhi->seconds_total, duration_buf, w->duration_width); if (have_score) { if (opts->mode == LS_MODE_LONG) sprintf(score_buf, "%*li ", w->score_width, d->score); @@ -942,8 +943,8 @@ static int prepare_ls_row(struct osl_row *row, void *ls_opts) w->frequency_width = PARA_MAX(w->frequency_width, num_digits); GET_NUM_DIGITS(d->afsi.num_played, &num_digits); w->num_played_width = PARA_MAX(w->num_played_width, num_digits); - /* just get the number of chars to print this amount of time */ - tmp = get_duration(d->afhi.seconds_total, NULL, 0); + /* get the number of chars to print this amount of time */ + tmp = get_duration_width(d->afhi.seconds_total); w->duration_width = PARA_MAX(w->duration_width, tmp); if (options->flags & LS_FLAG_ADMISSIBLE_ONLY) { GET_NUM_DIGITS(score, &num_digits); @@ -1347,8 +1348,6 @@ static int com_add_callback(const struct osl_object *query, default_afsi.last_played = time(NULL) - 365 * 24 * 60 * 60; default_afsi.audio_format_id = read_u8(buf + AFTROW_AUDIO_FORMAT_OFFSET); - if (flags & ADD_FLAG_VERBOSE) - PARA_NOTICE_LOG("adding %s\n", path); objs[AFTCOL_AFSI].data = &afsi_buf; objs[AFTCOL_AFSI].size = AFSI_SIZE; save_afsi(&default_afsi, &objs[AFTCOL_AFSI]); @@ -1458,6 +1457,8 @@ static int add_one_audio_file(const char *arg, const void *private_data) format_num = ret; afhi_ptr = &afhi; } + if (pad->flags & ADD_FLAG_VERBOSE) + send_va_buffer(pad->fd, "adding %s\n", path); munmap(map.data, map.size); save_audio_file_info(hash, path, afhi_ptr, pad->flags, format_num, &obj); /* Ask afs to consider this entry for adding. */ @@ -1483,7 +1484,6 @@ int com_add(int fd, int argc, char * const * const argv) struct private_add_data pad = {.fd = fd, .flags = 0}; struct stat statbuf; - PARA_NOTICE_LOG("argv[1]: %s\n", argv[1]); for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (arg[0] != '-')