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