[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 252bd4e 2/2: New macro for ImageCrop's verbose
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 252bd4e 2/2: New macro for ImageCrop's verbose filename output |
Date: |
Wed, 3 Aug 2016 23:45:04 +0000 (UTC) |
branch: master
commit 252bd4ef2709264007ba7465483b501b063f3eb4
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
New macro for ImageCrop's verbose filename output
Besides the log-file, ImageCrop also prints the output file names on the
terminal in verbose mode. However, unlike the log-file, the terminal has a
limited width and to be readable, it is important for the verbose mode to
also manage the width of the things it prints. This had created bugs #46241
and #45380 which were fixed with the previous commit (cb9f299).
However, the buffer length until know was a hard-coded number (30) in the
code. So with this commit, that number is changed to a C Pre-Processor
macro which is configurable in 'src/imgcrop/main.h'.
Besides this macro a few other minor corrections were made:
- The variable that keeps the filename length was changed to
'outnamelen', from 'job_len'. The variable's properties have an 'out'
in their names and this would make the code easier to read.
- While the curly braces did follow the GNU style, their indentation and
that of the lines between them did not. So this was also corrected.
---
src/imgcrop/imgcrop.c | 39 ++++++++++++++++++++++++---------------
src/imgcrop/main.h | 16 ++++++++++++++++
2 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/src/imgcrop/imgcrop.c b/src/imgcrop/imgcrop.c
index 7094168..8868cbe 100644
--- a/src/imgcrop/imgcrop.c
+++ b/src/imgcrop/imgcrop.c
@@ -49,8 +49,8 @@ imgmodecrop(void *inparam)
struct imgcropparams *p=crp->p;
struct gal_commonparams *cp=&p->cp;
- size_t i, job_len;
int status;
+ size_t i, outnamelen;
struct inputimgs *img;
struct imgcroplog *log;
char msg[GAL_TIMING_VERB_MSG_LENGTH_V];
@@ -99,27 +99,36 @@ imgmodecrop(void *inparam)
}
else log->centerfilled=0;
- /* Write the log entry for this crop, in this mode, each output
- image was only cropped from one image. Then print the result
- on the terminal, if the user askd for it. */
+ /* Write the log entry for this crop, in this mode, each output image
+ was only cropped from one image. Then print the result on the
+ terminal, if the user asked for it.
+
+ A maximum length of FILENAME_BUFFER_IN_VERB characters is set for
+ the filename. This length is set to make the output on the user's
+ terminal reasonable (in one line). So when the filename is longer
+ than this, its first set of characters are truncated. In the
+ log-file there is no truncation, therefore the log file should be
+ used for checking the outputs, not the outputs printed on the
+ screen. */
if(cp->verb)
- {
- job_len = strlen(log->name);
- if (job_len > 30)
- sprintf(msg, "...%s %lu %d", &log->name[job_len-27], log->numimg,
- log->centerfilled);
- else
- sprintf(msg, "%-30s %lu %d", log->name, log->numimg,
- log->centerfilled);
- gal_timing_report(NULL, msg, 2);
- }
+ {
+ outnamelen = strlen(log->name);
+ if ( outnamelen > FILENAME_BUFFER_IN_VERB )
+ sprintf(msg, "...%s %lu %d",
+ &log->name[ outnamelen - FILENAME_BUFFER_IN_VERB + 3 ],
+ log->numimg, log->centerfilled);
+ else
+ sprintf(msg, "%-" MACROSTR(FILENAME_BUFFER_IN_VERB) "s %lu %d",
+ log->name, log->numimg, log->centerfilled);
+ gal_timing_report(NULL, msg, 2);
+ }
}
/* Close the input image. */
status=0;
if( fits_close_file(crp->infits, &status) )
gal_fits_io_error(status, "imgmode.c: imgcroponthreads could "
- "not close FITS file");
+ "not close FITS file");
/* Wait until all other threads finish. */
if(cp->numthreads>1)
diff --git a/src/imgcrop/main.h b/src/imgcrop/main.h
index b8c9be7..e6c0043 100644
--- a/src/imgcrop/main.h
+++ b/src/imgcrop/main.h
@@ -39,6 +39,22 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
+
+/* Set the maximum length given to a file name when run in verbose
+ mode. The STR macro function is used to convert the numerical macro
+ value into a string (which is necessary). STR_HELPER(x) uses the C
+ pre-processor's "stringification" functionality. See the
+ "Stringification" section of the GNU C Pre-Processor manual for a
+ thorough explanation. Note that this is part of the C standard, not just
+ GNU C. */
+#define STRINGIFY(x) #x
+#define MACROSTR(x) STRINGIFY(x)
+#define FILENAME_BUFFER_IN_VERB 30
+
+
+
+
+
/* Structure for the log file. Since we are operating in parallel
mode, writing to a file will significantly decrease the speed. So
we will make an array to keep the status of each output.*/