Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

viewfile.cpp 4.01 KB
Newer Older
1 2 3 4 5 6
/* Synchronet file contents display routines */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *																			*
 * 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										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"
23
#include "filedat.h"
24 25 26 27 28

/****************************************************************************/
/* 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         */
29
/* Returns -1 for Batch, 1 for Next, -2 for Previous, or 0 for Quit         */
30
/****************************************************************************/
31
int sbbs_t::viewfile(file_t* f, bool ext)
32
{
33
	char	ch,str[256];
34 35
	char	fname[13];	/* This is one of the only 8.3 filename formats left! (used for display purposes only) */
	format_filename(f->name, fname, sizeof(fname)-1, /* pad: */FALSE);
36 37

	curdirnum=f->dir;	/* for ARS */
38
	bool	can_edit = dir_op(f->dir) || useron.exempt&FLAG('R') || stricmp(f->from, useron.alias) == 0;
39
	while(online) {
40
		sys_status &= ~SS_ABORT;
41 42
		SAFEPRINTF(str, text[FileInfoPrompt], fname);
		if(ext) {
43
			showfileinfo(f);
44 45 46
			if(can_edit)
				SAFEPRINTF(str, text[FileInfoEditPrompt], fname);
		} else
47 48 49
			viewfilecontents(f);
		ASYNC;
		mnemonics(str);
50 51 52 53
		SAFECOPY(str, "BEVQPN\b-\r");
		if(can_edit)
			SAFECAT(str, "D");
		ch=(char)getkeys(str, 0);
54 55 56 57 58 59 60
		if(ch=='Q' || sys_status&SS_ABORT)
			return(0);
		switch(ch) {
			case 'B':
				addtobatdl(f);
				CRLF;
				return(-1);
61 62 63
			case 'D':
				editfiledesc(f);
				continue;
64
			case 'E':
65 66 67
				if(ext && can_edit) {
					if(!editfiledesc(f))
						continue;
68
					editfileinfo(f);
69
				} else
70
					ext = true;
71 72
				continue;
			case 'V':
73
				ext = false;
74
				continue;
75 76 77 78
			case 'P':
			case '\b':
			case '-':
				return -2;
79
			case 'N':
80
			case CR:
81 82 83
				return(1); 
		} 
	}
84 85 86 87 88
	return(0);
}

/*****************************************************************************/
/*****************************************************************************/
89
bool sbbs_t::viewfile(const char* path)
90
{
91 92
    char	viewcmd[256];
    int		i;
93

94
	if(!fexist(path)) {
95
		bputs(text[FileNotFound]);
96
		return false; 
97
	}
98
	char* file_ext = getfext(path);
99
	if(file_ext == NULL) {
100 101
		bprintf(text[NonviewableFile], getfname(path));
		return false;
102
	}
103
	for(i=0;i<cfg.total_fviews;i++)
104
		if(wildmatchi(file_ext + 1, cfg.fview[i]->ext, /* path: */false) && chk_ar(cfg.fview[i]->ar,&useron,&client)) {
105
			SAFECOPY(viewcmd,cfg.fview[i]->cmd);
106
			break;
107
		}
108
	if(i >= cfg.total_fviews) {
109
		bprintf(text[NonviewableFile], file_ext);
110
		return false;
111
	}
112
	if((i=external(cmdstr(viewcmd, path, path, NULL), EX_STDIO|EX_SH))!=0) {
113
		errormsg(WHERE,ERR_EXEC,viewcmd,i);    /* must have EX_SH to ^C */
114 115 116
		return false;
	}
	return true;
117 118 119 120
}

/****************************************************************************/
/****************************************************************************/
121
bool sbbs_t::viewfilecontents(file_t* f)
122
{
123
	char	path[MAX_PATH + 1];
124

125
	getfilepath(&cfg, f, path);
126 127 128 129 130
	uint savedir = curdirnum;
	curdirnum = f->dir;	/* for ARS */
	bool result = viewfile(path);
	curdirnum = savedir;
	return result;
131
}