|
|
1.1 root 1: /* scandirs.cpp */
2:
3: /* Synchronet file database scanning routines */
4:
1.1.1.2 ! root 5: /* $Id: scandirs.cpp,v 1.5 2011/07/21 11:19:22 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 2011 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: /* Used to scan single or multiple directories. 'mode' is the scan type. */
42: /****************************************************************************/
43: void sbbs_t::scandirs(long mode)
44: {
45: char ch,str[256];
46: char tmp[512];
47: int s;
48: uint i,k;
49:
50: if(!usrlibs) return;
51: mnemonics(text[DirLibOrAll]);
52: ch=(char)getkeys("DLA\r",0);
53: if(sys_status&SS_ABORT || ch==CR) {
54: lncntr=0;
1.1.1.2 ! root 55: return;
! 56: }
1.1 root 57: if(ch!='A') {
58: if(mode&FL_ULTIME) { /* New file scan */
1.1.1.2 ! root 59: bprintf(text[NScanHdr],timestr(ns_time));
! 60: str[0]=0;
! 61: }
1.1 root 62: else if(mode==FL_NO_HDR) { /* Search for a string */
63: if(!getfilespec(tmp))
64: return;
1.1.1.2 ! root 65: padfname(tmp,str);
! 66: }
1.1 root 67: else if(mode==FL_FINDDESC) { /* Find text in description */
1.1.1.2 ! root 68: if(text[SearchExtendedQ][0] && !noyes(text[SearchExtendedQ]))
1.1 root 69: mode=FL_EXFIND;
70: if(sys_status&SS_ABORT) {
71: lncntr=0;
1.1.1.2 ! root 72: return;
! 73: }
1.1 root 74: bputs(text[SearchStringPrompt]);
75: if(!getstr(str,40,K_LINE|K_UPPER)) {
76: lncntr=0;
1.1.1.2 ! root 77: return;
! 78: }
! 79: }
! 80: }
1.1 root 81: if(ch=='D') {
82: if((s=listfiles(usrdir[curlib][curdir[curlib]],str,0,mode))==-1)
83: return;
84: bputs("\r\1>");
85: if(s>1)
86: bprintf(text[NFilesListed],s);
87: else if(!s && !(mode&FL_ULTIME))
88: bputs(text[FileNotFound]);
1.1.1.2 ! root 89: return;
! 90: }
1.1 root 91: if(ch=='L') {
92: k=0;
93: for(i=0;i<usrdirs[curlib] && !msgabort();i++) {
94: attr(LIGHTGRAY);
95: outchar('.');
96: if(i && !(i%5))
97: bputs("\b\b\b\b\b \b\b\b\b\b");
98: if(mode&FL_ULTIME /* New-scan */
99: && (cfg.lib[usrlib[curlib]]->offline_dir==usrdir[curlib][i]
100: || cfg.dir[usrdir[curlib][i]]->misc&DIR_NOSCAN))
101: continue;
102: else if((s=listfiles(usrdir[curlib][i],str,0,mode))==-1)
103: return;
1.1.1.2 ! root 104: else k+=s;
! 105: }
1.1 root 106: bputs("\r\1>");
107: if(k>1)
108: bprintf(text[NFilesListed],k);
109: else if(!k && !(mode&FL_ULTIME))
110: bputs(text[FileNotFound]);
1.1.1.2 ! root 111: return;
! 112: }
1.1 root 113:
114: scanalldirs(mode);
115: }
116:
117: /****************************************************************************/
118: /* Scan all directories in all libraries for files */
119: /****************************************************************************/
120: void sbbs_t::scanalldirs(long mode)
121: {
122: char str[256];
123: char tmp[512];
124: int s;
125: uint i,j,k,d;
126:
127: if(!usrlibs) return;
128: k=0;
129: if(mode&FL_ULTIME) { /* New file scan */
1.1.1.2 ! root 130: bprintf(text[NScanHdr],timestr(ns_time));
! 131: str[0]=0;
! 132: }
1.1 root 133: else if(mode==FL_NO_HDR) { /* Search for a string */
134: if(!getfilespec(tmp))
135: return;
1.1.1.2 ! root 136: padfname(tmp,str);
! 137: }
1.1 root 138: else if(mode==FL_FINDDESC) { /* Find text in description */
1.1.1.2 ! root 139: if(text[SearchExtendedQ][0] && !noyes(text[SearchExtendedQ]))
1.1 root 140: mode=FL_EXFIND;
141: if(sys_status&SS_ABORT) {
142: lncntr=0;
1.1.1.2 ! root 143: return;
! 144: }
1.1 root 145: bputs(text[SearchStringPrompt]);
146: if(!getstr(str,40,K_LINE|K_UPPER)) {
147: lncntr=0;
1.1.1.2 ! root 148: return;
! 149: }
! 150: }
1.1 root 151: for(i=d=0;i<usrlibs;i++) {
152: for(j=0;j<usrdirs[i] && !msgabort();j++,d++) {
153: attr(LIGHTGRAY);
154: outchar('.');
155: if(d && !(d%5))
156: bputs("\b\b\b\b\b \b\b\b\b\b");
157: if(mode&FL_ULTIME /* New-scan */
158: && (cfg.lib[usrlib[i]]->offline_dir==usrdir[i][j]
159: || cfg.dir[usrdir[i][j]]->misc&DIR_NOSCAN))
160: continue;
161: else if((s=listfiles(usrdir[i][j],str,0,mode))==-1)
162: return;
1.1.1.2 ! root 163: else k+=s;
! 164: }
1.1 root 165: if(j<usrdirs[i]) /* aborted */
1.1.1.2 ! root 166: break;
! 167: }
1.1 root 168: bputs("\r\1>");
169: if(k>1)
170: bprintf(text[NFilesListed],k);
171: else if(!k && !(mode&FL_ULTIME))
172: bputs(text[FileNotFound]);
173: }
174:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.