/* translation of file "error.k" */ /* generated by: * @(#)$Author: Kimwitu++ version 2.3.8 (C) 1998-2003 Humboldt-University of Berlin $ */ #define KC_FUNCTIONS_error_ #include #include "k.h" #include "error.h" namespace kc { } using namespace kc; /* included stuff */ // // The Termprocessor Kimwitu++ // // Copyright (C) 1991 University of Twente, Dept TIOS. // Copyright (C) 1998-2003 Humboldt-University of Berlin, Institute of Informatics // All rights reserved. // // Kimwitu++ is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // Kimwitu++ is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Kimwitu++; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // static char error_kAccesSid[] = "@(#)$Id: error.k,v 1.46 2003/09/26 09:04:15 piefel Exp $"; bool gp_no_fatal_problems; #define QUOTEDBACKSLASH '\\' #ifndef KC_MAX_STRING_LEN # define KC_MAX_STRING_LEN 200 #endif /* !KC_MAX_STRING_LEN */ viewnameoption ug_viewnameopt; int kc_filePrinter::indent_level = 4; kc_filePrinter::kc_filePrinter(FILE* f):file(f) { lineno=0; no_of_printed_string_chars=0; doit=false; lastChar='\n'; indent=0; bs_cnt=0; inString=false; inChar=false; inComment=false; inCppComment=false; spacePending=false; beginOfLine = false; keyword=0; indentKeyword=false; inPreProStmt=false; } kc_filePrinter v_stdout_printer(stdout); kc_filePrinter v_hfile_printer; kc_filePrinter v_ccfile_printer; printer_functor_class v_null_printer; bool kc_filePrinter::check_keyword(const char* s) { bool res=false; if(inPreProStmt) { // just to ignore #if and #else if(!isspace(*s)) inPreProStmt=false; } else if(!keyword) { if(*s=='#') inPreProStmt=true; else if(*s=='i' || *s=='e' || *s=='d' || *s=='w') // 'if', 'else', 'do', 'while' keyword=s; // 'for' not supported yet } else if(!isalnum(*s) && *s!='_') { // end of identifier ptrdiff_t length=s-keyword; if( (length==2 && strncmp(keyword,"if",length)==0) || (length==4 && strncmp(keyword,"else",length)==0) || (length==2 && strncmp(keyword,"do",length)==0) || (length==5 && strncmp(keyword,"while",length)==0)) res=true; // keyword found keyword=0; } return res; } void kc_filePrinter::operator()(const char *s, uview v) { char c; assertCond(file != 0); switch(v) { case view_no_of_printed_string_chars_reset_enum: no_of_printed_string_chars = 0; break; case view_printer_outputfileline_enum: fprintf( file, "\n" ); lineno = lineno +1; if(g_options.linedirec) fprintf( file, "%s %d \"%s%s\"\n", pg_line, lineno+1, g_options.dir_line.c_str(),filename.c_str() ); lineno = lineno +1; lastChar='\n'; break; default: while((c=*s++)) { switch( c ) { case '\0': return; case '\n': /* if (*s == QUOTEDBACKSLASH) s++; */ lineno = lineno +1; beginOfLine = true; /* FALLTHROUGH */ default: if (v == view_gen_unpstr_c) { if (no_of_printed_string_chars >= KC_MAX_STRING_LEN) { if (doit) { fprintf( file, "\"), " ); ug_viewnameopt->unparse( *this, view_gen_unparsedefs_other_c ); fprintf( file, " );\n kc_printer(kc_t(\"" ); lineno = lineno +1; no_of_printed_string_chars = 0; doit = false; } else { switch( c ) { case '\\': case '\n': break; default: doit = true; } } } no_of_printed_string_chars = no_of_printed_string_chars +1; } else if (v == view_filename) { /* duplicate (= escape) backslashes in file names. * we do this to help those that work on windows etc. */ if (c == QUOTEDBACKSLASH) { /* we have to quote it! */ putc( c, file ); } } if(inString) { if(c=='"' && bs_cnt%2==0) inString=false; putc( c, file ); lastChar=c; } else if(inChar) { if(c=='\'' && bs_cnt%2==0) inChar=false; putc( c, file ); lastChar=c; } else if(inComment) { if(c=='/' && lastChar=='*') inComment=false; /* C comments */ switch(c) { case '\v': case '\r': case '\b': break; default: putc( c, file ); lastChar=c; } } else if(inCppComment) { if(c=='\n') inCppComment=false; /* C++ comments */ switch(c) { case '\v': case '\r': case '\b': break; default: putc( c, file ); lastChar=c; } } else { int indent_offset=0; if(!indentKeyword) { indentKeyword=check_keyword(s-1); if(indentKeyword) ++indent; } switch(c) { case ';': if(indentKeyword) { --indent; indentKeyword=false; } goto default_case; case '{': if(indentKeyword) { --indent; indentKeyword=false; } // no break case '(': indent_offset=1; goto default_case; case '\v': ++indent; break; case '}': case ')': if(indent) --indent; goto default_case; case '\r': if(indent) --indent; break; case '\b': lastChar=c; break; case ' ': case '\t': if(lastChar=='\b' || !beginOfLine) goto default_case; if(isspace(lastChar)) break; if(isalnum(lastChar) || lastChar=='_' || lastChar=='"' || lastChar=='\'' || lastChar==')' || lastChar=='}') { if(isalnum(*(s+1))|| *(s+1)=='_'|| *(s+1)=='"' || *(s+1)=='\'') { c=' '; goto default_case; } spacePending=true; } break; default: default_case: if(lastChar=='\n' && c!='\n' && c!='#') { for(int i=indent*indent_level;i>0;) if(i>=8) { putc('\t',file); i-=8; } else { for(int k=0;kunparse( v_stderr_printer, v ); } else e->unparse( v_stderr_printer, view_error ); } static void v_stderr_printer(const char *s, uview v) { fflush( stdout ); fprintf( stderr, "%s", s ); fflush( stderr ); } } // namespace kc