--- mt-daapd-cvs-20050305/src/main.c	2005-03-03 08:56:58.000000000 +0200
+++ mt-daapd-cvs-20050305-tri/src/main.c	2005-03-09 11:48:43.000000000 +0200
@@ -806,6 +806,7 @@
     WSCONFIG ws_config;
     WSHANDLE server;
     int parseonly=0;
+    int scanonly=0;
     int foreground=0;
     int reload=0;
     int start_time;
@@ -821,7 +822,7 @@
     config.use_mdns=1;
     err_debuglevel=1;
 
-    while((option=getopt(argc,argv,"D:d:c:mpfry")) != -1) {
+    while((option=getopt(argc,argv,"D:d:c:mpfrSy")) != -1) {
 	switch(option) {
 	case 'd':
 	    err_debuglevel=atoi(optarg);
@@ -832,6 +833,11 @@
 		exit(EXIT_FAILURE);
 	    }
 	    break;
+	case 'S':
+	    scanonly = 1;
+	    foreground = 1;
+	    break;
+
 	case 'f':
 	    foreground=1;
 	    break;
@@ -888,7 +894,7 @@
     }
 
 #ifndef WITHOUT_MDNS
-    if((config.use_mdns) && (!parseonly)) {
+    if((config.use_mdns) && (!parseonly) && (!scanonly)) {
 	DPRINTF(E_LOG,L_MAIN,"Starting rendezvous daemon\n");
 	if(rend_init(config.runas)) {
 	    DPRINTF(E_FATAL,L_MAIN|L_REND,"Error in rend_init: %s\n",strerror(errno));
@@ -956,8 +962,26 @@
 	DPRINTF(E_FATAL,L_MAIN|L_DB,"Error in db_init: %s\n",strerror(errno));
     }
 
+    if(scanonly) {
+	int rv;
+
+	rv = scan_init(config.mp3dir, 1);
+
+	if(rv) {
+	    DPRINTF(E_FATAL,L_MAIN|L_SCAN,"Error scanning MP3 files: %s\n",strerror(errno));
+	}
+	config_close();
+	db_deinit();
+#ifdef DEBUG_MEMORY
+	fprintf(stderr,"Leaked memory:\n");
+	err_leakcheck();
+#endif
+	err_setdest(NULL,LOGDEST_STDERR);
+	return rv == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+    }
+
     DPRINTF(E_LOG,L_MAIN|L_SCAN,"Starting mp3 scan\n");
-    if(scan_init(config.mp3dir)) {
+    if(scan_init(config.mp3dir, 0)) {
 	DPRINTF(E_FATAL,L_MAIN|L_SCAN,"Error scanning MP3 files: %s\n",strerror(errno));
     }
 
@@ -1012,7 +1036,7 @@
 	    start_time=time(NULL);
 
 	    DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Rescanning database\n");
-	    if(scan_init(config.mp3dir)) {
+	    if(scan_init(config.mp3dir, 0)) {
 		DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Error rescanning... exiting\n");
 		config.stop=1;
 	    }
--- mt-daapd-cvs-20050305/src/mp3-scanner.c	2005-02-27 02:41:55.000000000 +0200
+++ mt-daapd-cvs-20050305-tri/src/mp3-scanner.c	2005-03-09 12:52:12.816411792 +0200
@@ -114,6 +114,11 @@
 
 
 int scan_mode_foreground=1;
+int scan_mode_verbose=0;
+int scan_mode_verbose_counter;
+
+#define SCAN_MODE_VERBOSE_REPORT_INTERVAL 250
+#define SCAN_MODE_VERBOSE_SMALL_REPORT_INTERVAL 10
 
 char *scan_winamp_genre[] = {
     "Blues",              // 0
@@ -358,12 +363,18 @@
  * and update files on a file-by-file basis
  */
 
-int scan_init(char *path) {
+int scan_init(char *path, int force_foreground) {
     int err=0;
 
+    scan_mode_verbose=0;
     scan_mode_foreground=0;
-    if(db_is_empty()) {
+    scan_mode_verbose_counter=0;
+
+    if(db_is_empty() || force_foreground) {
 	scan_mode_foreground=1;
+	if (force_foreground) {
+	    scan_mode_verbose=1;
+	}
     }
 
     if(db_start_initial_update()) 
@@ -375,10 +386,21 @@
 
     err=scan_path(path);
 
+    if (scan_mode_verbose) {
+	if ((scan_mode_verbose_counter != 1) &&
+	    ((scan_mode_verbose_counter %
+	      SCAN_MODE_VERBOSE_REPORT_INTERVAL) != 0)) {
+	    fprintf(stderr, ".%d", scan_mode_verbose_counter);
+	}
+	fprintf(stderr, "\n");
+    }
+
     if(db_end_initial_update())
-	return -1;
+	err = -1;
 
+    scan_mode_verbose=0;
     scan_mode_foreground=0;
+    scan_mode_verbose_counter=0;
 
     return err;
 }
@@ -575,6 +597,18 @@
 
 	db_add(&mp3file);
 	pl_eval(&mp3file); /* FIXME: move to db_add? */
+
+	if (scan_mode_verbose) {
+	    scan_mode_verbose_counter++;
+	    if ((scan_mode_verbose_counter == 1) ||
+		(scan_mode_verbose_counter %
+		 SCAN_MODE_VERBOSE_REPORT_INTERVAL) == 0) {
+		fprintf(stderr, "%d", scan_mode_verbose_counter);
+	    } else if ((scan_mode_verbose_counter %
+			SCAN_MODE_VERBOSE_SMALL_REPORT_INTERVAL) == 0) {
+		fprintf(stderr, ".");
+	    }
+	}
     } else {
 	DPRINTF(E_WARN,L_SCAN,"Skipping %s - scan_gettags failed\n",pde->d_name);
     }
--- mt-daapd-cvs-20050305/src/mp3-scanner.h	2004-12-08 05:21:12.000000000 +0200
+++ mt-daapd-cvs-20050305-tri/src/mp3-scanner.h	2005-03-09 11:44:50.000000000 +0200
@@ -69,7 +69,7 @@
     char compilation;
 } MP3FILE;
 
-extern int scan_init(char *path);
+extern int scan_init(char *path, int force_foreground);
 extern void make_composite_tags(MP3FILE *song);
 
 /* this should be refactored out of here... */
