aboutsummaryrefslogtreecommitdiff
path: root/gdb/tid-parse.h
blob: bc70b2d4e4c30c205e0c0b7eba7f32c4af401433 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* TID parsing for GDB, the GNU debugger.

   Copyright (C) 2015-2019 Free Software Foundation, Inc.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#ifndef TID_PARSE_H
#define TID_PARSE_H

#include "cli/cli-utils.h"

struct thread_info;

/* Issue an invalid thread ID error, pointing at STRING, the invalid
   ID.  */
extern void ATTRIBUTE_NORETURN invalid_thread_id_error (const char *string);

/* Parse TIDSTR as a per-inferior thread ID, in either INF_NUM.THR_NUM
   or THR_NUM form.  In the latter case, the missing INF_NUM is filled
   in from the current inferior.  If ENDPTR is not NULL,
   parse_thread_id stores the address of the first character after the
   thread ID.  Either a valid thread is returned, or an error is
   thrown.  */
struct thread_info *parse_thread_id (const char *tidstr, const char **end);

/* Parse a thread ID or a thread range list.

   A range will be of the form

     <inferior_num>.<thread_number1>-<thread_number2>

   and will represent all the threads of inferior INFERIOR_NUM with
   number between THREAD_NUMBER1 and THREAD_NUMBER2, inclusive.
   <inferior_num> can also be omitted, as in

     <thread_number1>-<thread_number2>

   in which case GDB infers the inferior number from the default
   passed to the constructor or to the last call to the init
   function.  */
class tid_range_parser
{
public:
  /* Default construction.  Must call init before calling get_*.  */
  tid_range_parser () {}

  /* Calls init automatically.  See init for description of
     parameters.  */
  tid_range_parser (const char *tidlist, int default_inferior);

  /* Reinitialize a tid_range_parser.  TIDLIST is the string to be
     parsed.  DEFAULT_INFERIOR is the inferior number to assume if a
     non-qualified thread ID is found.  */
  void init (const char *tidlist, int default_inferior);

  /* Parse a thread ID or a thread range list.

     This function is designed to be called iteratively.  While
     processing a thread ID range list, at each call it will return
     (in the INF_NUM and THR_NUM output parameters) the next thread ID
     in the range (irrespective of whether the thread actually
     exists).

     At the beginning of parsing a thread range, the char pointer
     PARSER->m_cur_tok will be advanced past <thread_number1> and left
     pointing at the '-' token.  Subsequent calls will not advance the
     pointer until the range is completed.  The call that completes
     the range will advance the pointer past <thread_number2>.

     This function advances through the input string for as long you
     call it.  Once the end of the input string is reached, a call to
     finished returns false (see below).

     E.g., with list: "1.2 3.4-6":

     1st call: *INF_NUM=1; *THR_NUM=2 (finished==0)
     2nd call: *INF_NUM=3; *THR_NUM=4 (finished==0)
     3rd call: *INF_NUM=3; *THR_NUM=5 (finished==0)
     4th call: *INF_NUM=3; *THR_NUM=6 (finished==1)

     Returns true if a thread/range is parsed successfully, false
     otherwise.  */
  bool get_tid (int *inf_num, int *thr_num);

  /* Like get_tid, but return a thread ID range per call, rather then
     a single thread ID.

     If the next element in the list is a single thread ID, then
     *THR_START and *THR_END are set to the same value.

     E.g.,. with list: "1.2 3.4-6"

     1st call: *INF_NUM=1; *THR_START=2; *THR_END=2 (finished==0)
     2nd call: *INF_NUM=3; *THR_START=4; *THR_END=6 (finished==1)

     Returns true if parsed a thread/range successfully, false
     otherwise.  */
  bool get_tid_range (int *inf_num, int *thr_start, int *thr_end);

  /* Returns true if processing a star wildcard (e.g., "1.*")
     range.  */
  bool in_star_range () const;

  /* Returns true if parsing has completed.  */
  bool finished () const;

  /* Return the current token being parsed.  When parsing has
     finished, this points past the last parsed token.  */
  const char *cur_tok () const;

  /* When parsing a range, advance past the final token in the
     range.  */
  void skip_range ();

  /* True if the TID last parsed was explicitly inferior-qualified.
     IOW, whether the spec specified an inferior number
     explicitly.  */
  bool tid_is_qualified () const;

private:
  /* No need for these.  They are intentionally not defined anywhere.  */
  tid_range_parser (const tid_range_parser &);
  tid_range_parser &operator= (const tid_range_parser &);

  bool get_tid_or_range (int *inf_num, int *thr_start, int *thr_end);

  /* The possible states of the tid range parser's state machine,
     indicating what sub-component are we expecting.  */
  enum
    {
      /* Parsing the inferior number.  */
      STATE_INFERIOR,

      /* Parsing the thread number or thread number range.  */
      STATE_THREAD_RANGE,

      /* Parsing a star wildcard thread range.  E.g., "1.*".  */
      STATE_STAR_RANGE,
    } m_state;

  /* The string being parsed.  When parsing has finished, this points
     past the last parsed token.  */
  const char *m_cur_tok;

  /* The range parser state when we're parsing the thread number
     sub-component.  */
  number_or_range_parser m_range_parser;

  /* Last inferior number returned.  */
  int m_inf_num;

  /* True if the TID last parsed was explicitly inferior-qualified.
     IOW, whether the spec specified an inferior number
     explicitly.  */
  bool m_qualified;

  /* The inferior number to assume if the TID is not qualified.  */
  int m_default_inferior;
};


/* Accept a string-form list of thread IDs such as is accepted by
   tid_range_parser.  Return true if the INF_NUM.THR.NUM thread is in
   the list.  DEFAULT_INFERIOR is the inferior number to assume if a
   non-qualified thread ID is found in the list.

   By definition, an empty list includes all threads.  This is to be
   interpreted as typing a command such as "info threads" with no
   arguments.  */
extern int tid_is_in_list (const char *list, int default_inferior,
			   int inf_num, int thr_num);

#endif /* TID_PARSE_H */
8'>618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
#!/bin/sh
### Copyright (C) 1991, 1992, Cygnus Support
### All Rights Reserved.

### This really needs to nestle up snuggly to the Release notes.  If you change
### this script, please be sure the release notes get coordinated too.

set -e

### this is our version number.
VERSION=cygnus-sol2-||RELNO||

### this is the default installation repository. We use this to test whether or
### not GCC_EXEC_PREFIX should be set when doing "Install test comp-tools".
#INSTALLDIR_DEFAULT=/giga/rich/tmp/installdir
INSTALLDIR_REAL=/opt
INSTALLDIR_DEFAULT=${INSTALLDIR_REAL}
### this is where we install into.  (useful for testing).
INSTALLDIR=${INSTALLDIR_DEFAULT}

### where to write the log files
LOGDIR=${INSTALLDIR}/${VERSION}

### who to call in bad situations
HOTLINE="the Cygnus Support Hotline at +1 415 322 7836"

### what the release doc is called and a few sections thereof
NOTES="the Installation Notes"
CHANGING_PATHS="\"Changing the Paths\""
NO_ACCESS="\"No Access to ${INSTALLDIR}\?\""
MIGHT_WRONG="\"Some Things that Might go Wrong\""
WHY_FIXINCLUDES="Why Convert System Header Files\?"
ANOTHER_TAPE="\"Steps to install with another machine\'s tape drive\""

### for debugging
#PATH=/bin:/usr/bin ; export PATH

### default the tape device
case "${TAPE}" in
  "") TAPE=||DEVdflt|| 
      ;;
  *) 
      ;;
esac # ${TAPE}

### clear and/or initialize some variables
ARCH=
TOOLS=
FTPRELEASE=no

REMOVE=no
EXTRACT=no
FIXINCLUDES=no
TESTINSTALLATION=no

INSTALLHOST=default
ERROR=

### where the binaries are in the release
#EXECDIR=${VERSION}/H-${INSTALLHOST}
EXECDIR=${VERSION}

### some tool defaults
### perhaps these should be hard coded to absolute paths instead?
TAR=tar
TARKEYS="xvvopf -"
SED=sed
MT=mt

### trigger words on the command line are:
###     bin, src
###     emacs, comp-tools
###     -tape=/dev/device
###     -installdir=/foo
###     extract, fixincludes, test-installation, remove

for arg in $* ; do
        case "${arg}" in
### options
        -tape=* | --tape=* | --tap=* | --ta=* | --t=*)
                TAPE=`echo ${arg} | ${SED} 's/-*t[a-z]*=//'`
                ;;

        -installdir=* | --installdir=* | --installdi=* | --installd=* | --install=* | --instal=* | --insta=* | --inst=* | --ins=* | --in=* | --i=*)
                INSTALLDIR=`echo ${arg} | ${SED} 's/-*i[a-z]*=//'`
		# we will make it an absolute path shortly.
                ;;

### actions
        *remove* | rm | -rm | --rm)     ACTIONS="${ACTIONS} rm" ;;
        *extract*)      ACTIONS="${ACTIONS} extract" ;;
        *fix*)          ACTIONS="${ACTIONS} fix" ;;
        *test*)         ACTIONS="${ACTIONS} test" ;;
### hosts
        *src* | *sour*) ARCH="${ARCH} src" ;;
        *bin*)          ARCH="${ARCH} bin" ;;

### packages
        *emacs*)        TOOLS="${TOOLS} emacs" ;;
        *comp*)         TOOLS="${TOOLS} comp" ;;
        *help*) ERROR=true ;;
        *)
                echo '***' I do not understand the option \"${arg}\".
                ERROR=true
                ;;
        esac # ${arg}
done # arg in $*

###
###
### check for a myriad of sins
###
###

if [ ! -d "${INSTALLDIR}" ] ; then
	echo '*** ' Can not cd to \"${INSTALLDIR}\" because it does not exist.
	echo '*** ' Try creating it with \"mkdir ${INSTALLDIR}\" and then try running Install again.
	exit 1
else
	if (cd "${INSTALLDIR}") ; then 
		true
	else
		echo '*** ' Can not cd to \"${INSTALLDIR}\" because I do not have execute permission.
		ls -lad ${INSTALLDIR}
		echo '*** ' Please fix this and then try running Install again.
		exit 1
	fi   # ! cd ${INSTALLDIR}
fi   # ! -d ${INSTALLDIR}

# Make INSTALLDIR absolute (parts below might need it that way).
# FIXME, do they really?
# FIXME, handle pwd failure from upper dir permission
INSTALLDIR=`cd ${INSTALLDIR} ; pwd`
LOGDIR=${INSTALLDIR}/${VERSION}

case "${ERROR}" in
  "")
### default tools
        case "${TOOLS}" in
          "") TOOLS="||BUNDLE||" ;;
          *) ;;
        esac # ${TOOLS}

        INSTALLHOST=

### decide where we are: try arch first.
        if (arch) > /dev/null 2>&1 ; then
                MAYBE=`arch`
        else
                true
        fi # (arch)

        case "${MAYBE}" in
          sun3) INSTALLHOST=${MAYBE} 
		;;
          *)
### next try uname
                if (uname > /dev/null) 2>&1 ; then
                        UNAME=`echo \`uname -s\`\`uname -m\`\`uname -r\``
                else
                        UNAME="machine without a uname command (type of machine unknown)"
                fi # (uname)

### map into names we recognize
                case "${UNAME}" in
                  AIX*)
                  	INSTALLHOST=rs6000
                        MT=tctl
                        ;;
                  ULTRIXRISC)     INSTALLHOST=decstation ;;
                  SunOSsun4*5*)   INSTALLHOST=sparc-sun-solaris2 ;;
                  SunOSsun4*)     INSTALLHOST=sun4 ;;
                  SunOSsun3*)     INSTALLHOST=sun3 ;;
                  IRIX*)          INSTALLHOST=iris4 ;;
                  *)              INSTALLHOST=unknown ;;
                esac # ${UNAME}
                ;;
        esac # ${MAYBE}

### default arch
        case "${ARCH}" in
          "")     ARCH="bin src" ;;
          *) ;;
        esac # ${ARCH}

### default actions

        case "${ACTIONS}" in
          "")
                case "${FTPRELEASE}" in
                  "yes") ACTIONS="test" ;;
                  "no" ) ACTIONS="extract test" ;;
                esac # ${FTPRELEASE}


### fixincludes only if comp-tools
                for tool in ${TOOLS} ; do
                        case ${tool} in
                          comp)
                                if echo ${ARCH} | grep bin > /dev/null 2>&1 ; then
                                        ACTIONS="${ACTIONS} fix"
                                fi
                                ;;
                          *) ;;
                        esac # ${TOOLS}
                done # for tool in ${TOOLS}
                ;;
        *) ;;
        esac # ${ACTIONS}
        ;;
  *) ;;
esac  # ${ERROR}

case "${ERROR}" in
  "")
### if binaries are not intended for this machine
        case "${INSTALLHOST}" in
        "||HOSTstr||") ### binaries are intended for this machine
                for action in ${ACTIONS} ; do
                        case ${action} in
                        test)
                                for tool in ${TOOLS} ; do
					OURWD=`(cd ${INSTALLDIR}; pwd) 2>/dev/null`
					DEFAULTWD=`(cd ${INSTALLDIR_REAL}; pwd) 2>/dev/null`
                                        case ${tool} in
                                        comp)
                                                case "${OURWD}" in
                                                  "${DEFAULTWD}") ;;
                                                  *)
        echo '***' If you want to use the compilation tools in an alternate
        echo '***   ' directory, GCC_EXEC_PREFIX must be set.  You probably
        echo '***   ' want to set it with:
        echo GCC_EXEC_PREFIX=${INSTALLDIR}/${EXECDIR}/lib/gcc-lib/||HOSTstr||/||GCCvn||/ ; export GCC_EXEC_PREFIX
        GCC_EXEC_PREFIX=${INSTALLDIR}/${EXECDIR}/lib/gcc-lib/||HOSTstr||/||GCCvn||/ ; export GCC_EXEC_PREFIX
        echo '***   ' This is what I will use for the installation tests.
						   # skip C++ msg on Solaris
						   case "${INSTALLHOST}" in
						   sparc-sun-solaris2) ;;
						   *)
        echo '***   ' And for g++ I will use the options:
        echo '***   '   -I${INSTALLDIR}/${EXECDIR}/lib/g++-include
        echo '***   '        -L${INSTALLDIR}/${EXECDIR}/lib
							;;
						   esac # ${INSTALLHOST}
        echo '***   ' For further help, please refer to ${CHANGING_PATHS}
        echo '***   ' in ${NOTES}.

        GPLUSOPTIONS="-I${INSTALLDIR}/${EXECDIR}/lib/g++-include -L${INSTALLDIR}/${EXECDIR}/lib"
                                                  ;;
                                                esac # ${INSTALLDIR}
                                                ;;
                                        emacs)
                                                case "${OURWD}" in
                                                  "${DEFAULTWD}") ;;
                                                  *)
                                                        echo '***' I cannot test Emacs.
                                                        echo '***   ' The provided Emacs binary can only run from the default
                                                        echo '***   ' installation directory.  If you wish to run emacs, please
                                                        echo '***   ' refer to ${CHANGING_PATHS} in ${NOTES}.
                                                        exit 1
                                                        ;;
                                                esac # ${INSTALLDIR}
                                                ;;
                                          *) true ;;
                                        esac # ${tool}
                                done # for tool in ${TOOLS}
                                ;;
                          *) true ;;
                        esac # ${action}
                done # for action in ${ACTIONS}
                ;;

        *)
                for action in ${ACTIONS} ; do
                        case ${action} in
                          rm | extract)   true ;;
                          fix)
                                if echo ${TOOLS} | grep comp > /dev/null ; then
                                        NOTFIXED="fixincludes"
                                        if echo ${ACTIONS} | grep test > /dev/null ; then
                                                JOINER=" or "
                                        else
                                                true
                                        fi # echo ${ACTIONS}
                                else
#                                       echo '***' If you only install Emacs you do not need to run fixincludes.
#                                       ERROR=true
                                        true
                                fi # echo ${TOOLS}
                                ;;
                          test)   NOTTESTED="the installation tests" ;;
                        esac # ${action}
                done # for action in ${ACTIONS}
                ;;
        esac # ${INSTALLHOST}
        ;;
  *) ;;
esac # ${ERROR}

if [ -n "${NOTFIXED}" -o -n "${NOTTESTED}" ] ; then
        case "${INSTALLHOST}" in
          "||HOSTstr||") ;;
          *)
                echo '***   ' This machine appears to be a \"${INSTALLHOST}\".
                echo '***   ' You may still run \"$0 -extract ...\" on this machine and then
                echo '***   ' run the other steps on the machine on which you wish to install.
                echo '***   ' You will need to do these steps separately.
                echo '***   ' For more information, please refer to
                echo '***   ' ${ANOTHER_TAPE} in ${NOTES}.
                ERROR=true
                ;;
        esac # ${INSTALLHOST}
fi # [ -n ${NOTFIXED -o -n ${NOTTESTED} ]

### if we can't read the tape drive...
popdir=`pwd`

if [ ! -d "${LOGDIR}" ] ; then
	if mkdir ${LOGDIR}; then
		true
	else
		echo '*** ' Can not write logs to \"${LOGDIR}\" because it does not exist.
		echo '*** ' Try creating it with \"mkdir ${LOGDIR}\" and then try running Install again.
		exit 1
	fi
else
        if [ ! -w "${LOGDIR}" ] ; then
                echo '*** ' Can not write logs to \"${LOGDIR}\" because I do not have write permission.
                ls -lad ${LOGDIR}
                echo '*** ' Please fix this and then try running Install again.
                exit 1
        fi   # ! -r ${LOGDIR}
fi   # ! -d ${LOGDIR}


cd ${INSTALLDIR}

### There is a window here that I don't know how to handle gracefully from
### shell.  If the directory DID exist and WAS executable but dissappeared
### before we could cd into it, we're kinda hosed.  If you get a call about
### this, make sure the directory exists, is readable, is executable, is the
### either the default installation directory or the -installdir=directory
### given on the command line.  Then ask them to just try again.  A few times.
### If you get the same error every time, we've got a very strange bug.  I
### can't help you.

if [ "$?" != "0" ] ; then
        echo '***' Cannot cd to \"${INSTALLDIR}\".  This is a problem.
        echo '***   ' For further help, please refer to
        echo '***   ' ${NO_ACCESS} in ${NOTES} or call
        echo '***   ' ${HOTLINE}
        exit 1
fi

if echo ${ACTIONS} | grep extract > /dev/null ; then
        if [ -z "${ERROR}" -a ! -r "${TAPE}" ] ; then
        ### try checking for a relative tape path
                if [ -r ${popdir}/${TAPE} ] ; then
                        TAPE=${popdir}/${TAPE}
                        echo '***' Using TAPE device \"${TAPE}\".
                else
                        echo '***' Can not read from TAPE device, \"${TAPE}\".
                        cd ${popdir} ; ls -lasd ${TAPE}
                        echo '***   ' Try using \"./Install -tape=/dev/something ...\" to name your tape
                        echo '***   ' drive or refer to ${MIGHT_WRONG} in
                        echo '***   ' ${NOTES}.
                        exit 1
                fi  # ! -r ${popdir}/${TAPE}
        fi   # -z ${ERROR}
fi   # extract in ${ACTIONS}

cd ${popdir}

### bail out

case "${ERROR}" in
"") ;;
*)
        cat <<EOF
You may supply at least one format on the command line.  Recognized formats
are:
    binaries    for binaries
    source      for source code
The default is both source and binaries.

You may also supply actions.  Recognized actions are:
    extract     read the appropriate files from tape
    fixincludes build a directory of corrected header files for comp-tools 
    test        run a very brief verification of your installation
Default actions are extract, fixincludes, and test, although fixincludes is not
necessary for emacs.

There are two other options:
    -tape=DEVICE   asks Install to read the necessary files from DEVICE. The
                   default DEVICE is ||DEVdflt||, the ||TAPdflt||, cartridge tape
                   drive on most ||HOSTstr||s.
    -installdir=DIRECTORY       asks Install to install files into DIRECTORY.
                                The default DIRECTORY is ${INSTALLDIR_DEFAULT}.
No action has been taken.
EOF
        exit 1
        ;;
esac


###
###
### build a file list
###     (easy this round because we have only one package).
###

FILE_LIST=
TRIGGERS=

for arch in ${ARCH} ; do
        case ${arch} in
        bin)
                FILE_LIST="${FILE_LIST} \
                        ${VERSION}/Install \
                        ${VERSION}/CYGNUS \
                        ${EXECDIR}/lib \
                        ${EXECDIR}/bin \
                        ${VERSION}/include \
                        ${VERSION}/info \
                        ${VERSION}/lib \
                        ${VERSION}/man"
                for tool in ${TOOLS} ; do
                        case ${tool} in
                        comp)   TRIGGERS="${TRIGGERS} ${EXECDIR}/bin/gcc" ;;
                        emacs)  TRIGGERS="${TRIGGERS} ${EXECDIR}/bin/emacs" ;;
                        *)
                                echo '***' Oops.  Sanity failure on triggers for binaries for ${tool}.
                                exit 1
                                ;;
                        esac
                done
                ;;
        src)
                FILE_LIST="${FILE_LIST} \
                        ${VERSION}/Install \
                        ${VERSION}/CYGNUS \
                        ${VERSION}/src"
                for tool in ${TOOLS} ; do
                        case ${tool} in
                        comp)   TRIGGERS="${TRIGGERS} ${VERSION}/src/gcc/gcc.c" ;;
                        emacs)  TRIGGERS="${TRIGGERS} ${VERSION}/src/emacs/src/emacs.c" ;;
                        *)
                                echo '***' Oops.  Sanity failure on triggers for source for ${tool}.
                                exit 1
                                ;;
                        esac
                done
                ;;
        *)
                echo '***' Oops.  Sanity failure on triggers for arch ${arch}.
                ;;
        esac
done

###
###
### removal
###
###

if echo ${ACTIONS} | grep rm > /dev/null 2>&1 ; then
        if [ ! -d "${INSTALLDIR}" ] ; then
                echo '***' Cannot remove anything from \"${INSTALLDIR}\" because it does not exist.
                echo '***   ' You probably do not need to remove anything.
        else
                popdir=`pwd`
                if [ ! -d "${INSTALLDIR}" ] ; then
                        echo '***' Can not cd to \"${INSTALLDIR}\" because it does not exist.
                        echo '***   ' You probably do not need to remove anything.
                        exit 1
                else
                        if [ ! -r "${INSTALLDIR}" ] ; then
                                echo '***' Can not cd to \"${INSTALLDIR}\" because I do not have execute permission.
                                ls -lad ${INSTALLDIR}
                                echo '***   ' Please fix this and then try running Install again.  For
                                echo '***   ' more information, please refer to ${NO_ACCESS}
                                echo '***   ' in ${NOTES}.
                                exit 1
                        fi
                fi

                cd ${INSTALLDIR}

### see also the above note about the timing window.

                if [ "$?" != "0" ] ; then
                        echo '***' Cannot cd to \"${INSTALLDIR}\".  This is a problem.
                        echo '***   ' For further help, please refer to
                        echo '***   ' ${NO_ACCESS} in ${NOTES} or call
                        echo '***   ' ${HOTLINE}
                        exit 1
                else
                        true
                fi

                if [ ! -d "${VERSION}" ] ; then
                        echo '***' Cannot remove anything from \"${INSTALLDIR}/${VERSION}\" because it does not exist.
                        echo '***   ' You probably do not need to remove anything.
                        exit 1
                else
                        true
                fi

                echo Removing from \"${INSTALLDIR}\"...

                if rm -rf ${FILE_LIST} ; then
                        # if neither binaries nor source are installed, remove installdir
                        if [ -d ${INSTALLDIR}/${EXECDIR} \
                                -o -d ${INSTALLDIR}/${VERSION}/src ] ; then
                                true
                        else
                                if rm -rf "${INSTALLDIR}/${VERSION}" ; then
                                        true
                                else
                                        if [ ! -w "${INSTALLDIR}" ] ; then
                                                echo '***' I can not remove ${INSTALLDIR}/${VERSION}
                                                echo '***   ' because I do not have write access to \"${INSTALLDIR}\"
                                                echo '***   ' Please fix this and try running Install again.  For more information
                                                echo '***   ' please refer to ${NO_ACCESS} in ${NOTES}.
                                                exit 1
                                        else
                                                echo '***' I do not know why I can not remove ${INSTALLDIR}/${VERSION}.  This is
                                                echo '***   ' probably not a problem.
                                        fi
                                        exit 1
                                fi
                        fi

                        echo Removed.
                else
                        echo '***' There appears to have been a removal error.
                        echo '***   ' Chances are that this is not a problem, but you might try removing
                        echo '***   ' again.
                        exit 1
                fi
        fi
        echo Cygnus Support software distribution removed!
else
        true
fi # if removing

###
###
### extraction
###
###

if echo ${ACTIONS} | grep extract > /dev/null 2>&1 ; then
        if [ ! -d "${INSTALLDIR}" ] ; then
                echo Trying to create \"${INSTALLDIR}\"...
                if mkdir ${INSTALLDIR} ; then
                        echo Created \"${INSTALLDIR}\".
                else
                        echo '***' I can not make directory, \"${INSTALLDIR}\".

### attempt to diagnose...

                        DIR=`echo ${INSTALLDIR} | ${SED} -e 's:/[^/]*$::'`
                        if [ ! -d "${DIR}" ] ; then
                                echo '***   ' It looks as though \"${DIR}\" does not even exist.
                                exit 1
                        else
                                if [ ! -w "${DIR}" ] ; then
                                        echo '***   ' It looks as though you do not have write access to \"${DIR}\".
                                        echo '***   ' Please fix this and try running Install again.  For more information
                                        echo '***   ' please refer to ${NO_ACCESS} in ${NOTES}.
                                        exit 1
                                else
                                        echo '***   ' I do not know why I can not create \"${INSTALLDIR}\".  This is a problem.
                                        echo '***   ' Please call ${HOTLINE}
                                        exit 1
                                fi  # ! -w ${DIR}
                        fi  # ! -d ${DIR}
                fi  # mkdir ${INSTALLDIR}
        else
                true
        fi  # ! -d ${INSTALLDIR}

        cd ${INSTALLDIR}

        if [ "$?" = "0" ] ; then
                for trigger in ${TRIGGERS} ; do
                        if [ -r "${trigger}" ] ; then
                                echo '***' \"${INSTALLDIR}/${trigger}\" exists and I will not overwrite it.
                                echo '***   ' If you really want to install it again, please remove it first.
                                exit 1
                        else
                                true
                        fi  # -r ${trigger}
                done  # for trigger
        else
                echo '***' I can not cd to \"${INSTALLDIR}\".

### attempt to diagnose...

                if [ ! -r "${INSTALLDIR}" ] ; then
                        echo '***   ' It looks as though you do not have execute permission to \"${INSTALLDIR}\".
                else
                        true
                fi  # ! -r ${INSTALLDIR}

                echo '***   ' For further help, please refer to
                echo '***   ' ${NO_ACCESS} in ${NOTES}.
                exit 1
        fi  # status is zero


### remove redundant names from the list
        echo ${FILE_LIST} ${COMMONS} ${EMACSHIBIN} | tr ' ' '
' | sort | uniq > ${LOGDIR}/extract_list

        echo It will take some time for me to read the tape.
        echo Verbose output will be saved in ${LOGDIR}/tar.log
        echo Extracting into \"${INSTALLDIR}\"... 

### make sure things come off the tape as they were written, but minus what could be a security hole.
        umask 0

### using the no rewind device, so rewind and fsf to be sure.

        if ${MT} -f ${TAPE} rewind > /dev/null 2>&1 ; then
                if ${MT} -f ${TAPE} fsf 1 ; then
                        true
                else
                        echo '***' Could not forward space tape device \"${TAPE}\".
                        exit 1
                fi  
        else
                if test -r ${TAPE} ; then
                        true
                else
                        echo '***' Could not rewind tape device \"${TAPE}\".
                        exit 1
                fi
        fi  # mt ${TAPE} rewind

        if dd if=${TAPE} bs=124b | compress -d | ${TAR} ${TARKEYS} `cat ${LOGDIR}/extract_list` > ${LOGDIR}/tar.log 2>&1 && test -d ${VERSION} ; then
		if [ -d ${INSTALLDIR}/${EXECDIR}/bin ] ; then
			echo Extracted.
		else
			echo '***' The extraction has failed.  The directory
			echo '***' ${INSTALLDIR}/${EXECDIR}/bin was not extracted.
			echo '***   ' The output from the tar command has been logged in ${LOGDIR}/tar.log
			echo '***   ' I do not know how to continue until this problem has been
			echo '***   ' corrected.  If you do not know how to fix it either, please
			echo '***   ' call ${HOTLINE}.
			exit 1
		fi

                if (${MT} -f ${TAPE} rewind > /dev/null 2>&1) ; then
                        true
                else
                        true
                fi  # mt rewind
        else
                echo '***' There appears to have been an extraction error.
                echo '***   ' The output from the tar command has been logged in ${LOGDIR}/tar.log
                echo '***   ' I do not know how to continue until this problem has been
                echo '***   ' corrected.  If you do not know how to fix it either, please
                echo '***   ' call ${HOTLINE}.
                exit 1
        fi  # dd | compress | tar ....

        rm -f ${LOGDIR}/extract_list
        echo Cygnus Support software distribution extracted!
else
        true
fi   # extraction in actions

###
###
### fixincludes
###
###

if echo ${ACTIONS} | grep fix > /dev/null 2>&1 ; then
        echo Running fixincludes for ${INSTALLHOST}.
        echo Verbose output will be stored in ${LOGDIR}/fixincludes.log
        echo This will take some time.
        LIB=${INSTALLDIR}/${EXECDIR}/lib/gcc-lib/||HOSTstr||/||GCCvn||/include ; export LIB

	if mkdir ${LIB}/tmpdir && mv ${LIB}/*.h ${LIB}/tmpdir ; then
		if ${INSTALLDIR}/${VERSION}/lib/fixincludes ${LIB} /usr/include ${INSTALLDIR}/${VERSION}/src/gcc > ${LOGDIR}/fixincludes.log ; then
			mv ${LIB}/tmpdir/* ${LIB} && rmdir ${LIB}/tmpdir 
			echo Finished with fixincludes.
		else
			echo '***' There seems to have been a problem with fixincludes.
			echo '***   ' The verbose output from the fixincludes script has been logged in
			echo '***   ' ${INSTALLDIR}/${VERSION}/fixincludes.log.
			echo '***   ' I do not know how to continue until this problem has been
			echo '***   ' corrected.  If you do not know how to fix it either, please
			echo '***   ' call ${HOTLINE}.
			mv ${LIB}/tmpdir/* ${LIB} && rmdir ${LIB}/tmpdir
			exit 1
		fi  # 
	else
                echo '***' Not able to create the temporary include dir
                echo '***  ' Please ensure that write permissions for
                echo '***  ' ${LIB} are allowed.
                echo '***  ' Or call ${HOTLINE} for more information.
                exit 1
	fi	
        echo Fixed include files installed!
else
        true
fi  # fix in actions

###
###
### testing the installation
###
###

if echo ${ACTIONS} | grep test > /dev/null 2>&1 && echo ${ARCH} | grep bin > /dev/null 2>&1 ; then
	popdir=`pwd`
	cd ${LOGDIR}
        for tool in ${TOOLS} ; do
                case ${tool} in
                  comp)
                        if [ -f ${INSTALLDIR}/${EXECDIR}/bin/gcc ] ; then
                        cat > ${LOGDIR}/hello.c <<'e!o!f'
#include <stdio.h>

extern int printf();

int main(int argc, char **argv) {
        (void) printf("hello: The compilation tools appear to be installed correctly on your %s.\n",
                MACHINE);
        return(0);
} /* main() */
e!o!f
                        if ${INSTALLDIR}/${EXECDIR}/bin/gcc -Wall -O -g \
                                -DMACHINE=\"${INSTALLHOST}\" ${LOGDIR}/hello.c -o ${LOGDIR}/hello ; then
                                if ${LOGDIR}/hello ; then
                                        echo This is good.
                                else
                                        echo '***' Hello.c fails to run.  This is a problem.
                                        echo '***   ' Please call ${HOTLINE}
                                        exit 1
                                fi  # ./hello
                        else
                                echo '***' Hello.c fails to compile.  This is a problem.
                                echo '***   ' Please call ${HOTLINE}
                                exit 1
                        fi  # run gcc

### now check for fixed includes.
                        cat > ${LOGDIR}/test-ioctl.c << 'e!o!f'
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>

double atof(const char *);

#ifdef __sun__
#include <sys/filio.h>

extern int ioctl();
extern int perror();
#endif /* __sun__ */

extern int printf();

int main(int argc, char **argv) {
#ifdef __sun__
        long l;
        int fd;
        int retval;

        if ((fd = open("/dev/tty", O_RDONLY)) == -1) {
                (void) perror("test-ioctl: can't open /dev/null");
                return(1);
        } else if ((retval = ioctl(fd, FIONREAD, &l)) != 0) {
                (void) perror("test-ioctl: ioctl failed");
                (void) printf("test-ioctl: Most likely, you have not run \"Install fixincludes\" on this machine.\n");
                return(2);
        }
#endif /* __sun__ */

        printf("test-ioctl: Ansi versions of the system header files, (the fixed includes),\n");
        printf("test-ioctl: appear to be installed correctly.\n");

/* that's right.  If closing /dev/tty fails, I don't want to know about it. */

        return(0);
}
e!o!f

                        case "||HOSTstr||" in
                        sun3 | sun4 | decstation)
                                if ${INSTALLDIR}/${EXECDIR}/bin/gcc -Wall -O -g \
                                        -DMACHINE=\"${INSTALLHOST}\" ${LOGDIR}/test-ioctl.c -o ${LOGDIR}/test-ioctl ; then
                                        if ${LOGDIR}/test-ioctl ; then
                                                echo This is good.
                                        else
                                                case "$?" in
                                                1)
                                                        echo '***' test-ioctl.c fails to read /dev/tty.  If you were running Install
                                                        echo '***   ' in batch or from a daemon, please try running it again interactively.
                                                        echo '***   ' If not, please call ${HOTLINE}
                                                        exit 1
                                                        ;;
                                                2)
                                                        echo '***' test-ioctl.c fails to ioctl.
                                                        echo '***   ' Most likely you need to run \"Install fixincludes\".
                                                        echo '***   ' Please run \"Install fixincludes\" and
                                                        echo '***   ' then try this test again.  For an explanation see
                                                        echo '***   ' ${WHY_FIXINCLUDES} in ${NOTES}.
                                                        exit 1
                                                        ;;
                                                *)
                                                        echo '***' test-ioctl.c fails to run.  This is a problem.
                                                        echo '***   ' Please call ${HOTLINE}
                                                        exit 1
                                                        ;;
                                                esac  # $?
                                                exit 1
                                        fi  # test-ioctl
                                else
### this presupposes that hello.c DID compile.
                                        echo '***' test-ioctl.c fails to compile.  This is a problem.
                                        echo '***   ' Please call ${HOTLINE}
                                        exit 1
                                fi  # run gcc
                                ;;
                        iris4)
                                if [ ! -f ${INSTALLDIR}/${EXECDIR}/lib/gcc-lib/||HOSTstr||/||GCCvn||/include/sys/cfeiroute.h ]
                                then
                                        echo '***' You seem to be missing ${INSTALLDIR}/${EXECDIR}/lib/gcc-lib/||HOSTstr||/||GCCvn||/include/sys/cfeiroute.h.
                                        echo '***   ' Most likely you need to run \"Install fixincludes\".
                                        echo '***   ' Please run \"Install fixincludes\" and
                                        echo '***   ' then try this test again.  For an explanation see
                                        echo '***   ' ${WHY_FIXINCLUDES} in ${NOTES}.
                                        exit 1
                                fi  # test fixincluded file
                                ;;
			sparc-sun-solaris2)
                                if [ ! -f ${INSTALLDIR}/${EXECDIR}/lib/gcc-lib/||HOSTstr||/||GCCvn||/include/ieeefp.h ]
                                then
                                        echo '***' You seem to be missing ${INSTALLDIR}/${EXECDIR}/lib/gcc-lib/||HOSTstr||/||GCCvn||/include/ieeefp.h.
                                        echo '***   ' Most likely you need to run \"Install fixincludes\".
                                        echo '***   ' Please run \"Install fixincludes\" and
                                        echo '***   ' then try this test again.  For an explanation see
                                        echo '***   ' ${WHY_FIXINCLUDES} in ${NOTES}.
                                        exit 1
				fi
				;;

                        rs6000)
                                if [ ! -f ${INSTALLDIR}/${EXECDIR}/lib/gcc-lib/||HOSTstr||/||GCCvn||/include/piostruct.h ]
                                then
                                        echo '***' You seem to be missing ${INSTALLDIR}/${EXECDIR}/lib/gcc-lib/||HOSTstr||/||GCCvn||/include/piostruct.h.
                                        echo '***   ' Most likely you need to run \"Install fixincludes\".
                                        echo '***   ' Please run \"Install fixincludes\" and
                                        echo '***   ' then try this test again.  For an explanation see
                                        echo '***   ' ${WHY_FIXINCLUDES} in ${NOTES}.
                                        exit 1
                                fi  # test fixincluded file
                                ;;
                        esac  # ||HOSTstr||
                        else
                                true
                        fi  # test if gcc present

### now check for g++.
                        if [ -f ${INSTALLDIR}/${EXECDIR}/bin/g++ ] ; then
                                cat > ${LOGDIR}/hello.C << 'e!o!f'
#include <iostream.h>

int main(int argc, char**argv)
{
  char *machine = MACHINE;
  cout << "hello: g++ appears to be installed correctly on your "
        << machine << ".\n";
  return(0);
}
e!o!f
                                if ${INSTALLDIR}/${EXECDIR}/bin/gcc ${GPLUSOPTIONS} -Wall -O -g \
                                        -DMACHINE=\"${INSTALLHOST}\" ${LOGDIR}/hello.C -o ${LOGDIR}/Hello -lg++ ; then
                                        if ${LOGDIR}/Hello ; then
                                                echo This is good.
                                        else
                                                echo '***' hello.C fails to run.  This is a problem.
                                                echo '***   ' Please call ${HOTLINE}
                                                exit 1
                                        fi  # ./Hello
                                else
        ### this presupposes that hello.c DID compile.
                                        echo '***' hello.C fails to compile.  This is a problem.
                                        echo '***   ' Please call ${HOTLINE}
                                        exit 1
                                fi  # run g++

        ### now check for static initialization.
                                cat > ${LOGDIR}/static-init.C << 'e!o!f'
#include <iostream.h>
int Three;

struct Foo {
    Foo(int i) { Three = i; }
};

Foo foo(3);

int main(int argc, char**argv)
{
  if (Three != 3) {
        cout << "static-init: static initialization fails.\n";
        return(1);
  }

  cout << "static-init: static initialization appears to work.\n";
  return(0);
}
e!o!f
                                if ${INSTALLDIR}/${EXECDIR}/bin/gcc ${GPLUSOPTIONS} -Wall -O -g \
                                        -DMACHINE=\"${INSTALLHOST}\" ${LOGDIR}/static-init.C -o ${LOGDIR}/static-init -lg++ ; then
                                        if ${LOGDIR}/static-init ; then
                                                echo This is good.
                                        else
                                                echo '***' Static initialization is not working.  This is a problem.
                                                echo '***   ' Please call ${HOTLINE}
                                                exit 1
                                        fi  # run static-init
                                else
        ### this presupposes that it DID compile.
                                        echo '***' static-init.c fails to compile.  This is a problem.
                                        echo '***   ' Please call ${HOTLINE}
                                        exit 1
                                fi  # run g++
                        else # no g++, so don't test it
                                true
                        fi  #  no g++
                        ;;
                emacs)
                        cat > ${LOGDIR}/hello.el <<'e!o!f'
(server-start)
(message "Emacs appears to be installed correctly.")
(kill-emacs 0)
e!o!f
                        if ${INSTALLDIR}/${EXECDIR}/bin/emacs -batch -l ${LOGDIR}/hello.el ; then
                                echo This is good.
                        else
                                echo '***' Emacs fails to run.  This is a problem.
                                echo '***   ' Please call ${HOTLINE}
                                exit 1
                        fi
			;;
		src)  	# if anyone can tell me how to test the installation of source...
			true 
			;;
		*)
			echo '***' I do not know how to test for tool \"${tool}\" because I have never
			echo '***   ' heard of it.  This is a problem.  Please call ${HOTLINE}.
			exit 1
			;;
		esac
	done
	rm -f hello* test-ioctl* static-init* Hello*
	cd ${popdir}
	echo Cygnus Support software distribution tested!
else
	true
fi

echo Done.

exit 0

###
### Local Variables:
### comment-column: 0
### fill-column: 131
### End:
###

### End of Install