diff options
-rw-r--r-- | src/ansi2knr.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/ansi2knr.c b/src/ansi2knr.c index c6ee83309..791eee04c 100644 --- a/src/ansi2knr.c +++ b/src/ansi2knr.c @@ -184,7 +184,7 @@ main(argc, argv) */ int convert_varargs = 1; - if ( argc > 1 && argv[1][0] == '-' ) + if ( argc > 1 && argv[1][0] == '-' && argv[1][1] ) { if ( !strcmp(argv[1], "--varargs") ) { convert_varargs = 1; argc--; @@ -195,30 +195,29 @@ main(argc, argv) exit(1); } } - if (argc < 2 || argc > 3) + switch ( argc ) { + default: printf("Usage: ansi2knr input_file [output_file]\n"); + exit(0); + case 2: + out = stdout; + break; + case 3: + out = fopen(argv[2], "w"); + if ( out == NULL ) + { fprintf(stderr, "Cannot open output file %s\n", argv[2]); exit(1); } - in = fopen(argv[1], "r"); + } + if ( argv[1][0] == '-' && !argv[1][1] ) + in = stdin; + else + in = fopen(argv[1], "r"); if ( in == NULL ) - { - fprintf(stderr, "Cannot open input file %s\n", argv[1]); + { fprintf(stderr, "Cannot open input file %s\n", argv[1]); exit(1); } - if (argc == 3) - { - out = fopen(argv[2], "w"); - if ( out == NULL ) - { - fprintf(stderr, "Cannot open output file %s\n", argv[2]); - exit(1); - } - } - else - { - out = stdout; - } fprintf(out, "#line 1 \"%s\"\n", argv[1]); buf = malloc(bufsize); line = buf; |