Skip to content

Commit

Permalink
Modify ncdump to print char-valued variables as utf8.
Browse files Browse the repository at this point in the history
re: Issue #2916

Currently, ncdump prints char-valued variables as a mix
of ascii and octal characters. The octal format is used
for non-printable ascii character values.

This PR changes this to print the char variable values
as raw binary. This means in practice that utf-8 tags
are properly interpreted and printed as utf-8.
  • Loading branch information
DennisHeimbigner committed May 7, 2024
1 parent e31e08f commit 211538c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

name: Run macOS-based netCDF Tests

on: [push,pull_request,workflow_dispatch]
on: [pull_request,workflow_dispatch]

concurrency:
group: ${{ github.workflow}}-${{ github.head_ref }}
Expand Down
157 changes: 0 additions & 157 deletions .github/workflows/run_tests_s3.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/run_tests_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

name: Run Ubuntu/Linux netCDF Tests

on: [push, pull_request, workflow_dispatch]
on: [ pull_request, workflow_dispatch]

concurrency:
group: ${{ github.workflow}}-${{ github.head_ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_win_cygwin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Run Cygwin-based tests

on: [push,pull_request,workflow_dispatch]
on: [pull_request,workflow_dispatch]

concurrency:
group: ${{ github.workflow}}-${{ github.head_ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_win_mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: Run MSYS2, MinGW64-based Tests (Not Visual Studio)
env:
CPPFLAGS: "-D_BSD_SOURCE"

on: [push,pull_request,workflow_dispatch]
on: [pull_request,workflow_dispatch]

concurrency:
group: ${{ github.workflow}}-${{ github.head_ref }}
Expand Down
15 changes: 12 additions & 3 deletions ncdump/vardata.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#include "vardata.h"
#include "netcdf_aux.h"

/* If set, then print char variables as utf-8.
If not set, then print non-printable characters as octal.
The latter was the default before this change.
*/
#define UTF8CHARS

/* maximum len of string needed for one value of a primitive type */
#define MAX_OUTPUT_LEN 100

Expand Down Expand Up @@ -340,6 +346,7 @@ pr_tvals(
sp = vals + len;
while (len != 0 && *--sp == '\0')
len--;
/* Walk the sequence of characters and write control characters in escape form. */
for (iel = 0; iel < len; iel++) {
unsigned char uc;
switch (uc = (unsigned char)(*vals++ & 0377)) {
Expand Down Expand Up @@ -371,10 +378,12 @@ pr_tvals(
printf("\\\"");
break;
default:
if (isprint(uc))
printf("%c",uc);
else
#ifdef UTF8CHARS
if (!isprint(uc))
printf("\\%.3o",uc);
else
#endif /*UTF8CHARS*/
printf("%c",uc);
break;
}
}
Expand Down

0 comments on commit 211538c

Please sign in to comment.