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

202 lines
5.7 KiB
C
Raw Normal View History

2001-11-18 23:19:08 +00:00
/*****************************************************************************
*
* $Id$
* Purpose: File Database Maintenance - List areas and totals
*
*****************************************************************************
2005-08-28 13:06:08 +00:00
* Copyright (C) 1997-2005
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
{
2004-05-04 14:31:25 +00:00
FILE *pAreas, *pTic;
2004-03-08 20:51:04 +00:00
int i, iAreas, fcount, tcount = 0, iTotal = 0, columns = 80;
2001-11-18 23:19:08 +00:00
long fsize, tsize = 0;
2001-12-02 17:10:49 +00:00
char *sAreas, *fAreas, *sTic, flags[6], *ticarea;
2004-05-04 14:31:25 +00:00
struct _fdbarea *fdb_area = NULL;
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;
2004-03-08 20:51:04 +00:00
/*
* See if we know the width of the users screen.
*/
if (getenv("COLUMNS")) {
i = atoi(getenv("COLUMNS"));
if (i >= 80)
columns = i;
}
mbse_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
2005-08-28 13:06:08 +00:00
snprintf(sAreas, PATH_MAX -1, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
2001-11-18 23:19:08 +00:00
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);
2005-08-28 13:06:08 +00:00
snprintf(sTic, PATH_MAX -1, "%s/etc/tic.data", getenv("MBSE_ROOT"));
2001-12-02 17:10:49 +00:00
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) {
2004-05-04 14:31:25 +00:00
/*
* Open the file database.
*/
fdb_area = mbsedb_OpenFDB(Area, 30);
2001-11-25 14:13:55 +00:00
fcount = 0;
fsize = 0L;
mbse_colour(CYAN, BLACK);
2001-11-25 14:13:55 +00:00
printf("File listing of area %d, %s\n\n", Area, area.Name);
2004-03-06 21:48:41 +00:00
printf("Short name Kb. File date Down Flg TIC Area Long name\n");
printf("------------ ----- ---------- ---- --- -------------------- ");
2004-03-08 20:51:04 +00:00
for (i = 60; i < columns; i++)
2001-12-02 17:10:49 +00:00
printf("-");
printf("\n");
mbse_colour(LIGHTGRAY, BLACK);
2001-11-25 14:13:55 +00:00
2004-05-04 14:31:25 +00:00
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
2005-08-28 13:06:08 +00:00
snprintf(flags, 3, "---");
2004-03-06 21:48:41 +00:00
if (fdb.Deleted)
flags[0] = 'D';
if (fdb.NoKill)
flags[1] = 'N';
if (fdb.Announced)
flags[2] = 'A';
2004-03-08 20:51:04 +00:00
fdb.LName[columns - 60] = '\0';
2004-03-06 21:48:41 +00:00
printf("%-12s %5ld %s %4ld %s %-20s %s\n", fdb.Name, (long)(fdb.Size / 1024), StrDateDMY(fdb.FileDate),
(long)(fdb.TimesDL), flags, fdb.TicArea, fdb.LName);
2001-11-25 14:13:55 +00:00
fcount++;
2004-03-06 21:48:41 +00:00
fsize = fsize + fdb.Size;
2001-11-25 14:13:55 +00:00
}
fsize = fsize / 1024;
mbse_colour(CYAN, BLACK);
2004-03-08 20:51:04 +00:00
printf("------------------------------------------------------------");
for (i = 60; i < columns; i++)
2001-12-02 17:10:49 +00:00
printf("-");
printf("\n");
2001-11-25 14:13:55 +00:00
printf("%d file%s, %ld Kbytes\n", fcount, (fcount == 1) ? "":"s", fsize);
2004-05-04 14:31:25 +00:00
mbsedb_CloseFDB(fdb_area);
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");
mbse_colour(CYAN, BLACK);
2001-11-25 14:13:55 +00:00
printf(" Area Files MByte File Group Area name\n");
printf("----- ----- ----- ------------ --------------------------------------------\n");
mbse_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) {
2004-05-04 14:31:25 +00:00
fdb_area = mbsedb_OpenFDB(i, 30);
2001-11-18 23:19:08 +00:00
fcount = 0;
fsize = 0L;
2004-05-04 14:31:25 +00:00
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
2001-11-18 23:19:08 +00:00
fcount++;
2004-03-06 21:48:41 +00:00
fsize = fsize + fdb.Size;
2001-11-18 23:19:08 +00:00
}
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++;
2004-05-04 14:31:25 +00:00
mbsedb_CloseFDB(fdb_area);
2001-11-18 23:19:08 +00:00
}
}
mbse_colour(CYAN, BLACK);
2001-11-25 14:13:55 +00:00
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
}