From 6fe1db1c734b9df8afe3c7a5c46203a7c858ece4 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 2 Nov 2019 17:13:17 +0200 Subject: [PATCH] genesys: Use std where needed --- backend/genesys/gl124.cpp | 15 +++++++-------- backend/genesys/gl646.cpp | 28 ++++++++++++++-------------- backend/genesys/gl841.cpp | 23 +++++++++++------------ backend/genesys/gl843.cpp | 27 +++++++++++++-------------- backend/genesys/gl846.cpp | 10 +++++----- backend/genesys/gl847.cpp | 10 +++++----- backend/genesys/low.cpp | 8 +++----- 7 files changed, 58 insertions(+), 63 deletions(-) diff --git a/backend/genesys/gl124.cpp b/backend/genesys/gl124.cpp index 1a3fdd8df..f1d555030 100644 --- a/backend/genesys/gl124.cpp +++ b/backend/genesys/gl124.cpp @@ -385,11 +385,10 @@ static void gl124_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); - for (i = 0; i < steps; i++) - { - sprintf (msg+strlen(msg), ",%d", slope_table[i]); - } + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); + for (i = 0; i < steps; i++) { + std::sprintf(msg + std::strlen(msg), ",%d", slope_table[i]); + } DBG (DBG_io, "%s: %s\n", __func__, msg); } @@ -1907,7 +1906,7 @@ SensorExposure CommandSetGl124::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl124_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl124_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), session.params.depth, channels, num_pixels, 1); } @@ -2068,7 +2067,7 @@ void CommandSetGl124::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl124_offset%03d.pnm", bottom); + std::snprintf(title, 30, "gl124_offset%03d.pnm", bottom); sanei_genesys_write_pnm_file(title, first_line.data(), session.params.depth, channels, pixels, lines); } @@ -2110,7 +2109,7 @@ void CommandSetGl124::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl124_offset%03d.pnm", dev->frontend.get_offset(1)); + std::snprintf(title, 30, "gl124_offset%03d.pnm", dev->frontend.get_offset(1)); sanei_genesys_write_pnm_file(title, second_line.data(), session.params.depth, channels, pixels, lines); } diff --git a/backend/genesys/gl646.cpp b/backend/genesys/gl646.cpp index c8e6cfedb..c8de2ee3d 100644 --- a/backend/genesys/gl646.cpp +++ b/backend/genesys/gl646.cpp @@ -112,15 +112,15 @@ print_status (uint8_t val) { char msg[80]; - sprintf (msg, "%s%s%s%s%s%s%s%s", - val & REG_0x41_PWRBIT ? "PWRBIT " : "", - val & REG_0x41_BUFEMPTY ? "BUFEMPTY " : "", - val & REG_0x41_FEEDFSH ? "FEEDFSH " : "", - val & REG_0x41_SCANFSH ? "SCANFSH " : "", - val & REG_0x41_HOMESNR ? "HOMESNR " : "", - val & REG_0x41_LAMPSTS ? "LAMPSTS " : "", - val & REG_0x41_FEBUSY ? "FEBUSY " : "", - val & REG_0x41_MOTMFLG ? "MOTMFLG" : ""); + std::sprintf(msg, "%s%s%s%s%s%s%s%s", + val & REG_0x41_PWRBIT ? "PWRBIT " : "", + val & REG_0x41_BUFEMPTY ? "BUFEMPTY " : "", + val & REG_0x41_FEEDFSH ? "FEEDFSH " : "", + val & REG_0x41_SCANFSH ? "SCANFSH " : "", + val & REG_0x41_HOMESNR ? "HOMESNR " : "", + val & REG_0x41_LAMPSTS ? "LAMPSTS " : "", + val & REG_0x41_FEBUSY ? "FEBUSY " : "", + val & REG_0x41_MOTMFLG ? "MOTMFLG" : ""); DBG(DBG_info, "status=%s\n", msg); } @@ -2074,7 +2074,7 @@ SensorExposure CommandSetGl646::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl646_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl646_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), 16, channels, settings.pixels, 1); } @@ -2337,7 +2337,7 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl646_offset%03d.pnm", bottom); + std::snprintf(title, 30, "gl646_offset%03d.pnm", bottom); sanei_genesys_write_pnm_file(title, first_line.data(), 8, channels, settings.pixels, settings.lines); } @@ -2355,7 +2355,7 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl646_offset%03d.pnm", top); + std::snprintf(title, 30, "gl646_offset%03d.pnm", top); sanei_genesys_write_pnm_file (title, second_line.data(), 8, channels, settings.pixels, settings.lines); } @@ -2379,7 +2379,7 @@ void CommandSetGl646::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[30]; - snprintf(title, 30, "gl646_offset%03d.pnm", dev->frontend.get_offset(1)); + std::snprintf(title, 30, "gl646_offset%03d.pnm", dev->frontend.get_offset(1)); sanei_genesys_write_pnm_file (title, second_line.data(), 8, channels, settings.pixels, settings.lines); } @@ -2467,7 +2467,7 @@ static void ad_fe_coarse_gain_calibration(Genesys_Device* dev, const Genesys_Sen /* log scanning data */ if (DBG_LEVEL >= DBG_data) { - sprintf (title, "gl646_alternative_gain%02d.pnm", pass); + std::sprintf(title, "gl646_alternative_gain%02d.pnm", pass); sanei_genesys_write_pnm_file(title, line.data(), 8, channels, settings.pixels, settings.lines); } diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index c1f9e2c5a..792d2414c 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -564,10 +564,9 @@ static void gl841_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); - for (i = 0; i < steps; i++) - { - sprintf (msg+strlen(msg), ",%d", slope_table[i]); + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); + for (i = 0; i < steps; i++) { + std::sprintf (msg+strlen(msg), ",%d", slope_table[i]); } DBG(DBG_io, "%s: %s\n", __func__, msg); } @@ -2737,7 +2736,7 @@ SensorExposure CommandSetGl841::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl841_led_%d.pnm", turn); + std::snprintf(fn, 30, "gl841_led_%d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), 16, channels, num_pixels, 1); } @@ -2920,7 +2919,7 @@ static void ad_fe_offset_calibration(Genesys_Device* dev, const Genesys_Sensor& gl841_stop_action (dev); if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl841_offset_%02d.pnm", turn); + std::snprintf(fn, 30, "gl841_offset_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), 8, 3, num_pixels, 1); } @@ -3069,7 +3068,7 @@ void CommandSetGl841::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl841_offset1_%02d.pnm", turn); + std::snprintf(fn, 30, "gl841_offset1_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, first_line.data(), 16, channels, num_pixels, 1); } @@ -3176,7 +3175,7 @@ void CommandSetGl841::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl841_offset2_%02d.pnm", turn); + std::snprintf(fn, 30, "gl841_offset2_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, second_line.data(), 16, channels, num_pixels, 1); } @@ -3792,8 +3791,8 @@ void CommandSetGl841::search_strip(Genesys_Device* dev, const Genesys_Sensor& se pass = 0; if (DBG_LEVEL >= DBG_data) { - sprintf(title, "gl841_search_strip_%s_%s%02u.pnm", black ? "black" : "white", - forward ? "fwd" : "bwd", pass); + std::sprintf(title, "gl841_search_strip_%s_%s%02u.pnm", black ? "black" : "white", + forward ? "fwd" : "bwd", pass); sanei_genesys_write_pnm_file(title, data.data(), session.params.depth, channels, pixels, lines); } @@ -3817,8 +3816,8 @@ void CommandSetGl841::search_strip(Genesys_Device* dev, const Genesys_Sensor& se if (DBG_LEVEL >= DBG_data) { - sprintf(title, "gl841_search_strip_%s_%s%02u.pnm", - black ? "black" : "white", forward ? "fwd" : "bwd", pass); + std::sprintf(title, "gl841_search_strip_%s_%s%02u.pnm", + black ? "black" : "white", forward ? "fwd" : "bwd", pass); sanei_genesys_write_pnm_file(title, data.data(), session.params.depth, channels, pixels, lines); } diff --git a/backend/genesys/gl843.cpp b/backend/genesys/gl843.cpp index 12cc42109..c04c2bd50 100644 --- a/backend/genesys/gl843.cpp +++ b/backend/genesys/gl843.cpp @@ -737,10 +737,9 @@ static void gl843_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); - for (i = 0; i < steps; i++) - { - sprintf (msg+strlen(msg), "%d", slope_table[i]); + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); + for (i = 0; i < steps; i++) { + std::sprintf (msg+strlen(msg), "%d", slope_table[i]); } DBG(DBG_io, "%s: %s\n", __func__, msg); } @@ -2425,7 +2424,7 @@ SensorExposure CommandSetGl843::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl843_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl843_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, image); } @@ -2630,8 +2629,8 @@ void CommandSetGl843::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[40]; - snprintf(fn, 40, "gl843_bottom_offset_%03d_%03d_%03d.pnm", - bottom[0], bottom[1], bottom[2]); + std::snprintf(fn, 40, "gl843_bottom_offset_%03d_%03d_%03d.pnm", + bottom[0], bottom[1], bottom[2]); sanei_genesys_write_pnm_file(fn, first_line); } @@ -2693,11 +2692,11 @@ void CommandSetGl843::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char title[100]; - snprintf(title, 100, "lines: %d pixels_per_line: %d offsets[0..2]: %d %d %d\n", - lines, pixels, - dev->frontend.get_offset(0), - dev->frontend.get_offset(1), - dev->frontend.get_offset(2)); + std::snprintf(title, 100, "lines: %d pixels_per_line: %d offsets[0..2]: %d %d %d\n", + lines, pixels, + dev->frontend.get_offset(0), + dev->frontend.get_offset(1), + dev->frontend.get_offset(2)); debug_image_info += title; std::copy(second_line.get_row_ptr(0), second_line.get_row_ptr(0) + second_line.get_row_bytes() * second_line.get_height(), @@ -3196,8 +3195,8 @@ void CommandSetGl843::search_strip(Genesys_Device* dev, const Genesys_Sensor& se if (DBG_LEVEL >= DBG_data) { char fn[40]; - snprintf(fn, 40, "gl843_search_strip_%s_%s%02d.pnm", - black ? "black" : "white", forward ? "fwd" : "bwd", pass); + std::snprintf(fn, 40, "gl843_search_strip_%s_%s%02d.pnm", + black ? "black" : "white", forward ? "fwd" : "bwd", pass); sanei_genesys_write_pnm_file(fn, data); } diff --git a/backend/genesys/gl846.cpp b/backend/genesys/gl846.cpp index becd75405..9994cb2b4 100644 --- a/backend/genesys/gl846.cpp +++ b/backend/genesys/gl846.cpp @@ -286,10 +286,10 @@ static void gl846_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); for (i = 0; i < steps; i++) { - sprintf (msg+strlen(msg), "%d", slope_table[i]); + std::sprintf(msg+strlen(msg), "%d", slope_table[i]); } DBG (DBG_io, "%s: %s\n", __func__, msg); } @@ -1577,7 +1577,7 @@ SensorExposure CommandSetGl846::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl846_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl846_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), session.params.depth, channels, num_pixels, 1); } @@ -2108,7 +2108,7 @@ void CommandSetGl846::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl846_offset%03d.pnm", bottom); + std::snprintf(fn, 30, "gl846_offset%03d.pnm", bottom); sanei_genesys_write_pnm_file(fn, first_line.data(), session.params.depth, channels, pixels, lines); } @@ -2150,7 +2150,7 @@ void CommandSetGl846::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl846_offset%03d.pnm", dev->frontend.get_offset(1)); + std::snprintf(fn, 30, "gl846_offset%03d.pnm", dev->frontend.get_offset(1)); sanei_genesys_write_pnm_file(fn, second_line.data(), session.params.depth, channels, pixels, lines); } diff --git a/backend/genesys/gl847.cpp b/backend/genesys/gl847.cpp index 6f23bdb2b..52fda7895 100644 --- a/backend/genesys/gl847.cpp +++ b/backend/genesys/gl847.cpp @@ -308,10 +308,10 @@ static void gl847_send_slope_table(Genesys_Device* dev, int table_nr, if (DBG_LEVEL >= DBG_io) { - sprintf (msg, "write slope %d (%d)=", table_nr, steps); + std::sprintf(msg, "write slope %d (%d)=", table_nr, steps); for (i = 0; i < steps; i++) { - sprintf (msg+strlen(msg), "%d", slope_table[i]); + std::sprintf(msg + std::strlen(msg), "%d", slope_table[i]); } DBG (DBG_io, "%s: %s\n", __func__, msg); } @@ -1610,7 +1610,7 @@ SensorExposure CommandSetGl847::led_calibration(Genesys_Device* dev, const Genes if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl847_led_%02d.pnm", turn); + std::snprintf(fn, 30, "gl847_led_%02d.pnm", turn); sanei_genesys_write_pnm_file(fn, line.data(), session.params.depth, channels, num_pixels, 1); } @@ -2174,7 +2174,7 @@ void CommandSetGl847::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl847_offset%03d.pnm", bottom); + std::snprintf(fn, 30, "gl847_offset%03d.pnm", bottom); sanei_genesys_write_pnm_file(fn, first_line.data(), session.params.depth, channels, pixels, lines); } @@ -2216,7 +2216,7 @@ void CommandSetGl847::offset_calibration(Genesys_Device* dev, const Genesys_Sens if (DBG_LEVEL >= DBG_data) { char fn[30]; - snprintf(fn, 30, "gl847_offset%03d.pnm", dev->frontend.get_offset(1)); + std::snprintf(fn, 30, "gl847_offset%03d.pnm", dev->frontend.get_offset(1)); sanei_genesys_write_pnm_file(fn, second_line.data(), session.params.depth, channels, pixels, lines); } diff --git a/backend/genesys/low.cpp b/backend/genesys/low.cpp index a7ee5caf3..bffec37fc 100644 --- a/backend/genesys/low.cpp +++ b/backend/genesys/low.cpp @@ -91,14 +91,12 @@ void sanei_genesys_init_cmd_set(Genesys_Device* dev) void sanei_genesys_write_file(const char* filename, const std::uint8_t* data, std::size_t length) { DBG_HELPER(dbg); - FILE *out; - - out = fopen (filename, "w"); + std::FILE* out = std::fopen(filename, "w"); if (!out) { throw SaneException("could not open %s for writing: %s", filename, strerror(errno)); } - fwrite(data, 1, length, out); - fclose(out); + std::fwrite(data, 1, length, out); + std::fclose(out); } // Write data to a pnm file (e.g. calibration). For debugging only