+ }
+
+ /* load skin file */
+ snprintf( skinfilename, sizeof( skinfilename ), "%s_%d.skin", name, skin );
+ skinfilename[sizeof( skinfilename ) - 1] = 0;
+ skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 );
+ if ( skinfilesize < 0 && skin != 0 ) {
+ /* fallback to skin 0 if invalid */
+ snprintf( skinfilename, sizeof( skinfilename ), "%s_0.skin", name );
+ skinfilename[sizeof( skinfilename ) - 1] = 0;
+ skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 );
+ if ( skinfilesize >= 0 ) {
+ Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );
+ }
+ }
+ sf = NULL;
+ if ( skinfilesize >= 0 ) {
+ Sys_Printf( "Using skin %d of %s\n", skin, name );
+ int pos;
+ for ( skinfileptr = skinfilecontent; *skinfileptr; skinfileptr = skinfilenextptr )
+ {
+ // for fscanf
+ char format[64];
+
+ skinfilenextptr = strchr( skinfileptr, '\r' );
+ if ( skinfilenextptr ) {
+ *skinfilenextptr++ = 0;
+ }
+ else
+ {
+ skinfilenextptr = strchr( skinfileptr, '\n' );
+ if ( skinfilenextptr ) {
+ *skinfilenextptr++ = 0;
+ }
+ else{
+ skinfilenextptr = skinfileptr + strlen( skinfileptr );
+ }
+ }
+
+ /* create new item */
+ sf2 = sf;
+ sf = safe_malloc( sizeof( *sf ) );
+ sf->next = sf2;
+
+ sprintf( format, "replace %%%ds %%%ds", (int)sizeof( sf->name ) - 1, (int)sizeof( sf->to ) - 1 );
+ if ( sscanf( skinfileptr, format, sf->name, sf->to ) == 2 ) {
+ continue;
+ }
+ sprintf( format, " %%%d[^, ] ,%%%ds", (int)sizeof( sf->name ) - 1, (int)sizeof( sf->to ) - 1 );
+ if ( ( pos = sscanf( skinfileptr, format, sf->name, sf->to ) ) == 2 ) {
+ continue;
+ }
+
+ /* invalid input line -> discard sf struct */
+ Sys_Printf( "Discarding skin directive in %s: %s\n", skinfilename, skinfileptr );
+ free( sf );
+ sf = sf2;
+ }
+ free( skinfilecontent );
+ }
+