📄 wzoutput.cxx
字号:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <strstream.h>
#include "wzoutput.hxx"
wzOutput& wzOutput::Default = * new wzOutput(cerr);
wzOutput& wzOutput::Warning = * new wzOutput(cout);
wzOutput& wzOutput::Error = * new wzOutput(cerr);
const unsigned wzOutput::allocated = 1000;
const unsigned wzOutput::format_length = 256; //sizeof(wzOutput::Request[.]);
extern "C" void wzPrintDocumentationEntry(char* url)
{
char base[256],entry[256],*c;
int i=0;
c = url;
while(*c){
if(*c=='.'){c++; break;}
base[i++]=*c++;
}
base[i]='\0'; i=0;
while(*c){
if(*c=='#'){c++; break;}
c++;
}
while(*c){
entry[i++]=*c++;
}
entry[i]='\0';
wzPrintDocumentationEntry(wzOutput::Default,base,entry);
}
wzOutput& wzOutput::operator,(wzOutputItem p)
{return (*this)<<p;}
wzOutput& wzOutput::operator()(char *format)
{fullFormat = format; pos=0; return *this;}
wzOutput::wzOutput(ostream& stream)
:out(stream),fullFormat(""),pos(0),Flush(1),throw_data(0),throw_format(0)
{Request[0]='\0';}
wzOutput::wzOutput()
:out(cerr),fullFormat(""),pos(0),Flush(1),throw_data(0),throw_format(0)
{Request[0]='\0';}
static void wzOutputCall_wzColor_(void *o, char *t,unsigned m, char *f)
{((wzColor*)(o))->get(t);}
static void wzOutputCall_char_(void *o, char *t,unsigned m, char *f)
{sprintf(t,"%c",o);}
static void wzOutputCall_int_(void *o, char *t,unsigned m, char *f)
{sprintf(t,"%d",o);}
static void wzOutputCall_unsigned_(void *o, char *t,unsigned m, char *f)
{sprintf(t,"%u",o);}
static void wzOutputCall_float_(void *o, char *t,unsigned m, char *f)
{sprintf(t,"%g",*(float*)o);}
static void wzOutputCall_double_(void *o, char *t,unsigned m, char *f)
{sprintf(t,"%lf",*(double*)o);}
static void wzOutputCall_str_(void *o, char *t,unsigned m, char *f)
{sprintf(t,"%s",o);}
wzOutputItem::wzOutputItem(char c)
:object(*(void**)(int*)&c),output(wzOutputCall_char_)
{;}
wzOutputItem::wzOutputItem(int i)
:object(*(void**)(int*)&i),output(wzOutputCall_int_)
{;}
wzOutputItem::wzOutputItem(const wzColor& i)
:object((void*)&i),output(wzOutputCall_wzColor_)
{;}
wzOutputItem::wzOutputItem(unsigned i)
:object(*(void**)(int*)&i),output(wzOutputCall_unsigned_)
{;}
wzOutputItem::wzOutputItem(float f)
:object((void*)(float*)new float(f)),output(wzOutputCall_float_)
{;}
wzOutputItem::wzOutputItem(double f)
:object((void*)(double*)new double(f)),output(wzOutputCall_double_)
{;}
wzOutputItem::wzOutputItem(char* i)
:object(*(void**)(int*)&i),output(wzOutputCall_str_)
{;}
wzOutput& wzOutput::operator<<(wzOutputItem p)
{char c; int i=0,noformat=0,m,format_error=0,data_error=0;
char buffer[allocated];
c=fullFormat[pos];
while(c!='<'){
if(c=='\\') {pos++; c=fullFormat[pos];}
if(c=='\0') {if(noformat) break; pos=0; c=fullFormat[pos]; noformat=1;}
pos++; out<<c; c=fullFormat[pos];
}
if(c!='<'){
i = m = 0;
}else{
pos++;
m = atoi(&fullFormat[pos]);
if(m>0){while(m>9999){pos++;m = atoi(&fullFormat[pos]);}
if(m>999) pos++;
if(m>99) pos++;
if(m>9) pos++;
pos++;
}else{
m=0;
}
while(c=fullFormat[pos]){
if(c=='>') {pos++; break;}
if(c=='\\') pos++;
Request[i] = fullFormat[pos];
pos++; i++; if(i>=format_length) break;
}
}
Request[i]='\0';
try{
p.output(p.object,buffer,m,Request);
}catch(wzOutputFormatError){
format_error = 1;
}catch(...){
data_error = 1;
for(int j=0;j<4;j++) buffer[j]='*';
buffer[4]='\0';
}
if(m){
buffer[m]='\0';
i=0; while(buffer[i]){i++;} while(i<m){buffer[i]=' '; i++;}
}else{
buffer[allocated-1]='\0';
}
out<<buffer;
if(c!='>'){
out<<'\n';
}else if(Flush){
flush();
}
if(data_error && throw_data) {throw wzOutputDataError();}
if(format_error && throw_format) {throw wzOutputFormatError();}
return *this;
}
void wzOutput::flush()
{
char c=fullFormat[pos];
while(c!='<'){
if(c=='\\') {pos++; c=fullFormat[pos];}
if(c=='\0') {pos=0; break;}
pos++; out<<c; c=fullFormat[pos];
}
}
static const int buflen=10000;
static int recursive = 0;
void wzPrintDocumentationEntry(wzOutput& o, wzString p, wzString i)
{
char filename[1000], entry[]="NAME=\"", entryname[1000], buffer[buflen];
int istext=1;
FILE *ff;int ib,ie; char ce; int found=0;
sprintf(filename,"%s/%s.html",wzHomePath,p);
sprintf(entryname,"NAME=\"%s\"",i);
ff=fopen(filename,"r");
if(!ff){
if(recursive){
o("documentation not found in <>; check $COG_HOME\n")<<filename;
}else{
recursive=1;
o("documentation not found in <>;\n")<<filename;
wzPrintDocumentationEntry(o,"wzwarningtest","Documentation_Not_Found");
recursive=0;
}
return;
}
// o("--- extracted from <> ---\n")<<filename;
found=0;
while(!feof(ff)){
fgets(buffer,buflen,ff);
ib=0;ie=0;
while(ce=entryname[ie]){
if(buffer[ib]=='\0') break;
if(buffer[ib]!=ce) {ie=0;ib++;continue;}
ib++; ie++;
}
if(ce) continue;
found=1;
fgets(buffer,buflen,ff);
while(!feof(ff)){
ib=0;ie=0;
while(ce=entry[ie]){
if(buffer[ib]=='\0') break;
if(buffer[ib]!=ce) {ie=0;ib++;continue;}
ib++; ie++;
}
if(ce) {
ie = 0; o("<>");
while(ce=buffer[ie]){
if(ce=='<') istext = 0;
if(istext) o << ce;
if(ce=='>') istext = 1;
ie++;
}
fgets(buffer,buflen,ff);
continue;
}
break;
}
break;
}
if(!found){
if(recursive){
o("documentation entry <> not found in <>.html;\n")<<i,p;
}else{
recursive=1;
o("documentation entry <> not found in <>.html;\n")<<i,p;
wzPrintDocumentationEntry(o,"wzwarningtest","Documentation_Entry_Not_Found");
recursive=0;
}
}
o("---- for more see <> ----\n")<<filename;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -