SDDS ToolKit Programs and Libraries for C and Python
All Classes Files Functions Variables Macros Pages
sddscheck.c File Reference

Detailed Description

Validates and checks an SDDS file for corruption or issues.

This program reads an SDDS (Self Describing Data Set) file and determines its validity. It processes the file by verifying its structure, pages, and data, and outputs the 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 contains errors.

Usage

sddscheck <filename> [-printErrors]

Options

Option Description
-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.

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

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 65 of file sddscheck.c.

65 {
66 SDDS_DATASET SDDS_input;
67 char *input;
68 long i_arg, retval, print_errors;
69 SCANNED_ARG *s_arg;
70
71 /* Register the program name for error reporting. */
73
74 /* Parse command-line arguments. */
75 argc = scanargs(&s_arg, argc, argv);
76 if (!s_arg || argc < 2) {
77 bomb(NULL, usage); /* Display usage and exit if arguments are insufficient. */
78 }
79
80 input = NULL;
81 print_errors = 0;
82
83 /* Process each command-line argument. */
84 for (i_arg = 1; i_arg < argc; i_arg++) {
85 if (s_arg[i_arg].arg_type == OPTION) {
86 /* Match recognized options. */
87 switch (match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0)) {
88 case CLO_PRINTERRORS:
89 print_errors = 1;
90 break;
91 default:
92 SDDS_Bomb("unknown option given"); /* Handle unrecognized options. */
93 break;
94 }
95 } else {
96 /* Assign the first non-option argument as the input file name. */
97 if (input == NULL)
98 input = s_arg[i_arg].list[0];
99 else
100 SDDS_Bomb("too many filenames"); /* Ensure only one input file is specified. */
101 }
102 }
103
104 /* Check if the input file exists. */
105 if (!fexists(input)) {
106 puts("nonexistent"); /* Indicate file does not exist. */
107 exit(0);
108 }
109
110 /* Initialize the SDDS input file. */
111 if (!SDDS_InitializeInput(&SDDS_input, input)) {
112 puts("badHeader"); /* Indicate the file header is invalid. */
113 if (print_errors)
114 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors); /* Print detailed errors if enabled. */
115 exit(0);
116 }
117
118 /* Read and process each page of the SDDS file. */
119 while ((retval = SDDS_ReadPage(&SDDS_input)) > 0) {
120 /* Loop continues until EOF or an error occurs. */
121 }
122
123 if (retval == -1) {
124 /* EOF reached successfully. */
125 puts("ok");
126 } else {
127 /* Handle file corruption or errors during processing. */
128 if (print_errors)
129 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
130 puts("corrupted");
131 }
132
133 return (0); /* Exit successfully. */
134}
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