Added mbfile sort command

This commit is contained in:
Michiel Broek 2003-11-08 15:30:04 +00:00
parent 739f4e303d
commit 406895a03c
10 changed files with 317 additions and 56 deletions

View File

@ -24,6 +24,8 @@ v0.39.1 22-Oct-2003
help is displayed instead of trying area 0 that doesn't exist.
With the file move command if the file already exists in the
destination area, the move is refused.
Added mbfile sort <area> command. Files are case insensitive
sorted on the long filename. After sort the indexes are rebuild.
mbcico:
Added hydra rpos id -1 indicator for compression stop that

5
TODO
View File

@ -112,7 +112,8 @@ mbcico:
mode and we did send a FREQ, a poll must be created after the
session to pickup the result of the FREQ.
N: Support binkp Argus freqs (Radius too?).
L: Support binkp Argus freqs (Radius too?). Remark: Argus is obsolete
and Radius will support normal freqs in the near future.
U: Fix binkp file resume when mbcico silently dies.
@ -125,8 +126,6 @@ mbfile:
L: Possibility to skip file areas from checking and reindexing.
N: Add area sorting
mbmsg:
N: With the post command if a netmail area is used the netmail area
will cause trouble later, should be blocked to be used on netmail

View File

@ -5,15 +5,15 @@
*/
BODY { background-color: white; font-family: Arial, Helvetica; font-size=10pt; }
BODY { background-color: white; font: 12pt sans-serif,helvetica,arial; }
/*
* H1 is the page header, H3 the paragraph header, H5 is topright update date.
*/
H1 { color: red; align: center; font-family: Arial, Helvetica; font-size: 16pt; font-weight: bold }
H2 { color: orange; align: center; font-family: Arial, Helvetica; font-size: 16pt; font-weight: bold }
H3 { color: black; margin-left: 40; font-family: Arial, Helvetica; font-size: 14pt; font-weight: bold }
H5 { color: black; align: right; font-family: Arial, Helvetica; font-size: 8pt; }
H1 { color: red; align: center; font: 16pt sans-serif,helvetica,arial; font-weight: bold }
H2 { color: orange; align: center; font: 14pt sans-serif,helvetica,arial; font-weight: bold }
H3 { position: relative; left: 60px; color: black; font: 14pt sans-serif,helvetica,arial; font-weight: bold }
H5 { color: black; align: right; font: 10pt sans-serif,helvetica,arial; }
A:link { color: blue }
A:visited { color: darkblue }

View File

@ -1,22 +1,21 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<!-- $Id$ -->
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO 8859-1">
<TITLE>MBSE BBS Programs - mbfile - File database maintenance program.</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META NAME="Language" content='en'>
<META http-equiv="Content-Style-Type" content="text/css">
<META name="author" lang="en" content="Michiel Broek">
<META name="copyright" lang="en" content="Copyright Michiel Broek">
<META name="description" lang="en" content="MBSE BBS Manual">
<META name="keywords" lang="en" content="MBSE BBS, MBSE, BBS, manual, fido, fidonet, gateway, tosser, mail, tic, mailer">
<TITLE>MBSE BBS Programs - mbfile - File database maintenance program.</TITLE>
<LINK rel=stylesheet HREF="../manual.css">
</HEAD>
<BODY>
<BLOCKQUOTE>
<h5>Last update 26-Jan-2002</h5>
<P>
<H1>mbfile - File database maintenance program.</H1>
<P>
<div align="right"><h5>Last update 08-Nov-2003</h5></div>
<div align="center"><H1>mbfile - File database maintenance program.</H1></div>
<H3>Synopsys.</H3>
<code><strong>mbfile</strong> [commands] &lt;options&gt;</code>
@ -137,6 +136,12 @@ you delete files with mbsetup or with mbfile, they are still in your database an
until you run <strong>mbfile pack</strong>.
<P>
<code><strong>mbfile</strong> sort &lt;area&gt;</code>
Sort the files in area on the long filenames. The sort is case insensitive. When
the sort is completed, the command <strong>mbfile index</strong> will automatic
run to rebuild all indexes.
<P>
<code><strong>mbfile</strong> undelete &lt;area&gt; &lt;file&gt;</code>
Mark a file that is marked for deletion to be available again, ie. undo the deletion
mark.
@ -153,14 +158,8 @@ that the added file(s) will be announced. This can be usefull if you add lots of
files that you don't want to announce these as new files.
<P>
<H3>Setup.</H3>
<P>
In <strong>mbsetup</strong> menu 1.16 you need to set the public FTP base
and the maximum security level.
<P>
<A HREF="index.htm"><IMG SRC="../images/larrow.png" ALT="Index" Border="0" width="40" height="30"> Back to index</A>&nbsp;
<A HREF="../index.htm"><IMG SRC="../images/b_arrow.png" ALT="Main" Border="0" width="33" height="35"> Back to Main index</A>
<A HREF="index.htm"><IMG SRC="../images/larrow.png" ALT="Index" Border="0">Back to index</A>&nbsp;
<A HREF="../index.htm"><IMG SRC="../images/b_arrow.png" ALT="Main" Border="0">Back to Main index</A>
</BLOCKQUOTE>
</BODY>
</HTML>

View File

@ -13,7 +13,7 @@ SRCS = addbbs.c backalias.c flock.c hatch.c mbdiff.c mgrutil.c qualify.c \
mbmsg.c newspost.c postemail.c scan.c toberep.c atoul.c filemgr.c \
hash.c mbaff.c mbseq.c notify.c postnetmail.c scannews.c tosspkt.c \
mbfkill.c mbfutil.c mbfindex.c mbfcheck.c mbfpack.c mbflist.c mbfadopt.c \
mbfimport.c virscan.c mbftoberep.c mbfmove.c mbfdel.c bounce.c \
mbfimport.c mbfsort.c virscan.c mbftoberep.c mbfmove.c mbfdel.c bounce.c \
createm.c createf.c msgflags.c dirsession.c queue.c dirlock.c
HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h qualify.h \
postnetmail.h scannews.h tosspkt.h addpkt.h bwrite.h forward.h \
@ -24,7 +24,7 @@ HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h qualify.h \
grlist.h maketags.h mbmsg.h newspost.h postecho.h rollover.h tic.h \
atoul.h filemgr.h hash.h mbaff.h mbseq.h notify.h postemail.h scan.h toberep.h \
mbfkill.h mbfutil.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfadopt.h \
mbfimport.h virscan.h mbftoberep.h mbfmove.h mbfdel.h bounce.h \
mbfimport.h mbfsort.h virscan.h mbftoberep.h mbfmove.h mbfdel.h bounce.h \
createm.h createf.h msgflags.h dirsession.h queue.h dirlock.h
MBFIDO_OBJS = flock.o tosspkt.o mbfido.o hatch.o maketags.o virscan.o tracker.o \
makestat.o scannews.o lhash.o bounce.o unpack.o tic.o ptic.o \
@ -39,7 +39,7 @@ MBAFF_OBJS = announce.o fflist.o filefind.o grlist.o mbaff.o msgutil.o
MBINDEX_OBJS = mbindex.o
MBDIFF_OBJS = mbdiff.o
MBFILE_OBJS = mbfile.o mbfkill.o mbfutil.o mbfindex.o mbfcheck.o mbfpack.o mbflist.o mbfadopt.o \
mbfimport.o virscan.o mbftoberep.o mbfmove.o mbfdel.o
mbfimport.o virscan.o mbftoberep.o mbfmove.o mbfdel.o mbfsort.o
MBMSG_OBJS = post.o mbmsg.o
MBFIDO_LIBS = ../lib/libclcomm.a ../lib/libcommon.a ../lib/libmsgbase.a \
../lib/libdbase.a ../lib/libdiesel.a ../lib/libmbinet.a ../lib/libnodelist.a
@ -156,7 +156,7 @@ unpack.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/recor
aliasdb.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h aliasdb.h
fsort.o: ../config.h ../lib/libs.h ../lib/clcomm.h fsort.h
magic.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbtic.h tic.h utic.h magic.h
mbfile.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfkill.h mbfadopt.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfimport.h mbftoberep.h mbfmove.h mbfdel.h mbfutil.h mbfile.h
mbfile.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfkill.h mbfadopt.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfimport.h mbftoberep.h mbfmove.h mbfdel.h mbfutil.h mbfsort.h mbfile.h
mover.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h tic.h mover.h
post.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h post.h
rnews.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h ../lib/dbdupe.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/msg.h ../lib/msgtext.h ../lib/mberrors.h rfc2ftn.h mbfido.h ../paths.h rnews.h
@ -197,6 +197,7 @@ mbfpack.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/reco
mbflist.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfutil.h mbflist.h
mbfadopt.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h virscan.h mbfutil.h mbflist.h
mbfimport.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h virscan.h mbfutil.h mbfimport.h
mbfsort.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfutil.h mbfsort.h
virscan.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h virscan.h
mbftoberep.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbftoberep.h
mbfmove.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfutil.h mbfmove.h

View File

@ -48,6 +48,7 @@
#include "mbfmove.h"
#include "mbfdel.h"
#include "mbfutil.h"
#include "mbfsort.h"
#include "mbfile.h"
@ -65,13 +66,13 @@ int do_list = FALSE; /* List fileareas */
int do_tobe = FALSE; /* List toberep database */
int do_move = FALSE; /* Move a file */
int do_del = FALSE; /* Delete/undelete a file */
int do_sort = FALSE; /* Sort a filebase */
extern int e_pid; /* Pid of external process */
extern int show_log; /* Show logging */
time_t t_start; /* Start time */
time_t t_end; /* End time */
int main(int argc, char **argv)
{
int i, Area = 0, ToArea = 0, UnDel = FALSE;
@ -179,6 +180,14 @@ int main(int argc, char **argv)
}
}
}
} else if (!strncasecmp(argv[i], "s", 1)) {
if (argc > (i + 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
do_sort = TRUE;
}
} else if (!strncasecmp(argv[i], "p", 1)) {
do_pack = TRUE;
} else if (!strncasecmp(argv[i], "c", 1)) {
@ -196,7 +205,8 @@ int main(int argc, char **argv)
}
}
if (!(do_pack || do_check || do_kill || do_index || do_import || do_list || do_adopt || do_del || do_move || do_tobe))
if (!(do_pack || do_sort || do_check || do_kill || do_index || do_import ||
do_list || do_adopt || do_del || do_move || do_tobe))
Help();
ProgName();
@ -236,6 +246,9 @@ int main(int argc, char **argv)
if (do_kill)
Kill();
if (do_sort)
SortFileBase(Area);
if (do_check)
Check();

View File

@ -1,6 +1,6 @@
/* $Id$ */
#ifndef _MBFPACK_H_
#ifndef _MBFPACK_H
#define _MBFPACK_H
void PackFileBase(void); /* Pack / Compress File Base */

238
mbfido/mbfsort.c Normal file
View File

@ -0,0 +1,238 @@
/*****************************************************************************
*
* $Id$
* Purpose: File Database Maintenance - Sort filebase
*
*****************************************************************************
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "../lib/libs.h"
#include "../lib/structs.h"
#include "../lib/users.h"
#include "../lib/records.h"
#include "../lib/common.h"
#include "../lib/clcomm.h"
#include "../lib/dbcfg.h"
#include "../lib/mberrors.h"
#include "mbfutil.h"
#include "mbfsort.h"
extern int do_quiet; /* Suppress screen output */
extern int do_index; /* Reindex filebases */
typedef struct _fdbs {
struct _fdbs *next;
struct FILERecord filrec;
} fdbs;
void fill_fdbs(struct FILERecord, fdbs **);
void fill_fdbs(struct FILERecord filrec, fdbs **fap)
{
fdbs *tmp;
tmp = (fdbs *)malloc(sizeof(fdbs));
tmp->next = *fap;
tmp->filrec = filrec;
*fap = tmp;
}
void tidy_fdbs(fdbs **);
void tidy_fdbs(fdbs **fap)
{
fdbs *tmp, *old;
for (tmp = *fap; tmp; tmp = old) {
old = tmp->next;
free(tmp);
}
*fap = NULL;
}
int comp_fdbs(fdbs **, fdbs **);
void sort_fdbs(fdbs **);
void sort_fdbs(fdbs **fap)
{
fdbs *ta, **vector;
size_t n = 0, i;
if (*fap == NULL)
return;
for (ta = *fap; ta; ta = ta->next)
n++;
vector = (fdbs **)malloc(n * sizeof(fdbs *));
i = 0;
for (ta = *fap; ta; ta = ta->next)
vector[i++] = ta;
qsort(vector, n, sizeof(fdbs *), (int(*)(const void*, const void *))comp_fdbs);
(*fap) = vector[0];
i = 1;
for (ta = *fap; ta; ta = ta->next) {
if (i < n)
ta->next = vector[i++];
else
ta->next = NULL;
}
free(vector);
return;
}
int comp_fdbs(fdbs **fap1, fdbs **fap2)
{
return strcasecmp((*fap1)->filrec.LName, (*fap2)->filrec.LName);
}
/*
* Sort files database
*/
void SortFileBase(int Area)
{
FILE *fp, *pAreas, *pFile;
int iAreas, iTotal = 0;
char *sAreas, *fAreas, *fTmp;
fdbs *fdx = NULL, *tmp;
sAreas = calloc(PATH_MAX, sizeof(char));
fAreas = calloc(PATH_MAX, sizeof(char));
fTmp = calloc(PATH_MAX, sizeof(char));
IsDoing("Sort filebase");
if (!do_quiet) {
colour(3, 0);
}
sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((pAreas = fopen (sAreas, "r")) == NULL) {
WriteError("Can't open %s", sAreas);
die(MBERR_INIT_ERROR);
}
fread(&areahdr, sizeof(areahdr), 1, pAreas);
fseek(pAreas, 0, SEEK_END);
iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize;
if ((Area < 1) || (Area > iAreas)) {
if (!do_quiet) {
printf("Area must be between 1 and %d\n", iAreas);
}
} else {
fseek(pAreas, ((Area - 1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
fread(&area, areahdr.recsize, 1, pAreas);
if (area.Available) {
if (!diskfree(CFG.freespace))
die(MBERR_DISK_FULL);
if (!do_quiet) {
printf("Sorting area %d: %-44s", Area, area.Name);
fflush(stdout);
}
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), Area);
sprintf(fTmp, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), Area);
if ((pFile = fopen(fAreas, "r")) == NULL) {
Syslog('!', "Creating new %s", fAreas);
if ((pFile = fopen(fAreas, "a+")) == NULL) {
WriteError("$Can't create %s", fAreas);
die(MBERR_GENERAL);
}
}
if ((fp = fopen(fTmp, "a+")) == NULL) {
WriteError("$Can't create %s", fTmp);
die(MBERR_GENERAL);
}
/*
* Fill the sort array
*/
while (fread(&file, sizeof(file), 1, pFile) == 1) {
iTotal++;
fill_fdbs(file, &fdx);
Syslog('f', "Adding %s", file.LName);
}
sort_fdbs(&fdx);
/*
* Write sorted files to temp database
*/
for (tmp = fdx; tmp; tmp = tmp->next) {
Syslog('f', "Sorted %s", tmp->filrec.LName);
fwrite(&tmp->filrec, sizeof(file), 1, fp);
}
tidy_fdbs(&fdx);
fclose(fp);
fclose(pFile);
if ((rename(fTmp, fAreas)) == 0) {
unlink(fTmp);
chmod(fAreas, 00660);
}
Syslog('+', "Sorted file area %d: %s", Area, area.Name);
do_index = TRUE;
} else {
printf("You cannot sort area %d\n", Area);
}
}
fclose(pAreas);
if (!do_quiet) {
printf("\r \r");
fflush(stdout);
}
free(fTmp);
free(sAreas);
free(fAreas);
}

8
mbfido/mbfsort.h Normal file
View File

@ -0,0 +1,8 @@
/* $Id$ */
#ifndef _MBFSORT_H
#define _MBFSORT_H
void SortFileBase(int); /* Sort File Base */
#endif

View File

@ -109,33 +109,34 @@ void die(int onsig)
void Help(void)
{
do_quiet = FALSE;
ProgName();
do_quiet = FALSE;
ProgName();
colour(LIGHTCYAN, BLACK);
printf("\nUsage: mbfile [command] <options>\n\n");
colour(LIGHTBLUE, BLACK);
printf(" Commands are:\n\n");
colour(CYAN, BLACK);
printf(" a adopt <area> <file> [desc] Adopt file to area\n");
printf(" c check Check filebase\n");
printf(" d delete <area> <file> Mark file in area for deletion\n");
printf(" im import <area> Import files in current dir to area\n");
printf(" in index Create filerequest index\n");
printf(" k kill Kill/move old files\n");
printf(" l list [area] List file areas or one area\n");
printf(" m move <from> <to> <file> Move file from to area\n");
printf(" p pack Pack filebase\n");
// printf(" r rearc <area> [file] [arc] Rearc file(s) in area\n");
printf(" t toberep Show toberep database\n");
printf(" u undelete <area> <file> Mark file in area for undeletion\n");
colour(LIGHTBLUE, BLACK);
printf("\n Options are:\n\n");
colour(CYAN, BLACK);
printf(" -a -announce Suppress announce added files\n");
printf(" -q -quiet Quiet mode\n");
printf(" -v -virus Suppress virus scanning, use with care\n");
die(MBERR_COMMANDLINE);
colour(LIGHTCYAN, BLACK);
printf("Usage: mbfile [command] <options>\n\n");
colour(LIGHTBLUE, BLACK);
printf(" Commands are:\n\n");
colour(CYAN, BLACK);
printf(" a adopt <area> <file> [desc] Adopt file to area\n");
printf(" c check Check filebase\n");
printf(" d delete <area> <file> Mark file in area for deletion\n");
printf(" im import <area> Import files in current dir to area\n");
printf(" in index Create filerequest index\n");
printf(" k kill Kill/move old files\n");
printf(" l list [area] List file areas or one area\n");
printf(" m move <from> <to> <file> Move file from to area\n");
printf(" p pack Pack filebase\n");
// printf(" r rearc <area> [file] [arc] Rearc file(s) in area\n");
printf(" s sort <area> Sort files in a file area\n");
printf(" t toberep Show toberep database\n");
printf(" u undelete <area> <file> Mark file in area for undeletion\n");
colour(LIGHTBLUE, BLACK);
printf("\n Options are:\n\n");
colour(CYAN, BLACK);
printf(" -a -announce Suppress announce added files\n");
printf(" -q -quiet Quiet mode\n");
printf(" -v -virus Suppress virus scanning, use with care\n");
die(MBERR_COMMANDLINE);
}