File: hf77.c

package info (click to toggle)
lam 6.1-11
  • links: PTS
  • area: main
  • in suites: slink
  • size: 7,764 kB
  • ctags: 5,834
  • sloc: ansic: 55,525; makefile: 1,449; fortran: 184; sh: 39; asm: 26; csh: 12
file content (136 lines) | stat: -rw-r--r-- 2,365 bytes parent folder | download
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
/*
 *	Ohio Trollius
 *	Copyright 1996 The Ohio State University
 *	GDB/RBD
 *
 *	$Id: hf77.c,v 6.1 96/11/23 19:37:12 nevin Rel $
 *
 *	Function:	- wrapper for FORTRAN program compilation
 */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#include <args.h>
#include <boot.h>
#include <portable.h>

#ifndef DEFTF77
#if HPUX
#define DEFTF77 "fort77"
#else
#define DEFTF77 "f77"
#endif
#endif

/*
 * external functions
 */
extern int		cnfexec();

/*
 * local variables
 */
static char		plib[LAM_PATH_MAX];

int
main(argc, argv)

int			argc;
char			*argv[];

{
	int		ac;		/* f77 # args */
	int		status;		/* f77 return code */
	int		fl_libs;	/* add libs to command line */
	int		fl_show;	/* show what would be done */
	int		i;		/* favourite index */
	char		**av;		/* f77 arg vector */
	char		**sys;		/* system libraries arg vector */
	char		*phome;		/* installation dir */
	char		*tf77;		/* f77 tool */

	phome = getenv("LAMHOME");
	if (phome == 0) phome = getenv("TROLLIUSHOME");
	if (phome == 0) phome = DEFP;

	if ((strlen(phome) + 32) >= LAM_PATH_MAX) {
		fprintf(stderr, "hf77: LAM home pathname too long\n");
		exit(1);
	}
/*
 * Form library directory pathname.
 */
	strcpy(plib, "-L");
	strcat(plib, phome);
	strcat(plib, STRSDIR);
	strcat(plib, "lib");

	tf77 = getenv("LAMHF77");
	if (tf77 == 0) tf77 = getenv("TROLLIUSHF77");
	if (tf77 == 0) tf77 = DEFTF77;

	ac = 0;
	av = 0;
	argvadd(&ac, &av, tf77);

	fl_show = 0;
	fl_libs = 1;

	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "-showme") == 0) {
			fl_show = 1;
		} else if (strcmp(argv[i], "-c") == 0) {
			fl_libs = 0;
		}
	}

	if (fl_libs) {
		argvadd(&ac, &av, plib);
	}

	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "-showme")) {
			argvadd(&ac, &av, argv[i]);
		}
	}

	if (fl_libs) {
		argvadd(&ac, &av, "-ltstdio");
		argvadd(&ac, &av, "-ltrillium");
		argvadd(&ac, &av, "-largs");
		argvadd(&ac, &av, "-lt");
/*
 * Add system dependent libraries.
 */
		if (strlen(SYSLIBS) > 0) {
			if ((sys = argvbreak(SYSLIBS, ' ')) == 0) {
				perror("hf77");
				exit(errno);
			}

			for ( ; *sys; sys++) {
				argvadd(&ac, &av, *sys);
			}
		}
	}

	if (fl_show) {
		for (i = 0; i < ac; i++) {
			printf("%s ", av[i]);
		}
		printf("\n");
	} else {
		status = cnfexec(av);

		if (status) {
			perror(tf77);
			exit(status);
		}
	}

	return(0);
}