- Timestamp:
- 2008-12-25T11:05:11Z (16 years ago)
- Branches:
- master
- Children:
- 9e768da
- Parents:
- 72b6783e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/ini.c
r72b6783e r489f996 53 53 } 54 54 55 /* Strips leading and trailing whitespace and returns a pointer to the first 56 non-ws character of the given string. */ 57 static char *ini_strip_whitespace( char *in ) 58 { 59 char *e; 60 61 while( isspace( *in ) ) 62 in++; 63 64 e = in + strlen( in ) - 1; 65 while( e > in && isspace( *e ) ) 66 e--; 67 e[1] = 0; 68 69 return in; 70 } 71 55 72 int ini_read( ini_t *file ) 56 73 { … … 62 79 63 80 file->line++; 64 65 /* Leading whitespace */66 while( *file->cur == ' ' || *file->cur == '\t' )67 file->cur++;68 81 69 82 /* Find the end of line */ 70 83 if( ( e = strchr( file->cur, '\n' ) ) != NULL ) 71 84 { 85 *e = 0; 72 86 next = e + 1; 73 87 } … … 75 89 { 76 90 /* No more lines. */ 77 e = file->cur + strlen( file->cur ) - 1;91 e = file->cur + strlen( file->cur ); 78 92 next = NULL; 79 93 } … … 81 95 /* Comment? */ 82 96 if( ( s = strchr( file->cur, '#' ) ) != NULL ) 83 e = s - 1;97 *s = 0; 84 98 85 /* And kill trailing whitespace. */ 86 while( isspace( *e ) && e > file->cur ) 87 e--; 88 e[1] = 0; 89 90 printf( "Stripped line: '%s'\n", file->cur ); 99 file->cur = ini_strip_whitespace( file->cur ); 91 100 92 101 if( *file->cur == '[' ) … … 97 106 *s = 0; 98 107 file->c_section = file->cur; 99 100 printf( "Section started: %s\n", file->c_section );101 108 } 102 109 } … … 104 111 { 105 112 *s = 0; 106 file->value = s + 1; 107 while( isspace( *file->value ) ) 108 file->value++; 109 110 s--; 111 while( isspace( *s ) && s > file->cur ) 112 s--; 113 s[1] = 0; 114 file->key = file->cur; 113 file->key = ini_strip_whitespace( file->cur ); 114 file->value = ini_strip_whitespace( s + 1 ); 115 115 116 116 if( ( s = strchr( file->key, '.' ) ) != NULL ) … … 126 126 127 127 file->cur = next; 128 129 printf( "%s.%s = '%s'\n", file->section, file->key, file->value );130 131 128 return 1; 132 129 } 133 /* else: noise , butlet's just ignore it. */130 /* else: noise/comment/etc, let's just ignore it. */ 134 131 135 132 file->cur = next;
Note: See TracChangeset
for help on using the changeset viewer.