static int S9xGetSDD1Dir(char * packdir) { char dir[_MAX_DIR + 1]; char drive[_MAX_DRIVE + 1]; char name[_MAX_FNAME + 1]; char ext[_MAX_EXT + 1]; PathSplit(S9xGetFilename(FILE_ROM), drive, dir, name, ext); if (strncmp(Memory.ROMName, "Star Ocean", 10) == 0) { PathMake(packdir, drive, dir, "socnsdd1", 0); return 1; } else if(strncmp(Memory.ROMName, "STREET FIGHTER ALPHA2", 21) == 0) { PathMake(packdir, drive, dir, "sfa2sdd1", 0); return 1; } else { S9xMessage(S9X_WARNING, S9X_ROM_INFO, "WARNING: No default SDD1 pack for this ROM"); return 0; } }
Path* PathNew( const char* path ) { if( !path ) return NULL; Path* p = (Path*) calloc( 1, sizeof( Path ) ); if( p == NULL ) { ERROR("[PathNew] Cannot allocate memory for path\n"); return NULL; } int len = strlen( path ); if( len > 0 ) { //DEBUG( "[PathNew] Here it is: %d\n", len ); p->raw = calloc( len + 1, sizeof( char ) ); p->p_CopyRaw = calloc( len + 1, sizeof( char ) ); memcpy( p->raw, path, len ); memcpy( p->p_CopyRaw, path, len ); p->rawSize = len; PathSplit( p ); // If we have a file segment if( path[ p->rawSize - 1 ] != '/' && p->size >= 1 ) { p->file = p->parts[p->size - 1]; p->extension = strrchr( p->file, '.' ); if( p->extension ) { p->extension++; } } } else { //DEBUG( "[PathNew] It is nothing.\n" ); p->raw = NULL; p->rawSize = 0; p->file = NULL; p->extension = 0; } // Update the raw path (Double slashes, etc will be removed from the raw string); PathMake( p ); return p; }
void PathResolve( Path* p ) { if( p->resolved || !p->size ) { return; } // First segment is ../; We're not even going to bother... if( strcmp( p->parts[0], ".." ) == 0 ) { return; } //char** newPaths = calloc( 1, sizeof(char*) * p->size ); int copyFrom = 0; int copyTo = 0; unsigned int i; for( i = 0; i < p->size; i++ ) { if( strcmp( p->parts[ i ], ".." ) == 0 ) { copyFrom++; } else { copyTo++; copyFrom++; } p->parts[ copyTo ] = p->parts[ copyFrom ]; } p->size = copyTo; // Were we able to resolve the path in its entierty? if( copyTo ) { p->resolved = TRUE; } // Update the raw path PathMake( p ); }