From: erg Date: Mon, 16 Nov 2009 20:29:02 +0000 (+0000) Subject: Fixes for bug 1816 X-Git-Tag: LAST_LIBGRAPH~32^2~1565 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad89aba3649571288ec7860b1ede579792dccae5;p=graphviz Fixes for bug 1816 --- diff --git a/cmd/smyrna/gui/frmobjectui.c b/cmd/smyrna/gui/frmobjectui.c index b061ecef0..1ae22e7d0 100644 --- a/cmd/smyrna/gui/frmobjectui.c +++ b/cmd/smyrna/gui/frmobjectui.c @@ -647,16 +647,15 @@ attr_list* load_attr_list(Agraph_t* g) 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) { @@ -689,10 +688,10 @@ attr_list* load_attr_list(Agraph_t* g) 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; @@ -701,7 +700,7 @@ attr_list* load_attr_list(Agraph_t* g) attr=new_attr_with_ref(sym); attr_list_add(l,attr); } - } + } sym=NULL; while ((sym = agnxtattr(g,AGNODE, sym))) { @@ -1394,10 +1393,6 @@ void change_selected_edge_attributes(Agraph_t * g, char *attrname, } } - - - - void load_attributes() { FILE *file; @@ -1488,6 +1483,7 @@ void load_attributes() } attrcount++; } + fclose (file); } } diff --git a/cmd/smyrna/gui/gui.c b/cmd/smyrna/gui/gui.c index e31c31cf2..27d1ca18a 100755 --- a/cmd/smyrna/gui/gui.c +++ b/cmd/smyrna/gui/gui.c @@ -400,6 +400,7 @@ void load_attributes(void) } attrcount++; } + fclose (file); } } void show_gui_warning(char *str) diff --git a/cmd/smyrna/hotkeymap.c b/cmd/smyrna/hotkeymap.c index 3beff0003..61e56d4b1 100644 --- a/cmd/smyrna/hotkeymap.c +++ b/cmd/smyrna/hotkeymap.c @@ -100,8 +100,7 @@ void load_mouse_actions (char* modefile,ViewInfo* v) 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) { @@ -139,20 +138,9 @@ void load_mouse_actions (char* modefile,ViewInfo* v) } ind++; } + fclose (file); } - - - - - - - - - - - - - + free (action_file); /* @@ -222,10 +210,6 @@ void load_mouse_actions (char* modefile,ViewInfo* v) } - - - - int get_mode(ViewInfo* v) { diff --git a/cmd/smyrna/main.c b/cmd/smyrna/main.c index aba12b254..9b0d949be 100755 --- a/cmd/smyrna/main.c +++ b/cmd/smyrna/main.c @@ -67,8 +67,7 @@ unsigned char SmyrnaVerbose; */ char *smyrnaPath(char *suffix) { - static int buflen; - static char *buf; + char *buf; static int baselen; int slen; #ifdef WIN32 @@ -78,16 +77,11 @@ char *smyrnaPath(char *suffix) #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; } diff --git a/cmd/smyrna/topview.c b/cmd/smyrna/topview.c index f3d5d9f83..7addf8cfe 100755 --- a/cmd/smyrna/topview.c +++ b/cmd/smyrna/topview.c @@ -327,7 +327,6 @@ void init_node_size(Agraph_t * g, topview * t) void update_topview(Agraph_t * g, topview * t, int init) { - char *info_file; char *str; char buf[512]; @@ -343,6 +342,7 @@ void update_topview(Agraph_t * g, topview * t, int init) 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; @@ -362,6 +362,7 @@ void update_topview(Agraph_t * g, topview * t, int init) /*end of temp code */ +#endif if (view->SignalBlock) btnToolZoomFit_clicked(NULL, NULL); diff --git a/cmd/smyrna/tvnodes.c b/cmd/smyrna/tvnodes.c index 82694e200..83df3f058 100755 --- a/cmd/smyrna/tvnodes.c +++ b/cmd/smyrna/tvnodes.c @@ -538,7 +538,9 @@ int create_save_subgraph_from_filter(char *filename) } 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 { diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index 4711d03a7..09e7d7334 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -350,6 +350,7 @@ void init_viewport(ViewInfo * view) FILE *input_file = NULL; FILE *input_file2 = NULL; get_data_dir(); + static char* path; input_file = fopen(view->template_file, "rb"); if (!input_file) { @@ -357,22 +358,28 @@ void init_viewport(ViewInfo * view) "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); } @@ -582,9 +589,10 @@ static Agraph_t *loadGraph(char *filename) 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; } @@ -592,7 +600,6 @@ static Agraph_t *loadGraph(char *filename) */ 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); @@ -720,7 +727,7 @@ md5_byte_t *get_md5_key(Agraph_t * graph) */ int save_graph_with_file_name(Agraph_t * graph, char *fileName) { - + int ret; FILE *output_file; update_graph_params(graph); if (fileName) @@ -736,7 +743,9 @@ int save_graph_with_file_name(Agraph_t * graph, char *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; }