static void update_regular_file(struct directory *directory, const char *name, const struct stat *st) { const char *suffix = uri_get_suffix(name); const struct decoder_plugin* plugin; #ifdef ENABLE_ARCHIVE const struct archive_plugin *archive; #endif if (suffix == NULL) return; if ((plugin = decoder_plugin_from_suffix(suffix, false)) != NULL) { struct song* song = songvec_find(&directory->songs, name); if (!(song != NULL && st->st_mtime == song->mtime && !walk_discard) && plugin->container_scan != NULL) { if (update_container_file(directory, name, st, plugin)) { if (song != NULL) delete_song(directory, song); return; } } if (song == NULL) { song = song_file_load(name, directory); if (song == NULL) { g_debug("ignoring unrecognized file %s/%s", directory_get_path(directory), name); return; } songvec_add(&directory->songs, song); modified = true; g_message("added %s/%s", directory_get_path(directory), name); } else if (st->st_mtime != song->mtime || walk_discard) { g_message("updating %s/%s", directory_get_path(directory), name); if (!song_file_update(song)) { g_debug("deleting unrecognized file %s/%s", directory_get_path(directory), name); delete_song(directory, song); } modified = true; } #ifdef ENABLE_ARCHIVE } else if ((archive = archive_plugin_from_suffix(suffix))) { update_archive_file(directory, name, st, archive); #endif } }
int main( int argc, char **argv ) { int c, error = 0; libspectrum_tape *tzx; progname = argv[0]; struct option long_options[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, { 0, 0, 0, 0 } }; while( ( c = getopt_long( argc, argv, "a:s:i:bhV", long_options, NULL ) ) != -1 ) { switch( c ) { case 'a': archive_file = optarg ; break; case 'b': beautify = 1; break; case 's': scr_file = optarg ; break; case 'i': inlay_file = optarg ; break; case 'h': show_help(); return 0; case 'V': show_version(); return 0; case '?': /* getopt prints an error message to stderr */ error = 1; break; default: error = 1; fprintf( stderr, "%s: unknown option `%c'\n", progname, (char) c ); break; } } argc -= optind; argv += optind; if( error ) { fprintf( stderr, "Try `%s --help' for more information.\n", progname ); return error; } if( argc < 2 ) { fprintf( stderr, "%s: usage: %s [-s <scr file>] [-a <archive info tzx>] " "[-b] [-i <inlay image>] <infile> <outfile>\n", progname, progname ); fprintf( stderr, "Try `%s --help' for more information.\n", progname ); return 1; } error = init_libspectrum(); if( error ) return error; if( read_tape( argv[0], &tzx ) ) return 1; if( archive_file && update_archive_file( archive_file, tzx ) ) { libspectrum_tape_free( tzx ); return 1; } if( scr_file && append_scr_file( scr_file, tzx ) ) { libspectrum_tape_free( tzx ); return 1; } if( inlay_file && append_inlay_file( inlay_file, tzx ) ) { libspectrum_tape_free( tzx ); return 1; } if( beautify && beautify_tzx_file( tzx ) ) { libspectrum_tape_free( tzx ); return 1; } if( write_tape( argv[1], tzx ) ) { libspectrum_tape_free( tzx ); return 1; } libspectrum_tape_free( tzx ); return 0; }