mirror of
https://github.com/cc65/cc65.git
synced 2024-11-19 06:31:31 +00:00
Merge pull request #40 from groessler/something_to_pull2
testcode/lib/tinyshell.c: add 'verbose' and 'cls' commands; add SP check
This commit is contained in:
commit
6466826dc8
@ -5,12 +5,22 @@
|
|||||||
|
|
||||||
#define VERSION_ASC "0.90"
|
#define VERSION_ASC "0.90"
|
||||||
|
|
||||||
#define KEYB_BUFSZ 80
|
|
||||||
#define PROMPT ">>> "
|
|
||||||
#ifdef __ATARI__
|
#ifdef __ATARI__
|
||||||
#define UPPERCASE /* define (e.g. for Atari) to convert filenames etc. to upper case */
|
#define UPPERCASE /* define (e.g. for Atari) to convert filenames etc. to upper case */
|
||||||
|
#define HAVE_SUBDIRS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE2__
|
||||||
|
#define HAVE_SUBDIRS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __CC65__
|
||||||
|
#define CHECK_SP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define KEYB_BUFSZ 80
|
||||||
|
#define PROMPT ">>> "
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -19,6 +29,7 @@
|
|||||||
#ifndef __CC65__
|
#ifndef __CC65__
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#define HAVE_SUBDIRS
|
||||||
#else
|
#else
|
||||||
#define MAXPATHLEN 64
|
#define MAXPATHLEN 64
|
||||||
#endif
|
#endif
|
||||||
@ -26,6 +37,10 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
|
#ifdef CHECK_SP
|
||||||
|
extern unsigned int getsp(void); /* comes from getsp.s */
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CMD_NOTHING 0
|
#define CMD_NOTHING 0
|
||||||
#define CMD_INVALID 1
|
#define CMD_INVALID 1
|
||||||
#define CMD_HELP 2
|
#define CMD_HELP 2
|
||||||
@ -38,7 +53,10 @@
|
|||||||
#define CMD_RENAME 9
|
#define CMD_RENAME 9
|
||||||
#define CMD_COPY 10
|
#define CMD_COPY 10
|
||||||
#define CMD_PWD 11
|
#define CMD_PWD 11
|
||||||
|
#define CMD_CLS 12
|
||||||
|
#define CMD_VERBOSE 13
|
||||||
|
|
||||||
|
static unsigned char verbose;
|
||||||
static unsigned char terminate;
|
static unsigned char terminate;
|
||||||
static unsigned char cmd;
|
static unsigned char cmd;
|
||||||
static unsigned char *cmd_asc, *arg1, *arg2, *arg3;
|
static unsigned char *cmd_asc, *arg1, *arg2, *arg3;
|
||||||
@ -56,11 +74,13 @@ struct cmd_table {
|
|||||||
{ "ls", CMD_LS },
|
{ "ls", CMD_LS },
|
||||||
{ "dir", CMD_LS },
|
{ "dir", CMD_LS },
|
||||||
{ "md", CMD_MKDIR },
|
{ "md", CMD_MKDIR },
|
||||||
|
#ifdef HAVE_SUBDIRS
|
||||||
{ "mkdir", CMD_MKDIR },
|
{ "mkdir", CMD_MKDIR },
|
||||||
{ "rd", CMD_RMDIR },
|
{ "rd", CMD_RMDIR },
|
||||||
{ "rmdir", CMD_RMDIR },
|
{ "rmdir", CMD_RMDIR },
|
||||||
{ "cd", CMD_CHDIR },
|
{ "cd", CMD_CHDIR },
|
||||||
{ "chdir", CMD_CHDIR },
|
{ "chdir", CMD_CHDIR },
|
||||||
|
#endif
|
||||||
{ "rm", CMD_RM },
|
{ "rm", CMD_RM },
|
||||||
{ "del", CMD_RM },
|
{ "del", CMD_RM },
|
||||||
{ "cp", CMD_COPY },
|
{ "cp", CMD_COPY },
|
||||||
@ -68,6 +88,10 @@ struct cmd_table {
|
|||||||
{ "mv", CMD_RENAME },
|
{ "mv", CMD_RENAME },
|
||||||
{ "ren", CMD_RENAME },
|
{ "ren", CMD_RENAME },
|
||||||
{ "pwd", CMD_PWD },
|
{ "pwd", CMD_PWD },
|
||||||
|
#ifdef __ATARI__
|
||||||
|
{ "cls", CMD_CLS },
|
||||||
|
#endif
|
||||||
|
{ "verbose", CMD_VERBOSE },
|
||||||
{ NULL, 0 }
|
{ NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,6 +106,22 @@ static void get_command(void)
|
|||||||
{
|
{
|
||||||
unsigned char i = 0;
|
unsigned char i = 0;
|
||||||
|
|
||||||
|
#ifdef CHECK_SP
|
||||||
|
static char firstcall = 1;
|
||||||
|
static unsigned int good_sp;
|
||||||
|
unsigned int sp;
|
||||||
|
if (firstcall)
|
||||||
|
sp = good_sp = getsp();
|
||||||
|
else
|
||||||
|
sp = getsp();
|
||||||
|
|
||||||
|
if (sp != good_sp) {
|
||||||
|
printf("SP: 0x%04X ***MISMATCH*** 0x%04X\n", sp, good_sp);
|
||||||
|
}
|
||||||
|
else if (verbose)
|
||||||
|
printf("SP: 0x%04X\n", sp);
|
||||||
|
#endif
|
||||||
|
|
||||||
arg1 = arg2 = arg3 = NULL;
|
arg1 = arg2 = arg3 = NULL;
|
||||||
|
|
||||||
/* issue prompt */
|
/* issue prompt */
|
||||||
@ -132,6 +172,10 @@ static void cmd_help(void)
|
|||||||
puts("cd, chdir - change directory or drive");
|
puts("cd, chdir - change directory or drive");
|
||||||
puts("md, mkdir - make directory or drive");
|
puts("md, mkdir - make directory or drive");
|
||||||
puts("rd, rmdir - remove directory or drive");
|
puts("rd, rmdir - remove directory or drive");
|
||||||
|
#ifdef __ATARI__
|
||||||
|
puts("cls - clear screen");
|
||||||
|
#endif
|
||||||
|
puts("verbose - set verbosity level");
|
||||||
puts("sorry, you cannot start programs here");
|
puts("sorry, you cannot start programs here");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,6 +217,8 @@ static void cmd_ls(void)
|
|||||||
else
|
else
|
||||||
arg = ".";
|
arg = ".";
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
printf("Buffer addr: %p\n", arg);
|
||||||
dir = opendir(arg);
|
dir = opendir(arg);
|
||||||
#ifdef __ATARI__
|
#ifdef __ATARI__
|
||||||
if (need_free) free(arg);
|
if (need_free) free(arg);
|
||||||
@ -203,6 +249,8 @@ static void cmd_rm(void)
|
|||||||
printf("remove failed: %s\n", strerror(errno));
|
printf("remove failed: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_SUBDIRS
|
||||||
|
|
||||||
static void cmd_mkdir(void)
|
static void cmd_mkdir(void)
|
||||||
{
|
{
|
||||||
if (!arg1 || arg2) {
|
if (!arg1 || arg2) {
|
||||||
@ -262,6 +310,8 @@ static void cmd_pwd(void)
|
|||||||
printf("malloc %u bytes failed: %s\n", MAXPATHLEN, strerror(errno));
|
printf("malloc %u bytes failed: %s\n", MAXPATHLEN, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (verbose)
|
||||||
|
printf("Buffer addr: %p\n", buf);
|
||||||
if (!getcwd(buf, MAXPATHLEN)) {
|
if (!getcwd(buf, MAXPATHLEN)) {
|
||||||
printf("getcwd failed: %s\n", strerror(errno));
|
printf("getcwd failed: %s\n", strerror(errno));
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -272,6 +322,8 @@ static void cmd_pwd(void)
|
|||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* #ifdef HAVE_SUBDIRS */
|
||||||
|
|
||||||
static void cmd_rename(void)
|
static void cmd_rename(void)
|
||||||
{
|
{
|
||||||
if (!arg2 || arg3) {
|
if (!arg2 || arg3) {
|
||||||
@ -309,6 +361,8 @@ static void cmd_copy(void)
|
|||||||
printf("malloc %u bytes failed: %s\n", cpbuf_sz, strerror(errno));
|
printf("malloc %u bytes failed: %s\n", cpbuf_sz, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (verbose)
|
||||||
|
printf("Buffer addr: %p\n", buf);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (srcfd == -1) {
|
if (srcfd == -1) {
|
||||||
@ -349,6 +403,33 @@ static void cmd_copy(void)
|
|||||||
if (dstfd >= 0) close(dstfd);
|
if (dstfd >= 0) close(dstfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __ATARI__
|
||||||
|
static void cmd_cls(void)
|
||||||
|
{
|
||||||
|
printf("\f");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void cmd_verbose(void)
|
||||||
|
{
|
||||||
|
unsigned long verb;
|
||||||
|
char *endptr;
|
||||||
|
|
||||||
|
if (!arg1 || arg2) {
|
||||||
|
puts("usage: verbose <level>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
verb = strtoul(arg1, &endptr, 10);
|
||||||
|
if (verb > 255 || *endptr) {
|
||||||
|
puts("invalid verbosity level");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
verbose = verb;
|
||||||
|
printf("verbosity level set to %d\n", verbose);
|
||||||
|
}
|
||||||
|
|
||||||
static void run_command(void)
|
static void run_command(void)
|
||||||
{
|
{
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
@ -359,12 +440,18 @@ static void run_command(void)
|
|||||||
case CMD_QUIT: terminate = 1; return;
|
case CMD_QUIT: terminate = 1; return;
|
||||||
case CMD_LS: cmd_ls(); return;
|
case CMD_LS: cmd_ls(); return;
|
||||||
case CMD_RM: cmd_rm(); return;
|
case CMD_RM: cmd_rm(); return;
|
||||||
|
#ifdef HAVE_SUBDIRS
|
||||||
case CMD_CHDIR: cmd_chdir(); return;
|
case CMD_CHDIR: cmd_chdir(); return;
|
||||||
case CMD_MKDIR: cmd_mkdir(); return;
|
case CMD_MKDIR: cmd_mkdir(); return;
|
||||||
case CMD_RMDIR: cmd_rmdir(); return;
|
case CMD_RMDIR: cmd_rmdir(); return;
|
||||||
case CMD_PWD: cmd_pwd(); return;
|
case CMD_PWD: cmd_pwd(); return;
|
||||||
|
#endif
|
||||||
case CMD_RENAME: cmd_rename(); return;
|
case CMD_RENAME: cmd_rename(); return;
|
||||||
case CMD_COPY: cmd_copy(); return;
|
case CMD_COPY: cmd_copy(); return;
|
||||||
|
#ifdef __ATARI__
|
||||||
|
case CMD_CLS: cmd_cls(); return;
|
||||||
|
#endif
|
||||||
|
case CMD_VERBOSE: cmd_verbose(); return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user