$(EXPAT_INCLUDES)
noinst_HEADERS = colortbl.h convert.h mmio.h matrix_market.h \
- graph_generator.h gml2gv.h gmlparse.h
+ graph_generator.h gml2gv.h gmlparse.h openFile.h
if ENABLE_STATIC
bin_PROGRAMS = gc gvcolor gxl2gv acyclic nop ccomps sccmap tred \
unflatten gvpack gvpack_static dijkstra bcomps mm2gv gvgen gml2gv gv2gml graphml2gv
#include <cgraph/cgraph.h>
#include <cgraph/exit.h>
#include <cgraph/unreachable.h>
+#include "openFile.h"
typedef struct {
Agrec_t h;
graphviz_exit(v);
}
-static FILE *openFile(const char *name, const char *mode)
-{
- FILE *fp;
- char *modestr;
-
- fp = fopen(name, mode);
- if (!fp) {
- if (*mode == 'r')
- modestr = "reading";
- else
- modestr = "writing";
- fprintf(stderr, "%s: could not open file %s for %s\n",
- cmd, name, modestr);
- graphviz_exit(-1);
- }
- return fp;
-}
-
static void init(int argc, char *argv[])
{
int c;
case 'o':
if (outFile != NULL)
fclose(outFile);
- outFile = openFile(optarg, "w");
+ outFile = openFile(argv[0], optarg, "w");
break;
case 'n':
doWrite = 0;
UNREACHABLE();
}
if (optind < argc) {
- inFile = openFile(argv[optind], "r");
+ inFile = openFile(argv[0], argv[optind], "r");
} else
inFile = stdin;
if (!outFile)
<Command>copy $(SolutionDir)windows\dependencies\libraries\vcpkg\installed\x86-windows\bin\getopt.dll $(OutDir)getopt.dll</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h" />
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="acyclic.c" />
</ItemGroup>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="acyclic.c">
<Filter>Source Files</Filter>
#include <cgraph/alloc.h>
#include <cgraph/exit.h>
#include <cgraph/unreachable.h>
+#include "openFile.h"
static int Verbose;
static char* gname = "";
return rv;
}
-static FILE *openFile(const char *name)
-{
- FILE *fp;
-
- fp = fopen(name, "w");
- if (!fp) {
- fprintf(stderr, "%s: could not open file %s for writing\n",
- CmdName, name);
- perror(name);
- graphviz_exit(1);
- }
- return fp;
-}
-
-
static char *useString = "Usage: %s [-v?] [-g<name>] [-o<file>] <files>\n\
-g<name> : use <name> as template for graph names\n\
-v : verbose mode\n\
case 'o':
if (outFile != NULL)
fclose(outFile);
- outFile = openFile(optarg);
+ outFile = openFile(CmdName, optarg, "w");
break;
case ':':
fprintf(stderr, "%s: option -%c missing argument\n", CmdName, optopt);
<ItemGroup>
<ClInclude Include="gml2gv.h" />
<ClInclude Include="gmlparse.h" />
+ <ClInclude Include="openFile.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="gml2gv.c" />
<ClInclude Include="gmlparse.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="openFile.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="gml2gv.c">
#include <getopt.h>
#include <stdio.h>
#include <string.h>
+#include "openFile.h"
#ifdef HAVE_EXPAT
#include <expat.h>
#include <ctype.h>
return rv;
}
-static FILE *openFile(const char *name)
-{
- FILE *fp;
-
- fp = fopen(name, "w");
- if (!fp) {
- fprintf(stderr, "%s: could not open file %s for writing\n", CmdName, name);
- perror(name);
- graphviz_exit(1);
- }
- return fp;
-}
-
static const char *use = "Usage: %s [-gd?] [-o<file>] [<graphs>]\n\
-g<name> : use <name> as template for graph names\n\
-o<file> : output to <file> (stdout)\n\
case 'o':
if (outFile != NULL)
fclose(outFile);
- outFile = openFile(optarg);
+ outFile = openFile(CmdName, optarg, "w");
break;
case ':':
fprintf(stderr, "%s: option -%c missing argument\n", CmdName, optopt);
copy $(SolutionDir)windows\dependencies\libraries\vcpkg\installed\x86-windows\bin\getopt.dll $(OutDir)getopt.dll</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h" />
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="graphml2gv.c" />
</ItemGroup>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="graphml2gv.c">
<Filter>Source Files</Filter>
#include <common/utils.h>
#include <ctype.h>
#include <ingraphs/ingraphs.h>
+#include "openFile.h"
static FILE *outFile;
static char *CmdName;
fprintf (outFile, "]\n");
}
-static FILE *openFile(const char *name)
-{
- FILE *fp;
-
- fp = fopen(name, "w");
- if (!fp) {
- fprintf(stderr, "%s: could not open file %s for writing\n",
- CmdName, name);
- perror(name);
- graphviz_exit(1);
- }
- return fp;
-}
-
-
static char *useString = "Usage: %s [-?] <files>\n\
-o<file> : output to <file> (stdout)\n\
-? - print usage\n\
case 'o':
if (outFile != NULL)
fclose(outFile);
- outFile = openFile(optarg);
+ outFile = openFile(CmdName, optarg, "w");
break;
case ':':
fprintf(stderr, "%s: option -%c missing parameter\n", CmdName, optopt);
<Command>copy $(SolutionDir)windows\dependencies\libraries\vcpkg\installed\x86-windows\bin\getopt.dll $(OutDir)getopt.dll</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h" />
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="gv2gml.c" />
</ItemGroup>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="gv2gml.c">
<Filter>Source Files</Filter>
#include <ctype.h>
#include <getopt.h>
#include "graph_generator.h"
-
+#include "openFile.h"
#include <cgraph/exit.h>
typedef enum { unknown, grid, circle, complete, completeb,
static char *cmd;
-static FILE *openFile(const char *name)
-{
- FILE *fp;
-
- fp = fopen(name, "w");
- if (!fp) {
- fprintf(stderr, "%s: could not open file %s for writing\n", cmd, name);
- graphviz_exit(1);
- }
- return fp;
-}
-
static char *Usage = "Usage: %s [-dv?] [options]\n\
-c<n> : cycle \n\
-C<x,y> : cylinder \n\
opts->name = optarg;
break;
case 'o':
- opts->outfile = openFile(optarg);
+ opts->outfile = openFile(cmd, optarg, "w");
break;
case 'p':
graphType = path;
<Command>copy $(SolutionDir)windows\dependencies\libraries\vcpkg\installed\x86-windows\bin\getopt.dll $(OutDir)getopt.dll</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h" />
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="graph_generator.c" />
<ClCompile Include="gvgen.c" />
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="graph_generator.c">
<Filter>Source Files</Filter>
#include <stddef.h>
#include <string>
#include <vector>
+#include "openFile.h"
extern "C" {
#ifdef GVDLL
graphviz_exit(v);
}
-static FILE *openFile(const char *name)
-{
- FILE *fp;
-
- fp = fopen(name, "w");
- if (!fp) {
- std::cerr << "gvpack: could not open file " << name << " for writing\n";
- graphviz_exit(1);
- }
- return (fp);
-}
-
/* setNameValue:
* If arg is a name-value pair, add it to the list
* and return 0; otherwise, return 1.
case 'o':
if (outfp != nullptr)
fclose(outfp);
- outfp = openFile(optarg);
+ outfp = openFile("gvpack", optarg, "w");
break;
case 'u':
pinfo->mode = l_undef;
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="graph_generator.h" />
+ <ClInclude Include="openFile.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="gvpack.cpp" />
<ClInclude Include="graph_generator.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="openFile.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="gvpack.cpp">
--- /dev/null
+#pragma once
+
+#include <cgraph/exit.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static inline FILE *openFile(const char *argv0, const char *name,
+ const char *mode) {
+ FILE *fp = fopen(name, mode);
+ if (fp == NULL) {
+ const char *modestr = strcmp(mode, "r") == 0 ? "reading" : "writing";
+ fprintf(stderr, "%s: could not open file %s for %s\n", argv0, name,
+ modestr);
+ perror(name);
+ graphviz_exit(EXIT_FAILURE);
+ }
+ return fp;
+}
#include <ingraphs/ingraphs.h>
#include <getopt.h>
+#include "openFile.h"
#define INF UINT_MAX
}
-static FILE *openFile(const char *name)
-{
- FILE *fp;
-
- fp = fopen(name, "w");
- if (!fp) {
- fprintf(stderr, "gvpack: could not open file %s for writing\n", name);
- graphviz_exit(1);
- }
- return (fp);
-}
-
static char *useString = "Usage: %s [-sdv?] <files>\n\
-s - only produce statistics\n\
-S - silent\n\
case 'o':
if (outfp != NULL)
fclose(outfp);
- outfp = openFile(optarg);
+ outfp = openFile(CmdName, optarg, "w");
break;
case 'v':
Verbose = 1;
<Command>copy $(SolutionDir)windows\dependencies\libraries\vcpkg\installed\x86-windows\bin\getopt.dll $(OutDir)getopt.dll</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h" />
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="sccmap.c" />
</ItemGroup>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="sccmap.c">
<Filter>Source Files</Filter>
#include <ingraphs/ingraphs.h>
#include <getopt.h>
+#include "openFile.h"
static bool Do_fans = false;
static int MaxMinlen = 0;
graphviz_exit(v);
}
-static FILE *openFile(const char *name)
-{
- FILE *fp;
-
- fp = fopen(name, "w");
- if (!fp) {
- fprintf(stderr, "%s: could not open file %s for writing\n", cmd, name);
- graphviz_exit(-1);
- }
- return fp;
-}
-
static char **scanargs(int argc, char **argv)
{
int c, ival;
case 'o':
if (outFile != NULL)
fclose(outFile);
- outFile = openFile(optarg);
+ outFile = openFile(cmd, optarg, "w");
break;
case '?':
if (optopt == '?')
<Command>copy $(SolutionDir)windows\dependencies\libraries\vcpkg\installed\x86-windows\bin\getopt.dll $(OutDir)getopt.dll</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h" />
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="unflatten.c" />
</ItemGroup>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="openFile.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
<ItemGroup>
<ClCompile Include="unflatten.c">
<Filter>Source Files</Filter>