|
|
1.1 root 1: /* viewfile.cpp */
2:
3: /* Synchronet file contents display routines */
4:
1.1.1.2 ! root 5: /* $Id: viewfile.cpp,v 1.9 2010/03/12 08:27:57 rswindell Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
1.1.1.2 ! root 11: * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39:
40: /****************************************************************************/
41: /* Views file with: */
42: /* (B)atch download, (V)iew file (E)xtended info, (Q)uit, or [Next]: */
43: /* call with ext=1 for default to extended info, or 0 for file view */
44: /* Returns -1 for Batch, 1 for Next, or 0 for Quit */
45: /****************************************************************************/
46: int sbbs_t::viewfile(file_t* f, int ext)
47: {
48: char ch,str[256];
49: char tmp[512];
50:
51: curdirnum=f->dir; /* for ARS */
52: while(online) {
53: if(ext)
54: fileinfo(f);
55: else
56: viewfilecontents(f);
57: ASYNC;
58: CRLF;
59: sprintf(str,text[FileInfoPrompt],unpadfname(f->name,tmp));
60: mnemonics(str);
61: ch=(char)getkeys("BEVQ\r",0);
62: if(ch=='Q' || sys_status&SS_ABORT)
63: return(0);
64: switch(ch) {
65: case 'B':
66: addtobatdl(f);
67: CRLF;
68: return(-1);
69: case 'E':
70: ext=1;
71: continue;
72: case 'V':
73: ext=0;
74: continue;
75: case CR:
1.1.1.2 ! root 76: return(1);
! 77: }
! 78: }
1.1 root 79: return(0);
80: }
81:
82: /*****************************************************************************/
83: /* View viewable file types from dir 'dirnum' */
84: /* 'fspec' must be padded */
85: /*****************************************************************************/
86: void sbbs_t::viewfiles(uint dirnum, char *fspec)
87: {
88: char viewcmd[256];
89: char tmp[512];
90: int i;
91:
92: curdirnum=dirnum; /* for ARS */
93: sprintf(viewcmd,"%s%s",cfg.dir[dirnum]->path,fspec);
94: if(!fexist(viewcmd)) {
95: bputs(text[FileNotFound]);
1.1.1.2 ! root 96: return;
! 97: }
1.1 root 98: padfname(fspec,tmp);
99: truncsp(tmp);
100: for(i=0;i<cfg.total_fviews;i++)
1.1.1.2 ! root 101: if(!stricmp(tmp+9,cfg.fview[i]->ext) && chk_ar(cfg.fview[i]->ar,&useron,&client)) {
1.1 root 102: strcpy(viewcmd,cfg.fview[i]->cmd);
1.1.1.2 ! root 103: break;
! 104: }
1.1 root 105: if(i==cfg.total_fviews) {
106: bprintf(text[NonviewableFile],tmp+9);
1.1.1.2 ! root 107: return;
! 108: }
1.1 root 109: sprintf(tmp,"%s%s",cfg.dir[dirnum]->path,fspec);
1.1.1.2 ! root 110: if((i=external(cmdstr(viewcmd,tmp,tmp,NULL),EX_STDIO|EX_SH))!=0)
! 111: errormsg(WHERE,ERR_EXEC,viewcmd,i); /* must have EX_SH to ^C */
1.1 root 112: }
113:
114: /****************************************************************************/
115: /****************************************************************************/
116: void sbbs_t::viewfilecontents(file_t* f)
117: {
1.1.1.2 ! root 118: char cmd[128];
! 119: char path[MAX_PATH+1];
! 120: char* ext;
1.1 root 121: int i;
122:
1.1.1.2 ! root 123: getfilepath(&cfg, f, path);
1.1 root 124:
1.1.1.2 ! root 125: if(f->size<=0L) {
! 126: bprintf(text[FileDoesNotExist],path);
! 127: return;
! 128: }
! 129: if((ext=getfext(path))!=NULL) {
! 130: ext++;
! 131: for(i=0;i<cfg.total_fviews;i++) {
! 132: if(!stricmp(ext,cfg.fview[i]->ext)
! 133: && chk_ar(cfg.fview[i]->ar,&useron,&client)) {
! 134: strcpy(cmd,cfg.fview[i]->cmd);
! 135: break;
! 136: }
! 137: }
! 138: }
! 139: if(ext==NULL || i==cfg.total_fviews)
! 140: bprintf(text[NonviewableFile],ext);
1.1 root 141: else
1.1.1.2 ! root 142: if((i=external(cmdstr(cmd,path,path,NULL),EX_STDIO))!=0)
! 143: errormsg(WHERE,ERR_EXEC,cmdstr(cmd,path,path,NULL),i);
1.1 root 144: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.