From 2c7b757b4caf152e26f9bb0bbb3fb0dba0b69f6c Mon Sep 17 00:00:00 2001 From: Bill Chatfield Date: Fri, 28 Jul 2017 17:44:13 -0400 Subject: [PATCH 1/4] Documented _filetype and _auxtype --- doc/apple2.sgml | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/doc/apple2.sgml b/doc/apple2.sgml index 3089a04c4..fe5c98767 100644 --- a/doc/apple2.sgml +++ b/doc/apple2.sgml @@ -511,6 +511,104 @@ url="ca65.html" name="assembler manual">.

+Specifying ProDOS File Types

+ + + + Problem Explanation + + ProDOS associates a file type and an auxiliary type with each file. + These type specifications are separate from the file's name, unlike + Windows and UNIX-like systems which use the file name's suffix (a.k.a. + extension) to specify the file type. For example, .exe, .doc, or .bat. + The ProDOS low-level + Machine-Language Interface (MLI) functions for creating and opening + files require these types to be specified. And if they don't match + with the file being opened, the operation may fail. + + In contrast, the ISO C function Solution + + There are two global variables provided that allow the file type + and auxiliary type to be specified before a call to + + extern unsigned char _filetype; /* Default: PRODOS_T_BIN */ + extern unsigned int _auxtype; /* Default: 0 */ + + + + The header file Example + + A text file cannot be created with just the + standard C functions because they default to the binary type + + + #include + #include + #include + #include + void main() + { + FILE *out; + char *name = "MY.FAVS"; + + _filetype = PRODOS_T_TXT; + _auxtype = PRODOS_AUX_T_TXT_SEQ; + + if ((out = fopen(name, "w")) != NULL) { + fputs("Jorah Mormont\r", out); + fputs("Brienne of Tarth\r", out); + fputs("Daenerys Targaryen\r", out); + fputs("Sandor Clegane\r", out); + if (fclose(out) == EOF) { + fprintf(stderr, "fclose failed for %s: %s", name, strerror(errno)); + } + } + else { + fprintf(stderr, "fopen failed for %s: %s", name, strerror(errno)); + } + } + + + +

+ License

From 9d89613bb2d5f8817cd38886acdb92fa1f5395c5 Mon Sep 17 00:00:00 2001 From: Bill Chatfield Date: Sat, 29 Jul 2017 01:25:07 -0400 Subject: [PATCH 2/4] Added documentation for setting the file type for fopen. --- doc/apple2.sgml | 27 ++++++++++++++++----------- doc/apple2enh.sgml | 8 ++++++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/doc/apple2.sgml b/doc/apple2.sgml index fe5c98767..4ed2af48c 100644 --- a/doc/apple2.sgml +++ b/doc/apple2.sgml @@ -511,11 +511,11 @@ url="ca65.html" name="assembler manual">.

-Specifying ProDOS File Types

+Specifying file types for fopen

- Problem Explanation + Explanation of File Types ProDOS associates a file type and an auxiliary type with each file. These type specifications are separate from the file's name, unlike @@ -531,18 +531,18 @@ url="ca65.html" name="assembler manual">. auxiliary type. Therefore, some additional mechanism for specifying the file types is needed. - Solution + Specifying the File Type and Auxiliary Type There are two global variables provided that allow the file type and auxiliary type to be specified before a call to + extern unsigned char _filetype; /* Default: PRODOS_T_BIN */ extern unsigned int _auxtype; /* Default: 0 */ - + The header file . + - #include - #include - #include - #include + #include <stdio.h> + #include <string.h> + #include <errno.h> + #include <apple2.h> + void main() { FILE *out; char *name = "MY.FAVS"; + /*-----------------------------*/ + _filetype = PRODOS_T_TXT; _auxtype = PRODOS_AUX_T_TXT_SEQ; + /*-----------------------------*/ + if ((out = fopen(name, "w")) != NULL) { fputs("Jorah Mormont\r", out); fputs("Brienne of Tarth\r", out); @@ -605,7 +610,7 @@ url="ca65.html" name="assembler manual">. } } - +

diff --git a/doc/apple2enh.sgml b/doc/apple2enh.sgml index 5e4626fbc..672f5d6aa 100644 --- a/doc/apple2enh.sgml +++ b/doc/apple2enh.sgml @@ -517,6 +517,14 @@ url="ca65.html" name="assembler manual">.

+Specifying file types for fopen

+ +See section + +in the apple2 docoumentation. + + + License

From 85e572f4e12e071ef61fb5846b8839b6e2781df8 Mon Sep 17 00:00:00 2001 From: Bill Chatfield Date: Sun, 30 Jul 2017 19:49:20 -0400 Subject: [PATCH 3/4] Made corrections according to review comments --- doc/apple2.sgml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/apple2.sgml b/doc/apple2.sgml index 4ed2af48c..33a878223 100644 --- a/doc/apple2.sgml +++ b/doc/apple2.sgml @@ -519,8 +519,9 @@ url="ca65.html" name="assembler manual">. ProDOS associates a file type and an auxiliary type with each file. These type specifications are separate from the file's name, unlike - Windows and UNIX-like systems which use the file name's suffix (a.k.a. - extension) to specify the file type. For example, .exe, .doc, or .bat. + Windows which uses the file name's suffix (a.k.a. + extension) to specify the file type. For example, . There are two global variables provided that allow the file type and auxiliary type to be specified before a call to @@ -547,8 +548,7 @@ url="ca65.html" name="assembler manual">. The header file Example @@ -563,8 +563,8 @@ url="ca65.html" name="assembler manual">. length text file is referred to as a sequential text file. This is equivalent to text files on other operating systems, except that the line terminator is a - carriage return instead of a new line (Linux/BSD/MacOS) or - carriage return, new line pair (Windows). + carriage return instead of a line-feed (Linux/BSD/MacOS) or + carriage return, line-feed pair (Windows). The "sequential" text file terminology is in contrast to a "random-access" text file which would @@ -584,7 +584,7 @@ url="ca65.html" name="assembler manual">. #include <errno.h> #include <apple2.h> - void main() + void main(void) { FILE *out; char *name = "MY.FAVS"; From 0bd5a8a3314b1b6b8047dc31113bd5ead59d706e Mon Sep 17 00:00:00 2001 From: Bill Chatfield Date: Sun, 30 Jul 2017 19:51:23 -0400 Subject: [PATCH 4/4] Made corrections according to review comments --- doc/apple2enh.sgml | 105 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 3 deletions(-) diff --git a/doc/apple2enh.sgml b/doc/apple2enh.sgml index 672f5d6aa..c7be9b474 100644 --- a/doc/apple2enh.sgml +++ b/doc/apple2enh.sgml @@ -519,9 +519,108 @@ url="ca65.html" name="assembler manual">. Specifying file types for fopen

-See section - -in the apple2 docoumentation. + + + Explanation of File Types + + ProDOS associates a file type and an auxiliary type with each file. + These type specifications are separate from the file's name, unlike + Windows which uses the file name's suffix (a.k.a. + extension) to specify the file type. For example, Specifying the File Type and Auxiliary Type + + There are two global variables provided that allow the file type + and auxiliary type to be specified before a call to + + extern unsigned char _filetype; /* Default: PRODOS_T_BIN */ + extern unsigned int _auxtype; /* Default: 0 */ + + + + The header file Example + + A text file cannot be created with just the + standard C functions because they default to the binary type + + + #include <stdio.h> + #include <string.h> + #include <errno.h> + #include <apple2.h> + + void main(void) + { + FILE *out; + char *name = "MY.FAVS"; + + /*-----------------------------*/ + + _filetype = PRODOS_T_TXT; + _auxtype = PRODOS_AUX_T_TXT_SEQ; + + /*-----------------------------*/ + + if ((out = fopen(name, "w")) != NULL) { + fputs("Jorah Mormont\r", out); + fputs("Brienne of Tarth\r", out); + fputs("Daenerys Targaryen\r", out); + fputs("Sandor Clegane\r", out); + if (fclose(out) == EOF) { + fprintf(stderr, "fclose failed for %s: %s", name, strerror(errno)); + } + } + else { + fprintf(stderr, "fopen failed for %s: %s", name, strerror(errno)); + } + } + + + +

+ +