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

example_c_5.c

C example program for the Open-RJ core library. Demonstrates handling of a "failure to open file" error.

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        example_c_5.c
00003  *
00004  * Purpose:     C example program for the Open-RJ core library. Demonstrates
00005  *              handling of a "failure to open file" error.
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 
00034 int main()
00035 {
00036     unsigned            flags   =   0;
00037     ORJDatabase const   *db;
00038     ORJError            error;
00039     ORJRC               rc;
00040 
00041     /* 1. Create a database instance on memory, so use memory_database */
00042     rc = ORJ_ReadDatabase("|i|n|v|a|l|i|d|n|a|m|e|", NULL, flags, &db, &error);
00043 
00044     if(0 != rc)
00045     {
00046         char    message[1001];
00047 
00048         fprintf(stdout, "Display the error manually:\n");
00049         fprintf(stderr, "  Error at line %ld, column %ld: %s\n", (long)error.invalidLine, (long)error.invalidColumn, ORJ_GetErrorStringA(rc));
00050 
00051         fprintf(stdout, "Display the error using ORJ_FormatErrorA():\n");
00052         ORJ_FormatErrorA(&message[0], sizeof(message) / sizeof(0[message]), rc, &error, "  Error code %d means: %E\n", (int)rc);
00053         fprintf(stderr, message);
00054 
00055         return EXIT_FAILURE;
00056     }
00057     else
00058     {
00059         /* Finally, free the database */
00060         ORJ_FreeDatabase(db);
00061     }
00062 
00063     return EXIT_SUCCESS;
00064 }
00065 
00066 /* /////////////////////////////////////////////////////////////////////////////
00067  * end of file
00068  */

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