home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / SHOWATTR.E < prev    next >
Text File  |  1992-08-26  |  6KB  |  148 lines

  1. ; ShowAttr.e by Larry Margolis
  2. ; A routine to produce a summary of all attributes used in a file.
  3. ; The Comment field displays the following for the specified classes:
  4. ;
  5. ; Bookmark:  Bookmark name, and (permanent) if it would be saved
  6. ; Color:     Names of the foreground and background colors
  7. ; Font:      Font name, size, and selector, separated by '.'
  8. ; Style:     Style name
  9. ;
  10. ; In addition, font and color attributes which would not be saved as part of
  11. ; the EA EPM.ATTRIBUTES because they're considered part of the preceding
  12. ; style attribute have the name of the style prepended to the comment field.
  13.  
  14. compile if not defined(SMALL)  -- Being compiled separately
  15.    include 'stdconst.e'
  16.    tryinclude 'MYCNF.E'
  17.  compile if not defined(NLS_LANGUAGE)
  18.   const NLS_LANGUAGE = 'ENGLISH'
  19.  compile endif
  20.    include NLS_LANGUAGE'.e'
  21.  
  22. defmain 'showattr'
  23.  
  24. compile endif
  25.  
  26. const
  27.    COLOR_CLASS = 1
  28.    BOOKMARK_CLASS = 13
  29.    STYLE_CLASS =  14
  30.    FONT_CLASS =  16
  31.    COLORS = 'Black Blue Green Cyan Red Magenta Brown light_Gray dark_Gray light_Blue light_Green light_Cyan light_Red light_Magenta Yellow White'
  32. ;; values = '0     1    2     3    4   5       6     7          8         9          10          11         12        13            14     15'
  33.  
  34. defc showattributes, showattr =
  35.    universal EPM_utility_array_ID
  36.    universal app_hini
  37.    universal default_font
  38.    display -8
  39.    sayerror 'Working...'  -- Might take a while...
  40.    display 8
  41.    getfileid start_fid
  42. ;; call psave_pos(savepos)
  43.    'xcom e /c .attrib'
  44.    if rc<>-282 then  -- -282 = sayerror("New file")
  45.       sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext(rc)
  46.       return
  47.    endif
  48.    .autosave = 0
  49.    getfileid attrib_fid
  50.    replaceline 'Attributes in' start_fid.filename, 1
  51.    insertline '', 2
  52.    insertline '         Class Value  Push Offst   Col  Line  Comments...', 3
  53.    insertline '         ===== ===== ===== ===== ===== =====  ===========', 4
  54.    attrib_fid.modify = 0
  55.    line=0; col=1; offst=0
  56.    style_line=0; style_col=0; style_offst=0; style_list=''; stylename = ''
  57.    do forever
  58.       class = 0  -- Find any class
  59.       attribute_action 1, class, offst, col, line, start_fid -- 1=FIND NEXT ATTR
  60.       if class=0 then leave; endif
  61.       query_attribute class, val, IsPush, offst, col, line, start_fid
  62.       l = line
  63.       comments = ''
  64.       class_type = ''
  65.       if class=BOOKMARK_CLASS then  -- get name
  66.          do_array 3, EPM_utility_array_ID, 'bmi.'val, bmname  -- Get the name
  67.          comments = bmname
  68.          if IsPush=4 then
  69.             comments = comments '(permanent)'
  70.          endif
  71.          class_type = 'Bookmark'
  72.       elseif class=COLOR_CLASS then
  73.          comments = word(colors, val//16+1) 'on' word(colors, val%16+1)
  74.          if line=style_line & col=style_col & (offst=style_offst+1 | offst=style_offst+2) then
  75.             comments = '(Style:' stylename')' comments
  76.          endif
  77.          class_type = 'Color'
  78. compile if EVERSION >= 5.50
  79.       elseif class=FONT_CLASS then  -- get font info
  80.          comments = queryfont(val)
  81.          parse value comments with fontname '.' fontsize '.' fontsel '.'
  82.          if fontsel then comments=comments '('font_attribs(fontsel)')'; endif
  83.          if line=style_line & col=style_col & offst=style_offst+1 then
  84.             comments = '(Style:' stylename')' comments
  85.          endif
  86.          class_type = 'Font'
  87. compile endif
  88.       elseif class=STYLE_CLASS then  -- get style info
  89.          do_array 3, EPM_utility_array_ID, 'si.'val, stylename -- Get the style name
  90.          style_line=line; style_col=col; style_offst=offst
  91.          comments = stylename
  92.          if val<256 & not pos(chr(val), style_list) then  -- a style we haven't seen yet
  93.             if style_list='' then
  94.                insertline 'Styles used in' start_fid.filename, 1
  95.                insertline '', 2, attrib_fid
  96.                insertline '', 2, attrib_fid
  97.             endif
  98.             style_list = style_list || chr(val)
  99.             parse value queryprofile(app_hini, 'Style', stylename) with fontname '.' fontsize '.' fontsel '.' fg '.' bg
  100.             if fontsel then fontsel=fontsel'='font_attribs(fontsel); endif
  101.             insertline leftstr(stylename,20) 'font('fontname') size('fontsize') sel('fontsel')  colors' word(colors, fg+1) 'on' word(colors, bg+1), 2+length(style_list), attrib_fid
  102.          endif  -- new style
  103.          class_type = 'Style'
  104.       endif  -- class=STYLE_CLASS
  105.       insertline leftstr(class_type, 8) rightstr(class,5) rightstr(val,5) rightstr(ispush,5) rightstr(offst,5) rightstr(col,5) rightstr(l,5)'  'comments, attrib_fid.last+1, attrib_fid
  106.    enddo
  107.    if attrib_fid.modify then
  108.       attrib_fid.filename = '.attrib'
  109.       attrib_fid.titletext = 'Attribute summary for' start_fid.filename
  110.       attrib_fid.modify = 0
  111.       'postme monofont'
  112.    else
  113.       'xcom quit'
  114.       sayerror 'No attributes found.'
  115.    endif
  116.  
  117. defproc font_attribs(attr)
  118.    attribs = ''
  119.    plus = ''
  120.    if attr // 2 then
  121.       attribs = 'Italic'
  122.       plus = ' + '
  123.    endif
  124.    if attr%2 - 2*(attr%4) then
  125.       attribs = attribs || plus || 'Underscore'
  126.       plus = ' + '
  127.    endif
  128.    if attr%4 - 2*(attr%8) then
  129.       attribs = attribs || plus || 'Negative'
  130.       plus = ' + '
  131.    endif
  132.    if attr%8 - 2*(attr%16) then
  133.       attribs = attribs || plus || 'Outline'
  134.       plus = ' + '
  135.    endif
  136.    if attr%16 - 2*(attr%32) then
  137.       attribs = attribs || plus || 'Strikeout'
  138.       plus = ' + '
  139.    endif
  140.    if attr%32 - 2*(attr%64) then
  141.       attribs = attribs || plus || 'Bold'
  142.       plus = ' + '
  143.    endif
  144.    if attr%64 then
  145.       attribs = attribs || plus || '(unknown selection(s))'
  146.    endif
  147.    return attribs
  148.