Implemented bbs view archive/textfile

This commit is contained in:
Michiel Broek
2003-04-12 11:12:26 +00:00
parent cad87472f1
commit b3b4b5dcb5
18 changed files with 557 additions and 346 deletions

View File

@@ -156,7 +156,7 @@ pop3.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs
lastcallers.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h input.h language.h lastcallers.h
timeout.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h timeout.h funcs.h bye.h filesub.h language.h
chat.o: ../config.h ../lib/libs.h ../lib/ansi.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h chat.h funcs.h input.h language.h misc.h whoson.h
file.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h filesub.h file.h funcs.h input.h language.h misc.h timeout.h exitinfo.h whoson.h change.h
file.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h filesub.h file.h funcs.h input.h language.h misc.h timeout.h exitinfo.h whoson.h change.h dispfile.h
mbstat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbstat.h
misc.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/mberrors.h funcs.h input.h language.h misc.h timeout.h exitinfo.h
offline.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/mbse.h ../lib/users.h ../lib/records.h ../lib/bluewave.h ../lib/common.h ../lib/clcomm.h ../lib/msgtext.h ../lib/msg.h mail.h funcs.h input.h language.h file.h filesub.h exitinfo.h timeout.h msgutil.h pop3.h offline.h whoson.h
@@ -165,7 +165,7 @@ mbnewusr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/str
input.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/mberrors.h input.h timeout.h language.h
whoson.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h input.h language.h exitinfo.h whoson.h
door.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h input.h timeout.h exitinfo.h whoson.h door.h
dispfile.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msgtext.h ../lib/msg.h ../lib/clcomm.h funcs.h language.h oneline.h misc.h timeout.h timecheck.h exitinfo.h mail.h email.h input.h dispfile.h
dispfile.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msgtext.h ../lib/msg.h ../lib/clcomm.h funcs.h language.h oneline.h misc.h timeout.h timecheck.h exitinfo.h mail.h email.h input.h dispfile.h filesub.h
userlist.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h userlist.h language.h input.h timeout.h
timestats.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h timestats.h funcs.h language.h input.h exitinfo.h
logentry.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h logentry.h

View File

@@ -4,7 +4,7 @@
* Purpose ...............: Display ANSI/ASCII textfiles
*
*****************************************************************************
* Copyright (C) 1997-2002
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@@ -50,7 +50,7 @@
#include "email.h"
#include "input.h"
#include "dispfile.h"
#include "filesub.h"
@@ -162,7 +162,7 @@ int DisplayTextFile(char *filename)
{
FILE *fp;
char *buf;
int i, x, c, lc = 0;
int i, x, c, z, lc = 0;
if ((fp = fopen(filename, "r")) == NULL) {
WriteError("$DisplayTextFile(%s) failed");
@@ -186,9 +186,26 @@ int DisplayTextFile(char *filename)
fflush(stdout);
lc++;
if (lc == exitinfo.iScreenLen) {
Pause();
if ((lc >= exitinfo.iScreenLen) && (lc < 1000)) {
lc = 0;
/* More (Y/n/=) */
pout(CFG.MoreF, CFG.MoreB, (char *) Language(61));
fflush(stdout);
alarm_on();
z = toupper(Getone());
if (z == Keystroke(61, 1)) {
printf("\n");
fflush(stdout);
fclose(fp);
free(buf);
return TRUE;
}
if (z == Keystroke(61, 2))
lc = 50000;
Blanker(strlen(Language(61)));
colour(CFG.TextColourF, CFG.TextColourB);
}
}
@@ -198,7 +215,7 @@ int DisplayTextFile(char *filename)
Enter(1);
/* Press ENTER to continue */
language(LIGHTMAGENTA, BLACK, 436);
language(CFG.MoreF, CFG.MoreB, 436);
fflush(stdout);
fflush(stdin);
alarm_on();
@@ -216,129 +233,121 @@ int DisplayTextFile(char *filename)
*/
int DisplayFile(char *filename)
{
FILE *pFileName;
long iSec = 0;
char *sFileName, *tmp, *tmp1;
char newfile[PATH_MAX];
int i, x;
FILE *pFileName;
long iSec = 0;
char *sFileName, *tmp, *tmp1, newfile[PATH_MAX];
int i, x;
sFileName = calloc(16385, sizeof(char));
tmp = calloc(PATH_MAX, sizeof(char));
tmp1 = calloc(PATH_MAX, sizeof(char));
sFileName = calloc(16385, sizeof(char));
tmp = calloc(PATH_MAX, sizeof(char));
tmp1 = calloc(PATH_MAX, sizeof(char));
/*
* Open the file in the following search order:
* 1 - if GraphMode -> users language .ans
* 2 - if GraphMode -> default language .ans
* 3 - users language .asc
* 4 - default language .asc
* 5 - Abort, there is no file to show.
*/
pFileName = NULL;
if (exitinfo.GraphMode) {
sprintf(newfile, "%s/%s.ans", lang.TextPath, filename);
if ((pFileName = fopen(newfile, "rb")) == NULL) {
sprintf(newfile, "%s/%s.ans", CFG.bbs_txtfiles, filename);
pFileName = fopen(newfile, "rb");
}
/*
* Open the file in the following search order:
* 1 - if GraphMode -> users language .ans
* 2 - if GraphMode -> default language .ans
* 3 - users language .asc
* 4 - default language .asc
* 5 - Abort, there is no file to show.
*/
pFileName = NULL;
if (exitinfo.GraphMode) {
sprintf(newfile, "%s/%s.ans", lang.TextPath, filename);
if ((pFileName = fopen(newfile, "rb")) == NULL) {
sprintf(newfile, "%s/%s.ans", CFG.bbs_txtfiles, filename);
pFileName = fopen(newfile, "rb");
}
if (pFileName == NULL) {
sprintf(newfile, "%s/%s.asc", lang.TextPath, filename);
if ((pFileName = fopen(newfile, "rb")) == NULL) {
sprintf(newfile, "%s/%s.asc", CFG.bbs_txtfiles, filename);
if ((pFileName = fopen(newfile, "rb")) == NULL) {
free(sFileName);
free(tmp);
free(tmp1);
return FALSE;
}
}
}
if (pFileName == NULL) {
sprintf(newfile, "%s/%s.asc", lang.TextPath, filename);
if ((pFileName = fopen(newfile, "rb")) == NULL) {
sprintf(newfile, "%s/%s.asc", CFG.bbs_txtfiles, filename);
if ((pFileName = fopen(newfile, "rb")) == NULL) {
free(sFileName);
free(tmp);
free(tmp1);
return FALSE;
}
}
}
Syslog('B', "Displayfile %s", newfile);
Syslog('B', "Displayfile %s", newfile);
while (!feof(pFileName)) {
i = fread(sFileName, sizeof(char), 16384, pFileName);
while (!feof(pFileName)) {
i = fread(sFileName, sizeof(char), 16384, pFileName);
for(x = 0; x < i; x++) {
switch(*(sFileName + x)) {
case '':
ControlCodeU(sFileName[++x]);
break;
for (x = 0; x < i; x++) {
switch(*(sFileName + x)) {
case '': ControlCodeU(sFileName[++x]);
break;
case '':
ControlCodeF(sFileName[++x]);
break;
case '': ControlCodeF(sFileName[++x]);
break;
case ' ':
ControlCodeK(sFileName[++x]);
break;
case ' ': ControlCodeK(sFileName[++x]);
break;
case '':
fflush(stdout);
fflush(stdin);
alarm_on();
Getone();
break;
case '': fflush(stdout);
fflush(stdin);
alarm_on();
Getone();
break;
case '':
/*
* This code will allow you to specify a security level
* in front of the text, ie ^B32000^Bthis is a test^B
* will print this is a test only if you have security
* above 32000. Only one set of control chars per line.
* You cannot have multiple securitys etc
*/
x++;
strcpy(tmp1, "");
while (*(sFileName + x) != '') {
sprintf(tmp, "%c", *(sFileName + x));
strcat(tmp1, tmp);
x++;
}
x++;
iSec = atoi(tmp1);
while ((x <= i) && (*(sFileName + x) != '')) {
if (exitinfo.Security.level >= iSec)
printf("%c", *(sFileName + x));
x++;
}
break;
case '': /*
* This code will allow you to specify a security level
* in front of the text, ie ^B32000^Bthis is a test^B
* will print this is a test only if you have security
* above 32000. Only one set of control chars per line.
* You cannot have multiple securitys etc
*/
x++;
strcpy(tmp1, "");
while (*(sFileName + x) != '') {
sprintf(tmp, "%c", *(sFileName + x));
strcat(tmp1, tmp);
x++;
}
x++;
iSec = atoi(tmp1);
while ((x <= i) && (*(sFileName + x) != '')) {
if (exitinfo.Security.level >= iSec)
printf("%c", *(sFileName + x));
x++;
}
break;
case '':
fflush(stdout);
sleep(1);
break;
case '': fflush(stdout);
sleep(1);
break;
default:
printf("%c", *(sFileName + x));
default: printf("%c", *(sFileName + x));
} /* switch */
} /* for */
} /* while !eof */
} /* switch */
} /* for */
} /* while !eof */
fclose(pFileName);
free(sFileName);
free(tmp);
free(tmp1);
return TRUE;
fclose(pFileName);
free(sFileName);
free(tmp);
free(tmp1);
return TRUE;
}
int DisplayFileEnter(char *File)
{
int rc;
int rc;
rc = DisplayFile(File);
Enter(1);
/* Press ENTER to continue */
language(13, 0, 436);
fflush(stdout);
fflush(stdin);
alarm_on();
Getone();
return rc;
rc = DisplayFile(File);
Enter(1);
/* Press ENTER to continue */
language(13, 0, 436);
fflush(stdout);
fflush(stdin);
alarm_on();
Getone();
return rc;
}

View File

@@ -4,7 +4,7 @@
* Purpose ...............: All the file functions.
*
*****************************************************************************
* Copyright (C) 1997-2002
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@@ -47,6 +47,7 @@
#include "exitinfo.h"
#include "whoson.h"
#include "change.h"
#include "dispfile.h"
@@ -2214,9 +2215,166 @@ void EditTaglist()
/*
* View a file in the current area, menu 103.
* If a file name is given, display direct,
* else ask for filename to view.
*/
void ViewFile()
void ViewFile(char *name)
{
char *File, *temp, *arc;
int count, total, rc, found = FALSE;
FILE *fp, *pFile;
Syslog('+', "ViewFile(%s)", printable(name, 0));
if (Access(exitinfo.Security, area.LTSec) == FALSE) {
colour(YELLOW, BLACK);
/* You don't have enough security to list this area */
printf("\n%s\n", (char *) Language(236));
Pause();
return;
}
File = calloc(PATH_MAX, sizeof(char));
if ((name != NULL) && strlen(name)) {
strcpy(File, name);
} else {
Enter(2);
/* Please enter filename: */
pout(YELLOW, BLACK, (char *) Language(245));
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(File, 80);
if ((strcmp(File, "")) == 0) {
free(File);
return;
}
if (*(File) == '.' || *(File) == '*' || *(File) == ' ' || *(File) == '/') {
colour(CFG.HiliteF, CFG.HiliteB);
/* Illegal Filename! */
printf("\n%s\n\n", (char *) Language(247));
Pause();
free(File);
return;
}
Strlen = strlen(File);
Strlen--;
if (*(File + Strlen) == '.' || *(File + Strlen) == '/' || *(File + Strlen) == ' ') {
colour(CFG.HiliteF, CFG.HiliteB);
/* Illegal Filename! */
printf("\n%s\n\n", (char *) Language(247));
Pause();
free(File);
return;
}
if ((!strcmp(File, "files.bbs")) || (!strcmp(File, "00index")) || (strstr(File, (char *)".html"))) {
colour(CFG.HiliteF, CFG.HiliteB);
/* Illegal Filename! */
printf("\n%s\n\n", (char *) Language(247));
Pause();
free(File);
return;
}
}
/*
* Now check if this file is present
*/
if ((pFile = OpenFileBase(iAreaNumber, FALSE)) == NULL) {
free(File);
return;
}
while (fread(&file, sizeof(file), 1, pFile) == 1) {
if (((strcasecmp(File, file.Name) == 0) || (strcasecmp(File, file.LName) == 0)) && (!file.Deleted) && (!file.Missing)) {
found = TRUE;
break;
}
}
fclose(pFile);
if (!found) {
colour(YELLOW, BLACK);
/* File does not exist, please try again ... */
printf("\n%s\n\n", (char *) Language(296));
free(File);
Pause();
return;
}
sprintf(File, "%s/%s", sAreaPath, file.LName);
arc = GetFileType(File);
Syslog('+', "File to view: %s, type %s", file.LName, printable(arc, 0));
if (arc != NULL) {
found = FALSE;
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/archiver.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) != NULL) {
fread(&archiverhdr, sizeof(archiverhdr), 1, fp);
while (fread(&archiver, archiverhdr.recsize, 1, fp) == 1) {
if ((strcmp(arc, archiver.name) == 0) && (archiver.available)) {
found = TRUE;
break;
}
}
fclose(fp);
}
if (!found || (strlen(archiver.varc) == 0)) {
Syslog('+', "No archiver view for %s available", File);
colour(YELLOW, BLACK);
/* Archiver not available */
printf("\n%s\n\n", Language(442));
free(File);
free(temp);
Pause();
return;
}
/*
* Archiver viewer is available. Make a temp file which we will
* display to the user.
*/
sprintf(temp, "%s/%s/temptxt", CFG.bbs_usersdir, exitinfo.Name);
rc = execute(archiver.varc, File, NULL, (char *)"/dev/null", temp, (char *)"/dev/null");
Syslog('+', "Display temp file %s", temp);
DisplayTextFile(temp);
unlink(temp);
free(temp);
} else {
/*
* Most likely a textfile, first check.
*/
total = count = 0;
if ((fp = fopen(File, "r"))) {
while (TRUE) {
rc = fgetc(fp);
if (rc == EOF)
break;
total++;
if (isascii(rc))
count++;
}
fclose(fp);
}
if (((count * 10) / total) < 8) {
Syslog('+', "This is not a ASCII textfile");
printf("\n%s\n\n", Language(17));
Pause();
free(File);
return;
}
Syslog('+', "Display text file %s", File);
DisplayTextFile(File);
}
free(File);
}

View File

@@ -1,6 +1,7 @@
#ifndef _FILE_H
#define _FILE_H
/* $Id$ */
void File_RawDir(char *); /* Raw Directory List of a Directory */
void File_List(void); /* List files in current Area */
@@ -18,7 +19,7 @@ void Delete_Home(void); /* Delete file from home directory */
int Download_Home(void); /* Allows user to download from home dir */
int Upload_Home(void); /* Allows user to upload to home directory */
void Copy_Home(void); /* Copy a file to home directory */
void ViewFile(void); /* View a file in the current area. */
void ViewFile(char *); /* View a file in the current area. */
#endif

View File

@@ -732,7 +732,7 @@ char *GetFileType(char *fn)
if (memcmp(buf, "MTM", 3) == 0) return (char *)"MTM";
if (memcmp(buf, "#!/bin/", 7) == 0) return (char *)"UNIX script";
if (memcmp(buf, "\037\235", 2) == 0) return (char *)"Compressed data";
if (memcmp(buf, "\037\213", 2) == 0) return (char *)"gzip compress";
if (memcmp(buf, "\037\213", 2) == 0) return (char *)"GZIP";
if (memcmp(buf, "\177ELF", 4) == 0) return (char *)"ELF";
if (memcmp(buf, "%!", 2) == 0) return (char *)"PostScript";
if (memcmp(buf, "GIF8", 4) == 0) return (char *)"GIF";

View File

@@ -429,7 +429,7 @@ void DoMenu(int Type)
break;
case 103:
ViewFile();
ViewFile(NULL);
break;
case 104: