Print this page
make: remove a bunch of unused and mis-licensed code from history


 723 
 724         /* 
 725          * Put the version number at the start of the string
 726          */
 727         MBSTOWCS(wcs_buffer, DEPINFO_FMT_VERSION);
 728         append_string(wcs_buffer, buffer, FIND_LENGTH);
 729         /* 
 730          * Add the rest of the conditional macros to the buffer
 731          */
 732         if (np->depends_on_conditional){
 733                 for (macro_list = np->conditional_macro_list; 
 734                      macro_list != NULL; macro_list = macro_list->next){
 735                         append_string(macro_list->macro_name, buffer, 
 736                                 FIND_LENGTH);
 737                         append_char((int) equal_char, buffer);
 738                         append_string(macro_list->value, buffer, FIND_LENGTH);
 739                         append_char((int) dollar_char, buffer);
 740                 }
 741         }
 742 }
 743 /*
 744  *      Copyright (c) 1987-1992 Sun Microsystems, Inc.  All Rights Reserved.
 745  *      Sun considers its source code as an unpublished, proprietary
 746  *      trade secret, and it is available only under strict license
 747  *      provisions.  This copyright notice is placed here only to protect
 748  *      Sun in the event the source is deemed a published work.  Dissassembly,
 749  *      decompilation, or other means of reducing the object code to human
 750  *      readable form is prohibited by the license agreement under which
 751  *      this code is provided to the user or company in possession of this
 752  *      copy.
 753  *      RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
 754  *      Government is subject to restrictions as set forth in subparagraph
 755  *      (c)(1)(ii) of the Rights in Technical Data and Computer Software
 756  *      clause at DFARS 52.227-7013 and in similar clauses in the FAR and
 757  *      NASA FAR Supplement.
 758  *
 759  * 1.3 91/09/30
 760  */
 761 
 762 
 763 /* Some includes are commented because of the includes at the beginning */
 764 /* #include <signal.h> */
 765 #include <sys/types.h>
 766 #include <sys/stat.h>
 767 #include <sys/param.h>
 768 /* #include <string.h> */
 769 #include <unistd.h>
 770 #include <stdlib.h>
 771 /* #include <stdio.h> */
 772 /* #include <avo/find_dir.h> */
 773 /* #ifndef TEAMWARE_MAKE_CMN
 774 #include <avo/find_dir.h>
 775 #endif */
 776 
 777 /* Routines to find the base directory name from which the various components
 778  * -executables, *crt* libraries etc will be accessed
 779  */
 780 
 781 /* This routine checks to see if a given filename is an executable or not.
 782    Logically similar to the csh statement : if  ( -x $i && ! -d $i )
 783  */
 784 
 785 static int
 786 check_if_exec(char *file)
 787 {
 788         struct stat stb;
 789         if (stat(file, &stb) < 0) {
 790                 return ( -1);
 791         }
 792         if (S_ISDIR(stb.st_mode)) {
 793                 return (-1);
 794         }
 795         if (!(stb.st_mode & S_IEXEC)) {
 796                 return ( -1);
 797         }
 798         return (0);
 799 }
 800 
 801 /* resolve - check for specified file in specified directory
 802  *      sets up dir, following symlinks.
 803  *      returns zero for success, or
 804  *      -1 for error (with errno set properly)
 805  */
 806 static int
 807 resolve (const char *indir,     /* search directory */
 808          const char *cmd,       /* search for name */
 809          char   *dir,   /* directory buffer */
 810          char   **run)  /* resultion name ptr ptr */
 811 {
 812     char               *p;
 813     int                 rv = -1;
 814     int                 sll;
 815     char                symlink[MAXPATHLEN + 1];
 816 
 817     do {
 818         errno = ENAMETOOLONG;
 819         if ((strlen (indir) + strlen (cmd) + 2) > (size_t) MAXPATHLEN)
 820             break;
 821 
 822         sprintf(dir, "%s/%s", indir, cmd);
 823         if (check_if_exec(dir) != 0)  /* check if dir is an executable */
 824         {
 825                 break;          /* Not an executable program */
 826         }
 827 
 828         /* follow symbolic links */
 829         while ((sll = readlink (dir, symlink, MAXPATHLEN)) >= 0) {
 830             symlink[sll] = 0;
 831             if (*symlink == '/')
 832                 strcpy (dir, symlink);
 833             else
 834                 sprintf (strrchr (dir, '/'), "/%s", symlink);
 835         }
 836         if (errno != EINVAL)
 837             break;
 838 
 839         p = strrchr (dir, '/');
 840         *p++ = 0;
 841         if (run)                /* user wants resolution name */
 842             *run = p;
 843         rv = 0;                 /* complete, with success! */
 844 
 845     } while (0);
 846 
 847     return rv;
 848 }
 849 
 850 /* 
 851  *find_run_directory - find executable file in PATH
 852  *
 853  * PARAMETERS:
 854  *      cmd     filename as typed by user (argv[0])
 855  *      cwd     buffer from which is read the working directory
 856  *               if first character is '/' or into which is
 857  *               copied working directory name otherwise
 858  *      dir     buffer into which is copied program's directory
 859  *      pgm     where to return pointer to tail of cmd (may be NULL
 860  *               if not wanted) 
 861  *      run     where to return pointer to tail of final resolved
 862  *               name ( dir/run is the program) (may be NULL
 863  *               if not wanted)
 864  *      path    user's path from environment
 865  *
 866  * Note: run and pgm will agree except when symbolic links have
 867  *      renamed files
 868  *
 869  * RETURNS:
 870  *      returns zero for success,
 871  *      -1 for error (with errno set properly).
 872  *
 873  * EXAMPLE:
 874  *      find_run_directory (argv[0], ".", &charray1, (char **) 0, (char **) 0,
 875  *                          getenv(NOGETTEXT("PATH")));
 876  */
 877 extern int
 878 find_run_directory (char        *cmd,
 879                     char        *cwd,
 880                     char        *dir,
 881                     char        **pgm,
 882                     char        **run,
 883                     char        *path)
 884 {
 885     int                 rv = 0;
 886     char                *f, *s;
 887     int                 i;
 888     char                tmp_path[MAXPATHLEN];
 889 
 890     if (!cmd || !*cmd || !cwd || !dir) {
 891         errno = EINVAL;         /* stupid arguments! */
 892         return -1;
 893     }
 894 
 895     if (*cwd != '/')
 896         if (!(getcwd (cwd, MAXPATHLEN)))
 897             return -1;          /* can not get working directory */
 898 
 899     f = strrchr (cmd, '/');
 900     if (pgm)                    /* user wants program name */
 901         *pgm = f ? f + 1 : cmd;
 902 
 903     /* get program directory */
 904     rv = -1;
 905     if (*cmd == '/')    /* absname given */
 906         rv = resolve ("", cmd + 1, dir, run);
 907     else if (f)         /* relname given */
 908         rv = resolve (cwd, cmd, dir, run);
 909     else {  /* from searchpath */
 910             if (!path || !*path) {      /* if missing or null path */
 911                     tmp_path[0] = '.';  /* assume sanity */
 912                     tmp_path[1] = '\0';
 913             } else {
 914                     strcpy(tmp_path, path);
 915             }
 916         f = tmp_path;
 917         rv = -1;
 918         errno = ENOENT; /* errno gets this if path empty */
 919         while (*f && (rv < 0)) {
 920             s = f;
 921             while (*f && (*f != ':'))
 922                 ++f;
 923             if (*f)
 924                 *f++ = 0;
 925             if (*s == '/')
 926                 rv = resolve (s, cmd, dir, run);
 927             else {
 928                 char                abuf[MAXPATHLEN];
 929 
 930                 sprintf (abuf, "%s/%s", cwd, s);
 931                 rv = resolve (abuf, cmd, dir, run);
 932             }
 933         }
 934     }
 935 
 936     /* Remove any trailing /. */
 937     i = strlen(dir);
 938     if ( dir[i-2] == '/' && dir[i-1] == '.') {
 939             dir[i-2] = '\0';
 940     }
 941 
 942     return rv;
 943 }
 944 


 723 
 724         /* 
 725          * Put the version number at the start of the string
 726          */
 727         MBSTOWCS(wcs_buffer, DEPINFO_FMT_VERSION);
 728         append_string(wcs_buffer, buffer, FIND_LENGTH);
 729         /* 
 730          * Add the rest of the conditional macros to the buffer
 731          */
 732         if (np->depends_on_conditional){
 733                 for (macro_list = np->conditional_macro_list; 
 734                      macro_list != NULL; macro_list = macro_list->next){
 735                         append_string(macro_list->macro_name, buffer, 
 736                                 FIND_LENGTH);
 737                         append_char((int) equal_char, buffer);
 738                         append_string(macro_list->value, buffer, FIND_LENGTH);
 739                         append_char((int) dollar_char, buffer);
 740                 }
 741         }
 742 }









































































































































































































 743