Fixed POSIX IO, (ACCEPT) now emits SPACE at end of line.
authorphil@softsynth.com <phil@softsynth.com@b0a0988d-7f52-0410-8c73-4f6cdee1a2cf>
Fri, 20 Feb 2009 18:38:25 +0000 (18:38 +0000)
committerphil@softsynth.com <phil@softsynth.com@b0a0988d-7f52-0410-8c73-4f6cdee1a2cf>
Fri, 20 Feb 2009 18:38:25 +0000 (18:38 +0000)
build/unix/Makefile
csrc/pf_core.c
csrc/pf_guts.h
csrc/pf_io.c
csrc/posix/pf_io_posix.c
fth/history.fth
releases.txt

index 5285ad3..2408291 100644 (file)
@@ -8,7 +8,6 @@
 # Options include: PF_SUPPORT_FP PF_NO_MALLOC PF_NO_INIT PF_DEBUG
 # See "docs/pf_ref.htm" file for more info.
 
 # Options include: PF_SUPPORT_FP PF_NO_MALLOC PF_NO_INIT PF_DEBUG
 # See "docs/pf_ref.htm" file for more info.
 
-# Note for Mac OS X, use cc instead of gcc
 COMPILER = gcc
 
 PFORTHDIR   := $(shell cd ../../; pwd)
 COMPILER = gcc
 
 PFORTHDIR   := $(shell cd ../../; pwd)
@@ -35,7 +34,10 @@ FULL_WARNINGS =  \
         -Wmissing-prototypes \
         -Wmissing-declarations
         
         -Wmissing-prototypes \
         -Wmissing-declarations
         
-CCOPTS = -DPF_SUPPORT_FP -DPF_POSIX_IO -O2 $(FULL_WARNINGS) $(EXTRA_CCOPTS)
+CCOPTS = -DPF_SUPPORT_FP -O2 $(FULL_WARNINGS) $(EXTRA_CCOPTS)
+
+IO_SOURCE = ${CSRCDIR}/posix/pf_io_posix.c
+#IO_SOURCE = ${CSRCDIR}/stdio/pf_io_stdio.c
 
 EMBCCOPTS = -DPF_STATIC_DIC
 
 
 EMBCCOPTS = -DPF_STATIC_DIC
 
@@ -43,17 +45,17 @@ EMBCCOPTS = -DPF_STATIC_DIC
 # Build file lists from wildcards.
 PFITEMP    = ${wildcard ${CSRCDIR}/*.h}
 PFINCLUDES = ${PFITEMP:${CSRCDIR}/pfdicdat.h=}
 # Build file lists from wildcards.
 PFITEMP    = ${wildcard ${CSRCDIR}/*.h}
 PFINCLUDES = ${PFITEMP:${CSRCDIR}/pfdicdat.h=}
-PFSOURCE   = ${wildcard ${CSRCDIR}/*.c} ${CSRCDIR}/posix/pf_io_posix.c
+PFSOURCE   = ${wildcard ${CSRCDIR}/*.c} ${IO_SOURCE}
 PFTEMP     = ${PFSOURCE:%.c=%.o}
 PFOBJS     = ${PFTEMP:${CSRCDIR}/%=${TEMPOBJECTDIR}/%}
 PFEMBOBJS  = ${PFTEMP:${CSRCDIR}/%=${OBJECTDIR}/%}
 
 COMPILE = $(COMPILER) $(CCOPTS) $(CDEFS)
        
 PFTEMP     = ${PFSOURCE:%.c=%.o}
 PFOBJS     = ${PFTEMP:${CSRCDIR}/%=${TEMPOBJECTDIR}/%}
 PFEMBOBJS  = ${PFTEMP:${CSRCDIR}/%=${OBJECTDIR}/%}
 
 COMPILE = $(COMPILER) $(CCOPTS) $(CDEFS)
        
-${TEMPOBJECTDIR}/%.o:  ${TEMPOBJECTDIR}/posix $(PFINCLUDES)  ${CSRCDIR}/%.c
+${TEMPOBJECTDIR}/%.o:  ${TEMPOBJECTDIR} $(PFINCLUDES)  ${CSRCDIR}/%.c
        $(COMPILE) -O -o ${TEMPOBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c
        
        $(COMPILE) -O -o ${TEMPOBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c
        
-${OBJECTDIR}/%.o:  ${OBJECTDIR}/posix $(PFINCLUDES) ${CSRCDIR}/%.c ${CSRCDIR}/pfdicdat.h 
+${OBJECTDIR}/%.o:  ${OBJECTDIR} $(PFINCLUDES) ${CSRCDIR}/%.c ${CSRCDIR}/pfdicdat.h 
        $(COMPILE) -O -o ${OBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c $(EMBCCOPTS)
 
 all: $(PFORTHAPP)
        $(COMPILE) -O -o ${OBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c $(EMBCCOPTS)
 
 all: $(PFORTHAPP)
@@ -70,11 +72,13 @@ pffiles:
        @echo "EMBEDDED OBJECT FILES ------------------"
        @echo ${PFEMBOBJS}
        
        @echo "EMBEDDED OBJECT FILES ------------------"
        @echo ${PFEMBOBJS}
        
-${TEMPOBJECTDIR}/posix
+${TEMPOBJECTDIR}: 
        mkdir -p ${TEMPOBJECTDIR}/posix
        mkdir -p ${TEMPOBJECTDIR}/posix
+       mkdir -p ${TEMPOBJECTDIR}/stdio
 
 
-${OBJECTDIR}/posix
+${OBJECTDIR}: 
        mkdir -p ${OBJECTDIR}/posix
        mkdir -p ${OBJECTDIR}/posix
+       mkdir -p ${OBJECTDIR}/stdio
 
 # build pforth by compiling 'C' source
 $(PFDICAPP): $(PFINCLUDES) $(PFOBJS)
 
 # build pforth by compiling 'C' source
 $(PFDICAPP): $(PFINCLUDES) $(PFOBJS)
@@ -86,7 +90,7 @@ pfdicapp: $(PFDICAPP)
 $(PFDICDAT): $(PFDICAPP)
        cd $(FTHDIR); $(PFDICAPP) -i system.fth ; mv pfdicdat.h $(PFDICDAT)
 
 $(PFDICDAT): $(PFDICAPP)
        cd $(FTHDIR); $(PFDICAPP) -i system.fth ; mv pfdicdat.h $(PFDICDAT)
 
-$(PFORTHAPP): ${TEMPOBJECTDIR}/posix $(PFDICDAT) $(PFINCLUDES) $(PFEMBOBJS)
+$(PFORTHAPP): ${TEMPOBJECTDIR} $(PFDICDAT) $(PFINCLUDES) $(PFEMBOBJS)
        $(COMPILER) $(PFEMBOBJS) -lm -o $(PFORTHAPP)
        @echo ""
        @echo "Standalone pForth executable written to $(PFORTHAPP)"
        $(COMPILER) $(PFEMBOBJS) -lm -o $(PFORTHAPP)
        @echo ""
        @echo "Standalone pForth executable written to $(PFORTHAPP)"
index ceab2be..c2fc2c9 100644 (file)
@@ -455,8 +455,8 @@ int32 pfDoForth( const char *DicName, const char *SourceName, int32 IfInit )
                if( !pfQueryQuiet() )\r
                {\r
                        MSG( "PForth V"PFORTH_VERSION );\r
                if( !pfQueryQuiet() )\r
                {\r
                        MSG( "PForth V"PFORTH_VERSION );\r
-                       if( IsHostLittleEndian() ) MSG("LE");\r
-                       else MSG("BE");\r
+                       if( IsHostLittleEndian() ) MSG("-LE");\r
+                       else MSG("-BE");\r
 #if PF_BIG_ENDIAN_DIC\r
             MSG("/BE");\r
 #elif PF_LITTLE_ENDIAN_DIC\r
 #if PF_BIG_ENDIAN_DIC\r
             MSG("/BE");\r
 #elif PF_LITTLE_ENDIAN_DIC\r
index 6c3b032..b3814ad 100644 (file)
@@ -23,7 +23,7 @@
 ** PFORTH_VERSION changes when PForth is modified and released.\r
 ** See README file for version info.\r
 */\r
 ** PFORTH_VERSION changes when PForth is modified and released.\r
 ** See README file for version info.\r
 */\r
-#define PFORTH_VERSION "23"\r
+#define PFORTH_VERSION "24"\r
 \r
 /*\r
 ** PFORTH_FILE_VERSION changes when incompatible changes are made\r
 \r
 /*\r
 ** PFORTH_FILE_VERSION changes when incompatible changes are made\r
index 3f57902..2cd3d3d 100644 (file)
@@ -87,7 +87,8 @@ cell ioKey( void )
 ** Receive line from keyboard.\r
 ** Return number of characters enterred.\r
 */\r
 ** Receive line from keyboard.\r
 ** Return number of characters enterred.\r
 */\r
-#define BACKSPACE  (8)\r
+#define SPACE      (0x20)\r
+#define BACKSPACE  (0x08)\r
 #define DELETE     (0x7F)\r
 cell ioAccept( char *buffer, cell maxChars )\r
 {\r
 #define DELETE     (0x7F)\r
 cell ioAccept( char *buffer, cell maxChars )\r
 {\r
@@ -135,6 +136,7 @@ DBUGX(("ioAccept(0x%x, 0x%x)\n", buffer, len ));
 \r
 gotline:\r
        sdDisableInput();\r
 \r
 gotline:\r
        sdDisableInput();\r
+       sdTerminalEcho( SPACE );\r
 \r
 /* NUL terminate line to simplify printing when debugging. */\r
        if( len < maxChars ) p[len] = '\0';\r
 \r
 /* NUL terminate line to simplify printing when debugging. */\r
        if( len < maxChars ) p[len] = '\0';\r
index bf4a5c3..211c516 100644 (file)
 **\r
 ****************************************************************\r
 ** 941004 PLB Extracted IO calls from pforth_main.c\r
 **\r
 ****************************************************************\r
 ** 941004 PLB Extracted IO calls from pforth_main.c\r
+** 090220 PLB Fixed broken sdQueryTerminal on Mac. It always returned true.\r
 ***************************************************************/\r
 \r
 #include "../pf_all.h"\r
 \r
 ***************************************************************/\r
 \r
 #include "../pf_all.h"\r
 \r
-#if PF_POSIX_IO\r
 /* Configure console so that characters are not buffered.\r
 /* Configure console so that characters are not buffered.\r
- * This allows KEY to work and also HISTORY.ON\r
- * Thanks to Ralf Baechle and David Feuer for contributing this.\r
+ * This allows KEY and ?TERMINAL to work and also HISTORY.ON\r
  */\r
 \r
 #include <unistd.h>\r
  */\r
 \r
 #include <unistd.h>\r
 #include <termios.h>\r
 #include <sys/poll.h>\r
 \r
 #include <termios.h>\r
 #include <sys/poll.h>\r
 \r
-#define stdin_fd 1\r
-\r
 static struct termios save_termios;\r
 static int stdin_is_tty;\r
 \r
 static struct termios save_termios;\r
 static int stdin_is_tty;\r
 \r
+/* poll() is broken in Mac OS X Tiger OS so use select() instead. */\r
+#define PF_USE_SELECT  (1)\r
+\r
 /* Default portable terminal I/O. */\r
 int  sdTerminalOut( char c )\r
 {\r
        return putchar(c);\r
 }\r
 /* Default portable terminal I/O. */\r
 int  sdTerminalOut( char c )\r
 {\r
        return putchar(c);\r
 }\r
-/* We don't need to echo because getchar() echos. */\r
+\r
 int  sdTerminalEcho( char c )\r
 {\r
 int  sdTerminalEcho( char c )\r
 {\r
-       TOUCH(c);\r
+       putchar(c);\r
        return 0;\r
 }\r
        return 0;\r
 }\r
+\r
 int  sdTerminalIn( void )\r
 {\r
        return getchar();\r
 int  sdTerminalIn( void )\r
 {\r
        return getchar();\r
@@ -66,44 +67,70 @@ int  sdTerminalFlush( void )
 /****************************************************/\r
 int sdQueryTerminal( void )\r
 {\r
 /****************************************************/\r
 int sdQueryTerminal( void )\r
 {\r
-       struct pollfd  pfd;\r
+#if PF_USE_SELECT\r
+       fd_set readfds;\r
+       struct timeval tv;\r
+       FD_ZERO(&readfds);\r
+       FD_SET(STDIN_FILENO, &readfds);\r
+       /* Set timeout to zero so that we just poll and return. */\r
+       tv.tv_sec = 0;\r
+       tv.tv_usec = 0;\r
+       int select_retval = select(STDIN_FILENO+1, &readfds, NULL, NULL, &tv);\r
+       if (select_retval < 0)\r
+       {\r
+               perror("sdTerminalInit: select");\r
+       }\r
+       return FD_ISSET(STDIN_FILENO,&readfds) ? FTRUE : FFALSE;\r
+\r
+#else\r
+       struct pollfd  pfd = { 0 };\r
        sdTerminalFlush();\r
        sdTerminalFlush();\r
-       pfd.fd = stdin_fd;\r
-       pfd.events = stdin_fd;\r
-       return poll( &pfd, 1, 0 );      \r
+       pfd.fd = STDIN_FILENO;\r
+       pfd.events = POLLIN;\r
+       int result = poll( &pfd, 1, 0 );\r
+    /* On a Mac it may set revents to POLLNVAL because poll() is broken on Tiger. */\r
+       if( pfd.revents & POLLNVAL )\r
+       {\r
+               PRT(("sdQueryTerminal: poll got POLLNVAL, stdin not open\n"));\r
+               return FFALSE;\r
+       }\r
+       else\r
+       {\r
+               return (pfd.revents & POLLIN) ? FTRUE : FFALSE;\r
+       }\r
+#endif\r
 }\r
 \r
 /****************************************************/\r
 void sdTerminalInit(void)\r
 {\r
 }\r
 \r
 /****************************************************/\r
 void sdTerminalInit(void)\r
 {\r
-        struct termios term;\r
-       \r
-        stdin_is_tty = isatty(stdin_fd);\r
-        if (!stdin_is_tty)\r
-                return;\r
-               \r
+       struct termios term;\r
+\r
+       stdin_is_tty = isatty(STDIN_FILENO);\r
+       if (stdin_is_tty)\r
+       {               \r
 /* Get current terminal attributes and save them so we can restore them. */\r
 /* Get current terminal attributes and save them so we can restore them. */\r
-        tcgetattr(stdin_fd, &term);\r
-        save_termios = term;\r
+               tcgetattr(STDIN_FILENO, &term);\r
+               save_termios = term;\r
        \r
 /* ICANON says to wait upon read until a character is received,\r
  * and then to return it immediately (or soon enough....)\r
  * ECHOCTL says not to echo backspaces and other control chars as ^H */\r
        \r
 /* ICANON says to wait upon read until a character is received,\r
  * and then to return it immediately (or soon enough....)\r
  * ECHOCTL says not to echo backspaces and other control chars as ^H */\r
-        term.c_lflag &= ~( ECHO | ECHONL | ECHOCTL | ICANON );\r
-        term.c_cc[VTIME] = 0;\r
-        term.c_cc[VMIN] = 1;\r
-        tcsetattr(stdin_fd, TCSANOW, &term);\r
+               term.c_lflag &= ~( ECHO | ECHONL | ECHOCTL | ICANON );\r
+               term.c_cc[VTIME] = 0;\r
+               term.c_cc[VMIN] = 1;\r
+               if( tcsetattr(STDIN_FILENO, TCSANOW, &term) < 0 )\r
+               {\r
+                       perror("sdTerminalInit: tcsetattr");\r
+               }\r
+       }\r
 }\r
 \r
 /****************************************************/\r
 void sdTerminalTerm(void)\r
 {\r
 }\r
 \r
 /****************************************************/\r
 void sdTerminalTerm(void)\r
 {\r
-        if (!stdin_is_tty)\r
-                return;\r
-\r
-        tcsetattr(stdin_fd, TCSANOW, &save_termios);\r
+       if (stdin_is_tty)\r
+       {\r
+               tcsetattr(STDIN_FILENO, TCSANOW, &save_termios);\r
+       }\r
 }\r
 }\r
-\r
-#undef stdin_fd\r
-\r
-#endif\r
index dfb7baa..5e5409e 100644 (file)
@@ -421,9 +421,9 @@ variable KH-INSIDE        ( true if we are scrolling inside the history buffer )
                kh.inschar\r
        REPEAT drop\r
        kh-span @ kh-cursor @ - ?dup\r
                kh.inschar\r
        REPEAT drop\r
        kh-span @ kh-cursor @ - ?dup\r
-       IF 1+ tio.forwards  ( move to end of line )\r
-       ELSE space\r
+       IF tio.forwards  ( move to end of line )\r
        THEN\r
        THEN\r
+       space\r
        flushemit\r
 ;\r
 \r
        flushemit\r
 ;\r
 \r
index 7cfef67..82b8c3d 100644 (file)
@@ -2,6 +2,11 @@ Release History for pForth - a Portable ANS-like Forth written in ANSI 'C'
 \r
 Documentation for pForth at http://www.softsynth.com/pforth/\r
 \r
 \r
 Documentation for pForth at http://www.softsynth.com/pforth/\r
 \r
+V24 2/20/09\r
+       - Fixed Posix IO on Mac. ?TERMINAL was always returning true.\r
+       - ACCCEPT now emits a space at end of line before output.\r
+       - Fixed RESIZE because it was returning the wrong address.\r
+\r
 V23 8/4/2008\r
        - Removed -v option from mkdir in build/unix/Makefile. It was not supported on FreeBSD.\r
          Thank you Alexsej Sauchdev for reporting this.\r
 V23 8/4/2008\r
        - Removed -v option from mkdir in build/unix/Makefile. It was not supported on FreeBSD.\r
          Thank you Alexsej Sauchdev for reporting this.\r
@@ -15,7 +20,7 @@ V22  (unreleased)
        - Modified ACCEPT so that a line at the end of a file that does NOT have a line\r
            terminator will now be processed.\r
        - Use _getch(), _putch(), and _kbhit() so that KEY, EMIT and ?TERMINAL will work on PC.\r
        - Modified ACCEPT so that a line at the end of a file that does NOT have a line\r
            terminator will now be processed.\r
        - Use _getch(), _putch(), and _kbhit() so that KEY, EMIT and ?TERMINAL will work on PC.\r
-       - Fixed  : foo { -- } 55 ;  - was entering local frame but not exiting.\r
+       - Fixed  : foo { -- } 55 ;  - Was entering local frame but not exiting. Now prints error.\r
     - Redefined MAKE_ID to protect it from 16 bit ints\r
     - John Providenza says "If you split local variables onto 2 lines, PForth crashes." Fixed. Also allow \\r
     - Fixed float evaluation in EVALUATE in "quit.fth".\r
     - Redefined MAKE_ID to protect it from 16 bit ints\r
     - John Providenza says "If you split local variables onto 2 lines, PForth crashes." Fixed. Also allow \\r
     - Fixed float evaluation in EVALUATE in "quit.fth".\r