From fbd1f2b6d9e61072d2697746a976583bf6578762 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Fri, 2 Nov 2001 05:31:24 +0000
Subject: [PATCH] Ported to Win32 (MSVC++ 6.0). Better detection of corrupted
 SBL database entries.

---
 xtrn/sbl/sblpack.c | 84 +++++++++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 35 deletions(-)

diff --git a/xtrn/sbl/sblpack.c b/xtrn/sbl/sblpack.c
index 9e590b2c03..4e31ce01b5 100644
--- a/xtrn/sbl/sblpack.c
+++ b/xtrn/sbl/sblpack.c
@@ -7,49 +7,63 @@
 /***************************************/
 
 #include <stdio.h>
+#include <stdlib.h>		/* exit() */
 #include <share.h>
 #include <time.h>
 #include <io.h>
 #include <fcntl.h>
 #include <sys/stat.h>
-#include "gen_defs.h"
+#include "xsdkwrap.h"	/* PLATFORM_DESC */
+#include "xsdkdefs.h"
 #include "sbldefs.h"
 
 int main(void)
 {
-	int file;
-	FILE *in,*out;
-	bbs_t bbs;
-
-printf("\nSBLPACK v1.00  Developed 1995-1997 Rob Swindell\n\n");
-
-if((file=open("SBL.DAB",O_RDWR|O_BINARY|O_DENYNONE|O_CREAT
-	,S_IWRITE|S_IREAD))==-1) {
-	printf("\n\7Error opening/creating SBL.DAB\n");
-	exit(1); }
-if((in=fdopen(file,"w+b"))==NULL) {
-	printf("\n\7Error converting SBL.DAB file handle to stream\n");
-	exit(1); }
-setvbuf(in,0L,_IOFBF,2048);
-if((out=fopen("SBL.TMP","wb"))==NULL) {
-	printf("\n\7Error opening SBL.TMP file\n");
-	exit(1); }
-
-while(!feof(in)) {
-	if(!fread(&bbs,sizeof(bbs_t),1,in))
-		break;
-	putchar('.');
-	if(!bbs.name[0])
-		continue;
-	fwrite(&bbs,sizeof(bbs_t),1,out); }
-fcloseall();
-putchar('\n');
-if(remove("SBL.DAB")) {
-	printf("\n\7Data file in use, can't remove.\n");
-	remove("SBL.TMP");
-	exit(1); }
-rename("SBL.TMP","SBL.DAB");
-printf("\nDone.\n");
-return(0);
+	int		file;
+	FILE *	in;
+	FILE *	out;
+	bbs_t	bbs;
+	ulong	records=0;
+	ulong	deleted=0;
+
+	printf("\nSBLPACK v1.10/%s  Developed 1995-2001 Rob Swindell\n\n"
+		,PLATFORM_DESC);
+
+	if((file=sopen("sbl.dab",O_RDWR|O_BINARY,SH_DENYNO))==-1) {
+		printf("\n\7Error opening/creating sbl.dab\n");
+		exit(1); }
+	if((in=fdopen(file,"w+b"))==NULL) {
+		printf("\n\7Error converting sbl.dab file handle to stream\n");
+		exit(1); }
+	setvbuf(in,0L,_IOFBF,2048);
+	if((out=fopen("sbl.tmp","wb"))==NULL) {
+		printf("\n\7Error opening sbl.tmp file\n");
+		exit(1); }
+
+	while(!feof(in)) {
+		if(!fread(&bbs,sizeof(bbs_t),1,in))
+			break;
+		records++;
+		putchar('.');
+		if(bbs.name[0]==0 
+			|| bbs.user[0]==0
+			|| bbs.total_numbers<1) {
+			deleted++;
+			continue;
+		}
+		fwrite(&bbs,sizeof(bbs_t),1,out); 
+	}
+	fcloseall();
+	putchar('\n');
+	if(remove("sbl.dab")) {
+		printf("\n\7Data file in use, can't remove.\n");
+		remove("sbl.tmp");
+		exit(1); 
+	}
+	rename("sbl.tmp","sbl.dab");
+	printf("\nDone.\n");
+	printf("\n%lu records in original file, %lu deleted (packed), new total = %lu.\n"
+		,records,deleted,records-deleted);
+	return(0);
 }
 
-- 
GitLab