slazav / mapsoft2

Programs for map handling, based on mapsoft2-libs
https://slazav.github.io/mapsoft2/
GNU General Public License v3.0
6 stars 1 forks source link

Некорректная работа HelpPrinter в ms2conv #51

Closed ioctl-user closed 4 years ago

ioctl-user commented 4 years ago

При запуске теста ms2conv.test1, а точнее assert_cmd "$P --help" "$help_msg" 1 с вероятностью 50% возникает ошибка из-за того, что функция HelpPrinter зачастую возвращает разную ширину окна, отчего меняется разбиение строк и сравнение выводов с --help не срабатывает. Видимо ioctl в HelpPrinter возвращает ошибку, отчего в переменной size.ws_col остаётся мусор из стека, который потом копируется в width. Исправить можно следующим патчем:

index d6f8291..6164f4d 100644
--- a/getopt/getopt.cpp
+++ b/getopt/getopt.cpp
@@ -153,8 +153,11 @@ HelpPrinter::HelpPrinter(
     usage_head(false), width(80) {

   struct winsize size;
-  ioctl(STDOUT_FILENO,TIOCGWINSZ,&size);
-  width = size.ws_col;
+  if (ioctl(STDOUT_FILENO,TIOCGWINSZ,&size) != -1) {
+    width = size.ws_col;
+  } else {
+    width = 80;
+  }
   if (width<1) width=80;
 }

Пытался сделать merge request, но у меня не получилось создать ветку на github. Как лучше поступать в дальнейшем в подобных случаях?

Ниже как выглядит ошибка:


  exp:
ms2conv -- mapsoft2 converter for geodata and raster maps
Usage:
        ms2conv <options> <input files> -o <output file>

Description

ms2conv reads geodata from files (OziExplorer, GPX, KML, GeoJSON, GarminUtils,
ZIP formats are supported). Then it applies filters and saves data to the output
file.

General options

 -h, --help
        Show help message.

 --pod
        Show help message as POD template.

 -v, --verbose
        Be verbose.

 -o, --out <arg>
        Output file.

 --out_fmt <arg>
        Output format, geodata (json, gu, gpx, kml, kmz, ozi, zip) or image
        (jpeg, png, gif, tiff, ps, pdf, svg)

Geodata input/output options

 --in_fmt <arg>
        Geodata input format (json, gu, gpx, kml, kmz, ozi, zip).

 --xml_compr <arg>
        Compress XML output (GPX and KML formats), default 0.

 --xml_indent <arg>
        Use XML indentation (GPX and KML formats), default 1.

 --xml_ind_str <arg>
        XML indentation string (GPX and KML formats), default '  '.

 --xml_qchar <arg>
        XML quoting character (GPX and KML formats), default '''.

 --gpx_write_rte <arg>
        Write waypoint lists as routes (GPX format), default 0.

 --json_sort_keys <arg>
        Sort json objects by keys (GeoJSON format), default 1.

 --json_compact <arg>
        Write compact json (GeoJSON format), default 0.

 --json_indent <arg>
        Use json indentation (GeoJSON format), default 1.

 --ozi_map_grid <arg>
        Write map reference points in grid coordinates (OziExplorer format),
        default 0

 --ozi_map_wgs <arg>
        Always use wgs84 datum for map coordinates (OziExplorer format), default
        0

 --gu_enc <arg>
        Garmin Utils format charset (default KOI8-R).

 --ozi_enc <arg>
        OziExplorer format charset (default Windows-1251).

Geodata filtering options

 --skip <arg>
        Skip part of geodata. Argument is a string which letters show what to
        skip: W - waypoints, T - tracks, M - maps, t - time, z - altitude, b -
        map borders.

 --join
        Join all waypoint lists, tracks, map lists.

 --nom_brd
        Set map border for a Soviet nomenclature map (the map should have a
        valid name)

Rendering images

ms2conv can produce images with raster maps, tracks and waypoints. Supported
formats: jpeg, png, gif, tiff, ps, pdf, svg. Format is selected by output file
extension or by --out_fmt option. Option --map can be used to save map reference
for the image (at the moment only OziExplorer map format is supported).

When rendering images the reference should be specified. If --mkref option
exists then it is created from options. If not, then reference of the first map
is used, or it is set to some default value.

Options for making map reference

 --mkref <arg>
        Choose map type (nom, google_tile, tms_tile, proj)

 --name <arg>
        Set map name. For "nom" maps it should contain a valid Soviet
        nomenclature name.

 --dpi <arg>
        Map resolution, pixels per inch ("nom" and "proj" maps)

 --mag <arg>
        Map magnification ("nom" maps)

 --margins <arg>
        Map margins, pixels ("nom" and "proj" maps).

 --top_margin <arg>
        Override top margin value ("nom" and "proj" maps).

 --left_margin <arg>
        Override left margin value ("nom" and "proj" maps).

 --right_margin <arg>
        Override right margin value ("nom" and "proj" maps).

 --bottom_margin <arg>
        Override bottom margin value ("nom" and "proj" maps).

 --zindex <arg>
        Tile zindex ("*_tile" maps). Can be skipped if tile argument has the
        form [x,y,z]

 --tiles <arg>
        Tile or tile range ("*_tile" maps), [x,y], [x,y,z], or [x,y,w,h]

 --coords <arg>
        Figure in projection coordinates (rectangle or lines) to be covered by
        the map ("proj" maps). Figure can be a rectangle written as [x,y,w,h],
        or a line, [[x1,y1],[x2,y2], ...], or a multi-segment line, [<line>,
        <line>, ...].

 --border <arg>
        Map border in projection coordinates ("proj" maps), a line or a
        multi-segment line.

 --coords_wgs <arg>
        Figure in wgs84 coordinates to be covered by the map ("*_tile" or "proj"
        maps), a rectangle, a line, or a multi-segment line.

 --border_wgs <arg>
        Map border in wgs84 coordinates ("*_tile" or "proj" maps), a line or a
        multi-segment line.

 --proj <arg>
        Projection setting, "libproj" parameter string (e.g. "+datum=WGS84
        +proj=lonlat") or mapsoft2 alias ("WGS", "WEB", "FI", "CH", "SU39",
        etc.).Default is WGS.

 --scale <arg>
        Map scale, projection units per map cm ("proj" maps). Default value is
        0.01 degree/cm for degree projections, 1000m/cm for metric projections.

Options for drawing tracks

 --trk_draw_mode <arg>
        Track drawing mode (normal, speed, height).

 --trk_draw_th <arg>
        Line thickness, overrides track setting.

 --trk_draw_color <arg>
        Color (for normal drawing mode), overrides track color.

 --trk_draw_dots <arg>
        Draw dots (for normal drawing mode), default: 1.

 --trk_draw_arrows <arg>
        Draw arrows (for normal drawing mode), default: 0.

 --trk_draw_min <arg>
        Min value (km/h for speed mode, m for height mode).

 --trk_draw_max <arg>
        Max value (km/h for speed mode, m for height mode).

 --trk_draw_grad <arg>
        Color gradient (for speed or height modes), default: BCGYRM.

Options for drawing waypoints

 --wpt_text_font <arg>
        Waypoint font (default: "serif").

 --wpt_text_size <arg>
        Waypoint font size, pixels (default: 10).

 --wpt_text_pad <arg>
        Waypoint text padding, pixels (default: 2).

 --wpt_draw_size <arg>
        Waypoint dot radius, pixels (default: 3).

 --wpt_line_width <arg>
        Waypoint line width, (default: 1).

 --wpt_stick_len <arg>
        Length of waypoint flag stick (default: 10).

 --wpt_color <arg>
        Waypoint color (default: 0xFF000000).

 --wpt_bgcolor <arg>
        Waypoint background color (default: 0xFFFFFFFF).

 --wpt_adj <arg>
        Adjust waypoint flag positions to prevent mutual collisions (default:
        1).

 --wpt_adj_brd <arg>
        Adjust waypoint flag positions to prevent boundary collisions (default:
        0).

 --wpt_skip_far <arg>
        Skip points if their labels can not be placed close enough (default:
        5*wpt_stick_len).

Options for drawing maps

 --map_smooth <arg>
        Smooth map drawing (interpolation for small scales, averaging for large
        ones), default 0.

 --map_clip_brd <arg>
        Clip map to its border (default 1).

 --map_draw_refs <arg>
        Draw map reference points (ARGB color, default 0).

 --map_draw_brd <arg>
        Draw map border (ARGB color, default 0).

 --map_fade <arg>
        Color to fade the map (default is 0, no fading).

Options for saving images

 --tiff_format <arg>
        When writing TIFF, convert image to one of following forms: argb, rgb,
        grey, pal (default depends on the image).

 --tiff_minwhite <arg>
        When writing greyscale TIFF, use MINISWHITE colors (default: 0).

 --jpeg_quality <arg>
        Set JPEG quality (default 95).

 --png_format <arg>
        When writing PNG, convert image to one of following forms: argb, rgb,
        grey, agrey, pal (default depends on the image).

 --cmap_colors <arg>
        Colormap size for reducing image colors (2..256). mage colors are
        reduced when saving to GIF, to PNG with --png_format=pal, to TIFF with
        --tiff_format=pal

 --cmap_alpha <arg>
        Alpha channel: none (default) -- remove it; full -- treat it equally
        with other channels; gif -- keep only fully-transparent color, if
        needed. When saving GIF file (which supports only fully transparent
        color) "full" works in the same way as "gif".

 --cmap_dim_method <arg>
        Analog of pnmcolormap options -spreadbrightness and -spreadluminosity.
        When a box in the color space is measured, color dimensions can be
        treated equally or with luminosity factors. Values: norm (default) or
        lumin.

 --cmap_rep_method <arg>
        Analog of pnmcolormap options -center, -meancolor, and -meanpixel. When
        a box in the color space is chosen, it can be represented by its
        geometrical center, or by averaging pixels or colors in it. Values:
        center, meanpix (default), meancol.

 --cmap_split_method <arg>
        Analog of pnmcolormap options -splitpix, -splitcol, -splitdim. How to
        choose a box in the color space for splitting: by its maximum dimension,
        maximum number of pixels or colors in it. Values: maxdim (default),
        maxpix, maxcol.

 --bgcolor <arg>
        Image background color (default 0xFFFFFFFF).

 -m, --map <arg>
        Write map file in OziExprorer format (by default it is not written).

 --skip_image
        Do not write image file (can be used if only the map file is needed).
        Option -o <file> should be provided anyway, the filename will be written
        to the map-file.
  res:
ms2conv -- mapsoft2 converter for geodata and raster maps
Usage:
        ms2conv <options> <input files> -o <output file>

Description

ms2conv reads geodata from files (OziExplorer, GPX, KML, GeoJSON, GarminUtils, ZIP formats are supported). Then it applies filters and saves data to the output file.

General options

 -h, --help
        Show help message.

 --pod
        Show help message as POD template.

 -v, --verbose
        Be verbose.

 -o, --out <arg>
        Output file.

 --out_fmt <arg>
        Output format, geodata (json, gu, gpx, kml, kmz, ozi, zip) or image (jpeg, png, gif, tiff, ps, pdf, svg)

Geodata input/output options

 --in_fmt <arg>
        Geodata input format (json, gu, gpx, kml, kmz, ozi, zip).

 --xml_compr <arg>
        Compress XML output (GPX and KML formats), default 0.

 --xml_indent <arg>
        Use XML indentation (GPX and KML formats), default 1.

 --xml_ind_str <arg>
        XML indentation string (GPX and KML formats), default '  '.

 --xml_qchar <arg>
        XML quoting character (GPX and KML formats), default '''.

 --gpx_write_rte <arg>
        Write waypoint lists as routes (GPX format), default 0.

 --json_sort_keys <arg>
        Sort json objects by keys (GeoJSON format), default 1.

 --json_compact <arg>
        Write compact json (GeoJSON format), default 0.

 --json_indent <arg>
        Use json indentation (GeoJSON format), default 1.

 --ozi_map_grid <arg>
        Write map reference points in grid coordinates (OziExplorer format), default 0

 --ozi_map_wgs <arg>
        Always use wgs84 datum for map coordinates (OziExplorer format), default 0

 --gu_enc <arg>
        Garmin Utils format charset (default KOI8-R).

 --ozi_enc <arg>
        OziExplorer format charset (default Windows-1251).

Geodata filtering options

 --skip <arg>
        Skip part of geodata. Argument is a string which letters show what to skip: W - waypoints, T - tracks, M - maps, t - time, z - altitude, b - map borders.

 --join
        Join all waypoint lists, tracks, map lists.

 --nom_brd
        Set map border for a Soviet nomenclature map (the map should have a valid name)

Rendering images

ms2conv can produce images with raster maps, tracks and waypoints. Supported formats: jpeg, png, gif, tiff, ps, pdf, svg. Format is selected by output file extension or by --out_fmt option. Option --map can be used to save map reference for the image (at the moment only OziExplorer map format is supported).

When rendering images the reference should be specified. If --mkref option exists then it is created from options. If not, then reference of the first map is used, or it is set to some default value.

Options for making map reference

 --mkref <arg>
        Choose map type (nom, google_tile, tms_tile, proj)

 --name <arg>
        Set map name. For "nom" maps it should contain a valid Soviet nomenclature name.

 --dpi <arg>
        Map resolution, pixels per inch ("nom" and "proj" maps)

 --mag <arg>
        Map magnification ("nom" maps)

 --margins <arg>
        Map margins, pixels ("nom" and "proj" maps).

 --top_margin <arg>
        Override top margin value ("nom" and "proj" maps).

 --left_margin <arg>
        Override left margin value ("nom" and "proj" maps).

 --right_margin <arg>
        Override right margin value ("nom" and "proj" maps).

 --bottom_margin <arg>
        Override bottom margin value ("nom" and "proj" maps).

 --zindex <arg>
        Tile zindex ("*_tile" maps). Can be skipped if tile argument has the form [x,y,z]

 --tiles <arg>
        Tile or tile range ("*_tile" maps), [x,y], [x,y,z], or [x,y,w,h]

 --coords <arg>
        Figure in projection coordinates (rectangle or lines) to be covered by the map ("proj" maps). Figure can be a rectangle written as [x,y,w,h], or a line, [[x1,y1],[x2,y2], ...], or a multi-segment line, [<line>, <line>, ...].

 --border <arg>
        Map border in projection coordinates ("proj" maps), a line or a multi-segment line.

 --coords_wgs <arg>
        Figure in wgs84 coordinates to be covered by the map ("*_tile" or "proj" maps), a rectangle, a line, or a multi-segment line.

 --border_wgs <arg>
        Map border in wgs84 coordinates ("*_tile" or "proj" maps), a line or a multi-segment line.

 --proj <arg>
        Projection setting, "libproj" parameter string (e.g. "+datum=WGS84 +proj=lonlat") or mapsoft2 alias ("WGS", "WEB", "FI", "CH", "SU39", etc.).Default is WGS.

 --scale <arg>
        Map scale, projection units per map cm ("proj" maps). Default value is 0.01 degree/cm for degree projections, 1000m/cm for metric projections.

Options for drawing tracks

 --trk_draw_mode <arg>
        Track drawing mode (normal, speed, height).

 --trk_draw_th <arg>
        Line thickness, overrides track setting.

 --trk_draw_color <arg>
        Color (for normal drawing mode), overrides track color.

 --trk_draw_dots <arg>
        Draw dots (for normal drawing mode), default: 1.

 --trk_draw_arrows <arg>
        Draw arrows (for normal drawing mode), default: 0.

 --trk_draw_min <arg>
        Min value (km/h for speed mode, m for height mode).

 --trk_draw_max <arg>
        Max value (km/h for speed mode, m for height mode).

 --trk_draw_grad <arg>
        Color gradient (for speed or height modes), default: BCGYRM.

Options for drawing waypoints

 --wpt_text_font <arg>
        Waypoint font (default: "serif").

 --wpt_text_size <arg>
        Waypoint font size, pixels (default: 10).

 --wpt_text_pad <arg>
        Waypoint text padding, pixels (default: 2).

 --wpt_draw_size <arg>
        Waypoint dot radius, pixels (default: 3).

 --wpt_line_width <arg>
        Waypoint line width, (default: 1).

 --wpt_stick_len <arg>
        Length of waypoint flag stick (default: 10).

 --wpt_color <arg>
        Waypoint color (default: 0xFF000000).

 --wpt_bgcolor <arg>
        Waypoint background color (default: 0xFFFFFFFF).

 --wpt_adj <arg>
        Adjust waypoint flag positions to prevent mutual collisions (default: 1).

 --wpt_adj_brd <arg>
        Adjust waypoint flag positions to prevent boundary collisions (default: 0).

 --wpt_skip_far <arg>
        Skip points if their labels can not be placed close enough (default: 5*wpt_stick_len).

Options for drawing maps

 --map_smooth <arg>
        Smooth map drawing (interpolation for small scales, averaging for large ones), default 0.

 --map_clip_brd <arg>
        Clip map to its border (default 1).

 --map_draw_refs <arg>
        Draw map reference points (ARGB color, default 0).

 --map_draw_brd <arg>
        Draw map border (ARGB color, default 0).

 --map_fade <arg>
        Color to fade the map (default is 0, no fading).

Options for saving images

 --tiff_format <arg>
        When writing TIFF, convert image to one of following forms: argb, rgb, grey, pal (default depends on the image).

 --tiff_minwhite <arg>
        When writing greyscale TIFF, use MINISWHITE colors (default: 0).

 --jpeg_quality <arg>
        Set JPEG quality (default 95).

 --png_format <arg>
        When writing PNG, convert image to one of following forms: argb, rgb, grey, agrey, pal (default depends on the image).

 --cmap_colors <arg>
        Colormap size for reducing image colors (2..256). mage colors are reduced when saving to GIF, to PNG with --png_format=pal, to TIFF with --tiff_format=pal

 --cmap_alpha <arg>
        Alpha channel: none (default) -- remove it; full -- treat it equally with other channels; gif -- keep only fully-transparent color, if needed. When saving GIF file (which supports only fully transparent color) "full" works in the same way as "gif".

 --cmap_dim_method <arg>
        Analog of pnmcolormap options -spreadbrightness and -spreadluminosity. When a box in the color space is measured, color dimensions can be treated equally or with luminosity factors. Values: norm (default) or lumin.

 --cmap_rep_method <arg>
        Analog of pnmcolormap options -center, -meancolor, and -meanpixel. When a box in the color space is chosen, it can be represented by its geometrical center, or by averaging pixels or colors in it. Values: center, meanpix (default), meancol.

 --cmap_split_method <arg>
        Analog of pnmcolormap options -splitpix, -splitcol, -splitdim. How to choose a box in the color space for splitting: by its maximum dimension, maximum number of pixels or colors in it. Values: maxdim (default), maxpix, maxcol.

 --bgcolor <arg>
        Image background color (default 0xFFFFFFFF).

 -m, --map <arg>
        Write map file in OziExprorer format (by default it is not written).

 --skip_image
        Do not write image file (can be used if only the map file is needed). Option -o <file> should be provided anyway, the filename will be written to the map-file.```
slazav commented 4 years ago

Спасибо, исправляю! А в чем проблема с pull request?

ioctl-user commented 4 years ago

Не получается создать ветку:

Username for 'https://github.com': ioctl-user
Password for 'https://ioctl-user@github.com': 
remote: Permission to slazav/mapsoft2-libs.git denied to ioctl-user.
fatal: «https://github.com/slazav/mapsoft2-libs.git/» недоступно: The requested URL returned error: 403

Может там в настройках проекта что-то можно подкрутить?

slazav commented 4 years ago
  1. Вроде, в github всегда должен быть user=git

  2. Обычно все чужие репозитории закрыты на запись. Стандартная практика - иметь свою копию, ioctl-user/mapsoft2-libs, туда пушить и оттуда делать pull-requests. Но, если так будет удобнее, могу и свой репозиторий открыть. Сейчас сделаю.