SDDSlib
Loading...
Searching...
No Matches
sddscheck.c File Reference

Validates and checks an SDDS file for corruption or issues. More...

#include "mdb.h"
#include "SDDS.h"
#include "scan.h"

Go to the source code of this file.

Macros

#define N_OPTIONS   1
 

Enumerations

enum  OptionType { CLO_PRINTERRORS = 0 }
 

Functions

int main (int argc, char **argv)
 

Variables

static char * option [N_OPTIONS]
 
char * usage
 

Detailed Description

Validates and checks an SDDS file for corruption or issues.

This program reads an SDDS file and outputs its status:

  • "ok" if the file is valid.
  • "nonexistent" if the file does not exist.
  • "badHeader" if the file has an invalid header.
  • "corrupted" if the file is corrupted.

Options: -printErrors: Outputs detailed error messages to stderr.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday

Definition in file sddscheck.c.

Macro Definition Documentation

◆ N_OPTIONS

#define N_OPTIONS   1

Definition at line 33 of file sddscheck.c.

Enumeration Type Documentation

◆ OptionType

enum OptionType

Definition at line 29 of file sddscheck.c.

29 {
30 CLO_PRINTERRORS = 0
OptionType
Enumeration for command-line options.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 55 of file sddscheck.c.

55 {
56 SDDS_DATASET SDDS_input;
57 char *input;
58 long i_arg, retval, print_errors;
59 SCANNED_ARG *s_arg;
60
61 /* Register the program name for error reporting. */
63
64 /* Parse command-line arguments. */
65 argc = scanargs(&s_arg, argc, argv);
66 if (!s_arg || argc < 2) {
67 bomb(NULL, usage); /* Display usage and exit if arguments are insufficient. */
68 }
69
70 input = NULL;
71 print_errors = 0;
72
73 /* Process each command-line argument. */
74 for (i_arg = 1; i_arg < argc; i_arg++) {
75 if (s_arg[i_arg].arg_type == OPTION) {
76 /* Match recognized options. */
77 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
78 case CLO_PRINTERRORS:
79 print_errors = 1;
80 break;
81 default:
82 SDDS_Bomb("unknown option given"); /* Handle unrecognized options. */
83 break;
84 }
85 } else {
86 /* Assign the first non-option argument as the input file name. */
87 if (input == NULL)
88 input = s_arg[i_arg].list[0];
89 else
90 SDDS_Bomb("too many filenames"); /* Ensure only one input file is specified. */
91 }
92 }
93
94 /* Check if the input file exists. */
95 if (!fexists(input)) {
96 puts("nonexistent"); /* Indicate file does not exist. */
97 exit(0);
98 }
99
100 /* Initialize the SDDS input file. */
101 if (!SDDS_InitializeInput(&SDDS_input, input)) {
102 puts("badHeader"); /* Indicate the file header is invalid. */
103 if (print_errors)
104 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors); /* Print detailed errors if enabled. */
105 exit(0);
106 }
107
108 /* Read and process each page of the SDDS file. */
109 while ((retval = SDDS_ReadPage(&SDDS_input)) > 0) {
110 /* Loop continues until EOF or an error occurs. */
111 }
112
113 if (retval == -1) {
114 /* EOF reached successfully. */
115 puts("ok");
116 } else {
117 /* Handle file corruption or errors during processing. */
118 if (print_errors)
119 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
120 puts("corrupted");
121 }
122
123 return (0); /* Exit successfully. */
124}
int32_t SDDS_InitializeInput(SDDS_DATASET *SDDS_dataset, char *filename)
Definition SDDS_input.c:49
int32_t SDDS_ReadPage(SDDS_DATASET *SDDS_dataset)
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
Definition SDDS_utils.c:432
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
Definition SDDS_utils.c:288
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
Definition bomb.c:26
long fexists(const char *filename)
Checks if a file exists.
Definition fexists.c:27
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
Definition scanargs.c:36

Variable Documentation

◆ option

char* option[N_OPTIONS]
static
Initial value:
= {
"printErrors"
}

Definition at line 35 of file sddscheck.c.

35 {
36 "printErrors"
37};

◆ usage

char* usage
Initial value:
=
"sddscheck <filename> [-printErrors]\n\n"
"This program allows you to determine whether an SDDS file has been\n"
"corrupted. It reads the entire file and prints a message to stdout.\n"
"\n"
"If the file is ok, \"ok\" is printed.\n"
"If the file has a problem, one of the following will be printed:\n"
" - \"nonexistent\": The file does not exist.\n"
" - \"badHeader\": The file header is invalid.\n"
" - \"corrupted\": The file contains errors.\n"
"\n"
"Options:\n"
" -printErrors: Deliver error messages to stderr.\n"
"\n"
"Program by Michael Borland. (" __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION ")\n"

Definition at line 39 of file sddscheck.c.