X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=aft.c;h=bfcd1fb0162fe8a8a03c0f5ba165acc60be71cf0;hp=8a8e5282576dec0f3319bb98685bd0e1df9767c5;hb=121015ff5cdbe6af7b84f6245ebe62fe2a52a859;hpb=030a9d5c9fe28328d5db977bf2c8ddbf7302673d diff --git a/aft.c b/aft.c index 8a8e5282..bfcd1fb0 100644 --- a/aft.c +++ b/aft.c @@ -676,21 +676,33 @@ int load_afd(int shmid, struct audio_file_data *afd) static int get_local_time(uint64_t *seconds, char *buf, size_t size, time_t current_time, enum ls_listing_mode lm) { - struct tm t; + struct tm *tm; + /* + * Omit year but show time if the given value is closer to the current + * time than this many seconds. + */ + const time_t m = 6 * 30 * 24 * 3600; /* six months */ - if (!localtime_r((time_t *)seconds, &t)) + tm = localtime((time_t *)seconds); + if (!tm) return -E_LOCALTIME; if (lm == LS_MODE_MBOX) { - if (!strftime(buf, size, "%c", &t)) + if (!strftime(buf, size, "%c", tm)) return -E_STRFTIME; return 1; } - if (*seconds + 6 * 30 * 24 * 3600 > current_time) { - if (!strftime(buf, size, "%b %e %k:%M", &t)) + if (*seconds > current_time - m && *seconds < current_time + m) { + if (!strftime(buf, size, "%b %e %k:%M", tm)) return -E_STRFTIME; return 1; } - if (!strftime(buf, size, "%b %e %Y", &t)) + /* + * If the given time is more than six month away from the current time, + * we print only the year. The additional space character in the format + * string below makes the formated date align nicely with dates that + * contain the time (those written by the above strftime() statement). + */ + if (!strftime(buf, size, "%b %e %Y", tm)) return -E_STRFTIME; return 1; } @@ -726,11 +738,11 @@ static void get_duration_buf(int seconds, char *buf, struct ls_options *opts) if (!hours) { /* m:ss or mm:ss */ max_width = opts->mode == LS_MODE_LONG? opts->widths.duration_width : 4; - sprintf(buf, "%*u:%02u", max_width - 3, mins, seconds % 60); + sprintf(buf, "%*u:%02d", max_width - 3, mins, seconds % 60); } else { /* more than one hour => h:mm:ss, hh:mm:ss, hhh:mm:ss, ... */ max_width = opts->mode == LS_MODE_LONG? opts->widths.duration_width : 7; - sprintf(buf, "%*u:%02u:%02u", max_width - 6, hours, mins, + sprintf(buf, "%*u:%02u:%02d", max_width - 6, hours, mins, seconds % 60); } } @@ -864,14 +876,14 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts, para_printf(b, "%s " /* attributes */ "%*u " /* amp */ - "%*d " /* image_id */ - "%*d " /* lyrics_id */ - "%*d " /* bitrate */ + "%*u " /* image_id */ + "%*u " /* lyrics_id */ + "%*u " /* bitrate */ "%*s " /* audio format */ - "%*d " /* frequency */ - "%d " /* channels */ + "%*u " /* frequency */ + "%u " /* channels */ "%s " /* duration */ - "%*d " /* num_played */ + "%*u " /* num_played */ "%s " /* last_played */ "%s\n", /* path */ att_buf, @@ -915,12 +927,14 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts, WRITE_STATUS_ITEM(b, SI_FREQUENCY, "%dHz\n", afhi->frequency); WRITE_STATUS_ITEM(b, SI_CHANNELS, "%d\n", afhi->channels); WRITE_STATUS_ITEM(b, SI_DURATION, "%s\n", duration_buf); - WRITE_STATUS_ITEM(b, SI_SECONDS_TOTAL, "%lu\n", afhi->seconds_total); + WRITE_STATUS_ITEM(b, SI_SECONDS_TOTAL, "%" PRIu32 "\n", + afhi->seconds_total); WRITE_STATUS_ITEM(b, SI_LAST_PLAYED, "%s\n", last_played_time); - WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%d\n", afsi->num_played); + WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%u\n", afsi->num_played); WRITE_STATUS_ITEM(b, SI_AMPLIFICATION, "%u\n", afsi->amp); WRITE_STATUS_ITEM(b, SI_CHUNK_TIME, "%lu\n", tv2ms(&afhi->chunk_tv)); - WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%lu\n", afhi->chunks_total); + WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%" PRIu32 "\n", + afhi->chunks_total); WRITE_STATUS_ITEM(b, SI_TECHINFO, "%s\n", afhi->techinfo); WRITE_STATUS_ITEM(b, SI_ARTIST, "%s\n", afhi->tags.artist); WRITE_STATUS_ITEM(b, SI_TITLE, "%s\n", afhi->tags.title); @@ -1396,10 +1410,14 @@ int com_ls(struct command_context *cc) return -E_AFT_SYNTAX; } } - if (!strcmp(arg, "-p")) { + if (!strcmp(arg, "-p") || !strcmp(arg, "-F")) { flags |= LS_FLAG_FULL_PATH; continue; } + if (!strcmp(arg, "-b")) { + flags &= ~LS_FLAG_FULL_PATH; + continue; + } if (!strcmp(arg, "-a")) { flags |= LS_FLAG_ADMISSIBLE_ONLY; continue; @@ -1737,6 +1755,8 @@ static int com_add_callback(struct afs_callback_arg *aca) objs[AFTCOL_AFSI].size = AFSI_SIZE; save_afsi(&default_afsi, &objs[AFTCOL_AFSI]); ret = osl(osl_add_and_get_row(audio_file_table, objs, &aft_row)); + if (ret < 0) + goto out; ret = afs_event(AUDIO_FILE_ADD, &aca->pbout, aft_row); out: if (ret < 0) @@ -2024,6 +2044,22 @@ static int com_touch_callback(struct afs_callback_arg *aca) .data = aca, .action = touch_audio_file }; + if (cto->image_id >= 0) { + ret = img_get_name_by_id(cto->image_id, NULL); + if (ret < 0) { + para_printf(&aca->pbout, "invalid image ID: %d\n", + cto->image_id); + return ret; + } + } + if (cto->lyrics_id >= 0) { + ret = lyr_get_name_by_id(cto->lyrics_id, NULL); + if (ret < 0) { + para_printf(&aca->pbout, "invalid lyrics ID: %d\n", + cto->lyrics_id); + return ret; + } + } if (cto->flags & TOUCH_FLAG_FNM_PATHNAME) pmd.fnmatch_flags |= FNM_PATHNAME; ret = for_each_matching_row(&pmd); @@ -2391,6 +2427,7 @@ static int com_setatt_callback(struct afs_callback_arg *aca) ) { char c; unsigned char bitnum; + uint64_t one = 1; len = strlen(p); ret = -E_ATTR_SYNTAX; @@ -2406,9 +2443,9 @@ static int com_setatt_callback(struct afs_callback_arg *aca) goto out; } if (c == '+') - cad.add_mask |= (1UL << bitnum); + cad.add_mask |= (one << bitnum); else - cad.del_mask |= (1UL << bitnum); + cad.del_mask |= (one << bitnum); } ret = -E_ATTR_SYNTAX; if (!cad.add_mask && !cad.del_mask) @@ -2604,7 +2641,7 @@ static int aft_open(const char *dir) if (ret >= 0) { unsigned num; osl_get_num_rows(audio_file_table, &num); - PARA_INFO_LOG("audio file table contains %d files\n", num); + PARA_INFO_LOG("audio file table contains %u files\n", num); return ret; } PARA_NOTICE_LOG("failed to open audio file table\n");