home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / backup / star-1.3.1.tar.gz / star-1.3.1.tar / star-1.3.1 / lib / getav0.c < prev    next >
C/C++ Source or Header  |  2000-05-07  |  2KB  |  112 lines

  1. /* @(#)getav0.c    1.10 00/05/07 Copyright 1985 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)getav0.c    1.10 00/05/07 Copyright 1985 J. Schilling";
  5. #endif
  6. /*
  7.  *    Get arg vector by scanning the stack
  8.  *
  9.  *    Copyright (c) 1985 J. Schilling
  10.  */
  11. /*
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2, or (at your option)
  15.  * any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; see the file COPYING.  If not, write to
  24.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  */
  26.  
  27. #include <mconfig.h>
  28. #include <sigblk.h>
  29. #include <avoffset.h>
  30. #include <standard.h>
  31. #include <schily.h>
  32.  
  33. #if    !defined(AV_OFFSET) || !defined(FP_INDIR)
  34. #    ifdef    HAVE_SCANSTACK
  35. #    undef    HAVE_SCANSTACK
  36. #    endif
  37. #endif
  38. #ifdef    NO_SCANSTACK
  39. #    ifdef    HAVE_SCANSTACK
  40. #    undef    HAVE_SCANSTACK
  41. #    endif
  42. #endif
  43.  
  44. #ifdef    HAVE_SCANSTACK
  45.  
  46. #include <stkframe.h>
  47.  
  48. #define    is_even(p)    ((((long)(p)) & 1) == 0)
  49. #define    even(p)        (((long)(p)) & ~1L)
  50. #ifdef    __future__
  51. #define    even(p)        (((long)(p)) - 1)/* will this work with 64 bit ?? */
  52. #endif
  53.  
  54. char **getavp()
  55. {
  56.     register struct frame *fp;
  57.     register struct frame *ofp;
  58.          char    **av;
  59. #if    FP_INDIR > 0
  60.     register int    i = 0;
  61. #endif
  62.  
  63.     ofp = fp = (struct frame *)getfp();
  64.     while (fp) {
  65.  
  66. #if    FP_INDIR > 0
  67.         i++;
  68. #endif
  69.         ofp = fp;
  70.         if (!is_even(fp->fr_savfp)) {
  71.             fp = (struct frame *)even(fp->fr_savfp);
  72.             fp = (struct frame *)((SIGBLK *)fp)->sb_savfp;
  73.             continue;
  74.         }
  75.         fp = fp->fr_savfp;
  76.     }
  77.  
  78. #if    FP_INDIR > 0
  79.     i -= FP_INDIR;
  80.         ofp = fp = (struct frame *)getfp();
  81.     while (fp) {
  82.         if (--i < 0)
  83.             break;
  84.         ofp = fp;
  85.         if (!is_even(fp->fr_savfp)) {
  86.             fp = (struct frame *)even(fp->fr_savfp);
  87.             fp = (struct frame *)((SIGBLK *)fp)->sb_savfp;
  88.             continue;
  89.         }
  90.         fp = fp->fr_savfp;
  91.     }
  92. #endif
  93.  
  94.         av = (char **)ofp + AV_OFFSET;    /* aus avoffset.h */
  95.                     /* (wird generiert mit av_offset) */
  96.     return (av);
  97. }
  98.  
  99. char *getav0()
  100. {
  101.     return (getavp()[0]);
  102. }
  103.  
  104. #else
  105.  
  106. char *getav0()
  107. {
  108.     return ("???");
  109. }
  110.  
  111. #endif    /* HAVE_SCANSTACK */
  112.