From 33b59d5723c1fb952bbf542a3d049f4f1e76d22f Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Sun, 26 Dec 2010 20:35:24 +0000 Subject: [PATCH] Updated copyrights to 2010. Reimplement locale stuff in hz (adding different controls for C and C++ locales), also take the recent locale-related changes in gtkmm into account. Cleanups in snprintf-related code, portable_snprintf(). Added doxygen-style comments to some hz headers. Better console redirection handling for win32. Blacklisted linux device mapper devices (annoying in LVM setups). Added beesu support and generally improved gsmartcontrol-root script (this is needed for Fedora 14 which doesn't have any old supported su mechanisms). Added "menu" dependency for deb packages. Added kdev4 project. --- gsmartcontrol/.svnignore.txt | 2 +- gsmartcontrol/TODO | 326 +++++++++++------- gsmartcontrol/configure.ac | 2 +- .../cron-based_noadmin/cron_gather_smart.sh | 6 +- .../cron-based_noadmin/smartctl_subst.sh | 6 +- gsmartcontrol/data/gsmartcontrol-root.in | 55 +-- gsmartcontrol/debian.dist/control | 2 +- gsmartcontrol/debian.dist/copyright | 4 +- gsmartcontrol/file2csource.sh | 2 +- gsmartcontrol/gsmartcontrol.kdev4 | 3 + gsmartcontrol/gsmartcontrol.spec.in | 9 + gsmartcontrol/src/applib/app_gtkmm_features.h | 2 +- gsmartcontrol/src/applib/app_gtkmm_utils.cpp | 2 +- gsmartcontrol/src/applib/app_gtkmm_utils.h | 2 +- gsmartcontrol/src/applib/app_pango_utils.cpp | 2 +- gsmartcontrol/src/applib/app_pango_utils.h | 2 +- gsmartcontrol/src/applib/app_pcrecpp.h | 2 +- gsmartcontrol/src/applib/app_ui_res_utils.h | 2 +- .../src/applib/app_ui_res_utils_test.cpp | 2 +- .../src/applib/app_ui_res_utils_test_data.cpp | 2 +- gsmartcontrol/src/applib/cmdex.cpp | 2 +- gsmartcontrol/src/applib/cmdex.h | 2 +- gsmartcontrol/src/applib/cmdex_sync.cpp | 2 +- gsmartcontrol/src/applib/cmdex_sync.h | 2 +- gsmartcontrol/src/applib/cmdex_sync_gui.cpp | 2 +- gsmartcontrol/src/applib/cmdex_sync_gui.h | 2 +- gsmartcontrol/src/applib/gui_utils.cpp | 2 +- gsmartcontrol/src/applib/gui_utils.h | 2 +- gsmartcontrol/src/applib/selftest.cpp | 2 +- gsmartcontrol/src/applib/selftest.h | 2 +- .../src/applib/smartctl_executor.cpp | 2 +- gsmartcontrol/src/applib/smartctl_executor.h | 2 +- .../src/applib/smartctl_executor_gui.h | 2 +- .../src/applib/smartctl_executor_test.cpp | 2 +- gsmartcontrol/src/applib/smartctl_parser.cpp | 26 +- gsmartcontrol/src/applib/smartctl_parser.h | 2 +- .../src/applib/smartctl_parser_test.cpp | 2 +- gsmartcontrol/src/applib/spawn_test.cpp | 2 +- gsmartcontrol/src/applib/storage_detector.cpp | 4 +- gsmartcontrol/src/applib/storage_detector.h | 2 +- .../src/applib/storage_detector_test.cpp | 2 +- gsmartcontrol/src/applib/storage_device.cpp | 2 +- gsmartcontrol/src/applib/storage_device.h | 2 +- gsmartcontrol/src/applib/storage_property.cpp | 2 +- gsmartcontrol/src/applib/storage_property.h | 2 +- .../src/applib/storage_property_colors.h | 2 +- .../src/applib/storage_property_descr.cpp | 2 +- .../src/applib/storage_property_descr.h | 2 +- gsmartcontrol/src/applib/storage_settings.h | 2 +- gsmartcontrol/src/applib/wrapping_label.h | 2 +- gsmartcontrol/src/global_macros.h | 2 +- gsmartcontrol/src/gsc_about_dialog.cpp | 4 +- gsmartcontrol/src/gsc_about_dialog.h | 2 +- .../src/gsc_executor_error_dialog.cpp | 2 +- gsmartcontrol/src/gsc_executor_error_dialog.h | 2 +- gsmartcontrol/src/gsc_executor_log_window.cpp | 4 +- gsmartcontrol/src/gsc_executor_log_window.h | 2 +- gsmartcontrol/src/gsc_help_window.cpp | 2 +- gsmartcontrol/src/gsc_help_window.h | 2 +- gsmartcontrol/src/gsc_info_window.cpp | 24 +- gsmartcontrol/src/gsc_info_window.h | 2 +- gsmartcontrol/src/gsc_init.cpp | 112 +++--- gsmartcontrol/src/gsc_init.h | 2 +- gsmartcontrol/src/gsc_main.cpp | 2 +- gsmartcontrol/src/gsc_main_window.cpp | 2 +- gsmartcontrol/src/gsc_main_window.h | 2 +- gsmartcontrol/src/gsc_main_window_iconview.h | 2 +- gsmartcontrol/src/gsc_preferences_window.cpp | 2 +- gsmartcontrol/src/gsc_preferences_window.h | 2 +- gsmartcontrol/src/gsc_settings.h | 2 +- gsmartcontrol/src/gsc_text_window.h | 2 +- gsmartcontrol/src/hz/Makefile.am | 2 +- gsmartcontrol/src/hz/any_convert.h | 2 +- gsmartcontrol/src/hz/any_type.h | 4 +- gsmartcontrol/src/hz/any_type_holder.h | 4 +- gsmartcontrol/src/hz/any_type_test.cpp | 2 +- gsmartcontrol/src/hz/ascii.h | 2 +- gsmartcontrol/src/hz/bad_cast_exception.h | 2 +- gsmartcontrol/src/hz/bin2ascii_encoder.h | 2 +- .../src/hz/bin2ascii_encoder_test.cpp | 2 +- gsmartcontrol/src/hz/common_types.h | 2 +- gsmartcontrol/src/hz/cstdint.h | 2 +- gsmartcontrol/src/hz/data_file.h | 2 +- gsmartcontrol/src/hz/debug.h | 2 +- gsmartcontrol/src/hz/down_cast.h | 2 +- gsmartcontrol/src/hz/down_cast_test.cpp | 2 +- gsmartcontrol/src/hz/env_tools.h | 2 +- gsmartcontrol/src/hz/errno_string.h | 2 +- gsmartcontrol/src/hz/errno_string_test.cpp | 2 +- gsmartcontrol/src/hz/error.h | 2 +- gsmartcontrol/src/hz/error_holder.h | 2 +- gsmartcontrol/src/hz/exceptions.h | 2 +- gsmartcontrol/src/hz/format_unit.h | 8 +- gsmartcontrol/src/hz/format_unit_test.cpp | 2 +- gsmartcontrol/src/hz/fs_common.h | 2 +- gsmartcontrol/src/hz/fs_dir.h | 2 +- gsmartcontrol/src/hz/fs_dir_platform.h | 2 +- gsmartcontrol/src/hz/fs_dir_test.cpp | 2 +- gsmartcontrol/src/hz/fs_error_holder.h | 2 +- gsmartcontrol/src/hz/fs_file.h | 2 +- gsmartcontrol/src/hz/fs_file_test.cpp | 2 +- gsmartcontrol/src/hz/fs_fstream.h | 2 +- gsmartcontrol/src/hz/fs_path.h | 2 +- gsmartcontrol/src/hz/fs_path_test.cpp | 2 +- gsmartcontrol/src/hz/fs_path_utils.h | 2 +- gsmartcontrol/src/hz/fs_tools.h | 2 +- gsmartcontrol/src/hz/function.h | 4 +- gsmartcontrol/src/hz/function_impl.h | 4 +- gsmartcontrol/src/hz/hz_config.h | 103 ++++-- gsmartcontrol/src/hz/i18n.h | 2 +- gsmartcontrol/src/hz/instance_manager.h | 2 +- gsmartcontrol/src/hz/intrusive_ptr.h | 4 +- gsmartcontrol/src/hz/intrusive_scoped_lock.h | 2 +- gsmartcontrol/src/hz/launch_url.h | 2 +- gsmartcontrol/src/hz/local_algo.h | 2 +- gsmartcontrol/src/hz/locale_tools.h | 277 ++++++++++++++- gsmartcontrol/src/hz/noncopyable.h | 4 +- gsmartcontrol/src/hz/optional_value.h | 2 +- gsmartcontrol/src/hz/portable_snprintf.h | 93 +++-- gsmartcontrol/src/hz/process_signal.h | 2 +- gsmartcontrol/src/hz/ptr_container.h | 2 +- gsmartcontrol/src/hz/res_data.h | 2 +- gsmartcontrol/src/hz/scoped_array.h | 6 +- gsmartcontrol/src/hz/scoped_ptr.h | 6 +- gsmartcontrol/src/hz/shared_ptr.h | 4 +- gsmartcontrol/src/hz/static_assert.h | 2 +- gsmartcontrol/src/hz/stream_cast.h | 4 +- gsmartcontrol/src/hz/string_algo.h | 2 +- gsmartcontrol/src/hz/string_algo_test.cpp | 2 +- gsmartcontrol/src/hz/string_format.h | 15 +- gsmartcontrol/src/hz/string_format_test.cpp | 2 +- gsmartcontrol/src/hz/string_num.h | 2 +- gsmartcontrol/src/hz/string_num_test.cpp | 2 +- gsmartcontrol/src/hz/string_sprintf.h | 126 ++++--- gsmartcontrol/src/hz/string_sprintf_macros.h | 79 +++++ gsmartcontrol/src/hz/string_wcmatch.h | 2 +- gsmartcontrol/src/hz/string_wcmatch_test.cpp | 2 +- gsmartcontrol/src/hz/sync.h | 2 +- gsmartcontrol/src/hz/sync_lock_ptr.h | 2 +- gsmartcontrol/src/hz/sync_multilock.h | 2 +- gsmartcontrol/src/hz/sync_multilock_test.cpp | 2 +- gsmartcontrol/src/hz/sync_part_get_policy.h | 2 +- gsmartcontrol/src/hz/sync_policy_boost.h | 2 +- gsmartcontrol/src/hz/sync_policy_glib.h | 2 +- gsmartcontrol/src/hz/sync_policy_glibmm.h | 2 +- gsmartcontrol/src/hz/sync_policy_poco.h | 2 +- gsmartcontrol/src/hz/sync_policy_pthread.h | 2 +- gsmartcontrol/src/hz/sync_policy_win32.h | 2 +- gsmartcontrol/src/hz/sync_test.cpp | 2 +- gsmartcontrol/src/hz/system_specific.h | 28 +- gsmartcontrol/src/hz/tls.h | 2 +- gsmartcontrol/src/hz/tls_policy_boost.h | 2 +- gsmartcontrol/src/hz/tls_policy_glib.h | 2 +- gsmartcontrol/src/hz/tls_policy_pthread.h | 2 +- gsmartcontrol/src/hz/tls_policy_win32.h | 2 +- gsmartcontrol/src/hz/tls_test.cpp | 2 +- gsmartcontrol/src/hz/type_categories.h | 2 +- gsmartcontrol/src/hz/win32_tools.h | 144 +++++--- gsmartcontrol/src/libdebug/dchannel.cpp | 2 +- gsmartcontrol/src/libdebug/dchannel.h | 2 +- gsmartcontrol/src/libdebug/dcmdarg.cpp | 2 +- gsmartcontrol/src/libdebug/dcmdarg.h | 2 +- gsmartcontrol/src/libdebug/dexcept.h | 2 +- gsmartcontrol/src/libdebug/dflags.cpp | 2 +- gsmartcontrol/src/libdebug/dflags.h | 2 +- gsmartcontrol/src/libdebug/dout.cpp | 2 +- gsmartcontrol/src/libdebug/dout.h | 5 +- gsmartcontrol/src/libdebug/dstate.cpp | 2 +- gsmartcontrol/src/libdebug/dstate.h | 2 +- gsmartcontrol/src/libdebug/dstate_pub.h | 2 +- gsmartcontrol/src/libdebug/dstream.cpp | 2 +- gsmartcontrol/src/libdebug/dstream.h | 2 +- gsmartcontrol/src/libdebug/libdebug.h | 2 +- gsmartcontrol/src/libdebug/libdebug_mini.h | 2 +- gsmartcontrol/src/libdebug/libdebug_test.cpp | 2 +- gsmartcontrol/src/rconfig/rcautosave.h | 2 +- gsmartcontrol/src/rconfig/rcdump.h | 2 +- gsmartcontrol/src/rconfig/rcloadsave.h | 2 +- gsmartcontrol/src/rconfig/rcmain.h | 2 +- gsmartcontrol/src/rconfig/rconfig.h | 2 +- gsmartcontrol/src/rconfig/rconfig_mini.h | 2 +- gsmartcontrol/src/rconfig/rconfig_test.cpp | 2 +- gsmartcontrol/src/rmn/resource_base.h | 4 +- gsmartcontrol/src/rmn/resource_data_any.h | 2 +- gsmartcontrol/src/rmn/resource_data_locking.h | 2 +- gsmartcontrol/src/rmn/resource_data_one.h | 2 +- gsmartcontrol/src/rmn/resource_data_types.h | 2 +- gsmartcontrol/src/rmn/resource_exception.h | 2 +- gsmartcontrol/src/rmn/resource_node.h | 4 +- gsmartcontrol/src/rmn/resource_node_dump.h | 4 +- .../src/rmn/resource_serialization.h | 6 +- gsmartcontrol/src/rmn/rmn.h | 4 +- gsmartcontrol/src/rmn/rmn_test.cpp | 4 +- gsmartcontrol/templates/cc | 6 - gsmartcontrol/templates/hh | 6 - 195 files changed, 1221 insertions(+), 630 deletions(-) create mode 100644 gsmartcontrol/gsmartcontrol.kdev4 create mode 100644 gsmartcontrol/src/hz/string_sprintf_macros.h delete mode 100644 gsmartcontrol/templates/cc delete mode 100644 gsmartcontrol/templates/hh diff --git a/gsmartcontrol/.svnignore.txt b/gsmartcontrol/.svnignore.txt index 0486330..4d2c657 100644 --- a/gsmartcontrol/.svnignore.txt +++ b/gsmartcontrol/.svnignore.txt @@ -13,4 +13,4 @@ install-sh *.glade.cpp *.ui.cpp *.txt.cpp -gsmartcontrol.spec +.kdev4 diff --git a/gsmartcontrol/TODO b/gsmartcontrol/TODO index 7bdb832..aff47ff 100644 --- a/gsmartcontrol/TODO +++ b/gsmartcontrol/TODO @@ -19,6 +19,17 @@ A treeview (also iconview, combobox) from glade comes with existing model, which should be unset. +Bugs / patches: + + Patch pangomm for Pango::strip_markup(). + ++ gtkmm bug: No Gtk::AboutDialog::set_logo(NULL); + ++ Gtk::Main m(argc, argv, false); + If gtk_get_option_group() and g_option_context_parse() were used before, + this generates a warning: + (gsmartcontrol:28241): Gtk-WARNING **: gtk_disable_setlocale() must be called before gtk_init() + -------------------------------------------------------- @@ -27,24 +38,26 @@ TODO: +Clear the test message area when starting a new test. -+Support launching from read-only media (win32 zip version) (seems like this was a windows problem). +Add debian/ubuntu's su-to-root support to gsmartcontrol-root. -Testing: If ETA time has elapsed, but it's still only at 10% completion, - ETA 0 is displayed. Fix. +Testing: + If ETA time has elapsed, but it's still only at 10% completion, + ETA 0 is displayed. Fix. + If smartctl -t ... returns an error, testing=true should not be set. + Detect running tests on launch (maybe ask the user too? some tests + may be stuck due to bad firmware). + Allow quitting when test is running (ask first). -Testing: If smartctl -t ... returns an error, testing=true should not be set. - -Testing: Detect running tests on launch (maybe ask the user too? some tests - may be stuck due to bad firmware). - -Testing: Allow quitting when test is running (ask first). - -Add ability to configure default save filename (in config-file only): +Add ability to configure default save filename (in config-file only?): "{serial}-{model}-{date}.txt", with the default being "{model}-{date}.txt". Add string_replace_linear(), where multiple strings are replaced into the original string (as opposed to previous result). ++Re-check long double printing - win32 libc doesn't support it, a cast + to double is needed. + The underlying problem is that in msvc, long double is the same size + as double, so printf() has mingw-incompatible presentation of long double. Add support for launching with consolehelper (from usermode package). Fedora uses this by default. @@ -54,16 +67,172 @@ Add support for launching with consolehelper (from usermode package). but I think we can check it with "which". http://fedoranews.org/contributors/matt_hansen/nautilus/ -Highlight soft-warning-having devices too (configurable?). +Add "Show output" button to the devices with "No further info available...". + +If the detection executes "smartctl -i", don't execute it again afterwards. When adding device, have an option to specify "-d" type and other parameters. This is needed to support multi-disk devices. + Maybe make "-d" a dropdown? + Not sure, "-l aaa /tmp" doesn't list all types. Also raid... -Add "Show output" button to the devices with "No further info available...". +Add support for multiple drives behind devices. + Add support for specifying these drives on gsmartcontrol command-line, + each one with optional smartctl parameters. + Use :: as delimiter, as in device::-d_string::other_options. + Show in UI as device (-d_string). + +Rework drive properties UI: + add properties for each multi-drive. + smartctl options + use 48-bit or not or auto. + Enable/disable/dont_touch SMART on startup for this drive. + Enable/disable/dont_touch AODC on startup for this drive. + +Add --init-smart-only option to only apply the SMART/AODC enabling status + from the drive properties. + Add also --no-init-smart to avoid doing that on GUI startup. + +Notifications: + Tied to (drive::subdrive, notif_key, exact_value(optional)). + If exact_value isn't specified when ignoring, notify on every value change. + Ignore options: + Per-drive: Ignore all notifications for this key, ignore only this value. + Don't generate multiple notifications for the same drive/key combo. + Clearing in preferences: Clear all ignored, clear ignored for this drive, clear individual. + Soft-warnings require "-a" by default, tricky for scsi (maybe try -a, then -i?). + +Monitor: + Needs root access, so not gonna happen until the dbus/udisks stuff + is finalized. + Same program, add --tray option to start in tray only. + Option to enable the tray icon. + Option to continue running in the tray on window close. + Use freedesktop notifications when notifications are generated + and we're running in tray only. + Don't generate the same notification at a single run time if it was + ignored (untouched) by the user; Change the tray icon and + show them in the main window instead. + Periodically re-run smartctl to refresh the notifications. + Periodically see if drives were added / removed (possibly use OS callbacks + instead of polling?) + +Fix inability to detect types in some error logs. + +Options->Prefs->Drives + Add a hint about "pd0" for Windows version. + +If a drive is not recognized, suggest using -d (sat, sat,12, ...) + Refer the user to + http://sourceforge.net/apps/trac/smartmontools/wiki/Supported_USB-Devices + + + +RAID: + http://sourceforge.net/apps/trac/smartmontools/wiki/Supported_RAID-Controllers + + Areca Linux: + Call as: smartctl -i -d areca,[1-24] /dev/sg0 + Detection: + Check if /proc/scsi/sg/device_strs contains "Areca RAID controller". + If not, there's no Areca controller present. + Check /proc/scsi/sg/devices, the line # with type 3 is the sg* number. + The "host" field value is the N value in /sys, see below. + Check /sys/bus/scsi/devices/hostN/scsi_host/hostN/host_fw_hd_channels, set + its contents as the number of ports. If not present, use 24. + Probe each port for a valid drive: If the output contains "Device Read Identity Failed", + then there is no drive on that port (or Areca has an old firmware, nothing we can + do there). + Notification: If /sys/bus/scsi/devices/hostN/scsi_host/hostN/host_fw_version + is older than "V1.46 2009-01-06", notify the user (maybe its better to grep + the smartctl output for that on port 0?). + + 3ware Linux: + Call as: smartctl -i -d 3ware,[0-127] /dev/twa[0-15] (or twe[0-15]) + Use twe* for [678]xxx series, and twa* for 9xxx series. + Note: twe* devices are limited to [0-15] ports (not sure about this). + Note: /dev/tw* devices may not exist, they are created by smartctl on the first run. + Note: for twe*, /dev/sda may also exist (to be used with -d 3ware,N), we should + somehow detect and ignore them. + Note: when specifying non-existent port, either a "Device Read Identity Failed" + error, or a "blank" info may be returned. + Detection: + Grep /proc/devices for "twa" or "twe" (e.g. "251 twa"). Use this for /dev/tw* part. + Grep /proc/scsi/scsi for AMCC (3ware, LSI too?), use number of matched lines N + for /dev/tw*[0, N-1]. + For detecting the number of ports, use "tw_cli /c0 show all", 0 being the controller N. + If there's no tw_cli, we'll have to scan all 127 ports. + + 3ware FreeBSD: + Call as: smartctl -i -d 3ware,[0-127] /dev/twa0 (or twe0) + Detection: unknown. + + 3ware Windows (XP so far, maybe the same under the others): + For 3ware 9xxx only. + Call as: smartctl -i sd[a-z],N + N is port, a-z is logical drive (unit) provided by controller. + N is limited to [0, 31] in the code. + The sd[a-z] device actually exists as \\.\PhysicalDrive[0-N]. + No idea how to check if it's 3ware. + Call as: smarctl -i tw_cli/cx/py + This runs tw_cli tool and parses the output; controller x, port y. + tw_cli is needed for 64-bit systems, as well as older controllers. + In tw_cli mode only limited information-gathering is supported. + tw_cli (part of 3DM2) is automatically added to system PATH, + no need to look for it. + 3DM2 install can be detected by checking: + HKEY_USERS\.DEFAULT\Software\3ware\3DM2, InstallPath + Another option for detection (whether it's 3ware) would be getting + \\.\PhysicalDrive0 properties, like smartctl does. + Newer (post-5.39.1) smartctl supports --scan-open, which will give us: + /dev/sda,0 -d ata (opened) + /dev/sda,1 -d ata (opened) + -d 3ware is not needed under Windows. We should treat sda as pd0 + and remove pd0 from PhysicalDrive-detected list. + Running smartctl on sda gives almost the same result as on sda,0. + + + LSI MegaRAID (SCSI/SAS), Linux: + Call as: smartctl -i -d megaraid,[0-?] /dev/sda + We should differentiate between ordinary sda and RAID one (not sure if sda is detected). + Detection: unknown. + + HighPoint RocketRAID ((S)ATA) Linux: + Call as: smartctl -i -d hpt,[1-8]/[1-8] /dev/sda + Call as: smartctl -i -d hpt,[1-8]/[1-8]/[1-15] /dev/sda + Note: /dev/sda should be derived from this controller. + We should differentiate between ordinary sda and RAID one (not sure if sda is detected). + Smartctl docs specify smaller limits, but the code says these are the ones. + Detection: unknown. + + HighPoint RocketRAID ((S)ATA) FreeBSD: + Call as: smartctl -i -d hpt,[1-8]/[1-8] /dev/hptrr + Call as: smartctl -i -d hpt,[1-8]/[1-8]/[1-15] /dev/hptrr + Note: /dev/hptrr should be derived from this controller. + Smartctl docs specify smaller limits, but the code says these are the ones. + Detection: unknown. + TODO: Analyze sent info. + + CCISS (HP (Compaq) Smart Array Controller) Linux: + Call as: smartctl -a -d cciss,[0-127] /dev/cciss/c0d0 + c0d0 is the controller (d0 seems to be a logical drive, doesn't matter?). + /dev/cciss/c0d0p1 is the first ordinary partition (used in mount, etc...). + The port limit had a brief regression in 5.39.x (limited to 15). + 5.39 doesn't seem to work at all (prereleases work with P400 controller)? + Possibly a 64-bit-only issue? + To detect controller presence: cat /proc/devices, contains "cciss0" + for controller 0. + There is a cciss_vol_status utility but it doesn't report anything except "OK" status. + It may not return the "SMART Health Status: OK" line in smartctl -i for some reason? + (It returns it in -a though, and in some freebsd output I found). + If no /dev/cciss exists, you may need to run "cd /dev; ./MAKEDEV cciss". + Smartctl SVN has some /dev/sg* stuff, check it out. + + CCISS (HP (Compaq) Smart Array Controller) FreeBSD: + Seems to be the same as Linux (uses the same driver?). + Detection: unknown. -Patch pangomm for Pango::strip_markup(). -No Gtk::AboutDialog::set_logo(NULL); libdebug: @@ -74,124 +243,33 @@ libdebug: use format_time() instead of ctime() and friends, with ISO formatting. +48-bit ATA command support: + '-l xerror' -> Extended Comprehensive Error log: An multi-sector and + LBA48 capable version of '-l error'. Output is similar, except more + entries can exists and the high bytes of the registers are also printed. + Some newer drives (Samsung) only write to this log. -If the detection executes "smartctl -i", don't execute it again afterwards. - - -RAID: -http://sourceforge.net/apps/trac/smartmontools/wiki/Supported_RAID-Controllers - -Areca Linux: - Call as: smartctl -i -d areca,[1-24] /dev/sg0 - Detection: - Check if /proc/scsi/sg/device_strs contains "Areca RAID controller". - If not, there's no Areca controller present. - Check /proc/scsi/sg/devices, the line # with type 3 is the sg* number. - The "host" field value is the N value in /sys, see below. - Check /sys/bus/scsi/devices/hostN/scsi_host/hostN/host_fw_hd_channels, set - its contents as the number of ports. If not present, use 24. - Probe each port for a valid drive: If the output contains "Device Read Identity Failed", - then there is no drive on that port (or Areca has an old firmware, nothing we can - do there). - Notification: If /sys/bus/scsi/devices/hostN/scsi_host/hostN/host_fw_version - is older than "V1.46 2009-01-06", notify the user (maybe its better to grep - the smartctl output for that on port 0?). - - -3ware Linux: - Call as: smartctl -i -d 3ware,[0-127] /dev/twa[0-15] (or twe[0-15]) - Use twe* for [678]xxx series, and twa* for 9xxx series. - Note: twe* devices are limited to [0-15] ports (not sure about this). - Note: /dev/tw* devices may not exist, they are created by smartctl on the first run. - Note: for twe*, /dev/sda may also exist (to be used with -d 3ware,N), we should - somehow detect and ignore them. - Note: when specifying non-existent port, either a "Device Read Identity Failed" - error, or a "blank" info may be returned. - Detection: - Grep /proc/devices for "twa" or "twe" (e.g. "251 twa"). Use this for /dev/tw* part. - Grep /proc/scsi/scsi for AMCC (3ware, LSI too?), use number of matched lines N - for /dev/tw*[0, N-1]. - - -3ware FreeBSD: - Call as: smartctl -i -d 3ware,[0-127] /dev/twa0 (or twe0) - - -3ware Windows: - For 9xxx only. - Call as: smartctl -i sd[a-z],N - N is port, a-z is logical drive (unit) provided by controller. - Call as: smarctl -i tw_cli/cx/py - This runs tw_cli tool and parses the output; controller x, port y. - tw_cli is needed for 64-bit systems, as well as older controllers. - In tw_cli mode only limited information-gathering is supported. - - -LSI MegaRAID (SCSI/SAS), Linux: - Call as: smartctl -i -d megaraid,[0-?] /dev/sda - - -HighPoint RocketRAID ((S)ATA) Linux: - Call as: smartctl -i -d hpt,[1-8]/[1-8] /dev/sda - Call as: smartctl -i -d hpt,[1-8]/[1-8]/[1-15] /dev/sda - Note: /dev/sda should be derived from this controller. - Smartctl docs specify smaller limits, but the code says these are the ones. - - -HighPoint RocketRAID ((S)ATA) FreeBSD: - Call as: smartctl -i -d hpt,[1-8]/[1-8] /dev/hptrr - Call as: smartctl -i -d hpt,[1-8]/[1-8]/[1-15] /dev/hptrr - Note: /dev/hptrr should be derived from this controller. - Smartctl docs specify smaller limits, but the code says these are the ones. - - -CCISS (HP (Compaq) Smart Array Controller) Linux: - Call as: smartctl -a -d cciss,[0-15] /dev/cciss/c0d0 - c0d0 is the controller (d0 seems to be a logical - drive, but it doesn't seem to matter?). - An unofficial patch adds support for [0-127] ports. - - -CCISS (HP (Compaq) Smart Array Controller) FreeBSD: - Seems to be the same as Linux (uses the same driver?). - + '-l xselftest' -> Extended Self Test Log: An multi-sector and LBA48 + capable version of '-l selftest'. Output will be similar, except more + entries can exists and the LBA values can be somewhat longer. + "smartctl -l this_wont_exist" gives the list of supported logs - this + is needed to detect xerror / xselftest support in smartctl. '-l sataphy' -> SATA Phy event counters: Non-SMART feature, useful to detect SATA cabling problems. -'-l xerror' -> Extended Comprehensive Error log: An multi-sector and -LBA48 capable version of '-l error'. Output is similar, except more -entries can exists and the high bytes of the registers are also printed. -Some newer drives (Samsung) only write to this log. -'-l scttemp' -> SCT Temperature history table. See below. +SCT Temperatures + -l scttemp prints temperature and history. + -t scttempint,N[,p] (N - count, p - preserve across reset or not). + This configures temperature logging interval (1 min by default) and clears the history. + -l scterc[,...] to get/set the SCT Error Recovery Control time limit (5.40 and newer). -'-l xselftest' -> Extended Self Test Log: An multi-sector and LBA48 -capable version of '-l selftest'. Output will be similar, except more -entries can exists and the LBA values can be somewhat longer. - -"smartctl -l this_wont_exist" gives the list of supported logs - this - is needed to detect xerror / xselftest support in smartctl. - - -Careful with GPL (xerror...) stuff until the jmicron situation clears up. Add detection for Interix (i586-pc-interix3), maybe with debian? -Re-check long double printing - win32 libc doesn't support it, a cast -to double is needed. - The underlying problem is that in msvc, long double is the same size - as double, so printf() has mingw-incompatible presentation of long double. - -Support USB flash disks in CVS smartctl versions: - Try smartctl -i /dev/sdc; - If it returns "Smartctl: please specify device type with the -d option.", - try "-d scsi", which should at least give us the name. - -Maybe make it easier to specify "-d" (with a dropdown?) - Not sure, "-l aaa /tmp" doesn't list all types. @@ -237,15 +315,9 @@ Maybe make it easier to specify "-d" (with a dropdown?) + smartctl exited with error - look it up in error map. -SCT Temperatures - -l scttemp prints temperature and history. - -t scttempint,N[,p] (N - count, p - preserve across reset or not). - This configures temperature logging interval (1 min by default) and clears the history. +Tests: - Ability to detect a testing drive on boot, show its info with testing tab. - Run one-time Immediate Offline test (-t offline). Offline tests only update Attributes, and if errors are found they will appear in SMART error log. Self-test logs are unaffected. diff --git a/gsmartcontrol/configure.ac b/gsmartcontrol/configure.ac index 3fcf6df..4f9c56e 100644 --- a/gsmartcontrol/configure.ac +++ b/gsmartcontrol/configure.ac @@ -1,5 +1,5 @@ -AC_INIT([GSmartControl],[0.8.5],[],[gsmartcontrol]) +AC_INIT([GSmartControl],[0.8.6],[],[gsmartcontrol]) AC_CONFIG_SRCDIR([configure.ac]) AC_CONFIG_HEADERS([config.h]) diff --git a/gsmartcontrol/contrib/cron-based_noadmin/cron_gather_smart.sh b/gsmartcontrol/contrib/cron-based_noadmin/cron_gather_smart.sh index 7ef795a..9a6e7de 100755 --- a/gsmartcontrol/contrib/cron-based_noadmin/cron_gather_smart.sh +++ b/gsmartcontrol/contrib/cron-based_noadmin/cron_gather_smart.sh @@ -1,9 +1,9 @@ #!/bin/bash ############################################################################ # Copyright: -# (C) 2008 - 2009 Alex Butcher -# (C) 2008 - 2009 Alexander Shaduri -# License: See LICENSE_whatever.txt file +# (C) 2008 - 2010 Alex Butcher +# (C) 2008 - 2010 Alexander Shaduri +# License: See LICENSE_unlicense.txt file ############################################################################ device="$1"; diff --git a/gsmartcontrol/contrib/cron-based_noadmin/smartctl_subst.sh b/gsmartcontrol/contrib/cron-based_noadmin/smartctl_subst.sh index 365a721..c9cfa0c 100755 --- a/gsmartcontrol/contrib/cron-based_noadmin/smartctl_subst.sh +++ b/gsmartcontrol/contrib/cron-based_noadmin/smartctl_subst.sh @@ -1,9 +1,9 @@ #!/bin/bash ############################################################################ # Copyright: -# (C) 2008 - 2009 Alex Butcher -# (C) 2008 - 2009 Alexander Shaduri -# License: See LICENSE_whatever.txt file +# (C) 2008 - 2010 Alex Butcher +# (C) 2008 - 2010 Alexander Shaduri +# License: See LICENSE_unlicense.txt file ############################################################################ if [ "$1" = "-V" ]; then diff --git a/gsmartcontrol/data/gsmartcontrol-root.in b/gsmartcontrol/data/gsmartcontrol-root.in index 322680e..5aa7d10 100644 --- a/gsmartcontrol/data/gsmartcontrol-root.in +++ b/gsmartcontrol/data/gsmartcontrol-root.in @@ -1,11 +1,12 @@ #!/bin/bash ############################################################################ # Copyright: -# (C) 2008 Alexander Shaduri +# (C) 2008 - 2010 Alexander Shaduri # License: See LICENSE_zlib.txt file ############################################################################ # Run gsmartcontrol with root, asking for root password first. +# export GSMARTCONTROL_SU to override a su command (e.g. "kdesu -c"). EXEC_BIN="@prefix@/bin/gsmartcontrol"; prog_name="gsmartcontrol" @@ -44,8 +45,8 @@ fi # They're basically the same, only the order is different. # sux requires xterm to ask for the password. # xdg-su is basically like this script, except worse :) -gnome_sus="gnomesu gksu kdesu xdg-su sux"; -kde_sus="kdesu gnomesu gksu xdg-su sux"; +gnome_sus="gnomesu gksu kdesu beesu xdg-su sux"; +kde_sus="kdesu gnomesu gksu beesu xdg-su sux"; other_sus="$gnome_sus"; @@ -60,18 +61,20 @@ elif [ "$DESKTOP" = "other" ]; then candidates="$other_sus"; fi -for subin in $candidates; do - which $subin &>/dev/null - if [ $? -eq 0 ]; then - found_su="$subin"; - break; - fi -done +if [ "$GSMARTCONTROL_SU" = "" ]; then + for subin in $candidates; do + which $subin &>/dev/null + if [ $? -eq 0 ]; then + found_su="$subin"; + break; + fi + done -if [ "$found_su" = "" ]; then - xmessage "Error launching ${prog_name}: No suitable su mechanism found. -Try installing kdesu, gnomesu, gksu or sux first."; - exit 1; + if [ "$found_su" = "" ]; then + xmessage "Error launching ${prog_name}: No suitable su mechanism found. +Try installing kdesu, gnomesu, gksu, beesu or sux first."; + exit 1; + fi fi @@ -82,7 +85,10 @@ fi # Add these directories _before_ existing PATH, so that the user is not # tricked into running it from some other path (we're running as root with # the user's env after all). -export PATH="/usr/sbin:/usr/local/sbin:$PATH" +# Note that beesu won't show a GUI login box if /usr/sbin is before /usr/bin, +# so add it first as well. +EXTRA_PATHS="/usr/bin:/usr/sbin:/usr/local/sbin"; +export PATH="$EXTRA_PATHS:$PATH" # echo $found_su; @@ -90,20 +96,29 @@ export PATH="/usr/sbin:/usr/local/sbin:$PATH" # Examples: # gnomesu -c 'gsmartcontrol --no-scan' # kdesu -c 'gsmartcontrol --no-scan' +# beesu -P 'gsmartcontrol --no-scan' # xterm -e sux -c 'gsmartcontrol --no-scan' # sux asks for password in a terminal -full_cmd="" -if [ "$found_su" = "sux" ]; then - full_cmd="xterm -e sux -c '$EXEC_BIN $@'" +full_cmd=""; + +if [ "$GSMARTCONTROL_SU" != "" ]; then + full_cmd="$GSMARTCONTROL_SU '$EXEC_BIN $@'"; + +elif [ "$found_su" = "sux" ]; then + full_cmd="xterm -e sux -c '$EXEC_BIN $@'"; elif [ "$found_su" = "gksu" ]; then - full_cmd="$found_su '$EXEC_BIN $@'" + full_cmd="$found_su '$EXEC_BIN $@'"; + +elif [ "$found_su" = "beesu" ]; then + full_cmd="$found_su -P '$EXEC_BIN $@'"; else # gnomesu, kdesu, xdg-su - full_cmd="$found_su -c '$EXEC_BIN $@'" + full_cmd="$found_su -c '$EXEC_BIN $@'"; fi +#echo $full_cmd eval $full_cmd diff --git a/gsmartcontrol/debian.dist/control b/gsmartcontrol/debian.dist/control index fdc66f3..6e7029c 100644 --- a/gsmartcontrol/debian.dist/control +++ b/gsmartcontrol/debian.dist/control @@ -12,7 +12,7 @@ Standards-Version: 3.7.3 Package: gsmartcontrol Architecture: any #Depends: ${shlibs:Depends}, ${misc:Depends}, smartmontools -Depends: ${shlibs:Depends}, smartmontools +Depends: ${shlibs:Depends}, smartmontools, menu Description: Hard disk drive health inspection tool GSmartControl is a graphical user interface for smartctl (from smartmontools package), which is a tool for querying and controlling SMART diff --git a/gsmartcontrol/debian.dist/copyright b/gsmartcontrol/debian.dist/copyright index 8944533..5383028 100644 --- a/gsmartcontrol/debian.dist/copyright +++ b/gsmartcontrol/debian.dist/copyright @@ -5,7 +5,7 @@ It was downloaded from Copyright: - Copyright (C) 2008 - 2009 Alexander Shaduri + Copyright (C) 2008 - 2010 Alexander Shaduri License: @@ -27,6 +27,6 @@ On Debian systems, the complete text of the GNU General Public Licenses can be found in `/usr/share/common-licenses/GPL-2' and `/usr/share/common-licenses/GPL-3'. -The Debian packaging is (C) 2008 - 2009 Alexander Shaduri and +The Debian packaging is (C) 2008 - 2010 Alexander Shaduri and is licensed under the GPLv2 and GPLv3, see above. diff --git a/gsmartcontrol/file2csource.sh b/gsmartcontrol/file2csource.sh index 420c0fb..439a9b9 100755 --- a/gsmartcontrol/file2csource.sh +++ b/gsmartcontrol/file2csource.sh @@ -1,7 +1,7 @@ #!/bin/bash ############################################################################ # Copyright: -# (C) 2008 - 2009 Alexander Shaduri +# (C) 2008 - 2010 Alexander Shaduri # License: See LICENSE_zlib.txt file ############################################################################ diff --git a/gsmartcontrol/gsmartcontrol.kdev4 b/gsmartcontrol/gsmartcontrol.kdev4 new file mode 100644 index 0000000..c4ab009 --- /dev/null +++ b/gsmartcontrol/gsmartcontrol.kdev4 @@ -0,0 +1,3 @@ +[Project] +Manager=KDevCustomBuildSystem +Name=gsmartcontrol diff --git a/gsmartcontrol/gsmartcontrol.spec.in b/gsmartcontrol/gsmartcontrol.spec.in index 7ba684b..8891432 100644 --- a/gsmartcontrol/gsmartcontrol.spec.in +++ b/gsmartcontrol/gsmartcontrol.spec.in @@ -62,6 +62,12 @@ Requires: smartmontools, pcre, gtkmm24 >= 2.6.0, libglademm24 >= 2.4.0 BuildRequires: gcc-c++, pcre-devel, gtkmm24-devel >= 2.6.0, libglademm24-devel >= 2.4.0 %endif +# Fedora doesn't include gnomesu or anything similar except beesu (since 11), so force it. +# usermode-gtk is for consolehelper-gtk (optional for beesu, needed for GUI auth). +%if 0%{?fedora_version} >= 11 +Requires: beesu, usermode-gtk +%endif + %endif @@ -145,6 +151,9 @@ rm -rf %buildroot %changelog +* Fri Dec 10 2010 Alexander Shaduri +- Fixes for Fedora 14. + * Fri Nov 14 2008 Alexander Shaduri - Updated .spec file to incorporate changes from the official Mandriva package. diff --git a/gsmartcontrol/src/applib/app_gtkmm_features.h b/gsmartcontrol/src/applib/app_gtkmm_features.h index 30f677a..7163a54 100644 --- a/gsmartcontrol/src/applib/app_gtkmm_features.h +++ b/gsmartcontrol/src/applib/app_gtkmm_features.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/app_gtkmm_utils.cpp b/gsmartcontrol/src/applib/app_gtkmm_utils.cpp index 6919c5c..1a10c03 100644 --- a/gsmartcontrol/src/applib/app_gtkmm_utils.cpp +++ b/gsmartcontrol/src/applib/app_gtkmm_utils.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/app_gtkmm_utils.h b/gsmartcontrol/src/applib/app_gtkmm_utils.h index 9c17b94..1e7d86f 100644 --- a/gsmartcontrol/src/applib/app_gtkmm_utils.h +++ b/gsmartcontrol/src/applib/app_gtkmm_utils.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/app_pango_utils.cpp b/gsmartcontrol/src/applib/app_pango_utils.cpp index 93db20e..2cb5693 100644 --- a/gsmartcontrol/src/applib/app_pango_utils.cpp +++ b/gsmartcontrol/src/applib/app_pango_utils.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/app_pango_utils.h b/gsmartcontrol/src/applib/app_pango_utils.h index 6ecbeab..4780ec9 100644 --- a/gsmartcontrol/src/applib/app_pango_utils.h +++ b/gsmartcontrol/src/applib/app_pango_utils.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/app_pcrecpp.h b/gsmartcontrol/src/applib/app_pcrecpp.h index faa497f..355b560 100644 --- a/gsmartcontrol/src/applib/app_pcrecpp.h +++ b/gsmartcontrol/src/applib/app_pcrecpp.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/app_ui_res_utils.h b/gsmartcontrol/src/applib/app_ui_res_utils.h index 27873cd..36d0b67 100644 --- a/gsmartcontrol/src/applib/app_ui_res_utils.h +++ b/gsmartcontrol/src/applib/app_ui_res_utils.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/app_ui_res_utils_test.cpp b/gsmartcontrol/src/applib/app_ui_res_utils_test.cpp index b34d134..1234bf9 100644 --- a/gsmartcontrol/src/applib/app_ui_res_utils_test.cpp +++ b/gsmartcontrol/src/applib/app_ui_res_utils_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/app_ui_res_utils_test_data.cpp b/gsmartcontrol/src/applib/app_ui_res_utils_test_data.cpp index fd5b73d..3579b58 100644 --- a/gsmartcontrol/src/applib/app_ui_res_utils_test_data.cpp +++ b/gsmartcontrol/src/applib/app_ui_res_utils_test_data.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/cmdex.cpp b/gsmartcontrol/src/applib/cmdex.cpp index 16b307c..9bcf613 100644 --- a/gsmartcontrol/src/applib/cmdex.cpp +++ b/gsmartcontrol/src/applib/cmdex.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/cmdex.h b/gsmartcontrol/src/applib/cmdex.h index f8e3804..94d2619 100644 --- a/gsmartcontrol/src/applib/cmdex.h +++ b/gsmartcontrol/src/applib/cmdex.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/cmdex_sync.cpp b/gsmartcontrol/src/applib/cmdex_sync.cpp index f949465..7f6b0a3 100644 --- a/gsmartcontrol/src/applib/cmdex_sync.cpp +++ b/gsmartcontrol/src/applib/cmdex_sync.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/cmdex_sync.h b/gsmartcontrol/src/applib/cmdex_sync.h index fd9c9e7..c3ac880 100644 --- a/gsmartcontrol/src/applib/cmdex_sync.h +++ b/gsmartcontrol/src/applib/cmdex_sync.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/cmdex_sync_gui.cpp b/gsmartcontrol/src/applib/cmdex_sync_gui.cpp index bf49782..2989eb5 100644 --- a/gsmartcontrol/src/applib/cmdex_sync_gui.cpp +++ b/gsmartcontrol/src/applib/cmdex_sync_gui.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/cmdex_sync_gui.h b/gsmartcontrol/src/applib/cmdex_sync_gui.h index 348cf05..02045d2 100644 --- a/gsmartcontrol/src/applib/cmdex_sync_gui.h +++ b/gsmartcontrol/src/applib/cmdex_sync_gui.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/gui_utils.cpp b/gsmartcontrol/src/applib/gui_utils.cpp index 6c29482..a024a5b 100644 --- a/gsmartcontrol/src/applib/gui_utils.cpp +++ b/gsmartcontrol/src/applib/gui_utils.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/gui_utils.h b/gsmartcontrol/src/applib/gui_utils.h index 44c4fbe..7ffb8cf 100644 --- a/gsmartcontrol/src/applib/gui_utils.h +++ b/gsmartcontrol/src/applib/gui_utils.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/selftest.cpp b/gsmartcontrol/src/applib/selftest.cpp index 99790b7..cc08edc 100644 --- a/gsmartcontrol/src/applib/selftest.cpp +++ b/gsmartcontrol/src/applib/selftest.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/selftest.h b/gsmartcontrol/src/applib/selftest.h index a85f27a..a4fe57a 100644 --- a/gsmartcontrol/src/applib/selftest.h +++ b/gsmartcontrol/src/applib/selftest.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/smartctl_executor.cpp b/gsmartcontrol/src/applib/smartctl_executor.cpp index 52402cb..7b2c3cd 100644 --- a/gsmartcontrol/src/applib/smartctl_executor.cpp +++ b/gsmartcontrol/src/applib/smartctl_executor.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/smartctl_executor.h b/gsmartcontrol/src/applib/smartctl_executor.h index 1e8fa9a..8b994f9 100644 --- a/gsmartcontrol/src/applib/smartctl_executor.h +++ b/gsmartcontrol/src/applib/smartctl_executor.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/smartctl_executor_gui.h b/gsmartcontrol/src/applib/smartctl_executor_gui.h index 954639c..42e1139 100644 --- a/gsmartcontrol/src/applib/smartctl_executor_gui.h +++ b/gsmartcontrol/src/applib/smartctl_executor_gui.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/smartctl_executor_test.cpp b/gsmartcontrol/src/applib/smartctl_executor_test.cpp index 74a0dd0..0d754cf 100644 --- a/gsmartcontrol/src/applib/smartctl_executor_test.cpp +++ b/gsmartcontrol/src/applib/smartctl_executor_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/smartctl_parser.cpp b/gsmartcontrol/src/applib/smartctl_parser.cpp index 88ee12f..9b7fbb5 100644 --- a/gsmartcontrol/src/applib/smartctl_parser.cpp +++ b/gsmartcontrol/src/applib/smartctl_parser.cpp @@ -1,11 +1,12 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ -#include // setlocale, localeconv +#include // localeconv +#include "hz/locale_tools.h" // ScopedCLocale, locale_c_get(). #include "hz/cstdint.h" // uint64_t #include "hz/string_algo.h" // string_* #include "hz/string_num.h" // string_is_numeric, number_to_string @@ -285,20 +286,15 @@ std::string SmartctlParser::parse_byte_size(const std::string& str, uint64_t& by // if current locale is C, then probably we didn't change it at application // startup, so set it now (temporarily). Otherwise, just use the current locale's // thousands separator. + { + std::string old_locale = hz::locale_c_get(); + hz::ScopedCLocale loc("", old_locale == "C"); // set system locale if the current one is C - std::string old_locale = std::setlocale(LC_ALL, NULL); - bool locale_is_c = (old_locale == "C"); - if (locale_is_c) { - std::setlocale(LC_ALL, ""); // set system locale - } - struct lconv* lc = std::localeconv(); - if (lc && lc->thousands_sep && *(lc->thousands_sep)) { - to_replace.push_back(lc->thousands_sep); - } - - if (locale_is_c) { - std::setlocale(LC_ALL, "C"); // restore it - } + struct lconv* lc = std::localeconv(); + if (lc && lc->thousands_sep && *(lc->thousands_sep)) { + to_replace.push_back(lc->thousands_sep); + } + } // the locale is restored here #endif to_replace.push_back("bytes"); diff --git a/gsmartcontrol/src/applib/smartctl_parser.h b/gsmartcontrol/src/applib/smartctl_parser.h index 4d1942f..30dff7a 100644 --- a/gsmartcontrol/src/applib/smartctl_parser.h +++ b/gsmartcontrol/src/applib/smartctl_parser.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/smartctl_parser_test.cpp b/gsmartcontrol/src/applib/smartctl_parser_test.cpp index 45d87a8..84c9c19 100644 --- a/gsmartcontrol/src/applib/smartctl_parser_test.cpp +++ b/gsmartcontrol/src/applib/smartctl_parser_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/spawn_test.cpp b/gsmartcontrol/src/applib/spawn_test.cpp index a55c293..8f105f9 100644 --- a/gsmartcontrol/src/applib/spawn_test.cpp +++ b/gsmartcontrol/src/applib/spawn_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_detector.cpp b/gsmartcontrol/src/applib/storage_detector.cpp index 384a9ff..720ac0f 100644 --- a/gsmartcontrol/src/applib/storage_detector.cpp +++ b/gsmartcontrol/src/applib/storage_detector.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ @@ -225,6 +225,7 @@ namespace { blacklist.push_back("/part[0-9]+$/"); // devfs had them blacklist.push_back("/p[0-9]+$/"); // partitions are usually marked this way blacklist.push_back("/md[0-9]*$/"); // linux software raid + blacklist.push_back("/dm-[0-9]*$/"); // linux device mapper for (unsigned int i = 0; i < lines.size(); ++i) { @@ -265,6 +266,7 @@ namespace { // smartctl accepts various variants, the most straight being pdN, // (or /dev/pdN, /dev/ being optional) where N comes from // "\\.\PhysicalDriveN" (winnt only). + // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx inline std::string detect_drives_win32(std::vector& devices) { diff --git a/gsmartcontrol/src/applib/storage_detector.h b/gsmartcontrol/src/applib/storage_detector.h index b24e45e..cac3222 100644 --- a/gsmartcontrol/src/applib/storage_detector.h +++ b/gsmartcontrol/src/applib/storage_detector.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_detector_test.cpp b/gsmartcontrol/src/applib/storage_detector_test.cpp index b66738b..0f539cf 100644 --- a/gsmartcontrol/src/applib/storage_detector_test.cpp +++ b/gsmartcontrol/src/applib/storage_detector_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_device.cpp b/gsmartcontrol/src/applib/storage_device.cpp index 774a6cd..8d3151f 100644 --- a/gsmartcontrol/src/applib/storage_device.cpp +++ b/gsmartcontrol/src/applib/storage_device.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_device.h b/gsmartcontrol/src/applib/storage_device.h index 399bc35..df184a8 100644 --- a/gsmartcontrol/src/applib/storage_device.h +++ b/gsmartcontrol/src/applib/storage_device.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_property.cpp b/gsmartcontrol/src/applib/storage_property.cpp index d927577..d0b2f64 100644 --- a/gsmartcontrol/src/applib/storage_property.cpp +++ b/gsmartcontrol/src/applib/storage_property.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_property.h b/gsmartcontrol/src/applib/storage_property.h index 8e8223d..ad1cd08 100644 --- a/gsmartcontrol/src/applib/storage_property.h +++ b/gsmartcontrol/src/applib/storage_property.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_property_colors.h b/gsmartcontrol/src/applib/storage_property_colors.h index bee1f46..f9e334c 100644 --- a/gsmartcontrol/src/applib/storage_property_colors.h +++ b/gsmartcontrol/src/applib/storage_property_colors.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_property_descr.cpp b/gsmartcontrol/src/applib/storage_property_descr.cpp index fca419a..629e0b4 100644 --- a/gsmartcontrol/src/applib/storage_property_descr.cpp +++ b/gsmartcontrol/src/applib/storage_property_descr.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_property_descr.h b/gsmartcontrol/src/applib/storage_property_descr.h index 43ade6d..1ec7fac 100644 --- a/gsmartcontrol/src/applib/storage_property_descr.h +++ b/gsmartcontrol/src/applib/storage_property_descr.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/storage_settings.h b/gsmartcontrol/src/applib/storage_settings.h index 1ed0d85..58f5a93 100644 --- a/gsmartcontrol/src/applib/storage_settings.h +++ b/gsmartcontrol/src/applib/storage_settings.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/applib/wrapping_label.h b/gsmartcontrol/src/applib/wrapping_label.h index ffae559..1a6a9f0 100644 --- a/gsmartcontrol/src/applib/wrapping_label.h +++ b/gsmartcontrol/src/applib/wrapping_label.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/global_macros.h b/gsmartcontrol/src/global_macros.h index 8137009..f3c68cb 100644 --- a/gsmartcontrol/src/global_macros.h +++ b/gsmartcontrol/src/global_macros.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_about_dialog.cpp b/gsmartcontrol/src/gsc_about_dialog.cpp index 234eba3..2b3a633 100644 --- a/gsmartcontrol/src/gsc_about_dialog.cpp +++ b/gsmartcontrol/src/gsc_about_dialog.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ @@ -47,7 +47,7 @@ GscAboutDialog::GscAboutDialog(BaseObjectType* gtkcobj, const app_ui_res_ref_t& set_license(LicenseTextResData().get_string()); // spammers go away - set_copyright("Copyright (C) 2008 - 2009 Alexander Shaduri " ""); + set_copyright("Copyright (C) 2008 - 2010 Alexander Shaduri " ""); std::string authors_str = AuthorsTextResData().get_string(); diff --git a/gsmartcontrol/src/gsc_about_dialog.h b/gsmartcontrol/src/gsc_about_dialog.h index ae00748..0db2d4d 100644 --- a/gsmartcontrol/src/gsc_about_dialog.h +++ b/gsmartcontrol/src/gsc_about_dialog.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_executor_error_dialog.cpp b/gsmartcontrol/src/gsc_executor_error_dialog.cpp index b112357..40dd950 100644 --- a/gsmartcontrol/src/gsc_executor_error_dialog.cpp +++ b/gsmartcontrol/src/gsc_executor_error_dialog.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_executor_error_dialog.h b/gsmartcontrol/src/gsc_executor_error_dialog.h index 5e5a3f9..5d7d369 100644 --- a/gsmartcontrol/src/gsc_executor_error_dialog.h +++ b/gsmartcontrol/src/gsc_executor_error_dialog.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_executor_log_window.cpp b/gsmartcontrol/src/gsc_executor_log_window.cpp index a72ab7b..d73cb7f 100644 --- a/gsmartcontrol/src/gsc_executor_log_window.cpp +++ b/gsmartcontrol/src/gsc_executor_log_window.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ @@ -236,7 +236,7 @@ void GscExecutorLogWindow::on_window_save_all_button_clicked() exss << "\n------------------------- LIBDEBUG LOG -------------------------\n\n\n"; exss << app_get_debug_buffer_str() << "\n\n\n"; - exss << "\n\n\n------------------------- EXECTION LOG -------------------------\n\n\n"; + exss << "\n\n\n------------------------- EXECUTION LOG -------------------------\n\n\n"; for (std::size_t i = 0; i < entries.size(); ++i) { exss << "\n\n\n------------------------- EXECUTED COMMAND " << (i+1) << " -------------------------\n\n"; diff --git a/gsmartcontrol/src/gsc_executor_log_window.h b/gsmartcontrol/src/gsc_executor_log_window.h index eeda8e3..2afd0cc 100644 --- a/gsmartcontrol/src/gsc_executor_log_window.h +++ b/gsmartcontrol/src/gsc_executor_log_window.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_help_window.cpp b/gsmartcontrol/src/gsc_help_window.cpp index c659adb..b465945 100644 --- a/gsmartcontrol/src/gsc_help_window.cpp +++ b/gsmartcontrol/src/gsc_help_window.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_help_window.h b/gsmartcontrol/src/gsc_help_window.h index b328c08..953a34f 100644 --- a/gsmartcontrol/src/gsc_help_window.h +++ b/gsmartcontrol/src/gsc_help_window.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_info_window.cpp b/gsmartcontrol/src/gsc_info_window.cpp index 661aad9..e7aaf27 100644 --- a/gsmartcontrol/src/gsc_info_window.cpp +++ b/gsmartcontrol/src/gsc_info_window.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ @@ -308,22 +308,22 @@ void GscInfoWindow::fill_ui_with_info(bool scan, bool clear_ui, bool clear_tests if (hide_tabs) { bool smart_enabled = (drive->get_smart_status() == StorageDevice::status_enabled); - Gtk::Widget* note_label = 0; + Gtk::Widget* note_page_box = 0; - if ((note_label = lookup_widget("capabilities_tab_vbox")) != 0) { - if (smart_enabled) { note_label->show(); } else { note_label->hide(); } + if ((note_page_box = lookup_widget("capabilities_tab_vbox")) != 0) { + if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } - if ((note_label = lookup_widget("attributes_tab_vbox")) != 0) { - if (smart_enabled) { note_label->show(); } else { note_label->hide(); } + if ((note_page_box = lookup_widget("attributes_tab_vbox")) != 0) { + if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } - if ((note_label = lookup_widget("error_log_tab_vbox")) != 0) { - if (smart_enabled) { note_label->show(); } else { note_label->hide(); } + if ((note_page_box = lookup_widget("error_log_tab_vbox")) != 0) { + if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } - if ((note_label = lookup_widget("selftest_log_tab_vbox")) != 0) { - if (smart_enabled) { note_label->show(); } else { note_label->hide(); } + if ((note_page_box = lookup_widget("selftest_log_tab_vbox")) != 0) { + if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } - if ((note_label = lookup_widget("test_tab_vbox")) != 0) { - if (smart_enabled) { note_label->show(); } else { note_label->hide(); } + if ((note_page_box = lookup_widget("test_tab_vbox")) != 0) { + if (smart_enabled) { note_page_box->show(); } else { note_page_box->hide(); } } } diff --git a/gsmartcontrol/src/gsc_info_window.h b/gsmartcontrol/src/gsc_info_window.h index 27c03ed..c97fbcc 100644 --- a/gsmartcontrol/src/gsc_info_window.h +++ b/gsmartcontrol/src/gsc_info_window.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_init.cpp b/gsmartcontrol/src/gsc_init.cpp index 3988466..e3c91e9 100644 --- a/gsmartcontrol/src/gsc_init.cpp +++ b/gsmartcontrol/src/gsc_init.cpp @@ -1,12 +1,10 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ #include -#include // std::locale -#include // std::setlocale // #include // _configthreadlocale (win32) #include // std::runtime_error #include // std::printf @@ -29,6 +27,7 @@ #include "hz/data_file.h" // data_file_add_search_directory #include "hz/fs_tools.h" // get_user_config_dir() #include "hz/fs_path.h" // FsPath +#include "hz/locale_tools.h" // locale_c* #include "hz/string_algo.h" // string_join() #include "hz/win32_tools.h" // win32_get_registry_value_string() @@ -194,7 +193,7 @@ struct CmdArgs { arg_add_device(NULL) { } - gboolean arg_locale; // if false, disable locale + gboolean arg_locale; // if false, disable using system locale gboolean arg_version; // if true, show version and exit gboolean arg_scan; // if false, don't scan the system for drives on startup gboolean arg_hide_tabs; // if true, hide additional info tabs when smart is disabled. false may help debugging. @@ -208,7 +207,7 @@ inline bool parse_cmdline_args(CmdArgs& args, int& argc, char**& argv) { static const GOptionEntry arg_entries[] = { - { "no-locale", 'l', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &(args.arg_locale), "Disable locale", NULL }, + { "no-locale", 'l', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &(args.arg_locale), "Don't use system locale", NULL }, { "version", 'V', 0, G_OPTION_ARG_NONE, &(args.arg_version), "Display version information", NULL }, { "no-scan", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &(args.arg_scan), "Don't scan devices on startup", NULL }, { "no-hide-tabs", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &(args.arg_hide_tabs), "Don't hide non-identity tabs when SMART is disabled. Useful for debugging.", NULL }, @@ -219,11 +218,16 @@ inline bool parse_cmdline_args(CmdArgs& args, int& argc, char**& argv) GError* error = 0; GOptionContext* context = g_option_context_new("- A GTK+ GUI for smartmontools"); + + // our options g_option_context_add_main_entries(context, arg_entries, NULL); - g_option_context_add_group(context, gtk_get_option_group(false)); // gtk options + + // gtk options + g_option_context_add_group(context, gtk_get_option_group(false)); // libdebug options; this will also automatically apply them g_option_context_add_group(context, debug_get_option_group()); + g_option_context_parse(context, &argc, &argv, &error); g_option_context_free(context); if (error) @@ -241,7 +245,7 @@ inline void app_print_version_info() std::string warningtext = std::string("\nWarning: GSmartControl"); warningtext += " comes with ABSOLUTELY NO WARRANTY.\n"; warningtext += "See LICENSE_gsmartcontrol.txt file for details.\n"; - warningtext += "\nCopyright (C) 2008 - 2009 Alexander Shaduri \n\n"; + warningtext += "\nCopyright (C) 2008 - 2010 Alexander Shaduri \n\n"; std::fprintf(stdout, "%s%s", versiontext.c_str(), warningtext.c_str()); } @@ -250,44 +254,32 @@ inline void app_print_version_info() bool app_init_and_loop(int& argc, char**& argv) { - - // glib needs locale initialized for command line args. It will be reset by Gtk::Main later. - - // set C and C++ locales to system LANG. - try { - // This may throw on freebsd and osx with - // "locale::facet::_S_create_c_locale name not valid", so make it non-fatal. - std::locale::global(std::locale("")); // C++ - } - catch (const std::runtime_error& e) { - // nothing. we can't print anything here, so just ignore it. - // newer gtkmm will print a warning if it cannot set a C++ locale, - // so it will be an indication. - } - - std::setlocale(LC_ALL, ""); // C - - // initialize GThread (for mutexes, etc... to work). Must be called before any other glib function. // Glib::thread_init(); - // parse command line args + // Glib needs the C locale set to system locale for command line args. + // We will reset it later if needed. + hz::locale_c_set(""); // set the current locale to system locale + + // Parse command line args. + // Due to gtk_get_option_group()/g_option_context_parse() calls, this + // will also initialize GTK and set the C locale to system locale (as well + // as do some locale-specific gdk initialization). CmdArgs args; if (! parse_cmdline_args(args, argc, argv)) { return true; } - // Note: parsing gtk option context is initializes gtk, so - // gtk_disable_setlocale() won't work here. + // If locale setting is explicitly disabled, revert to the original classic C locale. + // Note that changing GTK locale after it's inited isn't really supported by GTK, + // but we have no other choice - glib needs system locale when parsing the + // arguments, and gtk is inited while the parsing is performed. if (!args.arg_locale) { - // set classic locale. otherwise we're already in user locale. - try { - std::locale::global(std::locale::classic()); // C++ - } - catch (const std::runtime_error& e) { - } - std::setlocale(LC_ALL, "C"); + hz::locale_c_set("C"); + } else { + // change the C++ locale to match the C one. + hz::locale_cpp_set(""); // this may fail on some systems } @@ -346,25 +338,8 @@ bool app_init_and_loop(int& argc, char**& argv) app_init_config(); - debug_out_info("app", "Current C locale: " << std::setlocale(LC_ALL, NULL) << "\n"); - debug_out_info("app", "Current C++ locale: " << std::locale::locale().name() << "\n"); - - - // Initialize GTK+ -// Gtk::Main m(argc, argv, args.arg_locale); - Gtk::Main m(argc, argv); - - -#ifdef _WIN32 - // Now that all program-specific locale setup has been performed, - // make sure the future locale changes affect only current thread. - // Not available in mingw, so disable for now. -// _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); - -#endif - - - // Redirect all GTK+/Glib and related messages to libdebug + // Redirect all GTK+/Glib and related messages to libdebug. + // Do this before GTK+ init, to capture its possible warnings as well. static const char* const gtkdomains[] = { // no atk or cairo, they don't log. libgnomevfs may be loaded by gtk file chooser. "GLib", "GModule", "GLib-GObject", "GLib-GRegex", "GLib-GIO", "GThread", @@ -377,6 +352,35 @@ bool app_init_and_loop(int& argc, char**& argv) } + // Save the locale + std::locale final_loc_cpp = hz::locale_cpp_get(); + + // Initialize GTK+ (it's already initialized by command-line parser, + // so this doesn't do much). + // Newer gtkmm will try to set the C++ locale here. + // Note: passing false (as use_locale) as the third parameter here + // will generate a gtk_disable_setlocale() warning (due to gtk being + // already initialized), so manually save / restore the C++ locale + // (C locale won't be touched). + // Nothing is affected in gtkmm itself by C++ locale, so it's ok to do it. + Gtk::Main m(argc, argv); + + // Restore the locale + hz::locale_cpp_set(final_loc_cpp); + + + debug_out_info("app", "Current C locale: " << hz::locale_c_get() << "\n"); + debug_out_info("app", "Current C++ locale: " << hz::locale_cpp_get() << "\n"); + + +#ifdef _WIN32 + // Now that all program-specific locale setup has been performed, + // make sure the future locale changes affect only current thread. + // Not available in mingw, so disable for now. +// _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); +#endif + + // This shows up in About dialog gtk. Glib::set_application_name("GSmartControl"); // should be localized diff --git a/gsmartcontrol/src/gsc_init.h b/gsmartcontrol/src/gsc_init.h index 63d70f3..088b402 100644 --- a/gsmartcontrol/src/gsc_init.h +++ b/gsmartcontrol/src/gsc_init.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_main.cpp b/gsmartcontrol/src/gsc_main.cpp index b45ea23..b2c5fdc 100644 --- a/gsmartcontrol/src/gsc_main.cpp +++ b/gsmartcontrol/src/gsc_main.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_main_window.cpp b/gsmartcontrol/src/gsc_main_window.cpp index 42b942b..bf4e116 100644 --- a/gsmartcontrol/src/gsc_main_window.cpp +++ b/gsmartcontrol/src/gsc_main_window.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_main_window.h b/gsmartcontrol/src/gsc_main_window.h index f8e0298..b1dc284 100644 --- a/gsmartcontrol/src/gsc_main_window.h +++ b/gsmartcontrol/src/gsc_main_window.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_main_window_iconview.h b/gsmartcontrol/src/gsc_main_window_iconview.h index 9323534..76eac8c 100644 --- a/gsmartcontrol/src/gsc_main_window_iconview.h +++ b/gsmartcontrol/src/gsc_main_window_iconview.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_preferences_window.cpp b/gsmartcontrol/src/gsc_preferences_window.cpp index 4c83d31..fd70089 100644 --- a/gsmartcontrol/src/gsc_preferences_window.cpp +++ b/gsmartcontrol/src/gsc_preferences_window.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_preferences_window.h b/gsmartcontrol/src/gsc_preferences_window.h index fb11cd4..c9aa740 100644 --- a/gsmartcontrol/src/gsc_preferences_window.h +++ b/gsmartcontrol/src/gsc_preferences_window.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_settings.h b/gsmartcontrol/src/gsc_settings.h index d52120a..c7e8bcb 100644 --- a/gsmartcontrol/src/gsc_settings.h +++ b/gsmartcontrol/src/gsc_settings.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/gsc_text_window.h b/gsmartcontrol/src/gsc_text_window.h index 7baf3cc..c0b1104 100644 --- a/gsmartcontrol/src/gsc_text_window.h +++ b/gsmartcontrol/src/gsc_text_window.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_gsmartcontrol.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/Makefile.am b/gsmartcontrol/src/hz/Makefile.am index 6efca4a..1ed3150 100644 --- a/gsmartcontrol/src/hz/Makefile.am +++ b/gsmartcontrol/src/hz/Makefile.am @@ -9,7 +9,7 @@ noinst_HEADERS = any_convert.h any_type.h any_type_holder.h ascii.h \ instance_manager.h intrusive_ptr.h intrusive_scoped_lock.h launch_url.h local_algo.h \ locale_tools.h noncopyable.h optional_value.h portable_snprintf.h process_signal.h \ ptr_container.h res_data.h scoped_array.h scoped_ptr.h shared_ptr.h static_assert.h stream_cast.h \ - string_algo.h string_format.h string_num.h string_sprintf.h string_wcmatch.h sync.h \ + string_algo.h string_format.h string_num.h string_sprintf.h string_sprintf_macros.h string_wcmatch.h sync.h \ sync_lock_ptr.h sync_multilock.h sync_part_get_policy.h sync_policy_boost.h \ sync_policy_glib.h sync_policy_glibmm.h sync_policy_poco.h sync_policy_pthread.h \ sync_policy_win32.h system_specific.h tls.h tls_policy_boost.h tls_policy_glib.h \ diff --git a/gsmartcontrol/src/hz/any_convert.h b/gsmartcontrol/src/hz/any_convert.h index c0b38e7..c58f277 100644 --- a/gsmartcontrol/src/hz/any_convert.h +++ b/gsmartcontrol/src/hz/any_convert.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/any_type.h b/gsmartcontrol/src/hz/any_type.h index 6fbe827..250b911 100644 --- a/gsmartcontrol/src/hz/any_type.h +++ b/gsmartcontrol/src/hz/any_type.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2000 - 2009 Kevlin Henney - (C) 2008 - 2009 Alexander Shaduri + (C) 2000 - 2010 Kevlin Henney + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_boost_1_0.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/any_type_holder.h b/gsmartcontrol/src/hz/any_type_holder.h index 8a51681..769c2e8 100644 --- a/gsmartcontrol/src/hz/any_type_holder.h +++ b/gsmartcontrol/src/hz/any_type_holder.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2000 - 2009 Kevlin Henney - (C) 2008 - 2009 Alexander Shaduri + (C) 2000 - 2010 Kevlin Henney + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_boost_1_0.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/any_type_test.cpp b/gsmartcontrol/src/hz/any_type_test.cpp index fb0908d..316bb93 100644 --- a/gsmartcontrol/src/hz/any_type_test.cpp +++ b/gsmartcontrol/src/hz/any_type_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/ascii.h b/gsmartcontrol/src/hz/ascii.h index 2ee69fb..a8e3b6b 100644 --- a/gsmartcontrol/src/hz/ascii.h +++ b/gsmartcontrol/src/hz/ascii.h @@ -2,7 +2,7 @@ Copyright: (C) 1992, 1993 The Regents of the University of California License: See LICENSE_bsd-ucb.txt file - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/bad_cast_exception.h b/gsmartcontrol/src/hz/bad_cast_exception.h index 94b7fb8..70c6a0b 100644 --- a/gsmartcontrol/src/hz/bad_cast_exception.h +++ b/gsmartcontrol/src/hz/bad_cast_exception.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/bin2ascii_encoder.h b/gsmartcontrol/src/hz/bin2ascii_encoder.h index 6d93865..1becd8a 100644 --- a/gsmartcontrol/src/hz/bin2ascii_encoder.h +++ b/gsmartcontrol/src/hz/bin2ascii_encoder.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/bin2ascii_encoder_test.cpp b/gsmartcontrol/src/hz/bin2ascii_encoder_test.cpp index 3e04a2b..0187c56 100644 --- a/gsmartcontrol/src/hz/bin2ascii_encoder_test.cpp +++ b/gsmartcontrol/src/hz/bin2ascii_encoder_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/common_types.h b/gsmartcontrol/src/hz/common_types.h index 0080bea..abc6621 100644 --- a/gsmartcontrol/src/hz/common_types.h +++ b/gsmartcontrol/src/hz/common_types.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/cstdint.h b/gsmartcontrol/src/hz/cstdint.h index 4e1d5cc..f5807d4 100644 --- a/gsmartcontrol/src/hz/cstdint.h +++ b/gsmartcontrol/src/hz/cstdint.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2009 Alexander Shaduri + (C) 2009 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/data_file.h b/gsmartcontrol/src/hz/data_file.h index 0669de3..b339f33 100644 --- a/gsmartcontrol/src/hz/data_file.h +++ b/gsmartcontrol/src/hz/data_file.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2004 - 2009 Alexander Shaduri + (C) 2004 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/debug.h b/gsmartcontrol/src/hz/debug.h index a473200..7c3cf03 100644 --- a/gsmartcontrol/src/hz/debug.h +++ b/gsmartcontrol/src/hz/debug.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/down_cast.h b/gsmartcontrol/src/hz/down_cast.h index 41f16f4..e95106d 100644 --- a/gsmartcontrol/src/hz/down_cast.h +++ b/gsmartcontrol/src/hz/down_cast.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Alexander Shaduri + (C) 2003 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/down_cast_test.cpp b/gsmartcontrol/src/hz/down_cast_test.cpp index 703d3d9..1b0e263 100644 --- a/gsmartcontrol/src/hz/down_cast_test.cpp +++ b/gsmartcontrol/src/hz/down_cast_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/env_tools.h b/gsmartcontrol/src/hz/env_tools.h index 669b5ed..c2165b2 100644 --- a/gsmartcontrol/src/hz/env_tools.h +++ b/gsmartcontrol/src/hz/env_tools.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/errno_string.h b/gsmartcontrol/src/hz/errno_string.h index 5a8abbe..aeeb816 100644 --- a/gsmartcontrol/src/hz/errno_string.h +++ b/gsmartcontrol/src/hz/errno_string.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/errno_string_test.cpp b/gsmartcontrol/src/hz/errno_string_test.cpp index 66ade66..1f1ccac 100644 --- a/gsmartcontrol/src/hz/errno_string_test.cpp +++ b/gsmartcontrol/src/hz/errno_string_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/error.h b/gsmartcontrol/src/hz/error.h index 5864e66..4942680 100644 --- a/gsmartcontrol/src/hz/error.h +++ b/gsmartcontrol/src/hz/error.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/error_holder.h b/gsmartcontrol/src/hz/error_holder.h index bd5ef61..89fbe3d 100644 --- a/gsmartcontrol/src/hz/error_holder.h +++ b/gsmartcontrol/src/hz/error_holder.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/exceptions.h b/gsmartcontrol/src/hz/exceptions.h index d811f38..a62c354 100644 --- a/gsmartcontrol/src/hz/exceptions.h +++ b/gsmartcontrol/src/hz/exceptions.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/format_unit.h b/gsmartcontrol/src/hz/format_unit.h index 2f51abe..ac48063 100644 --- a/gsmartcontrol/src/hz/format_unit.h +++ b/gsmartcontrol/src/hz/format_unit.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Alexander Shaduri + (C) 2003 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ @@ -14,8 +14,8 @@ #include // for time.h, std::strftime, std::time, std::localtime, ... #include "cstdint.h" -#include "locale_tools.h" // ScopedLocale -#include "string_num.h" // number_to_string +#include "locale_tools.h" // hz::ScopedCLocale +#include "string_num.h" // hz::number_to_string #include "i18n.h" // HZ_NC_, HZ_C_ @@ -199,7 +199,7 @@ inline std::string format_date(const std::string& format, const struct std::tm* int iterations = 0; // strftime is locale-dependent. unless use_locale is true, we switch to classic locale. - const ScopedLocale classic(!use_locale); + const ScopedCLocale classic(!use_locale); do { char* buf = new char[buf_size]; diff --git a/gsmartcontrol/src/hz/format_unit_test.cpp b/gsmartcontrol/src/hz/format_unit_test.cpp index 07e36a2..8590380 100644 --- a/gsmartcontrol/src/hz/format_unit_test.cpp +++ b/gsmartcontrol/src/hz/format_unit_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_common.h b/gsmartcontrol/src/hz/fs_common.h index b46fbbb..c061c1c 100644 --- a/gsmartcontrol/src/hz/fs_common.h +++ b/gsmartcontrol/src/hz/fs_common.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_dir.h b/gsmartcontrol/src/hz/fs_dir.h index c81f24a..a7419ad 100644 --- a/gsmartcontrol/src/hz/fs_dir.h +++ b/gsmartcontrol/src/hz/fs_dir.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_dir_platform.h b/gsmartcontrol/src/hz/fs_dir_platform.h index eb24c60..65bc07c 100644 --- a/gsmartcontrol/src/hz/fs_dir_platform.h +++ b/gsmartcontrol/src/hz/fs_dir_platform.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2009 Alexander Shaduri + (C) 2009 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_dir_test.cpp b/gsmartcontrol/src/hz/fs_dir_test.cpp index f08ea39..daca1bc 100644 --- a/gsmartcontrol/src/hz/fs_dir_test.cpp +++ b/gsmartcontrol/src/hz/fs_dir_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_error_holder.h b/gsmartcontrol/src/hz/fs_error_holder.h index 675cea0..097fac3 100644 --- a/gsmartcontrol/src/hz/fs_error_holder.h +++ b/gsmartcontrol/src/hz/fs_error_holder.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_file.h b/gsmartcontrol/src/hz/fs_file.h index 5c17a6c..1e751f0 100644 --- a/gsmartcontrol/src/hz/fs_file.h +++ b/gsmartcontrol/src/hz/fs_file.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_file_test.cpp b/gsmartcontrol/src/hz/fs_file_test.cpp index ca6f6c6..2c1e9a8 100644 --- a/gsmartcontrol/src/hz/fs_file_test.cpp +++ b/gsmartcontrol/src/hz/fs_file_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_fstream.h b/gsmartcontrol/src/hz/fs_fstream.h index 927a884..4400a2e 100644 --- a/gsmartcontrol/src/hz/fs_fstream.h +++ b/gsmartcontrol/src/hz/fs_fstream.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2009 Alexander Shaduri + (C) 2009 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_path.h b/gsmartcontrol/src/hz/fs_path.h index 5fc8e5c..a189303 100644 --- a/gsmartcontrol/src/hz/fs_path.h +++ b/gsmartcontrol/src/hz/fs_path.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_path_test.cpp b/gsmartcontrol/src/hz/fs_path_test.cpp index ce233db..e765756 100644 --- a/gsmartcontrol/src/hz/fs_path_test.cpp +++ b/gsmartcontrol/src/hz/fs_path_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_path_utils.h b/gsmartcontrol/src/hz/fs_path_utils.h index 674a699..738d3d8 100644 --- a/gsmartcontrol/src/hz/fs_path_utils.h +++ b/gsmartcontrol/src/hz/fs_path_utils.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/fs_tools.h b/gsmartcontrol/src/hz/fs_tools.h index 3be4e67..0345eb3 100644 --- a/gsmartcontrol/src/hz/fs_tools.h +++ b/gsmartcontrol/src/hz/fs_tools.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/function.h b/gsmartcontrol/src/hz/function.h index 33c56bb..4e19a82 100644 --- a/gsmartcontrol/src/hz/function.h +++ b/gsmartcontrol/src/hz/function.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2007 - 2009 Thiago Rosso Adams - (C) 2009 Alexander Shaduri + (C) 2007 - 2010 Thiago Rosso Adams + (C) 2009 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/function_impl.h b/gsmartcontrol/src/hz/function_impl.h index 4751851..b3b19a1 100644 --- a/gsmartcontrol/src/hz/function_impl.h +++ b/gsmartcontrol/src/hz/function_impl.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2007 - 2009 Thiago Rosso Adams - (C) 2009 Alexander Shaduri + (C) 2007 - 2010 Thiago Rosso Adams + (C) 2009 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/hz_config.h b/gsmartcontrol/src/hz/hz_config.h index 380728b..1ec9361 100644 --- a/gsmartcontrol/src/hz/hz_config.h +++ b/gsmartcontrol/src/hz/hz_config.h @@ -1,28 +1,47 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ +/// \file +/// \author Alexander Shaduri +/// \ingroup hz +/// \weakgroup hz +/// @{ #ifndef HZ_HZ_CONFIG_H #define HZ_HZ_CONFIG_H -// This file is included from all hz headers. +/** +\file +\brief This file is included from all hz headers. -// You should include this file if you're using any of: -// macros from autoconf-generated config.h -// macros from global_macros.h -// This file has effect only if "-include" compiler option doesn't work. +You should include this file if you're using any of: +- macros from autoconf-generated config.h +- macros from global_macros.h +This file has effect only if "-include" compiler option doesn't work. -// The purpose of this file is to provide some common compatibility -// solutions for the whole hz, while not depending on "-include" -// compiler switches or pasting autoconf's config.h code in all files. +The purpose of this file is to provide some common compatibility +solutions for the whole hz, while not depending on "-include" +compiler switches or pasting autoconf's config.h code in all files. +*/ + + +/** +\namespace hz +HZ library, system-level abstraction and general utilities. +*/ + + +/** +\namespace hz::internal +HZ library internal implementation helpers. +*/ // Define HZ_NO_COMPILER_AUTOINCLUDE=1 from a compiler option to enable // auto-inclusion of global_macros.h. - #ifndef APP_GLOBAL_MACROS_INCLUDED // defined in global_macros.h #if defined HZ_NO_COMPILER_AUTOINCLUDE && HZ_NO_COMPILER_AUTOINCLUDE // define manually @@ -194,6 +213,29 @@ +// Whether the *printf() family (but not _*printf() or *printf_s()) behaves +// according to ISO specification in terms of 0-termination, return value +// and accepting %lld, %llu and %Lf format specifiers. + +// Note: If using mingw runtime >= 3.15 and __USE_MINGW_ANSI_STDIO, +// mingw supports both C99/POSIX and msvcrt format specifiers. +// This includes proper printing of long double (%Lf), %lld and %llu, etc... +// This does _not_ affect _snprintf() and similar non-standard functions. + +#ifndef HAVE_ISO_STDIO + // On win32, assume only with mingw with ansi/iso extensions. + // for others, assume it's always there. + #if !defined _WIN32 || ( defined __GNUC__ && \ + (!defined __NO_ISOCEXT || defined __USE_MINGW_ANSI_STDIO) ) + #define HAVE_ISO_STDIO 1 + #else + #define HAVE_ISO_STDIO 0 + #endif +#endif + + + + #ifndef HAVE__SNPRINTF // Win32's _snprintf (broken 0-termination) #if defined _WIN32 #define HAVE__SNPRINTF 1 @@ -202,30 +244,25 @@ #endif #endif -#ifndef HAVE_PROPER_SNPRINTF // snprintf() with correct 0-termination - // On win32, assume only with mingw with ansi/iso extensions. - // for others, assume it's always there. - // Mingw used to use _snprintf()-like termination for snprintf(), so - // we use HAVE_PROPER_SNPRINTF instead of HAVE_SNPRINTF. - #if !defined _WIN32 || ( defined __GNUC__ && \ - (!defined __NO_ISOCEXT || (defined __USE_MINGW_ANSI_STDIO)) ) - #define HAVE_PROPER_SNPRINTF 1 + +#ifndef HAVE__VSNPRINTF // Win32's _vsnprintf (broken 0-termination) + #if defined _WIN32 + #define HAVE__SNPRINTF 1 #else - #define HAVE_PROPER_SNPRINTF 0 + #define HAVE__SNPRINTF 0 #endif #endif - - -#ifndef HAVE_VASPRINTF // vasprintf() (GNU/glibc extension) - #if defined _GNU_SOURCE - #define HAVE_VASPRINTF 1 +#ifndef HAVE_SNPRINTF_S // snprintf_s (msvc 2005/8.0) + #if defined _MSC_VER && _MSC_VER >= 1400 + #define HAVE_SNPRINTF_S 1 #else - #define HAVE_VASPRINTF 0 + #define HAVE_SNPRINTF_S 0 #endif #endif + #ifndef HAVE_VSNPRINTF_S // vsnprintf_s (msvc 2005/8.0) #if defined _MSC_VER && _MSC_VER >= 1400 #define HAVE_VSNPRINTF_S 1 @@ -234,16 +271,12 @@ #endif #endif -#ifndef HAVE_PROPER_VSNPRINTF // vsnprintf() with correct 0-termination - // On win32, assume only with mingw with ansi/iso extensions. - // for others, assume it's always there. - // MSVC has _vsnprintf()-like termination for vsnprintf(), so - // we use HAVE_PROPER_VSNPRINTF instead of HAVE_VSNPRINTF. - #if !defined _WIN32 || ( defined __GNUC__ && \ - (!defined __NO_ISOCEXT || (defined __USE_MINGW_ANSI_STDIO)) ) - #define HAVE_PROPER_VSNPRINTF 1 + +#ifndef HAVE_VASPRINTF // vasprintf() (GNU/glibc extension) + #if defined _GNU_SOURCE + #define HAVE_VASPRINTF 1 #else - #define HAVE_PROPER_VSNPRINTF 0 + #define HAVE_VASPRINTF 0 #endif #endif @@ -281,3 +314,5 @@ #endif + +/// @} diff --git a/gsmartcontrol/src/hz/i18n.h b/gsmartcontrol/src/hz/i18n.h index d20dc6f..73e3a50 100644 --- a/gsmartcontrol/src/hz/i18n.h +++ b/gsmartcontrol/src/hz/i18n.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/instance_manager.h b/gsmartcontrol/src/hz/instance_manager.h index fc2542e..a3d05e1 100644 --- a/gsmartcontrol/src/hz/instance_manager.h +++ b/gsmartcontrol/src/hz/instance_manager.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/intrusive_ptr.h b/gsmartcontrol/src/hz/intrusive_ptr.h index 6698d55..ea9ee74 100644 --- a/gsmartcontrol/src/hz/intrusive_ptr.h +++ b/gsmartcontrol/src/hz/intrusive_ptr.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2001 - 2009 Peter Dimov - (C) 2008 - 2009 Alexander Shaduri + (C) 2001 - 2010 Peter Dimov + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_boost_1_0.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/intrusive_scoped_lock.h b/gsmartcontrol/src/hz/intrusive_scoped_lock.h index 6a0c336..4814039 100644 --- a/gsmartcontrol/src/hz/intrusive_scoped_lock.h +++ b/gsmartcontrol/src/hz/intrusive_scoped_lock.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/launch_url.h b/gsmartcontrol/src/hz/launch_url.h index 8b27b5b..e1dfcb2 100644 --- a/gsmartcontrol/src/hz/launch_url.h +++ b/gsmartcontrol/src/hz/launch_url.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/local_algo.h b/gsmartcontrol/src/hz/local_algo.h index ad4e73b..2155720 100644 --- a/gsmartcontrol/src/hz/local_algo.h +++ b/gsmartcontrol/src/hz/local_algo.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/locale_tools.h b/gsmartcontrol/src/hz/locale_tools.h index b6efe9e..4a802c3 100644 --- a/gsmartcontrol/src/hz/locale_tools.h +++ b/gsmartcontrol/src/hz/locale_tools.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ @@ -25,48 +25,291 @@ namespace hz { // However, for glibc, libstdc++ uses the "uselocale" extension, which // sets locale on per-thread basis. -// FIXME: catch std::runtime_error exceptions. no-exceptions mode? -// FIXME: Set C locale too. -// FIXME: add bad() status in case the change failed. -// Temporarily change to indicated locale. +// Set the C standard library locale +inline bool locale_c_set(const std::string& loc, std::string& old_locale) +{ + // even though undocumented, glibc returns 0 when the locale string is invalid. + char* old = std::setlocale(LC_ALL, loc.c_str()); + if (old) { + old_locale = old; + return true; + } + return false; +} -class ScopedLocale { + +// Set the C standard library locale +inline bool locale_c_set(const std::string& loc) +{ + return std::setlocale(LC_ALL, loc.c_str()); // returns 0 if invalid +} + + +// Get current C standard library locale +inline std::string locale_c_get() +{ + return std::setlocale(LC_ALL, 0); +} + + + + +// Set the C++ standard library locale (may also set the C locale) +inline bool locale_cpp_set(const std::locale& loc, std::locale& old_locale) +{ +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + try { +#endif + // under FreeBSD (at least 6.x) and OSX, this may throw on anything + // except "C" and "POSIX" with message: + // "locale::facet::_S_create_c_locale name not valid". + // Blame inadequate implementations. + old_locale = std::locale::global(loc); +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + } + catch (const std::runtime_error& e) { + return false; + } +#endif + return true; +} + + +// Set the C++ standard library locale (may also set the C locale) +inline bool locale_cpp_set(const std::locale& loc, std::string& old_locale) +{ +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + try { +#endif + old_locale = std::locale::global(loc).name(); // not sure, but name() may not be unique (?) +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + } + catch (const std::runtime_error& e) { + return false; + } +#endif + return true; +} + + +// Set the C++ standard library locale (may also set the C locale) +inline bool locale_cpp_set(const std::locale& loc) +{ +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + try { +#endif + std::locale::global(loc); +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + } + catch (const std::runtime_error& e) { + return false; + } +#endif + return true; +} + + + + +// Set the C++ standard library locale (may also set the C locale) +inline bool locale_cpp_set(const std::string& loc, std::locale& old_locale) +{ +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + try { +#endif + old_locale = std::locale::global(std::locale(loc.c_str())); +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + } + catch (const std::runtime_error& e) { + return false; + } +#endif + return true; +} + + +// Set the C++ standard library locale (may also set the C locale) +inline bool locale_cpp_set(const std::string& loc, std::string& old_locale) +{ +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + try { +#endif + old_locale = std::locale::global(std::locale(loc.c_str())).name(); // not sure, but name() may not be unique (?) +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + } + catch (const std::runtime_error& e) { + return false; + } +#endif + return true; +} + + +// Set the C++ standard library locale (may also set the C locale) +inline bool locale_cpp_set(const std::string& loc) +{ +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + try { +#endif + std::locale::global(std::locale(loc.c_str())); +#if !(defined DISABLE_EXCEPTIONS && DISABLE_EXCEPTIONS) + } + catch (const std::runtime_error& e) { + return false; + } +#endif + return true; +} + + + +// Get current C++ standard library locale +template +ReturnType locale_cpp_get(); // no definition - use the specializations below. + + +template<> inline +std::string locale_cpp_get() +{ + return std::locale().name(); // may return "*" if it's not representable as a string +} + + +template<> inline +std::locale locale_cpp_get() +{ + return std::locale(); +} + + + + + + + +// Temporarily change the C standard library locale +class ScopedCLocale { public: // change to classic locale (aka "C") - ScopedLocale(bool do_change = true) : do_change_(do_change) + ScopedCLocale(bool do_change = true) : do_change_(do_change), bad_(false) { - if (do_change_) - old_locale_ = std::locale::global(std::locale::classic()); + if (do_change_) { // avoid unnecessary const char* -> string conversion overhead + bad_ = locale_c_set("C", old_locale_); + } } // change to user-specified locale loc. - ScopedLocale(const std::string& loc, bool do_change = true) : do_change_(do_change) + ScopedCLocale(const std::string& loc, bool do_change = true) : do_change_(do_change), bad_(false) { - if (do_change_) - old_locale_ = std::locale::global(std::locale(loc.c_str())); + if (do_change_) { + bad_ = locale_c_set(loc, old_locale_); + } } // change back - ~ScopedLocale() + ~ScopedCLocale() { - if (do_change_) - std::locale::global(old_locale_); + this->restore(); } // get old locale - std::locale get_old() const + std::string old() const { return old_locale_; } + // Returns true if locale setting was unsuccessful + bool bad() const + { + return bad_; + } + + // Restore the locale. Invoked by destructor. + bool restore() + { + if (do_change_ && !bad_) { + bad_ = locale_c_set(old_locale_); + do_change_ = false; // avoid invoking again + } + return bad_; + } + private: - std::locale old_locale_; + std::string old_locale_; bool do_change_; + bool bad_; + +}; + + + +// Temporarily change the C++ standard library locale (may also set the C locale) +class ScopedCppLocale { + + public: + + // change to classic locale (aka "C") + ScopedCppLocale(bool do_change = true) : do_change_(do_change), bad_(false) + { + if (do_change) { + bad_ = locale_cpp_set(std::locale::classic(), old_locale_); + } + } + + // change to user-specified locale loc. + ScopedCppLocale(const std::string& loc, bool do_change = true) : do_change_(do_change), bad_(false) + { + if (do_change_) { + bad_ = locale_cpp_set(loc, old_locale_); + } + } + + // change to user-specified locale loc. + ScopedCppLocale(const std::locale& loc, bool do_change = true) : do_change_(do_change), bad_(false) + { + if (do_change_) { + bad_ = locale_cpp_set(loc, old_locale_); + } + } + + // change back + ~ScopedCppLocale() + { + this->restore(); + } + + // get old locale + std::locale old() const + { + return old_locale_; + } + + // Returns true if locale setting was unsuccessful + bool bad() const + { + return bad_; + } + + // Restore the locale. Invoked by destructor. + bool restore() + { + if (do_change_ && !bad_) { + bad_ = locale_cpp_set(old_locale_); + do_change_ = false; // avoid invoking again + } + return bad_; + } + + + private: + std::locale old_locale_; + bool do_change_; + bool bad_; }; diff --git a/gsmartcontrol/src/hz/noncopyable.h b/gsmartcontrol/src/hz/noncopyable.h index 2be8717..32af25b 100644 --- a/gsmartcontrol/src/hz/noncopyable.h +++ b/gsmartcontrol/src/hz/noncopyable.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 1999 - 2009 Beman Dawes - (C) 2008 - 2009 Alexander Shaduri + (C) 1999 - 2010 Beman Dawes + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_boost_1_0.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/optional_value.h b/gsmartcontrol/src/hz/optional_value.h index 815b3d9..98df676 100644 --- a/gsmartcontrol/src/hz/optional_value.h +++ b/gsmartcontrol/src/hz/optional_value.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/portable_snprintf.h b/gsmartcontrol/src/hz/portable_snprintf.h index 8b628c6..f52dd3f 100644 --- a/gsmartcontrol/src/hz/portable_snprintf.h +++ b/gsmartcontrol/src/hz/portable_snprintf.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2009 Alexander Shaduri + (C) 2009 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ @@ -20,6 +20,17 @@ namespace hz { // Note: There are macros, so they are not namespaced. +// portable_snprintf() and portable_vsnprintf() are snprintf() and vsnprintf() +// wrappers that always behave according to ISO standard in terms of 0-termination. + +// There types are non-portable (the first one is MS variant, the second one is standard): +// %I64d, %lld (long long int), +// %I64u, %llu (unsigned long long int), +// %f, %Lf (long double; needs casting to double under non-ANSI mingw if using %f). + +// HAVE_PORTABLE_SNPRINTF_MS - portable_snprintf() accepts I64d, I64u. +// HAVE_PORTABLE_SNPRINTF_ISO - portable_snprintf() accepts lld, llu, Lf. + // Usage: void portable_snprintf(char *str, size_t size, const char *format, ...); @@ -30,6 +41,26 @@ namespace hz { #define portable_snprintf(buf, buf_size, ...) \ (void)g_snprintf((buf), (buf_size), __VA_ARGS__) + #define HAVE_PORTABLE_SNPRINTF_MS 0 + #define HAVE_PORTABLE_SNPRINTF_ISO 1 + +#elif defined HAVE_ISO_STDIO && HAVE_ISO_STDIO + // mingw/ISO, all non-windows platforms. + #include // for cstdio + #include // snprintf + + #define portable_snprintf(buf, buf_size, ...) \ + (void)snprintf((buf), (buf_size), __VA_ARGS__) + + // mingw/ISO has both the MS and ISO specifiers + #if defined _WIN32 && defined __GNUC__ + #define HAVE_PORTABLE_SNPRINTF_MS 1 + #else + #define HAVE_PORTABLE_SNPRINTF_MS 0 + #endif + + #define HAVE_PORTABLE_SNPRINTF_ISO 1 + #elif defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS #include // for cstdio #include // _snprintf_s @@ -38,8 +69,10 @@ namespace hz { #define portable_snprintf(buf, buf_size, ...) \ (void)_snprintf_s((buf), (buf_size), _TRUNCATE, __VA_ARGS__) -#elif !(defined HAVE_PROPER_SNPRINTF && HAVE_PROPER_SNPRINTF) \ - && (defined HAVE__SNPRINTF && HAVE__SNPRINTF) + #define HAVE_PORTABLE_SNPRINTF_MS 1 + #define HAVE_PORTABLE_SNPRINTF_ISO 0 + +#elif defined HAVE__SNPRINTF && HAVE__SNPRINTF // Prefer snprintf() to _snprintf() if we're sure it's good. // Note that old versions of mingw used to define snprintf() as _snprintf(), // which is not proper. @@ -52,14 +85,12 @@ namespace hz { #define portable_snprintf(buf, buf_size, ...) \ (void)((_snprintf((buf), (buf_size) - 1, __VA_ARGS__) == ((buf_size) - 1)) && ((buf)[(buf_size)-1] = '\0')) + #define HAVE_PORTABLE_SNPRINTF_MS 0 + #define HAVE_PORTABLE_SNPRINTF_ISO 1 + #else - #include // for cstdio - #include // snprintf + #error Cannot find suitable snprintf() implementation for portable_snprintf() - // essentially (defined HAVE_PROPER_SNPRINTF && HAVE_PROPER_SNPRINTF), but - // since we have no other option, let's require snprintf(). - #define portable_snprintf(buf, buf_size, ...) \ - (void)snprintf((buf), (buf_size), __VA_ARGS__) #endif @@ -74,6 +105,26 @@ namespace hz { #define portable_vsnprintf(buf, buf_size, format, ap) \ (void)g_vsnprintf((buf), (buf_size), (format), (ap)) + #define HAVE_PORTABLE_VSNPRINTF_MS 0 + #define HAVE_PORTABLE_VSNPRINTF_ISO 1 + +#elif defined HAVE_ISO_STDIO && HAVE_ISO_STDIO + #include // for cstdio + #include // vsnprintf (mingw, posix(?)) + #include // for cstdarg + #include // vsnprintf (gnu) + + #define portable_vsnprintf(buf, buf_size, format, ap) \ + (void)vsnprintf((buf), (buf_size), (format), (ap)) + + // mingw/ISO has both the MS and ISO specifiers + #if defined _WIN32 && defined __GNUC__ + #define HAVE_PORTABLE_VSNPRINTF_MS 1 + #else + #define HAVE_PORTABLE_VSNPRINTF_MS 0 + #endif + #define HAVE_PORTABLE_VSNPRINTF_ISO 1 + #elif defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS #include // for cstdio #include // _vsnprintf_s @@ -82,8 +133,10 @@ namespace hz { #define portable_vsnprintf(buf, buf_size, format, ap) \ (void)vsnprintf_s((buf), (buf_size), _TRUNCATE, (format), (ap)) -#elif !(defined HAVE_PROPER_VSNPRINTF && HAVE_PROPER_VSNPRINTF) \ - && (defined HAVE__VSNPRINTF && HAVE__VSNPRINTF) + #define HAVE_PORTABLE_VSNPRINTF_MS 1 + #define HAVE_PORTABLE_VSNPRINTF_ISO 0 + +#elif defined HAVE__VSNPRINTF && HAVE__VSNPRINTF // prefer snprintf() to _snprintf() if we're sure it's good. #include // for cstdio @@ -93,24 +146,18 @@ namespace hz { // _vsnprintf() writes at most buf_size-1 bytes. the buffer should be zeroed out // beforehand. - // Note that MS's vsnprintf (which is the same as their _vsnprintf()) - // doesn't always write 0, that's why we have HAVE_PROPER_VSNPRINTF - // instead of HAVE_VSNPRINTF. + // Note that MS's vsnprintf() (which is the same as their _vsnprintf()) + // doesn't always write 0. // We use _vsnprintf() instead of vsnprintf() to avoid using the proper vsnprintf() // by chance (_vsnprintf() is always broken, vsnprintf() may not be). #define portable_vsnprintf(buf, buf_size, format, ap) \ (void)((_vsnprintf((buf), (buf_size) - 1, (format), (ap)) == ((buf_size) - 1)) && ((buf)[(buf_size)-1] = '\0')) -#else - #include // for cstdio - #include // vsnprintf (mingw, posix(?)) - #include // for cstdarg - #include // vsnprintf (gnu) + #define HAVE_PORTABLE_VSNPRINTF_MS 1 + #define HAVE_PORTABLE_VSNPRINTF_ISO 0 - // essentially (defined HAVE_PROPER_VSNPRINTF && HAVE_PROPER_VSNPRINTF), but - // since we have no other option, let's require vsnprintf(). - #define portable_vsnprintf(buf, buf_size, format, ap) \ - (void)vsnprintf((buf), (buf_size), (format), (ap)) +#else + #error Cannot find suitable vsnprintf() implementation for portable_vsnprintf() #endif diff --git a/gsmartcontrol/src/hz/process_signal.h b/gsmartcontrol/src/hz/process_signal.h index edec88d..d12a8ec 100644 --- a/gsmartcontrol/src/hz/process_signal.h +++ b/gsmartcontrol/src/hz/process_signal.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/ptr_container.h b/gsmartcontrol/src/hz/ptr_container.h index 0cbf54b..6218eef 100644 --- a/gsmartcontrol/src/hz/ptr_container.h +++ b/gsmartcontrol/src/hz/ptr_container.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/res_data.h b/gsmartcontrol/src/hz/res_data.h index e4ff547..21af157 100644 --- a/gsmartcontrol/src/hz/res_data.h +++ b/gsmartcontrol/src/hz/res_data.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/scoped_array.h b/gsmartcontrol/src/hz/scoped_array.h index eb31b57..e0e9bd9 100644 --- a/gsmartcontrol/src/hz/scoped_array.h +++ b/gsmartcontrol/src/hz/scoped_array.h @@ -1,8 +1,8 @@ /************************************************************************** Copyright: - (C) 1998 - 2009 Greg Colvin and Beman Dawes - (C) 2001 - 2009 Peter Dimov - (C) 2008 - 2009 Alexander Shaduri + (C) 1998 - 2010 Greg Colvin and Beman Dawes + (C) 2001 - 2010 Peter Dimov + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_boost_1_0.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/scoped_ptr.h b/gsmartcontrol/src/hz/scoped_ptr.h index f3a532c..dd15356 100644 --- a/gsmartcontrol/src/hz/scoped_ptr.h +++ b/gsmartcontrol/src/hz/scoped_ptr.h @@ -1,8 +1,8 @@ /************************************************************************** Copyright: - (C) 1998 - 2009 Greg Colvin and Beman Dawes - (C) 2001 - 2009 Peter Dimov - (C) 2008 - 2009 Alexander Shaduri + (C) 1998 - 2010 Greg Colvin and Beman Dawes + (C) 2001 - 2010 Peter Dimov + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_boost_1_0.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/shared_ptr.h b/gsmartcontrol/src/hz/shared_ptr.h index 09b45ff..5f732af 100644 --- a/gsmartcontrol/src/hz/shared_ptr.h +++ b/gsmartcontrol/src/hz/shared_ptr.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2007 - 2009 Thiago Rosso Adams - (C) 2009 Alexander Shaduri + (C) 2007 - 2010 Thiago Rosso Adams + (C) 2009 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/static_assert.h b/gsmartcontrol/src/hz/static_assert.h index 4abe73f..b5c9b0d 100644 --- a/gsmartcontrol/src/hz/static_assert.h +++ b/gsmartcontrol/src/hz/static_assert.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Alexander Shaduri + (C) 2003 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/stream_cast.h b/gsmartcontrol/src/hz/stream_cast.h index f7ed4d9..8f330fd 100644 --- a/gsmartcontrol/src/hz/stream_cast.h +++ b/gsmartcontrol/src/hz/stream_cast.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2000 - 2009 Kevlin Henney - (C) 2008 - 2009 Alexander Shaduri + (C) 2000 - 2010 Kevlin Henney + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_boost_1_0.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/string_algo.h b/gsmartcontrol/src/hz/string_algo.h index 744b5c9..aa4aed9 100644 --- a/gsmartcontrol/src/hz/string_algo.h +++ b/gsmartcontrol/src/hz/string_algo.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/string_algo_test.cpp b/gsmartcontrol/src/hz/string_algo_test.cpp index e04f1b1..966a3e0 100644 --- a/gsmartcontrol/src/hz/string_algo_test.cpp +++ b/gsmartcontrol/src/hz/string_algo_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/string_format.h b/gsmartcontrol/src/hz/string_format.h index 2895421..819bc5b 100644 --- a/gsmartcontrol/src/hz/string_format.h +++ b/gsmartcontrol/src/hz/string_format.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ @@ -14,8 +14,7 @@ #include // std::size_t, std::ptrdiff_t #include "cstdint.h" // (u)intmax_t -#include "system_specific.h" // HZ_FUNC_PRINTF_CHECK -#include "string_sprintf.h" // string_sprintf +#include "string_sprintf.h" // string_sprintf, HZ_FUNC_STRING_SPRINTF_CHECK #include "stream_cast.h" // stream_cast<> #include "local_algo.h" // returning_binary_search @@ -30,11 +29,15 @@ // Note: These functions use system *printf family of functions. -// Note: On MinGW there is no support for %Lf (long double). -// Also, you have to use %I64d instead of %lld for long long int +// Note: If using mingw without __USE_MINGW_ANSI_STDIO, +// you MUST cast long double to double and use %f instead of %Lf; +// also you have to use %I64d instead of %lld for long long int // and %I64u instead of %llu for unsigned long long int. // You can use hz::number_to_string() as a workaround. +// FIXME: Check string_sprintf() features through HAVE_STRING_SPRINTF_* +// macros and supply the necessary specifiers / casts. + namespace hz { @@ -48,7 +51,7 @@ namespace internal { // Public API: -inline internal::FormatState string_format(std::string& s, const char* format) HZ_FUNC_PRINTF_CHECK(2, 0); +inline internal::FormatState string_format(std::string& s, const char* format) HZ_FUNC_STRING_SPRINTF_CHECK(2, 0); inline internal::FormatState string_format(std::string& s, const std::string& format); diff --git a/gsmartcontrol/src/hz/string_format_test.cpp b/gsmartcontrol/src/hz/string_format_test.cpp index b829147..3549ed7 100644 --- a/gsmartcontrol/src/hz/string_format_test.cpp +++ b/gsmartcontrol/src/hz/string_format_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/string_num.h b/gsmartcontrol/src/hz/string_num.h index 38ac0f4..0c55a8f 100644 --- a/gsmartcontrol/src/hz/string_num.h +++ b/gsmartcontrol/src/hz/string_num.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/string_num_test.cpp b/gsmartcontrol/src/hz/string_num_test.cpp index 9b57621..f96237e 100644 --- a/gsmartcontrol/src/hz/string_num_test.cpp +++ b/gsmartcontrol/src/hz/string_num_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/string_sprintf.h b/gsmartcontrol/src/hz/string_sprintf.h index 6acbccc..cbd1475 100644 --- a/gsmartcontrol/src/hz/string_sprintf.h +++ b/gsmartcontrol/src/hz/string_sprintf.h @@ -1,8 +1,13 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ +/// \file +/// \author Alexander Shaduri +/// \ingroup hz +/// \weakgroup hz +/// @{ #ifndef HZ_STRING_SPRINTF_H #define HZ_STRING_SPRINTF_H @@ -18,39 +23,52 @@ #if defined ENABLE_GLIB && ENABLE_GLIB #include // g_strdup_vprintf(), g_printf_string_upper_bound() -#elif defined HAVE_VASPRINTF && HAVE_VASPRINTF +#elif defined HAVE_VASPRINTF && HAVE_VASPRINTF && defined HAVE_ISO_STDIO && HAVE_ISO_STDIO + // GNU #include // for stdio.h #include // vasprintf() #include // std::free -#elif defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS - #include // for stdio.h - #include // vsnprintf_s() - #include // vsnprintf_s() -#else // mingw, msvc, posix, c99 +#elif defined HAVE_ISO_STDIO && HAVE_ISO_STDIO + // POSIX, mingw/ISO #include // for stdio.h #include // vsnprintf() #include // vsnprintf() +#elif defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS + // msvc 2005 and later + #include // for stdio.h + #include // vsnprintf_s() + #include // vsnprintf_s() +#else + // mingw/no-ISO, msvc, possibly other old systems + #include // for stdio.h + #include // _vsnprintf() + #include // _vsnprintf() #endif -#include "system_specific.h" // HZ_FUNC_PRINTF_CHECK +#include "string_sprintf_macros.h" +/** +\file +\brief sprintf()-like formatting to std::string with automatic allocation. -// sprintf()-like formatting to std::string with automatic allocation. +\note These functions use system *printf family of functions. -// Note: These functions use system *printf family of functions. +\note If using mingw runtime >= 3.15 and __USE_MINGW_ANSI_STDIO, +mingw supports both C99/POSIX and msvcrt format specifiers. +This includes proper printing of long double, %lld and %llu, etc... +This does _not_ affect _snprintf() and similar non-standard functions. +Note that you may still get warnings from gcc regarding non-MS +format specifiers (see HZ_FUNC_PRINTF_CHECK). -// Note: If using mingw runtime >= 3.15 and __USE_MINGW_ANSI_STDIO, -// mingw supports both C99/POSIX and msvcrt format specifiers. -// This includes proper printing of long double, %lld and %llu, etc... -// This does _not_ affect _snprintf() and similar non-standard functions. -// Note that you may still get warnings from gcc regarding non-MS -// format specifiers (see HZ_FUNC_PRINTF_CHECK). -// For other Windows targets there is no support for %Lf (long double), -// you have to use %I64d instead of %lld for long long int -// and %I64u instead of %llu for unsigned long long int. -// You can use hz::number_to_string() as a workaround. +\note There types are non-portable (the first one is MS variant, the second one is standard): +%I64d, %lld (long long int), +%I64u, %llu (unsigned long long int), +%f, %Lf (long double; needs casting to double under non-ANSI mingw if using %f). + +See string_sprintf_macros.h on how to test the feature availability. +*/ @@ -58,20 +76,20 @@ namespace hz { -// Get the buffer size required to safely allocate a buffer (including terminating 0) and call vsnprintf(). -inline int string_vsprintf_get_buffer_size(const char* format, std::va_list ap) HZ_FUNC_PRINTF_CHECK(1, 0); +/// Get the buffer size required to safely allocate a buffer (including terminating 0) and call vsnprintf(). +inline int string_vsprintf_get_buffer_size(const char* format, std::va_list ap) HZ_FUNC_STRING_SPRINTF_CHECK(1, 0); -// same as above, but using varargs. -inline int string_sprintf_get_buffer_size(const char* format, ...) HZ_FUNC_PRINTF_CHECK(1, 2); +/// same as string_vsprintf_get_buffer_size(), but using varargs. +inline int string_sprintf_get_buffer_size(const char* format, ...) HZ_FUNC_STRING_SPRINTF_CHECK(1, 2); -// auto-allocating std::string-returning portable vsprintf -inline std::string string_vsprintf(const char* format, std::va_list ap) HZ_FUNC_PRINTF_CHECK(1, 0); +/// auto-allocating std::string-returning portable vsprintf +inline std::string string_vsprintf(const char* format, std::va_list ap) HZ_FUNC_STRING_SPRINTF_CHECK(1, 0); -// same as above, but using varargs -inline std::string string_sprintf(const char* format, ...) HZ_FUNC_PRINTF_CHECK(1, 2); +/// same as string_vsprintf(), but using varargs +inline std::string string_sprintf(const char* format, ...) HZ_FUNC_STRING_SPRINTF_CHECK(1, 2); @@ -87,10 +105,18 @@ inline int string_vsprintf_get_buffer_size(const char* format, std::va_list ap) // the glib version returns gsize return static_cast(g_printf_string_upper_bound(format, ap)); -#elif defined _WIN32 +#elif defined HAVE_ISO_STDIO && HAVE_ISO_STDIO + // In C99/POSIX, vsnprintf() returns the number of bytes it could have written + // (without \0) if buffer was large enough. + // This includes mingw/ISO. + char c = 0; + const int size = vsnprintf(&c, 1, format, ap); // C99 and others + if (size < 0) + return -1; + return size + 1; // that +1 is for \0. - // in C99, vsnprintf() returns the number of bytes it could have written - // (without \0) if buffer was large enough. Unfortunately, MS returns -1 if buffer +#else + // Unfortunately, MS (maybe some very old systems as well) return -1 if buffer // is not large enough, so we have to use incremental reallocation until it fits. errno = 0; // reset @@ -102,8 +128,13 @@ inline int string_vsprintf_get_buffer_size(const char* format, std::va_list ap) #if defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS const int size = vsnprintf_s(buf, buf_size, buf_size - 1, format, ap); // writes (buf_size - 1) chars, appends 0. + + #elif defined HAVE__VSNPRINTF && HAVE__VSNPRINTF + // Prefer _vsnprintf() to vsnprintf() as MS may change the latter eventually. + const int size = _vsnprintf(buf, buf_size, format, ap); // writes buf_size chars, including 0 (if it fits). + #else - const int size = vsnprintf(buf, buf_size, format, ap); // writes buf_size chars, including 0. + const int size = vsnprintf(buf, buf_size, format, ap); // assume same as above #endif if (size == -1) { @@ -114,7 +145,7 @@ inline int string_vsprintf_get_buffer_size(const char* format, std::va_list ap) } } else if (size <= buf_size) { - ret = size + 1; // for 0 + ret = size + 1; // for 0, as the returned value doesn't contain the 0. break; } else { // huh? @@ -127,14 +158,6 @@ inline int string_vsprintf_get_buffer_size(const char* format, std::va_list ap) return ret; -#else // normal systems have C99 or POSIX - - char c = 0; - const int size = vsnprintf(&c, 1, format, ap); // C99 and others - if (size < 0) - return -1; - return size + 1; // that +1 is for \0. - #endif } @@ -155,14 +178,16 @@ inline int string_sprintf_get_buffer_size(const char* format, ...) inline std::string string_vsprintf(const char* format, std::va_list ap) { #if defined ENABLE_GLIB && ENABLE_GLIB - // there's also g_vasprintf(), but only since glib 2.4. gchar* buf = g_strdup_vprintf(format, ap); std::string ret = (buf ? buf : ""); if (buf) g_free(buf); -#elif defined HAVE_VASPRINTF && HAVE_VASPRINTF +#elif defined HAVE_VASPRINTF && HAVE_VASPRINTF && defined HAVE_ISO_STDIO && HAVE_ISO_STDIO + // We check both vasprintf() and ISO compliance above to ensure that + // string_vsnprintf() and string_vsprintf_get_buffer_size() can work with + // the same format string. std::string ret; char* str = 0; @@ -177,11 +202,18 @@ inline std::string string_vsprintf(const char* format, std::va_list ap) if (size > 0) { char* buf = new char[size]; int written = 0; - #if defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS - written = vsnprintf_s(buf, size, size - 1, format, ap); // writes (size - 1) chars, appends 0. - #else + #if defined HAVE_ISO_STDIO && HAVE_ISO_STDIO // we could use vsprintf(), but it's deemed unsafe in many environments. written = vsnprintf(buf, size, format, ap); // writes size chars, including 0. + + #elif defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS + written = vsnprintf_s(buf, size, size - 1, format, ap); // writes (size - 1) chars, appends 0. + + #elif defined HAVE__VSNPRINTF && HAVE__VSNPRINTF + written = _vsnprintf(buf, size, format, ap); // writes size chars, including 0. + #else + // Same as the first one, to ensure that the order matches that of string_vsprintf_get_buffer_size(). + written = vsnprintf(buf, size, format, ap); // writes size chars, including 0. #endif if (written > 0) ret = buf; @@ -214,3 +246,5 @@ inline std::string string_sprintf(const char* format, ...) #endif + +/// @} diff --git a/gsmartcontrol/src/hz/string_sprintf_macros.h b/gsmartcontrol/src/hz/string_sprintf_macros.h new file mode 100644 index 0000000..797f39f --- /dev/null +++ b/gsmartcontrol/src/hz/string_sprintf_macros.h @@ -0,0 +1,79 @@ +/************************************************************************** + Copyright: + (C) 2008 - 2010 Alexander Shaduri + License: See LICENSE_zlib.txt file +***************************************************************************/ +/// \file +/// \author Alexander Shaduri +/// \ingroup hz +/// \weakgroup hz +/// @{ + +#ifndef HZ_STRING_SPRINTF_MACROS_H +#define HZ_STRING_SPRINTF_MACROS_H + +#include "hz_config.h" // feature macros + +#include "system_specific.h" // HZ_FUNC_PRINTF_*_CHECK + + +// This is a helper file for string_sprintf.h. It is useful if you need +// the macros only, but not the implementation (useful for header files). + + + +// HAVE_STRING_SPRINTF_MS - whether the MS (%I64d and %I64u) +// specifiers are supported. + +// HAVE_STRING_SPRINTF_ISO - whether the ISO +// (%lld, %llu, %Lf) specifiers are supported. + +#if defined ENABLE_GLIB && ENABLE_GLIB + #define HAVE_STRING_SPRINTF_MS 0 + #define HAVE_STRING_SPRINTF_ISO 1 + +#elif defined HAVE_ISO_STDIO && HAVE_ISO_STDIO + // mingw/ISO has both the MS and ISO specifiers + #if defined _WIN32 && defined __GNUC__ + #define HAVE_STRING_SPRINTF_MS 1 + #else + #define HAVE_STRING_SPRINTF_MS 0 + #endif + #define HAVE_STRING_SPRINTF_ISO 1 + +#elif defined HAVE_WIN_SE_FUNCS && HAVE_WIN_SE_FUNCS + #define HAVE_STRING_SPRINTF_MS 1 + #define HAVE_STRING_SPRINTF_ISO 0 + +#elif defined HAVE__VSNPRINTF && HAVE__VSNPRINTF + #define HAVE_STRING_SPRINTF_MS 0 + #define HAVE_STRING_SPRINTF_ISO 1 + +#else + #warning Cannot detect vsnprintf() availability + + #define HAVE_STRING_SPRINTF_MS 0 + #define HAVE_STRING_SPRINTF_ISO 0 +#endif + + + + +// HZ_FUNC_STRING_SPRINTF_CHECK - gcc printf format attribute checker, +// configured according to MS or ISO features (prefers ISO over MS). + +#if HAVE_STRING_SPRINTF_ISO + #define HZ_FUNC_STRING_SPRINTF_CHECK(format_idx, check_idx) HZ_FUNC_PRINTF_ISO_CHECK(format_idx, check_idx) +#elif HAVE_STRING_SPRINTF_MS + #define HZ_FUNC_STRING_SPRINTF_CHECK(format_idx, check_idx) HZ_FUNC_PRINTF_MS_CHECK(format_idx, check_idx) +#else + #define HZ_FUNC_STRING_SPRINTF_CHECK(format_idx, check_idx) +#endif + + + + + +#endif + +/// @} diff --git a/gsmartcontrol/src/hz/string_wcmatch.h b/gsmartcontrol/src/hz/string_wcmatch.h index 267ff78..997993d 100644 --- a/gsmartcontrol/src/hz/string_wcmatch.h +++ b/gsmartcontrol/src/hz/string_wcmatch.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: (C) 1989, 1993, 1994 The Regents of the University of California - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_bsd-ucb.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/string_wcmatch_test.cpp b/gsmartcontrol/src/hz/string_wcmatch_test.cpp index 043b5a1..e8d3827 100644 --- a/gsmartcontrol/src/hz/string_wcmatch_test.cpp +++ b/gsmartcontrol/src/hz/string_wcmatch_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync.h b/gsmartcontrol/src/hz/sync.h index 7553ff0..b33adbd 100644 --- a/gsmartcontrol/src/hz/sync.h +++ b/gsmartcontrol/src/hz/sync.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_lock_ptr.h b/gsmartcontrol/src/hz/sync_lock_ptr.h index bcdca22..4df7733 100644 --- a/gsmartcontrol/src/hz/sync_lock_ptr.h +++ b/gsmartcontrol/src/hz/sync_lock_ptr.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_multilock.h b/gsmartcontrol/src/hz/sync_multilock.h index 16eb76c..9d8b33b 100644 --- a/gsmartcontrol/src/hz/sync_multilock.h +++ b/gsmartcontrol/src/hz/sync_multilock.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_multilock_test.cpp b/gsmartcontrol/src/hz/sync_multilock_test.cpp index 6cd7f1a..2c048f0 100644 --- a/gsmartcontrol/src/hz/sync_multilock_test.cpp +++ b/gsmartcontrol/src/hz/sync_multilock_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_part_get_policy.h b/gsmartcontrol/src/hz/sync_part_get_policy.h index ad484b5..4685cbd 100644 --- a/gsmartcontrol/src/hz/sync_part_get_policy.h +++ b/gsmartcontrol/src/hz/sync_part_get_policy.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_policy_boost.h b/gsmartcontrol/src/hz/sync_policy_boost.h index b207774..dda9510 100644 --- a/gsmartcontrol/src/hz/sync_policy_boost.h +++ b/gsmartcontrol/src/hz/sync_policy_boost.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_policy_glib.h b/gsmartcontrol/src/hz/sync_policy_glib.h index 5f5c8e1..b86dc6c 100644 --- a/gsmartcontrol/src/hz/sync_policy_glib.h +++ b/gsmartcontrol/src/hz/sync_policy_glib.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_policy_glibmm.h b/gsmartcontrol/src/hz/sync_policy_glibmm.h index 4d58e76..a13920c 100644 --- a/gsmartcontrol/src/hz/sync_policy_glibmm.h +++ b/gsmartcontrol/src/hz/sync_policy_glibmm.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_policy_poco.h b/gsmartcontrol/src/hz/sync_policy_poco.h index c1e3bab..6231505 100644 --- a/gsmartcontrol/src/hz/sync_policy_poco.h +++ b/gsmartcontrol/src/hz/sync_policy_poco.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_policy_pthread.h b/gsmartcontrol/src/hz/sync_policy_pthread.h index e170dc6..e42408a 100644 --- a/gsmartcontrol/src/hz/sync_policy_pthread.h +++ b/gsmartcontrol/src/hz/sync_policy_pthread.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_policy_win32.h b/gsmartcontrol/src/hz/sync_policy_win32.h index f0f81db..8a4ae97 100644 --- a/gsmartcontrol/src/hz/sync_policy_win32.h +++ b/gsmartcontrol/src/hz/sync_policy_win32.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/sync_test.cpp b/gsmartcontrol/src/hz/sync_test.cpp index 5551912..9a04fcb 100644 --- a/gsmartcontrol/src/hz/sync_test.cpp +++ b/gsmartcontrol/src/hz/sync_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/system_specific.h b/gsmartcontrol/src/hz/system_specific.h index cd9879d..ec4b263 100644 --- a/gsmartcontrol/src/hz/system_specific.h +++ b/gsmartcontrol/src/hz/system_specific.h @@ -1,8 +1,13 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ +/// \file +/// \author Alexander Shaduri +/// \ingroup hz +/// \weakgroup hz +/// @{ #ifndef HZ_SYSTEM_SPECIFIC_H #define HZ_SYSTEM_SPECIFIC_H @@ -35,9 +40,14 @@ #endif -// for easy printf format checks. -#ifndef HZ_FUNC_PRINTF_CHECK +// For easy printf format checks. + +#ifndef HZ_FUNC_PRINTF_ISO_CHECK // See http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Function-Attributes.html + #define HZ_FUNC_PRINTF_ISO_CHECK(format_idx, check_idx) HZ_GCC_ATTR(format(printf, format_idx, check_idx)) +#endif + +#ifndef HZ_FUNC_PRINTF_MS_CHECK // ms_printf is available since gcc 4.4. // Note: When using __USE_MINGW_ANSI_STDIO, mingw uses // its own *printf() implementation (rather than msvcrt), which accepts @@ -47,9 +57,9 @@ // TODO: Check if simply specifying "printf" selects the correct // version for mingw. #if defined _WIN32 && HZ_GCC_CHECK_VERSION(4, 4, 0) - #define HZ_FUNC_PRINTF_CHECK(format_idx, check_idx) HZ_GCC_ATTR(format(ms_printf, format_idx, check_idx)) + #define HZ_FUNC_PRINTF_MS_CHECK(format_idx, check_idx) HZ_GCC_ATTR(format(ms_printf, format_idx, check_idx)) #else - #define HZ_FUNC_PRINTF_CHECK(format_idx, check_idx) HZ_GCC_ATTR(format(printf, format_idx, check_idx)) + #define HZ_FUNC_PRINTF_MS_CHECK(format_idx, check_idx) #endif #endif @@ -58,6 +68,11 @@ #include +/** +\fn std::string hz::type_name_demangle(const std::string& name) +Demangle a C/C++ type name, as returned by std::type_info.name(). +Similar to c++filt command. Supported under gcc only for now. +*/ #if defined HAVE_GCC_ABI_DEMANGLE && HAVE_GCC_ABI_DEMANGLE @@ -68,7 +83,6 @@ namespace hz { - // accepts input string as given by std::type_info.name(). inline std::string type_name_demangle(const std::string& name) { int status = 0; @@ -104,3 +118,5 @@ namespace hz { #endif + +/// @} diff --git a/gsmartcontrol/src/hz/tls.h b/gsmartcontrol/src/hz/tls.h index c33e769..fb7c84b 100644 --- a/gsmartcontrol/src/hz/tls.h +++ b/gsmartcontrol/src/hz/tls.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/tls_policy_boost.h b/gsmartcontrol/src/hz/tls_policy_boost.h index 71024aa..2036c7a 100644 --- a/gsmartcontrol/src/hz/tls_policy_boost.h +++ b/gsmartcontrol/src/hz/tls_policy_boost.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/tls_policy_glib.h b/gsmartcontrol/src/hz/tls_policy_glib.h index adc45b7..9383fc1 100644 --- a/gsmartcontrol/src/hz/tls_policy_glib.h +++ b/gsmartcontrol/src/hz/tls_policy_glib.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/tls_policy_pthread.h b/gsmartcontrol/src/hz/tls_policy_pthread.h index 48ca1eb..24be334 100644 --- a/gsmartcontrol/src/hz/tls_policy_pthread.h +++ b/gsmartcontrol/src/hz/tls_policy_pthread.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/tls_policy_win32.h b/gsmartcontrol/src/hz/tls_policy_win32.h index 9cf553e..c353f1a 100644 --- a/gsmartcontrol/src/hz/tls_policy_win32.h +++ b/gsmartcontrol/src/hz/tls_policy_win32.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/tls_test.cpp b/gsmartcontrol/src/hz/tls_test.cpp index 194f5bd..9bc6429 100644 --- a/gsmartcontrol/src/hz/tls_test.cpp +++ b/gsmartcontrol/src/hz/tls_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/type_categories.h b/gsmartcontrol/src/hz/type_categories.h index 1fc95ce..b57f908 100644 --- a/gsmartcontrol/src/hz/type_categories.h +++ b/gsmartcontrol/src/hz/type_categories.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Alexander Shaduri + (C) 2003 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/hz/win32_tools.h b/gsmartcontrol/src/hz/win32_tools.h index e89b64b..127c6dd 100644 --- a/gsmartcontrol/src/hz/win32_tools.h +++ b/gsmartcontrol/src/hz/win32_tools.h @@ -1,8 +1,13 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Alexander Shaduri + (C) 2003 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ +/// \file +/// \author Alexander Shaduri +/// \ingroup hz +/// \weakgroup hz +/// @{ #ifndef HZ_WIN32_TOOLS_H #define HZ_WIN32_TOOLS_H @@ -26,102 +31,119 @@ +/** +\file +\brief Win32-specific API functions. +\note The public API works with UTF-8 strings, unless noted otherwise. +*/ + + + namespace hz { -// Note: The public API works with UTF-8 strings, unless noted otherwise. - - -// Get a list of drives available for the user. The drives are in -// "C:\" format (uppercase, utf-8). +/// Get a list of drives available for the user. The drives are in +/// "C:\" format (uppercase, utf-8). template inline bool win32_get_drive_list(Container& put_here); -// Get windows "special" folder by CSIDL (CSIDL_APPDATA, for example). -// See http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx -// for details. +/// Get windows "special" folder by CSIDL (CSIDL_APPDATA, for example). +/// See http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx +/// for details. inline std::string win32_get_special_folder(int csidl, bool auto_create = true); -// Usually C:\Windows or something like that. +/// Usually C:\\Windows or something like that. inline std::string win32_get_windows_directory(); -// base may be e.g. HKEY_CURRENT_USER. -// Note that this works only with REG_SZ (string) types, -// returning their value as utf-8. False is returned for all other types. +/// Get registry value as a string. +/// Base may be e.g. HKEY_CURRENT_USER. +/// Note that this works only with REG_SZ (string) types, +/// returning their value as utf-8. False is returned for all other types. inline bool win32_get_registry_value_string(HKEY base, const std::string& keydir, const std::string& key, std::string& put_here); -// Note that this sets the type as REG_SZ (string). The accepted utf-8 -// value is converted to utf-16 for storage. +/// Set registry value as a string. +/// Note that this sets the type as REG_SZ (string). The accepted utf-8 +/// value is converted to utf-16 for storage. inline bool win32_set_registry_value_string(HKEY base, const std::string& keydir, const std::string& key, const std::string& value); -// Redirect stdout and stderr to console window (if open). -inline bool win32_redirect_stdio_to_console(); +/// Redirect stdout and stderr to console window (if open). Requires winxp (at compile-time). +/// \param create_if_none if true, create a new console if none was found and attach to it. +/// \return false if failed or unsupported. +inline bool win32_redirect_stdio_to_console(bool create_if_none = false); -// Redirect stdout to stdout.txt and stderr to stderr.txt. -// Call once. +/// Redirect stdout and stderr to console window (if open). Requires winxp (at compile-time). +/// \param create_if_none if true, create a new console if none was found and attach to it. +/// \param console_created Set to true if a new console was created due to \c create_if_none. +/// \return false if failed or unsupported. +inline bool win32_redirect_stdio_to_console(bool create_if_none, bool& console_created); + + +/// Redirect stdout to stdout.txt and stderr to stderr.txt. +/// Call once. +/// \return true on success, false on failure. inline bool win32_redirect_stdio_to_files(std::string stdout_file = "", std::string stderr_file = ""); -// Convert a string in user-specified encoding to utf-16 string (00-terminated array of wchar_t). -// wchar_t is 2 bytes on windows, thus holding utf-16 code unit. -// Caller must delete[] the returned value. -// returned_buf_size (if not 0) will be set to the size of returned buffer -// (in wchar_t; including terminating 00). The byte size will be (returned_buf_size*2). +/// Convert a string in user-specified encoding to utf-16 string (00-terminated array of wchar_t). +/// wchar_t is 2 bytes on windows, thus holding utf-16 code unit. +/// Caller must delete[] the returned value. +/// returned_buf_size (if not 0) will be set to the size of returned buffer +/// (in wchar_t; including terminating 00). The byte size will be (returned_buf_size*2). inline wchar_t* win32_user_to_utf16(UINT from_cp, const char* from_str, unsigned int* returned_buf_size = 0); -// Convert utf-16 string (represented as 0-terminated array of wchar_t, where -// wchar_t is 2 bytes (on windows)) to a string in user-specified encoding. -// Caller must delete[] the returned value. -// The size of the returned buffer is std::strlen(buf) + 1. -// returned_buf_size (if not 0) will be set to the size of returned buffer -// (in char; including terminating 0). +/// Convert utf-16 string (represented as 0-terminated array of wchar_t, where +/// wchar_t is 2 bytes (on windows)) to a string in user-specified encoding. +/// Caller must delete[] the returned value. +/// The size of the returned buffer is std::strlen(buf) + 1. +/// returned_buf_size (if not 0) will be set to the size of returned buffer +/// (in char; including terminating 0). inline char* win32_utf16_to_user(UINT to_cp, const wchar_t* utf16_str, unsigned int* returned_buf_size = 0); -// Convert utf-8 string to utf-16 string. See win32_user_to_utf16() for details. +/// Convert utf-8 string to utf-16 string. See win32_user_to_utf16() for details. inline wchar_t* win32_utf8_to_utf16(const char* utf8_str, unsigned int* returned_buf_size = 0); -// Convert utf-16 string to utf-8 string. See win32_utf16_to_user() for details. +/// Convert utf-16 string to utf-8 string. See win32_utf16_to_user() for details. inline char* win32_utf16_to_utf8(const wchar_t* utf16_str, unsigned int* returned_buf_size = 0); -// Same as win32_utf16_to_utf8(), but safer since it never returns 0 (it returns "" instead). -// Note that we don't provide non-utf8 versions of this function, because the other charsets -// may actually be multi-byte (std::string can't hold their terminating 0 properly). -// Also, we don't provide std::wstring versions for utf16, because they are not always -// supported by non-MS compilers (mingw, for example). +/// Same as win32_utf16_to_utf8(), but safer since it never returns 0 (it returns "" instead). +/// Note that we don't provide non-utf8 versions of this function, because the other charsets +/// may actually be multi-byte (std::string can't hold their terminating 0 properly). +/// Also, we don't provide std::wstring versions for utf16, because they are not always +/// supported by non-MS compilers (mingw, for example). inline std::string win32_utf16_to_utf8_string(const wchar_t* utf16_str); -// Convert current locale-encoded string to utf-16 string. See win32_user_to_utf16() for details. -// Use CP_ACP is system default windows ANSI codepage. -// Use CP_THREAD_ACP is for current thread. Think before you choose. :) +/// Convert current locale-encoded string to utf-16 string. See win32_user_to_utf16() for details. +/// Use CP_ACP is system default windows ANSI codepage. +/// Use CP_THREAD_ACP is for current thread. Think before you choose. :) inline wchar_t* win32_locale_to_utf16(const char* loc_str, unsigned int* returned_buf_size = 0, bool use_thread_locale = false); -// Convert utf-16 string to locale-encoded string. See win32_utf16_to_user() for details. +/// Convert utf-16 string to locale-encoded string. See win32_utf16_to_user() for details. inline char* win32_utf16_to_locale(const wchar_t* utf16_str, unsigned int* returned_buf_size = 0, bool use_thread_locale = false); -// Convert current locale-encoded string to utf-8 string. The returned value must be freed by caller. +/// Convert current locale-encoded string to utf-8 string. The returned value must be freed by caller. inline char* win32_locale_to_utf8(const char* loc_str, unsigned int* returned_buf_size = 0, bool use_thread_locale = false); -// Convert utf-8 string to locale-encoded string. See win32_utf8_to_user() for details. -inline char* win32_utf8_to_locale(const wchar_t* utf8_str, unsigned int* returned_buf_size = 0, +/// Convert utf-8 string to locale-encoded string. See win32_utf8_to_user() for details. +inline char* win32_utf8_to_locale(const char* utf8_str, unsigned int* returned_buf_size = 0, bool use_thread_locale = false); @@ -329,15 +351,35 @@ inline bool win32_set_registry_value_string(HKEY base, +// Redirect stdout and stderr to console window (if open). +inline bool win32_redirect_stdio_to_console(bool create_if_none) +{ + bool console_created = false; + return win32_redirect_stdio_to_console(create_if_none, console_created); +} + + // Redirect stdout and stderr to console window (if open). -inline bool win32_redirect_stdio_to_console() +inline bool win32_redirect_stdio_to_console(bool create_if_none, bool& console_created) { + console_created = false; + // AttachConsole is since winxp (note that mingw and MS headers say win2k, - // which is incorrect). + // which is incorrect; msdn is correct). #if defined WINVER && WINVER >= 0x0501 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { - return false; + if (create_if_none) { + // Even though msdn says that stdio is redirected to the new console, + // it isn't so and we must do it manually. + if (!AllocConsole()) { + return false; + } else { + console_created = true; + } + } else { + return false; + } } // redirect unbuffered STDOUT to the console @@ -384,7 +426,7 @@ namespace internal { - // returns full path (in utf-16) to the output filename (in utf-8) + /// Returns full path (in utf-16) to the output filename (in utf-8) inline wchar_t* win32_get_std_output_file(const char* base) { if (!base) @@ -417,8 +459,8 @@ namespace internal { - // Remove the output files if there was no output written. - // This is an atexit() callback. + /// Remove the output files if there was no output written. + /// This is an atexit() callback. extern "C" inline void win32_redirect_stdio_to_files_cleanup() { // Flush the output in case anything is queued @@ -688,3 +730,5 @@ inline char* win32_utf8_to_locale(const char* utf8_str, unsigned int* returned_b #endif // win32 #endif // hg + +/// @} diff --git a/gsmartcontrol/src/libdebug/dchannel.cpp b/gsmartcontrol/src/libdebug/dchannel.cpp index bdc899f..022c3c5 100644 --- a/gsmartcontrol/src/libdebug/dchannel.cpp +++ b/gsmartcontrol/src/libdebug/dchannel.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dchannel.h b/gsmartcontrol/src/libdebug/dchannel.h index 122c2be..ad60ed0 100644 --- a/gsmartcontrol/src/libdebug/dchannel.h +++ b/gsmartcontrol/src/libdebug/dchannel.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dcmdarg.cpp b/gsmartcontrol/src/libdebug/dcmdarg.cpp index 7a40125..4e8298a 100644 --- a/gsmartcontrol/src/libdebug/dcmdarg.cpp +++ b/gsmartcontrol/src/libdebug/dcmdarg.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dcmdarg.h b/gsmartcontrol/src/libdebug/dcmdarg.h index 23a5409..435a469 100644 --- a/gsmartcontrol/src/libdebug/dcmdarg.h +++ b/gsmartcontrol/src/libdebug/dcmdarg.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dexcept.h b/gsmartcontrol/src/libdebug/dexcept.h index a0e2a44..b2c9083 100644 --- a/gsmartcontrol/src/libdebug/dexcept.h +++ b/gsmartcontrol/src/libdebug/dexcept.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dflags.cpp b/gsmartcontrol/src/libdebug/dflags.cpp index d841d59..5c609e1 100644 --- a/gsmartcontrol/src/libdebug/dflags.cpp +++ b/gsmartcontrol/src/libdebug/dflags.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dflags.h b/gsmartcontrol/src/libdebug/dflags.h index bbf73a5..487ebea 100644 --- a/gsmartcontrol/src/libdebug/dflags.h +++ b/gsmartcontrol/src/libdebug/dflags.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dout.cpp b/gsmartcontrol/src/libdebug/dout.cpp index 9a4b08a..11a18ad 100644 --- a/gsmartcontrol/src/libdebug/dout.cpp +++ b/gsmartcontrol/src/libdebug/dout.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dout.h b/gsmartcontrol/src/libdebug/dout.h index 2e7c748..844ddb2 100644 --- a/gsmartcontrol/src/libdebug/dout.h +++ b/gsmartcontrol/src/libdebug/dout.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ @@ -14,6 +14,7 @@ #include "hz/system_specific.h" #include "hz/hz_config.h" // HAVE_CXX_* +#include "hz/string_sprintf_macros.h" // HZ_FUNC_STRING_SPRINTF_CHECK #include "dflags.h" @@ -51,7 +52,7 @@ std::ostream& debug_out(debug_level::flag level, const std::string& domain); void debug_print(debug_level::flag level, const std::string& domain, - const char* format, ...) HZ_FUNC_PRINTF_CHECK(3, 4); + const char* format, ...) HZ_FUNC_STRING_SPRINTF_CHECK(3, 4); diff --git a/gsmartcontrol/src/libdebug/dstate.cpp b/gsmartcontrol/src/libdebug/dstate.cpp index e162d7a..ef75028 100644 --- a/gsmartcontrol/src/libdebug/dstate.cpp +++ b/gsmartcontrol/src/libdebug/dstate.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dstate.h b/gsmartcontrol/src/libdebug/dstate.h index 213fe4d..1ccec50 100644 --- a/gsmartcontrol/src/libdebug/dstate.h +++ b/gsmartcontrol/src/libdebug/dstate.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dstate_pub.h b/gsmartcontrol/src/libdebug/dstate_pub.h index 54924b1..781c7db 100644 --- a/gsmartcontrol/src/libdebug/dstate_pub.h +++ b/gsmartcontrol/src/libdebug/dstate_pub.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dstream.cpp b/gsmartcontrol/src/libdebug/dstream.cpp index 96fb2bf..1b8695a 100644 --- a/gsmartcontrol/src/libdebug/dstream.cpp +++ b/gsmartcontrol/src/libdebug/dstream.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/dstream.h b/gsmartcontrol/src/libdebug/dstream.h index 2dba1ae..e654775 100644 --- a/gsmartcontrol/src/libdebug/dstream.h +++ b/gsmartcontrol/src/libdebug/dstream.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/libdebug.h b/gsmartcontrol/src/libdebug/libdebug.h index bc48bcb..bb54d6e 100644 --- a/gsmartcontrol/src/libdebug/libdebug.h +++ b/gsmartcontrol/src/libdebug/libdebug.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/libdebug_mini.h b/gsmartcontrol/src/libdebug/libdebug_mini.h index 88ced15..5ad196f 100644 --- a/gsmartcontrol/src/libdebug/libdebug_mini.h +++ b/gsmartcontrol/src/libdebug/libdebug_mini.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/libdebug/libdebug_test.cpp b/gsmartcontrol/src/libdebug/libdebug_test.cpp index f30b24f..e031014 100644 --- a/gsmartcontrol/src/libdebug/libdebug_test.cpp +++ b/gsmartcontrol/src/libdebug/libdebug_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/rconfig/rcautosave.h b/gsmartcontrol/src/rconfig/rcautosave.h index e47f0f4..0cfdd6c 100644 --- a/gsmartcontrol/src/rconfig/rcautosave.h +++ b/gsmartcontrol/src/rconfig/rcautosave.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/rconfig/rcdump.h b/gsmartcontrol/src/rconfig/rcdump.h index f2c06a7..887df3b 100644 --- a/gsmartcontrol/src/rconfig/rcdump.h +++ b/gsmartcontrol/src/rconfig/rcdump.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/rconfig/rcloadsave.h b/gsmartcontrol/src/rconfig/rcloadsave.h index fa4e205..e44bfda 100644 --- a/gsmartcontrol/src/rconfig/rcloadsave.h +++ b/gsmartcontrol/src/rconfig/rcloadsave.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/rconfig/rcmain.h b/gsmartcontrol/src/rconfig/rcmain.h index 30ce6cf..b0aa585 100644 --- a/gsmartcontrol/src/rconfig/rcmain.h +++ b/gsmartcontrol/src/rconfig/rcmain.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/rconfig/rconfig.h b/gsmartcontrol/src/rconfig/rconfig.h index 4ea84df..824b901 100644 --- a/gsmartcontrol/src/rconfig/rconfig.h +++ b/gsmartcontrol/src/rconfig/rconfig.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/rconfig/rconfig_mini.h b/gsmartcontrol/src/rconfig/rconfig_mini.h index e037f4b..e5eb792 100644 --- a/gsmartcontrol/src/rconfig/rconfig_mini.h +++ b/gsmartcontrol/src/rconfig/rconfig_mini.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_zlib.txt file ***************************************************************************/ diff --git a/gsmartcontrol/src/rconfig/rconfig_test.cpp b/gsmartcontrol/src/rconfig/rconfig_test.cpp index 513c2c7..88dd103 100644 --- a/gsmartcontrol/src/rconfig/rconfig_test.cpp +++ b/gsmartcontrol/src/rconfig/rconfig_test.cpp @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/src/rmn/resource_base.h b/gsmartcontrol/src/rmn/resource_base.h index afc5a92..dc32e83 100644 --- a/gsmartcontrol/src/rmn/resource_base.h +++ b/gsmartcontrol/src/rmn/resource_base.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Irakli Elizbarashvili - (C) 2008 - 2009 Alexander Shaduri + (C) 2003 - 2010 Irakli Elizbarashvili + (C) 2008 - 2010 Alexander Shaduri License: diff --git a/gsmartcontrol/src/rmn/resource_data_any.h b/gsmartcontrol/src/rmn/resource_data_any.h index 1bb4d57..646d4cf 100644 --- a/gsmartcontrol/src/rmn/resource_data_any.h +++ b/gsmartcontrol/src/rmn/resource_data_any.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: diff --git a/gsmartcontrol/src/rmn/resource_data_locking.h b/gsmartcontrol/src/rmn/resource_data_locking.h index 139f262..6c90aca 100644 --- a/gsmartcontrol/src/rmn/resource_data_locking.h +++ b/gsmartcontrol/src/rmn/resource_data_locking.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: diff --git a/gsmartcontrol/src/rmn/resource_data_one.h b/gsmartcontrol/src/rmn/resource_data_one.h index 098ee43..deae711 100644 --- a/gsmartcontrol/src/rmn/resource_data_one.h +++ b/gsmartcontrol/src/rmn/resource_data_one.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: diff --git a/gsmartcontrol/src/rmn/resource_data_types.h b/gsmartcontrol/src/rmn/resource_data_types.h index dd0543a..b32f2f2 100644 --- a/gsmartcontrol/src/rmn/resource_data_types.h +++ b/gsmartcontrol/src/rmn/resource_data_types.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: diff --git a/gsmartcontrol/src/rmn/resource_exception.h b/gsmartcontrol/src/rmn/resource_exception.h index 87e6efe..a8f4abf 100644 --- a/gsmartcontrol/src/rmn/resource_exception.h +++ b/gsmartcontrol/src/rmn/resource_exception.h @@ -1,6 +1,6 @@ /************************************************************************** Copyright: - (C) 2008 - 2009 Alexander Shaduri + (C) 2008 - 2010 Alexander Shaduri License: diff --git a/gsmartcontrol/src/rmn/resource_node.h b/gsmartcontrol/src/rmn/resource_node.h index 1cf7cf8..5476c07 100644 --- a/gsmartcontrol/src/rmn/resource_node.h +++ b/gsmartcontrol/src/rmn/resource_node.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Irakli Elizbarashvili - (C) 2008 - 2009 Alexander Shaduri + (C) 2003 - 2010 Irakli Elizbarashvili + (C) 2008 - 2010 Alexander Shaduri License: diff --git a/gsmartcontrol/src/rmn/resource_node_dump.h b/gsmartcontrol/src/rmn/resource_node_dump.h index 6f21bfd..b960559 100644 --- a/gsmartcontrol/src/rmn/resource_node_dump.h +++ b/gsmartcontrol/src/rmn/resource_node_dump.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Irakli Elizbarashvili - (C) 2008 - 2009 Alexander Shaduri + (C) 2003 - 2010 Irakli Elizbarashvili + (C) 2008 - 2010 Alexander Shaduri License: diff --git a/gsmartcontrol/src/rmn/resource_serialization.h b/gsmartcontrol/src/rmn/resource_serialization.h index cd60dca..60002c6 100644 --- a/gsmartcontrol/src/rmn/resource_serialization.h +++ b/gsmartcontrol/src/rmn/resource_serialization.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Irakli Elizbarashvili - (C) 2008 - 2009 Alexander Shaduri + (C) 2003 - 2010 Irakli Elizbarashvili + (C) 2008 - 2010 Alexander Shaduri License: @@ -31,7 +31,7 @@ #include // std::istream definition (calling bad() member) #include // std::ostream definition (calling bad() member) #include // std::ios::* -#include // std::locale +#include // std::locale::classic() #include "hz/cstdint.h" #include "hz/hz_config.h" // DISABLE_RTTI, RMN_* (global_macros.h) diff --git a/gsmartcontrol/src/rmn/rmn.h b/gsmartcontrol/src/rmn/rmn.h index 19366b6..40b6eb3 100644 --- a/gsmartcontrol/src/rmn/rmn.h +++ b/gsmartcontrol/src/rmn/rmn.h @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Irakli Elizbarashvili - (C) 2008 - 2009 Alexander Shaduri + (C) 2003 - 2010 Irakli Elizbarashvili + (C) 2008 - 2010 Alexander Shaduri License: diff --git a/gsmartcontrol/src/rmn/rmn_test.cpp b/gsmartcontrol/src/rmn/rmn_test.cpp index d1e29c0..ee63b01 100644 --- a/gsmartcontrol/src/rmn/rmn_test.cpp +++ b/gsmartcontrol/src/rmn/rmn_test.cpp @@ -1,7 +1,7 @@ /************************************************************************** Copyright: - (C) 2003 - 2009 Irakli Elizbarashvili - (C) 2008 - 2009 Alexander Shaduri + (C) 2003 - 2010 Irakli Elizbarashvili + (C) 2008 - 2010 Alexander Shaduri License: See LICENSE_unlicense.txt ***************************************************************************/ diff --git a/gsmartcontrol/templates/cc b/gsmartcontrol/templates/cc deleted file mode 100644 index 54e43b0..0000000 --- a/gsmartcontrol/templates/cc +++ /dev/null @@ -1,6 +0,0 @@ -/************************************************************************** - Copyright: - (C) 2008 Alexander Shaduri - License: See LICENSE.gsmartcontrol -***************************************************************************/ - diff --git a/gsmartcontrol/templates/hh b/gsmartcontrol/templates/hh deleted file mode 100644 index 54e43b0..0000000 --- a/gsmartcontrol/templates/hh +++ /dev/null @@ -1,6 +0,0 @@ -/************************************************************************** - Copyright: - (C) 2008 Alexander Shaduri - License: See LICENSE.gsmartcontrol -***************************************************************************/ -