SCP: Extend TYPE/CAT command to support offset and line count limit
This commit is contained in:
parent
80abfe0412
commit
6748a2c66f
1 changed files with 48 additions and 2 deletions
50
scp.c
50
scp.c
|
@ -1235,9 +1235,21 @@ static const char simh_help1[] =
|
||||||
#define HLP_TYPE "*Commands Displaying_Files TYPE"
|
#define HLP_TYPE "*Commands Displaying_Files TYPE"
|
||||||
"3TYPE\n"
|
"3TYPE\n"
|
||||||
"++TYPE file display a file contents\n"
|
"++TYPE file display a file contents\n"
|
||||||
|
"4Switches\n"
|
||||||
|
" The -O switch start displaying file contents at the specified\n"
|
||||||
|
" file offset.\n\n"
|
||||||
|
" The -N switch will display up to a specified number of lines\n"
|
||||||
|
" from the file.\n\n"
|
||||||
|
"++TYPE -{O}{N} {offset} {lines} file\n\n"
|
||||||
#define HLP_CAT "*Commands Displaying_Files CAT"
|
#define HLP_CAT "*Commands Displaying_Files CAT"
|
||||||
"3CAT\n"
|
"3CAT\n"
|
||||||
"++CAT file display a file contents\n"
|
"++CAT file display a file contents\n"
|
||||||
|
"4Switches\n"
|
||||||
|
" The -O switch start displaying file contents at the specified\n"
|
||||||
|
" file offset.\n\n"
|
||||||
|
" The -N switch will display up to a specified number of lines\n"
|
||||||
|
" from the file.\n\n"
|
||||||
|
"++TYPE -{O}{N} {offset} {lines} file\n\n"
|
||||||
"2Removing Files\n"
|
"2Removing Files\n"
|
||||||
#define HLP_DELETE "*Commands Removing_Files DEL"
|
#define HLP_DELETE "*Commands Removing_Files DEL"
|
||||||
"3DELETE\n"
|
"3DELETE\n"
|
||||||
|
@ -6877,6 +6889,8 @@ if (r != SCPE_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long sim_type_file_offset;
|
||||||
|
static long sim_type_line_count;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
t_stat stat;
|
t_stat stat;
|
||||||
|
@ -6890,6 +6904,7 @@ static void sim_type_entry (const char *directory,
|
||||||
{
|
{
|
||||||
char FullPath[PATH_MAX + 1];
|
char FullPath[PATH_MAX + 1];
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
long lines = 0;
|
||||||
char lbuf[4*CBUFSIZE];
|
char lbuf[4*CBUFSIZE];
|
||||||
|
|
||||||
sprintf (FullPath, "%s%s", directory, filename);
|
sprintf (FullPath, "%s%s", directory, filename);
|
||||||
|
@ -6899,7 +6914,10 @@ if (file == NULL) /* open failed? */
|
||||||
return;
|
return;
|
||||||
sim_printf ("\n%s\n\n", FullPath);
|
sim_printf ("\n%s\n\n", FullPath);
|
||||||
lbuf[sizeof(lbuf)-1] = '\0';
|
lbuf[sizeof(lbuf)-1] = '\0';
|
||||||
while (fgets (lbuf, sizeof(lbuf)-1, file))
|
if (sim_type_file_offset)
|
||||||
|
(void)fseek (file, sim_type_file_offset, SEEK_SET);
|
||||||
|
while ((NULL != fgets (lbuf, sizeof(lbuf)-1, file)) &&
|
||||||
|
(lines++ < sim_type_line_count))
|
||||||
sim_printf ("%s", lbuf);
|
sim_printf ("%s", lbuf);
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
|
@ -6908,11 +6926,36 @@ fclose (file);
|
||||||
t_stat type_cmd (int32 flg, CONST char *cptr)
|
t_stat type_cmd (int32 flg, CONST char *cptr)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
long lines = 0;
|
||||||
char lbuf[4*CBUFSIZE];
|
char lbuf[4*CBUFSIZE];
|
||||||
|
|
||||||
|
sim_type_file_offset = 0; /* beginning of file */
|
||||||
|
sim_type_line_count = 0X7FFFFFFF; /* output many lines */
|
||||||
GET_SWITCHES (cptr); /* get switches */
|
GET_SWITCHES (cptr); /* get switches */
|
||||||
if ((!cptr) || (*cptr == 0))
|
if ((!cptr) || (*cptr == 0))
|
||||||
return SCPE_2FARG;
|
return SCPE_2FARG;
|
||||||
|
if (sim_switches & SWMASK ('O')) { /* Specify Offset in file */
|
||||||
|
char gbuf[CBUFSIZE];
|
||||||
|
char *eptr;
|
||||||
|
|
||||||
|
cptr = get_glyph (cptr, gbuf, 0);
|
||||||
|
if ((!cptr) || (*cptr == 0))
|
||||||
|
return SCPE_2FARG;
|
||||||
|
sim_type_file_offset = strtol (gbuf, &eptr, 0);
|
||||||
|
if ((*eptr) || (sim_type_file_offset < 0))
|
||||||
|
return sim_messagef (SCPE_ARG, "Invalid file offset: %s\n", gbuf);
|
||||||
|
}
|
||||||
|
if (sim_switches & SWMASK ('N')) { /* Specify Line Count to display */
|
||||||
|
char gbuf[CBUFSIZE];
|
||||||
|
char *eptr;
|
||||||
|
|
||||||
|
cptr = get_glyph (cptr, gbuf, 0);
|
||||||
|
if ((!cptr) || (*cptr == 0))
|
||||||
|
return SCPE_2FARG;
|
||||||
|
sim_type_line_count = strtol (gbuf, &eptr, 0);
|
||||||
|
if ((*eptr) || (sim_type_line_count < 0))
|
||||||
|
return sim_messagef (SCPE_ARG, "Invalid file line count: %s\n", gbuf);
|
||||||
|
}
|
||||||
lbuf[sizeof(lbuf)-1] = '\0';
|
lbuf[sizeof(lbuf)-1] = '\0';
|
||||||
strlcpy (lbuf, cptr, sizeof(lbuf));
|
strlcpy (lbuf, cptr, sizeof(lbuf));
|
||||||
sim_trim_endspc(lbuf);
|
sim_trim_endspc(lbuf);
|
||||||
|
@ -6928,7 +6971,10 @@ if (file == NULL) { /* open failed? */
|
||||||
return sim_messagef (SCPE_OPENERR, "The system cannot find the file specified.\n");
|
return sim_messagef (SCPE_OPENERR, "The system cannot find the file specified.\n");
|
||||||
}
|
}
|
||||||
lbuf[sizeof(lbuf)-1] = '\0';
|
lbuf[sizeof(lbuf)-1] = '\0';
|
||||||
while (fgets (lbuf, sizeof(lbuf)-1, file))
|
if (sim_type_file_offset)
|
||||||
|
(void)fseek (file, sim_type_file_offset, SEEK_SET);
|
||||||
|
while ((NULL != fgets (lbuf, sizeof(lbuf)-1, file)) &&
|
||||||
|
(lines++ < sim_type_line_count))
|
||||||
sim_printf ("%s", lbuf);
|
sim_printf ("%s", lbuf);
|
||||||
fclose (file);
|
fclose (file);
|
||||||
return SCPE_OK;
|
return SCPE_OK;
|
||||||
|
|
Loading…
Add table
Reference in a new issue