home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 01e / miscfunc.zip / DB2ATTR.PRG < prev    next >
Text File  |  1988-04-12  |  4KB  |  100 lines

  1. **  DB2ATTR.PRG - translates dBase string expressions for color to DOS
  2. **                display attribute's numeric expression
  3. PARAMETERS colorvar,decattr
  4. PRIVATE dbbg,dbfg
  5. **                    
  6. **  Copyright Steve Titterud 1988
  7. **  2157 Glenridge Ave.
  8. **  St. Paul, MN 55119                  
  9. **  (612)-739-7229                  
  10. **                    
  11. **  Sister routine is ATTR2DB.PRG.  Easily converted to a QS function.                  
  12. **                    
  13. **  Usage:  do db2attr with <color variable>,"<numeric variable name>"                  
  14. **                    
  15. **  These routines were written to solve a problem I have encountered.  I have                  
  16. **  occasion to use add-on assembler routines, either in .bin form for LOAD                  
  17. **  and CALL, or in .obj form for CCALLing.  When these routines have a display                  
  18. **  function, they often ask for a display attribute as a decimal number.  And                  
  19. **  further, what they are displaying needs be integrated, in terms of color,                  
  20. **  intensity, and so on, with the rest of the display, which is set with dBase                  
  21. **  color commands as strings.  The same is true in reverse - dBase color 
  22. **  commands need to correspond to color commands set by one of these routines                  
  23. **  with a decimal number attribute.  Therefore I created routines to both                  
  24. **  find a dBase color expression corresponding to a decimal attribute, and                  
  25. **  to find a decimal attribute corresponding to a dBase color expression.                  
  26. **  This allows these values to be set at run-time based upon the color
  27. **  context, as expressed in a different form (number or string).
  28. **                    
  29. **  This ought to be written in assembler or C, but I'm not able at present.                  
  30. **                    
  31. **  Decattr is the QUOTED NAME of the variable which will hold the                   
  32. **  decimal value of the attribute byte recognized by DOS, corresponding
  33. **  to colorvar, a dBase expression for color (includes "/" separator).
  34. **  This variable name is then macro-expanded for the assignment.                  
  35. **                    
  36. **  A valid expression for colorvar is assumed, in form FG/BG.                  
  37. **                    
  38. **  Initialize &decattr to 0
  39. **                    
  40. &decattr=0
  41. **                    
  42. **  Parse dBase color expression for FG and BG subexpressions:
  43. **                    
  44. dbfg = upper(ltrim(rtrim(left(colorvar,at("/",colorvar)-1))))
  45. dbbg = upper(ltrim(rtrim(right(colorvar,len(colorvar)-at("/",colorvar)))))
  46. **
  47. **  Add in value of foreground component:
  48. **
  49. do case
  50.    case dbfg="W"
  51.       &decattr=&decattr+7
  52.    case dbfg="GR"
  53.       &decattr=&decattr+6
  54.    case dbfg="RB"
  55.       &decattr=&decattr+5
  56.    case dbfg="R"
  57.       &decattr=&decattr+4
  58.    case dbfg="BG"
  59.       &decattr=&decattr+3
  60.    case dbfg="G"
  61.       &decattr=&decattr+2
  62.    case dbfg="B"
  63.       &decattr=&decattr+1
  64.    case dbfg="N"
  65.       &decattr=&decattr+0
  66. endcase   
  67. **
  68. **  Add in value of background component:
  69. **
  70. do case
  71.    case dbbg="W"
  72.       &decattr=&decattr+112
  73.    case dbbg="GR"
  74.       &decattr=&decattr+96
  75.    case dbbg="RB"
  76.       &decattr=&decattr+80
  77.    case dbbg="R"
  78.       &decattr=&decattr+64
  79.    case dbbg="BG"
  80.       &decattr=&decattr+48
  81.    case dbbg="G"
  82.       &decattr=&decattr+32
  83.    case dbbg="B"
  84.       &decattr=&decattr+16
  85.    case dbbg="N"
  86.       &decattr=&decattr+0
  87. endcase   
  88. **
  89. **  Add in value of intensity component:
  90. **
  91. &decattr=&decattr+iif("+"$dbfg,8,0)
  92. **
  93. **  Add in value of blinking component:
  94. **
  95. &decattr=&decattr+iif("*"$dbfg,128,0)
  96. ?
  97. ? &decattr
  98. ?
  99. RETURN
  100.