Enlightenment CVS committal Author : dj2 Project : e17 Module : libs/engrave
Dir : e17/libs/engrave/src/lib Modified Files: engrave.l engrave.y engrave_image.c engrave_image.h engrave_parse.c engrave_part.c engrave_part.h engrave_part_state.c engrave_part_state.h Log Message: - add the inherit flag into engrave. - this will duplicate the description. once its done it forgets about the fact that it was inherited. So if you print it out again it will show two distinct description sections. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave.l,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- engrave.l 24 Oct 2004 06:28:37 -0000 1.3 +++ engrave.l 24 Oct 2004 23:03:48 -0000 1.4 @@ -120,6 +120,7 @@ image { KEYWORD_RETURN(IMAGE); } images { KEYWORD_RETURN(IMAGES); } in { KEYWORD_RETURN(IN); } +inherit { KEYWORD_RETURN(INHERIT); } item { KEYWORD_RETURN(ITEM); } IMAGE { KEYWORD_RETURN(IMAGE); } LINEAR { KEYWORD_RETURN(LINEAR); } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave.y,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- engrave.y 24 Oct 2004 20:46:29 -0000 1.6 +++ engrave.y 24 Oct 2004 23:03:48 -0000 1.7 @@ -47,7 +47,7 @@ %left MINUS PLUS %left TIMES DIVIDE %left NEG /* negation--unary minus */ -%token OPEN_PAREN CLOSE_PAREN DOT +%token OPEN_PAREN CLOSE_PAREN DOT INHERIT %type <string> STRING %type <val> FLOAT @@ -448,6 +448,7 @@ desc_preamble_entry: state | visible + | inherit | align | min | max @@ -466,6 +467,12 @@ } ; +inherit: INHERIT COLON STRING exp SEMICOLON { + engrave_parse_state_inherit($3, $4); + } + ; + + align: ALIGN COLON exp exp SEMICOLON { switch(section) { =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_image.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- engrave_image.c 24 Oct 2004 07:06:37 -0000 1.3 +++ engrave_image.c 24 Oct 2004 23:03:48 -0000 1.4 @@ -23,3 +23,18 @@ return image; } +/** + * engrave_image_dup - duplicate an Engrave_Image + * @param from: The Engrave_Image to duplicate + * + * @return Returns a pointer to the newly allocated Engrave_Image on success + * or NULL on failure + */ +Engrave_Image * +engrave_image_dup(Engrave_Image *from) +{ + Engrave_Image *to; + to = engrave_image_new(from->name, from->type, from->value); + return to; +} + =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_image.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- engrave_image.h 24 Oct 2004 07:06:37 -0000 1.2 +++ engrave_image.h 24 Oct 2004 23:03:48 -0000 1.3 @@ -28,8 +28,9 @@ double value; /**< Compression value for image */ }; -Engrave_Image * engrave_image_new(char *name, +Engrave_Image *engrave_image_new(char *name, Engrave_Image_Type type, double value); +Engrave_Image *engrave_image_dup(Engrave_Image *from); /** * @} =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_parse.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- engrave_parse.c 24 Oct 2004 20:46:30 -0000 1.5 +++ engrave_parse.c 24 Oct 2004 23:03:48 -0000 1.6 @@ -247,6 +247,47 @@ } void +engrave_parse_state_inherit(char *name, double val) +{ + Engrave_Group *group; + Engrave_Part *part; + Engrave_Part_State *to; + Engrave_Part_State *from; + char *state_name; + + group = engrave_file_group_last_get(engrave_file); + part = engrave_group_part_last_get(group); + + to = engrave_part_state_last_get(part); + state_name = engrave_part_state_name_get(to, NULL); + + /* must have a name set before we can be inherited into */ + if (!state_name) { + char *part_name = engrave_part_name_get(part); + fprintf(stderr, "part %s: inherit may only be used after state!\n", + part_name); + free(part_name); + return; + } + + /* can't inherit into the default part */ + if ((strlen(state_name) == 7) && (!strncmp(state_name, "default", 7))) { + char *part_name = engrave_part_name_get(part); + fprintf(stderr, "part %s: " + "inherit may not be used in the default description!\n", + part_name); + free(part_name); + return; + } + + from = engrave_part_state_by_name_value_find(part, name, val); + if (from) + engrave_part_state_copy(from, to); + else + fprintf(stderr, "Unable to locate description %s %f\n", name, val); +} + +void engrave_parse_state_align(double x, double y) { Engrave_Group *group; =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_part.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- engrave_part.c 24 Oct 2004 07:06:37 -0000 1.4 +++ engrave_part.c 24 Oct 2004 23:03:49 -0000 1.5 @@ -62,6 +62,20 @@ } /** + * engrave_part_name_get - Get the name of the part + * @param ep: The Engrave_Part to retrieve the name from. + * + * @return Returns a copy of the part name, this pointer must be freed by + * the application, or NULL if no name found. + */ +char * +engrave_part_name_get(Engrave_Part *ep) +{ + if (!ep || !ep->name) return NULL; + return strdup(ep->name); +} + +/** * engrave_part_type_set - set the type of the part * @param ep: The Engrave_Part to set the type on. * @param type: The Engrave_Part_Type to set on the part @@ -183,3 +197,39 @@ ep->states = evas_list_append(ep->states, eps); } +/** + * engrave_part_state_by_name_value_find - Find the Engrave_Part State that * matches the given name and value in this part + * @param ep: The Engrave_Part to search. + * @param name: The name to search for + * @param val: The value to search for. + * + * @return Returns a pointer to the Engrave_Part_State matching the given + * criteria or NULL if not found. + */ +Engrave_Part_State * +engrave_part_state_by_name_value_find(Engrave_Part *ep, + char *name, double val) +{ + Evas_List *l; + if (!ep || !name) return NULL; + + for (l = ep->states; l; l = l->next) { + char *state_name; + double state_val; + Engrave_Part_State *eps; + + eps = (Engrave_Part_State *)l->data; + state_name = engrave_part_state_name_get(eps, &state_val); + + if ((!strcmp(state_name, name)) && (strlen(name) == strlen(state_name)) + && (state_val == val)) { + free(state_name); + return eps; + } + free(state_name); + } + + return NULL; +} + + =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_part.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- engrave_part.h 24 Oct 2004 07:06:37 -0000 1.3 +++ engrave_part.h 24 Oct 2004 23:03:49 -0000 1.4 @@ -54,6 +54,7 @@ Engrave_Part * engrave_part_new(Engrave_Part_Type type); void engrave_part_name_set(Engrave_Part *ep, char *name); +char *engrave_part_name_get(Engrave_Part *ep); void engrave_part_mouse_events_set(Engrave_Part *ep, int val); void engrave_part_repeat_events_set(Engrave_Part *ep, int val); void engrave_part_type_set(Engrave_Part *ep, Engrave_Part_Type type); @@ -66,6 +67,8 @@ void engrave_part_dragable_y_set(Engrave_Part *ep, int y, int step, int count); void engrave_part_dragable_confine_set(Engrave_Part *ep, char *confine); void engrave_part_state_add(Engrave_Part *ep, Engrave_Part_State *eps); +Engrave_Part_State * engrave_part_state_by_name_value_find(Engrave_Part *ep, + char *name, double val); /** * @} =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_part_state.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- engrave_part_state.c 24 Oct 2004 20:46:30 -0000 1.4 +++ engrave_part_state.c 24 Oct 2004 23:03:49 -0000 1.5 @@ -76,6 +76,23 @@ } /** + * engrave_part_state_name_get- Get the name of the state + * @param eps: The Engrave_Part_State to retrieve the name from + * @param value: If not NULL will return the value param. + * + * @return Returns a copy of the name of the state this pointer must be + * freed by the application, or NULL if no name found. + */ +char * +engrave_part_state_name_get(Engrave_Part_State *eps, double *value) +{ + if (!eps || !eps->name) return NULL; + + if (value) *value = eps->value; + return strdup(eps->name); +} + +/** * engrave_part_state_visible_set - Set the visiblity of the state * @param eps: The Engrave_Part_State to set the value too. * @param visible: The visibility value to set to the state @@ -656,4 +673,73 @@ eps->text.align.y = y; } +/** + * engrave_part_state_copy - Copy the values from @a from to @ato + * @param from: The Engrave_Part_State from which to retrieve the values + * @param to: The Engrave_Part_State to place the values into + * + * @return Returns no value. + */ +void +engrave_part_state_copy(Engrave_Part_State *from, Engrave_Part_State *to) +{ + Evas_List *l; + char *to_name; + double to_val; + + if (!from || !to) return; + + /* back these up */ + to_name = to->name; + to_val = to->value; + + /* free all of the possible strings */ + IF_FREE(to->rel1.to_x); + IF_FREE(to->rel1.to_y); + IF_FREE(to->rel2.to_x); + IF_FREE(to->rel2.to_y); + IF_FREE(to->color_class); + IF_FREE(to->text.text); + IF_FREE(to->text.text_class); + IF_FREE(to->text.font); + + /* just dup the memory and restore the 2 unchanging entries */ + to = memcpy(to, from, sizeof(Engrave_Part_State)); + to->name = to_name; + to->value = to_val; + + /* re-dup these so we don't screw with the originals */ + if (to->rel1.to_x) to->rel1.to_x = strdup(to->rel1.to_x); + if (to->rel1.to_y) to->rel1.to_y = strdup(to->rel1.to_y); + if (to->rel2.to_x) to->rel2.to_x = strdup(to->rel2.to_x); + if (to->rel2.to_y) to->rel2.to_y = strdup(to->rel2.to_y); + if (to->color_class) to->color_class = strdup(to->color_class); + if (to->text.text) to->text.text = strdup(to->text.text); + if (to->text.text_class) to->text.text_class = strdup(to->text.text_class); + if (to->text.font) to->text.font = strdup(to->text.font); + + /* fix up the image normal pointer */ + if (to->image.normal) { + Engrave_Image *ei; + + ei = engrave_image_dup(to->image.normal); + if (ei) + to->image.normal = ei; + else + fprintf(stderr, "Insufficient memory to dup image\n"); + } + + /* copy the tween list correctly */ + to->image.tween = NULL; + for (l = from->image.tween; l; l = l->next) { + Engrave_Image *ei; + + ei = engrave_image_dup((Engrave_Image *)l->data); + if (ei) + to->image.tween = evas_list_append(to->image.tween, ei); + else + fprintf(stderr, "Insufficient memory to dup image\n"); + } +} + =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/engrave/src/lib/engrave_part_state.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- engrave_part_state.h 24 Oct 2004 20:46:30 -0000 1.3 +++ engrave_part_state.h 24 Oct 2004 23:03:49 -0000 1.4 @@ -172,6 +172,8 @@ Engrave_Part_State * engrave_part_state_new(void); void engrave_part_state_name_set(Engrave_Part_State *eps, char *name, double value); +char *engrave_part_state_name_get(Engrave_Part_State *eps, double *value); + void engrave_part_state_visible_set(Engrave_Part_State *eps, int visible); void engrave_part_state_align_set(Engrave_Part_State *eps, int x, int y); void engrave_part_state_step_set(Engrave_Part_State *eps, int x, int y); @@ -229,6 +231,12 @@ void engrave_part_state_text_min_set(Engrave_Part_State *eps, int x, int y); void engrave_part_state_text_align_set(Engrave_Part_State *eps, double x, double y); +void engrave_part_state_copy(Engrave_Part_State *from, + Engrave_Part_State *to); + +/** + * @} + */ #endif ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ enlightenment-cvs mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs