@@ -1081,7 +1081,7 @@ size_t trans_add_char( char ch, section_def *section )
10811081 * grow by a good, big amount
10821082 */
10831083 section -> allocated_size += 1024 ;
1084- section -> section_text = MemReallocSafe ( section -> section_text , section -> allocated_size * sizeof ( * section -> section_text ) );
1084+ section -> section_text = MemReallocSafe ( section -> section_text , section -> allocated_size );
10851085 }
10861086 section -> section_text [section -> section_size - 1 ] = ch ;
10871087 return ( 1 );
@@ -1159,7 +1159,7 @@ static void free_keyword_list( void )
11591159 Keyword_list = key -> next ;
11601160 MemFree ( key -> keyword );
11611161 MemFree ( key -> ctx_list );
1162- MemFree (key );
1162+ MemFree ( key );
11631163 }
11641164}
11651165
@@ -1319,24 +1319,38 @@ ctx_def *find_ctx( const char *ctx_name )
13191319 return ( NULL );
13201320}
13211321
1322+ static void free_keylist ( keylist_def * kl )
1323+ /*****************************************/
1324+ {
1325+ keylist_def * tmp ;
1326+
1327+ while ( (tmp = kl ) != NULL ) {
1328+ kl = tmp -> next ;
1329+ MemFree ( tmp );
1330+ }
1331+ }
1332+
1333+ static void free_section_list ( section_def * sl )
1334+ /**********************************************/
1335+ {
1336+ section_def * tmp ;
1337+
1338+ while ( (tmp = sl ) != NULL ) {
1339+ sl = tmp -> next ;
1340+ MemFree ( tmp -> section_text );
1341+ MemFree ( tmp );
1342+ }
1343+ }
1344+
13221345static void free_ctx_list ( void )
13231346/*******************************/
13241347{
13251348 ctx_def * ctx ;
1326- keylist_def * x1 ;
1327- section_def * x2 ;
13281349
13291350 while ( (ctx = Ctx_list ) != NULL ) {
13301351 Ctx_list = ctx -> next ;
1331- while ( (x1 = ctx -> keylist ) != NULL ) {
1332- ctx -> keylist = x1 -> next ;
1333- MemFree ( x1 );
1334- }
1335- while ( (x2 = ctx -> section_list ) != NULL ) {
1336- ctx -> section_list = x2 -> next ;
1337- MemFree ( x2 -> section_text );
1338- MemFree ( x2 );
1339- }
1352+ free_keylist ( ctx -> keylist );
1353+ free_section_list ( ctx -> section_list );
13401354 MemFree ( ctx -> title );
13411355 MemFree ( ctx -> ctx_name );
13421356 MemFree ( ctx );
@@ -1396,7 +1410,7 @@ static browse_def *add_browse( const char *browse_name, ctx_def *ctx )
13961410 }
13971411
13981412 browse_prev = NULL ;
1399- for ( browse = Browse_list ;; browse_prev = browse , browse = browse -> next ) {
1413+ for ( browse = Browse_list ; /* nothing */ ; browse_prev = browse , browse = browse -> next ) {
14001414 if ( browse == NULL ) {
14011415 browse = MemAllocSafe ( sizeof ( * browse ) );
14021416 browse -> browse_name = MemStrdupSafe ( browse_name );
@@ -1432,21 +1446,19 @@ static browse_def *add_browse( const char *browse_name, ctx_def *ctx )
14321446}
14331447
14341448
1435- static void add_ctx ( ctx_def * ctx , const char * title , char * keywords , const char * browse_name , int head_level )
1436- /************************************************************************************************************* /
1449+ static void add_ctx ( ctx_def * ctx , char * keywords , const char * browse_name , int head_level )
1450+ /******************************************************************************************/
14371451{
14381452 char * ptr ;
14391453 char * end ;
14401454 char ch ;
14411455 ctx_def * up_ctx ;
14421456 ctx_def * ctx_list ;
14431457
1444- if ( title != NULL && ctx -> title == NULL ) {
1445- ctx -> title = MemStrdupSafe ( title );
1446- }
14471458 if ( keywords != NULL && ctx -> keylist == NULL && * skip_blanks ( keywords ) != '\0' ) {
14481459 for ( ptr = keywords ;; ) {
1449- for ( end = ptr ; * end != ',' && * end != ';' && * end != '\0' ; end ++ );
1460+ for ( end = ptr ; * end != ',' && * end != ';' && * end != '\0' ; end ++ )
1461+ /* nothing */ ;
14501462 ch = * end ;
14511463 * end = '\0' ;
14521464 if ( !find_keyword ( ctx , ptr ) ) {
@@ -1566,7 +1578,10 @@ static ctx_def *define_ctx( void )
15661578 ctx = init_ctx ( ctx_name );
15671579 }
15681580 ctx -> title_fmt = title_fmt ;
1569- add_ctx ( ctx , title , keywords , browse_name , head_level );
1581+ if ( ctx -> title == NULL ) {
1582+ ctx -> title = MemStrdupSafe ( title );
1583+ }
1584+ add_ctx ( ctx , keywords , browse_name , head_level );
15701585
15711586 if (( old_ctx != NULL ) && ( old_ctx != ctx ) && ( old_ctx -> head_level == 0 )) {
15721587 ptr = old_ctx -> ctx_name ;
@@ -1597,7 +1612,7 @@ static bool read_ctx_topic( void )
15971612
15981613 if ( ctx == NULL ) {
15991614 ctx = init_ctx ( ctx_name );
1600- add_ctx ( ctx , NULL , NULL , NULL , -1 );
1615+ add_ctx ( ctx , NULL , NULL , -1 );
16011616 }
16021617 Curr_ctx = ctx ;
16031618
@@ -1720,11 +1735,11 @@ bool is_special_topic( ctx_def *ctx, bool dump_popup )
17201735 if ( ctx == NULL ) {
17211736 res = false;
17221737 } else {
1723- res = ( stricmp ( ctx -> ctx_name , "table_of_contents" ) == 0 ||
1724- stricmp ( ctx -> ctx_name , "index_of_topics" ) == 0 ||
1725- stricmp ( ctx -> ctx_name , "keyword_search" ) == 0 ||
1726- stricmp ( ctx -> ctx_name , "browse_lists" ) == 0 ||
1727- ( ctx -> title_fmt == TITLE_FMT_NOLINE && dump_popup ) );
1738+ res = ( stricmp ( ctx -> ctx_name , "table_of_contents" ) == 0
1739+ || stricmp ( ctx -> ctx_name , "index_of_topics" ) == 0
1740+ || stricmp ( ctx -> ctx_name , "keyword_search" ) == 0
1741+ || stricmp ( ctx -> ctx_name , "browse_lists" ) == 0
1742+ || ( ctx -> title_fmt == TITLE_FMT_NOLINE && dump_popup ) );
17281743 }
17291744 return ( res );
17301745}
0 commit comments