- Timestamp:
- 2008-02-02T21:48:09Z (15 years ago)
- Branches:
- master
- Children:
- 979cfb4
- Parents:
- f774e01
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
help.c
rf774e01 r0fbda193 71 71 { 72 72 /* FIXME: Clean up */ 73 // help_close( *help ); 74 *help = NULL; 73 help_free( help ); 75 74 g_free( s ); 76 return ( NULL );75 return NULL; 77 76 } 78 77 i = strchr( s, '\n' ) - s; 79 78 80 if( h-> string)79 if( h->title ) 81 80 { 82 81 h = h->next = g_new0( help_t, 1 ); 83 82 } 84 h-> string= g_new ( char, i );83 h->title = g_new ( char, i ); 85 84 86 strncpy( h-> string, s + 1, i - 1 );87 h-> string[i-1] = 0;85 strncpy( h->title, s + 1, i - 1 ); 86 h->title[i-1] = 0; 88 87 h->fd = (*help)->fd; 89 88 h->offset.file_offset = lseek( h->fd, 0, SEEK_CUR ) - buflen + i + 1; … … 103 102 } 104 103 105 char *help_get( help_t **help, char *string ) 104 void help_free( help_t **help ) 105 { 106 help_t *h, *oh; 107 int last_fd = -1; /* Weak de-dupe */ 108 109 if( help == NULL || *help == NULL ) 110 return; 111 112 h = *help; 113 while( h ) 114 { 115 if( h->fd != last_fd ) 116 { 117 close( h->fd ); 118 last_fd = h->fd; 119 } 120 g_free( h->title ); 121 h = (oh=h)->next; 122 g_free( oh ); 123 } 124 125 *help = NULL; 126 } 127 128 char *help_get( help_t **help, char *title ) 106 129 { 107 130 time_t mtime; … … 111 134 for( h = *help; h; h = h->next ) 112 135 { 113 if( h->string != NULL && 114 g_strcasecmp( h->string, string ) == 0 ) 136 if( h->title != NULL && g_strcasecmp( h->title, title ) == 0 ) 115 137 break; 116 138 } … … 119 141 char *s = g_new( char, h->length + 1 ); 120 142 121 if( fstat( h->fd, stat ) != 0 )122 {123 g_free( h );124 *help = NULL;125 return NULL;126 }127 mtime = stat->st_mtime;128 129 if( mtime > h->mtime )130 return NULL;131 132 143 s[h->length] = 0; 133 144 if( h->fd >= 0 ) 134 145 { 146 if( fstat( h->fd, stat ) != 0 ) 147 { 148 g_free( s ); 149 return NULL; 150 } 151 mtime = stat->st_mtime; 152 153 if( mtime > h->mtime ) 154 { 155 g_free( s ); 156 return NULL; 157 } 158 135 159 lseek( h->fd, h->offset.file_offset, SEEK_SET ); 136 160 read( h->fd, s, h->length );
Note: See TracChangeset
for help on using the changeset viewer.