mirror of
https://github.com/fscotto/fsnap.git
synced 2026-11-26 11:19:52 +00:00
Name the parse-error status instead of repeating 128
The literal appeared in list.c and diff.c, was spelled out in prose in both their headers, and collided with an unrelated 128 in RecordObjectCompare, where it is an ordering sentinel for a NULL argument rather than a status. Introduce include/status.h with FSNAP_EPARSE, use it in both commands, and say in types.h that the value there means something else. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
#ifndef DIFF_H
|
#ifndef DIFF_H
|
||||||
#define DIFF_H
|
#define DIFF_H
|
||||||
|
|
||||||
|
#include "status.h"
|
||||||
|
|
||||||
/* Compare two snapshot files and print added/deleted/modified entries.
|
/* Compare two snapshot files and print added/deleted/modified entries.
|
||||||
Returns 0 on success, -1 on system/IO error, 128 on parse error. */
|
Returns 0 on success, -1 on system/IO error, FSNAP_EPARSE on parse error. */
|
||||||
int diff(const char *file1, const char *file2);
|
int diff(const char *file1, const char *file2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#ifndef LIST_H
|
#ifndef LIST_H
|
||||||
#define LIST_H
|
#define LIST_H
|
||||||
|
|
||||||
|
#include "status.h"
|
||||||
|
|
||||||
/* List all entries in a snapshot file.
|
/* List all entries in a snapshot file.
|
||||||
Returns 0 on success, -1 on system/IO error, 128 on parse error. */
|
Returns 0 on success, -1 on system/IO error, FSNAP_EPARSE on parse error. */
|
||||||
int list(const char *snapshot);
|
int list(const char *snapshot);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
13
include/status.h
Normal file
13
include/status.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef STATUS_H
|
||||||
|
#define STATUS_H
|
||||||
|
|
||||||
|
/* Command return values.
|
||||||
|
|
||||||
|
0 is success and -1 a system error, with errno set. FSNAP_EPARSE says the
|
||||||
|
input itself was malformed, which is the snapshot's problem rather than the
|
||||||
|
system's: errno carries nothing useful and the command has already written a
|
||||||
|
snapshot:line: diagnostic to stderr. main maps every failure to
|
||||||
|
EXIT_FAILURE, so the distinction is internal for now. */
|
||||||
|
enum { FSNAP_EPARSE = 128 };
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -38,8 +38,10 @@ int RecordObjectUnpack(struct RecordObject *self, char *s, enum Fields *err);
|
|||||||
int RecordObjectWrite(struct RecordObject *self, const char *path, FILE *out);
|
int RecordObjectWrite(struct RecordObject *self, const char *path, FILE *out);
|
||||||
|
|
||||||
/* Compare two RecordObjects field by field.
|
/* Compare two RecordObjects field by field.
|
||||||
Returns 0 if equal, a non-zero difference otherwise.
|
Returns 0 if equal, and an ordering like strcmp otherwise: negative if self
|
||||||
On NULL self returns 128, on NULL other returns 1.
|
sorts first, positive if other does. On NULL self returns 128 and on NULL
|
||||||
|
other 1; those are ordering sentinels, unrelated to the FSNAP_EPARSE command
|
||||||
|
status that happens to share the value.
|
||||||
If err is non-NULL, sets *err to the first differing field. */
|
If err is non-NULL, sets *err to the first differing field. */
|
||||||
int RecordObjectCompare(const struct RecordObject *self,
|
int RecordObjectCompare(const struct RecordObject *self,
|
||||||
const struct RecordObject *other, enum Fields *err);
|
const struct RecordObject *other, enum Fields *err);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Returns 0 on success, -1 on a system error, 128 on a malformed record. */
|
/* Returns 0 on success, -1 on a system error, FSNAP_EPARSE if malformed. */
|
||||||
static int load_in_memory(const char *file, struct RecordObject ***records,
|
static int load_in_memory(const char *file, struct RecordObject ***records,
|
||||||
int *count) {
|
int *count) {
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
@@ -64,7 +64,7 @@ static int load_in_memory(const char *file, struct RecordObject ***records,
|
|||||||
else
|
else
|
||||||
fprintf(stderr, "%s:%d: unparsable line\n", file, i + 1);
|
fprintf(stderr, "%s:%d: unparsable line\n", file, i + 1);
|
||||||
RecordObjectRelease(objp);
|
RecordObjectRelease(objp);
|
||||||
rc = 128;
|
rc = FSNAP_EPARSE;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ int list(const char *snapshot) {
|
|||||||
RecordObjectFieldName(err));
|
RecordObjectFieldName(err));
|
||||||
else
|
else
|
||||||
fprintf(stderr, "%s:%d: unparsable line\n", snapshot, i + 1);
|
fprintf(stderr, "%s:%d: unparsable line\n", snapshot, i + 1);
|
||||||
rc = 128;
|
rc = FSNAP_EPARSE;
|
||||||
RecordObjectRelease(objp);
|
RecordObjectRelease(objp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user