Пример #1
0
char *low_gmxlibfn(const char *file, gmx_bool bAddCWD, gmx_bool bFatal)
{
    char *ret;
    char *lib,*dir;
    char buf[1024];
    char libpath[GMX_PATH_MAX];
    gmx_bool env_is_set=FALSE;
    char   *s,tmppath[GMX_PATH_MAX];

    /* GMXLIB can be a path now */
    lib=getenv("GMXLIB");
    if (lib != NULL)
    {
        env_is_set=TRUE;
        strncpy(libpath,lib,GMX_PATH_MAX);
    } 
    else if (!get_libdir(libpath))
    {
        strncpy(libpath,GMXLIBDIR,GMX_PATH_MAX);
    }

    ret = NULL;
    if (bAddCWD && gmx_fexist(file))
    {
        ret = strdup(file);
    }
    else 
    {
        strncpy(tmppath,libpath,GMX_PATH_MAX);
        s=tmppath;
        while(ret == NULL && (dir=gmx_strsep(&s, PATH_SEPARATOR)) != NULL )
        {
            sprintf(buf,"%s%c%s",dir,DIR_SEPARATOR,file);
            if (gmx_fexist(buf))
            {
                ret = strdup(buf);
            }
        }
        if (ret == NULL && bFatal) 
        {
            if (env_is_set) 
            {
                gmx_fatal(FARGS,
                          "Library file %s not found %sin your GMXLIB path.",
                          bAddCWD ? "in current dir nor " : "",file);
            }
            else
            {
                gmx_fatal(FARGS,
                          "Library file %s not found %sin default directories.\n"
                        "(You can set the directories to search with the GMXLIB path variable)",
                          bAddCWD ? "in current dir nor " : "",file);
            }
        }
    }

    return ret;
}
Пример #2
0
const char *low_libfn(const char *file, bool bFatal)
{
  const char *ret=NULL;
  char *lib,*dir;
  static char buf[1024];
  static char libpath[4096];
  static int  bFirst=1;
  static bool env_is_set;
  char   *s,tmppath[4096];
  bool found;
  
  if (bFirst) {
    /* GMXLIB can be a path now */
    lib=getenv("GMXLIB");
    if (lib != NULL) {
      env_is_set=TRUE;
      strcpy(libpath,lib);
    } 
    else if (!get_libdir(libpath))
      strcpy(libpath,GMXLIBDIR);
    
    bFirst=0;
  }

  if (fexist(file))
    ret=file;
  else {
    found=FALSE;
    strcpy(tmppath,libpath);
    s=tmppath;
    while(!found && (dir=strtok(s,PATH_SEPARATOR))!=NULL) {
      sprintf(buf,"%s%c%s",dir,DIR_SEPARATOR,file);
      found=fexist(buf);
      s = NULL;
    }
    ret=buf;
    if (bFatal && !found) {
      if (env_is_set) 
	gmx_fatal(FARGS,"Library file %s not found in current dir nor in your GMXLIB path.\n",file);
      else
	gmx_fatal(FARGS,"Library file %s not found in current dir nor in default directories.\n"
		    "(You can set the directories to search with the GMXLIB path variable)",file);
    }
  }
    
  return ret;
}
Пример #3
0
main(int argc, char **argv)
{
	int     c,fp;
	int     status, ok = TRUE;
	extern int  optind;
	extern char *optarg;
	char   *FRONT, *GEN, *BND; 
	char   *arg_name;
	char   *lib_name;
	char   *list_name;
	char   *source_name;
	char   *msg_name;
	char   *tmp_name;
	char   *s_temp;
	char   *l_name;
	char   *basep;
	int	   prefix_len, base_len, suffix_len;
	char   *lib_opt_str, *main_unit_name;
	char   *object_files = "";
	char   *front_options, *gen_options;
	int     bind_opt = 0, main_opt = 0, save_msg_opt = 0 ;
	int     list_opt = FALSE;   /* set to generate a listing */
	char   *list_arg;		/* for passing list_opt to mrg */
	int     lib_opt = FALSE;    /* set to TRUE if -l specified */
	int     newlib_opt = FALSE; /* set to TRUE if -n specified */
	int	    time_limit = 15;    /* default time limit in minutes */
#ifdef BSD
	struct rlimit rlp;
#endif

/* initializations */
	arg_name = (char *) 0;
	lib_name = (char *) 0;
	front_options = "";
	gen_options = "";

/*
 * command options
 *	-a		generated line number instructions
 *	-b 		bind the unit specified by 'm' option
 *	-g		insert generated code into listing
 *      -i              specify object files and libraries for pragma interface
 *	-l libname	(old) library libname
 *	-m main unit  	specify the main binding unit.
 *			or use default main unit
 *	-n libname	new library libname
 *      -s		create source program listing
 *	-v		trace executed commands and exit status
 *      -Y		save message files (for running B tests)
 *  	-P		compile predef
 */

#ifdef IBM_PC
	while((c = getopt(argc, argv, "AaBbGgL:l:M:m:NnSsVvYPi:")) != EOF) {
          if (isupper(c)) c = tolower(c);
#else
	while((c = getopt(argc, argv, "abgl:m:nsvMPi:")) != EOF) {
#endif
	switch(c) {
	  case 'a':
		s_temp = emalloc(strlen(gen_options) + 2);
		strcpy(s_temp, gen_options);
		strcat(s_temp, "l");
		gen_options = s_temp;
		break;
	  case 'b':
		bind_opt = 1;
		break;
	  case 'g':
		s_temp = emalloc(strlen(gen_options) + 2);
		strcpy(s_temp, gen_options);
		strcat(s_temp, "g");
		gen_options = s_temp;
		break;
	  case 'l':
		lib_opt = TRUE;
		lib_name = emalloc(strlen(optarg) + 1);
		strcpy(lib_name, optarg);
		break;
	  case 'm':    
		main_opt = 1;
		main_unit_name = emalloc(strlen(optarg) + 1);
		strcpy(main_unit_name, optarg);
		break;
	  case 'n':
		newlib_opt = TRUE;
		break;
	  case 'i':
		s_temp = emalloc(strlen(optarg) + 1);
		strcpy(s_temp, optarg);
		interface_opts[interface_cnt++] = s_temp;
		break;
	  case 's':
		list_opt++;
		break;
	  case 'v':
		exec_trace++;
		break;
	  case 'Y':
		save_msg_opt = TRUE ;
		break;
	  case 'P':
		s_temp = emalloc(strlen(front_options) + 2);
		strcpy(s_temp, front_options);
		strcat(s_temp, "p");
		front_options = s_temp;
		s_temp = emalloc(strlen(gen_options) + 2);
		strcpy(s_temp, gen_options);
		strcat(s_temp, "p");
		gen_options = s_temp;
		break;
	  case '?':
		exit(RC_ABORT);
		break;
		default:
		fprintf(stderr, "Unknown Option: %c\n", c);
		exit(RC_ABORT);
	}
	}
	if (optind < argc)
	arg_name = argv[optind];
	if (arg_name == (char *) 0) {
	fprintf(stderr,"Invalid Usage: No ada file specified\n");
	exit(RC_ABORT);
	}
	if (!lib_opt) { /* if -l not specified, try to get from environment */
	   lib_name = getenv("ADALIB");
	   if (lib_name!=(char *)0) {
	   lib_opt++;
	}
	if (lib_opt) {
		printf("library defined by ADALIB: %s\n",lib_name);
	}
	}
	if (!lib_opt) {
	   fprintf(stderr,
		"Invalid Usage: please specify a library\n");
	   exit(RC_ABORT);
	}
#ifdef BSD
	getrlimit(RLIMIT_CPU,&rlp);
	(&rlp)->rlim_cur = time_limit*60;     /* limit to time_limit mins */
	setrlimit(RLIMIT_CPU,&rlp);
#endif

	basep = parsefile(arg_name, &prefix_len, &base_len, &suffix_len);
	/* check for presence of ada file;  if none, make it ada */
	if (suffix_len ==0) {
	source_name = emalloc(strlen(arg_name) + 4 + 1);
	strcpy(source_name, arg_name);
	strcat(source_name, ".ada");
	}
	else {
		source_name = arg_name;
	}
	base_name = emalloc(base_len + 1);
	strncpy(base_name, basep, base_len);
	if ((fp = open(source_name,O_RDONLY,0700)) < 0) {
	fprintf(stderr,"Cannot access file %s\n",source_name);
	exit(RC_ABORT);
	}
	close(fp);


	if (newlib_opt){
		if (exec_trace) {
		fprintf(stderr, "mkdir %s ", lib_name);
		}
		status = mkdir(lib_name, 0777);
		if (exec_trace) {
		fprintf(stderr, " ? %d\n", status);
		}
	}
	status = 0;
	if (status) {
		fprintf(stderr,"%s cannot be used as a library\n", lib_name);
		exit(RC_ABORT);
	}
	if (!newlib_opt) {
		/* check for presence of library file */
	l_name = emalloc(strlen(lib_name) + strlen(LIBFILENAME) + 2);
	strcpy(l_name, lib_name);

#ifdef BSD
	strcat(l_name, "/");
#endif
#ifdef SYSTEM_V
	strcat(l_name, "/");
#endif
#ifdef IBM_PC
	strcat(l_name, "/");
#endif
	strcat(l_name, LIBFILENAME);

		if ((fp = open(l_name,O_RDONLY,0700)) < 0) {
		    fprintf(stderr,"%s cannot be used as a library\n", lib_name);
		    exit(RC_ABORT);
		}
	efree(l_name);
		close(fp);
	}

	/* format library option as expected by adafront & adagen */
	lib_opt_str = ((newlib_opt) ? "-nl" : "-l");

	FRONT = getsym("ADAFRONT", FRONT_NAME);
	other_opts[opts_cnt = 0] = FRONT;
	if (strlen(front_options) != 0) {
		other_opts[++opts_cnt] = "-s";
		other_opts[++opts_cnt] = front_options;
	}
	other_opts[++opts_cnt] = lib_opt_str;
	other_opts[++opts_cnt] = lib_name;
	other_opts[++opts_cnt] = source_name;
	other_opts[++opts_cnt] = (char *) 0;
	if (exec_trace)
		arg_dump();
	status = run_prog(FRONT, other_opts);
	if (exec_trace)
		fprintf(stderr, " ? %d\n", status);
	ok = check_status(status, "FRONT", arg_name);
		/* check for front end errors (adafront will exit with RC_ERRORS) */
	if (status_get(status)== RC_ERRORS)
		ok = FALSE;

	if (ok) {
		GEN = getsym("GEN", GEN_NAME);
		other_opts[opts_cnt = 0] = GEN;
		if (strlen(gen_options) != 0) {
			other_opts[++opts_cnt] = "-g";
			other_opts[++opts_cnt] = gen_options;
		}
		other_opts[++opts_cnt] = lib_opt_str;
		other_opts[++opts_cnt] = lib_name;
		other_opts[++opts_cnt] = base_name;
		other_opts[++opts_cnt] = (char *) 0;
		if (exec_trace)
			arg_dump();
		status =  run_prog(GEN, other_opts);
		if (exec_trace)
			fprintf(stderr, " ? %d\n", status);
		ok = check_status(status, "GEN", arg_name);
	}

	if (ok && bind_opt) { /* run binder if desired */
		BND = getsym("BND", BND_NAME);
		other_opts[opts_cnt = 0] = BND;
		other_opts[++opts_cnt] = "-c"; /* indicate errors in message form */
		other_opts[++opts_cnt] = base_name; /* pass filename for msg listing */

		while(interface_cnt) {
			other_opts[++opts_cnt] = "-i";
			other_opts[++opts_cnt] = interface_opts[--interface_cnt];
		}
		if (main_opt) {
			other_opts[++opts_cnt] = "-m";
			other_opts[++opts_cnt] = main_unit_name;
		}
		other_opts[++opts_cnt] = lib_name; /* library is current directory */
		other_opts[++opts_cnt] = (char *) 0;
		if (exec_trace)
			arg_dump();
		status =  run_prog(BND, other_opts);
		if (exec_trace)
			fprintf(stderr, " ? %d\n", status);
		ok = check_status(status, "BND", arg_name);
	}
#ifdef IBM_PC
	list_name = emalloc(strlen(base_name) + 4 + 1);
	strcpy(list_name, base_name);
	strcat(list_name, ".lis");
#endif
#ifdef SYSTEM_V
	list_name = emalloc(strlen(base_name) + 4 + 1);
	strcpy(list_name, base_name);
	strcat(list_name, ".lis");
#endif
#ifdef BSD
	list_name = emalloc(strlen(base_name) + 4 + 1);
	strcpy(list_name, base_name);
	strcat(list_name, ".lis");
#endif
	list_arg = (list_opt>0) ? "1" : "0";
	msg_name = emalloc(strlen(lib_name) + strlen(base_name) + 7);
	strcpy(msg_name, lib_name);
#ifdef BSD
	strcat(msg_name,"/");
#endif
#ifdef SYSTEM_V
	strcat(msg_name,"/");
#endif
#ifdef IBM_PC
	strcat(msg_name,"/");
#endif
	strcat(msg_name, base_name);
	strcat(msg_name, ".msg");
	status = mrg(source_name,msg_name, list_name, list_arg);
	efree(list_name);
	if (!save_msg_opt) {
		delete_file(msg_name);
	efree(msg_name);
	}

	exit(maxstatus);
}

static char *getsym(char *env_name, char *def_value)		/*;getsym*/
{
  /* Retrieve environment variable designating the executable module for
   * a given phase of the compiler.
   * If the variable is not defined, a default is supplied for BSD systems.
   */
	char   *s;

	s = getenv(env_name);
	if (s==(char *)0) {
		char *t = get_libdir();
		s = emalloc(strlen(t) + strlen(def_value) + 2);
		sprintf(s,"%s/%s", t, def_value);
	}
	return s;
}
Пример #4
0
static int low_fflib_search_file_end(const char *ffdir,
                                     gmx_bool bAddCWD,
                                     const char *file_end,
                                     gmx_bool bFatalError,
                                     char ***filenames,
                                     char ***filenames_short)
{
    char *ret=NULL;
    char *lib,*dir;
    char buf[1024];
    char *libpath;
    gmx_bool env_is_set;
    int  len_fe,len_name;
    char **fns,**fns_short;
    char dir_print[GMX_PATH_MAX];
    char *pdum;
    char *s,fn_dir[GMX_PATH_MAX];
    gmx_directory_t dirhandle;
    char nextname[STRLEN];
    int  n,n_thisdir,rc;

    len_fe = strlen(file_end);

    env_is_set = FALSE;
    if (ffdir != NULL)
    {
        /* Search in current dir and ffdir */
        libpath = gmxlibfn(ffdir);
    }
    else
    {
        /* GMXLIB can be a path now */
        lib = getenv("GMXLIB");
        snew(libpath,GMX_PATH_MAX);
        if (bAddCWD)
        {
            sprintf(libpath,"%s%s",".",PATH_SEPARATOR);
        }
        if (lib != NULL)
        {
            env_is_set = TRUE;
            strncat(libpath,lib,GMX_PATH_MAX);
        } 
        else if (!get_libdir(libpath+strlen(libpath)))
        {
            strncat(libpath,GMXLIBDIR,GMX_PATH_MAX);
        }
    }
    s = libpath;
    n = 0;
    fns       = NULL;
    fns_short = NULL;
    /* Loop over all the entries in libpath */
    while ((dir=gmx_strsep(&s, PATH_SEPARATOR)) != NULL)
    {
        rc = gmx_directory_open(&dirhandle,dir);
        if (rc==0)
        {
            strcpy(dir_print,dir);

            n_thisdir = 0;
            while (gmx_directory_nextfile(dirhandle,nextname,STRLEN-1)==0)
            {
                nextname[STRLEN-1]=0;
                if (debug)
                {
                    fprintf(debug,"dir '%s' %d file '%s'\n",
                            dir,n_thisdir,nextname);
                }
                len_name = strlen(nextname);
                /* What about case sensitivity? */
                if (len_name >= len_fe &&
                    strcmp(nextname+len_name-len_fe,file_end) == 0)
                {
                    /* We have a match */
                    srenew(fns,n+1);
                    sprintf(fn_dir,"%s%c%s",
                            dir_print,DIR_SEPARATOR,nextname);

                    /* Copy the file name, possibly including the path. */
                    fns[n] = strdup(fn_dir);

                    if (ffdir == NULL)
                    {
                        /* We are searching in a path.
                         * Use the relative path when we use share/top
                         * from the installation.
                         * Add the full path when we use the current
                         * working directory of GMXLIB.
                         */
                        srenew(fns_short,n+1);
                        if (strcmp(dir,".") == 0 || env_is_set)
                        {
                            fns_short[n] = strdup(fn_dir);
                        }
                        else
                        {
                            fns_short[n] = strdup(nextname);
                        }
                    }
                    n++;
                    n_thisdir++;
                }
            }
            gmx_directory_close(dirhandle);

            sort_filenames(n_thisdir,
                           fns+n-n_thisdir,
                           fns_short==NULL ? NULL : fns_short+n-n_thisdir);
        }
    }

    sfree(libpath);

    if (n == 0 && bFatalError)
    {
        if (ffdir != NULL)
        {
            gmx_fatal(FARGS,"Could not find any files ending on '%s' in the force field directory '%s'",file_end,ffdir);
        }
        else
        {
            gmx_fatal(FARGS,"Could not find any files ending on '%s' in the current directory or the GROMACS library search path",file_end);
        }
    }

    *filenames = fns;
    if (ffdir == NULL)
    {
        *filenames_short = fns_short;
    }

    return n;
}