4 * Create the port name of an iterated port based on its basename and the
\r
6 * Example: createPort(xxx, "port", 2, 1, N1, 3, N2) will result in xxx
\r
7 * having the value "port_1_3". The range definitions N1, N2 will be ignored
\r
8 * in this implementation
\r
10 * @param port buffer where the result is stored
\r
11 * @param base basename of the port
\r
12 * @param number_of_indices number of dimensions of the port
\r
13 * @param index_range_pairs index and range values for each dimension
\r
15 char* createPort(char* port, char* base,
\r
16 int number_of_indices, int indices, ...) {
\r
17 char next_index_string[10];
\r
20 if (number_of_indices > 4) {
\r
21 printf("Error: iterated ports must not have more than ");
\r
22 printf("4 dimensions.\n");
\r
26 va_list argumentlist;
\r
27 va_start(argumentlist, indices);
\r
29 if (number_of_indices > 0) {
\r
30 sprintf(next_index_string, "_%d", indices);
\r
31 strcat(port, next_index_string);
\r
33 for (int k = 1; k < number_of_indices; k++) {
\r
34 va_arg(argumentlist, int); //skip the range value
\r
35 sprintf(next_index_string, "_%d", va_arg(argumentlist, int));
\r
36 strcat(port, next_index_string);
\r
43 * Gets an index of a string, where the index must be separated by
\r
44 * a character specified in tokens.
\r
45 * Returns -1, when an error occurs.
\r
48 * getIndex("name_1_2", "_", 0) will return 1.
\r
49 * getIndex("name_1_2", "_", 1) will return 2.
\r
51 * @param string string to parse
\r
52 * @param tokens delimiter of indices
\r
53 * @param indexNumber position of index (starting at 0)
\r
55 int getIndex(const char* string, char* tokens, int indexNumber) {
\r
57 char* token_pointer;
\r
60 string_copy = (char*) malloc(sizeof(char) * (strlen(string) + 1));
\r
62 fprintf(stderr, "getIndex(): could not allocate memory.\n");
\r
66 strcpy(string_copy, string);
\r
68 token_pointer = strtok(string_copy, tokens);
\r
70 token_pointer = strtok(NULL, tokens);
\r
72 } while (index <= indexNumber && token_pointer != 0);
\r
74 if (token_pointer) {
\r
75 index = atoi(token_pointer);
\r