static bool SemOS2WriteSubMenu( FullMenuOS2 *submenu, int *err_code, uint_32 codepage ) /******************************************************************/ { int count = 0; bool error; FullMenuItemOS2 *curritem; MenuHeaderOS2 head; if( ErrorHasOccured ) { return( false ); } head.Size = SemOS2CalcSubMenuSize( submenu, &count ); head.Codepage = codepage; head.Class = 4; head.NumItems = count; error = ResOS2WriteMenuHeader( &head, CurrResFile.handle ); if( error ) { ErrorHasOccured = true; return( error ); } if( submenu == NULL ) { return( error ); } error = false; for( curritem = submenu->head; curritem != NULL && !error; curritem = curritem->next ) { if( !ErrorHasOccured ) { error = SemOS2WriteMenuItem( curritem, err_code ); if( !error && (curritem->item.ItemStyle & OS2_MIS_SUBMENU) ) { error = SemOS2WriteSubMenu( curritem->submenu, err_code, codepage ); } } } if( error ) { ErrorHasOccured = true; } return( error ); }
static int SemOS2CalcSubMenuSize( FullMenuOS2 *submenu, int *count ) /******************************************************************/ { FullMenuItemOS2 *curritem; int size = 0, dummycount; size += sizeof( MenuHeaderOS2 ); if( submenu == NULL ) { return( size ); } for( curritem = submenu->head; curritem != NULL; curritem = curritem->next ) { *count += 1; size += 3 * sizeof(uint_16); if( !(curritem->item.ItemStyle & OS2_MIS_SEPARATOR) && curritem->item.ItemText != NULL ) size += strlen( curritem->item.ItemText ) + 1; if( curritem->item.ItemStyle & OS2_MIS_SUBMENU ) { size += SemOS2CalcSubMenuSize( curritem->submenu, &dummycount ); } } return( size ); }