Example #1
0
/* Get a command. This does all the bookkeeping things like turning
 * command completion on and off...  */
static wordlist *
getcommand(char *string)
{
    wordlist *wlist;

    if (cp_debug)
        fprintf(cp_err, "calling getcommand %s\n", string ? string : "");

#if !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE)
    /* set cp_altprompt for use by the lexer - see parser/lexical.c */
    cp_altprompt = get_alt_prompt();
#endif /* !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE) */

    cp_cwait = TRUE;
    wlist = cp_parse(string);
    cp_cwait = FALSE;
    if (cp_debug) {
        printf("getcommand ");
        wl_print(wlist, stdout);
        putc('\n', stdout);
    }
    return (wlist);
}
Example #2
0
/* should be able to do this by sleight of hand on graph parameters */
static void
zoomin(GRAPH *graph)
{
/* note: need to add circular boxes XXX */

    int x0, y0, x1, y1;
    double fx0, fx1, fy0, fy1, ftemp;
    char buf[BSIZE_SP];
    char buf2[128];
    char *t;

    Window rootwindow, childwindow;
    int rootx, rooty;
    unsigned int state;
    int x, y, upperx, uppery;
    unsigned width, height;

    /* open box and get area to zoom in on */

    XQueryPointer(display, DEVDEP(graph).window, &rootwindow,
                  &childwindow, &rootx, &rooty, &x0, &y0, &state);

    x = x1 = x0 + BOXSIZE;
    y = y1 = y0 + BOXSIZE;

    upperx = x0;
    uppery = y0;

    width  = BOXSIZE;
    height = BOXSIZE;

    XDrawRectangle(display, DEVDEP(graph).window, xorgc,
                   upperx, uppery, width, height);

    XWarpPointer(display, None, DEVDEP(graph).window, 0, 0, 0, 0, x1, y1);

    while (state & Button3Mask) {
        if (x != x1 || y != y1) {

            x1 = x;
            y1 = y;

            XDrawRectangle(display, DEVDEP(graph).window, xorgc,
                           upperx, uppery, width, height);

            upperx = MIN(x1, x0);
            uppery = MIN(y1, y0);

            width  = (unsigned) ABS(x1 - x0);
            height = (unsigned) ABS(y1 - y0);

            XDrawRectangle(display, DEVDEP(graph).window, xorgc,
                           upperx, uppery, width, height);
        }
        XQueryPointer(display, DEVDEP(graph).window, &rootwindow,
                      &childwindow, &rootx, &rooty, &x, &y, &state);
    }
    XDrawRectangle(display, DEVDEP(graph).window, xorgc,
                   upperx, uppery, width, height);

    X_ScreentoData(graph, x0, y0, &fx0, &fy0);
    X_ScreentoData(graph, x1, y1, &fx1, &fy1);

    if (fx0 > fx1) {
        ftemp = fx0;
        fx0 = fx1;
        fx1 = ftemp;
    }
    if (fy0 > fy1) {
        ftemp = fy0;
        fy0 = fy1;
        fy1 = ftemp;
    }

    strncpy(buf2, graph->plotname, sizeof(buf2));
    if ((t = strchr(buf2, ':')) != NULL)
        *t = 0;

    if (!eq(plot_cur->pl_typename, buf2)) {
        (void) sprintf(buf,
                       "setplot %s; %s xlimit %.20e %.20e ylimit %.20e %.20e; setplot $curplot\n",
                       buf2, graph->commandline, fx0, fx1, fy0, fy1);
    } else {
        (void) sprintf(buf, "%s xlimit %e %e ylimit %e %e\n",
                       graph->commandline, fx0, fx1, fy0, fy1);
    }

/* don't use the following if using GNU Readline or BSD EditLine */
#if !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE)
    {
        wordlist *wl;

        /* hack for Gordon Jacobs */
        /* add to history list if plothistory is set */
        if (cp_getvar("plothistory", CP_BOOL, NULL)) {
            wl = cp_parse(buf);
            (void) cp_addhistent(cp_event++, wl);
        }
    }
#endif /* !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE) */

    (void) cp_evloop(buf);
}
Example #3
0
/* should be able to do this by sleight of hand on graph parameters */
void
zoomin(GRAPH *graph)
{
/* note: need to add circular boxes XXX */

    int x0, y0, x1, y1;
    double fx0, fx1, fy0, fy1, ftemp;
    char buf[BSIZE_SP];
    char buf2[128];
    char *t;

    Window rootwindow, childwindow;
    int rootx, rooty;
    unsigned int state;
    int x, y, upperx, uppery, lowerx, lowery;

    /* open box and get area to zoom in on */

    XQueryPointer(display, DEVDEP(graph).window, &rootwindow,
	    &childwindow, &rootx, &rooty, &x0, &y0, &state);

    x = lowerx = x1 = x0 + BOXSIZE;
    y = lowery = y1 = y0 + BOXSIZE;
    upperx = x0;
    uppery = y0;

    XDrawRectangle(display, DEVDEP(graph).window, xorgc,
	    upperx, uppery, lowerx - upperx, lowery - uppery);

/* note: what are src_x, src_y, src_width, and src_height for? XXX */
    XWarpPointer(display, None, DEVDEP(graph).window, 0, 0, 0, 0, x1, y1);

    while (state & Button3Mask) {
      if (x != x1 || y != y1) {
	XDrawRectangle(display, DEVDEP(graph).window, xorgc,
	    upperx, uppery, lowerx - upperx, lowery - uppery);
	x1 = x;
	y1 = y;
	/* figure out upper left corner */
	/* remember X11's (and X10's) demented coordinate system */
	if (y0 < y1) {
	  uppery = y0;
	  upperx = x0;
	  lowery = y1;
	  lowerx = x1;
	} else {
	  uppery = y1;
	  upperx = x1;
	  lowery = y0;
	  lowerx = x0;
	}
	XDrawRectangle(display, DEVDEP(graph).window, xorgc,
	    upperx, uppery, lowerx - upperx, lowery - uppery);
      }
      XQueryPointer(display, DEVDEP(graph).window, &rootwindow,
	       &childwindow, &rootx, &rooty, &x, &y, &state);
    }
    XDrawRectangle(display, DEVDEP(graph).window, xorgc,
	    upperx, uppery, lowerx - upperx, lowery - uppery);

    X_ScreentoData(graph, x0, y0, &fx0, &fy0);
    X_ScreentoData(graph, x1, y1, &fx1, &fy1);

    if (fx0 > fx1) {
      ftemp = fx0;
      fx0 = fx1;
      fx1 = ftemp;
    }
    if (fy0 > fy1) {
      ftemp = fy0;
      fy0 = fy1;
      fy1 = ftemp;
    }

    strncpy(buf2, graph->plotname, sizeof(buf2));
    if ((t =strchr(buf2, ':')))
	    *t = 0;

    if (!eq(plot_cur->pl_typename, buf2)) {
      (void) sprintf(buf,
"setplot %s; %s xlimit %.20e %.20e ylimit %.20e %.20e; setplot $curplot\n",
       buf2, graph->commandline, fx0, fx1, fy0, fy1);
    } else {
      (void) sprintf(buf, "%s xlimit %e %e ylimit %e %e\n",
	    graph->commandline, fx0, fx1, fy0, fy1);
    }

/* don't use the following if using GNU Readline or BSD EditLine */
#if !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE)
    {
	wordlist *wl;
	int dummy;
	
	/* hack for Gordon Jacobs */
	/* add to history list if plothistory is set */
	if (cp_getvar("plothistory", VT_BOOL, (char *) &dummy)) {
	  wl = cp_parse(buf);
	  (void) cp_addhistent(cp_event++, wl);
	}
    }
#endif /* !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE) */

    (void) cp_evloop(buf);

}
Example #4
0
File: index.c Project: t-k-/OPMES
int main(int argc, char* argv[])
{
	char   *frml = NULL, *url = NULL;
	struct list_it li_subpath;
	void          *db_formula;
	void          *db_webpage;
	void          *db_textree;
	BOOL           bad_parse = 0;
	int            subpath_err;
	uint64_t       records;
	CP_ID          id_new;
	CP_NBRW        n_brw;
	int            c;

	/* log file initialize */
	trace_init("index.log");

	/* open key-value database files */
	db_formula = db_init(CONFIG_FORMULA_DB_NAME, DB_OMOD_WR);
	db_webpage = db_init(CONFIG_WEBPAGE_DB_NAME, DB_OMOD_WR);
	db_textree = db_init(CONFIG_TEXTREE_DB_NAME, DB_OMOD_WR);

	/* set parser_root to NULL initially */
	/* or "go to exit" might free a random address. */
	parser_root = NULL;

	/* handle program arguments */
	while ((c = getopt(argc, argv, "hf:u:")) != -1) {
		switch (c) {
		case 'h':
			printf("DESCRIPTION:\n");
			printf("index raw collection.\n");
			printf("\n");
			printf("SYNOPSIS:\n");
			printf("%s -h | "
			       "-f <formula string> "
			       "-u <url> "
			       "\n",
			       argv[0]);
			goto exit;

		case 'f':
			frml = cp_strdup(optarg);
			break;
		
		case 'u':
			url = cp_strdup(optarg);
			break;

		default:
			goto exit;
		}
	}

	if (frml == NULL || url == NULL) {
		printf("bad argument.\n");
		goto exit;
	}

	printf("index... (`" C_RED "%s" C_RST "' @ %s)\n", frml, url);

	/* before parsing, it is necessary to substitute possible
	 * carriage return(s) with space. Because a Mathjax content
	 * $ a\<^M>b $ will be interpreted as $ a\ b $, we infer a 
	 * line-feed or carriage return should be replaced by a space.
	 */
	sub_cr_space(frml);

	/* parse formula string */
	if (!cp_parse(frml))
		goto exit;

	/* handle parser error */
	if (parser_err_flg) {
		parser_err_flg = 0;
		printf("parser: %s\n", parser_err_msg);

		bad_parse = 1;
		goto exit;
	}

	/* check parser root */
	if (NULL == parser_root) {
		trace(INDEX, "NULL parser root.\n", NULL);

		bad_parse = 1;
		goto exit;
	}

	/* assign new formula ID in order */
	records = (CP_ID)db_num_records(db_formula);

	if (0 != records % 3) 
		trace(INDEX, "bad records number: %u.\n", records);

	if (records / 3 + 1 >= MAX_CP_ID) {
		trace(INDEX, "NO available ID to assign.\n", NULL);
		goto exit;
	} else {
		id_new = records / 3 + 1;
		printf("assign ID = %u\n", id_new);
	}

	/* prepare posting file */
	n_brw = tex_tr_update(parser_root);
	if (n_brw == 0) {
		trace(INDEX, "tex_tr_update() fails.\n", NULL);
		goto exit;
	}

	li_subpath = tex_tr_subpaths(parser_root, &subpath_err);
	if (subpath_err) {
		trace(INDEX, "tex_tr_subpaths() fails.\n", NULL);

		subpaths_free(&li_subpath);
		goto exit;
	}

	/* write posting file */
	posting_write(&li_subpath, id_new);
	subpaths_free(&li_subpath);

	/* index formula */
	if (db_formula) {
		if (!index_formula(db_formula, id_new, frml, url, n_brw))
			goto exit;
	} else {
		trace(INDEX, "fail to open %s for writing.\n", 
		      CONFIG_FORMULA_DB_NAME);
		goto exit;
	}

	/* index URL */
	if (db_webpage) {
		index_webpage(db_webpage, url, id_new);
	}

	/* index tree shape */
	if (db_textree) {
		index_textree(db_textree, id_new);
	}

exit:
	/* releases textree */
	if (parser_root) {
		tex_tr_release(parser_root);
		parser_root = NULL;
	}

	/* free program argument string */
	if (frml)
		cp_free(frml);

	if (url)
		cp_free(url);

	/* database release */
	if (db_formula)
		db_release(db_formula);

	if (db_webpage)
		db_release(db_webpage);

	if (db_textree)
		db_release(db_textree);

	/* unfree trace */
	if (0 != trace_unfree()) {
		for (c = 0; c < argc; c ++) {
			trace(UNFREE, "%s \n", argv[c]);
		}
		
		trace(UNFREE, "\n", NULL);
	}

	/* log release */
	trace_uninit();

	return bad_parse;
}