From 6578bb8cdc3e75c0d4e6aae18fd2f74920e0195b Mon Sep 17 00:00:00 2001 From: zvezdochiot Date: Tue, 26 Jul 2022 21:53:56 +0300 Subject: [PATCH] 1.3.2: added description and type for picture --- doc/CHANGELOG | 4 ++++ doc/opuspic2tag.1 | 8 +++++++- doc/opustags.1 | 2 +- package_version | 2 +- src/clipic.c | 29 +++++++++++++++++++---------- src/clitags.c | 5 +++-- src/opustags.h | 2 ++ src/picture.c | 8 +++++--- 8 files changed, 42 insertions(+), 18 deletions(-) diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 59fcc12..ec81f53 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -1,6 +1,10 @@ opustags https://github.com/zvezdochiot/opustags [fork](https://github.com/fmang/opustags) +1.3.2 "convert" + +added description and type for picture + 1.3.1 "convert" added tool for convert picture to tag diff --git a/doc/opuspic2tag.1 b/doc/opuspic2tag.1 index 4797d30..82d8cbe 100644 --- a/doc/opuspic2tag.1 +++ b/doc/opuspic2tag.1 @@ -1,4 +1,4 @@ -.TH OpusPic2Tag 1 "7 Mar 2019" "1.3.1" "User Manual" +.TH OpusPic2Tag 1 "26 Jul 2022" "1.3.2" "User Manual" .SH NAME opuspic2tag \- Convert picture to opus tag .SH SYNOPSIS @@ -13,6 +13,12 @@ opuspic2tag \- Convert picture to opus tag .B \-h, \-\-help Display a brief description of the options. .TP +.B \-d, \-\-desc \fISTRING\fI +description picture +.TP +.B \-t, \-\-type NUM +set image type by 0-20 or keywords, default=3 +.TP .B \-o, \-\-output \fIFILE\fI Output text file. .SH EXAMPLE diff --git a/doc/opustags.1 b/doc/opustags.1 index 86d7c55..00fbea1 100644 --- a/doc/opustags.1 +++ b/doc/opustags.1 @@ -1,4 +1,4 @@ -.TH OpusTags 1 "7 Mar 2019" "1.3.1" "User Manual" +.TH OpusTags 1 "26 Jul 2022" "1.3.2" "User Manual" .SH NAME opustags \- Opus comment editor .SH SYNOPSIS diff --git a/package_version b/package_version index 2b1720b..7b66cc1 100644 --- a/package_version +++ b/package_version @@ -1 +1 @@ -PACKAGE_VERSION="1.3.1" +PACKAGE_VERSION="1.3.2" diff --git a/src/clipic.c b/src/clipic.c index 4399c9b..f7aa72c 100644 --- a/src/clipic.c +++ b/src/clipic.c @@ -18,10 +18,14 @@ const char *usage = "Usage: " UTILS_NAME " [OPTIONS] FILE{.jpg,.png,.gif}\n"; const char *help = "Options:\n" " -h, --help print this help\n" + " -d, --desc STRING description picture\n" + " -t, --type NUM set image type by 0-20 or keywords, default=3\n" " -o, --output FILE write tag to a file (default=stdout)\n"; struct option options[] = { {"help", no_argument, 0, 'h'}, + {"desc", required_argument, 0, 'd'}, + {"type", required_argument, 0, 't'}, {"output", required_argument, 0, 'o'}, {NULL, 0, 0, 0} }; @@ -34,16 +38,24 @@ int main(int argc, char **argv) fputs(usage, stdout); return EXIT_SUCCESS; } - char *path_picture = NULL, *picture_data = NULL, *path_out = NULL; + char *path_picture = NULL, *picture_data = NULL, *picture_desc = NULL, *path_out = NULL; const char *error_message; + unsigned long picture_type = 3; int print_help = 0; int c; - while((c = getopt_long(argc, argv, "ho:", options, NULL)) != -1) + while((c = getopt_long(argc, argv, "hd:t:o:", options, NULL)) != -1) { switch(c){ case 'h': print_help = 1; break; + case 'd': + picture_desc = optarg; + break; + case 't': + picture_type = atoi(optarg); + picture_type = (picture_type > 20) ? 3 : picture_type; + break; case 'o': path_out = optarg; break; @@ -68,7 +80,7 @@ int main(int argc, char **argv) if(path_picture != NULL) { int seen_file_icons=0; - picture_data = opustags_picture_specification_parse(path_picture, &error_message, &seen_file_icons); + picture_data = opustags_picture_specification_parse(path_picture, &error_message, picture_desc, picture_type, &seen_file_icons); if(picture_data == NULL) { fprintf(stderr,"Not read picture: %s\n", error_message); @@ -77,14 +89,10 @@ int main(int argc, char **argv) FILE *out = NULL; if(path_out != NULL) { - char canon_picture[PATH_MAX+1], canon_out[PATH_MAX+1]; - if(realpath(path_picture, canon_picture) && realpath(path_out, canon_out)) + if(strcmp(path_picture, path_out) == 0) { - if(strcmp(canon_picture, canon_out) == 0) - { - fputs("error: the input and output files are the same\n", stderr); - return EXIT_FAILURE; - } + fputs("error: the input and output files are the same\n", stderr); + return EXIT_FAILURE; } out = fopen(path_out, "w"); if(!out) @@ -113,6 +121,7 @@ int main(int argc, char **argv) } fwrite(picture_meta, 1, picture_meta_len, out); free(picture_meta); + fwrite("\n", 1, 1, out); } if(out) fclose(out); diff --git a/src/clitags.c b/src/clitags.c index 0f88188..f420947 100644 --- a/src/clitags.c +++ b/src/clitags.c @@ -54,11 +54,12 @@ int main(int argc, char **argv) fputs(usage, stdout); return EXIT_SUCCESS; } - char *path_in, *path_out = NULL, *inplace = NULL, *path_picture = NULL, *picture_data = NULL; + char *path_in, *path_out = NULL, *inplace = NULL, *path_picture = NULL, *picture_desc = NULL, *picture_data = NULL; const char* to_add[argc]; const char* to_delete[argc]; const char* to_picture[1]; const char *error_message; + unsigned long picture_type = 3; int count_add = 0, count_delete = 0; int delete_all = 0; int set_all = 0; @@ -208,7 +209,7 @@ int main(int argc, char **argv) if(path_picture != NULL) { int seen_file_icons=0; - picture_data = opustags_picture_specification_parse(path_picture, &error_message, &seen_file_icons); + picture_data = opustags_picture_specification_parse(path_picture, &error_message, picture_desc, picture_type, &seen_file_icons); if(picture_data == NULL) { fprintf(stderr,"Not read picture: %s\n", error_message); diff --git a/src/opustags.h b/src/opustags.h index 196b4f2..7ad4d6d 100644 --- a/src/opustags.h +++ b/src/opustags.h @@ -66,6 +66,8 @@ void opustags_params_extract_jpeg(const unsigned char *data, size_t data_length, char *opustags_picture_specification_parse(const char *spec, const char **error_message, + const char *desc, + unsigned long picture_type, int *seen_file_icons); #define READ_U32_BE(buf) \ diff --git a/src/picture.c b/src/picture.c index 9f913b2..4f3770d 100644 --- a/src/picture.c +++ b/src/picture.c @@ -230,9 +230,11 @@ void opustags_params_extract_jpeg(const unsigned char *data, size_t data_length, tag.*/ char *opustags_picture_specification_parse(const char *spec, const char **error_message, - int *seen_file_icons){ + const char *desc, + unsigned long picture_type, + int *seen_file_icons) +{ FILE *picture_file; - unsigned long picture_type; unsigned long width; unsigned long height; unsigned long depth; @@ -254,11 +256,11 @@ char *opustags_picture_specification_parse(const char *spec, full specification just from the spec string. Instead, try to open the file. If it exists, the user probably meant the file.*/ - picture_type=3; width=height=depth=colors=0; mime_type=mime_type_end=description=description_end=filename=spec; is_url=0; picture_file=fopen(filename,"rb"); + if (desc != NULL) description = desc; if(picture_file==NULL&&strchr(spec,'|')){ const char *p; char *q;