coan 4.2.4
|
00001 /*************************************************************************** 00002 * Copyright (C) 2004, 2006 Symbian Software Ltd. * 00003 * All rights reserved. * 00004 * * 00005 * Contributed originally by Mike Kinghan, imk@strudl.org * 00006 * * 00007 * Redistribution and use in source and binary forms, with or without * 00008 * modification, are permitted provided that the following conditions * 00009 * are met: * 00010 * * 00011 * Redistributions of source code must retain the above copyright * 00012 * notice, this list of conditions and the following disclaimer. * 00013 * * 00014 * Redistributions in binary form must reproduce the above copyright * 00015 * notice, this list of conditions and the following disclaimer in the * 00016 * documentation and/or other materials provided with the distribution. * 00017 * * 00018 * Neither the name of Symbian Software Ltd. nor the names of its * 00019 * contributors may be used to endorse or promote products derived from * 00020 * this software without specific prior written permission. * 00021 * * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * 00029 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * 00030 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,* 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * 00032 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 00033 * DAMAGE. * 00034 * * 00035 **************************************************************************/ 00036 00037 #include "report.h" 00038 #include "contradiction.h" 00039 #include "line_despatch.h" 00040 #include "if_control.h" 00041 #include "args.h" 00042 #include "io.h" 00043 #include "chew.h" 00044 #include "line_edit.h" 00045 #include "exception.h" 00046 #include "dataset.h" 00047 #include "configured_symbols.h" 00048 #include "unconfigured_symbols.h" 00049 #include "includes_tally.h" 00050 #include "line_select.h" 00051 00059 00061 static void ready(void); 00062 00064 static void process(void); 00065 00067 int 00068 main(int argc, char *argv[]) 00069 { 00070 ready(); 00071 atexit(exit_diagnostics); 00072 parse_executable(argv); 00073 parse_args(argc,argv); 00074 finish_args(); 00075 process(); 00076 give_up_confused(); /* bug*/ 00077 return 0; 00078 } 00079 00082 static void 00083 line_debug(int line) 00084 { 00085 if (line < 0) { 00086 /* Call with negative value to write line numbers*/ 00087 printf("%d\n",GET_PUBLIC(io,line_num)); 00088 } else if (line > 0 && line == GET_PUBLIC(io,line_num)) { 00089 /* Call with positive line number and put breakpoint here ...*/ 00090 fputs("Here\n",stderr); 00091 } 00092 } 00093 00094 static void 00095 ready(void) 00096 { 00097 INITIALISE(chew); 00098 INITIALISE(report); 00099 INITIALISE(evaluator); 00100 INITIALISE(if_control); 00101 INITIALISE(io); 00102 INITIALISE(dataset); 00103 INITIALISE(line_edit); 00104 INITIALISE(args); 00105 INITIALISE(configured_symbols); 00106 INITIALISE(unconfigured_symbols); 00107 INITIALISE(line_despatch); 00108 INITIALISE(contradiction); 00109 INITIALISE(includes_tally); 00110 INITIALISE(directives_tally); 00111 INITIALISE(line_select); 00112 } 00113 00128 static void 00129 node_proc( file_tree_h ft, 00130 char const *name, 00131 file_tree_traverse_state_t context) 00132 { 00133 static int error; 00134 switch(context) { 00135 case FT_AT_FILE: { 00136 line_type_t lineval; 00137 if_control_toplevel(); 00138 processing_file(name); 00139 open_io(name); 00140 chew_toplevel(); 00141 exceptions_enabled = true; 00142 error = catch(); 00143 for (; !error && (lineval = eval_line()) != LT_EOF;) { 00144 line_debug(0); 00145 if (lineval != LT_DIRECTIVE_DROP) { 00146 transition(lineval); 00147 } 00148 else { 00149 drop(); 00150 } 00151 debug(DBG_19,lineval); 00152 } 00153 exceptions_enabled = false; 00154 close_io(error); 00155 } 00156 break; 00157 case FT_ENTERING_DIR: { 00158 file_tree_count_t count; 00159 file_tree_count(ft,FT_COUNT_CHILDREN | FT_COUNT_ALL,&count); 00160 if_control_toplevel(); 00161 /* Don't report entry to a directory if it is merely 00162 the parent of another*/ 00163 if (count.dirs != 1 || count.files != 0) { 00164 entering_dir(name); 00165 } 00166 } 00167 break; 00168 case FT_LEAVING_DIR: { 00169 file_tree_count_t count; 00170 file_tree_count(ft,FT_COUNT_CHILDREN | FT_COUNT_ALL,&count); 00171 /* Don't report leaving a directory if it is merely 00172 the parent of another*/ 00173 if_control_toplevel(); 00174 if (count.dirs != 1 || count.files != 0) { 00175 leaving_dir(name); 00176 } 00177 } 00178 break; 00179 case FT_ENTERING_TREE: 00180 if (file_tree_is_empty(ft)) { 00181 node_proc(ft,STDIN_NAME,FT_AT_FILE); 00182 } 00183 break; 00184 case FT_LEAVING_TREE: 00185 io_toplevel(); 00186 break; 00187 default: 00188 assert(false); 00189 } 00190 } 00191 00192 static void 00193 process(void) 00194 { 00195 file_tree_h ft = GET_PUBLIC(dataset,file_tree); 00196 file_tree_traverse(ft,node_proc); 00197 exit(exitcode()); 00198 } 00199 00202 /* EOF*/