summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-08-13 17:22:20 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-08-13 17:30:57 -0700
commit4618f9dbbcb93805b64d86fae3a1ec82f8f6849b (patch)
treefe75672a9f32569c229268b8437976183e354ef9
parentce1a1d32f1dc4220a8b6d87d270120d69ba00509 (diff)
Reduce variable scopes as suggested by cppcheck
[showfont.c:170]: (style) The scope of the variable 'err' can be reduced. [showfont.c:172]: (style) The scope of the variable 'start' can be reduced. [showfont.c:179]: (style) The scope of the variable 'format' can be reduced. [showfont.c:380]: (style) The scope of the variable 'show_all' can be reduced. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--showfont.c46
1 files changed, 18 insertions, 28 deletions
diff --git a/showfont.c b/showfont.c
index e98f264..4e3b41f 100644
--- a/showfont.c
+++ b/showfont.c
@@ -167,21 +167,12 @@ show_glyphs(
FSChar2b last)
{
FSXCharInfo *extents;
- int err,
- ch,
- start;
int offset = 0;
unsigned char *glyphs;
FSOffset *offsets;
int scanpad;
- int r,
- b;
- FSBitmapFormat format;
FSChar2b chars[2];
int num_chars;
- int row,
- col,
- temp_ch;
if (show_all) {
num_chars = 0;
@@ -193,9 +184,9 @@ show_glyphs(
FSQueryXExtents16(svr, fid, True, chars, num_chars, &extents);
if (!extents_only) {
- format = make_format();
- err = FSQueryXBitmaps16(svr, fid, format, True, chars, num_chars,
- &offsets, &glyphs);
+ FSBitmapFormat format = make_format();
+ int err = FSQueryXBitmaps16(svr, fid, format, True, chars, num_chars,
+ &offsets, &glyphs);
if (err != FSSuccess) {
fprintf(stderr, "QueryGlyphs failed\n");
@@ -205,17 +196,17 @@ show_glyphs(
scanpad = scan_pad >> 3;
- for (row = (int)first.high; row <= (int)last.high; row++) {
- start = first.low + (row << 8);
- for (col = (int)first.low; col <= (int)last.low; col++) {
+ for (int row = (int)first.high; row <= (int)last.high; row++) {
+ int start = first.low + (row << 8);
+ for (int col = (int)first.low; col <= (int)last.low; col++) {
int bottom,
bpr,
charwidth;
- ch = ((row - (int)first.high)
- * ((int)last.low - (int)first.low + 1))
+ int ch = ((row - (int)first.high)
+ * ((int)last.low - (int)first.low + 1))
+ (col - (int)first.low);
- temp_ch = start + (col - (int)first.low);
+ int temp_ch = start + (col - (int)first.low);
printf("char #%d", temp_ch);
if ((temp_ch >= 0) && (temp_ch <= 127) && isprint(temp_ch))
printf(" '%c'\n", (char) (temp_ch));
@@ -261,10 +252,10 @@ show_glyphs(
bottom * bpr, bpr, bottom, offsets[ch].length);
}
offset = offsets[ch].position;
- for (r = 0; r < bottom; r++) {
+ for (int r = 0; r < bottom; r++) {
unsigned char *rowp = glyphs + offset;
- for (b = 0; b < charwidth; b++) {
+ for (int b = 0; b < charwidth; b++) {
putchar((rowp[b >> 3] &
(1 << (7 - (b & 7)))) ? '#' : '-');
}
@@ -286,12 +277,11 @@ show_props(
FSPropOffset *po,
unsigned char *pd)
{
- int i;
char buf[512];
int num_props;
num_props = pi->num_offsets;
- for (i = 0; i < num_props; i++, po++) {
+ for (int i = 0; i < num_props; i++, po++) {
strncpy(buf, (char *) (pd + po->name.position), po->name.length);
buf[po->name.length] = '\0';
printf("%s\t", buf);
@@ -369,19 +359,14 @@ main(int argc, char **argv)
{
const char *servername = "localhost:7100"; /* -server: font server name */
char *fontname = NULL; /* -fn: font name */
- int i;
Font fid,
dummy;
FSBitmapFormat format;
FSBitmapFormatMask fmask;
- FSChar2b first,
- last;
- FSXFontInfoHeader hdr;
- Bool show_all = True;
ProgramName = argv[0];
- for (i = 1; i < argc; i++) {
+ for (int i = 1; i < argc; i++) {
if (!strncmp(argv[i], "-se", 3)) {
if (++i < argc)
servername = argv[i];
@@ -460,6 +445,11 @@ main(int argc, char **argv)
BitmapFormatMaskScanLineUnit);
fid = FSOpenBitmapFont(svr, format, fmask, fontname, &dummy);
if (fid) {
+ Bool show_all = True;
+ FSChar2b first,
+ last;
+ FSXFontInfoHeader hdr;
+
printf("opened font %s\n", fontname);
show_info(fid, &hdr, &first, &last);
if (first_ch != 0 &&