Am Montag, den 27.06.2005, 15:56 -0400 schrieb Vladimir Dergachev:
> I have been going through R300 drm source trying to implement all the 
> suggestions that people offerred.
> 
> I am having some hard time with 80 column rule. Now, in general, I agree 
> with it and it makes sense. However take a look at the following piece of 
> code:
> 
> /******** snip ***** line 264 r300_cmdbuf.c ********/
>       for(i=0;i<sz;i++){
>               values[i]=((int __user*)cmdbuf->buf)[i];
>               switch(r300_reg_flags[(reg>>2)+i]){
>                       case MARK_SAFE:
>                               break;
>                       case MARK_CHECK_OFFSET:
>                               if(r300_check_offset(dev_priv, (u32)values[i])){
>                                       DRM_ERROR("Offset failed range check 
> (reg=%04x sz=%d)\n", reg, sz);
>                                       return DRM_ERR(EINVAL);
>                                       }
>                               break;
> /******** snip ************************************/
> 
> To me it looks perfectly fine - we have a for cycle, a switch statement 
> inside and an error check in one of switch statement clauses. I don't see 
> how separating these out into other functions is going to improve 
> readability.
> 
> Problem is that there is no sane way I can fit the error message in 80 
> columns without being cryptic.
> 
> Any ideas ?

Not indenting case labels saves you 8 columns. Also you can split
strings like this:

                                DRM_ERROR("Offset failed range check "
                                          "(reg=%04x sz=%d)\n", reg, sz);

Or refactor the code like this, saving another 8 columns for the error
message by avoiding one nesting level:

                switch(r300_reg_flags[(reg>>2)+i]){
                case MARK_SAFE:
                        break;
                case MARK_CHECK_OFFSET:
                        if(!r300_check_offset(dev_priv, (u32)values[i]))
                                break; /* Check passed. */
                        DRM_ERROR("Offset failed range check "
                                  "(reg=%04x sz=%d)\n", reg, sz);
                        return DRM_ERR(EINVAL);

Use your fantasy! ;-)

> 
>                         thank you !
> 
>                                Vladimir Dergachev
> 

Cheers,
  Felix

-- 
| Felix Kühling <[EMAIL PROTECTED]>                     http://fxk.de.vu |
| PGP Fingerprint: 6A3C 9566 5B30 DDED 73C3  B152 151C 5CC1 D888 E595 |




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
--
_______________________________________________
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel

Reply via email to