Changeset 128cbbabfd57761c125f35d64bae1f8ed83acfc4
- Timestamp:
- 10/11/06 21:56:10
(2 years ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1163192170 +0000
- git-parent:
[69263809ad62332f167463d06cacad2504c47fda]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1163192170 +0000
- Message:
Switch the directory to the UTF-8 wrappers
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r07b2e36 |
r128cbba |
|
| 137 | 137 | struct stat stat_info; |
|---|
| 138 | 138 | |
|---|
| 139 | | #ifdef HAVE_SYS_STAT_H |
|---|
| | 139 | #ifdef S_ISDIR |
|---|
| 140 | 140 | if (utf8_stat (p_access->psz_path, &stat_info) |
|---|
| 141 | 141 | || !S_ISDIR (stat_info.st_mode)) |
|---|
| … | … | |
| 179 | 179 | static int Read( access_t *p_access, uint8_t *p_buffer, int i_len) |
|---|
| 180 | 180 | { |
|---|
| 181 | | char *psz_name = NULL; |
|---|
| 182 | 181 | char *psz; |
|---|
| 183 | | char *ptr; |
|---|
| 184 | 182 | int i_mode, i_activity; |
|---|
| 185 | 183 | |
|---|
| 186 | | playlist_item_t *p_item, *p_root_category; |
|---|
| 187 | | playlist_t *p_playlist = pl_Yield( p_access ); |
|---|
| 188 | | |
|---|
| 189 | | psz_name = ToLocale( p_access->psz_path ); |
|---|
| 190 | | ptr = strdup( psz_name ); |
|---|
| 191 | | LocaleFree( psz_name ); |
|---|
| 192 | | if( ptr == NULL ) |
|---|
| 193 | | goto end; |
|---|
| 194 | | |
|---|
| 195 | | psz_name = ptr; |
|---|
| | 184 | char *psz_name = strdup (p_access->psz_path); |
|---|
| | 185 | if (psz_name == NULL) |
|---|
| | 186 | return VLC_ENOMEM; |
|---|
| 196 | 187 | |
|---|
| 197 | 188 | /* Remove the ending '/' char */ |
|---|
| 198 | | ptr += strlen( ptr ); |
|---|
| 199 | | if( ( ptr > psz_name ) ) |
|---|
| 200 | | { |
|---|
| 201 | | switch( *--ptr ) |
|---|
| | 189 | if (psz_name[0]) |
|---|
| | 190 | { |
|---|
| | 191 | char *ptr = psz_name + strlen (psz_name); |
|---|
| | 192 | switch (*--ptr) |
|---|
| 202 | 193 | { |
|---|
| 203 | 194 | case '/': |
|---|
| … | … | |
| 206 | 197 | } |
|---|
| 207 | 198 | } |
|---|
| | 199 | |
|---|
| | 200 | playlist_item_t *p_item, *p_root_category; |
|---|
| | 201 | playlist_t *p_playlist = pl_Yield( p_access ); |
|---|
| 208 | 202 | |
|---|
| 209 | 203 | /* Handle mode */ |
|---|
| … | … | |
| 241 | 235 | DIRECTORY_ACTIVITY ); |
|---|
| 242 | 236 | |
|---|
| 243 | | ReadDir( p_playlist, psz_name , i_mode, p_item, p_root_category ); |
|---|
| | 237 | ReadDir( p_playlist, psz_name, i_mode, p_item, p_root_category ); |
|---|
| 244 | 238 | |
|---|
| 245 | 239 | i_activity = var_GetInteger( p_playlist, "activity" ); |
|---|
| 246 | 240 | var_SetInteger( p_playlist, "activity", i_activity - |
|---|
| 247 | 241 | DIRECTORY_ACTIVITY ); |
|---|
| 248 | | end: |
|---|
| 249 | 242 | if( psz_name ) free( psz_name ); |
|---|
| 250 | 243 | vlc_object_release( p_playlist ); |
|---|
| … | … | |
| 332 | 325 | } |
|---|
| 333 | 326 | |
|---|
| 334 | | static int Filter( const struct dirent *foo ) |
|---|
| 335 | | { |
|---|
| 336 | | return VLC_TRUE; |
|---|
| | 327 | |
|---|
| | 328 | static int Sort (const char **a, const char **b) |
|---|
| | 329 | { |
|---|
| | 330 | return strcoll (*a, *b); |
|---|
| 337 | 331 | } |
|---|
| 338 | 332 | |
|---|
| … | … | |
| 344 | 338 | playlist_item_t *p_parent_category ) |
|---|
| 345 | 339 | { |
|---|
| 346 | | struct dirent **pp_dir_content = 0; |
|---|
| | 340 | char **pp_dir_content = NULL; |
|---|
| 347 | 341 | int i_dir_content, i, i_return = VLC_SUCCESS; |
|---|
| 348 | 342 | playlist_item_t *p_node; |
|---|
| 349 | 343 | |
|---|
| 350 | | char **ppsz_extensions = 0; |
|---|
| | 344 | char **ppsz_extensions = NULL; |
|---|
| 351 | 345 | int i_extensions = 0; |
|---|
| 352 | 346 | char *psz_ignore; |
|---|
| 353 | 347 | |
|---|
| 354 | 348 | /* Get the first directory entry */ |
|---|
| 355 | | i_dir_content = scandir( psz_name, &pp_dir_content, Filter, alphasort ); |
|---|
| | 349 | i_dir_content = utf8_scandir (psz_name, &pp_dir_content, NULL, Sort); |
|---|
| 356 | 350 | if( i_dir_content == -1 ) |
|---|
| 357 | 351 | { |
|---|
| … | … | |
| 378 | 372 | } |
|---|
| 379 | 373 | |
|---|
| 380 | | ppsz_extensions = (char **)malloc( sizeof( char * ) * i_extensions ); |
|---|
| | 374 | ppsz_extensions = (char **)calloc (i_extensions, sizeof (char *)); |
|---|
| 381 | 375 | |
|---|
| 382 | 376 | for( a = 0; a < i_extensions; a++ ) |
|---|
| … | … | |
| 394 | 388 | } |
|---|
| 395 | 389 | } |
|---|
| | 390 | if( psz_ignore ) free( psz_ignore ); |
|---|
| 396 | 391 | |
|---|
| 397 | 392 | /* While we still have entries in the directory */ |
|---|
| 398 | 393 | for( i = 0; i < i_dir_content; i++ ) |
|---|
| 399 | 394 | { |
|---|
| 400 | | struct dirent *p_dir_content = pp_dir_content[i]; |
|---|
| | 395 | const char *entry = pp_dir_content[i]; |
|---|
| 401 | 396 | int i_size_entry = strlen( psz_name ) + |
|---|
| 402 | | strlen( p_dir_content->d_name ) + 2; |
|---|
| 403 | | char *psz_uri = (char *)malloc( sizeof(char) * i_size_entry ); |
|---|
| 404 | | |
|---|
| 405 | | sprintf( psz_uri, "%s/%s", psz_name, p_dir_content->d_name ); |
|---|
| | 397 | strlen( entry ) + 2; |
|---|
| | 398 | char psz_uri[i_size_entry]; |
|---|
| | 399 | |
|---|
| | 400 | sprintf( psz_uri, "%s/%s", psz_name, entry); |
|---|
| 406 | 401 | |
|---|
| 407 | 402 | /* if it starts with '.' then forget it */ |
|---|
| 408 | | if( p_dir_content->d_name[0] != '.' ) |
|---|
| | 403 | if (entry[0] != '.') |
|---|
| 409 | 404 | { |
|---|
| 410 | 405 | #if defined( S_ISDIR ) |
|---|
| 411 | 406 | struct stat stat_data; |
|---|
| 412 | 407 | |
|---|
| 413 | | if( !stat( psz_uri, &stat_data ) |
|---|
| | 408 | if (!utf8_stat (psz_uri, &stat_data) |
|---|
| 414 | 409 | && S_ISDIR(stat_data.st_mode) && i_mode != MODE_COLLAPSE ) |
|---|
| 415 | | #elif defined( DT_DIR ) |
|---|
| 416 | | if( ( p_dir_content->d_type & DT_DIR ) && i_mode != MODE_COLLAPSE ) |
|---|
| 417 | 410 | #else |
|---|
| 418 | 411 | if( 0 ) |
|---|
| … | … | |
| 425 | 418 | * in a non-portable way. |
|---|
| 426 | 419 | */ |
|---|
| 427 | | if( lstat( psz_uri, &stat_data ) |
|---|
| | 420 | if (utf8_lstat (psz_uri, &stat_data) |
|---|
| 428 | 421 | || S_ISLNK(stat_data.st_mode) ) |
|---|
| 429 | 422 | { |
|---|
| 430 | 423 | msg_Dbg( p_playlist, "skipping directory symlink %s", |
|---|
| 431 | 424 | psz_uri ); |
|---|
| 432 | | free( psz_uri ); |
|---|
| 433 | 425 | continue; |
|---|
| 434 | 426 | } |
|---|
| … | … | |
| 437 | 429 | { |
|---|
| 438 | 430 | msg_Dbg( p_playlist, "skipping subdirectory %s", psz_uri ); |
|---|
| 439 | | free( psz_uri ); |
|---|
| 440 | 431 | continue; |
|---|
| 441 | 432 | } |
|---|
| 442 | 433 | else if( i_mode == MODE_EXPAND ) |
|---|
| 443 | 434 | { |
|---|
| 444 | | char *psz_newname, *psz_tmp; |
|---|
| 445 | | msg_Dbg(p_playlist, "reading subdirectory %s", psz_uri ); |
|---|
| 446 | | |
|---|
| 447 | | psz_tmp = FromLocale( p_dir_content->d_name ); |
|---|
| 448 | | psz_newname = vlc_fix_readdir_charset( |
|---|
| 449 | | p_playlist, psz_tmp ); |
|---|
| 450 | | LocaleFree( psz_tmp ); |
|---|
| 451 | | |
|---|
| 452 | | if( p_parent_category ) |
|---|
| 453 | | { |
|---|
| 454 | | p_node = playlist_NodeCreate( p_playlist, psz_newname, |
|---|
| 455 | | p_parent_category ); |
|---|
| 456 | | } |
|---|
| 457 | | else |
|---|
| 458 | | { |
|---|
| 459 | | p_node = playlist_NodeCreate( p_playlist, psz_newname, |
|---|
| 460 | | p_parent_category ); |
|---|
| 461 | | } |
|---|
| 462 | | |
|---|
| 463 | | /* an strdup() just because of Mac OS X */ |
|---|
| 464 | | free( psz_newname ); |
|---|
| | 435 | msg_Dbg(p_playlist, "creading subdirectory %s", psz_uri ); |
|---|
| | 436 | |
|---|
| | 437 | p_node = playlist_NodeCreate (p_playlist, entry, |
|---|
| | 438 | p_parent_category); |
|---|
| 465 | 439 | |
|---|
| 466 | 440 | /* If we had the parent in category, the it is now node. |
|---|
| … | … | |
| 478 | 452 | { |
|---|
| 479 | 453 | input_item_t *p_input; |
|---|
| 480 | | char *psz_tmp1, *psz_tmp2, *psz_loc; |
|---|
| 481 | 454 | |
|---|
| 482 | 455 | if( i_extensions > 0 ) |
|---|
| 483 | 456 | { |
|---|
| 484 | | char *psz_dot = strrchr( p_dir_content->d_name, '.' ); |
|---|
| | 457 | const char *psz_dot = strrchr (entry, '.' ); |
|---|
| 485 | 458 | if( psz_dot++ && *psz_dot ) |
|---|
| 486 | 459 | { |
|---|
| … | … | |
| 494 | 467 | { |
|---|
| 495 | 468 | msg_Dbg( p_playlist, "ignoring file %s", psz_uri ); |
|---|
| 496 | | free( psz_uri ); |
|---|
| 497 | 469 | continue; |
|---|
| 498 | 470 | } |
|---|
| … | … | |
| 500 | 472 | } |
|---|
| 501 | 473 | |
|---|
| 502 | | psz_loc = FromLocale( psz_uri ); |
|---|
| 503 | | psz_tmp1 = vlc_fix_readdir_charset( VLC_OBJECT(p_playlist), |
|---|
| 504 | | psz_loc ); |
|---|
| 505 | | LocaleFree( psz_loc ); |
|---|
| 506 | | |
|---|
| 507 | | psz_loc = FromLocale( p_dir_content->d_name ); |
|---|
| 508 | | psz_tmp2 = vlc_fix_readdir_charset( VLC_OBJECT(p_playlist), |
|---|
| 509 | | psz_loc ); |
|---|
| 510 | | LocaleFree( psz_loc ); |
|---|
| 511 | | |
|---|
| 512 | 474 | p_input = input_ItemNewWithType( VLC_OBJECT(p_playlist), |
|---|
| 513 | | psz_tmp1, psz_tmp2, 0, NULL, |
|---|
| | 475 | psz_uri, entry, 0, NULL, |
|---|
| 514 | 476 | -1, ITEM_TYPE_VFILE ); |
|---|
| 515 | | |
|---|
| 516 | | playlist_AddWhereverNeeded( p_playlist, p_input, p_parent, |
|---|
| 517 | | p_parent_category, VLC_FALSE, |
|---|
| 518 | | PLAYLIST_APPEND|PLAYLIST_PREPARSE); |
|---|
| | 477 | if (p_input != NULL) |
|---|
| | 478 | playlist_AddWhereverNeeded (p_playlist, p_input, p_parent, |
|---|
| | 479 | p_parent_category, VLC_FALSE, |
|---|
| | 480 | PLAYLIST_APPEND|PLAYLIST_PREPARSE); |
|---|
| 519 | 481 | } |
|---|
| 520 | 482 | } |
|---|
| 521 | | free( psz_uri ); |
|---|
| 522 | 483 | } |
|---|
| 523 | 484 | |
|---|
| … | … | |
| 526 | 487 | if( ppsz_extensions ) free( ppsz_extensions ); |
|---|
| 527 | 488 | |
|---|
| 528 | | if( psz_ignore ) free( psz_ignore ); |
|---|
| 529 | | |
|---|
| 530 | 489 | for( i = 0; i < i_dir_content; i++ ) |
|---|
| 531 | 490 | if( pp_dir_content[i] ) free( pp_dir_content[i] ); |
|---|