|
|
1.1 root 1: /* addfiles.c */
2:
3: /* Program to add files to a Synchronet file database */
4:
5: /* $Id: addfiles.c,v 1.35 2004/05/30 06:47:52 deuce Exp $ */
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 2003 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: #define ADDFILES_VER "3.01"
41:
42: scfg_t scfg;
43:
44: int cur_altpath=0;
45:
46: long files=0,removed=0,mode=0;
47:
48: char lib[LEN_GSNAME+1];
49:
50: #define DEL_LIST (1L<<0)
51: #define NO_EXTEND (1L<<1)
52: #define FILE_DATE (1L<<2)
53: #define TODAYS_DATE (1L<<3)
54: #define FILE_ID (1L<<4)
55: #define NO_UPDATE (1L<<5)
56: #define NO_NEWDATE (1L<<6)
57: #define ASCII_ONLY (1L<<7)
58: #define UL_STATS (1L<<8)
59: #define ULDATE_ONLY (1L<<9)
60: #define KEEP_DESC (1L<<10)
61: #define AUTO_ADD (1L<<11)
62: #define SEARCH_DIR (1L<<12)
63: #define SYNC_LIST (1L<<13)
64: #define KEEP_SPACE (1L<<14)
65:
66: /****************************************************************************/
67: /* This is needed by load_cfg.c */
68: /****************************************************************************/
69: int lprintf(int level, char *fmat, ...)
70: {
71: va_list argptr;
72: char sbuf[512];
73: int chcount;
74:
75: va_start(argptr,fmat);
76: chcount=vsprintf(sbuf,fmat,argptr);
77: va_end(argptr);
78: truncsp(sbuf);
79: printf("%s\n",sbuf);
80: return(chcount);
81: }
82:
83: void prep_desc(uchar *str)
84: {
85: char tmp[1024];
86: int i,j;
87:
88: for(i=j=0;str[i] && j < sizeof(tmp)-1;i++) {
89: if(j && str[i]==' ' && tmp[j-1]==' ' && (mode&KEEP_SPACE))
90: tmp[j++]=str[i];
91: else if(j && str[i]<=' ' && tmp[j-1]==' ')
92: continue;
93: else if(i && !isalnum(str[i]) && str[i]==str[i-1])
94: continue;
95: else if(str[i]>=' ')
96: tmp[j++]=str[i];
97: else if(str[i]==TAB || (str[i]==CR && str[i+1]==LF))
98: tmp[j++]=' ';
99: }
100: tmp[j]=0;
101: strcpy(str,tmp);
102: }
103:
104: /*****************************************************************************/
105: /* Returns command line generated from instr with %c replacments */
106: /*****************************************************************************/
107: char *mycmdstr(char *instr, char *fpath, char *fspec, char *outstr)
108: {
109: static char cmd[MAX_PATH+1];
110: char str[MAX_PATH+1];
111: int i,j,len;
112: #ifdef _WIN32
113: char sfpath[MAX_PATH+1];
114: #endif
115:
116: len=strlen(instr);
117: for(i=j=0;i<len && j<128;i++) {
118: if(instr[i]=='%') {
119: i++;
120: cmd[j]=0;
121: switch(toupper(instr[i])) {
122: case 'F': /* File path */
123: strcat(cmd,fpath);
124: break;
125: case '~': /* DOS-compatible (8.3) filename */
126: #ifdef _WIN32
127: SAFECOPY(sfpath,fpath);
128: GetShortPathName(fpath,sfpath,sizeof(sfpath));
129: strcat(cmd,sfpath);
130: #else
131: strcat(cmd,fpath);
132: #endif
133: break;
134: case 'G': /* Temp directory */
135: strcat(cmd,scfg.temp_dir);
136: break;
137: case 'J':
138: strcat(cmd,scfg.data_dir);
139: break;
140: case 'K':
141: strcat(cmd,scfg.ctrl_dir);
142: break;
143: case 'N': /* Node Directory (same as SBBSNODE environment var) */
144: strcat(cmd,scfg.node_dir);
145: break;
146: case 'S': /* File Spec */
147: strcat(cmd,fspec);
148: break;
149: case 'Z':
150: strcat(cmd,scfg.text_dir);
151: break;
152: case '!': /* EXEC Directory */
153: strcat(cmd,scfg.exec_dir);
154: break;
155: case '#': /* Node number (same as SBBSNNUM environment var) */
156: sprintf(str,"%d",scfg.node_num);
157: strcat(cmd,str);
158: break;
159: case '%': /* %% for percent sign */
160: strcat(cmd,"%");
161: break;
162: default: /* unknown specification */
163: break;
164: }
165: j=strlen(cmd);
166: }
167: else
168: cmd[j++]=instr[i];
169: }
170: cmd[j]=0;
171:
172: return(cmd);
173: }
174:
175: /****************************************************************************/
176: /* Updates dstst.dab file */
177: /****************************************************************************/
178: void updatestats(ulong size)
179: {
180: char str[MAX_PATH+1];
181: int file;
182: ulong l;
183:
184: sprintf(str,"%sdsts.dab",scfg.ctrl_dir);
185: if((file=nopen(str,O_RDWR|O_BINARY))==-1) {
186: printf("ERR_OPEN %s\n",str);
187: return;
188: }
189: lseek(file,20L,SEEK_SET); /* Skip timestamp, logons and logons today */
190: read(file,&l,4); /* Uploads today */
191: l++;
192: lseek(file,-4L,SEEK_CUR);
193: write(file,&l,4);
194: read(file,&l,4); /* Upload bytes today */
195: l+=size;
196: lseek(file,-4L,SEEK_CUR);
197: write(file,&l,4);
198: close(file);
199: }
200:
201: void addlist(char *inpath, file_t f, uint dskip, uint sskip)
202: {
203: char str[MAX_PATH+1];
204: char tmp[MAX_PATH+1];
205: char fname[MAX_PATH+1];
206: char listpath[MAX_PATH+1];
207: char filepath[MAX_PATH+1];
208: char curline[256],nextline[256];
209: char *p;
210: uchar ext[1024],tmpext[513];
211: int i,file;
212: long l;
213: BOOL exist;
214: FILE *stream;
215: DIR* dir;
216: DIRENT* dirent;
217:
218: if(mode&SEARCH_DIR) {
219: strcpy(str,cur_altpath ? scfg.altpath[cur_altpath-1] : scfg.dir[f.dir]->path);
220: printf("Searching %s\n\n",str);
221: dir=opendir(str);
222:
223: while(dir!=NULL && (dirent=readdir(dir))!=NULL) {
224: sprintf(tmp,"%s%s"
225: ,cur_altpath ? scfg.altpath[cur_altpath-1] : scfg.dir[f.dir]->path
226: ,dirent->d_name);
227: if(isdir(tmp))
228: continue;
229: #ifdef _WIN32
230: GetShortPathName(tmp, filepath, sizeof(filepath));
231: #else
232: strcpy(filepath,tmp);
233: #endif
234: f.misc=0;
235: f.desc[0]=0;
236: f.cdt=flength(filepath);
237: padfname(getfname(filepath),f.name);
238: printf("%s %10lu %s\n"
239: ,f.name,f.cdt,unixtodstr(&scfg,fdate(filepath),str));
240: exist=findfile(&scfg,f.dir,f.name);
241: if(exist) {
242: if(mode&NO_UPDATE)
243: continue;
244: getfileixb(&scfg,&f);
245: if(mode&ULDATE_ONLY) {
246: f.dateuled=time(NULL);
247: update_uldate(&scfg, &f);
248: continue;
249: }
250: }
251:
252: if(mode&FILE_DATE) { /* get the file date and put into desc */
253: unixtodstr(&scfg,fdate(filepath),f.desc);
254: strcat(f.desc," ");
255: }
256:
257: if(mode&TODAYS_DATE) { /* put today's date in desc */
258: unixtodstr(&scfg,time(NULL),f.desc);
259: strcat(f.desc," ");
260: }
261:
262: if(mode&FILE_ID) {
263: for(i=0;i<scfg.total_fextrs;i++)
264: if(!stricmp(scfg.fextr[i]->ext,f.name+9) && chk_ar(&scfg,scfg.fextr[i]->ar,NULL))
265: break;
266: if(i<scfg.total_fextrs) {
267: sprintf(tmp,"%sFILE_ID.DIZ",scfg.temp_dir);
268: remove(tmp);
269: system(mycmdstr(scfg.fextr[i]->cmd,filepath,"FILE_ID.DIZ",NULL));
270: if(!fexistcase(tmp)) {
271: sprintf(tmp,"%sDESC.SDI",scfg.temp_dir);
272: remove(tmp);
273: system(mycmdstr(scfg.fextr[i]->cmd,filepath,"DESC.SDI",NULL));
274: fexistcase(tmp);
275: }
276: if((file=nopen(tmp,O_RDONLY|O_BINARY))!=-1) {
277: memset(ext,0,513);
278: read(file,ext,512);
279: for(i=512;i;i--)
280: if(ext[i-1]>' ')
281: break;
282: ext[i]=0;
283: if(mode&ASCII_ONLY)
284: strip_exascii(ext);
285: if(!(mode&KEEP_DESC)) {
286: sprintf(tmpext,"%.256s",ext);
287: prep_desc(tmpext);
288: for(i=0;tmpext[i];i++)
289: if(isalpha(tmpext[i]))
290: break;
291: sprintf(f.desc,"%.*s",LEN_FDESC,tmpext+i);
292: for(i=0;f.desc[i]>=' ' && i<LEN_FDESC;i++)
293: ;
294: f.desc[i]=0; }
295: close(file);
296: f.misc|=FM_EXTDESC;
297: }
298: }
299: }
300:
301: f.dateuled=time(NULL);
302: f.altpath=cur_altpath;
303: prep_desc(f.desc);
304: if(mode&ASCII_ONLY)
305: strip_exascii(f.desc);
306: if(exist) {
307: putfiledat(&scfg,&f);
308: if(!(mode&NO_NEWDATE))
309: update_uldate(&scfg, &f);
310: }
311: else
312: addfiledat(&scfg,&f);
313: if(f.misc&FM_EXTDESC) {
314: truncsp(ext);
315: putextdesc(&scfg,f.dir,f.datoffset,ext);
316: }
317: if(mode&UL_STATS)
318: updatestats(f.cdt);
319: files++;
320: }
321: if(dir!=NULL)
322: closedir(dir);
323: return;
324: }
325:
326:
327: strcpy(listpath,inpath);
328: fexistcase(listpath);
329: if((stream=fopen(listpath,"r"))==NULL) {
330: fprintf(stderr,"Error %d (%s) opening %s\n"
331: ,errno,strerror(errno),listpath);
332: sprintf(listpath,"%s%s",cur_altpath ? scfg.altpath[cur_altpath-1]
333: : scfg.dir[f.dir]->path,inpath);
334: fexistcase(listpath);
335: if((stream=fopen(listpath,"r"))==NULL) {
336: printf("Can't open: %s\n"
337: " or: %s\n",inpath,listpath);
338: return;
339: }
340: }
341:
342: printf("Adding %s to %s %s\n\n"
343: ,listpath,scfg.lib[scfg.dir[f.dir]->lib]->sname,scfg.dir[f.dir]->sname);
344:
345: fgets(nextline,255,stream);
346: while(!feof(stream) && !ferror(stream)) {
347: f.misc=0;
348: f.desc[0]=0;
349: strcpy(curline,nextline);
350: nextline[0]=0;
351: fgets(nextline,255,stream);
352: truncsp(curline);
353: if(curline[0]<=' ' || (mode&ASCII_ONLY && (uchar)curline[0]>=0x7e))
354: continue;
355: printf("%s\n",curline);
356: strcpy(fname,curline);
357:
358: p=strchr(fname,'.');
359: if(!p || p==fname || p>fname+8) /* no dot or invalid dot location */
360: continue;
361: p=strchr(p,' ');
362: if(p) *p=0;
363: else /* no space after filename? */
364: continue;
365: #if 0
366: strupr(fname);
367: #endif
368: strcpy(fname,unpadfname(fname,tmp));
369:
370: padfname(fname,f.name);
371: if(strcspn(f.name,"\\/|<>+[]:=\";,")!=strlen(f.name))
372: continue;
373:
374: for(i=0;i<12;i++)
375: if(f.name[i]<' ' || (mode&ASCII_ONLY && (uchar)f.name[i]>0x7e))
376: break;
377:
378: if(i<12) /* Ctrl chars or EX-ASCII in filename? */
379: continue;
380: exist=findfile(&scfg,f.dir,f.name);
381: if(exist) {
382: if(mode&NO_UPDATE)
383: continue;
384: getfileixb(&scfg,&f);
385: if(mode&ULDATE_ONLY) {
386: f.dateuled=time(NULL);
387: update_uldate(&scfg, &f);
388: continue;
389: }
390: }
391:
392: sprintf(filepath,"%s%s",cur_altpath ? scfg.altpath[cur_altpath-1]
393: : scfg.dir[f.dir]->path,fname);
394:
395: if(mode&FILE_DATE) { /* get the file date and put into desc */
396: l=fdate(filepath);
397: unixtodstr(&scfg,l,f.desc);
398: strcat(f.desc," ");
399: }
400:
401: if(mode&TODAYS_DATE) { /* put today's date in desc */
402: l=time(NULL);
403: unixtodstr(&scfg,l,f.desc);
404: strcat(f.desc," ");
405: }
406:
407: if(dskip && strlen(curline)>=dskip) p=curline+dskip;
408: else {
409: p++;
410: while(*p==' ') p++;
411: }
412: SAFECOPY(tmp,p);
413: prep_desc(tmp);
414: sprintf(f.desc+strlen(f.desc),"%.*s",(int)(LEN_FDESC-strlen(f.desc)),tmp);
415:
416: if(nextline[0]==' ' || strlen(p)>LEN_FDESC) { /* ext desc */
417: if(!(mode&NO_EXTEND)) {
418: memset(ext,0,513);
419: f.misc|=FM_EXTDESC;
420: sprintf(ext,"%s\r\n",p);
421: }
422:
423: if(nextline[0]==' ') {
424: strcpy(str,nextline); /* tack on to end of desc */
425: p=str+dskip;
426: while(*p && *p<=' ') p++;
427: i=LEN_FDESC-strlen(f.desc);
428: if(i>1) {
429: p[i-1]=0;
430: truncsp(p);
431: if(p[0]) {
432: strcat(f.desc," ");
433: strcat(f.desc,p);
434: }
435: }
436: }
437:
438: while(!feof(stream) && !ferror(stream) && strlen(ext)<512) {
439: if(nextline[0]!=' ')
440: break;
441: truncsp(nextline);
442: printf("%s\n",nextline);
443: if(!(mode&NO_EXTEND)) {
444: f.misc|=FM_EXTDESC;
445: p=nextline+dskip;
446: while(*p==' ') p++;
447: strcat(ext,p);
448: strcat(ext,"\r\n");
449: }
450: nextline[0]=0;
451: fgets(nextline,255,stream);
452: }
453: }
454:
455:
456: if(sskip) l=atol(fname+sskip);
457: else {
458: l=flength(filepath);
459: if(l<1L) {
460: printf("%s not found.\n",filepath);
461: continue;
462: }
463: }
464:
465: if(mode&FILE_ID) {
466: for(i=0;i<scfg.total_fextrs;i++)
467: if(!stricmp(scfg.fextr[i]->ext,f.name+9) && chk_ar(&scfg,scfg.fextr[i]->ar,NULL))
468: break;
469: if(i<scfg.total_fextrs) {
470: sprintf(tmp,"%sFILE_ID.DIZ",scfg.temp_dir);
471: remove(tmp);
472: system(mycmdstr(scfg.fextr[i]->cmd,filepath,"FILE_ID.DIZ",NULL));
473: if(!fexistcase(tmp)) {
474: sprintf(tmp,"%sDESC.SDI",scfg.temp_dir);
475: remove(tmp);
476: system(mycmdstr(scfg.fextr[i]->cmd,filepath,"DESC.SDI",NULL));
477: fexistcase(tmp);
478: }
479: if((file=nopen(tmp,O_RDONLY|O_BINARY))!=-1) {
480: memset(ext,0,513);
481: read(file,ext,512);
482: for(i=512;i;i--)
483: if(ext[i-1]>' ')
484: break;
485: ext[i]=0;
486: if(mode&ASCII_ONLY)
487: strip_exascii(ext);
488: if(!(mode&KEEP_DESC)) {
489: sprintf(tmpext,"%.256s",ext);
490: prep_desc(tmpext);
491: for(i=0;tmpext[i];i++)
492: if(isalpha(tmpext[i]))
493: break;
494: sprintf(f.desc,"%.*s",LEN_FDESC,tmpext+i);
495: for(i=0;f.desc[i]>=' ' && i<LEN_FDESC;i++)
496: ;
497: f.desc[i]=0;
498: }
499: close(file);
500: f.misc|=FM_EXTDESC;
501: }
502: }
503: }
504:
505: f.cdt=l;
506: f.dateuled=time(NULL);
507: f.altpath=cur_altpath;
508: prep_desc(f.desc);
509: if(mode&ASCII_ONLY)
510: strip_exascii(f.desc);
511: if(exist) {
512: putfiledat(&scfg,&f);
513: if(!(mode&NO_NEWDATE))
514: update_uldate(&scfg, &f);
515: }
516: else
517: addfiledat(&scfg,&f);
518: if(f.misc&FM_EXTDESC) {
519: truncsp(ext);
520: putextdesc(&scfg,f.dir,f.datoffset,ext);
521: }
522:
523: if(mode&UL_STATS)
524: updatestats(l);
525: files++;
526: }
527: fclose(stream);
528: if(mode&DEL_LIST && !(mode&SYNC_LIST)) {
529: printf("\nDeleting %s\n",listpath);
530: remove(listpath);
531: }
532:
533: }
534:
535: void synclist(char *inpath, int dirnum)
536: {
537: uchar str[1024];
538: char fname[MAX_PATH+1];
539: char listpath[MAX_PATH+1];
540: uchar* ixbbuf;
541: uchar* p;
542: int i,file,found;
543: long l,m,length;
544: FILE* stream;
545: file_t f;
546:
547: sprintf(str,"%s%s.ixb",scfg.dir[dirnum]->data_dir,scfg.dir[dirnum]->code);
548: if((file=nopen(str,O_RDONLY|O_BINARY))==-1) {
549: printf("ERR_OPEN %s\n",str);
550: return;
551: }
552: length=filelength(file);
553: if(length%F_IXBSIZE) {
554: close(file);
555: printf("ERR_LEN (%ld) of %s\n",length,str);
556: return;
557: }
558: if((ixbbuf=(uchar HUGE16 *)MALLOC(length))==NULL) {
559: close(file);
560: printf("ERR_ALLOC %s\n",str);
561: return;
562: }
563: if(lread(file,ixbbuf,length)!=length) {
564: close(file);
565: FREE((char *)ixbbuf);
566: printf("ERR_READ %s\n",str);
567: return;
568: }
569: close(file);
570:
571: strcpy(listpath,inpath);
572: if((stream=fopen(listpath,"r"))==NULL) {
573: sprintf(listpath,"%s%s",cur_altpath ? scfg.altpath[cur_altpath-1]
574: : scfg.dir[dirnum]->path,inpath);
575: if((stream=fopen(listpath,"r"))==NULL) {
576: printf("Can't open: %s\n"
577: " or: %s\n",inpath,listpath);
578: return;
579: }
580: }
581:
582: printf("\nSynchronizing %s with %s %s\n\n"
583: ,listpath,scfg.lib[scfg.dir[dirnum]->lib]->sname,scfg.dir[dirnum]->sname);
584:
585: for(l=0;l<length;l+=F_IXBSIZE) {
586: m=l;
587: for(i=0;i<12 && l<length;i++)
588: if(i==8)
589: str[i]=ixbbuf[m]>' ' ? '.' : ' ';
590: else
591: str[i]=ixbbuf[m++]; /* Turns FILENAMEEXT into FILENAME.EXT */
592: str[i]=0;
593: unpadfname(str,fname);
594: rewind(stream);
595: found=0;
596: while(!found) {
597: if(!fgets(str,1000,stream))
598: break;
599: truncsp(str);
600: p=strchr(str,' ');
601: if(p) *p=0;
602: if(!stricmp(str,fname))
603: found=1;
604: }
605: if(found)
606: continue;
607: padfname(fname,f.name);
608: printf("%s not found in list - ",f.name);
609: f.dir=dirnum;
610: f.datoffset=ixbbuf[m]|((long)ixbbuf[m+1]<<8)|((long)ixbbuf[m+2]<<16);
611: getfiledat(&scfg,&f);
612: if(f.opencount) {
613: printf("currently OPEN by %u users\n",f.opencount);
614: continue;
615: }
616: removefiledat(&scfg,&f);
617: if(remove(getfilepath(&scfg,&f,str)))
618: printf("Error removing %s\n",str);
619: removed++;
620: printf("Removed from database\n");
621: }
622:
623: if(mode&DEL_LIST) {
624: printf("\nDeleting %s\n",listpath);
625: remove(listpath);
626: }
627: }
628:
629: char *usage="\nusage: addfiles code [.alt_path] [-opts] [\"*user\"] +list "
630: "[desc_off] [size_off]"
631: "\n or: addfiles code [.alt_path] [-opts] [\"*user\"] file "
632: "\"description\"\n"
633: "\navailable opts:"
634: "\n a import ASCII only (no extended ASCII)"
635: "\n b synchronize database with file list (use with caution)"
636: "\n c do not remove extra spaces from file description"
637: "\n d delete list after import"
638: "\n e do not import extended descriptions"
639: "\n f include file date in descriptions"
640: "\n t include today's date in descriptions"
641: "\n i include added files in upload statistics"
642: "\n n do not update information for existing files"
643: "\n o update upload date only for existing files"
644: "\n u do not update upload date for existing files"
645: "\n z check for and import FILE_ID.DIZ and DESC.SDI"
646: "\n k keep original short description (not DIZ)"
647: "\n s search directory for files (no file list)"
648: "\n l specify library (short name) to Auto-ADD"
649: "\n"
650: "\nAuto-ADD: use * in place of code for Auto-ADD of FILES.BBS"
651: "\n use *filename to Auto-ADD a different filename"
652: "\n use -l \"libname\" to only Auto-ADD files to a specific library"
653: "\n"
654: ;
655:
656: /*********************/
657: /* Entry point (duh) */
658: /*********************/
659: int main(int argc, char **argv)
660: {
661: char error[512];
662: char revision[16];
663: char str[MAX_PATH+1];
664: char tmp[MAX_PATH+1];
665: uchar *p,exist,listgiven=0,namegiven=0,ext[513]
666: ,auto_name[MAX_PATH+1]="FILES.BBS";
667: int i,j,file;
668: uint desc_offset=0, size_offset=0;
669: long l;
670: file_t f;
671:
672: sscanf("$Revision: 1.35 $", "%*s %s", revision);
673:
674: fprintf(stderr,"\nADDFILES v%s-%s (rev %s) - Adds Files to Synchronet "
675: "Filebase\n"
676: ,ADDFILES_VER
677: ,PLATFORM_DESC
678: ,revision
679: );
680:
681: if(argc<2) {
682: printf(usage);
683: return(1);
684: }
685:
686: p=getenv("SBBSCTRL");
687: if(p==NULL) {
688: printf("\nSBBSCTRL environment variable not set.\n");
689: printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
690: exit(1);
691: }
692:
693: memset(&scfg,0,sizeof(scfg));
694: scfg.size=sizeof(scfg);
695: SAFECOPY(scfg.ctrl_dir,p);
696:
697: if(chdir(scfg.ctrl_dir)!=0)
698: fprintf(stderr,"!ERROR changing directory to: %s", scfg.ctrl_dir);
699:
700: printf("\nLoading configuration files from %s\n",scfg.ctrl_dir);
701: if(!load_cfg(&scfg,NULL,TRUE,error)) {
702: fprintf(stderr,"!ERROR loading configuration files: %s\n",error);
703: exit(1);
704: }
705: prep_dir(scfg.data_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
706:
707: if(!(scfg.sys_misc&SM_LOCAL_TZ))
708: putenv("TZ=UTC0");
709:
710: if(argv[1][0]=='*') {
711: if(argv[1][1])
712: SAFECOPY(auto_name,argv[1]+1);
713: mode|=AUTO_ADD;
714: i=0;
715: } else {
716: if(!isalnum(argv[1][0]) && argc==2) {
717: printf(usage);
718: return(1);
719: }
720:
721: for(i=0;i<scfg.total_dirs;i++)
722: if(!stricmp(scfg.dir[i]->code,argv[1]))
723: break;
724:
725: if(i>=scfg.total_dirs) {
726: printf("Directory code '%s' not found.\n",argv[1]);
727: exit(1);
728: }
729: }
730:
731: memset(&f,0,sizeof(file_t));
732: f.dir=i;
733: strcpy(f.uler,"-> ADDFILES <-");
734:
735: for(j=2;j<argc;j++) {
736: if(argv[j][0]=='*') /* set the uploader name */
737: sprintf(f.uler,"%.25s",argv[j]+1);
738: else
739: if(argv[j][0]=='-'
740: || argv[j][0]=='/'
741: ) { /* options */
742: for(i=1;argv[j][i];i++)
743: switch(toupper(argv[j][i])) {
744: case 'A':
745: mode|=ASCII_ONLY;
746: break;
747: case 'B':
748: mode|=(SYNC_LIST|NO_UPDATE);
749: break;
750: case 'C':
751: mode|=KEEP_SPACE;
752: break;
753: case 'D':
754: mode|=DEL_LIST;
755: break;
756: case 'E':
757: mode|=NO_EXTEND;
758: break;
759: case 'I':
760: mode|=UL_STATS;
761: break;
762: case 'L':
763: j++;
764: if(argv[j]==NULL) {
765: printf(usage);
766: return(-1);
767: }
768: SAFECOPY(lib,argv[j]);
769: i=strlen(argv[j])-1;
770: break;
771: case 'Z':
772: mode|=FILE_ID;
773: break;
774: case 'K':
775: mode|=KEEP_DESC; /* Don't use DIZ for short desc */
776: break;
777: case 'N':
778: mode|=NO_UPDATE;
779: break;
780: case 'O':
781: mode|=ULDATE_ONLY;
782: break;
783: case 'U':
784: mode|=NO_NEWDATE;
785: break;
786: case 'F':
787: mode|=FILE_DATE;
788: break;
789: case 'T':
790: mode|=TODAYS_DATE;
791: break;
792: case 'S':
793: mode|=SEARCH_DIR;
794: break;
795: default:
796: printf(usage);
797: return(1);
798: }
799: }
800: else if(isdigit(argv[j][0])) {
801: if(desc_offset==0)
802: desc_offset=atoi(argv[j]);
803: else
804: size_offset=atoi(argv[j]);
805: continue;
806: }
807: else if(argv[j][0]=='+') { /* filelist - FILES.BBS */
808: listgiven=1;
809: if(argc > j+1
810: && isdigit(argv[j+1][0])) { /* skip x characters before description */
811: if(argc > j+2
812: && isdigit(argv[j+2][0])) { /* skip x characters before size */
813: addlist(argv[j]+1,f,atoi(argv[j+1]),atoi(argv[j+2]));
814: j+=2;
815: }
816: else {
817: addlist(argv[j]+1,f,atoi(argv[j+1]),0);
818: j++;
819: }
820: }
821: else
822: addlist(argv[j]+1,f,0,0);
823: if(mode&SYNC_LIST)
824: synclist(argv[j]+1,f.dir);
825: }
826: else if(argv[j][0]=='.') { /* alternate file path */
827: cur_altpath=atoi(argv[j]+1);
828: if(cur_altpath>scfg.altpaths) {
829: printf("Invalid alternate path.\n");
830: exit(1);
831: }
832: }
833: else {
834: namegiven=1;
835: padfname(argv[j],f.name);
836: f.desc[0]=0;
837: #if 0
838: strupr(f.name);
839: #endif
840: if(j+1==argc) {
841: printf("%s no description given.\n",f.name);
842: continue;
843: }
844: sprintf(str,"%s%s",cur_altpath ? scfg.altpath[cur_altpath-1]
845: : scfg.dir[f.dir]->path,argv[j]);
846: if(mode&FILE_DATE)
847: sprintf(f.desc,"%s ",unixtodstr(&scfg,fdate(str),tmp));
848: if(mode&TODAYS_DATE)
849: sprintf(f.desc,"%s ",unixtodstr(&scfg,time(NULL),tmp));
850: sprintf(tmp,"%.*s",(int)(LEN_FDESC-strlen(f.desc)),argv[++j]);
851: strcpy(f.desc,tmp);
852: l=flength(str);
853: if(l==-1) {
854: printf("%s not found.\n",str);
855: continue;
856: }
857: exist=findfile(&scfg,f.dir,f.name);
858: if(exist) {
859: if(mode&NO_UPDATE)
860: continue;
861: getfileixb(&scfg,&f);
862: if(mode&ULDATE_ONLY) {
863: f.dateuled=time(NULL);
864: update_uldate(&scfg, &f);
865: continue;
866: }
867: }
868: f.cdt=l;
869: f.dateuled=time(NULL);
870: f.altpath=cur_altpath;
871: prep_desc(f.desc);
872: if(mode&ASCII_ONLY)
873: strip_exascii(f.desc);
874: printf("%s %7lu %s\n",f.name,f.cdt,f.desc);
875: if(mode&FILE_ID) {
876: for(i=0;i<scfg.total_fextrs;i++)
877: if(!stricmp(scfg.fextr[i]->ext,f.name+9) && chk_ar(&scfg,scfg.fextr[i]->ar,NULL))
878: break;
879: if(i<scfg.total_fextrs) {
880: sprintf(tmp,"%sFILE_ID.DIZ",scfg.temp_dir);
881: remove(tmp);
882: system(mycmdstr(scfg.fextr[i]->cmd,str,"FILE_ID.DIZ",NULL));
883: if(!fexistcase(tmp)) {
884: sprintf(tmp,"%sDESC.SDI",scfg.temp_dir);
885: remove(tmp);
886: system(mycmdstr(scfg.fextr[i]->cmd,str,"DESC.SDI",NULL));
887: fexistcase(tmp);
888: }
889: if((file=nopen(tmp,O_RDONLY|O_BINARY))!=-1) {
890: memset(ext,0,513);
891: read(file,ext,512);
892: if(!(mode&KEEP_DESC)) {
893: sprintf(f.desc,"%.*s",LEN_FDESC,ext);
894: for(i=0;f.desc[i]>=' ' && i<LEN_FDESC;i++)
895: ;
896: f.desc[i]=0;
897: }
898: close(file);
899: f.misc|=FM_EXTDESC;
900: }
901: }
902: }
903: if(exist) {
904: putfiledat(&scfg,&f);
905: if(!(mode&NO_NEWDATE))
906: update_uldate(&scfg, &f);
907: }
908: else
909: addfiledat(&scfg,&f);
910:
911: if(f.misc&FM_EXTDESC)
912: putextdesc(&scfg,f.dir,f.datoffset,ext);
913:
914: if(mode&UL_STATS)
915: updatestats(l);
916: files++;
917: }
918: }
919:
920: if(mode&AUTO_ADD) {
921: for(i=0;i<scfg.total_dirs;i++) {
922: if(lib[0] && stricmp(scfg.lib[scfg.dir[i]->lib]->sname,lib))
923: continue;
924: if(scfg.dir[i]->misc&DIR_NOAUTO)
925: continue;
926: f.dir=i;
927: if(mode&SEARCH_DIR) {
928: addlist("",f,desc_offset,size_offset);
929: continue;
930: }
931: sprintf(str,"%s%s.lst",scfg.dir[f.dir]->path,scfg.dir[f.dir]->code);
932: if(fexistcase(str) && flength(str)>0L) {
933: printf("Auto-adding %s\n",str);
934: addlist(str,f,desc_offset,size_offset);
935: if(mode&SYNC_LIST)
936: synclist(str,i);
937: continue;
938: }
939: sprintf(str,"%s%s",scfg.dir[f.dir]->path,auto_name);
940: if(fexistcase(str) && flength(str)>0L) {
941: printf("Auto-adding %s\n",str);
942: addlist(str,f,desc_offset,size_offset);
943: if(mode&SYNC_LIST)
944: synclist(str,i);
945: continue;
946: }
947: }
948: }
949:
950: else {
951: if(!listgiven && !namegiven) {
952: sprintf(str,"%s%s.lst",scfg.dir[f.dir]->path, scfg.dir[f.dir]->code);
953: if(!fexistcase(str) || flength(str)<=0L)
954: sprintf(str,"%s%s",scfg.dir[f.dir]->path, auto_name);
955: addlist(str,f,desc_offset,size_offset);
956: if(mode&SYNC_LIST)
957: synclist(str,f.dir);
958: }
959: }
960:
961: printf("\n%lu file(s) added.",files);
962: if(removed)
963: printf("\n%lu files(s) removed.",removed);
964: printf("\n");
965: return(0);
966: }
967:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.