00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <openrj/openrj.h>
00026
00027
00028 #include <assert.h>
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032
00033
00034
00035
00036
00037
00038 static const char contents[] =
00039
00040 "%% Sample Open-RJ database - Cats and Dogs\n"
00041 "%% Created: 28th September 2004\n"
00042 "%% Updated: 29th September 2004\n"
00043 "Name: Barney\n"
00044 "Species: Dog\n"
00045 "Breed: Bijon \\\n"
00046 " Frieze\n"
00047 "%%\n"
00048 "Name: Elsa\n"
00049 "Species: Dog\n"
00050 "Breed: Mixed\n"
00051 "%%\n"
00052 "Name: Fluffy Kitten\n"
00053 "Species: Cat\n"
00054 "%%\n"
00055 "Name: Moet\n"
00056 "Species: Dog\n"
00057 "Breed: Boxer\n"
00058 "%%\n"
00059 "Name: Rebel\n"
00060 "Species: Dog\n"
00061 "Breed: German \\\n"
00062 " Shepherd\n"
00063 "%%\n"
00064 "Name: Sparky\n"
00065 "Species: Cat\n"
00066 "%%\n";
00067
00068
00069
00070 int main()
00071 {
00072 unsigned flags = 0;
00073 ORJDatabase const *db;
00074 ORJError error;
00075 ORJRC rc;
00076
00077
00078 rc = ORJ_CreateDatabaseFromMemory(contents, sizeof(contents), NULL, flags, &db, &error);
00079
00080 if(0 != rc)
00081 {
00082 printf("Error at line %ld, column %ld: %s\n", (long)error.invalidLine, (long)error.invalidColumn, ORJ_GetErrorStringA(rc));
00083
00084 return EXIT_FAILURE;
00085 }
00086 else
00087 {
00088 size_t i;
00089
00090 printf("Enumerating all fields in the database:\n");
00091
00092 for(i = 0; i < db->numFields; ++i)
00093 {
00094 ORJField const *field;
00095
00096 rc = ORJ_Database_GetFieldA(db, i, &field);
00097
00098
00099
00100
00101
00102 assert(ORJ_RC_SUCCESS == rc);
00103
00104 printf(" %.*s=%.*s\n", (int)field->name.len, field->name.ptr, (int)field->value.len, field->value.ptr);
00105 }
00106
00107
00108 ORJ_FreeDatabase(db);
00109 }
00110
00111 return EXIT_SUCCESS;
00112 }
00113
00114
00115
00116