Functions | Variables
srt_ntf77 Namespace Reference

Functions

def main ()
 MAIN FUNCTION. More...
 
def construct_temp_file_name (source_name)
 
def translate_command (string, sub_dict)
 

Variables

 result = main()
 

Function Documentation

def srt_ntf77.construct_temp_file_name (   source_name)

Definition at line 266 of file srt_ntf77.py.

266 def construct_temp_file_name (source_name):
267  #
268  # Strip off the extension...
269  #
270  (base_dir, file_name) = os.path.split (source_name)
271  (basename, ext) = os.path.splitext (file_name)
272  return basename + "_pp.f"
273 
274 #
275 # translate_command
276 #
277 # Given a dictionary of replacements, do them in the current string
278 #
def construct_temp_file_name(source_name)
Definition: srt_ntf77.py:266
def srt_ntf77.main ( )

MAIN FUNCTION.

1D plots hits vs w //

Definition at line 33 of file srt_ntf77.py.

References srt_path_util.file_type(), translate_command(), and srt_ntbashutil.translate_path().

33 def main():
34 
35  #
36  # Setup and make sure command line stuff is there and cool.
37  #
38 
39  cmd_options = srt_options_line.options_line (sys.argv[1:])
40 
41  if cmd_options.length() == 0:
42  sys.stderr.write("Usage: " + sys.argv[0] + " <arguments>\n")
43  return 1
44 
45  cmd_line = ""
46  output_file = ""
47  gcc_cmd_line = ""
48  need_preprocessor = 0
49  link_line = "/link "
50  link_line_valid = 0
51 
52  #
53  # Are we dumping for IDE stuff, or something else?
54  #
55 
56  do_ide_dump = 0
57  if os.environ.has_key("IDE_DUMP"):
58  f_name = srt_ntbashutil.translate_path(os.environ["IDE_DUMP"])
59  sys.stdout = open (f_name, "a+")
60  do_ide_dump = 1
61 
62  #
63  # Now, loop over all the arguments in the command line.
64  #
65 
66  if do_ide_dump:
67  print "->IDE<- *compile_fortran"
68  print "->IDE<- working_dir " + os.getcwd()
69  if os.environ.has_key("CURPKG"):
70  print "->IDE<- package_name " + os.environ["CURPKG"]
71 
72  while cmd_options.has_more_options():
73  option = cmd_options.get_next_option ("this should never fail!")
74  if option[0] == "-":
75  option = option[1:]
76  #
77  # I -- An include file
78  #
79 
80  if option[0] == "I":
81  translated_path = srt_ntbashutil.translate_path (option[1:])
82  nt_path_list = srt_ntbashutil.resolve_bash_aliases (translated_path)
83  if do_ide_dump:
84  print "->IDE<- unix_include_file_path " + option[1:]
85  gcc_cmd_line = gcc_cmd_line + "-I" + option[1:] + " "
86  #for path in nt_path_list:
87  # c_path = srt_ntbashutil.compress_path(path)
88  # gcc_cmd_line = gcc_cmd_line + "-I" + c_path + " "
89  # if do_ide_dump:
90  # print "->IDE<- include_file_path " + c_path
91 
92  #
93  # D -- Deifne a C macro symbol
94  #
95 
96  elif option[0] == "D":
97  gcc_cmd_line = gcc_cmd_line + "-D" + option[1:] + " "
98 # if do_ide_dump:
99 # print "->IDE<- define_macro " + option[1:]
100 # print "Warning: Fortran doesn't really do Defines (" + option[1:] + ")."
101 
102  #
103  # c -- Don't link, only compile (defualt for cl).
104  #
105 
106  elif option[0] == "c":
107  cmd_line = cmd_line + "/c" + " "
108  link_line_valid = 0
109  if do_ide_dump:
110  print "->IDE<- do_compile_only"
111 
112  #
113  # o -- Stuff the object file in the next argument.
114  #
115 
116  elif option[0] == "o":
117  unix_output_file = cmd_options.get_next_option("output file name")
118  output_file = srt_ntbashutil.translate_path(unix_output_file)
119  if srt_path_util.file_type(output_file) == "":
120  link_line = link_line + "/exe:" + output_file + " "
121  if do_ide_dump:
122  print "->IDE<- build_app " + output_file
123  else:
124  cmd_line = cmd_line + "/object:_OBJECT_ "
125  if do_ide_dump:
126  print "->IDE<- build_obj " + output_file
127 
128  #
129  # Pass through options -- these are really NT options, but we have to
130  # use "-" instead of "/" when talking to them!
131  #
132 
133  elif option[0:2] == "NT":
134  cmd_line = cmd_line + "/" + option[2:] + " "
135  if do_ide_dump:
136  print "->IDE<- option " + option[2:]
137 
138 # elif option[0:1] == "L":
139 # link_line = link_line + "/libpath:" + srt_ntbashutil.translate_path(option[1:]) + " "
140 # link_line_valid = 1
141 # if do_ide_dump:
142 # print "->IDE<- library_search_path " + srt_ntbashutil.translate_path(option[1:])
143 
144 # elif option[0:1] == "l":
145 # link_line = link_line + "lib" + option[1:] + ".lib "
146 # link_line_valid = 1
147 # if do_ide_dump:
148 # print "->IDE<- library lib" + option[1:] + ".lib"
149 
150  #
151  # Game over. Wonder what this option was supposed to be?
152  #
153 
154  else:
155  sys.stderr.write("WARNING: Unkown gcc option in ntf77.py!!: -" + option + "\n")
156  #return 1
157  else:
158  #
159  # Got a plain file. If it is a .a file, change it to a .lib file. NT, of course,
160  # uses .lib, while UNIX (dark ages) uses .a.
161  #
162 
163  nt_path = srt_ntbashutil.translate_path (option)
164  file_type = srt_path_util.file_type(nt_path)
165  if file_type == "a":
166  nt_path = srt_path_util.change_to_type (nt_path, "lib")
167 
168  #
169  # Construct default output filenames
170  #
171 
172  if output_file == "":
173  (file_base, file_ext) = os.path.splitext (option)
174  unix_output_file = file_base + ".obj"
175  output_file = srt_ntbashutil.translate_path(unix_output_file)
176 
177  #
178  # If this is a fortran file of type .F, then we will have to run the
179  # preprocessor on it.
180  #
181 
182  if file_type == "F":
183  need_preprocessor = 1
184 
185  gcc_cmd_line = gcc_cmd_line + "_SOURCE_" + " "
186 
187  if do_ide_dump:
188  print "->IDE<- source_file " + nt_path
189 
190  input_file_name = nt_path
191 
192  #
193  # If a link is involved here, then add the various commands into the command line.
194  #
195 
196  if link_line_valid:
197  cmd_line = cmd_line + link_line
198 
199  #
200  # If we are dumping the IDE, don't really do anything here (afterall, we might crash cause the
201  # input files are dummy files also!!); just create the output files. Otherwise, execute the
202  # command, making sure to remember the result.
203  #
204 
205  result = 0
206  if do_ide_dump:
207  if output_file == "":
208  sys.stderr.write("*** ERROR: No output file specified!\n")
209  sys.stderr.flush()
210  return 2
211  f_handle = open (output_file, "w")
212  f_handle.write ("Temp File")
213  f_handle.close()
214  srt_ntide_dummy_files.record_temp_file (output_file)
215 
216  result = 0
217 
218  #
219  # Run the commands. If we are doing an IDE file, only make sure they
220  # get into the IDE text file. Replace the various strings that need to
221  # be replaced...
222  #
223 
224  sub_dict = {}
225  sub_dict['_SOURCE_'] = input_file_name
226  sub_dict['_OBJECT_'] = output_file
227  (temp_dir, junk) = os.path.split (output_file)
228  sub_dict['_TEMP_'] = temp_dir
229 
230  if need_preprocessor:
231  #
232  # Construct temporary output filename
233  #
234  temp_fortran_name = "_TEMP_" + construct_temp_file_name (output_file)
235  unix_temp_fortran_name = srt_path_util.path_to_unix (temp_fortran_name)
236  gcc_cmd_line = "-o " + unix_temp_fortran_name + " " + gcc_cmd_line
237 
238  full_gcc_command = "gcc -P -C -x c -E " + gcc_cmd_line
239  if do_ide_dump:
240  print "->IDE<- special_command set PATH=%CYGNUS_BIN%;%PATH%"
241  print "->IDE<- special_command " + full_gcc_command
242  else:
243  result = os.system(translate_command(full_gcc_command,sub_dict))
244  input_file_name = srt_ntbashutil.translate_path(temp_fortran_name)
245  if result == 0:
246  full_df_command = "df " + cmd_line + " " + input_file_name
247  if do_ide_dump:
248  print "->IDE<- special_command " + full_df_command
249  else:
250  result = os.system(translate_command(full_df_command,sub_dict))
251 
252  #
253  # Make sure to flush the output. This seems to be required under certian circumstances
254  # when running the b18 version of cygwin's bash util and piping the output of this script
255  # to a file from the gmake command line. :-)
256  #
257 
258  return result
259 
260 #
261 # construct_temp_file_name
262 #
263 # Build a temp filename outta the given name. The temp filename will end with
264 # _pp.f.
265 #
def main()
MAIN FUNCTION.
Definition: srt_ntf77.py:33
def file_type(the_path)
def translate_command(string, sub_dict)
Definition: srt_ntf77.py:279
def translate_path(bash_path)
def srt_ntf77.translate_command (   string,
  sub_dict 
)

Definition at line 279 of file srt_ntf77.py.

Referenced by main(), and srt_nt_example_command.main().

279 def translate_command (string, sub_dict):
280  result = string
281  for a_sub in sub_dict.keys():
282  result = regsub.gsub (a_sub, sub_dict[a_sub], result)
283  return result
284 
285 #
286 # Execute the routine and let the shell know what happened.
287 #
def translate_command(string, sub_dict)
Definition: srt_ntf77.py:279

Variable Documentation

srt_ntf77.result = main()

Definition at line 289 of file srt_ntf77.py.