Commit 8a3d8d2c authored by rswindell's avatar rswindell
Browse files

New @-codes (for The Millionaire):

- FILESIZE - total file size in an auto-rounded value with suffix (B/K/M/G)
- FILEBYTES - total file size in bytes
- FILEKB - total file size in kibibytes
- FILEMB - total file size in mebibytes
- FILEGB - total file size in gibibytes

All of the above default to the current file transfer directory path from where
to find / calculate the sizes of files. Only files that exist in the actual
storage directory are counted (offline files or file in alt. file paths are not
counted).

All of the above support 2 alternate syntaxes:

FILE*:<dir-code> where <dir-code> is the internal code of a file directory, or
FILE*:<path[/file-spec]> where <path> is a directory path and [/file-spec] is
an optinal file name/specification (i.e. w/wildcards).
parent e7c6c5cb
......@@ -143,6 +143,15 @@ int sbbs_t::show_atcode(const char *instr)
return(len);
}
static const char* getpath(scfg_t* cfg, const char* path)
{
for(int i = 0; i < cfg->total_dirs; i++) {
if(stricmp(cfg->dir[i]->code, path) == 0)
return cfg->dir[i]->path;
}
return path;
}
const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode)
{
char* tp = NULL;
......@@ -439,13 +448,9 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode)
}
if(strncmp(sp, "FILES:", 6) == 0) { // Number of files in specified directory
for(i = 0; i < cfg.total_dirs; i++) {
if(stricmp(cfg.dir[i]->code, sp + 6) == 0) {
safe_snprintf(str, maxlen, "%lu", (ulong)getfiles(&cfg, i));
return str;
}
}
return nulstr;
const char* path = getpath(&cfg, sp + 6);
safe_snprintf(str, maxlen, "%lu", getfilecount(path, ALLFILES));
return str;
}
if(strcmp(sp, "FILES") == 0) { // Number of files in current directory
......@@ -453,6 +458,66 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode)
return str;
}
if(strncmp(sp, "FILESIZE:", 9) == 0) {
const char* path = getpath(&cfg, sp + 9);
byte_estimate_to_str(getfilesizetotal(path), str, maxlen, /* unit: */1, /* precision: */1);
return str;
}
if(strcmp(sp, "FILESIZE") == 0) {
byte_estimate_to_str(getfilesizetotal(cfg.dir[usrdir[curlib][curdir[curlib]]]->path)
,str, maxlen, /* unit: */1, /* precision: */1);
return str;
}
if(strncmp(sp, "FILEBYTES:", 10) == 0) { // Number of bytes in current file directory
const char* path = getpath(&cfg, sp + 10);
safe_snprintf(str, maxlen, "%" PRIu64, getfilesizetotal(path));
return str;
}
if(strcmp(sp, "FILEBYTES") == 0) { // Number of bytes in current file directory
safe_snprintf(str, maxlen, "%" PRIu64
,getfilesizetotal(cfg.dir[usrdir[curlib][curdir[curlib]]]->path));
return str;
}
if(strncmp(sp, "FILEKB:", 7) == 0) { // Number of kibibytes in current file directory
const char* path = getpath(&cfg, sp + 7);
safe_snprintf(str, maxlen, "%1.1f", getfilesizetotal(path) / 1024.0);
return str;
}
if(strcmp(sp, "FILEKB") == 0) { // Number of kibibytes in current file directory
safe_snprintf(str, maxlen, "%1.1f"
,getfilesizetotal(cfg.dir[usrdir[curlib][curdir[curlib]]]->path) / 1024.0);
return str;
}
if(strncmp(sp, "FILEMB:", 7) == 0) { // Number of mebibytes in current file directory
const char* path = getpath(&cfg, sp + 7);
safe_snprintf(str, maxlen, "%1.1f", getfilesizetotal(path) / (1024.0 * 1024.0));
return str;
}
if(strcmp(sp, "FILEMB") == 0) { // Number of mebibytes in current file directory
safe_snprintf(str, maxlen, "%1.1f"
,getfilesizetotal(cfg.dir[usrdir[curlib][curdir[curlib]]]->path) / (1024.0 * 1024.0));
return str;
}
if(strncmp(sp, "FILEGB:", 7) == 0) { // Number of gibibytes in current file directory
const char* path = getpath(&cfg, sp + 7);
safe_snprintf(str, maxlen, "%1.1f", getfilesizetotal(path) / (1024.0 * 1024.0 * 1024.0));
return str;
}
if(strcmp(sp, "FILEGB") == 0) { // Number of gibibytes in current file directory
safe_snprintf(str, maxlen, "%1.1f"
,getfilesizetotal(cfg.dir[usrdir[curlib][curdir[curlib]]]->path) / (1024.0 * 1024.0 * 1024.0));
return str;
}
if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
getstats(&cfg,0,&stats);
safe_snprintf(str,maxlen,"%lu", (ulong)stats.logons);
......
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