viewfile.cpp 4.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/* viewfile.cpp */

/* Synchronet file contents display routines */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
rswindell's avatar
rswindell committed
11
 * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html		*
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 *																			*
 * This program 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			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"

/****************************************************************************/
/* Views file with:                                                         */
/* (B)atch download, (V)iew file (E)xtended info, (Q)uit, or [Next]:        */
/* call with ext=1 for default to extended info, or 0 for file view         */
/* Returns -1 for Batch, 1 for Next, or 0 for Quit                          */
/****************************************************************************/
int sbbs_t::viewfile(file_t* f, int ext)
{
48 49
	char	ch,str[256];
	char 	tmp[512];
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

	curdirnum=f->dir;	/* for ARS */
	while(online) {
		if(ext)
			fileinfo(f);
		else
			viewfilecontents(f);
		ASYNC;
		CRLF;
		sprintf(str,text[FileInfoPrompt],unpadfname(f->name,tmp));
		mnemonics(str);
		ch=(char)getkeys("BEVQ\r",0);
		if(ch=='Q' || sys_status&SS_ABORT)
			return(0);
		switch(ch) {
			case 'B':
				addtobatdl(f);
				CRLF;
				return(-1);
			case 'E':
				ext=1;
				continue;
			case 'V':
				ext=0;
				continue;
			case CR:
76 77 78
				return(1); 
		} 
	}
79 80 81 82 83 84 85 86 87
	return(0);
}

/*****************************************************************************/
/* View viewable file types from dir 'dirnum'                                */
/* 'fspec' must be padded                                                    */
/*****************************************************************************/
void sbbs_t::viewfiles(uint dirnum, char *fspec)
{
88 89 90
    char	viewcmd[256];
	char 	tmp[512];
    int		i;
91 92 93 94 95

	curdirnum=dirnum;	/* for ARS */
	sprintf(viewcmd,"%s%s",cfg.dir[dirnum]->path,fspec);
	if(!fexist(viewcmd)) {
		bputs(text[FileNotFound]);
96 97
		return; 
	}
98 99 100
	padfname(fspec,tmp);
	truncsp(tmp);
	for(i=0;i<cfg.total_fviews;i++)
rswindell's avatar
rswindell committed
101
		if(!stricmp(tmp+9,cfg.fview[i]->ext) && chk_ar(cfg.fview[i]->ar,&useron,&client)) {
102
			strcpy(viewcmd,cfg.fview[i]->cmd);
103 104
			break; 
		}
105 106
	if(i==cfg.total_fviews) {
		bprintf(text[NonviewableFile],tmp+9);
107 108
		return; 
	}
109
	sprintf(tmp,"%s%s",cfg.dir[dirnum]->path,fspec);
rswindell's avatar
rswindell committed
110 111
	if((i=external(cmdstr(viewcmd,tmp,tmp,NULL),EX_OUTL|EX_OUTR|EX_INR|EX_SH))!=0)
		errormsg(WHERE,ERR_EXEC,viewcmd,i);    /* must of EX_SH to ^C */
112 113 114 115 116 117
}

/****************************************************************************/
/****************************************************************************/
void sbbs_t::viewfilecontents(file_t* f)
{
118 119 120
	char	cmd[128];
	char	path[MAX_PATH+1];
	char* 	ext;
121
	int		i;
122

123
	getfilepath(&cfg, f, path);
124

125 126 127 128 129 130 131 132
	if(f->size<=0L) {
		bprintf(text[FileDoesNotExist],path);
		return; 
	}
	if((ext=getfext(path))!=NULL) {
		ext++;
		for(i=0;i<cfg.total_fviews;i++) {
			if(!stricmp(ext,cfg.fview[i]->ext)
rswindell's avatar
rswindell committed
133
				&& chk_ar(cfg.fview[i]->ar,&useron,&client)) {
134 135 136 137 138 139 140
				strcpy(cmd,cfg.fview[i]->cmd);
				break; 
			} 
		}
	}
	if(ext==NULL || i==cfg.total_fviews)
		bprintf(text[NonviewableFile],ext);
141
	else
142
		if((i=external(cmdstr(cmd,path,path,NULL)
rswindell's avatar
rswindell committed
143
			,EX_OUTL|EX_OUTR|EX_INR))!=0)
144
			errormsg(WHERE,ERR_EXEC,cmdstr(cmd,path,path,NULL),i);
145
}