home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / stack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-21  |  1.1 KB  |  61 lines

  1. /* stack.c (emx+gcc) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <signal.h>
  7. #include <alloca.h>
  8.  
  9. void print_esp (void)
  10. {
  11.   unsigned long n;
  12.  
  13.   n = (unsigned long)&n;
  14.   printf ("ESP = 0x%.8lx\n", n);
  15. }
  16.  
  17. void mysig (int sig)
  18. {
  19.   printf ("\n---Signal\n");
  20.   exit (1);
  21. }
  22.  
  23. void test (int level)
  24. {
  25.   int n, fill_flag;
  26.   char buf[10000], *p;
  27.  
  28.   signal (SIGINT, mysig);   /* DosSetSignalExceptionFocus */
  29.   fill_flag = 0;
  30.   for (;;)
  31.     {
  32.       print_esp ();
  33.       printf ("Input(%d): ", level); fflush (stdout);
  34.       if (fgets (buf, sizeof (buf), stdin) == NULL)
  35.         exit (0);
  36.       p = strchr (buf, '\n');
  37.       if (p != NULL) *p = 0;
  38.       errno = 0;
  39.       if (buf[0] == 0)
  40.         break;
  41.       if (buf[0] == 'r')
  42.         test (level+1);
  43.       else if (buf[0] == 'f')
  44.         fill_flag = !fill_flag;
  45.       else if ((n = strtol (buf, &p, 0)) > 0 && errno == 0 && *p == 0)
  46.         {
  47.           p = alloca (n);
  48.           if (fill_flag)
  49.             memset (p, '*', n);
  50.         }
  51.       else
  52.         printf ("Redo!\n");
  53.     }
  54. }
  55.  
  56. int main (void)
  57. {
  58.   test (1);
  59.   return (0);
  60. }
  61.