Added mbfile list [area]

This commit is contained in:
Michiel Broek 2001-11-25 14:13:55 +00:00
parent a877a50ded
commit 9f48fb1352
4 changed files with 107 additions and 32 deletions

View File

@ -124,8 +124,15 @@ int main(int argc, char **argv)
cmd = xstrcat(cmd, argv[i]);
}
}
if (!strncmp(argv[i], "l", 1))
if (!strncmp(argv[i], "l", 1)) {
do_list = TRUE;
if (argc > (i + 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
}
}
if (!strncmp(argv[i], "p", 1))
do_pack = TRUE;
if (!strncmp(argv[i], "c", 1))
@ -173,7 +180,7 @@ int main(int argc, char **argv)
Index();
if (do_list)
ListFileAreas();
ListFileAreas(Area);
die(0);
return 0;

View File

@ -42,37 +42,115 @@
extern int do_quiet; /* Supress screen output */
void ListFileAreas(void)
void ListFileAreas(int Area)
{
FILE *pAreas, *pFile;
int i, iAreas, fcount, tcount = 0;
int iTotal = 0;
long fsize, tsize = 0;
char *sAreas, *fAreas;
char *sAreas, *fAreas, flags[6];
/*
* If nothing to display allowed, return at once.
*/
if (do_quiet)
return;
colour(LIGHTRED, BLACK);
sAreas = calloc(PATH_MAX, sizeof(char));
fAreas = calloc(PATH_MAX, sizeof(char));
IsDoing("List fileareas");
if (!do_quiet) {
colour(3, 0);
printf(" Area Files MByte File Group Area name\n");
printf("----- ----- ----- ------------ --------------------------------------------\n");
colour(7, 0);
}
sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((pAreas = fopen (sAreas, "r")) == NULL) {
WriteError("Can't open %s", sAreas);
if (!do_quiet)
printf("Can't open %s\n", sAreas);
printf("Can't open %s\n", sAreas);
die(0);
}
fread(&areahdr, sizeof(areahdr), 1, pAreas);
fseek(pAreas, 0, SEEK_END);
iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize;
if (Area) {
IsDoing("List area %d", Area);
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);
die(0);
}
}
fcount = 0;
fsize = 0L;
colour(CYAN, BLACK);
printf("File listing of area %d, %s\n\n", Area, area.Name);
printf("File name Kbytes File date Dnlds Flags Description\n");
printf("------------ ------ ---------- ----- ----- ------------------------------------\n");
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';
if (strlen(file.Desc[0]) > 36)
file.Desc[0][36] = '\0';
printf("%-12s %6ld %s %5ld %s %s\n",
file.Name, file.Size / 1024, StrDateDMY(file.FileDate),
file.TimesDL + file.TimesFTP + file.TimesReq, flags, file.Desc[0]);
fcount++;
fsize = fsize + file.Size;
}
fsize = fsize / 1024;
colour(CYAN, BLACK);
printf("-------------------------------------------------------------------------------\n");
printf("%d file%s, %ld Kbytes\n", fcount, (fcount == 1) ? "":"s", fsize);
} else {
WriteError("Area %d is not available", Area);
printf("Area %d is not available\n", Area);
return;
}
free(sAreas);
free(fAreas);
return;
}
IsDoing("List fileareas");
colour(CYAN, BLACK);
printf(" Area Files MByte File Group Area name\n");
printf("----- ----- ----- ------------ --------------------------------------------\n");
colour(LIGHTGRAY, BLACK);
for (i = 1; i <= iAreas; i++) {
fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
@ -80,11 +158,10 @@ void ListFileAreas(void)
if (area.Available) {
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
/*
* Open the file database, create new one if it doesn't excist.
* Open the file database, create new one if it doesn't exist.
*/
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
if ((pFile = fopen(fAreas, "r+")) == NULL) {
Syslog('!', "Creating new %s", fAreas);
if ((pFile = fopen(fAreas, "a+")) == NULL) {
@ -103,24 +180,15 @@ void ListFileAreas(void)
tcount += fcount;
tsize += fsize;
if (!do_quiet)
printf("%5d %5d %5ld %-12s %s\n", i, fcount, fsize, area.BbsGroup, area.Name);
printf("%5d %5d %5ld %-12s %s\n", i, fcount, fsize, area.BbsGroup, area.Name);
iTotal++;
}
}
if (!do_quiet) {
colour(3, 0);
printf("----- ----- ----- ---------------------------------------------------------\n");
printf("%5d %5d %5ld \n", iTotal, tcount, tsize);
}
colour(CYAN, BLACK);
printf("----- ----- ----- ---------------------------------------------------------\n");
printf("%5d %5d %5ld \n", iTotal, tcount, tsize);
fclose(pAreas);
if (!do_quiet) {
printf("\r \r");
fflush(stdout);
}
free(sAreas);
free(fAreas);
}

View File

@ -3,6 +3,6 @@
#ifndef _MBFLIST_H_
#define _MBFLIST_H
void ListFileAreas(void); /* List fileareas */
void ListFileAreas(int); /* List fileareas */
#endif

View File

@ -119,7 +119,7 @@ void Help(void)
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 List file areas\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");