function writestring( str, strsize )
{
         printf( "%s", str ) > "games.dat" ;
         for ( i = length(str) ; i < strsize ; i++ )
         {
            printf( "%c", 0 ) > "games.dat" ;
         }
}
function writedword( val )
{
     val1 = val / 16777216 ;
     val  = val%16777216 ;
     val2 = val / 65536 ;
     val  = val%65536 ;
     val3 = val / 256 ;
     val4 = val%256 ;

     printf( "%c%c%c%c", val4, val3, val2, val1 ) > "games.dat" ;
}
BEGIN {


     namesize = 0 ;
     commentsize = 0 ;
     filesize = 0 ;
     scrsize = 0 ;
     mussize = 0 ;
     cracksize = 0 ;
     sidsize = 0 ;
     progsize = 0 ;
     langsize = 0 ;
     comment2size = 0 ;
     
     while ( getline <"xboxgames.txt" )
     {
        if ( length($1) > namesize )
           namesize = length($1) ;
        if ( length($3) > commentsize )
           commentsize = length($3) ;
        if ( length($4) > filesize )
           filesize = length($4) ;
        if ( length($5) > scrsize )
           scrsize = length($5) ;
        if ( length($6) > mussize )
           mussize = length($6) ;
        if ( length($9) > cracksize )
           cracksize = length($9) ;
        if ( length($10) > sidsize )
           sidsize = length($10) ;
        if ( length($11) > progsize )
           progsize = length($11) ;
        if ( length($12) > langsize )
           langsize = length($12) ;
        if ( length($17) > comment2size )
           comment2size = length($17) ;
     }

     namesize++ ;
     commentsize++ ;
     filesize++ ;
     scrsize++ ;
     mussize++ ;
     cracksize++; 
     sidsize++ ;
     progsize++ ; 
     langsize++ ;
     comment2size++ ;

     close( "xboxgames.txt" ) ;


     writedword( 20 ) ;
     writedword( namesize ) ;
     writedword( 4 ) ;
     writedword( commentsize) ;
     writedword( filesize) ;
     writedword( scrsize) ;
     writedword( mussize) ;
     writedword( 4) ;
     writedword( 4) ;
     writedword( cracksize) ;
     writedword( sidsize) ;
     writedword( progsize) ;
     writedword( langsize) ;
     writedword( 4) ;
     writedword( 4) ;
     writedword( 4) ;
     writedword( 4) ;
     writedword( comment2size) ;
     writedword( 4 ) ;
     writedword( 4 ) ;
     writedword( 4 ) ;


     while ( getline <"xboxgames.txt" )
     {
         writestring( $1, namesize ) ;
         writedword( $2 ) ;
         writestring( $3, commentsize ) ;
         writestring( $4, filesize ) ;
         writestring( $5, scrsize ) ;
         writestring( $6, mussize ) ;
         writedword( $7 ) ;
         writedword( $8 ) ;
         writestring( $9, cracksize ) ;
         writestring( $10, sidsize ) ;
         writestring( $11, progsize ) ;
         writestring( $12, langsize ) ;
         writedword( $13 ) ;
         writedword( $14 ) ;
         writedword( $15 ) ;
         writedword( $16 ) ;
         writestring( $17, comment2size ) ;
         writedword( $18 ) ;
         writedword( $19 ) ;
         writedword( $20 ) ;
     }

     close( "games.dat" ) ;
}
{

}
