FILE *file;
Agsym_t* sym; /*cgraph atttribute*/
char line[BUFSIZ];
- char* smyrna_attrs = smyrnaPath ("attrs.txt");
+ static char* smyrna_attrs;
char* a;
- g=view->g[view->activeGraph];
- file = fopen(smyrna_attrs, "r");
-
- l=attr_list_new(NULL,1);
-
- if (file != NULL)
- {
+ if (!smyrna_attrs)
+ smyrna_attrs = smyrnaPath ("attrs.txt");
+ g=view->g[view->activeGraph];
+ l=attr_list_new(NULL,1);
+ file = fopen(smyrna_attrs, "r");
+ if (file != NULL) {
int i=0;
while (fgets(line, BUFSIZ, file) != NULL)
{
attr_list_add(l,attr);
}
- }
- sym=NULL;
- while ((sym = agnxtattr(g,AGRAPH, sym)))
- {
+ fclose (file);
+ }
+ sym=NULL;
+ while ((sym = agnxtattr(g,AGRAPH, sym))) {
attr=binarySearch(l, sym->name);
if (attr)
attr->objType[0]=1;
attr=new_attr_with_ref(sym);
attr_list_add(l,attr);
}
- }
+ }
sym=NULL;
while ((sym = agnxtattr(g,AGNODE, sym)))
{
}
}
-
-
-
-
void load_attributes()
{
FILE *file;
}
attrcount++;
}
+ fclose (file);
}
}
}
attrcount++;
}
+ fclose (file);
}
}
void show_gui_warning(char *str)
char* a;
char* action_file = smyrnaPath ("mouse_actions.txt");
file = fopen(action_file, "r");
- if (file != NULL)
- {
+ if (file != NULL) {
int ind=0;
while (fgets(line, BUFSIZ, file) != NULL)
{
}
ind++;
}
+ fclose (file);
}
-
-
-
-
-
-
-
-
-
-
-
-
-
+ free (action_file);
/*
}
-
-
-
-
int get_mode(ViewInfo* v)
{
*/
char *smyrnaPath(char *suffix)
{
- static int buflen;
- static char *buf;
+ char *buf;
static int baselen;
int slen;
#ifdef WIN32
#endif
assert(smyrnaDir);
- if (!buf) {
+ if (baselen == 0) {
baselen = (int)strlen(smyrnaDir) + 2;
- buflen = baselen + 100;
- buf = N_NEW(buflen, char);
}
slen = (int)strlen(suffix);
- if (baselen + slen > buflen) {
- buflen = baselen + slen;
- buf = realloc(buf, buflen);
- }
+ buf = N_NEW(baselen+slen, char);
sprintf(buf, "%s%s%s", smyrnaDir, pathSep, suffix);
return buf;
}
void update_topview(Agraph_t * g, topview * t, int init)
{
-
char *info_file;
char *str;
char buf[512];
settvxdot(view->g[view->activeGraph], view->Topview);
init_node_size(g, t);
/*This is a temp code , need to be removed after Xue's demo */
+#if UNUSED
info_file = agget(g, "demo_file");
if ((info_file != NULL) && (strlen(info_file) != 0)) {
agxbuf xbuf;
/*end of temp code */
+#endif
if (view->SignalBlock)
btnToolZoomFit_clicked(NULL, NULL);
}
if ((outputfile = fopen(filename, "w"))) {
- if (agwrite(subg, outputfile)) {
+ int ret = agwrite(subg, outputfile);
+ fclose (outputfile);
+ if (ret) {
agdelsubg(view->g[view->activeGraph], subg);
return 1;
} else {
FILE *input_file = NULL;
FILE *input_file2 = NULL;
get_data_dir();
+ static char* path;
input_file = fopen(view->template_file, "rb");
if (!input_file) {
"default attributes template graph file \"%s\" not found\n",
view->template_file);
exit(-1);
- } else if (!(view->systemGraphs.def_attrs = agread(input_file, 0))) {
+ }
+ view->systemGraphs.def_attrs = agread(input_file, 0);
+ fclose (input_file);
+
+ if (!view->systemGraphs.def_attrs) {
fprintf(stderr,
"could not load default attributes template graph file \"%s\"\n",
view->template_file);
exit(-1);
}
- printf ("%s\n",smyrnaPath("attr_widgets.dot"));
- input_file2 = fopen(smyrnaPath("attr_widgets.dot"), "rb");
- if (!input_file2)
- {
+ if (!path)
+ path = smyrnaPath("attr_widgets.dot");
+ printf ("%s\n", path);
+ input_file2 = fopen(path, "rb");
+ if (!input_file2) {
fprintf(stderr, "default attributes template graph file \"%s\" not found\n",smyrnaPath("attr_widgets.dot"));
exit(-1);
}
- else if (!(view->systemGraphs.attrs_widgets = agread(input_file2, 0)))
- {
+ view->systemGraphs.attrs_widgets = agread(input_file2, 0);
+ fclose (input_file2);
+ if (!(view->systemGraphs.attrs_widgets )) {
fprintf(stderr,"could not load default attribute widgets graph file \"%s\"\n",smyrnaPath("attr_widgets.dot"));
exit(-1);
}
g_print("Cannot open %s\n", filename);
return 0;
}
- if (!(g = agread(input_file, NIL(Agdisc_t *)))) {
+ g = agread(input_file, NIL(Agdisc_t *));
+ fclose (input_file);
+ if (!g) {
g_print("Cannot read graph in %s\n", filename);
- fclose(input_file);
return 0;
}
*/
if (!agattr(g, AGNODE, "pos", NULL)) {
g_print("There is no position info in %s\n", filename);
- fclose(input_file);
return 0;
}
free(view->Topview->Graphdata.GraphFileName);
*/
int save_graph_with_file_name(Agraph_t * graph, char *fileName)
{
-
+ int ret;
FILE *output_file;
update_graph_params(graph);
if (fileName)
return 0;
}
- if (agwrite(graph, (void *) output_file)) {
+ ret = agwrite(graph, (void *) output_file);
+ fclose (output_file);
+ if (ret) {
g_print("%s successfully saved \n", fileName);
return 1;
}