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

Commit a4c3f383 authored by rswindell's avatar rswindell

Added -F (capital 'F') option to specify the format of the date/time stamp

to put in the description (in strftime() format). Can also be used in
combination with '-t' if you want today's date/time instead.
It's not very clear from the help/usage output, but if you specify both -f
(or -F) and -t, you'll *only* get today's date in the description (not both
the file date and today's date).
parent 2152d557
......@@ -45,6 +45,7 @@ int cur_altpath=0;
long files=0,removed=0,mode=0;
char lib[LEN_GSNAME+1];
const char* datefmt = NULL;
#define DEL_LIST (1L<<0)
#define NO_EXTEND (1L<<1)
......@@ -120,49 +121,49 @@ char *mycmdstr(const char *instr, const char *fpath, const char *fspec, char *ou
cmd[j]=0;
switch(toupper(instr[i])) {
case 'F': /* File path */
strcat(cmd,fpath);
SAFECAT(cmd,fpath);
break;
case '~': /* DOS-compatible (8.3) filename */
#ifdef _WIN32
SAFECOPY(sfpath,fpath);
GetShortPathName(fpath,sfpath,sizeof(sfpath));
strcat(cmd,sfpath);
SAFECAT(cmd,sfpath);
#else
strcat(cmd,fpath);
SAFECAT(cmd,fpath);
#endif
break;
case 'G': /* Temp directory */
strcat(cmd,scfg.temp_dir);
SAFECAT(cmd,scfg.temp_dir);
break;
case 'J':
strcat(cmd,scfg.data_dir);
SAFECAT(cmd,scfg.data_dir);
break;
case 'K':
strcat(cmd,scfg.ctrl_dir);
SAFECAT(cmd,scfg.ctrl_dir);
break;
case 'N': /* Node Directory (same as SBBSNODE environment var) */
strcat(cmd,scfg.node_dir);
SAFECAT(cmd,scfg.node_dir);
break;
case 'S': /* File Spec */
strcat(cmd,fspec);
SAFECAT(cmd,fspec);
break;
case 'Z':
strcat(cmd,scfg.text_dir);
SAFECAT(cmd,scfg.text_dir);
break;
case '!': /* EXEC Directory */
strcat(cmd,scfg.exec_dir);
SAFECAT(cmd,scfg.exec_dir);
break;
case '@': /* EXEC Directory for DOS/OS2/Win32, blank for Unix */
#ifndef __unix__
strcat(cmd,scfg.exec_dir);
SAFECAT(cmd,scfg.exec_dir);
#endif
break;
case '#': /* Node number (same as SBBSNNUM environment var) */
sprintf(str,"%d",scfg.node_num);
strcat(cmd,str);
SAFECAT(cmd,str);
break;
case '%': /* %% for percent sign */
strcat(cmd,"%");
SAFECAT(cmd,"%");
break;
default: /* unknown specification */
break;
......@@ -318,14 +319,24 @@ void addlist(char *inpath, file_t f, uint dskip, uint sskip)
getextdesc(&scfg, f.dir, f.datoffset, ext);
}
if(mode&FILE_DATE) { /* get the file date and put into desc */
unixtodstr(&scfg,(time32_t)file_timestamp,f.desc);
strcat(f.desc," ");
}
if(mode&TODAYS_DATE) { /* put today's date in desc */
unixtodstr(&scfg,time32(NULL),f.desc);
strcat(f.desc," ");
time_t now = time(NULL);
if(datefmt) {
struct tm tm = {0};
localtime_r(&now, &tm);
strftime(f.desc, sizeof(f.desc), datefmt, &tm);
} else
unixtodstr(&scfg, (time32_t)now, f.desc);
SAFECAT(f.desc," ");
}
else if(mode&FILE_DATE) { /* get the file date and put into desc */
if(datefmt) {
struct tm tm = {0};
localtime_r(&file_timestamp, &tm);
strftime(f.desc, sizeof(f.desc), datefmt, &tm);
} else
unixtodstr(&scfg,(time32_t)file_timestamp,f.desc);
SAFECAT(f.desc," ");
}
if(mode&FILE_ID)
......@@ -443,15 +454,24 @@ void addlist(char *inpath, file_t f, uint dskip, uint sskip)
getextdesc(&scfg, f.dir, f.datoffset, ext);
}
if(mode&FILE_DATE) { /* get the file date and put into desc */
unixtodstr(&scfg,(time32_t)file_timestamp,f.desc);
strcat(f.desc," ");
}
if(mode&TODAYS_DATE) { /* put today's date in desc */
l=time32(NULL);
unixtodstr(&scfg,l,f.desc);
strcat(f.desc," ");
time_t now = time(NULL);
if(datefmt) {
struct tm tm = {0};
localtime_r(&now, &tm);
strftime(f.desc, sizeof(f.desc), datefmt, &tm);
} else
unixtodstr(&scfg, (time32_t)now, f.desc);
SAFECAT(f.desc," ");
}
else if(mode&FILE_DATE) { /* get the file date and put into desc */
if(datefmt) {
struct tm tm = {0};
localtime_r(&file_timestamp, &tm);
strftime(f.desc, sizeof(f.desc), datefmt, &tm);
} else
unixtodstr(&scfg,(time32_t)file_timestamp,f.desc);
SAFECAT(f.desc," ");
}
if(dskip && strlen(curline)>=dskip) p=curline+dskip;
......@@ -480,8 +500,8 @@ void addlist(char *inpath, file_t f, uint dskip, uint sskip)
p[i-1]=0;
truncsp(p);
if(p[0]) {
strcat(f.desc," ");
strcat(f.desc,p);
SAFECAT(f.desc," ");
SAFECAT(f.desc,p);
}
}
}
......@@ -495,8 +515,8 @@ void addlist(char *inpath, file_t f, uint dskip, uint sskip)
f.misc|=FM_EXTDESC;
p=nextline+dskip;
while(*p==' ') p++;
strcat(ext,p);
strcat(ext,"\r\n");
SAFECAT(ext,p);
SAFECAT(ext,"\r\n");
}
nextline[0]=0;
fgets(nextline,255,stream);
......@@ -656,6 +676,7 @@ char *usage="\nusage: addfiles code [.alt_path] [-opts] +list "
"\n -d delete list after import"
"\n -e do not import extended descriptions"
"\n -f include file date in descriptions"
"\n -F <fmt> include file date in descriptions, using strftime format"
"\n -t include today's date in descriptions"
"\n -i include added files in upload statistics"
"\n -n do not update information for existing files"
......@@ -820,6 +841,16 @@ int main(int argc, char **argv)
break;
case 'F':
mode|=FILE_DATE;
if(argv[j][i] == 'F') {
j++;
if(argv[j]==NULL) {
puts(usage);
return(-1);
}
datefmt = argv[j];
i=strlen(argv[j]) - 1;
break;
}
break;
case 'T':
mode|=TODAYS_DATE;
......@@ -879,12 +910,28 @@ int main(int argc, char **argv)
}
sprintf(str,"%s%s",cur_altpath ? scfg.altpath[cur_altpath-1]
: scfg.dir[f.dir]->path,argv[j]);
if(mode&FILE_DATE)
sprintf(f.desc,"%s ",unixtodstr(&scfg,(time32_t)fdate(str),tmp));
if(mode&TODAYS_DATE)
sprintf(f.desc,"%s ",unixtodstr(&scfg,time32(NULL),tmp));
sprintf(tmp,"%.*s",(int)(LEN_FDESC-strlen(f.desc)),argv[++j]);
SAFECOPY(f.desc,tmp);
if(mode&TODAYS_DATE) {
time_t now = time(NULL);
if(datefmt) {
struct tm tm = {0};
localtime_r(&now, &tm);
strftime(f.desc, sizeof(f.desc), datefmt, &tm);
} else
SAFECOPY(f.desc, unixtodstr(&scfg, (time32_t)now, tmp));
SAFECAT(f.desc, " ");
}
else if(mode&FILE_DATE) {
time_t file_timestamp = fdate(str);
if(datefmt) {
struct tm tm = {0};
localtime_r(&file_timestamp, &tm);
strftime(f.desc, sizeof(f.desc), datefmt, &tm);
} else
SAFECOPY(f.desc, unixtodstr(&scfg,(time32_t)file_timestamp,tmp));
SAFECAT(f.desc, " ");
}
j++;
SAFECAT(f.desc, argv[j]);
l=flength(str);
if(l==-1) {
printf("%s not found.\n",str);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment