SCP: Add MKDIR and RMDIR commands

This commit is contained in:
Mark Pizzolato 2019-07-08 00:38:08 -07:00
parent 85770281fb
commit 461f2ea513
2 changed files with 65 additions and 0 deletions

63
scp.c
View file

@ -1186,6 +1186,14 @@ static const char simh_help[] =
#define HLP_CP "*Commands Copying_Files CP"
"3CP\n"
"++CP sfile dfile copies a file\n"
"2Creating Directories\n"
#define HLP_MKDIR "*Commands Creating_Directories MKDIR"
"3MKDIR\n"
"++MKDIR path creates a directory\n"
"2Deleting Directories\n"
#define HLP_RMDIR "*Commands Deleting_Directories RMDIR"
"3RMDIR\n"
"++RMDIR path deleting a directory\n"
#define HLP_SET "*Commands SET"
"2SET\n"
/***************** 80 character line width template *************************/
@ -2334,6 +2342,8 @@ static CTAB cmd_table[] = {
{ "RM", &delete_cmd, 0, HLP_RM, NULL, NULL },
{ "COPY", &copy_cmd, 0, HLP_COPY, NULL, NULL },
{ "CP", &copy_cmd, 0, HLP_CP, NULL, NULL },
{ "MKDIR", &mkdir_cmd, 0, HLP_MKDIR, NULL, NULL },
{ "RMDIR", &rmdir_cmd, 0, HLP_RMDIR, NULL, NULL },
{ "SET", &set_cmd, 0, HLP_SET, NULL, NULL },
{ "SHOW", &show_cmd, 0, HLP_SHOW, NULL, NULL },
{ "DO", &do_cmd, 1, HLP_DO, NULL, NULL },
@ -6548,6 +6558,59 @@ if ((stat == SCPE_OK) && (copy_state.count))
return copy_state.stat;
}
t_stat mkdir_cmd (int32 flg, CONST char *cptr)
{
char path[CBUFSIZE];
char *c;
struct stat filestat;
if ((!cptr) || (*cptr == '\0'))
return sim_messagef (SCPE_2FARG, "Must specify a directory path\n");
strlcpy (path, cptr, sizeof (path));
while ((c = strchr (path, '\\')))
*c = '/';
c = path;
while ((c = strchr (c, '/'))) {
*c = '\0';
if (!stat (path, &filestat)) {
if (filestat.st_mode & S_IFDIR) {
*c = '/'; /* restore / */
++c;
continue;
}
return sim_messagef (SCPE_ARG, "%s is not a directory\n", path);
}
if (
#if defined(_MSC_VER)
mkdir (path)
#else
mkdir (path, 0777)
#endif
)
return sim_messagef (SCPE_ARG, "Can't create directory: %s - %s\n", path, strerror (errno));
*c = '/'; /* restore / */
++c;
}
if (
#if defined(_MSC_VER)
mkdir (path)
#else
mkdir (path, 0777)
#endif
)
return sim_messagef (SCPE_ARG, "Can't create directory: %s - %s\n", path, strerror (errno));
return SCPE_OK;
}
t_stat rmdir_cmd (int32 flg, CONST char *cptr)
{
if ((!cptr) || (*cptr == '\0'))
return sim_messagef (SCPE_2FARG, "Must specify a directory\n");
if (rmdir (cptr))
return sim_messagef (SCPE_ARG, "Can't remove directory: %s - %s\n", cptr, strerror (errno));
return SCPE_OK;
}
/* Debug command */
t_stat debug_cmd (int32 flg, CONST char *cptr)

2
scp.h
View file

@ -95,6 +95,8 @@ t_stat dir_cmd (int32 flg, CONST char *cptr);
t_stat type_cmd (int32 flg, CONST char *cptr);
t_stat delete_cmd (int32 flg, CONST char *cptr);
t_stat copy_cmd (int32 flg, CONST char *cptr);
t_stat mkdir_cmd (int32 flg, CONST char *cptr);
t_stat rmdir_cmd (int32 flg, CONST char *cptr);
t_stat brk_cmd (int32 flag, CONST char *ptr);
t_stat do_cmd (int32 flag, CONST char *ptr);
t_stat goto_cmd (int32 flag, CONST char *ptr);