output.cc (10810:683ab55819fd) output.cc (11259:4006183015a1)
1/*
2 * Copyright (c) 2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 63 unchanged lines hidden (view full) ---

72 if (name == "cout" || name == "stdout")
73 return &cout;
74
75 return NULL;
76}
77
78ostream *
79OutputDirectory::openFile(const string &filename,
1/*
2 * Copyright (c) 2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 63 unchanged lines hidden (view full) ---

72 if (name == "cout" || name == "stdout")
73 return &cout;
74
75 return NULL;
76}
77
78ostream *
79OutputDirectory::openFile(const string &filename,
80 ios_base::openmode mode)
80 ios_base::openmode mode, bool no_gz)
81{
81{
82 if (filename.find(".gz", filename.length()-3) < filename.length()) {
82 bool gz = !no_gz;
83 gz = gz && filename.find(".gz", filename.length()-3) < filename.length();
84 if (gz) {
83 ogzstream *file = new ogzstream(filename.c_str(), mode);
84 if (!file->is_open())
85 fatal("Cannot open file %s", filename);
86 assert(files.find(filename) == files.end());
87 files[filename] = file;
88 return file;
89 } else {
90 ofstream *file = new ofstream(filename.c_str(), mode);

--- 57 unchanged lines hidden (view full) ---

148
149string
150OutputDirectory::resolve(const string &name) const
151{
152 return (name[0] != PATH_SEPARATOR) ? dir + name : name;
153}
154
155ostream *
85 ogzstream *file = new ogzstream(filename.c_str(), mode);
86 if (!file->is_open())
87 fatal("Cannot open file %s", filename);
88 assert(files.find(filename) == files.end());
89 files[filename] = file;
90 return file;
91 } else {
92 ofstream *file = new ofstream(filename.c_str(), mode);

--- 57 unchanged lines hidden (view full) ---

150
151string
152OutputDirectory::resolve(const string &name) const
153{
154 return (name[0] != PATH_SEPARATOR) ? dir + name : name;
155}
156
157ostream *
156OutputDirectory::create(const string &name, bool binary)
158OutputDirectory::create(const string &name, bool binary, bool no_gz)
157{
158 ostream *file = checkForStdio(name);
159 if (file)
160 return file;
161
162 string filename = resolve(name);
163 ios_base::openmode mode =
164 ios::trunc | (binary ? ios::binary : (ios::openmode)0);
159{
160 ostream *file = checkForStdio(name);
161 if (file)
162 return file;
163
164 string filename = resolve(name);
165 ios_base::openmode mode =
166 ios::trunc | (binary ? ios::binary : (ios::openmode)0);
165 file = openFile(filename, mode);
167 file = openFile(filename, mode, no_gz);
166
167 return file;
168}
169
170ostream *
171OutputDirectory::find(const string &name) const
172{
173 ostream *file = checkForStdio(name);

--- 97 unchanged lines hidden ---
168
169 return file;
170}
171
172ostream *
173OutputDirectory::find(const string &name) const
174{
175 ostream *file = checkForStdio(name);

--- 97 unchanged lines hidden ---