⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hre_api.c

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 C
📖 第 1 页 / 共 2 页
字号:
	return (NULL);    }    /*Get shared library pathname. *//* *    if( (ri->ri_name = shared_library_name(directory,locale,name)) == NULL ) { *	delete_rec_info(ri); *	return(NULL); *    } */    /*Initialize the subset information. */    if (subset != NULL) {	/*Count the subset strings. */	for (len = 1; subset[len] != NULL; len++);	/*Copy the subset strings. */	ri->ri_subset = (char **) safe_malloc((len + 1) * sizeof(char *));	for (i = 0; i < len; i++) {	    if (subset[i] != NULL) {		if ((ri->ri_subset[i] = strdup(subset[i])) == NULL) {		    delete_rec_info(ri);		    return (NULL);		}	    } else {		ri->ri_subset[i] = subset[i];	    }	}	ri->ri_subset[i] = NULL;    } else {	ri->ri_subset = NULL;    }    return (ri);}static voiddelete_rec_info(rec_info * ri){    if (ri != NULL) {	if (ri->ri_locale != NULL) {	    free(ri->ri_locale);	}/* *	if( ri->ri_name != NULL ) { *	    free(ri->ri_name); *	} */	if (ri->ri_subset != NULL) {	    int i;	    for (i = 0; ri->ri_subset[i] != NULL; i++) {		free(ri->ri_subset[i]);	    }	    free(ri->ri_subset);	}	free(ri);    }}/*check_for_user_home-Check whether USERRECHOME has been created.*/#if 0static intcheck_for_user_home(){    char *homedir = getenv(HOME);    char *rechome = NULL;    if (homedir == NULL) {	the_last_error = "Home environment variable HOME not set.";	return (-1);    }    rechome = (char *) safe_malloc(strlen(homedir) + strlen(USERRECHOME) + 2);    /*Form name. */    strcpy(rechome, homedir);    strcat(rechome, "/");    strcat(rechome, USERRECHOME);    /*Create directory. */    if (mkdir(rechome, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {	/*If errno is EEXIST, then OK. */	if (errno != EEXIST) {	    the_last_error = "Error during creation of USERRECHOME.";	    free(rechome);	    return (-1);	}    }    free(rechome);    return (0);}#endif/* * Constructor functions for making structures. * *    The general philosophy here is that we control all memory *    in connected data structures, *except* for pen_point arrays. *    There are likely to be lots and lots of points, they are likely *    to come from the window system; so if we wanted to control them, *    we would have to copy which would be slow. We require the client *    to deal with them directly, or the client can give us permission *    to delete them.*//* * recognizer*/recognizermake_recognizer(rec_info * rif){    recognizer rec;    /*Allocate it. */    rec = (recognizer) safe_malloc(sizeof(*rec));    rec->recognizer_magic = REC_MAGIC;    rec->recognizer_version = REC_VERSION;    rec->recognizer_info = rif;    rec->recognizer_specific = NULL;    rec->recognizer_end_magic = REC_END_MAGIC;    rec->recognizer_load_state = NULL;    rec->recognizer_save_state = NULL;    rec->recognizer_load_dictionary = NULL;    rec->recognizer_save_dictionary = NULL;    rec->recognizer_free_dictionary = NULL;    rec->recognizer_add_to_dictionary = NULL;    rec->recognizer_delete_from_dictionary = NULL;    rec->recognizer_error = NULL;    rec->recognizer_set_context = NULL;    rec->recognizer_get_context = NULL;    rec->recognizer_clear = NULL;    rec->recognizer_get_buffer = NULL;    rec->recognizer_set_buffer = NULL;    rec->recognizer_translate = NULL;    rec->recognizer_get_extension_functions = NULL;    rec->recognizer_get_gesture_names = NULL;    rec->recognizer_set_gesture_action = NULL;    return (rec);}voiddelete_recognizer(recognizer rec){    if (rec != NULL) {	if (rec->recognizer_info != NULL) {	    delete_rec_info(rec->recognizer_info);	}	free(rec);    }}/* * rec_alternative*/rec_alternative *make_rec_alternative_array(u_int size){    int i;    rec_alternative *ri;    ri = (rec_alternative *) safe_malloc(size * sizeof(rec_alternative));    for (i = 0; i < size; i++) {	ri[i].ra_elem.re_type = REC_NONE;	ri[i].ra_elem.re_result.aval = NULL;	ri[i].ra_elem.re_conf = 0;	ri[i].ra_nalter = 0;	ri[i].ra_next = NULL;    }    return (ri);}rec_alternative *initialize_rec_alternative(rec_alternative * ra, u_int nelem){    if (ra != NULL) {	if ((ra->ra_next = make_rec_alternative_array(nelem)) == NULL) {	    return (NULL);	}	ra->ra_nalter = nelem;    }    return (ra);}voiddelete_rec_alternative_array(u_int nalter,			     rec_alternative * ra, bool delete_points_p){    int i;    if (ra != NULL) {	for (i = 0; i < nalter; i++) {	    cleanup_rec_element(&ra[i].ra_elem, delete_points_p);	    /*Now do the next one down the line. */	    if (ra[i].ra_nalter > 0) {		delete_rec_alternative_array(ra[i].ra_nalter,					     ra[i].ra_next, delete_points_p);	    }	}	free(ra);    }}/*initialize_rec_element-Initialize a recognition element.*/rec_element *initialize_rec_element(rec_element * re,		       char type,		       u_int size, void *trans, rec_confidence conf){    if (re != NULL) {	re->re_type = type;	re->re_conf = conf;	re->re_result.aval = NULL;	switch (type) {	case REC_GESTURE:	    if (size > 0 && trans != NULL) {		re->re_result.gval = (gesture *) safe_malloc(sizeof(gesture));		memcpy((void *) re->re_result.gval, trans, sizeof(gesture));	    }	    break;	case REC_ASCII:	case REC_VAR:	case REC_OTHER:	    if (size > 0 && trans != NULL) {		re->re_result.aval =		    (char *) safe_malloc((size + 1) * sizeof(char));		memcpy((void *) re->re_result.aval, trans,		       size * sizeof(char));		re->re_result.aval[size] = '\000';	    }	    break;	case REC_WCHAR:	    if (size > 0 && trans != NULL) {		re->re_result.wval =		    (unsigned int *) safe_malloc((size + 1) *						 sizeof(unsigned int));		memcpy((void *) re->re_result.wval, trans,		       size * sizeof(unsigned int));		re->re_result.wval[size] = '\000';	    }	    break;	case REC_CORR:	    if (size > 0 && trans != NULL) {		re->re_result.rcval =		    (rec_correlation *) safe_malloc(sizeof(rec_correlation));		memcpy((void *) re->re_result.rcval,		       trans, sizeof(rec_correlation));	    }	    break;	default:	    return (NULL);	}    }    return (re);}static voidcleanup_rec_element(rec_element * re, bool delete_points_p){    switch (re->re_type) {    case REC_NONE:	break;    case REC_ASCII:    case REC_VAR:    case REC_WCHAR:    case REC_OTHER:	free(re->re_result.aval);	break;    case REC_GESTURE:	delete_gesture_array(1, re->re_result.gval, true);	break;    case REC_CORR:	delete_rec_correlation(re->re_result.rcval, delete_points_p);	break;    }}/* * rec_correlation*/rec_correlation *make_rec_correlation(char type,		     u_int size,		     void *trans, rec_confidence conf, u_int ps_size){    rec_correlation *rc;    rc = (rec_correlation *) safe_malloc(sizeof(rec_correlation));    rc->ro_nstrokes = ps_size;    /*First initialize element. */    if (initialize_rec_element(&(rc->ro_elem),			       type, size, trans, conf) == NULL) {	return (NULL);    }    if ((rc->ro_strokes = make_pen_stroke_array(ps_size)) == NULL) {	return (NULL);    }    rc->ro_start = (u_int *) safe_malloc(ps_size * sizeof(int));    rc->ro_stop = (u_int *) safe_malloc(ps_size * sizeof(int));    return (rc);}voiddelete_rec_correlation(rec_correlation * rc, bool delete_points_p){    if (rc != NULL) {	cleanup_rec_element(&rc->ro_elem, delete_points_p);	delete_pen_stroke_array(rc->ro_nstrokes, rc->ro_strokes,				delete_points_p);	if (rc->ro_start != NULL) {	    free(rc->ro_start);	}	if (rc->ro_stop != NULL) {	    free(rc->ro_stop);	}	free(rc);    }}/* * rec_fn*/rec_fn *make_rec_fn_array(u_int size){    rec_fn *ri = (rec_fn *) safe_malloc((size + 1) * sizeof(rec_fn));    int i;    for (i = 0; i < size; i++) {	ri[i] = NULL;    }    ri[i] = NULL;    return (ri);}voiddelete_rec_fn_array(rec_fn * rf){    if (rf != NULL) {	free(rf);    }}/* * pen_stroke*/pen_stroke *make_pen_stroke_array(u_int size){    int i;    pen_stroke *ri;    ri = (pen_stroke *) safe_malloc(size * sizeof(pen_stroke));    for (i = 0; i < size; i++) {	ri[i].ps_npts = 0;	ri[i].ps_pts = NULL;	ri[i].ps_nstate = 0;	ri[i].ps_state = NULL;    }    return (ri);}pen_stroke *initialize_pen_stroke(pen_stroke * ps,		      u_int npts,		      pen_point * pts,		      u_int nstate, u_int * trans, pen_state * state){    if (ps != NULL) {	ps->ps_npts = npts;	ps->ps_pts = pts;	ps->ps_nstate = nstate;	ps->ps_trans = trans;	ps->ps_state = state;    }    return (ps);}voiddelete_pen_stroke_array(u_int size, pen_stroke * ps, bool delete_points_p){    int i;    if (ps != NULL) {	for (i = 0; i < size; i++) {	    if (ps[i].ps_state != NULL) {		free(ps[i].ps_state);	    }	    if (ps[i].ps_trans != NULL) {		free(ps[i].ps_trans);	    }	    if (delete_points_p) {		delete_pen_point_array(ps[i].ps_pts);	    }	}	free(ps);    }}/* * pen_point*/pen_point *make_pen_point_array(u_int size){    pen_point *pp = (pen_point *) safe_malloc(size * sizeof(pen_point));    int i;    for (i = 0; i < size; i++) {	pp[i].time = 0;	pp[i].x = pp[i].y = 0;    }    return (pp);}voiddelete_pen_point_array(pen_point * pp){    if (pp != NULL) {	free(pp);    }}/* * pen_state*/pen_state *make_pen_state_array(u_int size){    int i;    pen_state *ps = (pen_state *) safe_malloc(size * sizeof(pen_state));    for (i = 0; i < size; i++) {	ps[i].pt_button = 0;	ps[i].pt_pen = 0;	ps[i].pt_pressure = 0;	ps[i].pt_anglex = 0.0;	ps[i].pt_angley = 0.0;	ps[i].pt_barrelrotate = 0.0;    }    return (ps);}pen_state *initialize_pen_state(pen_state * ps,		     u_short button,		     u_short pen,		     short pressure,		     double anglex, double angley, double barrelrotate){    if (ps != NULL) {	ps->pt_button = button;	ps->pt_pen = pen;	ps->pt_pressure = pressure;	ps->pt_anglex = anglex;	ps->pt_angley = angley;	ps->pt_barrelrotate = barrelrotate;    }    return (ps);}voiddelete_pen_state_array(pen_state * ps){    if (ps != NULL) {	free(ps);    }}/* * gesture */gesture *make_gesture_array(u_int size){    return ((gesture *) safe_malloc(size * sizeof(gesture)));}gesture *initialize_gesture(gesture * g,		   char *name,		   u_int nhs,		   pen_point * hspots,		   pen_rect bbox, xgesture fn, void *wsinfo){    if (g != NULL) {	/*We don't do points, 'cause they come from the window system. */	g->g_nhs = nhs;	g->g_hspots = hspots;	g->g_name = strdup(name);	g->g_bbox.x = bbox.x;	g->g_bbox.y = bbox.y;	g->g_bbox.width = bbox.width;	g->g_bbox.height = bbox.height;	g->g_action = fn;	g->g_wsinfo = wsinfo;    }    return (g);}voiddelete_gesture_array(u_int size, gesture * ga, bool delete_points_p){    int i;    if (ga != NULL) {	for (i = 0; i < size; i++) {	    free(ga[i].g_name);	    if (delete_points_p) {		delete_pen_point_array(ga[i].g_hspots);	    }	}	free(ga);    }}/* * copy fns for stroke buffer management.*/static pen_stroke *copy_pen_stroke(pen_stroke * ps1, pen_stroke * ps2){    u_int *trans = NULL;    pen_state *state = NULL;    if ((trans =	 copy_state_trans_array(ps2->ps_nstate, ps2->ps_trans)) == NULL) {	return (NULL);    }    if ((state = copy_pen_state_array(ps2->ps_nstate, ps2->ps_state)) == NULL) {	free(trans);	return (NULL);    }    initialize_pen_stroke(ps1,			  ps2->ps_npts,			  ps2->ps_pts, ps2->ps_nstate, trans, state);    return (ps1);}pen_stroke *copy_pen_stroke_array(u_int nstrokes, pen_stroke * strokes){    int i;    pen_stroke *ps = make_pen_stroke_array(nstrokes);    if (ps != NULL) {	for (i = 0; i < nstrokes; i++) {	    copy_pen_stroke(&ps[i], &strokes[i]);	}    }    return (ps);}pen_state *copy_pen_state_array(u_int nstate, pen_state * state){    pen_state *ps = make_pen_state_array(nstate);    int i;    if (ps != NULL) {	for (i = 0; i < nstate; i++) {	    initialize_pen_state(&ps[i],				 state[i].pt_button,				 state[i].pt_pen,				 state[i].pt_pressure,				 state[i].pt_anglex,				 state[i].pt_angley,				 state[i].pt_barrelrotate);	}    }    return (ps);}u_int *copy_state_trans_array(u_int ntrans, u_int * trans){    u_int *pt = (u_int *) safe_malloc(ntrans * sizeof(u_int));    int i;    for (i = 0; i < ntrans; i++) {	pt[i] = trans[i];    }    return (pt);}pen_stroke *concatenate_pen_strokes(int nstrokes1,			pen_stroke * strokes1,			int nstrokes2,			pen_stroke * strokes2,			int *nstrokes3, pen_stroke ** strokes3){    int i;    int ns;    pen_stroke *ps;    /*Measure new strokes */    ns = nstrokes1 + nstrokes2;    /*Allocate memory */    if ((ps = make_pen_stroke_array(ns)) == NULL) {	return (NULL);    }    /*Copy old ones into new. */    for (i = 0; i < nstrokes1; i++) {	if (copy_pen_stroke(&ps[i], &strokes1[i]) == NULL) {	    delete_pen_stroke_array(ns, ps, false);	    return (NULL);	}    }    for (; i < ns; i++) {	if (copy_pen_stroke(&ps[i], &strokes2[i - nstrokes1]) == NULL) {	    delete_pen_stroke_array(ns, ps, false);	    return (NULL);	}    }    *nstrokes3 = ns;    *strokes3 = ps;    return (ps);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -