style cleanup: follow style guide for formatting of if/for/while loops, and else...
[blender.git] / source / blender / editors / space_text / text_python.c
index 88bd6b9c4c0c38f29dd8247014e7bf0f234b8560..f8472a132e18c877d2d53f7a02b4362c0e8ce022 100644 (file)
@@ -55,24 +55,24 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
        int tgti, *top;
        int mval[2] = {0, 0};
        
-       if(!st || !st->text) return 0;
-       if(!texttool_text_is_active(st->text)) return 0;
+       if (!st || !st->text) return 0;
+       if (!texttool_text_is_active(st->text)) return 0;
 
        first = texttool_suggest_first();
        last = texttool_suggest_last();
        /* sel = texttool_suggest_selected(); */ /* UNUSED */
        top = texttool_suggest_top();
 
-       if(!last || !first)
+       if (!last || !first)
                return 0;
 
        /* Count the visible lines to the cursor */
-       for(tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
-       if(l<0) return 0;
+       for (tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
+       if (l<0) return 0;
 
        text_update_character_width(st);
        
-       if(st->showlinenrs) {
+       if (st->showlinenrs) {
                x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
        }
        else {
@@ -85,19 +85,19 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
 
        // XXX getmouseco_areawin(mval);
 
-       if(mval[0]<x || x+w<mval[0] || mval[1]<y-h || y<mval[1])
+       if (mval[0]<x || x+w<mval[0] || mval[1]<y-h || y<mval[1])
                return 0;
 
        /* Work out which of the items is at the top of the visible list */
-       for(i=0, item=first; i<*top && item->next; i++, item=item->next);
+       for (i=0, item=first; i<*top && item->next; i++, item=item->next);
 
        /* Work out the target item index in the visible list */
        tgti = (y-mval[1]-4) / st->lheight;
-       if(tgti<0 || tgti>SUGG_LIST_SIZE)
+       if (tgti<0 || tgti>SUGG_LIST_SIZE)
                return 1;
 
-       for(i=tgti; i>0 && item->next; i--, item=item->next);
-       if(item)
+       for (i=tgti; i>0 && item->next; i--, item=item->next);
+       if (item)
                texttool_suggest_select(item);
        return 1;
 }
@@ -112,13 +112,13 @@ void text_pop_suggest_list(void)
        top= texttool_suggest_top();
 
        i= 0;
-       while(item && item != sel) {
+       while (item && item != sel) {
                item= item->next;
                i++;
        }
-       if(i > *top+SUGG_LIST_SIZE-1)
+       if (i > *top+SUGG_LIST_SIZE-1)
                *top= i-SUGG_LIST_SIZE+1;
-       else if(i < *top)
+       else if (i < *top)
                *top= i;
 }
 
@@ -127,16 +127,16 @@ static void get_suggest_prefix(Text *text, int offset)
        int i, len;
        char *line, tmp[256];
 
-       if(!text) return;
-       if(!texttool_text_is_active(text)) return;
+       if (!text) return;
+       if (!texttool_text_is_active(text)) return;
 
        line= text->curl->line;
-       for(i=text->curc-1+offset; i>=0; i--)
-               if(!text_check_identifier(line[i]))
+       for (i=text->curc-1+offset; i>=0; i--)
+               if (!text_check_identifier(line[i]))
                        break;
        i++;
        len= text->curc-i+offset;
-       if(len > 255) {
+       if (len > 255) {
                printf("Suggestion prefix too long\n");
                len = 255;
        }
@@ -151,29 +151,29 @@ static void confirm_suggestion(Text *text, int skipleft)
        int i, over=0;
        char *line;
 
-       if(!text) return;
-       if(!texttool_text_is_active(text)) return;
+       if (!text) return;
+       if (!texttool_text_is_active(text)) return;
 
        sel = texttool_suggest_selected();
-       if(!sel) return;
+       if (!sel) return;
 
        line= text->curl->line;
        i=text->curc-skipleft-1;
-       while(i>=0) {
-               if(!text_check_identifier(line[i]))
+       while (i>=0) {
+               if (!text_check_identifier(line[i]))
                        break;
                over++;
                i--;
        }
 
-       for(i=0; i<skipleft; i++)
+       for (i=0; i<skipleft; i++)
                txt_move_left(text, 0);
-       for(i=0; i<over; i++)
+       for (i=0; i<over; i++)
                txt_move_left(text, 1);
 
        txt_insert_buf(text, sel->name);
        
-       for(i=0; i<skipleft; i++)
+       for (i=0; i<skipleft; i++)
                txt_move_right(text, 0);
 
        texttool_text_clear();
@@ -196,78 +196,78 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
        ARegion *ar= NULL; // XXX
        int qual= 0; // XXX
        int draw=0, tools=0, swallow=0, scroll=1;
-       if(!texttool_text_is_active(st->text)) return 0;
-       if(!st->text || st->text->id.lib) return 0;
+       if (!texttool_text_is_active(st->text)) return 0;
+       if (!st->text || st->text->id.lib) return 0;
 
-       if(st->doplugins && texttool_text_is_active(st->text)) {
-               if(texttool_suggest_first()) tools |= TOOL_SUGG_LIST;
-               if(texttool_docs_get()) tools |= TOOL_DOCUMENT;
+       if (st->doplugins && texttool_text_is_active(st->text)) {
+               if (texttool_suggest_first()) tools |= TOOL_SUGG_LIST;
+               if (texttool_docs_get()) tools |= TOOL_DOCUMENT;
        }
 
-       if(ascii) {
-               if(tools & TOOL_SUGG_LIST) {
-                       if((ascii != '_' && ascii != '*' && ispunct(ascii)) || text_check_whitespace(ascii)) {
+       if (ascii) {
+               if (tools & TOOL_SUGG_LIST) {
+                       if ((ascii != '_' && ascii != '*' && ispunct(ascii)) || text_check_whitespace(ascii)) {
                                confirm_suggestion(st->text, 0);
                                text_update_line_edited(st->text->curl);
                        }
-                       else if((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
+                       else if ((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
                                get_suggest_prefix(st->text, 0);
                                text_pop_suggest_list();
                                swallow= 1;
                                draw= 1;
                        }
                }
-               if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
+               if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
 
        }
-       else if(val==1 && evnt) {
+       else if (val==1 && evnt) {
                switch (evnt) {
                        case LEFTMOUSE:
-                               if(text_do_suggest_select(st, ar))
+                               if (text_do_suggest_select(st, ar))
                                        swallow= 1;
                                else {
-                                       if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
-                                       if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
+                                       if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
+                                       if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
                                }
                                draw= 1;
                                break;
                        case MIDDLEMOUSE:
-                               if(text_do_suggest_select(st, ar)) {
+                               if (text_do_suggest_select(st, ar)) {
                                        confirm_suggestion(st->text, 0);
                                        text_update_line_edited(st->text->curl);
                                        swallow= 1;
                                }
                                else {
-                                       if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
-                                       if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
+                                       if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
+                                       if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
                                }
                                draw= 1;
                                break;
                        case ESCKEY:
                                draw= swallow= 1;
-                               if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
-                               else if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
+                               if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
+                               else if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
                                else draw= swallow= 0;
                                break;
                        case RETKEY:
-                               if(tools & TOOL_SUGG_LIST) {
+                               if (tools & TOOL_SUGG_LIST) {
                                        confirm_suggestion(st->text, 0);
                                        text_update_line_edited(st->text->curl);
                                        swallow= 1;
                                        draw= 1;
                                }
-                               if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
+                               if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
                                break;
                        case LEFTARROWKEY:
                        case BACKSPACEKEY:
-                               if(tools & TOOL_SUGG_LIST) {
-                                       if(qual)
+                               if (tools & TOOL_SUGG_LIST) {
+                                       if (qual)
                                                texttool_suggest_clear();
                                        else {
                                                /* Work out which char we are about to delete/pass */
-                                               if(st->text->curl && st->text->curc > 0) {
+                                               if (st->text->curl && st->text->curc > 0) {
                                                        char ch= st->text->curl->line[st->text->curc-1];
-                                                       if((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
+                                                       if ((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
                                                                get_suggest_prefix(st->text, -1);
                                                                text_pop_suggest_list();
                                                        }
@@ -278,17 +278,17 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
                                                        texttool_suggest_clear();
                                        }
                                }
-                               if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
+                               if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
                                break;
                        case RIGHTARROWKEY:
-                               if(tools & TOOL_SUGG_LIST) {
-                                       if(qual)
+                               if (tools & TOOL_SUGG_LIST) {
+                                       if (qual)
                                                texttool_suggest_clear();
                                        else {
                                                /* Work out which char we are about to pass */
-                                               if(st->text->curl && st->text->curc < st->text->curl->len) {
+                                               if (st->text->curl && st->text->curc < st->text->curl->len) {
                                                        char ch= st->text->curl->line[st->text->curc+1];
-                                                       if((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
+                                                       if ((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
                                                                get_suggest_prefix(st->text, 1);
                                                                text_pop_suggest_list();
                                                        }
@@ -299,24 +299,24 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
                                                        texttool_suggest_clear();
                                        }
                                }
-                               if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
+                               if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
                                break;
                        case PAGEDOWNKEY:
                                scroll= SUGG_LIST_SIZE-1;
                        case WHEELDOWNMOUSE:
                        case DOWNARROWKEY:
-                               if(tools & TOOL_DOCUMENT) {
+                               if (tools & TOOL_DOCUMENT) {
                                        doc_scroll++;
                                        swallow= 1;
                                        draw= 1;
                                        break;
                                }
-                               else if(tools & TOOL_SUGG_LIST) {
+                               else if (tools & TOOL_SUGG_LIST) {
                                        SuggItem *sel = texttool_suggest_selected();
-                                       if(!sel) {
+                                       if (!sel) {
                                                texttool_suggest_select(texttool_suggest_first());
                                        }
-                                       else while(sel && sel!=texttool_suggest_last() && sel->next && scroll--) {
+                                       else while (sel && sel!=texttool_suggest_last() && sel->next && scroll--) {
                                                texttool_suggest_select(sel->next);
                                                sel= sel->next;
                                        }
@@ -329,15 +329,15 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
                                scroll= SUGG_LIST_SIZE-1;
                        case WHEELUPMOUSE:
                        case UPARROWKEY:
-                               if(tools & TOOL_DOCUMENT) {
-                                       if(doc_scroll>0) doc_scroll--;
+                               if (tools & TOOL_DOCUMENT) {
+                                       if (doc_scroll>0) doc_scroll--;
                                        swallow= 1;
                                        draw= 1;
                                        break;
                                }
-                               else if(tools & TOOL_SUGG_LIST) {
+                               else if (tools & TOOL_SUGG_LIST) {
                                        SuggItem *sel = texttool_suggest_selected();
-                                       while(sel && sel!=texttool_suggest_first() && sel->prev && scroll--) {
+                                       while (sel && sel!=texttool_suggest_first() && sel->prev && scroll--) {
                                                texttool_suggest_select(sel->prev);
                                                sel= sel->prev;
                                        }
@@ -350,8 +350,8 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
                        case LEFTSHIFTKEY:
                                break;
                        default:
-                               if(tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw= 1;
-                               if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
+                               if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw= 1;
+                               if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
                }
        }
 
@@ -365,13 +365,13 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
 #if 0
 #ifdef WITH_PYTHON     
        /* Run text plugin scripts if enabled */
-       if(st->doplugins && event && val) {
-               if(BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
+       if (st->doplugins && event && val) {
+               if (BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
                        do_draw= 1;
                }
        }
 #endif
-       if(do_draw)
+       if (do_draw)
                ; // XXX redraw_alltext();
 #endif
 
@@ -383,26 +383,26 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
        int qual= 0; // XXX
 
        text= st->text;
-       if(!text || text->id.lib || text->curl != text->sell) return 0;
+       if (!text || text->id.lib || text->curl != text->sell) return 0;
 
        marker= txt_find_marker(text, text->sell, text->selc, 0, 0);
-       if(marker && (marker->start > text->curc || marker->end < text->curc))
+       if (marker && (marker->start > text->curc || marker->end < text->curc))
                marker= NULL;
 
-       if(!marker) {
+       if (!marker) {
                /* Find the next temporary marker */
-               if(evnt==TABKEY) {
+               if (evnt==TABKEY) {
                        int lineno= txt_get_span(text->lines.first, text->curl);
                        mrk= text->markers.first;
-                       while(mrk) {
-                               if(!marker && (mrk->flags & TMARK_TEMP)) marker= mrk;
-                               if((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno==lineno && mrk->end > text->curc))) {
+                       while (mrk) {
+                               if (!marker && (mrk->flags & TMARK_TEMP)) marker= mrk;
+                               if ((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno==lineno && mrk->end > text->curc))) {
                                        marker= mrk;
                                        break;
                                }
                                mrk= mrk->next;
                        }
-                       if(marker) {
+                       if (marker) {
                                txt_move_to(text, marker->lineno, marker->start, 0);
                                txt_move_to(text, marker->lineno, marker->end, 1);
                                // XXX text_update_cursor_moved(C);
@@ -412,60 +412,60 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
                                swallow= 1;
                        }
                }
-               else if(evnt==ESCKEY) {
-                       if(txt_clear_markers(text, 0, TMARK_TEMP)) swallow= 1;
-                       else if(txt_clear_markers(text, 0, 0)) swallow= 1;
+               else if (evnt==ESCKEY) {
+                       if (txt_clear_markers(text, 0, TMARK_TEMP)) swallow= 1;
+                       else if (txt_clear_markers(text, 0, 0)) swallow= 1;
                        else return 0;
                        evnt= ascii= val= 0;
                        draw= 1;
                }
-               if(!swallow) return 0;
+               if (!swallow) return 0;
        }
 
-       if(ascii) {
-               if(marker->flags & TMARK_EDITALL) {
+       if (ascii) {
+               if (marker->flags & TMARK_EDITALL) {
                        c= text->curc-marker->start;
                        s= text->selc-marker->start;
-                       if(s<0 || s>marker->end-marker->start) return 0;
+                       if (s<0 || s>marker->end-marker->start) return 0;
 
                        mrk= txt_next_marker(text, marker);
-                       while(mrk) {
+                       while (mrk) {
                                nxt=txt_next_marker(text, mrk); /* mrk may become invalid */
                                txt_move_to(text, mrk->lineno, mrk->start+c, 0);
-                               if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
-                               if(st->overwrite) {
-                                       if(txt_replace_char(text, ascii))
+                               if (s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
+                               if (st->overwrite) {
+                                       if (txt_replace_char(text, ascii))
                                                text_update_line_edited(st->text->curl);
                                }
                                else {
-                                       if(txt_add_char(text, ascii)) {
+                                       if (txt_add_char(text, ascii)) {
                                                text_update_line_edited(st->text->curl);
                                        }
                                }
 
-                               if(mrk==marker || mrk==nxt) break;
+                               if (mrk==marker || mrk==nxt) break;
                                mrk=nxt;
                        }
                        swallow= 1;
                        draw= 1;
                }
        }
-       else if(val) {
+       else if (val) {
                switch(evnt) {
                        case BACKSPACEKEY:
-                               if(marker->flags & TMARK_EDITALL) {
+                               if (marker->flags & TMARK_EDITALL) {
                                        c= text->curc-marker->start;
                                        s= text->selc-marker->start;
-                                       if(s<0 || s>marker->end-marker->start) return 0;
+                                       if (s<0 || s>marker->end-marker->start) return 0;
                                        
                                        mrk= txt_next_marker(text, marker);
-                                       while(mrk) {
+                                       while (mrk) {
                                                nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
                                                txt_move_to(text, mrk->lineno, mrk->start+c, 0);
-                                               if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
+                                               if (s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
                                                txt_backspace_char(text);
                                                text_update_line_edited(st->text->curl);
-                                               if(mrk==marker || mrk==nxt) break;
+                                               if (mrk==marker || mrk==nxt) break;
                                                mrk= nxt;
                                        }
                                        swallow= 1;
@@ -473,19 +473,19 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
                                }
                                break;
                        case DELKEY:
-                               if(marker->flags & TMARK_EDITALL) {
+                               if (marker->flags & TMARK_EDITALL) {
                                        c= text->curc-marker->start;
                                        s= text->selc-marker->start;
-                                       if(s<0 || s>marker->end-marker->start) return 0;
+                                       if (s<0 || s>marker->end-marker->start) return 0;
                                        
                                        mrk= txt_next_marker(text, marker);
-                                       while(mrk) {
+                                       while (mrk) {
                                                nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
                                                txt_move_to(text, mrk->lineno, mrk->start+c, 0);
-                                               if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
+                                               if (s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
                                                txt_delete_char(text);
                                                text_update_line_edited(st->text->curl);
-                                               if(mrk==marker || mrk==nxt) break;
+                                               if (mrk==marker || mrk==nxt) break;
                                                mrk= nxt;
                                        }
                                        swallow= 1;
@@ -493,20 +493,20 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
                                }
                                break;
                        case TABKEY:
-                               if(qual & LR_SHIFTKEY) {
+                               if (qual & LR_SHIFTKEY) {
                                        nxt= marker->prev;
-                                       if(!nxt) nxt= text->markers.last;
+                                       if (!nxt) nxt= text->markers.last;
                                }
                                else {
                                        nxt= marker->next;
-                                       if(!nxt) nxt= text->markers.first;
+                                       if (!nxt) nxt= text->markers.first;
                                }
-                               if(marker->flags & TMARK_TEMP) {
-                                       if(nxt==marker) nxt= NULL;
+                               if (marker->flags & TMARK_TEMP) {
+                                       if (nxt==marker) nxt= NULL;
                                        BLI_freelinkN(&text->markers, marker);
                                }
                                mrk= nxt;
-                               if(mrk) {
+                               if (mrk) {
                                        txt_move_to(text, mrk->lineno, mrk->start, 0);
                                        txt_move_to(text, mrk->lineno, mrk->end, 1);
                                        // XXX text_update_cursor_moved(C);
@@ -521,7 +521,7 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
                        case ZKEY: if(evnt==ZKEY && !(qual & LR_CTRLKEY)) break;
                        case RETKEY:
                        case ESCKEY:
-                               if(marker->flags & (TMARK_EDITALL | TMARK_TEMP))
+                               if (marker->flags & (TMARK_EDITALL | TMARK_TEMP))
                                        txt_clear_markers(text, marker->group, 0);
                                else
                                        BLI_freelinkN(&text->markers, marker);
@@ -532,11 +532,11 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
                        case LEFTMOUSE:
                                break;
                        case FKEY: /* Allow find */
-                               if(qual & LR_SHIFTKEY) swallow= 1;
+                               if (qual & LR_SHIFTKEY) swallow= 1;
                                break;
 
                        default:
-                               if(qual!=0 && qual!=LR_SHIFTKEY)
+                               if (qual!=0 && qual!=LR_SHIFTKEY)
                                        swallow= 1; /* Swallow all other shortcut events */
                }
        }