nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 * 00004 * Copyright CEA/DAM/DIF (2008) 00005 * contributeur : Philippe DENIEL philippe.deniel@cea.fr 00006 * Thomas LEIBOVICI thomas.leibovici@cea.fr 00007 * 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 3 of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 * --------------------------------------- 00024 */ 00025 00026 #include "config.h" 00027 #include "analyse.h" 00028 #include <stdlib.h> 00029 #include <stdio.h> 00030 00031 #if HAVE_STRING_H 00032 # include <string.h> 00033 #endif 00034 00038 list_items *config_CreateItemsList() 00039 { 00040 list_items *new = (list_items *) malloc(sizeof(list_items)); 00041 00042 (*new) = NULL; 00043 return new; 00044 } 00045 00049 generic_item *config_CreateBlock(char *blockname, list_items * list) 00050 { 00051 generic_item *new = (generic_item *) malloc(sizeof(generic_item)); 00052 00053 new->type = TYPE_BLOCK; 00054 00055 strncpy(new->item.block.block_name, blockname, MAXSTRLEN); 00056 00057 if(list) 00058 { 00059 new->item.block.block_content = *list; 00060 free(list); 00061 } 00062 else 00063 new->item.block.block_content = NULL; 00064 00065 new->next = NULL; 00066 00067 return new; 00068 00069 } 00070 00074 generic_item *config_CreateAffect(char *varname, char *varval) 00075 { 00076 generic_item *new = (generic_item *) malloc(sizeof(generic_item)); 00077 00078 new->type = TYPE_AFFECT; 00079 strncpy(new->item.affect.varname, varname, MAXSTRLEN); 00080 strncpy(new->item.affect.varvalue, varval, MAXSTRLEN); 00081 00082 new->next = NULL; 00083 00084 return new; 00085 00086 } 00087 00091 void config_AddItem(list_items * list, generic_item * item) 00092 { 00093 if((*list) == NULL) 00094 { 00095 (*list) = item; 00096 } 00097 else 00098 { 00099 item->next = (*list); 00100 (*list) = item; 00101 } 00102 } 00103 00107 static void print_list_ident(FILE * output, list_items * list, unsigned int indent) 00108 { 00109 00110 generic_item *curr_item; 00111 00112 /* sanity check */ 00113 if(!list) 00114 return; 00115 00116 curr_item = (*list); 00117 00118 while(curr_item) 00119 { 00120 00121 if(curr_item->type == TYPE_BLOCK) 00122 { 00123 fprintf(output, "%*s<BLOCK '%s'>\n", indent, " ", 00124 curr_item->item.block.block_name); 00125 print_list_ident(output, &curr_item->item.block.block_content, indent + 3); 00126 fprintf(output, "%*s</BLOCK '%s'>\n", indent, " ", 00127 curr_item->item.block.block_name); 00128 } 00129 else 00130 { 00131 /* affectation */ 00132 fprintf(output, "%*sKEY: '%s', VALUE: '%s'\n", indent, " ", 00133 curr_item->item.affect.varname, curr_item->item.affect.varvalue); 00134 } 00135 00136 curr_item = curr_item->next; 00137 } 00138 00139 } 00140 00144 void config_print_list(FILE * output, list_items * list) 00145 { 00146 00147 print_list_ident(output, list, 0); 00148 00149 } 00150 00151 static void free_list_items_recurse(list_items * list) 00152 { 00153 generic_item *curr_item; 00154 generic_item *next_item; 00155 00156 /* sanity check */ 00157 if(!list) 00158 return; 00159 00160 curr_item = (*list); 00161 00162 while(curr_item) 00163 { 00164 00165 next_item = curr_item->next; 00166 00167 if(curr_item->type == TYPE_BLOCK) 00168 { 00169 free_list_items_recurse(&curr_item->item.block.block_content); 00170 } 00171 00172 free(curr_item); 00173 curr_item = next_item; 00174 00175 } 00176 return; 00177 } 00178 00183 void config_free_list(list_items * list) 00184 { 00185 00186 free_list_items_recurse(list); 00187 free(list); 00188 return; 00189 }