[xiph-cvs] cvs commit: vorbis-tools/vorbiscomment vcomment.c
Michael Smith
msmith at xiph.org
Wed Jul 11 21:01:44 PDT 2001
msmith 01/07/11 21:01:43
Modified: vorbiscomment vcomment.c
Log:
Add some stuff to vorbiscomment:
Document -c option
Add -a option to append a set of comments instead of just writing them.
Add capability to use a temporary file automatically, and rename it to
the input file at the end.
Revision Changes Path
1.8 +39 -9 vorbis-tools/vorbiscomment/vcomment.c
Index: vcomment.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vorbiscomment/vcomment.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- vcomment.c 2001/07/12 02:26:40 1.7
+++ vcomment.c 2001/07/12 04:01:43 1.8
@@ -32,11 +32,13 @@
char *infilename, *outfilename;
char *commentfilename;
FILE *in, *out, *com;
+ int tempoutfile;
} param_t;
#define MODE_NONE 0
#define MODE_LIST 1
#define MODE_WRITE 2
+#define MODE_APPEND 3
/* prototypes */
void usage(void);
@@ -99,7 +101,7 @@
return 0;
}
- if (param->mode == MODE_WRITE) {
+ if (param->mode == MODE_WRITE || param->mode == MODE_APPEND) {
state = vcedit_new_state();
@@ -112,8 +114,11 @@
/* grab and clear the exisiting comments */
vc = vcedit_comments(state);
- vorbis_comment_clear(vc);
- vorbis_comment_init(vc);
+ if(param->mode != MODE_APPEND)
+ {
+ vorbis_comment_clear(vc);
+ vorbis_comment_init(vc);
+ }
/* build the replacement structure */
{
@@ -226,10 +231,17 @@
fprintf(stderr,
"Usage: \n"
" vorbiscomment [-l] file.ogg (to list the comments)\n"
+ " vorbiscomment -a in.ogg out.ogg (to append comments)\n"
" vorbiscomment -w in.ogg out.ogg (to modify comments)\n"
" in the write case, a new set of comments in the form\n"
" 'TAG=value' is expected on stdin. This set will\n"
" completely replace the existing set.\n"
+ " Either of -a and -w can take only a single filename,\n"
+ " in which case a temporary file will be used.\n"
+ " -c can be used to take comments from a specified file\n"
+ " instead of stdin.\n"
+ " Example: vorbiscomment -a in.ogg -c comments.txt\n"
+ " will append the comments in comments.txt to in.ogg\n"
);
}
@@ -273,7 +285,7 @@
int ret;
int option_index = 1;
- while ((ret = getopt_long(argc, argv, "lwhqc:",
+ while ((ret = getopt_long(argc, argv, "alwhqc:",
long_options, &option_index)) != -1) {
switch (ret) {
case 0:
@@ -286,6 +298,9 @@
case 'w':
param->mode = MODE_WRITE;
break;
+ case 'a':
+ param->mode = MODE_APPEND;
+ break;
case 'h':
usage();
exit(0);
@@ -303,14 +318,26 @@
}
/* remaining bits must be the filenames */
- if ((param->mode == MODE_LIST && (argc - optind) != 1) ||
- (param->mode == MODE_WRITE && (argc - optind) != 2)) {
+ if((param->mode == MODE_LIST && (argc-optind) != 1) ||
+ ((param->mode == MODE_WRITE || param->mode == MODE_APPEND) &&
+ ((argc-optind) < 1 || (argc-optind) > 2))) {
usage();
exit(1);
}
+
param->infilename = strdup(argv[optind]);
- if (param->mode == MODE_WRITE)
- param->outfilename = strdup(argv[optind+1]);
+ if (param->mode == MODE_WRITE || param->mode == MODE_APPEND)
+ {
+ if(argc-optind == 1)
+ {
+ param->tempoutfile = 1;
+ param->outfilename = malloc(strlen(param->infilename)+8);
+ strcpy(param->outfilename, param->infilename);
+ strcat(param->outfilename, ".vctemp");
+ }
+ else
+ param->outfilename = strdup(argv[optind+1]);
+ }
}
/**********
@@ -341,7 +368,7 @@
exit(1);
}
- if (p->mode == MODE_WRITE) {
+ if (p->mode == MODE_WRITE || p->mode == MODE_APPEND) {
/* open output for write mode */
@@ -407,4 +434,7 @@
if (p->in != NULL) fclose(p->in);
if (p->out != NULL) fclose(p->out);
if (p->com != NULL) fclose(p->com);
+
+ if(p->tempoutfile)
+ rename(p->outfilename, p->infilename);
}
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list