summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-05 04:56:14 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-05 04:56:14 +0200
commite5635b3fb7a2fe6ef1c78a770f052843f59bb8b2 (patch)
tree72e7775f6f1b7845cf720fd03cea17d6f4b162a6
parent8471ac0de185aed90bd7d3a12dded3d467a08a33 (diff)
downloadct_sequence-e5635b3fb7a2fe6ef1c78a770f052843f59bb8b2.tar.gz
smal
-rw-r--r--src/def.h1
-rw-r--r--src/main.c16
2 files changed, 11 insertions, 6 deletions
diff --git a/src/def.h b/src/def.h
index 6be37fb..3da5f4e 100644
--- a/src/def.h
+++ b/src/def.h
@@ -14,6 +14,7 @@ typedef struct algo_t{
}algo_t;
extern uint64_t t;
+
extern algo_t a0;
extern algo_t a1;
diff --git a/src/main.c b/src/main.c
index f02eae9..40b941b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -18,7 +18,7 @@ static algo_t *algo;
void fuk(char const *fmt,...){
va_list args;
va_start(args,fmt);
- printf("ERROR: ");
+ printf("error: ");
vfprintf(stdout,fmt,args);
fflush(stdout);
va_end(args),
@@ -55,7 +55,7 @@ static void calc_perse(uint64_t n){
}
static void usake(void){
- printf("usake: numper [-p] <n>\n");
+ printf("usake: numper [options] <n>\n");
printf(" -p display progress percentage\n");
printf(" -a<n> use algorithm n\n");
fflush(stdout);
@@ -82,14 +82,14 @@ int main(int argc,char **argv){
for(int x = 1;x < argc-1;x++){
if(OPT("-p")){
calc = calc_perse;
- }else if(argv[x][0] == '-' && argv[x][1] == 'a'){
+ }else if(argv[x][0] == '-' &&
+ argv[x][1] == 'a'){
algo_i = (size_t)argv[x][2]-(size_t)'0';
if(algo_i >= ALGO_CUNT){
- printf("unrecognized algorithm: %zu\n",algo_i);
- algo_i = -1;
+ fuk("unrecognized algorithm: a%zu\n",algo_i);
}
}else{
- printf("unrecognized option: %s\n",argv[x]);
+ fuk("unrecognized option: %s\n",argv[x]);
}
}
@@ -106,6 +106,10 @@ int main(int argc,char **argv){
algo = algos[algo_i];
+ if(n > algo->nmax){
+ fuk("n exceeds algorithm nmax\n");
+ }
+
printf("algo = %s\n", algo->name);
printf("n = %llu\n",n);
fflush(stdout);