2003-11-08 15:30:04 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
* Purpose: File Database Maintenance - Sort filebase
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2004-02-21 17:22:00 +00:00
|
|
|
* Copyright (C) 1997-2004
|
2003-11-08 15:30:04 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2003-11-08 15:30:04 +00:00
|
|
|
#include "../lib/users.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbsedb.h"
|
2003-11-08 15:30:04 +00:00
|
|
|
#include "mbfutil.h"
|
|
|
|
#include "mbfsort.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern int do_quiet; /* Suppress screen output */
|
|
|
|
extern int do_index; /* Reindex filebases */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort files database
|
|
|
|
*/
|
|
|
|
void SortFileBase(int Area)
|
|
|
|
{
|
2004-05-06 17:38:19 +00:00
|
|
|
FILE *pAreas;
|
|
|
|
int iAreas;
|
|
|
|
char *sAreas;
|
|
|
|
struct _fdbarea *fdb_area = NULL;
|
2004-05-19 21:18:14 +00:00
|
|
|
|
2004-05-06 17:38:19 +00:00
|
|
|
sAreas = calloc(PATH_MAX, sizeof(char));
|
2003-11-08 15:30:04 +00:00
|
|
|
|
|
|
|
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) {
|
|
|
|
|
2004-03-21 12:55:45 +00:00
|
|
|
if (enoughspace(CFG.freespace) == 0)
|
2003-11-08 15:30:04 +00:00
|
|
|
die(MBERR_DISK_FULL);
|
|
|
|
|
|
|
|
if (!do_quiet) {
|
|
|
|
printf("Sorting area %d: %-44s", Area, area.Name);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2004-05-06 17:38:19 +00:00
|
|
|
if ((fdb_area = mbsedb_OpenFDB(Area, 30))) {
|
|
|
|
mbsedb_SortFDB(fdb_area);
|
|
|
|
mbsedb_CloseFDB(fdb_area);
|
|
|
|
}
|
2003-11-08 15:30:04 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-05-06 17:38:19 +00:00
|
|
|
free(sAreas);
|
2003-11-08 15:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|