Commit | Line | Data |
---|---|---|
fc4ef1d0 C |
1 | /* entry_dump.c - routines to dump the database */ |
2 | ||
3 | #ifndef lint | |
4 | static char *rcsid = "$Header: /f/osi/quipu/RCS/entry_dump.c,v 7.3 91/03/09 11:56:50 mrose Exp $"; | |
5 | #endif | |
6 | ||
7 | /* | |
8 | * $Header: /f/osi/quipu/RCS/entry_dump.c,v 7.3 91/03/09 11:56:50 mrose Exp $ | |
9 | * | |
10 | * | |
11 | * $Log: entry_dump.c,v $ | |
12 | * Revision 7.3 91/03/09 11:56:50 mrose | |
13 | * update | |
14 | * | |
15 | * Revision 7.2 91/02/22 09:39:19 mrose | |
16 | * Interim 6.8 | |
17 | * | |
18 | * Revision 7.1 90/10/17 11:54:16 mrose | |
19 | * sync | |
20 | * | |
21 | * Revision 7.0 89/11/23 22:17:31 mrose | |
22 | * Release 6.0 | |
23 | * | |
24 | */ | |
25 | ||
26 | /* | |
27 | * NOTICE | |
28 | * | |
29 | * Acquisition, use, and distribution of this module and related | |
30 | * materials are subject to the restrictions of a license agreement. | |
31 | * Consult the Preface in the User's Manual for the full terms of | |
32 | * this agreement. | |
33 | * | |
34 | */ | |
35 | ||
36 | ||
37 | #include "quipu/util.h" | |
38 | #include "quipu/entry.h" | |
39 | #include <errno.h> | |
40 | #include "tailor.h" | |
41 | ||
42 | extern LLog * log_dsap; | |
43 | ||
44 | #ifndef TURBO_DISK | |
45 | ||
46 | extern RDN parse_rdn; | |
47 | extern char * new_version(); | |
48 | ||
49 | static header_print (psa,edb) | |
50 | PS psa; | |
51 | Entry edb; | |
52 | { | |
53 | switch (edb->e_data) { | |
54 | case E_DATA_MASTER: | |
55 | ps_print (psa,"MASTER\n"); | |
56 | break; | |
57 | case E_TYPE_SLAVE : | |
58 | ps_print (psa,"SLAVE\n"); | |
59 | break; | |
60 | default: | |
61 | ps_print (psa,"CACHE\n"); | |
62 | break; | |
63 | } | |
64 | if (edb->e_parent != NULLENTRY) | |
65 | ps_printf (psa,"%s\n",edb->e_parent->e_edbversion); | |
66 | else | |
67 | ps_printf (psa,"%s\n",new_version()); | |
68 | } | |
69 | ||
70 | static entry_print (psa,entryptr) | |
71 | PS psa; | |
72 | Entry entryptr; | |
73 | { | |
74 | rdn_print (psa,entryptr->e_name,EDBOUT); | |
75 | parse_rdn = entryptr->e_name; | |
76 | ps_print (psa,"\n"); | |
77 | as_print (psa,entryptr->e_attributes,EDBOUT); | |
78 | parse_rdn = NULLRDN; | |
79 | } | |
80 | ||
81 | ||
82 | static entry_block_print (psa,block) | |
83 | PS psa; | |
84 | Entry block; | |
85 | { | |
86 | Entry ptr; | |
87 | ||
88 | header_print (psa,block); | |
89 | ||
90 | if (block != NULLENTRY) { | |
91 | #ifdef TURBO_AVL | |
92 | for ( ptr = (Entry) avl_getfirst(block->e_parent->e_children); ptr != NULLENTRY; | |
93 | ptr = (Entry) avl_getnext()) { | |
94 | #else | |
95 | for ( ptr = block; ptr != NULLENTRY; ptr = ptr->e_sibling) { | |
96 | #endif | |
97 | if (ptr->e_data != E_TYPE_CONSTRUCTOR) { | |
98 | entry_print (psa,ptr); | |
99 | ps_print (psa,"\n"); | |
100 | } | |
101 | } | |
102 | } | |
103 | } | |
104 | ||
105 | write_edb (ptr,filename) | |
106 | Entry ptr; | |
107 | char * filename; | |
108 | { | |
109 | int um; | |
110 | FILE * fptr; | |
111 | PS entryps; | |
112 | extern char * parse_file; | |
113 | extern int errno; | |
114 | ||
115 | um = umask (0177); | |
116 | if ((fptr = fopen (filename,"w")) == (FILE *) NULL) { | |
117 | LLOG (log_dsap,LLOG_EXCEPTIONS,("file_open failed: \"%s\" (%d)",filename,errno)); | |
118 | return NOTOK; | |
119 | } | |
120 | (void) umask (um); | |
121 | ||
122 | if ((entryps = ps_alloc (std_open)) == NULLPS) { | |
123 | LLOG (log_dsap,LLOG_EXCEPTIONS,("ps_alloc failed")); | |
124 | (void) fclose (fptr); | |
125 | return NOTOK; | |
126 | } | |
127 | if (std_setup (entryps,fptr) == NOTOK) { | |
128 | LLOG (log_dsap,LLOG_EXCEPTIONS,("std_setup failed")); | |
129 | (void) fclose (fptr); | |
130 | return NOTOK; | |
131 | } | |
132 | ||
133 | parse_file = filename; | |
134 | ||
135 | entry_block_print (entryps,ptr); | |
136 | ||
137 | if (entryps->ps_errno != PS_ERR_NONE) { | |
138 | LLOG (log_dsap,LLOG_EXCEPTIONS,("write_edb ps error: %s",ps_error(entryps->ps_errno))); | |
139 | (void) fclose (fptr); | |
140 | return NOTOK; | |
141 | } | |
142 | ps_free (entryps); | |
143 | ||
144 | if (fflush (fptr) != 0) { | |
145 | LLOG (log_dsap,LLOG_EXCEPTIONS,("write_edb flush error: %d",errno)); | |
146 | return NOTOK; | |
147 | } | |
148 | if (fsync (fileno(fptr)) != 0) { | |
149 | LLOG (log_dsap,LLOG_EXCEPTIONS,("write_edb fsync error: %d",errno)); | |
150 | return NOTOK; | |
151 | } | |
152 | if (fclose (fptr) != 0) { | |
153 | LLOG (log_dsap,LLOG_EXCEPTIONS,("write_edb EDB close error: %d",errno)); | |
154 | return NOTOK; | |
155 | } | |
156 | ||
157 | LLOG (log_dsap,LLOG_NOTICE,("Written %s",filename)); | |
158 | ||
159 | return (OK); | |
160 | } | |
161 | ||
162 | #else | |
163 | ||
164 | write_edb() | |
165 | { | |
166 | LLOG (log_dsap,LLOG_FATAL,("write_edb implementation error")); | |
167 | } | |
168 | ||
169 | #endif /* NOT TURBO_DISK */ |