Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/errorlog.c
Parent Directory
|
Revision Log
Revision 1320 -
(show annotations)
(download)
(as text)
Tue May 14 18:57:52 2013 UTC (11 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 3257 byte(s)
Tue May 14 18:57:52 2013 UTC (11 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 3257 byte(s)
Copy errorlogx.h to errorlog.h and create errorlog.c so that they mirror the nodes.h and nodes.c filenames. Add functions to read in a set of error logs from a file.
1 | /*************************************** |
2 | Error log data type functions. |
3 | |
4 | Part of the Routino routing software. |
5 | ******************/ /****************** |
6 | This file Copyright 2013 Andrew M. Bishop |
7 | |
8 | This program is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU Affero General Public License as published by |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public License |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | ***************************************/ |
21 | |
22 | |
23 | #include <stdlib.h> |
24 | #include <math.h> |
25 | |
26 | #include "types.h" |
27 | #include "errorlog.h" |
28 | |
29 | #include "files.h" |
30 | |
31 | |
32 | /*++++++++++++++++++++++++++++++++++++++ |
33 | Load in an error log list from a file. |
34 | |
35 | ErrorLogs *LoadErrorLogs Returns the error log list. |
36 | |
37 | const char *filename The name of the file to load. |
38 | ++++++++++++++++++++++++++++++++++++++*/ |
39 | |
40 | ErrorLogs *LoadErrorLogs(const char *filename) |
41 | { |
42 | ErrorLogs *errorlogs; |
43 | |
44 | errorlogs=(ErrorLogs*)malloc(sizeof(ErrorLogs)); |
45 | |
46 | #if !SLIM |
47 | |
48 | errorlogs->data=MapFile(filename); |
49 | |
50 | /* Copy the ErrorLogsFile header structure from the loaded data */ |
51 | |
52 | errorlogs->file=*((ErrorLogsFile*)errorlogs->data); |
53 | |
54 | /* Set the pointers in the ErrorLogs structure. */ |
55 | |
56 | errorlogs->offsets =(index_t* )(errorlogs->data+sizeof(ErrorLogsFile)); |
57 | errorlogs->errorlogs_geo =(ErrorLog*)(errorlogs->data+sizeof(ErrorLogsFile)+(errorlogs->file.latbins*errorlogs->file.lonbins+1)*sizeof(index_t)); |
58 | errorlogs->errorlogs_nongeo=(ErrorLog*)(errorlogs->data+sizeof(ErrorLogsFile)+(errorlogs->file.latbins*errorlogs->file.lonbins+1)*sizeof(index_t)+errorlogs->file.number_geo*sizeof(ErrorLog)); |
59 | errorlogs->strings =(char* )(errorlogs->data+sizeof(ErrorLogsFile)+(errorlogs->file.latbins*errorlogs->file.lonbins+1)*sizeof(index_t)+errorlogs->file.number*sizeof(ErrorLog)); |
60 | |
61 | #else |
62 | |
63 | errorlogs->fd=ReOpenFile(filename); |
64 | |
65 | /* Copy the ErrorLogsFile header structure from the loaded data */ |
66 | |
67 | ReadFile(errorlogs->fd,&errorlogs->file,sizeof(ErrorLogsFile)); |
68 | |
69 | errorlogs->offsetsoffset =sizeof(ErrorLogsFile); |
70 | errorlogs->errorlogsoffset_geo =sizeof(ErrorLogsFile)+(errorlogs->file.latbins*errorlogs->file.lonbins+1)*sizeof(index_t); |
71 | errorlogs->errorlogsoffset_nongeo=sizeof(ErrorLogsFile)+(errorlogs->file.latbins*errorlogs->file.lonbins+1)*sizeof(index_t)+errorlogs->file.number_geo*sizeof(ErrorLog); |
72 | errorlogs->stringsoffset =sizeof(ErrorLogsFile)+(errorlogs->file.latbins*errorlogs->file.lonbins+1)*sizeof(index_t)+errorlogs->file.number*sizeof(ErrorLog); |
73 | |
74 | #endif |
75 | |
76 | return(errorlogs); |
77 | } |
78 | |
79 | |
80 | /*++++++++++++++++++++++++++++++++++++++ |
81 | Destroy the node list. |
82 | |
83 | ErrorLogs *errorlogs The node list to destroy. |
84 | ++++++++++++++++++++++++++++++++++++++*/ |
85 | |
86 | void DestroyErrorLogs(ErrorLogs *errorlogs) |
87 | { |
88 | #if !SLIM |
89 | |
90 | errorlogs->data=UnmapFile(errorlogs->data); |
91 | |
92 | #else |
93 | |
94 | errorlogs->fd=CloseFile(errorlogs->fd); |
95 | |
96 | #endif |
97 | |
98 | free(errorlogs); |
99 | } |