|
|
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.5 2003/07/26 03:59:25 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: * *
11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
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:
76: return(1); } }
77: return(0);
78: }
79:
80: /*****************************************************************************/
81: /* View viewable file types from dir 'dirnum' */
82: /* 'fspec' must be padded */
83: /*****************************************************************************/
84: void sbbs_t::viewfiles(uint dirnum, char *fspec)
85: {
86: char viewcmd[256];
87: char tmp[512];
88: int i;
89:
90: curdirnum=dirnum; /* for ARS */
91: sprintf(viewcmd,"%s%s",cfg.dir[dirnum]->path,fspec);
92: if(!fexist(viewcmd)) {
93: bputs(text[FileNotFound]);
94: return; }
95: padfname(fspec,tmp);
96: truncsp(tmp);
97: for(i=0;i<cfg.total_fviews;i++)
1.1.1.2 ! root 98: if(!stricmp(tmp+9,cfg.fview[i]->ext) && chk_ar(cfg.fview[i]->ar,&useron)) {
1.1 root 99: strcpy(viewcmd,cfg.fview[i]->cmd);
100: break; }
101: if(i==cfg.total_fviews) {
102: bprintf(text[NonviewableFile],tmp+9);
103: return; }
104: sprintf(tmp,"%s%s",cfg.dir[dirnum]->path,fspec);
1.1.1.2 ! root 105: if((i=external(cmdstr(viewcmd,tmp,tmp,NULL),EX_OUTL|EX_OUTR|EX_INR|EX_SH))!=0)
! 106: errormsg(WHERE,ERR_EXEC,viewcmd,i); /* must of EX_SH to ^C */
1.1 root 107: }
108:
109: /****************************************************************************/
110: /****************************************************************************/
111: void sbbs_t::viewfilecontents(file_t* f)
112: {
113: char str[128],cmd[128];
114: char tmp[512];
115: int i;
116:
117: if(f->size<=0L) {
118: bputs(text[FileNotThere]);
119: return; }
120:
121: sprintf(str,"%s%s",f->altpath > 0 && f->altpath<=cfg.altpaths
122: ? cfg.altpath[f->altpath-1] : cfg.dir[f->dir]->path
123: ,unpadfname(f->name,tmp));
124: strcpy(tmp,f->name);
125: truncsp(tmp);
126: for(i=0;i<cfg.total_fviews;i++) {
127: if(!stricmp(tmp+9,cfg.fview[i]->ext)
128: && chk_ar(cfg.fview[i]->ar,&useron)) {
129: strcpy(cmd,cfg.fview[i]->cmd);
130: break; } }
131: if(i==cfg.total_fviews)
132: bprintf(text[NonviewableFile],tmp+9);
133: else
134: if((i=external(cmdstr(cmd,str,str,NULL)
1.1.1.2 ! root 135: ,EX_OUTL|EX_OUTR|EX_INR))!=0)
1.1 root 136: errormsg(WHERE,ERR_EXEC,cmdstr(cmd,str,str,NULL),i);
137: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.