diff --git a/scp.c b/scp.c index d90f963c..ba15f052 100644 --- a/scp.c +++ b/scp.c @@ -1651,6 +1651,8 @@ static const char simh_help[] = "++%%~pI%% - expands the value of %%I%% to a path only\n" "++%%~nI%% - expands the value of %%I%% to a file name only\n" "++%%~xI%% - expands the value of %%I%% to a file extension only\n\n" + "++%%~tI%% - expands the value of %%I%% to date/time of file\n\n" + "++%%~zI%% - expands the value of %%I%% to size of file\n\n" " The modifiers can be combined to get compound results:\n\n" "++%%~pnI%% - expands the value of %%I%% to a path and name only\n" "++%%~nxI%% - expands the value of %%I%% to a file name and extension only\n\n" @@ -4210,7 +4212,7 @@ for (; *ip && (op < oend); ) { if (*ip == '~') { expand_it = TRUE; ++ip; - for (i=0; (i < (sizeof (parts) - 1)) && (strchr ("fpnx", *ip)); i++, ip++) { + for (i=0; (i < (sizeof (parts) - 1)) && (strchr ("fpnxtz", *ip)); i++, ip++) { parts[i] = *ip; parts[i + 1] = '\0'; } diff --git a/sim_fio.c b/sim_fio.c index cc43e2c8..97c1c0ca 100644 --- a/sim_fio.c +++ b/sim_fio.c @@ -742,6 +742,8 @@ char *fullpath = NULL, *result = NULL; char *c, *name, *ext; char chr; const char *p; +char filesizebuf[32] = ""; +char filedatetimebuf[32] = ""; if (((*filepath == '\'') || (*filepath == '"')) && (filepath[strlen (filepath) - 1] == *filepath)) { @@ -812,6 +814,20 @@ if (ext == NULL) tot_size = 0; if (*parts == '\0') /* empty part specifier means strip only quotes */ tot_size = strlen (tempfilepath); +if (strchr (parts, 't') || strchr (parts, 'z')) { + struct stat filestat; + struct tm *tm; + + memset (&filestat, 0, sizeof (filestat)); + (void)stat (fullpath, &filestat); + if (sizeof (filestat.st_size) == 4) + sprintf (filesizebuf, "%ld ", filestat.st_size); + else + sprintf (filesizebuf, "%" LL_FMT "d ", (LL_TYPE)filestat.st_size); + tm = localtime (&filestat.st_mtime); + sprintf (filedatetimebuf, "%02d/%02d/%04d %02d:%02d %cM ", 1 + tm->tm_mon, tm->tm_mday, 1900 + tm->tm_year, + tm->tm_hour % 12, tm->tm_min, (0 == (tm->tm_hour % 12)) ? 'A' : 'P'); + } for (p = parts; *p; p++) { switch (*p) { case 'f': @@ -826,6 +842,12 @@ for (p = parts; *p; p++) { case 'x': tot_size += strlen (ext); break; + case 't': + tot_size += strlen (filedatetimebuf); + break; + case 'z': + tot_size += strlen (filesizebuf); + break; } } result = (char *)malloc (1 + tot_size); @@ -852,6 +874,12 @@ for (p = parts; *p; p++) { case 'x': strlcat (result, ext, 1 + tot_size); break; + case 't': + strlcat (result, filedatetimebuf, 1 + tot_size); + break; + case 'z': + strlcat (result, filesizebuf, 1 + tot_size); + break; } } free (fullpath);