HP85 GPIB Disk Emulator
1.0
HP85GPIBDiskEmulator
|
Go to the documentation of this file.
26 #include "user_config.h"
52 "Note: posix prefix is optional\n"
53 #ifdef POSIX_EXTENDED_TESTS
54 "posix chmod file NNN\n"
56 "posix cat file [-p]\n"
58 "posix copy file1 file2\n"
59 #ifdef POSIX_EXTENDED_TESTS
60 "posix hexdump file [-p]\n"
65 #ifdef POSIX_EXTENDED_TESTS
68 "posix page NN - used for cat -p\n"
70 #ifdef POSIX_EXTENDED_TESTS
76 "posix rename old new\n"
77 #ifdef POSIX_EXTENDED_TESTS
108 printf(
"argv[%d]=%s\n",(
int)i, argv[i]);
116 if(
MATCH(ptr,
"posix") )
119 if ( !ptr ||
MATCH(ptr,
"help") )
126 if (
MATCHARGS(ptr,
"cat", (ind + 1), argc))
130 for(i=ind;i<argc;++i)
132 if(
MATCH(argv[i],
"-p"))
135 for(i=ind;i<argc;++i)
137 if(!
MATCH(argv[i],
"-p"))
140 cat(argv[ind], page);
146 #ifdef POSIX_EXTENDED_TESTS
147 else if (
MATCHARGS(ptr,
"chmod",(ind+2),argc))
151 printf(
"chmod: %s %s - FAILED\n",argv[ind],argv[ind+1]);
158 else if (
MATCHARGS(ptr,
"copy", (ind + 2), argc))
160 if(
copy(argv[ind],argv[ind+1]) < 0)
165 else if (
MATCHARGS(ptr,
"cd", (ind + 1), argc))
167 if (
chdir(argv[ind]) != 0)
169 printf(
"chdir %s failed\n", argv[ind]);
175 #ifdef POSIX_EXTENDED_TESTS
176 else if (
MATCHARGS(ptr,
"hexdump", (ind + 1), argc))
180 for(i=ind;i<argc;++i)
182 if(
MATCH(argv[i],
"-p"))
185 for(i=ind;i<argc;++i)
187 if(!
MATCH(argv[i],
"-p"))
189 if(
hexdump(argv[ind], page) ==0 )
191 printf(
"hexdump failed\n");
199 else if (
MATCHARGS(ptr,
"log", (ind + 2), argc))
201 if(
logfile(argv[ind],argv[ind+1]) < 0)
207 else if (
MATCHI(ptr,
"ls") )
211 for(i=ind;i<argc;++i)
215 printf(
"ls: null argument # %d\n", i);
218 if(
MATCH(argv[i],
"-l"))
220 if(
ls(argv[i],1) < 0)
236 #ifdef POSIX_EXTENDED_TESTS
237 else if (
MATCHARGS(ptr,
"mkfs", (ind + 1), argc))
240 if (
mkfs(argv[ind]) == 0)
242 printf(
"mkfs %s FAILED\n");
249 else if (
MATCHARGS(ptr,
"mkdir", (ind + 1), argc))
256 if (
mkdir(argv[ind],mode) != 0 )
258 printf(
"mkdir %s failed\n", argv[ind]);
264 else if (
MATCHARGS(ptr,
"page", (ind + 1), argc))
270 else if (
MATCHARGS(ptr,
"pwd", (ind + 0), argc))
273 char *ptr =
getcwd(path,
sizeof(path)-2);
283 else if (
MATCHARGS(ptr,
"rename", (ind + 2), argc))
285 if(
rename(argv[ind],argv[ind+1]) != 0)
287 printf(
"rename %s to %s\n", argv[ind], argv[ind+1]);
293 else if (
MATCHARGS(ptr,
"rm", (ind + 1), argc))
295 if (
unlink(argv[ind]) != 0)
297 printf(
"rm %s failed\n", argv[ind]);
303 #ifdef POSIX_EXTENDED_TESTS
304 else if (
MATCHARGS(ptr,
"sum", (ind + 1), argc))
306 if(
sum(argv[ind]) < 0)
308 printf(
"sum %s FAILED\n",argv[ind]);
314 else if (
MATCHARGS(ptr,
"stat", (ind + 1), argc))
318 if(
stat(argv[ind], &p) < 0)
320 printf(
"stat %s FAILED\n", argv[ind]);
328 else if (
MATCHARGS(ptr,
"rmdir", (ind + 1), argc))
330 if (
rmdir(argv[ind]) != 0)
332 printf(
"rmdir %s failed\n", argv[ind]);
338 #ifdef POSIX_EXTENDED_TESTS
339 else if (
MATCHARGS(ptr,
"upload", (ind + 1), argc))
355 long cat(
char *name,
int dopage)
362 fp =
fopen(name,
"rb");
365 printf(
"Can't open: %s\n", name);
368 while(
fgets(line,
sizeof(line)-2,fp) !=
NULL)
381 optimistic_yield(1000);
387 printf(
"%ld bytes\n", (
long)size);
405 printf(
"Opening %s\n", from);
407 fi =
fopen(from,
"rb");
410 printf(
"Can't open: %s\n", from);
414 printf(
"Creating %s\n", to);
418 printf(
"Can't open: %s\n", to);
434 if( (
int)
fwrite(buf,1,len,fo) < len)
440 printf(
"Copied: %08ld\r", size);
442 optimistic_yield(1000);
446 printf(
"%lu bytes copied.\n", size);
454 #ifdef POSIX_EXTENDED_TESTS
459 int hexdump(
char *name,
int dopage)
470 printf(
"Can' open: %s\n", name);
476 while( (len =
fread(buf,1, 16, fi)) > 0)
481 printf(
"%02x ",0xff & buf[i]);
489 if(buf[i] >= 0x20 && buf[i] <= 0x7e)
506 optimistic_yield(1000);
541 optimistic_yield(1000);
570 if(
stat(name, &sp) == -1)
572 printf(
"can not stat: %s\n", name);
600 printf(
"%s none none %12ld %s %s\n",
614 int ls(
char *name,
int verbose)
624 if(!name || !*name ||
MATCH(name,
".") )
626 if( !
getcwd(fullpath,
sizeof(fullpath)-2) )
628 printf(
"ls: Can't get current directory\n");
640 if (
stat(fullpath, &st))
642 printf(
"ls: cannot stat [%s]\n", fullpath);
645 printf(
"Listing:[%s]\n",fullpath);
650 files =
ls_info(fullpath,verbose);
656 printf(
"opendir failed\n");
667 printf(
"name:[%s] too long with full path\n",de->
d_name);
670 if(!
MATCH(fullpath,
"/") )
675 files +=
ls_info(fullpath,verbose);
679 optimistic_yield(1000);
686 printf(
"Files: %d\n", (
int)files);
691 #ifdef POSIX_EXTENDED_TESTS
697 long logfile(
char *name,
char *str)
702 fo =
fopen(name,
"ab");
705 printf(
"Can't open: %s\n", name);
710 if(
fwrite(str, 1, size, fo) < size)
720 #ifdef POSIX_EXTENDED_TESTS
725 uint16_t
sum(
char *name)
736 printf(
"Can' open: %s\n", name);
740 while( (len =
fread(buffer,1, 256, fi)) > 0)
743 sum += (0xff & buffer[i]);
745 optimistic_yield(1000);
750 printf(
"Sum: %04Xh, %5u\n", (
int)
sum, (
unsigned int)
sum);
754 #ifdef POSIX_EXTENDED_TESTS
769 fp =
fopen(name,
"wb");
772 printf(
"Can' open: %s\n", name);
785 len2 =
fwrite(buffer, 1, len,fp);
MEMSPACE FILE * fopen(const char *path, const char *mode)
POSIX Open a file with path name and ascii file mode string.
MEMSPACE int chdir(const char *pathname)
POSIX change directory.
MEMSPACE int printf(const char *format,...)
#define stdin
define stdin, stdout and stderr
MEMSPACE void dump_stat(struct stat *sp)
Display struct stat, from POSIX stat(0 or fstat(), in ASCII. NOT POSIX.
MEMSPACE int hexdump(char *name, int dopage)
MEMSPACE char * mctime(time_t timev)
Display Ascii formatted time from timev seconds NOT POSIX.
MEMSPACE int MATCH(char *str, char *pat)
Compare two strings.
MEMSPACE int MATCHI(char *str, char *pat)
Compare two strings without case.
MEMSPACE void sync(void)
POSIX Sync all pending file changes and metadata on ALL files.
int mkfs(char *name)
Formt SD card.
MEMSPACE WEAK_ATR char * strcat(char *dest, const char *src)
Append string.
void * safecalloc(int size, int elements)
Safe Alloc - Display Error message if Calloc fails.
MEMSPACE int ls(char *name, int verbose)
Directory listing.
MEMSPACE char * fgets(char *str, int size, FILE *stream)
get a string from stdin See fdevopen() sets stream->put get for TTY devices
int closedir(DIR *dirp)
POSIX closedir.
int putchar(int c)
put a character to stdout See fdevopen() sets stream->put get for TTY devices
MEMSPACE long strtol(const char *nptr, char **endptr, int base)
Convert ASCII string to number in a given base.
MEMSPACE int chmod(const char *pathname, mode_t mode)
POSIX chmod function - change file access permission Unfortunately file f_open modes and f_chmod mode...
Various string and character functions.
#define S_IFMT
POSIX File types, see fstat and stat.
MEMSPACE int rename(const char *oldpath, const char *newpath)
POSIX rename a file by name.
MEMSPACE long upload(char *name)
MEMSPACE size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
POSIX write nmemb elements from buf, size bytes each, to the stream fd.
void safefree(void *p)
Safe free - Only free a pointer if it is in malloc memory range.
MEMSPACE long cat(char *name, int dopage)
Display the contents of a file.
MEMSPACE long logfile(char *name, char *str)
MEMSPACE int rmdir(const char *pathname)
POSIX delete a directory.
MEMSPACE void trim_tail(char *str)
Trim White space and control characters from end of string.
MEMSPACE int testpage(int count)
Used to page output of functions like cat, hexdump, etc.
static int _pagesize
Used to page output of functions like cat, hexdump, etc.
MEMSPACE int stat(char *name, struct stat *buf)
POSIX stat - get file status of named file.
MEMSPACE uint16_t sum(char *name)
MEMSPACE int getchar()
functions normally defined as macros
dirent_t * readdir(DIR *dirp)
MEMSPACE WEAK_ATR char * strcpy(char *dest, const char *src)
copy a string
MEMSPACE void posix_help(int full)
char d_name[MAX_NAME_LEN]
MEMSPACE int ls_info(char *name, int verbose)
list one file
MEMSPACE size_t WEAK_ATR strlen(const char *str)
String Length.
Common Linux/POSIX time functions.
MEMSPACE char * basename(char *str)
POSIX Basename of filename.
MEMSPACE int setpage(int count)
DIR * opendir(const char *pathdir)
MEMSPACE int fclose(FILE *stream)
POSIX close a file stream.
MEMSPACE int atoi(const char *str)
Convert ASCII string to number in base 10.
MEMSPACE int mkdir(const char *pathname, mode_t mode)
POSIX make a directory.
MEMSPACE int MATCHARGS(char *str, char *pat, int min, int argc)
Match two strings and compare argument index Display message if the number of arguments is too few.
MEMSPACE long copy(char *from, char *to)
Copy a file.
MEMSPACE char * getcwd(char *pathname, int len)
POSIX get current working directory.
uint32_t time_t
type of EPOCH result.
MEMSPACE int unlink(const char *pathname)
POSIX delete a file.
Math IO functions, and verious conversion code with floating point support.
MEMSPACE size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
POSIX read nmemb elements from buf, size bytes each, to the stream fd.
MEMSPACE int posix_tests(int argc, char *argv[])
POSIX tests.
MEMSPACE int puts(const char *str)
put a string to stdout See fdevopen() sets stream->put get for TTY devices