static int proc_args(int argc, char *argv[]) { unsigned short n, ass, n_timed; unsigned short *toogle; unsigned short argnr; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "scan", strlen("scan")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of kbd_test_scan() \n"); return 1; } if( (ass = parse_ushort(argv[2], 10)) == USHRT_MAX ) return 1; printf("timer: kbd_test_scan\n"); kbd_test_scan(ass); return 0; } else if (strncmp(argv[1], "leds", strlen("leds")) == 0) { argnr = (argc - 2); n = argnr; unsigned short * leds = (unsigned short *) malloc (n); unsigned short a = 2; unsigned short l = 0; for (; a<argc; a++, l++) { if (parse_ushort(argv[a], 10) > 2 || parse_ushort(argv[a], 10) < 0) { printf("error : non valid value for LEDS"); free(leds); return 1; } else leds[l] = parse_ushort(argv[a], 10); } printf("timer: kbs_test_leds\n"); kbd_test_leds(n, leds); free(leds); return 0; } else if (strncmp(argv[1], "timed_scan", strlen("timed_scan")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of timer_test_int() \n"); return 1; } if( (n_timed = parse_ushort(argv[2], 10)) == USHRT_MAX ) return 1; printf("timer: kbd_test_time_scan\n"); kbd_test_timed_scan(n_timed); return 0; } else { printf("timer: non valid function \"%s\" to test\n", argv[1]); return 1; } }
static int proc_args(int argc, char *argv[]) { unsigned long C, n; unsigned short *leds; int i; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "test_scan", strlen("test_scan")) == 0) { if( argc != 3 ) { printf("kbd: wrong no of arguments for test of kbd_test_scan \n"); return 1; } if( (C = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; if(C>1 || C < 0){ printf("kbd: invalid value for the parametrer\n"); return 1; } printf("kbd:: kbd_test_scan(%lu)\n", (unsigned)C); kbd_test_scan(C); return 0; } else if (strncmp(argv[1], "test_leds", strlen("test_leds")) == 0) { if( argc < 3) { printf("kbd: wrong no of arguments for test of kbd_test_leds \n"); return 1; } leds = malloc((argc - 2) * sizeof(unsigned short)); for (i = 0; i < argc - 2; i++){ leds[i] = parse_ulong(argv[2+i], 10); if(leds[i]<0 || leds[i]>2){ printf("kbd: there is no led with %s bit\n", leds[i]); return 1; } } kbd_test_leds(argc-2,leds); return 0; } else if (strncmp(argv[1], "test_timed_scan", strlen("test_timed_scan")) == 0) { if( argc != 3) { printf("kbd: wrong no of arguments for test of kbd_test_timed_scan \n"); return 1; } if( (n = parse_ulong(argv[2], 10)) == ULONG_MAX ) return 1; if(n < 0){ printf("kbd: %lu is not a valid number for time\n", n); return 1; } printf("kbd:: kbd_test_timed_scan(%lu)\n", (unsigned)n); kbd_test_timed_scan(n); return 0; } else { printf("kbd: non valid function \"%s\" to test\n", argv[1]); return 1; } }