diff --git a/dbfadd.c b/dbfadd.c index c5563e4..d51cc85 100644 --- a/dbfadd.c +++ b/dbfadd.c @@ -43,7 +43,10 @@ int main(int argc, char **argv) } const int iRecord = DBFGetRecordCount(hDBF); - + + SHPDate date; + char bool; + // Loop assigning the new field values. for (int i = 0; i < DBFGetFieldCount(hDBF); i++) { @@ -51,7 +54,22 @@ int main(int argc, char **argv) DBFWriteNULLAttribute(hDBF, iRecord, i); else if (DBFGetFieldInfo(hDBF, i, NULL, NULL, NULL) == FTString) DBFWriteStringAttribute(hDBF, iRecord, i, argv[i + 2]); + else if (DBFGetFieldInfo(hDBF, i, NULL, NULL, NULL) == FTDate) + { + if (3 == sscanf(argv[i + 2], "%4d%2d%2d", &date.year, &date.month, + &date.day)) + { + DBFWriteDateAttribute(hDBF, iRecord, i, &date); + } + } + else if (DBFGetFieldInfo(hDBF, i, NULL, NULL, NULL) == FTLogical) + { + if (1 == sscanf(argv[i + 2], "%c", &bool)) { + DBFWriteLogicalAttribute(hDBF, iRecord, i, bool); + } + } else + DBFWriteDoubleAttribute(hDBF, iRecord, i, atof(argv[i + 2])); } diff --git a/dbfcreate.c b/dbfcreate.c index 45affa0..1fc8e43 100644 --- a/dbfcreate.c +++ b/dbfcreate.c @@ -65,6 +65,32 @@ int main(int argc, char **argv) } i += 3; } + else if (i < argc - 1 && strcmp(argv[i], "-d") == 0) + { + const char *field = argv[i + 1]; + const int width = 8; + const int decimals = 0; + if (DBFAddField(hDBF, field, FTDate, width, decimals) == -1) + { + printf("DBFAddField(%s,FTDate,%d,0) failed.\n", field, width); + DBFClose(hDBF); + return 4; + } + i += 1; + } + else if (i < argc - 1 && strcmp(argv[i], "-l") == 0) + { + const char *field = argv[i + 1]; + const int width = 1; + const int decimals = 0; + if (DBFAddField(hDBF, field, FTLogical, width, decimals) == -1) + { + printf("DBFAddField(%s,FTLogical,%d,0) failed.\n", field, width); + DBFClose(hDBF); + return 4; + } + i += 1; + } else { printf("Argument incomplete, or unrecognised: %s\n", argv[i]); diff --git a/tests/expect3.out b/tests/expect3.out index 1ab8af4..0d89f1d 100644 --- a/tests/expect3.out +++ b/tests/expect3.out @@ -31,7 +31,7 @@ Shape:2 (Polygon) nVertices=4, nParts=1 (160,150, 0) (180,170, 0) (150,150, 0) -Descriptio TestInt TestDouble -Square with triangle missing 1 2.50000 -Smaller triangle 100 1000.25000 -(NULL) (NULL) (NULL) +Descriptio TestInt TestDouble TestDate TestBool +Square with triangle missing 1 2.50000 20241102 T +Smaller triangle 100 1000.25000 20241102 F +(NULL) (NULL) (NULL) (NULL) (NULL) diff --git a/tests/test3.sh b/tests/test3.sh index 8067e58..530b016 100755 --- a/tests/test3.sh +++ b/tests/test3.sh @@ -12,16 +12,16 @@ readonly EXPECT="${1:-$SCRIPTDIR/expect3.out}" { "${SHPCREATE:-./shpcreate}" test polygon -"${DBFCREATE:-./dbfcreate}" test.dbf -s Description 30 -n TestInt 6 0 -n TestDouble 16 5 +"${DBFCREATE:-./dbfcreate}" test.dbf -s Description 30 -n TestInt 6 0 -n TestDouble 16 5 -d TestDate -l TestBool "${SHPADD:-./shpadd}" test 0 0 100 0 100 100 0 100 0 0 + 20 20 20 30 30 30 20 20 -"${DBFADD:-./dbfadd}" test.dbf "Square with triangle missing" 1.4 2.5 +"${DBFADD:-./dbfadd}" test.dbf "Square with triangle missing" 1.4 2.5 20241102 T "${SHPADD:-./shpadd}" test 150 150 160 150 180 170 150 150 -"${DBFADD:-./dbfadd}" test.dbf "Smaller triangle" 100 1000.25 +"${DBFADD:-./dbfadd}" test.dbf "Smaller triangle" 100 1000.25 20241102 F "${SHPADD:-./shpadd}" test 150 150 160 150 180 170 150 150 -"${DBFADD:-./dbfadd}" test.dbf "" "" "" +"${DBFADD:-./dbfadd}" test.dbf "" "" "" "" "" "${SHPDUMP:-./shpdump}" test.shp "${DBFDUMP:-./dbfdump}" test.dbf