| rev |
line source |
|
Me@0
|
1 /*
|
|
Me@0
|
2 * Author: SeanHalle@yahoo.com
|
|
Me@0
|
3 *
|
|
Me@0
|
4 * Created on June 15, 2009, 10:12 AM
|
|
Me@0
|
5 */
|
|
Me@0
|
6
|
|
Me@0
|
7 #include <stdio.h>
|
|
Me@0
|
8 #include <stdlib.h>
|
|
Me@0
|
9 #include <string.h>
|
|
Me@0
|
10
|
|
Me@0
|
11 #include "../Matrix_Mult.h"
|
|
Me@0
|
12
|
|
Me@0
|
13 ParamStruc * makeParamFromStrs( char * type, char *value );
|
|
Me@0
|
14
|
|
Me@0
|
15 #define _GNU_SOURCE
|
|
Me@0
|
16
|
|
Me@0
|
17 /*Copied from gnu's win32 lib
|
|
Me@0
|
18 */
|
|
Me@0
|
19 ssize_t
|
|
Me@0
|
20 getline( char **lineptr, size_t *n, FILE *stream )
|
|
Me@0
|
21 {
|
|
Me@0
|
22 if ( lineptr == NULL || n == NULL) return -1;
|
|
Me@0
|
23 if (*lineptr == NULL || *n == 0)
|
|
Me@0
|
24 { *n = 500; //max length of line in a config file
|
|
Me@0
|
25 *lineptr = (char *) malloc( *n );
|
|
Me@0
|
26 if (*lineptr == NULL) return -1;
|
|
Me@0
|
27 }
|
|
Me@0
|
28 if( fgets( *lineptr, *n, stream ) )
|
|
Me@0
|
29 return *n;
|
|
Me@0
|
30 else
|
|
Me@0
|
31 return -1;
|
|
Me@0
|
32 }
|
|
Me@0
|
33
|
|
Me@0
|
34 void
|
|
Me@0
|
35 readParamFileIntoBag( char *paramFileName, ParamBag * bag )
|
|
Me@0
|
36 {
|
|
Me@0
|
37 size_t lineSz = 0;
|
|
Me@0
|
38 FILE* paramFile;
|
|
Me@0
|
39 char* line = NULL;
|
|
Me@0
|
40
|
|
Me@0
|
41 char* paramType;// = malloc( 12 ); //"double" is the longest type
|
|
Me@0
|
42 char* paramName;// = malloc( 500 ); //max of 500 chars in name
|
|
Me@0
|
43 char* paramValue;// = malloc( 500 ); //max of 500 chars in value
|
|
Me@0
|
44
|
|
Me@0
|
45 lineSz = 500; //max length of line in a config file
|
|
Me@0
|
46 line = (char *) malloc( lineSz );
|
|
Me@0
|
47 if( line == NULL )
|
|
Me@0
|
48 { BLIS_DKU__throwError( "no mem for line" );
|
|
Me@0
|
49 return;
|
|
Me@0
|
50 }
|
|
Me@0
|
51
|
|
Me@0
|
52
|
|
Me@0
|
53 paramFile = fopen( paramFileName, "r" );
|
|
Me@0
|
54 fseek( paramFile, 0, SEEK_SET );
|
|
Me@0
|
55 while( !feof( paramFile ) )
|
|
Me@0
|
56 { while( getline( &line, &lineSz, paramFile ) != -1 )
|
|
Me@0
|
57 {
|
|
Me@0
|
58 char *lineEnd = line + strlen(line) +1;
|
|
Me@0
|
59 char *searchPos = line;
|
|
Me@0
|
60
|
|
Me@0
|
61 if( *line == '\n') continue; //blank line
|
|
Me@0
|
62 if( *line == '/' ) continue; //comment line
|
|
Me@0
|
63
|
|
Me@0
|
64 //read the param type
|
|
Me@0
|
65 paramType = line; //start of string
|
|
Me@0
|
66 int foundIt = 0;
|
|
Me@0
|
67 for( ; searchPos < lineEnd && !foundIt; searchPos++)
|
|
Me@0
|
68 { if( *searchPos == ',' )
|
|
Me@0
|
69 { foundIt = 1;
|
|
Me@0
|
70 *searchPos = 0; //mark end of string
|
|
Me@0
|
71 }
|
|
Me@0
|
72 }
|
|
Me@0
|
73 //get rid of leading spaces
|
|
Me@0
|
74 for( ; searchPos < lineEnd; searchPos++)
|
|
Me@0
|
75 { if( *searchPos != ' ' ) break;
|
|
Me@0
|
76 }
|
|
Me@0
|
77 //read the param name
|
|
Me@0
|
78 paramName = searchPos;
|
|
Me@0
|
79 foundIt = 0;
|
|
Me@0
|
80 for( ; searchPos < lineEnd && !foundIt; searchPos++)
|
|
Me@0
|
81 { if( *searchPos == ',' )
|
|
Me@0
|
82 { foundIt = 1;
|
|
Me@0
|
83 *searchPos = 0; //mark end
|
|
Me@0
|
84 }
|
|
Me@0
|
85 }
|
|
Me@0
|
86 //get rid of leading spaces
|
|
Me@0
|
87 for( ; searchPos < lineEnd; searchPos++)
|
|
Me@0
|
88 { if( *searchPos != ' ' ) break;
|
|
Me@0
|
89 }
|
|
Me@0
|
90 //read the param value
|
|
Me@0
|
91 paramValue = searchPos;
|
|
Me@0
|
92 foundIt = 0;
|
|
Me@0
|
93 for( ; searchPos < lineEnd && !foundIt; searchPos++)
|
|
Me@0
|
94 { if( *searchPos == '\n' )
|
|
Me@0
|
95 { foundIt = 1;
|
|
Me@0
|
96 *searchPos = 0; //mark end
|
|
Me@0
|
97 }
|
|
Me@0
|
98 }
|
|
Me@0
|
99 if( foundIt )
|
|
Me@0
|
100 { printf("Found: %s, %s, %s\n", paramType, paramName, paramValue );
|
|
Me@0
|
101 ParamStruc *
|
|
Me@0
|
102 paramStruc = makeParamFromStrs( paramType, paramValue );
|
|
Me@0
|
103 addParamToBag( paramName, paramStruc, bag );
|
|
Me@0
|
104 }
|
|
Me@0
|
105 }
|
|
Me@0
|
106 }
|
|
Me@0
|
107 free( line );
|
|
Me@0
|
108 }
|
|
Me@0
|
109
|