From 406895a03cb1e3da20b4051d104083a9087b5a22 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 8 Nov 2003 15:30:04 +0000 Subject: [PATCH] Added mbfile sort command --- ChangeLog | 2 + TODO | 5 +- html/manual.css | 10 +- html/programs/mbfile.html | 29 +++-- mbfido/Makefile | 9 +- mbfido/mbfile.c | 17 ++- mbfido/mbfpack.h | 2 +- mbfido/mbfsort.c | 238 ++++++++++++++++++++++++++++++++++++++ mbfido/mbfsort.h | 8 ++ mbfido/mbfutil.c | 53 ++++----- 10 files changed, 317 insertions(+), 56 deletions(-) create mode 100644 mbfido/mbfsort.c create mode 100644 mbfido/mbfsort.h diff --git a/ChangeLog b/ChangeLog index 59c89a3f..1f58a42c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 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 diff --git a/TODO b/TODO index fdb48de6..37b18eb7 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/html/manual.css b/html/manual.css index 388e2477..61d0fbbf 100644 --- a/html/manual.css +++ b/html/manual.css @@ -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 } diff --git a/html/programs/mbfile.html b/html/programs/mbfile.html index ac1da1ca..9a98f18e 100644 --- a/html/programs/mbfile.html +++ b/html/programs/mbfile.html @@ -1,22 +1,21 @@ + - +MBSE BBS Programs - mbfile - File database maintenance program. + + -MBSE BBS Programs - mbfile - File database maintenance program.
-
Last update 26-Jan-2002
-

- -

mbfile - File database maintenance program.

-

+

Last update 08-Nov-2003
+

mbfile - File database maintenance program.

Synopsys.

mbfile [commands] <options> @@ -137,6 +136,12 @@ you delete files with mbsetup or with mbfile, they are still in your database an until you run mbfile pack.

+mbfile sort <area> +Sort the files in area on the long filenames. The sort is case insensitive. When +the sort is completed, the command mbfile index will automatic +run to rebuild all indexes. +

+ mbfile undelete <area> <file> 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.

-

Setup.

-

-In mbsetup menu 1.16 you need to set the public FTP base -and the maximum security level. -

- -Index Back to index  -Main Back to Main index +IndexBack to index  +MainBack to Main index

diff --git a/mbfido/Makefile b/mbfido/Makefile index 349d5185..5741393a 100644 --- a/mbfido/Makefile +++ b/mbfido/Makefile @@ -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 diff --git a/mbfido/mbfile.c b/mbfido/mbfile.c index 7d85abe0..29bdb521 100644 --- a/mbfido/mbfile.c +++ b/mbfido/mbfile.c @@ -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(); diff --git a/mbfido/mbfpack.h b/mbfido/mbfpack.h index f6dbe35f..4a0fec91 100644 --- a/mbfido/mbfpack.h +++ b/mbfido/mbfpack.h @@ -1,6 +1,6 @@ /* $Id$ */ -#ifndef _MBFPACK_H_ +#ifndef _MBFPACK_H #define _MBFPACK_H void PackFileBase(void); /* Pack / Compress File Base */ diff --git a/mbfido/mbfsort.c b/mbfido/mbfsort.c new file mode 100644 index 00000000..6b92a5d0 --- /dev/null +++ b/mbfido/mbfsort.c @@ -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); +} + + + diff --git a/mbfido/mbfsort.h b/mbfido/mbfsort.h new file mode 100644 index 00000000..bb74bf56 --- /dev/null +++ b/mbfido/mbfsort.h @@ -0,0 +1,8 @@ +/* $Id$ */ + +#ifndef _MBFSORT_H +#define _MBFSORT_H + +void SortFileBase(int); /* Sort File Base */ + +#endif diff --git a/mbfido/mbfutil.c b/mbfido/mbfutil.c index 3859d70e..795b7057 100644 --- a/mbfido/mbfutil.c +++ b/mbfido/mbfutil.c @@ -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] \n\n"); - colour(LIGHTBLUE, BLACK); - printf(" Commands are:\n\n"); - colour(CYAN, BLACK); - printf(" a adopt [desc] Adopt file to area\n"); - printf(" c check Check filebase\n"); - printf(" d delete Mark file in area for deletion\n"); - printf(" im import 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 Move file from to area\n"); - printf(" p pack Pack filebase\n"); -// printf(" r rearc [file] [arc] Rearc file(s) in area\n"); - printf(" t toberep Show toberep database\n"); - printf(" u undelete 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] \n\n"); + colour(LIGHTBLUE, BLACK); + printf(" Commands are:\n\n"); + colour(CYAN, BLACK); + printf(" a adopt [desc] Adopt file to area\n"); + printf(" c check Check filebase\n"); + printf(" d delete Mark file in area for deletion\n"); + printf(" im import 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 Move file from to area\n"); + printf(" p pack Pack filebase\n"); +// printf(" r rearc [file] [arc] Rearc file(s) in area\n"); + printf(" s sort Sort files in a file area\n"); + printf(" t toberep Show toberep database\n"); + printf(" u undelete 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); }