note description: "[ Objects that ... ]" author: "$Author$" date: "$Date$" revision: "$Revision$" class BUILD_HTML_INDEX inherit ARGUMENTS_32 create make feature {NONE} -- Initialization make -- Initialize `Current'. local ini_location: PATH icons_location: PATH output_location: PATH i,n: INTEGER s: READABLE_STRING_GENERAL do if argument_count >= 3 then create ini_location.make_from_string (argument (1)) ini_location := ini_location.absolute_path.canonical_path create icons_location.make_from_string (argument (2)) icons_location := icons_location.absolute_path.canonical_path create output_location.make_from_string (argument (3)) output_location := output_location.absolute_path.canonical_path is_png_mode := False is_svg_mode := False check is_svg_mode: is_svg_mode end if argument_count > 3 then from i := 4 n := argument_count until i > n loop s := argument (i) if s /= Void then if s.is_case_insensitive_equal ("--png") then is_png_mode := True end if s.is_case_insensitive_equal ("--svg") then is_svg_mode := True end end i := i + 1 end if not is_svg_mode and not is_png_mode then is_svg_mode := True -- Default end end process (ini_location, icons_location, output_location) else print ("Usage: prog path-to-ini-file icons-directory html-output%N") (create {EXCEPTIONS}).die (-1) end end feature -- Execution process (a_ini_location: PATH; a_icons_location: PATH; a_output_location: PATH) local ini, output: PLAIN_TEXT_FILE i: INTEGER rn: detachable IMMUTABLE_STRING_8 icon_name: IMMUTABLE_STRING_8 s: STRING_8 line, index: INTEGER fn1, fn2: STRING_32 l_icons_path: IMMUTABLE_STRING_8 l_width: INTEGER pw,ph: INTEGER fut: FILE_UTILITIES cl: detachable STRING_8 l_missing: BOOLEAN l_has_svg, l_has_png: BOOLEAN do create ini.make_with_path (a_ini_location) if ini.exists and then ini.is_access_readable then ini.open_read fn1 := a_output_location.parent.name fn2 := a_icons_location.name if fn2.starts_with (fn1) then fn2.remove_head (fn1.count + 1) end -- if not fn2.is_empty then l_icons_path := {UTF_CONVERTER}.utf_32_string_to_utf_8_string_8 (fn2) + "/" else l_icons_path := "" end create output.make_with_path (a_output_location) if not output.exists or else output.is_access_writable then output.create_read_write output.put_string ("[ ]") if is_svg_mode then if is_png_mode then output.put_string ("

All SVG and PNG icons

") else output.put_string ("

All SVG icons (or PNG if missing)

") end else output.put_string ("

All PNG icons (or SVG if missing)

") end output.put_string ("[
Background color: None | Red | Green | White | Black | Grey
]") output.put_string ("
") from until ini.end_of_file loop ini.read_line s := ini.last_string s.adjust if s.is_whitespace then -- Skip elseif s [1] = ';' then -- Skip commented line elseif s [1] = '[' then i := s.index_of (']', 2) if i > 0 then s := s.substring (2, i - 1) s.adjust if s.is_empty then -- Ignore elseif s [1] = '@' then s.remove_head (1) s.left_adjust create rn.make_from_string (s) output.put_string ("
") else create rn.make_from_string (s) line := line + 1 index := 0 output.put_string ("
%N
%N") output.put_string ("
%N") end else -- Ignore line, as unexpected! end elseif rn /= Void then s := rn + " " + s s.replace_substring_all (" ", "_") create icon_name.make_from_string (s) index := index + 1 if l_width > 0 and index > l_width then index := 1 line := line + 1 end l_has_svg := fut.file_path_exists (a_icons_location.extended (line.out).extended (index.out).appended_with_extension ("svg")) l_has_png := fut.file_path_exists (a_icons_location.extended (line.out).extended (index.out).appended_with_extension ("png")) l_missing := not (l_has_png or l_has_svg) cl := "" if l_has_svg then cl.append (" svg") end if l_has_png then cl.append (" png") end if l_missing then cl.append (" missing") end output.put_string ("%T
") if is_svg_mode then if l_has_svg then output.put_string (" 0 then output.put_string (" style=%"width: "+ pw.out +"%"") end output.put_string (" title=%"svg ("+ line.out + "," + index.out + ") %"") output.put_string ("/>") else if l_has_png and not is_png_mode then output.put_string ("") else output.put_string (" 0 then output.put_string (" style=%"min-width: "+ pw.out +"; min-height: "+ ph.out +"%"") end output.put_string (">?") end end end if is_png_mode then if l_has_png then output.put_string ("") else if l_has_svg and not is_svg_mode then output.put_string (" 0 then output.put_string (" style=%"width: "+ pw.out +"%"") end output.put_string (" title=%"png ("+ line.out + "," + index.out + ") %"") output.put_string ("/>") else output.put_string (" 0 then output.put_string (" style=%"min-width: "+ pw.out +"; min-height: "+ ph.out +"%"") end output.put_string (">?") end end end if l_missing and (is_svg_mode xor is_png_mode) then output.put_string (" 0 then output.put_string (" style=%"min-width: "+ pw.out +"; min-height: "+ ph.out +"%"") end output.put_string (">?") end output.put_string ("
") output.put_string (icon_name) output.put_string (" (" + line.out + "," + index.out + ")") output.put_string ("
") output.put_string ("
%N") elseif s.starts_with ("width=") then s.remove_head (s.index_of ('=', 1)) l_width := s.to_integer elseif s.starts_with ("pixel_width=") then s.remove_head (s.index_of ('=', 1)) pw := s.to_integer elseif s.starts_with ("pixel_height=") then s.remove_head (s.index_of ('=', 1)) ph := s.to_integer end end output.put_string ("
%N") output.put_string ("[ ]") output.close else io.error.put_string_32 ("ERROR: can not write to file: " + a_output_location.name + "%N") end ini.close else io.error.put_string_32 ("ERROR: can not read file: " + a_ini_location.name + "%N") end end feature -- Access is_svg_mode: BOOLEAN -- Use SVG, then PNG -- Default: True is_png_mode: BOOLEAN -- Use PNG, then SVG -- Default: False feature -- Change feature {NONE} -- Implementation invariant -- invariant_clause: True end