octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MINGW build


From: Paul Kienzle
Subject: Re: MINGW build
Date: Mon, 23 Sep 2002 21:47:10 -0400

> > src/sysdep.cc:
> >
> >   termio stuf undefined
> >
> > => I will need to write a windows replacement for kbhit.  MinGW defines
> > termio.h, but it is empty.  I hacked around this with an #ifdef WIN32
> > but that is not the best solution.  Again, not needed for the first cut.
> >
> > src/sysdep.cc:
> >
> >   sleep undeclared
> 
> sleep is known as _sleep, and it takes milliseconds, not seconds (off by 3
> orders of magnitude bugs). I would prefer to see Sleep instead. Once your
> code is in CVS, I can probably help a bit.

Here's my patch for sleep and kbhit.  John, this repeats some bits of a
prior patch.  Let me know if you need another, and I can rediff from CVS.

I've renamed kbhit to octave_kbhit because windows has a kbhit and I
didn't want to cause confusion.  I've created octave_sleep since windows
doesn't have sleep, but instead has Sleep and _sleep in units of milliseconds.

Note the #define HAVE_SLEEP test is confusing because it is testing for
"Sleep" not "sleep".  Oh, well.

Index: configure.in
===================================================================
RCS file: /cvs/octave/configure.in,v
retrieving revision 1.366
diff -c -p -r1.366 configure.in
*** configure.in        2002/09/23 15:38:05     1.366
--- configure.in        2002/09/23 21:07:56
*************** AC_CHECK_HEADERS(termio.h, have_termio_h
*** 811,816 ****
--- 811,817 ----
  AC_CHECK_HEADERS(sgtty.h, have_sgtty_h=yes, have_sgtty_h=no)
  AC_CHECK_HEADERS(glob.h, have_glob_h=yes, have_glob_h=no)
  AC_CHECK_HEADERS(fnmatch.h, have_fnmatch_h=yes, have_fnmatch_h=no)
+ AC_CHECK_HEADERS(conio.h, have_conio_h=yes, have_conio_h=no)
  
  ### I'm told that termios.h is broken on NeXT systems.
  
*************** if test "$have_termios_h" = yes \
*** 828,834 ****
      || test "$have_sgtty_h" = yes; then
    true
  else
!   AC_MSG_ERROR([I couldn't find termios.h, termio.h, or sgtty.h!])
  fi
  
  ## I'm told that setting LIBGLOB to be $(TOPDIR)/glob/libglob.a causes
--- 829,835 ----
      || test "$have_sgtty_h" = yes; then
    true
  else
!   AC_MSG_WARN([I couldn't find termios.h, termio.h, sgtty.h or conio.h!])
  fi
  
  ## I'm told that setting LIBGLOB to be $(TOPDIR)/glob/libglob.a causes
*************** AC_SUBST(GLOB_INCFLAGS)
*** 868,877 ****
  AC_CHECK_FUNCS(atexit bcopy bzero dup2 endgrent endpwent execvp \
    fcntl fork getcwd getegid geteuid getgid getgrent getgrgid \
    getgrnam getpgrp getpid getppid getpwent \
!   getpwuid gettimeofday getuid getwd link localtime_r lstat \
    memmove mkdir mkfifo on_exit pipe poll putenv readlink rename \
    rindex rmdir select setgrent setpwent setvbuf sigaction sigpending \
!   sigprocmask sigsuspend stat strcasecmp strdup strerror strftime \
    stricmp strncasecmp strnicmp strptime symlink tempnam umask unlink \
    usleep vfprintf vsprintf vsnprintf waitpid)
  
--- 869,878 ----
  AC_CHECK_FUNCS(atexit bcopy bzero dup2 endgrent endpwent execvp \
    fcntl fork getcwd getegid geteuid getgid getgrent getgrgid \
    getgrnam getpgrp getpid getppid getpwent \
!   getpwuid gettimeofday getuid getwd _kbhit link localtime_r lstat \
    memmove mkdir mkfifo on_exit pipe poll putenv readlink rename \
    rindex rmdir select setgrent setpwent setvbuf sigaction sigpending \
!   sigprocmask sigsuspend Sleep stat strcasecmp strdup strerror strftime \
    stricmp strncasecmp strnicmp strptime symlink tempnam umask unlink \
    usleep vfprintf vsprintf vsnprintf waitpid)
  
Index: src/sysdep.cc
===================================================================
RCS file: /cvs/octave/src/sysdep.cc,v
retrieving revision 1.99
diff -c -p -r1.99 sysdep.cc
*** src/sysdep.cc       2000/06/08 14:45:56     1.99
--- src/sysdep.cc       2002/09/23 21:07:58
*************** Software Foundation, 59 Temple Place - S
*** 47,54 ****
  #include <termio.h>
  #elif defined (HAVE_SGTTY_H)
  #include <sgtty.h>
! #else
! LOSE! LOSE!
  #endif
  
  #if defined (HAVE_SYS_IOCTL_H)
--- 47,56 ----
  #include <termio.h>
  #elif defined (HAVE_SGTTY_H)
  #include <sgtty.h>
! #endif
! 
! #if defined(HAVE_CONIO_H)
! #include <conio.h>
  #endif
  
  #if defined (HAVE_SYS_IOCTL_H)
*************** raw_mode (bool on, bool wait)
*** 302,308 ****
      ioctl (tty_fd, TIOCSETN, &s);
    }
  #else
! LOSE! LOSE!
  #endif
  
    curr_on = on;
--- 304,311 ----
      ioctl (tty_fd, TIOCSETN, &s);
    }
  #else
!   warning("no support for raw mode console I/O on this system");
!   on = curr_on;  // make sure the current mode doesn't toggle
  #endif
  
    curr_on = on;
*************** LOSE! LOSE!
*** 311,318 ****
  // Read one character from the terminal.
  
  int
! kbhit (bool wait)
  {
    raw_mode (true, wait);
  
    int c = std::cin.get ();
--- 314,327 ----
  // Read one character from the terminal.
  
  int
! octave_kbhit (bool wait)
  {
+ #ifdef HAVE__KBHIT
+   if (!wait && !_kbhit())
+     c = 0;
+   else
+     c = std::cin.get ();
+ #else
    raw_mode (true, wait);
  
    int c = std::cin.get ();
*************** kbhit (bool wait)
*** 321,326 ****
--- 330,336 ----
      std::cin.clear ();
  
    raw_mode (false, true);
+ #endif /* defined(HAVE__KBHIT) */
  
    return c;
  }
*************** returning the empty string if no key is 
*** 432,438 ****
  
    if (interactive || forced_interactive)
      {
!       int c = kbhit (args.length () == 0);
  
        if (c == -1)
        c = 0;
--- 442,448 ----
  
    if (interactive || forced_interactive)
      {
!       int c = octave_kbhit (args.length () == 0);
  
        if (c == -1)
        c = 0;
*************** clc;\n\
*** 485,504 ****
          else if (xisinf (dval))
            {
              flush_octave_stdout ();
!             kbhit ();
            }
          else
            {
              int delay = NINT (dval);
              if (delay > 0)
!               sleep (delay);
            }
        }
      }
    else
      {
        flush_octave_stdout ();
!       kbhit ();
      }
  
    return retval;
--- 495,514 ----
          else if (xisinf (dval))
            {
              flush_octave_stdout ();
!             octave_kbhit ();
            }
          else
            {
              int delay = NINT (dval);
              if (delay > 0)
!               octave_sleep (delay);
            }
        }
      }
    else
      {
        flush_octave_stdout ();
!       octave_kbhit ();
      }
  
    return retval;
*************** Suspend the execution of the program for
*** 524,530 ****
            {
              int delay = NINT (dval);
              if (delay > 0)
!               sleep (delay);
            }
        }
      }
--- 534,540 ----
            {
              int delay = NINT (dval);
              if (delay > 0)
!               octave_sleep (delay);
            }
        }
      }
Index: src/sysdep.h
===================================================================
RCS file: /cvs/octave/src/sysdep.h,v
retrieving revision 1.27
diff -c -p -r1.27 sysdep.h
*** src/sysdep.h        2000/04/11 19:02:05     1.27
--- src/sysdep.h        2002/09/23 21:07:58
*************** extern void sysdep_init (void);
*** 32,38 ****
  
  extern void raw_mode (bool, bool wait = true);
  
! extern int kbhit (bool wait = true);
  
  #endif
  
--- 32,38 ----
  
  extern void raw_mode (bool, bool wait = true);
  
! extern int octave_kbhit (bool wait = true);
  
  #endif
  
Index: src/cutils.c
===================================================================
RCS file: /cvs/octave/src/cutils.c,v
retrieving revision 1.7
diff -c -p -r1.7 cutils.c
*** src/cutils.c        2000/03/23 06:47:22     1.7
--- src/cutils.c        2002/09/23 21:07:58
*************** Software Foundation, 59 Temple Place - S
*** 24,29 ****
--- 24,36 ----
  #include <config.h>
  #endif
  
+ #ifdef HAVE_SLEEP
+ /* This is checking for Sleep, not sleep!! */
+ 
+ #include <windows.h>
+ 
+ #else /* !defined(HAVE_SLEEP) */
+ 
  #ifdef HAVE_UNISTD_H
  #ifdef HAVE_SYS_TYPES_H
  #include <sys/types.h>
*************** Software Foundation, 59 Temple Place - S
*** 39,44 ****
--- 46,53 ----
  #include <sys/poll.h>
  #endif
  
+ #endif /* !defined(HAVE_SLEEP) */
+ 
  #include <stdarg.h>
  #include <stdio.h>
  #include <stdlib.h>
*************** do_octave_usleep (unsigned int useconds)
*** 72,79 ****
--- 81,101 ----
  }
  
  void
+ octave_sleep (unsigned int seconds)
+ {
+ #ifdef HAVE_SLEEP
+   Sleep(seconds*1000);
+ #else
+   sleep(seconds);
+ #endif
+ }
+ 
+ void
  octave_usleep (unsigned int useconds)
  {
+ #ifdef HAVE_SLEEP
+   Sleep(useconds/1000);
+ #else
    unsigned int sec = useconds / 1000000;
    unsigned int usec = useconds % 1000000;
  
*************** octave_usleep (unsigned int useconds)
*** 81,86 ****
--- 103,109 ----
      sleep (sec);
  
    do_octave_usleep (usec);
+ #endif
  }
  
  int
Index: src/utils.h
===================================================================
RCS file: /cvs/octave/src/utils.h,v
retrieving revision 1.64
diff -c -p -r1.64 utils.h
*** src/utils.h 2000/03/23 06:28:21     1.64
--- src/utils.h 2002/09/23 21:07:58
*************** octave_vformat (std::ostream& os, const 
*** 75,80 ****
--- 75,82 ----
  
  extern "C" void octave_usleep (unsigned int useconds);
  
+ extern "C" void octave_sleep (unsigned int seconds);
+ 
  extern "C" int octave_strcasecmp (const char *s1, const char *s2);
  
  extern "C" int octave_strncasecmp (const char *s1, const char *s2, size_t n);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]