[Mplayer-cvslog] CVS: main/TOOLS vivodump.c,1.8,1.9

Alexander Strasser eclipse7 at gmx.net
Thu Oct 28 16:23:14 CEST 2004


Diego Biurrun CVS wrote ( On Thu, Oct 28, 2004 at 03:02:26AM +0200 ):
> CVS change done by Diego Biurrun CVS
> 
> Update of /cvsroot/mplayer/main/TOOLS
> In directory mail:/var2/tmp/cvs-serv30824
> 
> Modified Files:
> 	vivodump.c 
> Log Message:
> Remove hardcoded filenames in favor of command line parameters, some error
> checking added, patch by Reza Jelveh.
> 
> 
> Index: vivodump.c
> ===================================================================
[...]
> -int main(){
> +int main(int argv,char ** argc){

A bit weird variable naming imho.
Interchanging the traditional main param names doesn't make sense.

[...]
> +// input
> +if(!(f=fopen(argc[1],"rb"))){
> +       printf("Couldn't open input file.\n");
> +       return -1;
> +}
> +// output
> +if(!(f2=fopen(argc[2],"wb"))){
> +       printf("Couldn't open output file.\n");
> +       return -1;
> +}

This is ugly: whatever is at this positions when there are less than 2 extra
args given to the program shouldn't be interpreted as filenames.
Though according to the standards ( at least ANSI I guess ) you can be sure
that the last pointer in the argument vector is NULL. So with this code and
too few arguments one of the fopen()s fails and thus the program terminates,
but I'm quite sure this wasn't intended and it's ugly anyway.

I would say sth like the attached patch should be commited instead.

  Alex (beastd)
-------------- next part --------------
Index: vivodump.c
===================================================================
RCS file: /cvsroot/mplayer/main/TOOLS/vivodump.c,v
retrieving revision 1.8
diff -u -r1.8 vivodump.c
--- vivodump.c	28 Oct 2004 00:50:21 -0000	1.8
+++ vivodump.c	28 Oct 2004 13:40:02 -0000
@@ -151,15 +151,15 @@
 
 int postable[32768];
 
-int main(){
+int main(int argc,char ** argv){
 int c;
 unsigned int head=-1;
 int pos=0;
 int frames=0;
-FILE *f=fopen("paulvandykforanangel.viv","rb");
-FILE *f2=fopen("GB1.avi","wb");
-muxer_t* avi=muxer_new_muxer(MUXER_TYPE_AVI,f2);
-muxer_stream_t* mux=muxer_new_stream(avi,MUXER_TYPE_VIDEO);
+FILE *f;
+FILE *f2;
+muxer_t* avi;
+muxer_stream_t* mux;
 //unsigned char* buffer=malloc(0x200000);
 int i,len;
 int v_id=0;
@@ -167,6 +167,27 @@
 int flag2=0;
 int prefix=0;
 
+if ( argc == 3 ){
+    // input
+    if(!(f=fopen(argv[1],"rb"))){
+           printf("Couldn't open input file.\n");
+           return -1;
+    }
+    // output
+    if(!(f2=fopen(argv[2],"wb"))){
+           printf("Couldn't open output file.\n");
+           return -1;
+    }
+} else {
+    printf("Too few arguments given!\n"
+           "Usage: %s <input_file> <output_file>\n", argv[0]);
+
+    return -1;
+}
+
+avi=muxer_new_muxer(MUXER_TYPE_AVI,f2);
+mux=muxer_new_stream(avi,MUXER_TYPE_VIDEO);
+
 mux->buffer_size=0x200000;
 mux->buffer=malloc(mux->buffer_size);
 


More information about the MPlayer-cvslog mailing list