@@ -16,14 +16,15 @@ SDL_Color text_color = {COLOR_TEXT_R, COLOR_TEXT_G, COLOR_TEXT_B};
1616
1717/* Static Variables */
1818static s_prod_test prod_tests [] = {
19- {"FAIL" , launch_prod_screen_fail },
20- {"WAIT_BATTERY" , launch_prod_screen_waitbattery },
21- {"DISPLAY" , launch_prod_screen_display },
22- {"BUTTONS" , launch_prod_screen_buttons },
23- {"SPEAKER" , launch_prod_screen_speaker },
24- {"LED" , launch_prod_screen_LED },
25- {"MAGNET" , launch_prod_screen_magnet },
26- {"VALIDATE" , launch_prod_screen_validation }
19+ {"FAIL" , launch_prod_screen_fail , 0 },
20+ {"WAIT_BATTERY" , launch_prod_screen_waitbattery , 0 },
21+ {"DISPLAY" , launch_prod_screen_display , 0 },
22+ {"BUTTONS" , launch_prod_screen_buttons , 0 },
23+ {"SPEAKER" , launch_prod_screen_speaker , 0 },
24+ {"LED" , launch_prod_screen_LED , 0 },
25+ {"MAGNET" , launch_prod_screen_magnet , 0 },
26+ {"VALIDATE" , launch_prod_screen_validation , 0 },
27+ {"SHOW_IMAGE" , launch_prod_screen_showImage , 1 }
2728};
2829static int idx_current_prod_test = 0 ;
2930
@@ -87,48 +88,58 @@ void deinit_libraries(){
8788
8889void usage (char * progname ){
8990 int i ;
90- fprintf (stderr , "Usage: %s [prod_test]\n\n" , progname );
91+ fprintf (stderr , "Usage: %s [prod_test] [optionnal: arg] \n\n" , progname );
9192 fprintf (stderr , "\"prod_tests\" in:\n" );
9293 for (i = 0 ; i < sizeof (prod_tests )/sizeof (prod_tests [0 ]); i ++ ){
93- fprintf (stderr , " %s\n" , prod_tests [i ].cmd_line_argument );
94+ if (!prod_tests [i ].nb_args_needed ){
95+ fprintf (stderr , " %s\n" , prod_tests [i ].cmd_line_argument );
96+ }
97+ else {
98+ fprintf (stderr , " %s [needs %d additional args]\n" ,
99+ prod_tests [i ].cmd_line_argument , prod_tests [i ].nb_args_needed );
100+ }
94101 }
95102 exit (EXIT_FAILURE );
96103}
97104
98105
99106int main (int argc , char * argv [])
100107{
101- int optind , i ;
108+ int i ;
102109 int res = ERROR_MANUAL_FAIL ;
103110
104- if (argc != 2 ){
111+ if (argc < 2 ){
105112 usage (argv [0 ]);
106113 }
107114
108- for (optind = 1 ; optind < argc ; optind ++ ) {
115+ char * prod_test_str = argv [1 ];
116+ int test_found = 0 ;
109117
110- int test_found = 0 ;
111-
112- /* Check argument */
113- for (i = 0 ; i < sizeof (prod_tests )/sizeof (prod_tests [0 ]); i ++ ){
114- if (!strcmp (prod_tests [i ].cmd_line_argument , argv [optind ])){
115- test_found = 1 ;
116- idx_current_prod_test = i ;
117- break ;
118- }
118+ /* Check argument */
119+ for (i = 0 ; i < sizeof (prod_tests )/sizeof (prod_tests [0 ]); i ++ ){
120+ if (!strcmp (prod_tests [i ].cmd_line_argument , prod_test_str )){
121+ test_found = 1 ;
122+ idx_current_prod_test = i ;
123+ break ;
119124 }
125+ }
120126
121- if (!test_found ){
122- usage (argv [0 ]);
123- }
124-
125- }
127+ if (test_found && (prod_tests [i ].nb_args_needed + 2 != argc ) ){
128+ fprintf (stderr , "ERROR: %s needs %d additional args\n" ,
129+ prod_tests [idx_current_prod_test ].cmd_line_argument ,
130+ prod_tests [idx_current_prod_test ].nb_args_needed );
131+ exit (EXIT_FAILURE );
132+ }
133+
134+ if (!test_found ){
135+ usage (argv [0 ]);
136+ }
126137
127138 /// Init SDL
128139 init_libraries ();
129140
130141 /// Launch Program
131- res = prod_tests [idx_current_prod_test ].ptr_function_launch_test ();
142+ res = prod_tests [idx_current_prod_test ].ptr_function_launch_test (argc - 2 , & argv [ 2 ] );
132143
133144 /// Deinit SDL
134145 deinit_libraries ();
0 commit comments