summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-09-16 16:51:45 +0200
committertomsmeding <tom.smeding@gmail.com>2016-09-16 16:51:45 +0200
commite00e4b169975eafdab7479e30c1773c00ec29943 (patch)
treebb7d5771c3fea8d2a15a1858ab66e25e3de00796
parent09e3e442e122d5e6fcab9f36712401ced40ee090 (diff)
Fix negative number parsingHEADmaster
-rw-r--r--number.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/number.c b/number.c
index 4c1f9b2..24bcc33 100644
--- a/number.c
+++ b/number.c
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
+#include <ctype.h>
#include <inttypes.h>
__attribute__((noreturn)) void usage(int argc,char **argv){
@@ -145,6 +146,14 @@ int main(int argc,char **argv){
usage(argc,argv);
}
if(argv[i][0]=='-'){
+ if(isdigit(argv[i][1])){
+ if(numstr==NULL)numstr=argv[i];
+ else {
+ fprintf(stderr,"Unexpected second number '%s'\n",argv[i]);
+ usage(argc,argv);
+ }
+ continue;
+ }
for(int j=1;argv[i][j];j++){
switch(argv[i][j]){
case 'c': capfirst=true; break;
@@ -157,7 +166,7 @@ int main(int argc,char **argv){
} else {
if(numstr==NULL)numstr=argv[i];
else {
- fprintf(stderr,"Unexpected second bare argument '%s'\n",argv[i]);
+ fprintf(stderr,"Unexpected second number '%s'\n",argv[i]);
usage(argc,argv);
}
}