From a32cc95fa87e50efbd2ea152ea44766614894a49 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 30 Mar 2012 10:00:20 +0000 Subject: style cleanup --- source/blender/editors/util/editmode_undo.c | 172 ++++++++++++++-------------- 1 file changed, 86 insertions(+), 86 deletions(-) (limited to 'source/blender/editors/util/editmode_undo.c') diff --git a/source/blender/editors/util/editmode_undo.c b/source/blender/editors/util/editmode_undo.c index 4416228e2d3..8849a9af9c0 100644 --- a/source/blender/editors/util/editmode_undo.c +++ b/source/blender/editors/util/editmode_undo.c @@ -62,11 +62,11 @@ * Add this in your local code: * * void undo_editmode_push(bContext *C, const char *name, - * void * (*getdata)(bContext *C), // use context to retrieve current editdata - * void (*freedata)(void *), // pointer to function freeing data - * void (*to_editmode)(void *, void *), // data to editmode conversion - * void * (*from_editmode)(void *)) // editmode to data conversion - * int (*validate_undo)(void *, void *)) // check if undo data is still valid + * void * (*getdata)(bContext *C), // use context to retrieve current editdata + * void (*freedata)(void *), // pointer to function freeing data + * void (*to_editmode)(void *, void *), // data to editmode conversion + * void * (*from_editmode)(void *)) // editmode to data conversion + * int (*validate_undo)(void *, void *)) // check if undo data is still valid * * * Further exported for UI is: @@ -83,24 +83,24 @@ static void error(const char *UNUSED(arg)) {} /* ****** XXX ***** */ -#define MAXUNDONAME 64 +#define MAXUNDONAME 64 typedef struct UndoElem { struct UndoElem *next, *prev; - ID id; // copy of editmode object ID - Object *ob; // pointer to edited object - int type; // type of edited object + ID id; // copy of editmode object ID + Object *ob; // pointer to edited object + int type; // type of edited object void *undodata; uintptr_t undosize; char name[MAXUNDONAME]; - void * (*getdata)(bContext *C); + void * (*getdata)(bContext * C); void (*freedata)(void *); void (*to_editmode)(void *, void *, void *); void * (*from_editmode)(void *, void *); int (*validate_undo)(void *, void *); } UndoElem; -static ListBase undobase={NULL, NULL}; -static UndoElem *curundo= NULL; +static ListBase undobase = {NULL, NULL}; +static UndoElem *curundo = NULL; /* ********************* xtern api calls ************* */ @@ -114,14 +114,14 @@ static void undo_restore(UndoElem *undo, void *editdata, void *obdata) /* name can be a dynamic string */ void undo_editmode_push(bContext *C, const char *name, - void * (*getdata)(bContext *C), - void (*freedata)(void *), - void (*to_editmode)(void *, void *, void *), - void *(*from_editmode)(void *, void *), - int (*validate_undo)(void *, void *)) + void * (*getdata)(bContext * C), + void (*freedata)(void *), + void (*to_editmode)(void *, void *, void *), + void *(*from_editmode)(void *, void *), + int (*validate_undo)(void *, void *)) { UndoElem *uel; - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); void *editdata; int nr; uintptr_t memused, totmem, maxmem; @@ -131,65 +131,65 @@ void undo_editmode_push(bContext *C, const char *name, /* remove all undos after (also when curundo==NULL) */ while (undobase.last != curundo) { - uel= undobase.last; + uel = undobase.last; uel->freedata(uel->undodata); BLI_freelinkN(&undobase, uel); } /* make new */ - curundo= uel= MEM_callocN(sizeof(UndoElem), "undo editmode"); + curundo = uel = MEM_callocN(sizeof(UndoElem), "undo editmode"); BLI_strncpy(uel->name, name, sizeof(uel->name)); BLI_addtail(&undobase, uel); - uel->getdata= getdata; - uel->freedata= freedata; - uel->to_editmode= to_editmode; - uel->from_editmode= from_editmode; - uel->validate_undo= validate_undo; + uel->getdata = getdata; + uel->freedata = freedata; + uel->to_editmode = to_editmode; + uel->from_editmode = from_editmode; + uel->validate_undo = validate_undo; /* limit amount to the maximum amount*/ - nr= 0; - uel= undobase.last; + nr = 0; + uel = undobase.last; while (uel) { nr++; - if (nr==U.undosteps) break; - uel= uel->prev; + if (nr == U.undosteps) break; + uel = uel->prev; } if (uel) { - while (undobase.first!=uel) { - UndoElem *first= undobase.first; + while (undobase.first != uel) { + UndoElem *first = undobase.first; first->freedata(first->undodata); BLI_freelinkN(&undobase, first); } } /* copy */ - memused= MEM_get_memory_in_use(); - editdata= getdata(C); - curundo->undodata= curundo->from_editmode(editdata, obedit->data); - curundo->undosize= MEM_get_memory_in_use() - memused; - curundo->ob= obedit; - curundo->id= obedit->id; - curundo->type= obedit->type; + memused = MEM_get_memory_in_use(); + editdata = getdata(C); + curundo->undodata = curundo->from_editmode(editdata, obedit->data); + curundo->undosize = MEM_get_memory_in_use() - memused; + curundo->ob = obedit; + curundo->id = obedit->id; + curundo->type = obedit->type; if (U.undomemory != 0) { /* limit to maximum memory (afterwards, we can't know in advance) */ - totmem= 0; - maxmem= ((uintptr_t)U.undomemory)*1024*1024; + totmem = 0; + maxmem = ((uintptr_t)U.undomemory) * 1024 * 1024; - uel= undobase.last; + uel = undobase.last; while (uel && uel->prev) { - totmem+= uel->undosize; - if (totmem>maxmem) break; - uel= uel->prev; + totmem += uel->undosize; + if (totmem > maxmem) break; + uel = uel->prev; } if (uel) { if (uel->prev && uel->prev->prev) - uel= uel->prev; + uel = uel->prev; - while (undobase.first!=uel) { - UndoElem *first= undobase.first; + while (undobase.first != uel) { + UndoElem *first = undobase.first; first->freedata(first->undodata); BLI_freelinkN(&undobase, first); } @@ -201,69 +201,69 @@ void undo_editmode_push(bContext *C, const char *name, static void undo_clean_stack(bContext *C) { UndoElem *uel, *next; - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); /* global undo changes pointers, so we also allow identical names */ /* side effect: when deleting/renaming object and start editing new one with same name */ - uel= undobase.first; + uel = undobase.first; while (uel) { - void *editdata= uel->getdata(C); - int isvalid= 0; - next= uel->next; + void *editdata = uel->getdata(C); + int isvalid = 0; + next = uel->next; /* for when objects are converted, renamed, or global undo changes pointers... */ - if (uel->type==obedit->type) { - if (strcmp(uel->id.name, obedit->id.name)==0) { - if (uel->validate_undo==NULL) - isvalid= 1; + if (uel->type == obedit->type) { + if (strcmp(uel->id.name, obedit->id.name) == 0) { + if (uel->validate_undo == NULL) + isvalid = 1; else if (uel->validate_undo(uel->undodata, editdata)) - isvalid= 1; + isvalid = 1; } } if (isvalid) - uel->ob= obedit; + uel->ob = obedit; else { if (uel == curundo) - curundo= NULL; + curundo = NULL; uel->freedata(uel->undodata); BLI_freelinkN(&undobase, uel); } - uel= next; + uel = next; } - if (curundo == NULL) curundo= undobase.last; + if (curundo == NULL) curundo = undobase.last; } /* 1= an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation */ void undo_editmode_step(bContext *C, int step) { - Object *obedit= CTX_data_edit_object(C); + Object *obedit = CTX_data_edit_object(C); /* prevent undo to happen on wrong object, stack can be a mix */ undo_clean_stack(C); - if (step==0) { + if (step == 0) { undo_restore(curundo, curundo->getdata(C), obedit->data); } - else if (step==1) { + else if (step == 1) { - if (curundo==NULL || curundo->prev==NULL) error("No more steps to undo"); + if (curundo == NULL || curundo->prev == NULL) error("No more steps to undo"); else { if (G.f & G_DEBUG) printf("undo %s\n", curundo->name); - curundo= curundo->prev; + curundo = curundo->prev; undo_restore(curundo, curundo->getdata(C), obedit->data); } } else { /* curundo has to remain current situation! */ - if (curundo==NULL || curundo->next==NULL) error("No more steps to redo"); + if (curundo == NULL || curundo->next == NULL) error("No more steps to redo"); else { undo_restore(curundo->next, curundo->getdata(C), obedit->data); - curundo= curundo->next; + curundo = curundo->next; if (G.f & G_DEBUG) printf("redo %s\n", curundo->name); } } @@ -282,25 +282,25 @@ void undo_editmode_clear(void) { UndoElem *uel; - uel= undobase.first; + uel = undobase.first; while (uel) { uel->freedata(uel->undodata); - uel= uel->next; + uel = uel->next; } BLI_freelistN(&undobase); - curundo= NULL; + curundo = NULL; } /* based on index nr it does a restore */ void undo_editmode_number(bContext *C, int nr) { UndoElem *uel; - int a=1; + int a = 1; - for (uel= undobase.first; uel; uel= uel->next, a++) { - if (a==nr) break; + for (uel = undobase.first; uel; uel = uel->next, a++) { + if (a == nr) break; } - curundo= uel; + curundo = uel; undo_editmode_step(C, 0); } @@ -308,12 +308,12 @@ void undo_editmode_name(bContext *C, const char *undoname) { UndoElem *uel; - for (uel= undobase.last; uel; uel= uel->prev) { - if (strcmp(undoname, uel->name)==0) + for (uel = undobase.last; uel; uel = uel->prev) { + if (strcmp(undoname, uel->name) == 0) break; } if (uel && uel->prev) { - curundo= uel->prev; + curundo = uel->prev; undo_editmode_step(C, 0); } } @@ -324,8 +324,8 @@ int undo_editmode_valid(const char *undoname) if (undoname) { UndoElem *uel; - for (uel= undobase.last; uel; uel= uel->prev) { - if (strcmp(undoname, uel->name)==0) + for (uel = undobase.last; uel; uel = uel->prev) { + if (strcmp(undoname, uel->name) == 0) break; } return uel != NULL; @@ -343,12 +343,12 @@ const char *undo_editmode_get_name(bContext *C, int nr, int *active) /* prevent wrong numbers to be returned */ undo_clean_stack(C); - if (active) *active= 0; + if (active) *active = 0; - uel= BLI_findlink(&undobase, nr); + uel = BLI_findlink(&undobase, nr); if (uel) { - if (active && uel==curundo) - *active= 1; + if (active && uel == curundo) + *active = 1; return uel->name; } return NULL; @@ -357,7 +357,7 @@ const char *undo_editmode_get_name(bContext *C, int nr, int *active) void *undo_editmode_get_prev(Object *ob) { - UndoElem *ue= undobase.last; - if (ue && ue->prev && ue->prev->ob==ob) return ue->prev->undodata; + UndoElem *ue = undobase.last; + if (ue && ue->prev && ue->prev->ob == ob) return ue->prev->undodata; return NULL; } -- cgit v1.2.3