1 /* Littlewood-Richardson Calculator 2 * Copyright (C) 1999- Anders S. Buch (asbuch at math rutgers edu) 3 * See the file LICENSE for license information. 4 */ 5 6 #include <ctype.h> 7 #include <unistd.h> 8 #include <stdlib.h> 9 extern int optind; 10 11 #include "vectarg.h" 12 #include "vector.h" 13 get_vect_arg(int ac,char ** av)14vector *get_vect_arg(int ac, char **av) 15 { 16 int n, i, x; 17 int *tmp; 18 vector *res; 19 char *endptr; 20 char ch; 21 22 if (optind == ac) 23 return NULL; 24 25 if (optind == 0) 26 { 27 optind++; 28 } 29 else 30 { 31 /* skip any "-" or "/" argument */ 32 ch = *(av[optind]); 33 if ((ch == '-' || ch == '/') && *(av[optind] + 1) == '\0') 34 optind++; 35 } 36 37 tmp = amalloc((ac - optind) * sizeof(int)); 38 n = 0; 39 40 while (optind < ac) 41 { 42 x = strtol(av[optind], &endptr, 10); 43 if (endptr == av[optind] || *endptr != '\0') 44 break; 45 46 tmp[n++] = x; 47 optind++; 48 } 49 50 if (n == 0) 51 { 52 afree(tmp); 53 return NULL; 54 } 55 56 res = v_new(n); 57 for (i = 0; i < n; i++) 58 v_elem(res, i) = tmp[i]; 59 60 afree(tmp); 61 62 return res; 63 } 64