/*
* Copyright (c) 1999
* Steven G. Kargl. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided by Steven G. Kargl and contributors ``as is'' and
* any express or implied warranties, including, but not limited to, the implied
* warranties of merchantability and fitness for a particular purpose are
* disclaimed. In no event shall Steven G. Kargl or contributors be liable for
* any direct, indirect, incidental, special, exemplary, or consequential
* damages (including, but not limited to, procurement of substitute goods or
* services; loss of use, data, or profits; or business interruption) however
* caused and on any theory of liability, whether in contract, strict liability,
* or tort (including negligence or otherwise) arising in any way out of the
* use of this software, even if advised of the possibility of such damage.
*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include "f77.h"
#include "proto.h"
void cmds(int ac, char **av) {
extern flags_t flags;
extern int index_f2c_cmd, index_cc_cmd, index_files;
extern int index_pp_cmd;
extern int index_libdirs, index_libs;
extern char **f2c_cmd, **cc_cmd, **files, **libs, **libdirs;
extern char **pp_cmd;
extern char *output_name, *tmpdir;
char **ov;
int len;
ov = av;
/* Remove f77 from argument list */
ac--;
ov++;
while(ac--) {
if (*ov[0] == '-') { /* It's an option */
if (strlen(*ov) == 2) {
switch ((*ov)[1]) {
case '1':
if (!(flags & ONETRIP)) {
f2c_cmd[index_f2c_cmd++] = mkstring("-onetrip");
flags |= ONETRIP;
}
break;
case 'C':
if (!(flags & BOUNDS_CHECK)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= BOUNDS_CHECK;
}
break;
case 'c':
flags |= COMPILE_ONLY;
break;
case 'E':
flags |= PREPROCESS_ONLY;
break;
case 'f':
if (flags & COLUMNS_72) {
fputs("f77: cmds: conflicting options: ", stderr);
fputs("-f and -72\n", stderr);
exit(1);
}
if (!(flags & FREE_FORM)) {
f2c_cmd[index_f2c_cmd++] = *ov;
#ifdef SUN_FPP
pp_cmd[index_pp_cmd++] = mkstring("-free");
#endif
flags |= FREE_FORM;
}
break;
case 'h':
if (!(flags & F66_HOLLERITH)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= F66_HOLLERITH;
}
break;
case 'o':
if (output_name) free(output_name);
output_name = *++ov;
ac--;
break;
case 'R':
if (!(flags & NO_PROMOTE_REAL)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= NO_PROMOTE_REAL;
}
break;
case 'r':
if (!(flags & REAL_FUNCS)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= REAL_FUNCS;
}
break;
case 'T':
if (tmpdir) free(tmpdir);
tmpdir = *++ov;
ac--;
break;
case 'V':
flags |= ECHO;
break;
case 'v':
if (!(flags & VERBOSE)) {
f2c_cmd[index_f2c_cmd++] = *ov;
cc_cmd[index_cc_cmd++] = *ov;
flags |= VERBOSE;
}
break;
case 'w':
if (!(flags & NO_WARNINGS)) {
f2c_cmd[index_f2c_cmd++] = *ov;
#ifdef SUN_FPP
pp_cmd[index_pp_cmd++] = *ov;
#endif
flags |= NO_WARNINGS;
}
break;
case 'z':
if (!(flags & NO_DBLE_CMPLX)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= NO_DBLE_CMPLX;
}
break;
default:
cc_cmd[index_cc_cmd++] = *ov;
} /* End of Switch */
} else if (strcmp(*ov, "-cd") == 0) {
if (!(flags & IGNORE_CD_FUNCS)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= IGNORE_CD_FUNCS;
}
} else if (strlen(*ov) > 2 && (*ov)[1] == 'D') {
pp_cmd[index_pp_cmd++] = *ov;
} else if (strcmp(*ov, "-ext") == 0) {
if (!(flags & STRICT_F77)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= STRICT_F77;
}
} else if (strcmp(*ov, "-72") == 0) {
if (flags & FREE_FORM) {
fputs("f77: cmds: conflicting options: ", stderr);
fputs("-f and -72\n", stderr);
exit(1);
}
if (!(flags & COLUMNS_72)) {
f2c_cmd[index_f2c_cmd++] = *ov;
#ifdef SUN_FPP
pp_cmd[index_pp_cmd++] = mkstring("-fixed");
#endif
flags |= COLUMNS_72;
}
} else if (strcmp(*ov, "-hd") == 0) {
if (!(flags & F66_HOLLERITH)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= F66_HOLLERITH;
}
} else if (strcmp(*ov, "-I2") == 0) {
if (!(flags & SHORT_INTEGER)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= SHORT_INTEGER;
}
} else if (strncmp(*ov, "-I", 2) == 0) {
pp_cmd[index_pp_cmd++] = *ov;
} else if (strcmp(*ov, "-i90") == 0) {
if (!(flags & IGNORE_F90_BITS)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= IGNORE_F90_BITS;
}
} else if (strcmp(*ov, "-kr") == 0 || strcmp(*ov, "-krd") == 0) {
if (!(flags & F77_TEMPORARY)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= F77_TEMPORARY;
}
} else if (strncmp(*ov, "-L", 2) == 0) {
libdirs[index_libdirs++] = *ov;
} else if (strncmp(*ov, "-l", 2) == 0) {
libs[index_libs++] = *ov;
#ifdef SUN_FPP
} else if (strncmp(*ov, "-macro=", 7) == 0) {
if (!(flags & SUN_FPP_MACROS)) {
pp_cmd[index_pp_cmd++] = *ov;
flags |= SUN_FPP_MACROS;
}
#endif
} else if (strcmp(*ov, "-onetrip") == 0) {
if (!(flags & ONETRIP)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= ONETRIP;
}
} else if (strcmp(*ov, "-r8") == 0) {
if (!(flags & PROMOTE_REAL2DP)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= PROMOTE_REAL2DP;
}
} else if (strlen(*ov) > 2 && (*ov)[1] == 'U') {
pp_cmd[index_pp_cmd++] = *ov;
} else if (strcmp(*ov, "-undef") == 0) {
if (!(flags & SUN_FPP_UNDEF)) {
pp_cmd[index_pp_cmd++] = *ov;
flags |= SUN_FPP_UNDEF;
}
} else if (strcmp(*ov, "-w8") == 0) {
if (!(flags & ALIGN_COMMON)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= ALIGN_COMMON;
}
#ifdef SUN_FPP
} else if (strcmp(*ov, "-w0") == 0) {
if (!(flags & SUN_FPP_NO_WARN)) {
pp_cmd[index_pp_cmd++] = *ov;
flags |= SUN_FPP_NO_WARN;
}
#endif
} else if (strcmp(*ov, "-w66") == 0) {
if (!(flags & SUPRESS_F66_WARN)) {
f2c_cmd[index_f2c_cmd++] = *ov;
flags |= SUPRESS_F66_WARN;
}
} else /* Pass through to gcc */
cc_cmd[index_cc_cmd++] = *ov;
} else { /* We have a file */
len = strlen(*ov);
if ((*ov)[len - 2] == '.') {
switch((*ov)[len - 1]) {
case 'F':
case 'f':
case 'o':
case 'a':
files[index_files++] = *ov;
break;
default:
fputs("f77: cmds: unrecognized file: ", stderr);
fprintf(stderr, "%s\n", *ov);
exit(1);
}
} else {
fputs("f77: cmds: unrecognized file: ", stderr);
fprintf(stderr, "%s\n", *ov);
exit(1);
}
}
ov++;
} /* End while */
}
void print_cmd(int n, char **cmd) {
char **av;
av = cmd;
while (n--) printf("%s ", *av++);
printf("\n");
}
syntax highlighted by Code2HTML, v. 0.9.1