This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbfido/mbflist.c

234 lines
6.5 KiB
C
Raw Normal View History

2001-11-18 23:19:08 +00:00
/*****************************************************************************
*
* $Id$
* Purpose: File Database Maintenance - List areas and totals
*
*****************************************************************************
2004-02-21 17:22:00 +00:00
* Copyright (C) 1997-2004
2001-11-18 23:19:08 +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
2003-08-15 20:05:34 +00:00
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
2001-11-18 23:19:08 +00:00
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2004-02-21 17:22:00 +00:00
#include "../lib/mbselib.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2004-02-21 17:22:00 +00:00
#include "../lib/mbsedb.h"
2001-11-18 23:19:08 +00:00
#include "mbfutil.h"
#include "mbflist.h"
extern int do_quiet; /* Suppress screen output */
2001-11-18 23:19:08 +00:00
2001-11-25 14:13:55 +00:00
void ListFileAreas(int Area)
2001-11-18 23:19:08 +00:00
{
2001-12-02 17:10:49 +00:00
FILE *pAreas, *pFile, *pTic;
2001-11-18 23:19:08 +00:00
int i, iAreas, fcount, tcount = 0;
int iTotal = 0;
long fsize, tsize = 0;
2001-12-02 17:10:49 +00:00
char *sAreas, *fAreas, *sTic, flags[6], *ticarea;
2001-11-18 23:19:08 +00:00
2001-11-25 14:13:55 +00:00
/*
* If nothing to display allowed, return at once.
*/
if (do_quiet)
return;
colour(LIGHTRED, BLACK);
2001-12-02 17:10:49 +00:00
sAreas = calloc(PATH_MAX, sizeof(char));
fAreas = calloc(PATH_MAX, sizeof(char));
sTic = calloc(PATH_MAX, sizeof(char));
ticarea = calloc(21, sizeof(char));
2001-11-18 23:19:08 +00:00
sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((pAreas = fopen (sAreas, "r")) == NULL) {
WriteError("Can't open %s", sAreas);
2001-11-25 14:13:55 +00:00
printf("Can't open %s\n", sAreas);
2002-10-20 20:58:55 +00:00
die(MBERR_INIT_ERROR);
2001-11-18 23:19:08 +00:00
}
fread(&areahdr, sizeof(areahdr), 1, pAreas);
fseek(pAreas, 0, SEEK_END);
iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize;
2001-12-02 17:10:49 +00:00
2001-11-25 14:13:55 +00:00
if (Area) {
IsDoing("List area %d", Area);
2001-12-02 17:10:49 +00:00
sprintf(sTic, "%s/etc/tic.data", getenv("MBSE_ROOT"));
if ((pTic = fopen(sTic, "r")) == NULL) {
WriteError("Can't open %s", sTic);
printf("Can't open %s\n", sTic);
2002-10-20 20:58:55 +00:00
die(MBERR_GENERAL);
2001-12-02 17:10:49 +00:00
}
fread(&tichdr, sizeof(tichdr), 1, pTic);
2001-11-25 14:13:55 +00:00
if (fseek(pAreas, ((Area - 1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET)) {
WriteError("$Can't seek area %d", Area);
printf("Can't seek area %d\n", Area);
return;
}
if (fread(&area, areahdr.recsize, 1, pAreas) != 1) {
WriteError("$Can't read record for area %d", Area);
printf("Can't read record for area %d\n", Area);
return;
}
if (area.Available) {
/*
* Open the file database, create new one if it doesn't exist.
*/
sprintf(fAreas, "%s/fdb/fdb%d.data", 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);
2002-10-20 20:58:55 +00:00
die(MBERR_GENERAL);
2001-11-25 14:13:55 +00:00
}
}
fcount = 0;
fsize = 0L;
colour(CYAN, BLACK);
printf("File listing of area %d, %s\n\n", Area, area.Name);
2001-12-02 17:10:49 +00:00
printf("Short name Kb. File date Down Flags TIC Area Long name\n");
printf("------------ ----- ---------- ---- ----- -------------------- ");
for (i = 63; i < COLS; i++)
printf("-");
printf("\n");
2001-11-25 14:13:55 +00:00
colour(LIGHTGRAY, BLACK);
while (fread(&file, sizeof(file), 1, pFile) == 1) {
sprintf(flags, "-----");
if (file.Free)
flags[0] = 'F';
if (file.Deleted)
flags[1] = 'D';
if (file.Missing)
flags[2] = 'M';
if (file.NoKill)
flags[3] = 'N';
if (file.Announced)
flags[4] = 'A';
2001-12-02 17:10:49 +00:00
if (file.TicAreaCRC) {
/*
* Fill the default answer
*/
sprintf(ticarea, "Not found");
fseek(pTic, tichdr.hdrsize, SEEK_SET);
while (fread(&tic, tichdr.recsize, 1, pTic)) {
if (StringCRC32(tic.Name) == file.TicAreaCRC) {
sprintf(ticarea, "%s", tic.Name);
break;
}
fseek(pTic, tichdr.syssize, SEEK_CUR);
}
} else {
sprintf(ticarea, "N/A");
}
file.LName[COLS - 63] = '\0';
printf("%-12s %5ld %s %4ld %s %-20s %s\n",
file.Name, (long)(file.Size / 1024), StrDateDMY(file.FileDate),
2001-12-02 17:10:49 +00:00
(long)(file.TimesDL + file.TimesFTP + file.TimesReq), flags, ticarea, file.LName);
2001-11-25 14:13:55 +00:00
fcount++;
fsize = fsize + file.Size;
}
fsize = fsize / 1024;
colour(CYAN, BLACK);
2001-12-02 17:10:49 +00:00
printf("--------------------------------------------------------------");
for (i = 63; i < COLS; i++)
printf("-");
printf("\n");
2001-11-25 14:13:55 +00:00
printf("%d file%s, %ld Kbytes\n", fcount, (fcount == 1) ? "":"s", fsize);
2003-12-08 18:01:25 +00:00
fclose(pFile);
2001-11-25 14:13:55 +00:00
} else {
WriteError("Area %d is not available", Area);
printf("Area %d is not available\n", Area);
return;
}
2003-12-08 18:01:25 +00:00
fclose(pAreas);
2001-12-02 17:10:49 +00:00
fclose(pTic);
free(ticarea);
2001-11-25 14:13:55 +00:00
free(sAreas);
free(fAreas);
2001-12-02 17:10:49 +00:00
free(sTic);
2001-11-25 14:13:55 +00:00
return;
}
IsDoing("List fileareas");
colour(CYAN, BLACK);
printf(" Area Files MByte File Group Area name\n");
printf("----- ----- ----- ------------ --------------------------------------------\n");
colour(LIGHTGRAY, BLACK);
2001-11-18 23:19:08 +00:00
for (i = 1; i <= iAreas; i++) {
fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
fread(&area, areahdr.recsize, 1, pAreas);
if (area.Available) {
/*
2001-11-25 14:13:55 +00:00
* Open the file database, create new one if it doesn't exist.
2001-11-18 23:19:08 +00:00
*/
2001-11-25 14:13:55 +00:00
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
2001-11-18 23:19:08 +00:00
if ((pFile = fopen(fAreas, "r+")) == NULL) {
Syslog('!', "Creating new %s", fAreas);
if ((pFile = fopen(fAreas, "a+")) == NULL) {
WriteError("$Can't create %s", fAreas);
2002-10-20 20:58:55 +00:00
die(MBERR_GENERAL);
2001-11-18 23:19:08 +00:00
}
}
fcount = 0;
fsize = 0L;
while (fread(&file, sizeof(file), 1, pFile) == 1) {
fcount++;
fsize = fsize + file.Size;
}
fsize = fsize / 1048576;
tcount += fcount;
tsize += fsize;
2001-11-25 14:13:55 +00:00
printf("%5d %5d %5ld %-12s %s\n", i, fcount, fsize, area.BbsGroup, area.Name);
2001-11-18 23:19:08 +00:00
iTotal++;
2003-12-08 18:01:25 +00:00
fclose(pFile);
2001-11-18 23:19:08 +00:00
}
}
2001-11-25 14:13:55 +00:00
colour(CYAN, BLACK);
printf("----- ----- ----- ---------------------------------------------------------\n");
printf("%5d %5d %5ld \n", iTotal, tcount, tsize);
2001-11-18 23:19:08 +00:00
fclose(pAreas);
2001-12-02 17:10:49 +00:00
free(ticarea);
2001-11-18 23:19:08 +00:00
free(sAreas);
free(fAreas);
2001-12-02 17:10:49 +00:00
free(sTic);
2001-11-18 23:19:08 +00:00
}