コード例 #1
0
ファイル: window.c プロジェクト: je-so/js-projekt
static int childprocess_unittest(void)
{
   resourceusage_t   usage = resourceusage_FREE;
   display_t         disp  = display_FREE;
   window_t          win   = window_FREE;
   window_evh_t      evhandler = window_evh_INIT_NULL;
   EGLContext        eglcontext = EGL_NO_CONTEXT;

   // prepare
   TEST(0 == initdefault_display(&disp))
   TEST(0 == init_test_window(&win, &eglcontext, &disp, &evhandler));

   if (test_transparentalpha(&disp))   goto ONERR;

   TEST(0 == init_resourceusage(&usage));

   if (test_initfree(&disp))           goto ONERR;

   acceptleak_helper(&usage);
   TEST(0 == same_resourceusage(&usage));
   TEST(0 == free_resourceusage(&usage));

   WAITFOR(&disp, false);
   size_t    logsize;
   uint8_t * logbuffer;
   GETBUFFER_ERRLOG(&logbuffer, &logsize);
   for (unsigned i = 0; i <= 2; ++i) {
      TEST(0 == init_resourceusage(&usage));

      if (test_showhide(&win, &disp))     goto ONERR;
      if (test_position(&win, &disp))     goto ONERR;
      if (test_resize(&win, &disp))       goto ONERR;

      WAITFOR(&disp, false);
      if (0 == same_resourceusage(&usage)) break;
      TEST(0 == free_resourceusage(&usage));
      TRUNCATEBUFFER_ERRLOG(logsize);
   }
   TEST(0 == same_resourceusage(&usage));
   TEST(0 == free_resourceusage(&usage));

   // unprepare
   TEST(0 == free_window(&win));
   TEST(0 == free_display(&disp));

   return 0;
ONERR:
   (void) free_resourceusage(&usage);
   (void) free_window(&win);
   (void) free_display(&disp);
   return EINVAL;
}
コード例 #2
0
ファイル: viewportqlabel.cpp プロジェクト: cacunas/VAT
void ViewportQLabel::free_window() {
    if(display_window != NULL) {
        QObject::disconnect(display_window,SIGNAL(dialogClosed()),this,SLOT(free_window()));
        delete display_window;
        display_window = NULL;
    }
}
コード例 #3
0
ファイル: ff_radial.c プロジェクト: robwink/davinci
Var* ff_radial_symmetry2(vfuncptr func, Var* arg)
{
	Var *obj = NULL, *rval = NULL;
	float ignore = FLT_MIN;
	float* out;
	int x, y, z, i, j;
	int size  = 0;
	int width = 0, height = 0;
	Window* w;

	Alist alist[9];
	alist[0]      = make_alist("object", ID_VAL, NULL, &obj);
	alist[1]      = make_alist("x", DV_INT32, NULL, &width);
	alist[2]      = make_alist("y", DV_INT32, NULL, &height);
	alist[3]      = make_alist("size", DV_INT32, NULL, &size);
	alist[4]      = make_alist("ignore", DV_FLOAT, NULL, &ignore);
	alist[5].name = NULL;

	if (parse_args(func, arg, alist) == 0) return (NULL);

	if (obj == NULL) {
		parse_error("%s: No object specified\n", func->name);
		return (NULL);
	}

	if (size) {
		width  = size;
		height = size;
	}

	if (width <= 0 || height <= 0) {
		parse_error("%s: Invalid size specified (%dx%d)\n", func->name, width, height);
		return (NULL);
	}

	x = GetX(obj);
	y = GetY(obj);
	z = GetZ(obj);
	w = create_window(width, height, DV_FLOAT);

	out  = calloc((size_t)x * (size_t)y, sizeof(float));
	rval = newVal(BSQ, x, y, 1, DV_FLOAT, out);

	for (i = 0; i < x; i += 1) {
		load_window(w, obj, i, 0, ignore);
		for (j = 0; j < y; j += 1) {
			if (j) roll_window(w, obj, i, j, ignore);

			out[cpos(i, j, 0, rval)] = radial_symmetry2(w->row, width, height, ignore);
		}
	}

	free_window(w);
	return (rval);
}
コード例 #4
0
ファイル: viewportqlabel.cpp プロジェクト: cacunas/VAT
void ViewportQLabel::mouseDoubleClickEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton){
        const QPixmap *p = this->pixmap();
        if(p != NULL) {
            if(display_window == NULL) {
                display_window = new ImageWindowDisplay(label,0);
                QObject::connect(display_window,SIGNAL(dialogClosed()),this,SLOT(free_window()));
                display_window->show();
            } else {
                display_window->raise();
            }
            display_window->setPixmap(p);
        }
    }
}
コード例 #5
0
ファイル: ff_median.c プロジェクト: robwink/davinci
Var* ff_local_maximum(vfuncptr func, Var* arg)
{
	Var *obj = NULL, *rval = NULL;
	float ignore = FLT_MIN;
	float* out;
	int x, y, i, j;
	int size        = 3;
	float threshold = FLT_MIN;
	Window* w;

	Alist alist[9];
	alist[0]      = make_alist("object", ID_VAL, NULL, &obj);
	alist[1]      = make_alist("size", DV_INT32, NULL, &size);
	alist[2]      = make_alist("ignore", DV_FLOAT, NULL, &ignore);
	alist[3]      = make_alist("threshold", DV_FLOAT, NULL, &threshold);
	alist[4].name = NULL;

	if (parse_args(func, arg, alist) == 0) return (NULL);

	if (obj == NULL) {
		parse_error("%s: No object specified\n", func->name);
		return (NULL);
	}

	x = GetX(obj);
	y = GetY(obj);
	w = create_window(size, size, DV_FLOAT);

	out  = calloc(x * y, sizeof(float));
	rval = newVal(BSQ, x, y, 1, DV_FLOAT, out);

	for (i = 0; i < x; i += 1) {
		load_window(w, obj, i, 0, ignore);
		for (j = 0; j < y; j += 1) {
			if (j) roll_window(w, obj, i, j, ignore);

			out[cpos(i, j, 0, rval)] = local_maximum(w, threshold, ignore);
		}
	}

	free_window(w);
	return (rval);
}
コード例 #6
0
ファイル: riftwm.c プロジェクト: nandor/riftwm
static void
destroy_window(riftwm_t *wm, Window window)
{
  riftwin_t *win = wm->windows, *last = NULL, *tmp;

  while (win) {
    if (win->window == window) {
      tmp = win;
      win = win->next;
      if (last) {
        last->next = win;
      } else {
        wm->windows = win;
      }

      wm->window_count--;
      free_window(wm, tmp);
    } else {
      last = win;
      win = win->next;
    }
  }
}
コード例 #7
0
ファイル: ff_radial.c プロジェクト: robwink/davinci
Var* ff_radial_symmetry3(vfuncptr func, Var* arg)
{
	Var* obj     = NULL;
	float ignore = FLT_MIN;
	int width = 0, height = 0;
	int end   = 1;
	Var* rval = NULL;
	int x, y;
	float* out;
	Window* w;

	int *distance, d;
	int dx, dy;
	double ssxx, ssyy, ssxy;
	int i, j, p, q, r;
	int h2, w2;
	float v1, v2;
	int total;
	float *r1, *r2;
	int start = 0, step = 1;

	struct dstore {
		double sumx;
		double sumy;
		double sumxx;
		double sumyy;
		double sumxy;
		int count;
	} * accum, *a1, *a2;

	Alist alist[6];
	alist[0]      = make_alist("object", ID_VAL, NULL, &obj);
	alist[1]      = make_alist("size", DV_INT32, NULL, &end);
	alist[2]      = make_alist("ignore", DV_FLOAT, NULL, &ignore);
	alist[3]      = make_alist("start", DV_INT32, NULL, &start);
	alist[4]      = make_alist("step", DV_INT32, NULL, &step);
	alist[5].name = NULL;

	if (parse_args(func, arg, alist) == 0) return (NULL);

	if (obj == NULL) {
		parse_error("%s: No object specified\n", func->name);
		return (NULL);
	}

	if (end <= 0) {
		parse_error("%s: Invalid end value specified\n", func->name);
		return (NULL);
	}

	x = GetX(obj);
	y = GetY(obj);

	width  = end * 2 + 1;
	height = end * 2 + 1;
	// width = end;
	// height = end;
	w = create_window(width, height, DV_FLOAT);

	/* cache some frequently used computed values */
	h2    = height / 2;
	w2    = width / 2;
	total = width * height;

	/* precompute the distance of every point in a given sized window
	** to the center of the window.
	**
	** In theory, this only needs to be 1 quadrant of the window, but that's
	** too hard to bookkeep, and doesn't save much.
	*/
	distance = calloc(total, sizeof(int));
	for (i = 0; i < width; i++) {
		dx = i - w2;
		for (j = 0; j < height; j++) {
			dy                      = j - h2;
			distance[i + j * width] = floor(sqrt(dx * dx + dy * dy));
			/* precheck for values outside the largest circle */
			if (distance[i + j * width] > end) distance[i + j * width] = 0;
		}
	}

	out   = calloc((size_t)x * (size_t)y * (size_t)((end - start) / step + 1), sizeof(float));
	rval  = newVal(BSQ, x, y, ((end - start) / step + 1), DV_FLOAT, out);
	accum = calloc(end + 1, sizeof(struct dstore));

	/* run a window over every pixel and do the math */
	for (i = 0; i < x; i += 1) {
		load_window(w, obj, i, 0, ignore);
		for (j = 0; j < y; j += 1) {
			if (j) roll_window(w, obj, i, j, ignore);

			v1 = ((float**)w->row)[h2][w2];

			if (v1 == ignore) {
				continue;
			}

			memset(accum, 0, (end + 1) * sizeof(struct dstore));

			/*
			** pick a pair of opposing points, and add them to the
			** accumulator for their given distance.  We'll sum all the
			** accumulators later for a complete result from dist 1..N.
			*/

			for (q = 0; q <= h2; q++) {
				/* one of the double-derefs moved to here for speed */
				r1 = ((float**)w->row)[q];
				r2 = ((float**)w->row)[(height - 1) - q];
				for (p = 0; p < width; p++) {
					if (q == h2 && p == w2) {
						/* We only run the window up to the center point  */
						break;
					}

					v1 = r1[p];
					v2 = r2[(width - 1) - p];

					if (v1 == ignore || v2 == ignore) continue;

					if ((d = distance[p + q * width]) != 0) {
						a1 = &(accum[d]);
						a1->sumx += v1;
						a1->sumy += v2;
						a1->sumxx += v1 * v1;
						a1->sumyy += v2 * v2;
						a1->sumxy += v1 * v2;
						a1->count++;
					}
				}
			}

			/* now compute correlation from per-radii accumulators */
			for (r = 1; r <= end; r++) {
				/* sum the values in preceeding bins */
				a1 = &accum[r - 1];
				a2 = &accum[r];
				if (a1->count) {
					a2->sumx += a1->sumx;
					a2->sumy += a1->sumy;
					a2->sumxx += a1->sumxx;
					a2->sumyy += a1->sumyy;
					a2->sumxy += a1->sumxy;
					a2->count += a1->count;
				}
				// Don't bother if at least 1/2 the box isn't ignore values
				// this is M_PI_4 because we're only counting half the pixels
				// to begin with.
				if ((r - start) % step == 0) {
					if (a2->count > r * r * M_PI_4) {
						double c = a2->count;
						ssxx     = a2->sumxx - a2->sumx * a2->sumx / c;
						ssyy     = a2->sumyy - a2->sumy * a2->sumy / c;
						ssxy     = a2->sumxy - a2->sumx * a2->sumy / c;
						if (ssxx != 0 && ssyy != 0) {
							out[cpos(i, j, ((r - start) / step), rval)] =
							    sqrt(ssxy * ssxy / (ssxx * ssyy));
						}
					}
				}
			}
		}
		printf("%d/%d\r", i, x);
		fflush(stdout);
	}

	free_window(w);
	free(distance);
	free(accum);

	return (rval);
}
コード例 #8
0
ファイル: ff_radial.c プロジェクト: robwink/davinci
Var* ff_radial_symmetry(vfuncptr func, Var* arg)
{
	Var *obj = NULL, *rval = NULL;
	float ignore = FLT_MIN;
	float* out   = NULL;
	int x, y, z, i, j, k;
	int size   = 10;
	int xdelta = 0.0, ydelta = 0.0;
	float* line = NULL;
	int all     = 0;
	int first   = 1;
	Window* w;

	Alist alist[9];
	alist[0]      = make_alist("object", ID_VAL, NULL, &obj);
	alist[1]      = make_alist("size", DV_INT32, NULL, &size);
	alist[2]      = make_alist("xdelta", DV_INT32, NULL, &xdelta);
	alist[3]      = make_alist("ydelta", DV_INT32, NULL, &ydelta);
	alist[4]      = make_alist("ignore", DV_FLOAT, NULL, &ignore);
	alist[5]      = make_alist("all", DV_INT32, NULL, &all);
	alist[6]      = make_alist("first", DV_INT32, NULL, &first);
	alist[7].name = NULL;

	if (parse_args(func, arg, alist) == 0) return (NULL);

	if (obj == NULL) {
		parse_error("%s: No object specified\n", func->name);
		return (NULL);
	}

	if (size < 0) {
		parse_error("%s: Invalid size specified\n", func->name);
		return (NULL);
	}

	x = GetX(obj);
	y = GetY(obj);
	z = GetZ(obj);
	w = create_window(size, size, DV_FLOAT);

	if (all) {
		size_t n = (size_t)x * (size_t)y * (size_t)(size - first + 1);
		out      = (float*)calloc(n, sizeof(float));
		rval     = newVal(BSQ, x, y, (size - first + 1), DV_FLOAT, out);
		line     = (float*)calloc(size, sizeof(float));
	} else {
		size_t n = (size_t)x * (size_t)y;
		out      = (float*)calloc(n, sizeof(float));
		rval     = newVal(BSQ, x, y, 1, DV_FLOAT, out);
		line     = NULL;
	}

	for (i = 0; i < x; i += 1) {
		load_window(w, obj, i, 0, ignore);
		for (j = 0; j < y; j += 1) {
			if (j) roll_window(w, obj, i, j, ignore);

			out[cpos(i, j, 0, rval)] =
			    radial_symmetry(w->row, size, size, ignore, xdelta, ydelta, size, line);
			if (all) {
				for (k = first; k <= size; k++) {
					out[cpos(i, j, k - first, rval)] = line[k];
				}
			}
		}
	}

	free_window(w);
	return (rval);
}
コード例 #9
0
ファイル: window.c プロジェクト: je-so/js-projekt
static int test_initfree(display_t * disp)
{
   window_t    win   = window_FREE;
   gconfig_t   gconf = gconfig_FREE;
   int32_t     surfattr[4][7] = {
         { gconfig_TYPE, gconfig_value_TYPE_WINDOW_BIT, gconfig_BITS_RED, 8, gconfig_NONE },
         { gconfig_TYPE, gconfig_value_TYPE_WINDOW_BIT, gconfig_BITS_ALPHA, 1, gconfig_BITS_STENCIL, 1, gconfig_NONE },
         { gconfig_TYPE, gconfig_value_TYPE_WINDOW_BIT, gconfig_BITS_BUFFER, 24, gconfig_BITS_DEPTH, 1, gconfig_NONE },
         { gconfig_TYPE, gconfig_value_TYPE_WINDOW_BIT, gconfig_CONFORMANT, gconfig_value_CONFORMANT_ES2_BIT|gconfig_value_CONFORMANT_OPENGL_BIT, gconfig_NONE },
   };
   windowconfig_t winattr[] = {
         windowconfig_INIT_FRAME, windowconfig_INIT_TRANSPARENCY(255), windowconfig_INIT_TITLE("name"),
         windowconfig_INIT_MINSIZE(10,10), windowconfig_INIT_MAXSIZE(1000,1000),
         windowconfig_INIT_SIZE(1000,1000), windowconfig_INIT_POS(333,444), windowconfig_INIT_NONE
   };

   // TEST window_FREE
   TEST(1 == isfree_helper(&win));
   TEST(1 == ISFREE_OSWINDOW(&win.oswindow));

   for (unsigned i = 0; i < lengthof(surfattr); ++i) {
      TEST(0 == init_gconfig(&gconf, disp, surfattr[i]));

      // TEST init_window
      TEST(0 == init_window(&win, disp, defaultscreennr_display(disp), 0, &gconf, winattr));
      TEST(0 != gl_window(&win));

      // TEST free_window
      TEST(0 == free_window(&win));
      TEST(1 == isfree_helper(&win));
      TEST(1 == ISFREE_OSWINDOW(&win.oswindow));
      TEST(0 == free_window(&win));
      TEST(1 == isfree_helper(&win));
      TEST(1 == ISFREE_OSWINDOW(&win.oswindow));

      TEST(0 == free_gconfig(&gconf));
   }

   // prepare
   TEST(0 == init_gconfig(&gconf, disp, surfattr[0]));

   // TEST init_window: E2BIG
   windowconfig_t winattr2big[3*windowconfig__NROF+2];
   for (unsigned i = 0; i < lengthof(winattr2big)-1; ++i) {
      winattr2big[i] = (windowconfig_t)windowconfig_INIT_FRAME;
   }
   winattr2big[lengthof(winattr2big)-1] = (windowconfig_t) windowconfig_INIT_NONE;
   TEST(E2BIG == init_window(&win, disp, defaultscreennr_display(disp), 0, &gconf, winattr2big));
   TEST(0 == free_window(&win));
   TEST(1 == isfree_helper(&win));

   // TEST init_window: ERROR
   for (unsigned i = 1; i <= 2; ++i) {
      init_testerrortimer(&s_window_errtimer, i, ENOMEM);
      TEST(ENOMEM == init_window(&win, disp, defaultscreennr_display(disp), 0, &gconf, winattr));
      TEST(0 == free_window(&win));
      TEST(1 == isfree_helper(&win));
   }

   // TEST free_window: ERROR
   for (unsigned i = 1; i <= 2; ++i) {
      TEST(0 == init_window(&win, disp, defaultscreennr_display(disp), 0, &gconf, winattr));
      init_testerrortimer(&s_window_errtimer, i, ENOMEM);
      TEST(ENOMEM == free_window(&win));
      TEST(0 == free_window(&win));
      TEST(1 == isfree_helper(&win));
   }

   // unprepare
   TEST(0 == free_gconfig(&gconf));

   return 0;
ONERR:
   (void) free_gconfig(&gconf);
   (void) free_window(&win);
   return EINVAL;
}
コード例 #10
0
ファイル: window.c プロジェクト: je-so/js-projekt
static int test_transparentalpha(display_t * disp)
{
   int32_t           surfattr[] = {
                        gconfig_TRANSPARENT_ALPHA, 1,
                        gconfig_BITS_BUFFER, 32, gconfig_NONE
                     };
   windowconfig_t    winattr[]  = {
                        windowconfig_INIT_TITLE("test-graphic-window"),
                        windowconfig_INIT_SIZE(100, 100),
                        windowconfig_INIT_POS(50, 100),
                        windowconfig_INIT_NONE
                     };
   window_t    top      = window_FREE;
   window_t    bottom   = window_FREE;
   gconfig_t   gconf = gconfig_FREE;
   uint32_t    snr      = defaultscreennr_display(disp);
   EGLContext  eglcontext = EGL_NO_CONTEXT;

   // prepare
   TEST(0 == init_gconfig(&gconf, disp, surfattr));
   eglcontext = eglCreateContext(gl_display(disp), gl_gconfig(&gconf), EGL_NO_CONTEXT, 0);
   TEST(EGL_NO_CONTEXT != eglcontext);

   // TEST init_window: gconfig_TRANSPARENT_ALPHA: draw overlay on top of bottom
   TEST(0 == init_window(&top, disp, snr, 0, &gconf, winattr));
   TEST(0 == init_window(&bottom, disp, snr, 0, &gconf, winattr));

   // TEST swapbuffer_window: bottom window opaque color
   TEST(0 == show_x11window(os_window(&bottom)));
   WAITFOR(disp, os_window(&bottom)->state == x11window_state_SHOWN);
   TEST(EGL_TRUE == eglMakeCurrent(gl_display(disp), (void*)gl_window(&bottom), (void*)gl_window(&bottom), eglcontext));
   glClearColor(1, 0, 0, 1);
   glClear(GL_COLOR_BUFFER_BIT);
   TEST(0 == swapbuffer_window(&bottom, disp));
   eglWaitGL();
   // red color
   TEST(0 == compare_color(os_window(&bottom), 100, 100, 1, 0, 0));

   // TEST swapbuffer_window: top window with transparent value
   TEST(0 == show_x11window(os_window(&top)));
   WAITFOR(disp, os_window(&top)->state == x11window_state_SHOWN);
   TEST(EGL_TRUE == eglMakeCurrent(gl_display(disp), (void*)gl_window(&top), (void*)gl_window(&top), eglcontext));
   glClearColor(0, 0, 1, 0); // transparent blue
   glClear(GL_COLOR_BUFFER_BIT);
   TEST(0 == swapbuffer_window(&top, disp));
   eglWaitGL();
   // resulting color is the combination of red and blue
   TEST(0 == compare_color(os_window(&bottom), 100, 100, 1, 0, 1));

   // unprepare
	TEST(EGL_TRUE == eglMakeCurrent(gl_display(disp), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
	TEST(EGL_TRUE == eglDestroyContext(gl_display(disp), eglcontext));
   TEST(0 == free_gconfig(&gconf));
   TEST(0 == free_window(&bottom));
   TEST(0 == free_window(&top));
   WAITFOR(disp, false);
   eglReleaseThread();

   return 0;
ONERR:
   eglMakeCurrent(gl_display(disp), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
   if (eglcontext != EGL_NO_CONTEXT) eglDestroyContext(gl_display(disp), eglcontext);
   (void) free_gconfig(&gconf);
   (void) free_window(&top);
   (void) free_window(&bottom);
   return EINVAL;
}
コード例 #11
0
ファイル: draw_graph.c プロジェクト: coin-or/SYMPHONY
int main(void)
{
   dg_prob *dgp;
   dg_params *par;
   FILE *read_from, *write_to;
   int childpid, sender;

   char tcl_msg[MAX_LINE_LENGTH +1];
   char name[MAX_NAME_LENGTH +1], name2[MAX_NAME_LENGTH +1];
   char source[MAX_NAME_LENGTH +1], target[MAX_NAME_LENGTH +1];
   char title[MAX_TITLE_LENGTH +1], title2[MAX_TITLE_LENGTH +1];
   char fname[MAX_FILE_NAME_LENGTH +1];
   char old_weight[MAX_WEIGHT_LENGTH +1], new_weight[MAX_WEIGHT_LENGTH +1];
   char new_label[MAX_LABEL_LENGTH +1];
   char new_dash[MAX_DASH_PATTERN_LENGTH +1];
   char *str;
   int msgtag, keyword, key, r_bufid, s_bufid, bufid, bytes, len;

   int i, j, k, number, add_nodenum, change_nodenum, delete_nodenum;
   int add_edgenum, change_edgenum, delete_edgenum;
   int nodenum, new_nodenum, edgenum, new_edgenum, node_id, edge_id;
   int new_radius, old_deleted_nodenum;
   unsigned int id;
   win_desc *desc;
   dg_graph *g;
   dg_node *nodes, *nod;
   dg_edge *edges, *edg;
   window *win, *new_win, *source_win, *target_win;

   register_process();
   dgp = (dg_prob *) calloc(1, sizeof(dg_prob));

   /* receive parameters from the master */
   r_bufid = receive_msg(ANYONE, DG_DATA);
   bufinfo(r_bufid, &bytes, &msgtag, &dgp->master);
   receive_char_array((char *)&dgp->par, sizeof(dg_params));
   freebuf(r_bufid);
   par = &(dgp->par);
   echo_commands = par->echo_commands;

   /* fork the wish shell */
   childpid = start_child((char *)"wish", &read_from, &write_to);

   /* Source the tcl scripts into wish and invoke startUp*/
   spprint(write_to, "source %s/Init.tcl\n", par->source_path);
   spprint(write_to, "source %s/Tools.tcl\n", par->source_path);
   spprint(write_to, "source %s/NodeEdgeBasics.tcl\n", par->source_path);
   spprint(write_to, "source %s/FileMenu.tcl\n", par->source_path);
   spprint(write_to, "source %s/WindowMenu.tcl\n", par->source_path);
   spprint(write_to, "source %s/NodeMenu.tcl\n", par->source_path);
   spprint(write_to, "source %s/EdgeMenu.tcl\n", par->source_path);
   spprint(write_to, "source %s/CAppl.tcl\n", par->source_path);

   spprint(write_to, "Igd_StartUp\n");

   /* set application defaults to those stored in par */
   spprint(write_to,
	   "Igd_SetApplDefaults %i %i %i %i %i %i %i {%s} {%s} %i %i %i %f {%s} {%s} {%s}\n",
	   par->canvas_width, par->canvas_height, par->viewable_width,
	   par->viewable_height, par->disp_nodelabels,
	   par->disp_nodeweights, par->disp_edgeweights, par->node_dash,
	   par->edge_dash, par->node_radius, par->interactive_mode,
	   par->mouse_tracking, par->scale_factor, par->nodelabel_font,
	   par->nodeweight_font, par->edgeweight_font);

   /* invoke user initialization */
#ifdef USE_SYM_APPLICATION
   CALL_USER_FUNCTION( user_initialize_dg(&dgp->user) );
#endif

   while(TRUE){

      msgtag = 0;

      if (dgp->waiting_to_die){
	 for ( i = 0; i < dgp->window_num; ){
	    if ( ! dgp->windows[i]->wait_for_click ){
	       spprint(write_to, "Igd_QuitWindow %u\n",dgp->windows[i]->id);
	       free_window(&dgp->window_num, dgp->windows, i);
	    }else{
	       i++;
	    }
	 }
	 if ( ! dgp->window_num )
	    wait_for_you_can_die(dgp, write_to);
      }

      /* Interpret message coming from the tcl application. */
      if (fgets(tcl_msg, 80, read_from) != NULL) {
	 sscanf(tcl_msg, "%i", &msgtag);

	 switch(msgtag){

	  case IGDTOI_CLICK_HAPPENED:
	    /* if wait_for_click is 2, send a message to the owner */
	    fgets(name2, MAX_NAME_LENGTH +1, read_from);
	    sscanf(name2, "%u", &id);
	    for (i = dgp->window_num - 1; i >= 0; i-- )
	       if ( dgp->windows[i]->id == id )
		  break;
	    if ( i < 0 ) {
	       /* this should never happen */
	       printf("Window of id %u is not found\n", id);
	       break;
	    }
	    if ( dgp->windows[i]->wait_for_click == 2 ) {
	       s_bufid = init_send(DataInPlace);
	       send_str(name);
	       send_msg(dgp->windows[i]->owner_tid, ITOC_CLICK_HAPPENED); 
	       freebuf(s_bufid); 
	    }
	    dgp->windows[i]->wait_for_click = 0;
	    break;

	  case IGDTOI_QUIT_WINDOW:
	    /* delete data structure corresponding to this window */
	    fgets(name2, MAX_NAME_LENGTH +1, read_from);
	    sscanf(name2, "%u", &id);
	    for (i = dgp->window_num - 1; i >= 0; i-- )
	       if ( dgp->windows[i]->id == id )
		  break;
	    if ( i < 0 ) {
	       /* this should never happen */
	       printf("Window of id %u is not found\n", id);
	       break;
	    }
	    spprint(write_to, "Igd_QuitWindow %u\n", id);
	    free_window(&dgp->window_num, dgp->windows, i);
	    break;

	  case IGDTOI_QUIT_APPLICATION:
	    /* delete all windows */
	    for ( i = 0; i < dgp->window_num; ){
	       if ( ! dgp->windows[i]->wait_for_click ){
		  spprint(write_to, "Igd_QuitWindow %u\n",dgp->windows[i]->id);
		  free_window(&dgp->window_num, dgp->windows, i);
	       }else{
		  i++;
	       }
	    }
	    dgp->waiting_to_die = TRUE;
	    break;

	  case IGDTOI_TEXT_ENTERED:
	    fgets(name2, MAX_NAME_LENGTH +1, read_from);
	    sscanf(name2, "%u", &id);
	    for (i = dgp->window_num - 1; i >= 0; i-- )
	       if ( dgp->windows[i]->id == id )
		  break;
	    win = dgp->windows[i];
	    if ( i < 0 ) {
	       /* this should never happen */
	       printf("Window of id %u is not found\n", id);
	       break;
	    }
	    fgets(tcl_msg, MAX_LINE_LENGTH +1, read_from);
	    sscanf(tcl_msg, "%i", &win->text_length);
	    win->text = (char *) malloc( (win->text_length + 1) * CSIZE);
	    fread(win->text, CSIZE, win->text_length, read_from);
	    win->text[win->text_length] = 0;

	    /* invoke function that interprets the message */
#ifdef USE_SYM_APPLICATION
	    CALL_USER_FUNCTION( user_interpret_text(dgp->user,
						    win->text_length,
						    win->text,
						    win->owner_tid) );
#endif
	    break;

	  case IGDTOI_REQUEST_GRAPH:
	    fgets(name2, MAX_NAME_LENGTH +1, read_from);
	    sscanf(name2, "%u", &id);
	    for (i = dgp->window_num - 1; i >= 0; i-- )
	       if ( dgp->windows[i]->id == id )
		  break;
	    if ( i < 0 ) {
	       /* this should never happen */
	       printf("Window of id %u is not found\n", id);
	       break;
	    }
	    display_graph_on_canvas(dgp->windows[i], write_to);
	    break;

	  default:
	    printf("Unknown message type from IGD to I (%i)\n", msgtag);
	    break;
	 
	 } /* end switch */
      } /* end if */

      if (dgp->waiting_to_die)
	 continue;


      /* Interpret the message coming from the C application.

	 All the messages except INITIALIZE_WINDOW and COPY_GRAPH
	 and QUIT will be put on the pipe corresponding to the appropriate
	 window (messages are processed in FIFO order

	 In case of INITIALIZE_WINDOW the data structure associated
	 with a winow is created (including the pipes.

	 In case of COPY_GRAPH a message must be placed on both the
	 source and the target window's pipe.

	 In case of QUIT all data structures are disassembled and then
	 the tcl application is killed.                                   */

      r_bufid = nreceive_msg(ANYONE, ANYTHING);
      if (r_bufid > 0){
	 bufinfo(r_bufid, &bytes, &msgtag, &sender);
	 switch (msgtag){

	  case CTOI_INITIALIZE_WINDOW:

	    /* get the name of the new window */
	    receive_str(name);
	    receive_str(title);

	    /* if a window with this name already exists: error */
	    i = find_window(dgp->window_num, dgp->windows, name);
	    if ( i >= 0 ) {
	       INTERMED_ERROR(name, msgtag, sender,ITOC_WINDOW_ALREADY_EXISTS);
	       freebuf(r_bufid);
	       break;
	    }
	    /* allocate space for the new window */
	    win = init_dgwin(dgp, sender, name, title);

	    /* set up the window description */
	    receive_int_array(&number, 1);
	    copy_win_desc_from_par(win, &dgp->par);
	    for ( ; number > 0; number-- ) {
	       /* read out the key - value pairs */
	       receive_int_array(&key, 1);
	       set_window_desc_pvm(key, win);
	    }

	    freebuf(r_bufid);
	    break;


	  case CTOI_COPY_GRAPH:
	    /* Copy source's graph into target's window.
	       Here a message is placed onto both target's and source's
	       pipe so that they can wait for each other before the
	       actual copying happens (shake hands) */
	    
	    receive_str(target);
	    receive_str(source);

	    i = find_window(dgp->window_num, dgp->windows, target);
	    if (i < 0) { /* target doesn't exist, send error message */
	       INTERMED_ERROR(target, msgtag, sender,ITOC_WINDOW_DOESNT_EXIST);
	       freebuf(r_bufid);
	       break;
	    }
	    j = find_window(dgp->window_num, dgp->windows, source);
	    if (j < 0) { /* source doesn't exist, send error message */
	       INTERMED_ERROR(source, msgtag, sender,ITOC_WINDOW_DOESNT_EXIST);
	       freebuf(r_bufid);
	       break;
	    }
	    bufid = init_send(DataInPlace);
	    msgtag = WAITING_TO_GET_A_COPY;
	    send_int_array(&msgtag, 1);
	    send_str(source);
	    add_msg(dgp->windows[i], bufid);
	    setsbuf(0);

	    bufid = init_send(DataInPlace);
	    msgtag = WAITING_TO_BE_COPIED;
	    send_int_array(&msgtag, 1);
	    send_str(target);
	    add_msg(dgp->windows[j], bufid);
	    setsbuf(0);

	    freebuf(r_bufid);
	    break;


	  case CTOI_QUIT:
	    /* quit from all windows, disassemble data structures.
	     * (actually, this will happen on the top of the while loop...) */
	    if (! dgp->waiting_to_die)
	       dgp->waiting_to_die = TRUE;
	    freebuf(r_bufid);
	    break;

	  case CTOI_YOU_CAN_DIE:
	    /* quit from all windows, disassemble data structures.
	     * (actually, this will happen on the top of the while loop...)
	     * and die */
	    dgp->waiting_to_die = 2 * TRUE;
	    freebuf(r_bufid);
	    break;


	  default:
	    /* Check if window with name exists. If not, send back error
	       message. If yes, copy the message over to window's pipe. */
	    receive_str(name);
	    len = strlen(name);
	    i = find_window(dgp->window_num, dgp->windows, name);
	    if (i < 0){
	       /* there is no window of that name: send error message */
	       INTERMED_ERROR(name, msgtag, sender,ITOC_WINDOW_DOESNT_EXIST);
	       freebuf(r_bufid);
	       break;
	    }

	    add_msg(dgp->windows[i], r_bufid);
	    setrbuf(0);
	    break;
	 } /* end switch */
      } /* endif r_bufid > 0 */


      if (dgp->waiting_to_die)
	 continue;

      /* Process one message from each window's pipe. */

      for ( i = 0; i < dgp->window_num; i++ ) {

	 win = dgp->windows[i];

	 /* if wait_for_click is set, skip */
	 if ( win->wait_for_click )
	    continue;

	 /* if window is waiting to be copied or waiting to get a copy, skip */
	 if ( win->copy_status )
	    continue;

	 /* if no message in the pipe, skip */
	 if (win->buf.bufread == -1)
	    continue;

	 /* else: process the message .... */
	 msgtag = 0;
	 r_bufid = get_next_msg(win);
	 setrbuf(r_bufid);
	 bufinfo(r_bufid, &bytes, &msgtag, &sender);

	 if (msgtag == 0){
	    /* This means that the message was locally 'hand-packed' */
	    receive_int_array(&msgtag, 1);
	 }

	 switch ( msgtag ) {

	  case CTOI_USER_MESSAGE:
#ifdef USE_SYM_APPLICATION
	    user_dg_process_message(win->user, win, write_to);
#endif
	    break;

	  case CTOI_QUIT_WINDOW:
	    /* delete this window */
	    spprint(write_to, "Igd_QuitWindow %u\n", win->id);
	    free_window(&dgp->window_num, dgp->windows, i);
	    i--;
	    break;


	  case CTOI_CHANGE_WINDOW_DESC:
	    /* change window descriptions */
	    receive_int_array(&number, 1);
	    for ( ; number > 0; number-- ) {
	       /* read out the key - value pairs */
	       receive_int_array(&key, 1);
	       set_window_desc_pvm(key, win);
	    }
	    desc = &(win->desc);
	    if ( win->window_displayed ) {
	       spprint(write_to, "Igd_SetAndExecuteWindowDesc %u %i %i %i %i %i %i %i {%s} {%s} %i %i %i %f {%s} {%s} {%s}\n",
		       win->id, desc->canvas_width, desc->canvas_height,
		       desc->viewable_width, desc->viewable_height,
		       desc->disp_nodelabels, desc->disp_nodeweights,
		       desc->disp_edgeweights, desc->node_dash,
		       desc->edge_dash, desc->node_radius,
		       desc->interactive_mode, desc->mouse_tracking,
		       desc->scale_factor, desc->nodelabel_font,
		       desc->nodeweight_font, desc->edgeweight_font);
	    }
	    break;


	  case CTOI_SET_GRAPH:
	  case CTOI_SET_AND_DRAW_GRAPH:
	    /* define the graph corresponding to this window */
	    g = &(win->g);
	    FREE(g->nodes);
	    FREE(g->edges);

	    receive_int_array(&g->nodenum, 1);
	    if ( g->nodenum ) {
	       nodes = g->nodes =
		  (dg_node *) malloc(g->nodenum * sizeof(dg_node));
	       for ( j = 0; j < g->nodenum; j++ ) {
		  read_node_desc_from_pvm(nodes+j, win);
	       }
	    }

	    receive_int_array(&g->edgenum, 1);
	    if ( g->edgenum ) {
	       edges = g->edges =
		  (dg_edge *) malloc(g->edgenum * sizeof(dg_edge));
	       for ( j = 0; j < g->edgenum; j++ ) {
		  read_edge_desc_from_pvm(edges+j, win);
	       }
	    }

	    if ( msgtag == CTOI_SET_AND_DRAW_GRAPH || win->window_displayed )
	       display_graph_on_canvas(win, write_to);

	    break;


	  case CTOI_DRAW_GRAPH:
	    /* first erase/create the window itself, then display all the nodes
	       and edges */
	    display_graph_on_canvas(win, write_to);
	    break;


	  case CTOI_DELETE_GRAPH:
	    /* delete the data structure of the graph and erase its window
	     if open */
	    FREE(win->g.nodes);
	    FREE(win->g.edges);
	    win->g.nodenum = win->g.deleted_nodenum = 0;
	    win->g.edgenum = win->g.deleted_edgenum = 0;
	    if ( win->window_displayed ){
	       spprint(write_to, "Igd_EraseWindow %u\n", win->id);
	    }
	    break;


	  case CTOI_WAIT_FOR_CLICK_NO_REPORT:
	    /* window will not get any messages until the Continue button
	       is pressed. the window has to be open to have an effect */
	    if ( win->window_displayed ) {
	       win->wait_for_click = 1;
	       spprint(write_to, "Igd_CApplWaitForClick %u\n", win->id);
	    } else {
	       INTERMED_ERROR(win->name, msgtag, win->owner_tid,
			      ITOC_WINDOW_ISNT_DISPLAYED);
	    }
	    break;


	  case CTOI_WAIT_FOR_CLICK_AND_REPORT:
	    /* window will not get any messages until the Continue button
	       is pressed. the window has to be open to have an effect.
	       the owner gets a message */
	    if ( win->window_displayed ) {
	       win->wait_for_click = 2;
	       spprint(write_to, "Igd_CApplWaitForClick %u\n", win->id);
	    } else {
	       INTERMED_ERROR(win->name, msgtag, win->owner_tid,
			      ITOC_WINDOW_ISNT_DISPLAYED);
	    }
	    break;


	  case CTOI_SAVE_GRAPH_TO_FILE:
	    /* save the graph into a file (only if it is displayed!) */
	    receive_str(fname);
	    if ( win->window_displayed ) {
	       spprint(write_to, "Igd_SaveGraph %u {%s}\n", win->id, fname);
	    } else {
	       INTERMED_ERROR(win->name, msgtag, win->owner_tid,
			      ITOC_WINDOW_ISNT_DISPLAYED);
	    }
	    break;


	  case CTOI_SAVE_GRAPH_PS_TO_FILE:
	    /* save postscript of the picture displayed. works only if
	       window is displayed. */
	    receive_str(fname);
	    if ( win->window_displayed ) {
	       spprint(write_to, "Igd_SavePs %u {%s}\n", win->id, fname);
	    } else {
	       INTERMED_ERROR(win->name, msgtag, win->owner_tid,
			      ITOC_WINDOW_ISNT_DISPLAYED);
	    }
	    break;


	  case CTOI_CLONE_WINDOW:
	    /* clone this window. if window is not displayed, only the
	     graph data structure will be copied over. */
	    /* wait_for_click, copy_status and text will not be copied over. */
	    receive_str(name2);
	    receive_str(title2);

	    if ( find_window(dgp->window_num, dgp->windows, name2) >= 0 ) {
	       INTERMED_ERROR(win->name, msgtag, sender,
			      ITOC_WINDOW_ALREADY_EXISTS);
	       break;
	    }

	    new_win = init_dgwin(dgp, sender, name2, title2);
	    copy_window_structure(new_win, win);

	    if ( win->window_displayed ) {
	       spprint(write_to,
		       "Igd_CopyWindowDesc %u %u\n", new_win->id, win->id);
	       spprint(write_to,
		       "Igd_InitWindow %u {%s}\n", new_win->id, title2);
	       spprint(write_to, "Igd_DisplayWindow %u\n", new_win->id);
	       spprint(write_to, "Igd_EnableCAppl %u\n", new_win->id);
	       spprint(write_to, "Igd_CopyGraph %u %u\n", new_win->id,win->id);
	       new_win->window_displayed = 1;
	    }
	    break;
	    

	  case CTOI_RENAME_WINDOW:
	    /* change the title of the window */
	    receive_str(win->title);
	    if ( win->window_displayed ){
	       spprint(write_to,
		       "Igd_RenameWindow %u {%s}\n", win->id, win->title);
	    }
	    break;


	  case CTOI_RESIZE_VIEWABLE_WINDOW:
	    /* change the sizes of canvas */
	    receive_int_array(&win->desc.viewable_width, 1);
	    receive_int_array(&win->desc.viewable_height, 1);
	    if ( win->window_displayed ){
	       spprint(write_to, "Igd_ResizeViewableWindow %u %i %i\n",
		       win->id, win->desc.viewable_width,
		       win->desc.viewable_height);
	    }
	    break;


	  case CTOI_RESIZE_CANVAS:
	    /* change the size of the canvas */
	    receive_int_array(&win->desc.canvas_width, 1);
	    receive_int_array(&win->desc.canvas_height, 1);
	    if ( win->window_displayed ){
	       spprint(write_to, "Igd_ResizeCanvas %u %i %i\n", win->id,
		       win->desc.canvas_width, win->desc.canvas_height);
	    }
	    break;


	  case WAITING_TO_GET_A_COPY:
	    /* Read out the name of the source-graph from the pipe.
	       If the source-graph is waiting to be copied, source and
	       target have found each other */
	    receive_str(win->source) ;
	    win->copy_status = 2;

	    j = find_window(dgp->window_num, dgp->windows, win->source);
	    if ( j >= 0 && dgp->windows[j]->copy_status == 1 ) {
	       /* source graph exists and it is waiting to be copied */
	       source_win = dgp->windows[j];

	       /* copy the data structure */
	       copy_window_structure(win, source_win);

	       /* if the window is displayed, change picture */
	       if ( win->window_displayed ) {
		  display_graph_on_canvas(win, write_to);
	       }

	       /* zero out the copy stati */
	       win->copy_status = 0;
	       win->source[0] = 0;
	       source_win->copy_status = 0;
	       source_win->target[0] = 0;
	    }
	    break;


	  case WAITING_TO_BE_COPIED:
	    /* Read out the name of the target graph from the pipe.
	       If the target-graph is waiting to get a copy, source and
	       target have found each other. */
	    receive_str(win->target);
	    win->copy_status = 1;

	    j = find_window(dgp->window_num, dgp->windows, win->target);
	    if ( j >= 0 && dgp->windows[j]->copy_status == 2 ) {
	       /* target exists and waiting for a copy */
	       target_win = dgp->windows[j];

	       /* copy the data structure */
	       copy_window_structure(target_win, win);

	       /* if the target window is displayed, update the picture */
	       if ( target_win->window_displayed ) {
		  display_graph_on_canvas(target_win, write_to);
	       }

	       /* zero out the copy stati */
	       win->copy_status = 0;
	       win->target[0] = 0;
	       target_win->copy_status = 0;
	       target_win->source[0] = 0;
	    }
	    break;
	    

	  case CTOI_MODIFY_GRAPH:
	    /* Make changes in the graph. The data structure is updated,
	       and if the window is displayed, the picture gets updated, too */

	    /* The message is in keyword - description pairs, with the
	       END_OF_MESSAGE keyword at the end. We switch on the keyword */

	    do {
	       receive_int_array(&keyword, 1);

	       switch ( keyword ) {

		case MODIFY_ADD_NODES:
		  /* same format as in SET_GRAPH */
		  receive_int_array(&add_nodenum, 1);
		  if ( add_nodenum ) {
		     g = &(win->g);
		     nodenum = g->nodenum;
		     nodes = g->nodes = (dg_node *)
			realloc(g->nodes,
				(nodenum + add_nodenum) * sizeof(dg_node));
		     for (j = 0, new_nodenum = nodenum; j < add_nodenum; j++) {
			read_node_desc_from_pvm(nodes+new_nodenum, win);
			if (find_node(nodes[new_nodenum].node_id, g) < 0)
			   new_nodenum++;
		     }
		     g->nodenum = new_nodenum;

		     if ( win->window_displayed ) {
			for ( j = nodenum; j < new_nodenum; j++ ) {
			   nod = nodes + j;
			   spprint(write_to,
				   "Igd_MakeNode %u %i %i %i {%s} {%s} %i\n",
				   win->id, nod->node_id, nod->posx,
				   nod->posy, nod->label, nod->dash,
				   nod->radius);
			   if ( *nod->weight != 0 ){
			      spprint(write_to,
				      "Igd_MakeNodeWeight %u %i {%s}\n",
				      win->id, nod->node_id, nod->weight);
			   }
			}
		     }
		  }

		  break;


		case MODIFY_CHANGE_WEIGHTS_OF_NODES:
		  /* change weights of nodes. nodes not in the graph or nodes
		     already deleted are skipped, no error message is given. */
		  g = &(win->g);
		  receive_int_array(&change_nodenum, 1);
		  for ( j = 0; j < change_nodenum; j++ ) {
		     receive_int_array(&node_id, 1);
		     receive_str(new_weight);
		     if ( (k = find_node(node_id, g)) >= 0 ) {
			strcpy(g->nodes[k].weight, new_weight);
			if ( win->window_displayed ) {
			   strcpy(old_weight, g->nodes[k].weight);
			   if ( *old_weight != 0 ) {
			      if ( *new_weight != 0 ) {
				 spprint(write_to,
					 "Igd_ChangeOneNodeWeight %u %i {%s}\n"
					 , win->id, node_id, new_weight);
			      } else {
				 /* new weight == 0 */
				 spprint(write_to,
					 "Igd_DeleteNodeWeight %u %i\n",
					 win->id, node_id);
			      }
			   } else {
			      /* no weight before */
			      if ( *new_weight != 0 ) {
				 spprint(write_to,
					 "Igd_MakeNodeWeight %u %i {%s}\n",
					 win->id, node_id, new_weight);
			      }
			   }
			}
		     }
		  }
		  break;


		case MODIFY_CHANGE_LABELS_OF_NODES:
		  /* change labels of nodes. nodes not in the graph or nodes
		     already deleted are skipped, no error message is given */
		  g = &(win->g);
		  receive_int_array(&change_nodenum, 1);
		  for ( j = 0; j < change_nodenum; j++ ) {
		     receive_int_array(&node_id, 1);
		     receive_str(new_label);
		     if ( (k = find_node(node_id, g)) >= 0 ) {
			strcpy(g->nodes[k].label, new_label);
			if ( win->window_displayed ) {
			   spprint(write_to,
				   "Igd_ChangeOneNodeLabel %u %i {%s}\n",
				   win->id, node_id, new_label);
			}
		     }
		  }
		  break;


		case MODIFY_CHANGE_DASH_OF_NODES:
		  /* change dash pattern of individual nodes. nodes not in the
		     graph will not cause error messages */
		  g = &(win->g);
		  receive_int_array(&change_nodenum, 1);
		  for ( j = 0; j < change_nodenum; j++ ) {
		     receive_int_array(&node_id, 1);
		     receive_str(new_dash);
		     if ( (k = find_node(node_id, g)) >= 0 ) {
			strcpy(g->nodes[k].dash, new_dash);
			if ( win->window_displayed ){
			   spprint(write_to,
				   "Igd_ChangeOneNodeDash %u %i {%s}\n",
				   win->id, node_id, new_dash);
			}
		     }
		  }
		  break;


		case MODIFY_CHANGE_RADII_OF_NODES:
		  /* change radii of individual nodes. nodes not in the
		     graph will not cause error messages */
		  g = &(win->g);
		  receive_int_array(&change_nodenum, 1);
		  for ( j = 0; j < change_nodenum; j++ ) {
		     receive_int_array(&node_id, 1);
		     receive_int_array(&new_radius, 1);
		     if ( (k = find_node(node_id, g)) >= 0 ) {
			g->nodes[k].radius = new_radius;
			if ( win->window_displayed ){
			   spprint(write_to,
				   "Igd_ChangeOneNodeRadius %u %i %i\n",
				   win->id, node_id, new_radius);
			}
		     }
		  }
		  break;


		case MODIFY_DELETE_NODES:
		  /* nodes not in the graph will not cause error messages */
		  receive_int_array(&delete_nodenum, 1);
		  if ( delete_nodenum ) {
		     g = &(win->g);
		     old_deleted_nodenum = g->deleted_nodenum;
		     for ( j = 0; j < delete_nodenum; j++ ) {
			receive_int_array(&node_id, 1);
			if ( (k = find_node(node_id, g)) >= 0 ) {
			   g->nodes[k].deleted = 1;
			   g->deleted_nodenum++;
			   if ( win->window_displayed ){
			      spprint(write_to,
				      "Igd_DeleteNode %u %i\n", win->id,
				      node_id);
			   }
			}
		     }
		     if ( g->deleted_nodenum > old_deleted_nodenum ) { 
			/* mark edges that have at least one deleted endpoint
			   to be deleted. Igd_DeleteNode already took care of
			   deleting these edges from the picture */
			for (k=g->edgenum-1, edg=g->edges; k >= 0; k--, edg++)
			   if ( ! edg->deleted &&
				((find_node(edg->tail, g) < 0) ||
				 (find_node(edg->head, g) < 0))){
			      edg->deleted = 1;
			      g->deleted_edgenum++;
			   }
		     }
		     /* if too many nodes and/or edges have been deleted,
			compress the graph */
		     if ( g->deleted_nodenum > 0.1 * g->nodenum ||
			 g->deleted_edgenum > 0.1 * g->edgenum )
			compress_graph(g);
		  }
		     
		  break;


		case MODIFY_ADD_EDGES:
		  /* same format as in SET_GRAPH. Nonvalid edges (one or
		   both endpoints is not in the graph will not cause an error
		   message. */
		  receive_int_array(&add_edgenum, 1);
		  if ( add_edgenum ) {
		     g = &(win->g);
		     edgenum = g->edgenum;
		     edges = g->edges = (dg_edge *)
			realloc(g->edges,
				(edgenum+add_edgenum)*sizeof(dg_edge));
		     for (j = 0, new_edgenum = edgenum; j < add_edgenum; j++) {
			edg = edges + new_edgenum;
			read_edge_desc_from_pvm(edg, win);
			if ((find_edge(edg->edge_id, g) < 0) &&
			    (find_node(edg->tail, g) >= 0) &&
			    (find_node(edg->head, g) >= 0))
			   new_edgenum++;
		     }
		     g->edgenum = new_edgenum;

		     if ( win->window_displayed ) {
			for ( j = edgenum; j < new_edgenum; j++ ) {
			   edg = edges + j;
			   spprint(write_to, "Igd_MakeEdge %u %i %i %i {%s}\n",
				   win->id, edg->edge_id, edg->tail,
				   edg->head, edg->dash);
			   if ( *edg->weight != 0 ){
			      spprint(write_to,
				      "Igd_MakeEdgeWeight %u %i {%s}\n",
				      win->id, edg->edge_id, edg->weight);
			   }
			}
		     }
		  }

		  break;


		case MODIFY_CHANGE_WEIGHTS_OF_EDGES:
		  /* change weights of edges. edges not in the graph or edges
		     already deleted are skipped, no error message is given. */
		  g = &(win->g);
		  receive_int_array(&change_edgenum, 1);
		  for ( j = 0; j < change_edgenum; j++ ) {
		     receive_int_array(&edge_id, 1);
		     receive_str(new_weight);
		     if ( (k = find_edge(edge_id, g)) >= 0 ) {
			strcpy(g->edges[k].weight, new_weight);
			if ( win->window_displayed ) {
			   strcpy(old_weight, g->edges[k].weight);
			   if ( *old_weight != 0 ) {
			      if ( *new_weight != 0 ) {
				 spprint(write_to,
					 "Igd_ChangeOneEdgeWeight %u %i {%s}\n"
					 , win->id, edge_id, new_weight);
			      } else {
				 /* new weight : 0 */
				 spprint(write_to,
					 "Igd_DeleteEdgeWeight %u %i\n",
					 win->id, edge_id);
			      }
			   } else {
			      /* no weight before */
			      if ( *new_weight != 0 ) {
				 spprint(write_to,
					 "Igd_MakeEdgeWeight %u %i {%s}\n",
					 win->id, edge_id, new_weight);
			      }
			   }
			}
		     }
		  }

		  break;


		case MODIFY_CHANGE_DASH_OF_EDGES:
		  /* change dash pattern of individual edges. edges not in the
		     graph will not cause error messages */
		  g = &(win->g);
		  receive_int_array(&change_edgenum, 1);
		  for ( j = 0; j < change_edgenum; j++ ) {
		     receive_int_array(&edge_id, 1);
		     receive_str(new_dash);
		     if ( (k = find_edge(edge_id, g)) >= 0 ) {
			strcpy(g->edges[k].dash, new_dash);
			if ( win->window_displayed ){
			   spprint(write_to,
				   "Igd_ChangeOneEdgeDash %u %i {%s}\n",
				   win->id, edge_id, new_dash);
			}
		     }
		  }
		  
		  break;


		case MODIFY_DELETE_EDGES:
		  /* edges not in the graph will not cause error messages */
		  g = &(win->g);
		  receive_int_array(&delete_edgenum, 1);
		  for ( j = 0; j < delete_edgenum; j++ ) {
		     receive_int_array(&edge_id, 1);
		     if ( (k = find_edge(edge_id, g)) >= 0 ) {
			g->edges[k].deleted = 1;
			g->deleted_edgenum++;
			if ( win->window_displayed ) {
			   spprint(write_to, "Igd_DeleteEdge %u %i\n",
				   win->id, edge_id);
			}
		     }
		  }
		  /* if too many edges have been deleted, compress the
		     graph */
		  if ( g->deleted_edgenum > 0.1 * g->edgenum )
		     compress_graph(g);
		  
		  break;


		case MODIFY_DELETE_ALL_EDGES:
		  /* will delete all edges from the graph */
		  g = &(win->g);
		  if ( win->window_displayed ) {
		     for ( j = 0; j < g->edgenum; j++ ) 
			if ( ! g->edges[j].deleted ){
			   spprint(write_to, "Igd_DeleteEdge %u %i\n",
				   win->id, g->edges[j].edge_id);
			}
		  }
		  FREE(g->edges);
		  g->edgenum = 0;
		  
		  break;
		  
		case MODIFY_END_OF_MESSAGE:
		  break;
		  
		  
		default:
		  printf("Unrecognized keyword %i\n", keyword);
		  break;
		  
		  
	       } /* end switch (keyword) */
	       
	    } while ( keyword != MODIFY_END_OF_MESSAGE );

	    break;


	  case CTOI_CLEAR_MESSAGE:
	    if ( win->window_displayed ) {
	       spprint(write_to, "Igd_CApplClearCmsg %u\n", win->id);
	    }
	    break;

	  case CTOI_PRINT_MESSAGE:
	    if ( win->window_displayed ) {
	       str = malloc(bytes);
	       receive_str(str);
	       spprint(write_to, "Igd_CApplSetCmsg %u {%s}\n", win->id, str);
	       FREE(str);
	    }
	    break;

	  case CTOI_APPEND_MESSAGE:
	    if ( win->window_displayed ) {
	       str = malloc(bytes);
	       receive_str(str);
	       spprint(write_to, "Igd_CApplAppendCmsg %u {%s}\n", win->id,str);
	       FREE(str);
	    }
	    break;

	  default:
	    printf("Unknown message tag: %i\n", msgtag);
	    break;

	 } /* end switch (msgtag) */

	 freebuf(r_bufid);
      } /* end for */
      
   } /* end while */
   return(0);
}
コード例 #12
0
ファイル: worker_thread.c プロジェクト: pinchyCZN/DB_UTIL
void __cdecl thread(void *args)
{
	int id;
	HANDLE *event_list=args;
	HANDLE event=0,event_idle=0;
	if(args==0)
		return;
	event=event_list[0];
	event_idle=event_list[1];
	if(event==0 || event_idle==0)
		return;
	printf("worker thread started\n");
	while(TRUE){
		stop_thread_menu(FALSE);
		SetEvent(event_idle);
		id=WaitForSingleObject(event,INFINITE);
		if(id==WAIT_OBJECT_0){
			stop_thread_menu(TRUE);
			strncpy(localinfo,taskinfo,sizeof(localinfo));
			printf("db=%s\n",localinfo);
			switch(task){
			case TASK_CLOSE_DB:
				{
					DB_TREE *db=0;
					if(find_db_tree(localinfo,&db)){
						intelli_del_db(db->name);
						mdi_remove_db(db);
						set_status_bar_text(ghstatusbar,0,"closed %s",localinfo);
					}
					else
						set_status_bar_text(ghstatusbar,0,"cant find %s",localinfo);
				}
				break;
			case TASK_OPEN_DB_AND_TABLE:
			case TASK_OPEN_DB:
				{
					DB_TREE *db=0;
					char *table;
					int result=FALSE;
					table=strstr(localinfo,";TABLE=");
					if(table!=0){
						table[0]=0;
						table++;
					}
					SetWindowText(ghstatusbar,"opening DB");
					if(!wait_for_treeview()){
						SetWindowText(ghstatusbar,"treeview error");
						break;
					}
					acquire_db_tree(localinfo,&db);
					if(!mdi_open_db(db)){
						char str[512];
						mdi_remove_db(db);
						_snprintf(str,sizeof(str),"Cant open %s",localinfo);
						str[sizeof(str)-1]=0;
						MessageBox(ghmainframe,str,"OPEN DB FAIL",MB_OK);
						SetWindowText(ghstatusbar,"error opening DB");
						set_focus_after_open(db);
					}
					else{
						intelli_add_db(db->name);
						set_focus_after_open(db);
						reassign_tables(db);
						if(task==TASK_OPEN_DB_AND_TABLE &&
							table!=0 && strncmp(table,"TABLE=",sizeof("TABLE=")-1)==0){
							table+=sizeof("TABLE=")-1;
							ResetEvent(event);
							task_open_table(db->name,table);
							continue;
						}
						else{
							load_tables_if_empty(db);
							if(keep_closed)
								close_db(db);
							result=TRUE;
						}
					}
					set_status_bar_text(ghstatusbar,0,"open DB %s %s",result?"done":"failed",keep_closed?"(closed DB)":"");
				}
				break;
			case TASK_GET_COL_INFO:
				{
					void *db=0;
					char table[80]={0};
					sscanf(localinfo,"DB=0x%08X;TABLE=%79[ -~]",&db,table);
					table[sizeof(table)-1]=0;
					if(db!=0){
						int result;
						set_status_bar_text(ghstatusbar,0,"getting col info for %s",table);
						result=get_col_info(db,table);
						if(keep_closed)
							close_db(db);
						if(result)
							set_status_bar_text(ghstatusbar,0,"col info done, %s",keep_closed?"(closed DB)":"");
						set_focus_after_open(db);
					}
				}
				break;
			case TASK_GET_INDEX_INFO:
				{
					void *db=0;
					char table[80]={0};
					sscanf(localinfo,"DB=0x%08X;TABLE=%79[ -~]",&db,table);
					table[sizeof(table)-1]=0;
					if(db!=0){
						int result;
						set_status_bar_text(ghstatusbar,0,"getting index info for %s",table);
						result=get_index_info(db,table);
						if(keep_closed)
							close_db(db);
						if(result)
							set_status_bar_text(ghstatusbar,0,"index info done, %s",keep_closed?"(closed DB)":"");
						set_focus_after_open(db);
					}
				}
				break;
			case TASK_GET_FOREIGN_KEYS:
				{
					void *db=0;
					char table[80]={0};
					sscanf(localinfo,"DB=0x%08X;TABLE=%79[ -~]",&db,table);
					table[sizeof(table)-1]=0;
					if(db!=0){
						int result;
						set_status_bar_text(ghstatusbar,0,"getting foreign keys for %s",table);
						result=get_foreign_keys(db,table);
						if(keep_closed)
							close_db(db);
						if(result)
							set_status_bar_text(ghstatusbar,0,"index info done, %s",keep_closed?"(closed DB)":"");
						set_focus_after_open(db);
					}
				}
				break;
			case TASK_UPDATE_ROW:
				{
					int result=FALSE;
					void *win=0;
					int row=0;
					sscanf(localinfo,"WIN=0x%08X;ROW=%i",&win,&row);
					if(win!=0){
						char *s=strstr(localinfo,"DATA=");
						if(s!=0){
							s+=sizeof("DATA=")-1;
							result=update_row(win,row,s);
							if(keep_closed){
								void *db=0;
								acquire_db_tree_from_win(win,&db);
								close_db(db);
							}
						}
					}
					set_status_bar_text(ghstatusbar,0,"update row %s %s",
						result?"done":"failed",
						keep_closed?"(closed DB)":"");
				}
				break;
			case TASK_DELETE_ROW:
				{
					int result=FALSE;
					void *win=0;
					int row=0;
					sscanf(localinfo,"WIN=0x%08X;ROW=%i",&win,&row);
					if(win!=0){
						result=delete_row(win,row);
						if(keep_closed){
							void *db=0;
							acquire_db_tree_from_win(win,&db);
							close_db(db);
						}
					}
					set_status_bar_text(ghstatusbar,0,"delete row %s",
						result?"done":"failed",
						(win!=0 && keep_closed)?"(closed DB)":"");
				}
				break;
			case TASK_INSERT_ROW:
				{
					int result=FALSE;
					void *win=0,*hlistview=0;
					sscanf(localinfo,"WIN=%08X,HLISTVIEW=0x%08X",&win,&hlistview);
					if(win!=0 && hlistview!=0){
						int msg=IDOK;
						result=insert_row(win,hlistview);
						if(!result)
							msg=IDCANCEL;
						PostMessage(GetParent(hlistview),WM_USER,msg,hlistview);
						if(keep_closed){
							void *db=0;
							acquire_db_tree_from_win(win,&db);
							close_db(db);
						}
					}
					set_status_bar_text(ghstatusbar,0,"inserting row %s %s",
						result?"done":"failed",
						(win!=0 && hlistview!=0 && keep_closed)?"(closed DB)":"");

				}
				break;
			case TASK_EXECUTE_QUERY:
				{
					void *win=0;
					int result=FALSE;
					win=strtoul(localinfo,0,0);
					if(win==0)
						mdi_get_current_win(&win);
					if(win!=0){
						char *s=0;
						int size=0;
						reopen_db(win);
						mdi_create_abort(win);
						mdi_get_edit_text(win,&s,&size);
						if(s!=0){
							sql_remove_comments(s,size);
							result=execute_sql(win,s,TRUE);
							free(s);
						}
						mdi_destroy_abort(win);
						if(keep_closed){
							void *db=0;
							acquire_db_tree_from_win(win,&db);
							close_db(db);
						}
						set_focus_after_result(win,result);
					}
					if(!result)
						set_status_bar_text(ghstatusbar,0,"execute sql failed %s",
							keep_closed?"(closed DB)":"");
				}
				break;
			case TASK_NEW_QUERY:
				{
					void *db=0;
					find_selected_tree(&db);
					if(db!=0){
						void *win=0;
						char *tname="new_query";
						if(acquire_table_window(&win,tname)){
							create_table_window(ghmdiclient,win);
							set_focus_after_result(win,FALSE);
							assign_db_to_table(db,win,tname);
						}
					}
				}
				break;
			case TASK_REFRESH_TABLES:
			case TASK_REFRESH_TABLES_ALL:
				{
					int result=FALSE;
					DB_TREE *db=0;
					SetWindowText(ghstatusbar,"refreshing tables");
					if(acquire_db_tree(localinfo,&db)){
						if(!mdi_open_db(db)){
							mdi_remove_db(db);
							SetWindowText(ghstatusbar,"error opening DB");
						}
						else{
							intelli_add_db(db->name);
							result=refresh_tables(db,task==TASK_REFRESH_TABLES_ALL);
							if(keep_closed)
								close_db(db);
						}
						if(result)
							set_status_bar_text(ghstatusbar,0,"refreshed tables %s",
								keep_closed?"(closed DB)":"");
					}
					else
						SetWindowText(ghstatusbar,"error refreshing cant acquire table");
				}
				break;
			case TASK_LIST_TABLES:
				{
					int result=FALSE;
					DB_TREE *db=0;
					SetWindowText(ghstatusbar,"listing tables");
					if(acquire_db_tree(localinfo,&db)){
						if(!mdi_open_db(db)){
							mdi_remove_db(db);
							SetWindowText(ghstatusbar,"error opening DB");
						}
						else{
							intelli_add_db(db->name);
							result=get_table_list(db);
							if(keep_closed)
								close_db(db);
						}
						if(result){
							set_status_bar_text(ghstatusbar,0,"done listing tables %s",
								keep_closed?"(closed DB)":"");
						}else{
							SetWindowText(ghstatusbar,"error listing tables");
						}
					}
					else
						SetWindowText(ghstatusbar,"error refreshing cant acquire tree");
				}
				break;
			case TASK_LIST_PROCS:
				{
					int result=FALSE;
					DB_TREE *db=0;
					SetWindowText(ghstatusbar,"listing stored procedures");
					if(acquire_db_tree(localinfo,&db)){
						if(!mdi_open_db(db)){
							mdi_remove_db(db);
							SetWindowText(ghstatusbar,"error opening DB");
						}
						else{
							intelli_add_db(db->name);
							result=get_proc_list(db);
							if(keep_closed)
								close_db(db);
						}
						if(result){
							set_status_bar_text(ghstatusbar,0,"done listing stored procs %s",
								keep_closed?"(closed DB)":"");
						}else{
							SetWindowText(ghstatusbar,"error listing stored procs");
						}
					}
					else
						SetWindowText(ghstatusbar,"error refreshing cant acquire tree");
				}
				break;
			case TASK_OPEN_TABLE:
				{
					int result=FALSE;
					char dbname[MAX_PATH*2]={0},table[80]={0},*p;
					p=strrchr(localinfo,';');
					if(p!=0){
						void *db=0;
						p[0]=0;
						strncpy(dbname,localinfo,sizeof(dbname));
						strncpy(table,p+1,sizeof(table));
						if(find_db_tree(dbname,&db)){
							void *win=0;
							if(acquire_table_window(&win,table)){
								char sql[256]={0};
								create_table_window(ghmdiclient,win);
								open_db(db);
								assign_db_to_table(db,win,table);
								if(strchr(table,' ')!=0)
									_snprintf(sql,sizeof(sql),"SELECT * FROM [%s]",table);
								else
									_snprintf(sql,sizeof(sql),"SELECT * FROM %s",table);
								mdi_set_edit_text(win,sql);
								mdi_create_abort(win);
								result=execute_sql(win,sql,TRUE);
								mdi_destroy_abort(win);
								load_tables_if_empty(db);
								set_focus_after_result(win,result);
								if(keep_closed)
									close_db(db);

							}
							else
								free_window(win);

						}
					}
					if(!result)
						set_status_bar_text(ghstatusbar,0,"open table:%s %s %s",
							table,"failed",keep_closed?"(closed DB)":"");
				}
				break;
			case TASK_INTELLISENSE_ADD_ALL:
				{
					void *win=0;
					int result=FALSE;
					win=strtoul(localinfo,0,0);
					if(win==0)
						mdi_get_current_win(&win);
					if(win!=0){
						reopen_db(win);
						mdi_create_abort(win);
						result=intellisense_add_all(win);
						mdi_destroy_abort(win);
						if(keep_closed){
							void *db=0;
							acquire_db_tree_from_win(win,&db);
							close_db(db);
						}
						set_focus_after_result(win,FALSE);
					}
					if(!result)
						set_status_bar_text(ghstatusbar,0,"intellisense add all failed %s",
							keep_closed?"(closed DB)":"");
				}
				break;
			default:
				break;
			}
		}
		ResetEvent(event);
	}
	CloseHandle(event);
	hworker=0;
}
コード例 #13
0
ファイル: cosby.c プロジェクト: nicknassar/cosby
int press_record(char *data_filename, char *wave_filename) {
  /* The overall goal here is to seamlessly decode as many different audio
     inputs as possible.

     There's a lot of subtlety to decoding analog input with an FFT,
     especially for a protocol like this one with a symbol that's
     half a wavelength.

     Instead of making proper hardware to amplify and filter the
     output of the TI99/4a, I made this software capable of decoding
     the weak, noisy crap obtained from connecting the microphone
     output to a line-in without any filter or amplifier.

     I perform an FFT over one wavelength once per sample. Computing
     the FFT for every sample is probably overkill, but it's
     significantly faster than realtime even on an old PowerBook G4,
     and it doesn't hurt to average out noise better.

     Using a buffer size of one wavelength means that the first and
     second harmonics are centered at exactly the frequencies we're
     looking at. I believe it's necessary to use a window function, so
     that alternating 0s and ones can be differentiated. I'm using the
     Hamming window (half a sine wave), but there may be better ones.
     
     There can be a lot of noise in the signal, so I keep a
     half-symbol size buffer of the difference between the signal
     strengths of the two frequencies and use the average.  (It it was
     a whole buffer, it would blur out the boundaries between
     symbols.)  If the difference between the low and high and low
     frequncies drops below or rises above the midpoint, it triggers a
     new signal.

*/


  void *in_file;
  FILE *out_file;
  size_t num_harmonics;
  sf_count_t samples_read;
  fftw_complex *harmonics;
  fftw_plan get_frequencies;
  size_t offset = 0;
  double *audio_samples;
  int (*read_samples)(void *device, double *buffer, size_t count);

  /* Initialize the FFT

     If the FFT is over the wavelength of the low frequency (twice the symbol size)

     sample 0 - DC
     sample 1 - wavelen of 2 symbols - "Zero"
     sample 2 - wavelen of 1 symbol - "One"

     This doesn't have a very narrow filter, so it might be susceptable to interference.     
   */
  num_harmonics = DEFAULT_WAVELENGTH/2+1;
  harmonics = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*num_harmonics);

  audio_samples = (double*) fftw_malloc(sizeof(double)*DEFAULT_WAVELENGTH);
  if (wave_filename == NULL) {
    read_samples = &read_from_mic;
    init_mic_input(&in_file);

  } else {
    read_samples = &read_from_file;
    init_file_input(&in_file,wave_filename);
  }
  init_audio_buffer(read_samples, in_file);
  init_history();
  init_window();
  if (data_filename == NULL)
    out_file = stdout;
  else
    out_file = fopen(data_filename,"wb");

  get_frequencies = fftw_plan_dft_r2c_1d(DEFAULT_WAVELENGTH, audio_samples,
					 harmonics,
					 FFTW_ESTIMATE | FFTW_DESTROY_INPUT);


  while ((samples_read = audio_at_offset(read_samples, in_file, audio_samples, offset++, DEFAULT_WAVELENGTH))>0) {
    apply_window_func(audio_samples);
    fftw_execute(get_frequencies);
    if (process_harmonics(harmonics, num_harmonics, out_file))
      break;
  }
  cosby_print("Done!\n");

  if (data_filename != NULL)    
    fclose(out_file);
 
  fftw_destroy_plan(get_frequencies);

  fftw_free(harmonics);
  fftw_free(audio_samples);
  if (wave_filename == NULL) {
  } else {
    free_audio_buffer(in_file);
  }
  free_history();
  free_window();

  return 1;
}