Changeset 822

Show
Ignore:
Timestamp:
06/27/07 17:20:02 (17 months ago)
Author:
volker
Message:

indentation with ./indent.sh; short circuit evaluation modified

Location:
branches/volker_dev
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/volker_dev/drv_X11.c

    r819 r822  
    140140    int i; 
    141141    float dim; 
    142      
     142 
    143143    /* -1 is used to query the current brightness */ 
    144144    if (brightness == -1) 
    145145  return Brightness; 
    146      
     146 
    147147    if (brightness < 0) 
    148148  brightness = 0; 
    149149    if (brightness > 255) 
    150150  brightness = 255; 
    151      
     151 
    152152    if (Brightness != brightness) { 
    153         Brightness = brightness; 
    154         dim = Brightness / 255.0; 
    155         col.R *= dim; 
    156         col.G *= dim; 
    157         col.B *= dim; 
    158          
    159         debug("%s: set backlight to %d%%, original backlight color: 0x%02x%02x%02x%02x, dimmed: 0x%02x%02x%02x%02x", 
    160               Name, (int)(dim * 100), BL_COL.R, BL_COL.G, BL_COL.B, BL_COL.A, col.R, col.G, col.B, col.A); 
    161         for (i = 0; i < DCOLS * DROWS; i++) { 
    162             drv_X11_FB[i] = col; 
    163         } 
    164          
    165         drv_X11_color(col); 
    166          
    167         XFillRectangle(dp, pm, gc, 0, 0, dimx + 2 * border + btnwidth, dimy + 2 * border); 
    168         XSetWindowBackground(dp, w, xc.pixel); 
    169         XClearWindow(dp, w); 
    170          
    171         /* redraw every LCD pixel */ 
    172         drv_X11_blit(0, 0, LROWS, LCOLS); 
     153  Brightness = brightness; 
     154  dim = Brightness / 255.0; 
     155  col.R *= dim; 
     156  col.G *= dim; 
     157  col.B *= dim; 
     158 
     159  debug("%s: set backlight to %d%%, original backlight color: 0x%02x%02x%02x%02x, dimmed: 0x%02x%02x%02x%02x", 
     160        Name, (int) (dim * 100), BL_COL.R, BL_COL.G, BL_COL.B, BL_COL.A, col.R, col.G, col.B, col.A); 
     161  for (i = 0; i < DCOLS * DROWS; i++) { 
     162      drv_X11_FB[i] = col; 
     163  } 
     164 
     165  drv_X11_color(col); 
     166 
     167  XFillRectangle(dp, pm, gc, 0, 0, dimx + 2 * border + btnwidth, dimy + 2 * border); 
     168  XSetWindowBackground(dp, w, xc.pixel); 
     169  XClearWindow(dp, w); 
     170 
     171  /* redraw every LCD pixel */ 
     172  drv_X11_blit(0, 0, LROWS, LCOLS); 
    173173    } 
    174174 
     
    180180{ 
    181181    int val = WIDGET_KEY_PRESSED; 
    182      
     182 
    183183    switch (num) { 
    184         case 1: 
    185             val += WIDGET_KEY_UP; 
    186             break; 
    187         case 2: 
    188             val += WIDGET_KEY_DOWN; 
    189             break; 
    190         case 3: 
    191             val += WIDGET_KEY_LEFT; 
    192             break; 
    193         case 4: 
    194             val += WIDGET_KEY_RIGHT; 
    195             break; 
    196         case 5: 
    197             val += WIDGET_KEY_CONFIRM; 
    198             break; 
    199         case 6: 
    200             val += WIDGET_KEY_CANCEL; 
    201             break; 
    202         default: 
    203             error("%s: unknown keypad value %d", Name, num); 
    204     } 
    205      
     184    case 1: 
     185  val += WIDGET_KEY_UP; 
     186  break; 
     187    case 2: 
     188  val += WIDGET_KEY_DOWN; 
     189  break; 
     190    case 3: 
     191  val += WIDGET_KEY_LEFT; 
     192  break; 
     193    case 4: 
     194  val += WIDGET_KEY_RIGHT; 
     195  break; 
     196    case 5: 
     197  val += WIDGET_KEY_CONFIRM; 
     198  break; 
     199    case 6: 
     200  val += WIDGET_KEY_CANCEL; 
     201  break; 
     202    default: 
     203  error("%s: unknown keypad value %d", Name, num); 
     204    } 
     205 
    206206    debug("%s: key %c (0x%x) pressed", Name, num, num); 
    207207    return val; 
     
    228228    char *s; 
    229229    char unknownTxt[10]; 
    230      
     230 
    231231    x0 = x - pixel; 
    232232    x1 = x + pixel + width; 
     
    246246  } 
    247247    } 
    248      
     248 
    249249    /* Keypad on the right side */ 
    250250    if (x1 >= xoffset) { 
    251         xfs = XQueryFont(dp, XGContextFromGC(DefaultGC(dp, 0))); 
    252         if (drv_X11_brightness(-1) > 127) { 
    253             drv_X11_color(FG_COL); 
    254         } else { 
    255             drv_X11_color(BG_COL); 
    256         } 
    257         for (r = 0; r < buttons; r++) { 
    258             yk = yoffset + r * (btnheight + pgap); 
    259             switch(r) { 
    260                 case 0: 
    261                     s = "Up"; 
    262                     break; 
    263                 case 1: 
    264                     s = "Down"; 
    265                     break; 
    266                 case 2: 
    267                     s = "Left"; 
    268                     break; 
    269                 case 3: 
    270                     s = "Right"; 
    271                     break; 
    272                 case 4: 
    273                     s = "Confirm"; 
    274                     break; 
    275                 case 5: 
    276                     s = "Cancel"; 
    277                     break; 
    278                 default: 
    279                     snprintf(unknownTxt, sizeof(unknownTxt), "#%d??", r); 
    280                     s = unknownTxt; 
    281             } 
    282             XDrawRectangle(dp, w, gc, xoffset, yk, btnwidth, btnheight - 2); 
    283             XDrawString(dp, w, gc, 
    284                         xoffset + btnwidth / 2 - (xfs->max_bounds.width * strlen(s)) / 2, yk + btnheight / 2 + xfs->max_bounds.ascent / 2, 
    285                         s, strlen(s));       
    286         } 
    287     } 
    288         //XSync(dp, False); 
     251  xfs = XQueryFont(dp, XGContextFromGC(DefaultGC(dp, 0))); 
     252  if (drv_X11_brightness(-1) > 127) { 
     253      drv_X11_color(FG_COL); 
     254  } else { 
     255      drv_X11_color(BG_COL); 
     256  } 
     257  for (r = 0; r < buttons; r++) { 
     258      yk = yoffset + r * (btnheight + pgap); 
     259      switch (r) { 
     260      case 0: 
     261    s = "Up"; 
     262    break; 
     263      case 1: 
     264    s = "Down"; 
     265    break; 
     266      case 2: 
     267    s = "Left"; 
     268    break; 
     269      case 3: 
     270    s = "Right"; 
     271    break; 
     272      case 4: 
     273    s = "Confirm"; 
     274    break; 
     275      case 5: 
     276    s = "Cancel"; 
     277    break; 
     278      default: 
     279    snprintf(unknownTxt, sizeof(unknownTxt), "#%d??", r); 
     280    s = unknownTxt; 
     281      } 
     282      XDrawRectangle(dp, w, gc, xoffset, yk, btnwidth, btnheight - 2); 
     283      XDrawString(dp, w, gc, 
     284      xoffset + btnwidth / 2 - (xfs->max_bounds.width * strlen(s)) / 2, 
     285      yk + btnheight / 2 + xfs->max_bounds.ascent / 2, s, strlen(s)); 
     286  } 
     287    } 
     288    //XSync(dp, False); 
    289289} 
    290290 
     
    297297    int yoffset = border + (DROWS / YRES) * rgap; 
    298298    static int btn = 0; 
    299   
     299 
    300300    if (XCheckWindowEvent(dp, w, ExposureMask | ButtonPressMask | ButtonReleaseMask, &ev) == 0) 
    301301  return; 
    302     switch(ev.type) { 
    303         case Expose: 
    304             drv_X11_expose(ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height); 
    305             break; 
    306         case ButtonPress: 
    307             if ( ev.xbutton.x >= xoffset && ev.xbutton.x <= xoffset + btnwidth 
    308                  && ev.xbutton.y >= yoffset && ev.xbutton.y <= yoffset + buttons * btnheight + (buttons -1 ) *pgap ) { 
    309                 btn = (ev.xbutton.y - yoffset) / (btnheight + pgap) + 1;    /* btn 0 is unused */ 
    310                 drv_X11_color(BG_COL); 
    311                 XFillRectangle(dp, w, gc, xoffset + 1, yoffset + (btn - 1) * (btnheight + pgap) + 1, btnwidth - 1, btnheight - 2 - 1); 
    312                 drv_generic_keypad_press(btn); 
    313             } 
    314             break; 
    315         case ButtonRelease: 
    316             if ( ev.xbutton.x >= xoffset && ev.xbutton.x <= xoffset + btnwidth 
    317      && ev.xbutton.y >= yoffset && ev.xbutton.y <= yoffset + buttons * btnheight + (buttons -1 ) *pgap ) { 
    318                 XClearArea(dp, w, xoffset, yoffset + (btn - 1) * (btnheight + pgap), btnwidth, btnheight - 2, 1 /* true */); 
    319                 btn = (ev.xbutton.y - yoffset) / (btnheight + pgap) + 1;    /* btn 0 is unused */ 
    320                 info("%s: Button %d released", Name, btn); 
    321             } 
    322             break; 
    323         default: 
    324             debug("%s: unknown XEvent %d", Name, ev.type); 
     302    switch (ev.type) { 
     303    case Expose: 
     304  drv_X11_expose(ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height); 
     305  break; 
     306    case ButtonPress: 
     307  if (ev.xbutton.x >= xoffset && ev.xbutton.x <= xoffset + btnwidth 
     308      && ev.xbutton.y >= yoffset && ev.xbutton.y <= yoffset + buttons * btnheight + (buttons - 1) * pgap) { 
     309      btn = (ev.xbutton.y - yoffset) / (btnheight + pgap) + 1;  /* btn 0 is unused */ 
     310      drv_X11_color(BG_COL); 
     311      XFillRectangle(dp, w, gc, xoffset + 1, yoffset + (btn - 1) * (btnheight + pgap) + 1, btnwidth - 1, 
     312         btnheight - 2 - 1); 
     313      drv_generic_keypad_press(btn); 
     314  } 
     315  break; 
     316    case ButtonRelease: 
     317  if (ev.xbutton.x >= xoffset && ev.xbutton.x <= xoffset + btnwidth 
     318      && ev.xbutton.y >= yoffset && ev.xbutton.y <= yoffset + buttons * btnheight + (buttons - 1) * pgap) { 
     319      XClearArea(dp, w, xoffset, yoffset + (btn - 1) * (btnheight + pgap), btnwidth, btnheight - 2, 
     320           1 /* true */ ); 
     321      btn = (ev.xbutton.y - yoffset) / (btnheight + pgap) + 1;  /* btn 0 is unused */ 
     322      info("%s: Button %d released", Name, btn); 
     323  } 
     324  break; 
     325    default: 
     326  debug("%s: unknown XEvent %d", Name, ev.type); 
    325327    } 
    326328} 
     
    378380    } 
    379381    free(s); 
    380      
     382 
    381383    /* virtual keyboard: number of buttons (0..6) */ 
    382384    if (cfg_number(section, "buttons", 0, 0, 6, &buttons) < 0) 
    383       return -1; 
     385  return -1; 
    384386 
    385387    drv_X11_FB = malloc(DCOLS * DROWS * sizeof(*drv_X11_FB)); 
     
    462464{ 
    463465    double brightness; 
    464      
     466 
    465467    switch (argc) { 
    466         case 0: 
    467             brightness = drv_X11_brightness(-1); 
    468             SetResult(&result, R_NUMBER, &brightness); 
    469             break; 
    470         case 1: 
    471             brightness = drv_X11_brightness(R2N(argv[0])); 
    472             SetResult(&result, R_NUMBER, &brightness); 
    473             break; 
    474         default: 
    475             error("%s.brightness(): wrong number of parameters", Name); 
    476             SetResult(&result, R_STRING, ""); 
     468    case 0: 
     469  brightness = drv_X11_brightness(-1); 
     470  SetResult(&result, R_NUMBER, &brightness); 
     471  break; 
     472    case 1: 
     473  brightness = drv_X11_brightness(R2N(argv[0])); 
     474  SetResult(&result, R_NUMBER, &brightness); 
     475  break; 
     476    default: 
     477  error("%s.brightness(): wrong number of parameters", Name); 
     478  SetResult(&result, R_STRING, ""); 
    477479    } 
    478480} 
     
    514516    if ((ret = drv_generic_keypad_init(section, Name)) != 0) 
    515517  return ret; 
    516      
     518 
    517519    drv_generic_graphic_clear(); 
    518520 
  • branches/volker_dev/drv_generic_graphic.c

    r815 r822  
    189189    /* Layer 0 is topmost: Find lowest opaque layer */ 
    190190    for (l = 0; l < LAYERS; l++) { 
    191         if (drv_generic_graphic_FB[l][row * LCOLS + col].A >= 255) { 
    192             /* Layers below are fully covered */ 
    193             opaqueBottomLayer = l; 
    194             break; 
    195         } 
     191  if (drv_generic_graphic_FB[l][row * LCOLS + col].A >= 255) { 
     192      /* Layers below are fully covered */ 
     193      opaqueBottomLayer = l; 
     194      break; 
     195  } 
    196196    } 
    197197    for (l = opaqueBottomLayer; l >= 0; l--) { 
  • branches/volker_dev/evaluator.c

    r820 r822  
    989989  argc = Root->Children; 
    990990  if (argc > 10) { 
    991             error("evaluator: more than 10 children (operands) not supported!"); 
     991      error("evaluator: more than 10 children (operands) not supported!"); 
    992992      argc = 10; 
    993         } 
     993  } 
    994994  for (i = 0; i < argc; i++) { 
    995             EvalTree(Root->Child[i]); 
     995      EvalTree(Root->Child[i]); 
    996996      param[i] = Root->Child[i]->Result; 
    997997  } 
     
    10111011  case O_LST:   /* expression list: result is last expression */ 
    10121012      i = Root->Children - 1; 
    1013             EvalTree(Root->Child[i]); 
     1013      EvalTree(Root->Child[i]); 
    10141014      type = Root->Child[i]->Result->type; 
    10151015      number = Root->Child[i]->Result->number; 
     
    10181018 
    10191019  case O_SET:   /* variable assignment */ 
    1020             EvalTree(Root->Child[0]); 
     1020      EvalTree(Root->Child[0]); 
    10211021      CopyResult(&Root->Variable->value, Root->Child[0]->Result); 
    10221022      type = Root->Child[0]->Result->type; 
     
    10261026 
    10271027  case O_CND:   /* conditional expression */ 
    1028             EvalTree(Root->Child[0]); 
     1028      EvalTree(Root->Child[0]); 
    10291029      i = 1 + (R2N(Root->Child[0]->Result) == 0.0); 
    1030             EvalTree(Root->Child[i]); 
     1030      EvalTree(Root->Child[i]); 
    10311031      type = Root->Child[i]->Result->type; 
    10321032      number = Root->Child[i]->Result->number; 
     
    10361036  case O_OR:    /* logical OR */ 
    10371037      type = R_NUMBER; 
    1038             EvalTree(Root->Child[0]); 
    1039             if (R2N(Root->Child[0]->Result) == 0.0) { 
    1040                 /* calculate 2nd operator only, if 1st operator is false */ 
    1041                 EvalTree(Root->Child[1]); 
    1042             } 
    1043       number = ((R2N(Root->Child[0]->Result) != 0.0) || (R2N(Root->Child[1]->Result) != 0.0)); 
     1038      EvalTree(Child[0]); 
     1039      if (R2N(Root->Child[0]->Result) == 0.0) { 
     1040    EvalTree(Child[1]) 
     1041        number = (Child[1]->Result != 0.0); 
     1042      } else { 
     1043    number = 1.0; 
     1044      } 
    10441045      break; 
    10451046 
    10461047  case O_AND:   /* logical AND */ 
    10471048      type = R_NUMBER; 
    1048             EvalTree(Root->Child[0]); 
    1049             if (R2N(Root->Child[0]->Result) != 0.0) { 
    1050                 /* calculate 2nd operator only, if 1st operator is true */ 
    1051                 EvalTree(Root->Child[1]); 
    1052             } 
    1053       number = ((R2N(Root->Child[0]->Result) != 0.0) && (R2N(Root->Child[1]->Result) != 0.0)); 
     1049      EvalTree(Root->Child[0]); 
     1050      if (R2N(Root->Child[0]->Result) != 0.0) { 
     1051    EvalTree(Child[1]) 
     1052        number = (Child[1]->Result != 0.0); 
     1053      } else { 
     1054    number = 0.0; 
     1055      } 
    10541056      break; 
    10551057 
    10561058  case O_EQ:    /* numeric equal */ 
    10571059      type = R_NUMBER; 
    1058             EvalTree(Root->Child[0]); 
    1059             EvalTree(Root->Child[1]); 
     1060      EvalTree(Root->Child[0]); 
     1061      EvalTree(Root->Child[1]); 
    10601062      number = (R2N(Root->Child[0]->Result) == R2N(Root->Child[1]->Result)); 
    10611063      break; 
     
    10631065  case O_NE:    /* numeric not equal */ 
    10641066      type = R_NUMBER; 
    1065             EvalTree(Root->Child[0]); 
    1066             EvalTree(Root->Child[1]); 
     1067      EvalTree(Root->Child[0]); 
     1068      EvalTree(Root->Child[1]); 
    10671069      number = (R2N(Root->Child[0]->Result) != R2N(Root->Child[1]->Result)); 
    10681070      break; 
     
    10701072  case O_LT:    /* numeric less than */ 
    10711073      type = R_NUMBER; 
    1072             EvalTree(Root->Child[0]); 
    1073             EvalTree(Root->Child[1]); 
     1074      EvalTree(Root->Child[0]); 
     1075      EvalTree(Root->Child[1]); 
    10741076      number = (R2N(Root->Child[0]->Result) < R2N(Root->Child[1]->Result)); 
    10751077      break; 
     
    10771079  case O_LE:    /* numeric less equal */ 
    10781080      type = R_NUMBER; 
    1079             EvalTree(Root->Child[0]); 
    1080             EvalTree(Root->Child[1]); 
     1081      EvalTree(Root->Child[0]); 
     1082      EvalTree(Root->Child[1]); 
    10811083      number = (R2N(Root->Child[0]->Result) <= R2N(Root->Child[1]->Result)); 
    10821084      break; 
     
    10841086  case O_GT:    /* numeric greater than */ 
    10851087      type = R_NUMBER; 
    1086             EvalTree(Root->Child[0]); 
    1087             EvalTree(Root->Child[1]); 
     1088      EvalTree(Root->Child[0]); 
     1089      EvalTree(Root->Child[1]); 
    10881090      number = (R2N(Root->Child[0]->Result) > R2N(Root->Child[1]->Result)); 
    10891091      break; 
     
    10911093  case O_GE:    /* numeric greater equal */ 
    10921094      type = R_NUMBER; 
    1093             EvalTree(Root->Child[0]); 
    1094             EvalTree(Root->Child[1]); 
     1095      EvalTree(Root->Child[0]); 
     1096      EvalTree(Root->Child[1]); 
    10951097      number = (R2N(Root->Child[0]->Result) >= R2N(Root->Child[1]->Result)); 
    10961098      break; 
     
    10981100  case O_ADD:   /* addition */ 
    10991101      type = R_NUMBER; 
    1100             EvalTree(Root->Child[0]); 
    1101             EvalTree(Root->Child[1]); 
     1102      EvalTree(Root->Child[0]); 
     1103      EvalTree(Root->Child[1]); 
    11021104      number = R2N(Root->Child[0]->Result) + R2N(Root->Child[1]->Result); 
    11031105      break; 
     
    11051107  case O_SUB:   /* subtraction */ 
    11061108      type = R_NUMBER; 
    1107             EvalTree(Root->Child[0]); 
    1108             EvalTree(Root->Child[1]); 
     1109      EvalTree(Root->Child[0]); 
     1110      EvalTree(Root->Child[1]); 
    11091111      number = R2N(Root->Child[0]->Result) - R2N(Root->Child[1]->Result); 
    11101112      break; 
     
    11121114  case O_SGN:   /* sign */ 
    11131115      type = R_NUMBER; 
    1114             EvalTree(Root->Child[0]); 
     1116      EvalTree(Root->Child[0]); 
    11151117      number = -R2N(Root->Child[0]->Result); 
    11161118      break; 
     
    11181120  case O_CAT:   /* string concatenation */ 
    11191121      type = R_STRING; 
    1120             EvalTree(Root->Child[0]); 
    1121             EvalTree(Root->Child[1]); 
     1122      EvalTree(Root->Child[0]); 
     1123      EvalTree(Root->Child[1]); 
    11221124      s1 = R2S(Root->Child[0]->Result); 
    11231125      s2 = R2S(Root->Child[1]->Result); 
     
    11301132  case O_MUL:   /* multiplication */ 
    11311133      type = R_NUMBER; 
    1132             EvalTree(Root->Child[0]); 
    1133             EvalTree(Root->Child[1]); 
     1134      EvalTree(Root->Child[0]); 
     1135      EvalTree(Root->Child[1]); 
    11341136      number = R2N(Root->Child[0]->Result) * R2N(Root->Child[1]->Result); 
    11351137      break; 
     
    11371139  case O_DIV:   /* division */ 
    11381140      type = R_NUMBER; 
    1139             EvalTree(Root->Child[0]); 
    1140             EvalTree(Root->Child[1]); 
     1141      EvalTree(Root->Child[0]); 
     1142      EvalTree(Root->Child[1]); 
    11411143      dummy = R2N(Root->Child[1]->Result); 
    11421144      if (dummy == 0) { 
     
    11501152  case O_MOD:   /* modulo */ 
    11511153      type = R_NUMBER; 
    1152             EvalTree(Root->Child[0]); 
    1153             EvalTree(Root->Child[1]); 
     1154      EvalTree(Root->Child[0]); 
     1155      EvalTree(Root->Child[1]); 
    11541156      dummy = R2N(Root->Child[1]->Result); 
    11551157      if (dummy == 0) { 
     
    11631165  case O_POW:   /* x^y */ 
    11641166      type = R_NUMBER; 
    1165             EvalTree(Root->Child[0]); 
    1166             EvalTree(Root->Child[1]); 
     1167      EvalTree(Root->Child[0]); 
     1168      EvalTree(Root->Child[1]); 
    11671169      number = pow(R2N(Root->Child[0]->Result), R2N(Root->Child[1]->Result)); 
    11681170      break; 
     
    11701172  case O_NOT:   /* logical NOT */ 
    11711173      type = R_NUMBER; 
    1172             EvalTree(Root->Child[0]); 
     1174      EvalTree(Root->Child[0]); 
    11731175      number = (R2N(Root->Child[0]->Result) == 0.0); 
    11741176      break; 
  • branches/volker_dev/lcd4linux.c

    r818 r822  
    245245      printf("%s\n", copyright); 
    246246      drv_list(); 
    247             printf("\n"); 
    248             plugin_list(); 
     247      printf("\n"); 
     248      plugin_list(); 
    249249      exit(0); 
    250250  case 'o':