Open-RJ C/C++ User's Journal Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

example_c_7.c

C example program for the Open-RJ core library. Demonstrates processing of all database fields via structure members.

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        example_c_7.c
00003  *
00004  * Purpose:     C example program for the Open-RJ core library. Demonstrates
00005  *              processing of all database fields via structure members.
00006  *
00007  * Created:     12th May 2006
00008  * Updated:     28th May 2006
00009  *
00010  * www:         http://www.openrj.org/
00011  *
00012  * License:     Copyright (c) 2006, Synesis Software Pty Ltd.
00013  *              All rights reserved.
00014  *
00015  *              (Licensed under the Synesis Software Open License)
00016  *
00017  *              This source code is placed into the public domain 2006
00018  *              by Synesis Software Pty Ltd. There are no restrictions
00019  *              whatsoever to your use of the software.
00020  *
00021  * ////////////////////////////////////////////////////////////////////////// */
00022 
00023 
00024 /* Open-RJ Header Files */
00025 #include <openrj/openrj.h>
00026 
00027 /* Standard C Library Files */
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <string.h>
00031 
00032 /* /////////////////////////////////////////////////////////////////////////////
00033  * Globals
00034  */
00035 
00036 /* Sample database */
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     /* 1. Create a database instance on memory */
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         /* Free the database */
00099         ORJ_FreeDatabase(db);
00100     }
00101 
00102     return EXIT_SUCCESS;
00103 }
00104 
00105 /* /////////////////////////////////////////////////////////////////////////////
00106  * end of file
00107  */

Open-RJ Library documentation © Synesis Software Pty Ltd, 2004-2005