Esempio n. 1
0
/*PLA V.88*/ 
#include ".\INCLUDE\CONST1.C"
#include ".\INCLUDE\VAR1.C"
#include ".\INCLUDE\DOS1.C"
int BCC=1; /*is Borland C, dann kein BSS */
unsigned char testa[]={148,153,129,154,0}; /*"öÖüÜ";*/
int test3( int i, unsigned int u){ 
_AX=0xB800;
}
char Nametemp[16];
int doglob() { int symlen; int j; int isstringarray; isstringarray=0;
  if (GTop >= GMAX) error1("Globale Tabelle voll");
  symlen = strlen1(symbol);
  if (symlen > 15 ) error1("Variable ist laenger als 15 Zeichen");
  if (istoken('[')) { istype='&';
    if (istoken(T_CONST)) {
      if (BCC == FALSE) {prs("\nAData = $\norg "); prnum(orgData);}
      prs("\n"); prs(symbol); 
      if (iswidth=='B') prs(" db "); else prs(" dw "); 
      prnum(lexval); prs(" dup (?)"); 
      if (BCC == FALSE) prs("\norg AData");
      orgData=orgData+lexval; if (iswidth=='W') orgData=orgData+lexval;
      GData[GTop]=lexval; expect(']'); 
    }else { expect(']');
      if (iswidth=='W') error1("Nur ByteArray erlaubt");
      prs("\n"); prs(symbol); prs(" db "); 
      isstringarray=1; strcpy1(Nametemp, symbol);
      expect('='); 
      if (istoken(T_STRING)) { 
        prc(34); prscomment(symbol); prc(34); prs(",0"); 
        symlen=strlen1(symbol); GData[GTop]=symlen; }
      else if (istoken('{' )) { narg=0;
        do { if(narg) prc(','); 
          expect(T_CONST); prnum(lexval); narg++; } 
        while (istoken(',')); expect('}'); }  
      else error1("String oder Zahlenarray erwartet");    
      }; 
  }else { expect('=');
    prs("\n"); prs(symbol); if (istype=='*') prs(" dw ");
    else { if(iswidth=='B') prs(" db "); else   prs(" dw "); }
    if(istoken('-')) prc('-');
    expect(T_CONST); prnum(lexval); }
  GSign [GTop]=issign; GWidth[GTop]=iswidth; GType [GTop]=istype;
  j=GTop*16; pt=&GNameField + j;  
  if (isstringarray) strcpy1(pt, Nametemp); else strcpy1(pt, symbol);
  GTop++; expect(';'); }
int addlocal() { int j;
  if(LTop >= LMAX) error1("Lokale Tabelle voll");
  GSign [LTop]=issign; GWidth[LTop]=iswidth; GType [LTop]=istype;
  j=LTop*16; pt=&GNameField + j;  
  strcpy1(pt, symbol);  LTop++; }
int gettypes(int i) {int j; char c;
  c=GSign [i]; if (c=='S') signi =1;    else signi =0;
  c=GWidth[i]; if (c=='W') widthi=wi=1; else widthi=wi=0;
  c=GType [i]; typei=0; if (c=='*') typei=wi=1; 
  if (c=='&')  typei=2;  
  return i; }  
int adrofname(int i) {int j; int k; j=i*16; k=&GNameField + j; return k; }  
int printName(int i) { i=adrofname(i); prs(i); }
int searchname() { int i; int j;
  i=LStart;while(i<LTop) {j=adrofname(i);if(eqstr(symbol,j))return i; i++;}
  i=0;     while(i<GTop) {j=adrofname(i);if(eqstr(symbol,j))return i; i++;}
  error1("Variable unbekannt"); }
    
int typeName() { int m; /*0=V,1=*,2=&*/
  issign='S';
  if(istoken(T_SIGNED))   issign='S';    if(istoken(T_UNSIGNED)) issign='U';
  if(istoken(T_VOID))     error1("Void ist unbekannt");
  iswidth='W';
  if(istoken(T_CHAR))     iswidth='B';   if(istoken(T_INT))      iswidth='W';
  istype='V'; m=0;
  if(istoken('*'))  { istype='*'; m=1; } if(istoken('&'))  { istype='&'; m=2; }   
  name1(); return m; }
int name1() {if (token!=T_NAME) error1("Name erwartet"); token=getlex(); }

int dofunc() { cloc=&co; strcpy1(fname, symbol);
  prs("\n\n"); prs(symbol); prs(" PROC");
  expect('('); narg=0; LTop=LStart;
  if (istoken(')')==0) { prs("\narg ");
    do { typeName();  addlocal();    
      if (narg) prc(','); prs(symbol); 
      if (istype!='*') {if (iswidth=='B') prs(":byte ");} narg++; }
    while (istoken(','));  expect(')'); }
  expect('{'); /*body*/
  nlocal=0; nreturn=0; nconst=0;
  if (isvariable()) prs("\nlocal ");
  while(isvariable()) {
    do { typeName();    addlocal();
      if (nlocal) prc(',');   prs(symbol); 
      if (istype!='*') {if (iswidth=='B') prs(":byte ");} nlocal++;
      if (istoken('[')){istype='&';GType[LTop]='&';expect(T_CONST);expect(']');
        prs(":BYTE:"); prnum(lexval);  }
      } while (istoken(',')); expect(';'); }
  while(istoken('}')==0)   stmt();
  if (nreturn) prs("\n@@retn:"); prs("\n ret\nENDP"); listproc(); }

int pexpr() {expect('('); iscmp=0; 
  if (token==T_NAME) {if (eqstr(symbol, "_")) {constantexpr(); return;}}   
  expr(); if (iscmp==0) prs("\n or  al, al\n je @@"); 
  expect(')'); }

int constantexpr() { int mode; int id1;int ids;
  token=getlex();   mode=typeName();  
  id1=searchname(); gettypes(id1); ids=signi;
  if (isrelational() ==0) error1("Vergleich erwartet");
  expect(T_CONST);
  prs("; constant expression");
  prs("\ncmp "); printName(id1); prs(", "); prnum(lexval); cmpneg(ids); 
   expect(')');
}  
int expr() { int mode; int id1; int ixarr; int ids;
  if (istoken(T_CONST)) {doconst(); return 1; }
  mode=typeName(); /*0=V,1=*,2=&*/
  if (token=='(')  {docall1(); goto e1; }
  if (isreg()) goto e1;
  id1=searchname(); gettypes(id1); ids=signi;
  ixarr=0;
  if (istoken('[')) { ixarr=searchname(); expect(T_NAME); expect(']');  
    gettypes(ixarr);
    if (widthi==0) error1("Arrayindex muss int sein"); } 
  if (istoken(T_PLUSPLUS  )) {if(mode)error1("Nur var erlaubt");doinc();goto e1;}
  if (istoken(T_MINUSMINUS)) {if(mode)error1("Nur var erlaubt");dodec();goto e1;}
  if (istoken(T_PLUSASS   )) {compoundass("add", mode); goto e1;}
  if (istoken(T_MINUSASS  )) {compoundass("sub", mode); goto e1;}
  if (istoken(T_ANDASS    )) {compoundass("and", mode); goto e1;}
  if (istoken(T_ORASS     )) {compoundass("or" , mode); goto e1;}    
  if (istoken(T_MULASS    )) {error1("nicht implementiert");}
  if (istoken(T_DIVASS    )) {error1("nicht implementiert");}      
  if (istoken('=')) { isconst=expr(); 
     if (isconst) { if(mode==0) {prs("\n;++++ mov  "); printName(id1); 
       prs(", "); prnum(lexval);  } }
     doassign(mode, id1, ixarr); goto e1;} 
  dovar1(mode, "mov", ixarr, id1);
e1:    if (istoken('+')) rterm("add");
  else if (istoken('-')) rterm("sub" );
  else if (istoken('&')) rterm("and" );
  else if (istoken('|')) rterm("or" );  
  else if (istoken(T_LESSLESS)) rterm("shl");
  else if (istoken(T_GREATGREAT)) rterm("shr");  
  else if (istoken('*')) domul (ids);
  else if (istoken('/')) doidiv(ids);
  else if (istoken('%')) domod (ids);
  if (isrelational()) { rterm("cmp"); cmpneg(ids);}
  return 0;
}
int compoundass(char *op, int mode) {
  if(mode) error1("Nur scalar Var erlaubt");
  prnl(); prs(op); prs("  "); prs(symbol); prs(", ");
  expect(T_CONST); prnum(lexval);
}
int dovar1(int mode, int op, int ixarr, int id1) { 
  gettypes(id1);
  if (mode==1) {prs("\n mov bx, "); printName(id1); prnl(); prs(op);
    if(widthi) prs(" ax, [bx]"); 
    else prs(" al, [bx]\n mov ah, 0"); return; }
  if (mode==2){prnl();prs(op);prs(" ax, offset ");printName(id1); return; }
  if (ixarr) {
    prs("\n mov bx, "); printName(ixarr);
    if (wi) prs("\n shl bx, 1");
    prs("\n "); prs(op);
    if (wi) prs(" ax, "); else prs(" al, ");
    printName(id1); prs(" [bx]"); return; }
  prnl();prs(op);
  if(wi) prs(" ax, "); else prs(" al, "); printName(id1);
}
int rterm(char *op) {int mode; int opint; int ixarr; int id1;
  if (istoken(T_CONST)) { prnl(); prs(op); 
    if (wi) prs(" ax, "); else prs(" al, "); prnum(lexval); return;}
  mode=typeName(); id1=searchname(); ixarr=0;
  if (istoken('[')) { ixarr=searchname(); expect(T_NAME); expect(']');  
    gettypes(ixarr);
    if (widthi==0) error1("Arrayindex muss int sein"); } 
  if (eqstr(symbol,"_AX")) return;
  opint=op; dovar1(mode, opint, ixarr, id1);
}
int isreg() {
  if (eqstr(symbol,"_AH")) {doreg("ah"); goto r1;}
  if (eqstr(symbol,"_AL")) {doreg("al"); goto r1;}  
  if (eqstr(symbol,"_AX")) {doreg("ax"); goto r1;}
  if (eqstr(symbol,"_BH")) {doreg("bh"); goto r1;}
  if (eqstr(symbol,"_BL")) {doreg("bl"); goto r1;}
  if (eqstr(symbol,"_BX")) {doreg("bx"); goto r1;}    
  if (eqstr(symbol,"_CH")) {doreg("ch"); goto r1;}
  if (eqstr(symbol,"_CL")) {doreg("cl"); goto r1;}
  if (eqstr(symbol,"_CX")) {doreg("cx"); goto r1;}    
  if (eqstr(symbol,"_DH")) {doreg("dh"); goto r1;}
  if (eqstr(symbol,"_DL")) {doreg("dl"); goto r1;}
  if (eqstr(symbol,"_DX")) {doreg("dx"); goto r1;}  
  if (eqstr(symbol,"_FLAGS")) {doreg("flags"); goto r1;}  
  return 0;   r1: return 1; 
}
int doreg(char *dr) { expect('=');
  prs("\n mov  "); prs(dr); prs(", ");
       if (istoken(T_CONST)) prunsign(lexval);
  else if (istoken(T_NAME )) {
    if (eqstr(symbol,"_DX")) prs("dx");
    else if (eqstr(symbol,"_CX")) prs("cx");
    else prs(symbol); }
  else error1("Nur Zahl oder Var erlaubt"); }

int doinc() { prs("\n inc  "); prs(symbol); }
int dodec() { prs("\n dec  "); prs(symbol); }

int doassign(int mode, int i, int ixarr) {
  gettypes(i);
  if (mode==1) {prs("\n mov  bx, ");printName(i);
    if (widthi) prs("\n mov  [bx], ax"); else  prs("\n mov  [bx], al"); return;}
  if (mode==2) {prs("\n mov  offset ");printName(i); prs(", ax"); return;}
  if (ixarr) {
    prs("\n mov bx, "); printName(ixarr);
    if (wi) prs("\n shl bx, 1");
    prs("\n mov "); printName(i);
    if (wi) prs(" [bx], ax"); else prs(" [bx], al"); return; }  
  prs("\n mov  "); printName(i); 
  if (wi) prs(", ax"); else prs(", al");  
}
int domul(int ids) {
  if (ids) rterm("imul"); else {
  if (istoken(T_CONST)) {prs("\n mov bx, "); prnum(lexval); prs("\n mul bx"); }
  else error1("Bei MUL nur Zahl als Multiplikator erlaubt"); } }
int doidiv(int ids) {
  if (istoken(T_CONST)) {
    prs("\n mov bx, "); prnum(lexval); 
    if (ids) prs("\n cwd\n idiv bx"); else prs("\n mov dx, 0\n div bx"); }
  else error1("Nur Zahl als Divisor erlaubt"); }
int domod(int ids) { doidiv(ids); prs("\n mov ax, dx"); }
int doconst() { prs("\n mov ax, "); prnum(lexval); }

int part1=0;int part2=0;int part3=0;int part4=0;int part5=0;int part6=0;
int parn1=0;int parn2=0;int parn3=0;int parn4=0;int parn5=0;int parn6=0; 
char procname[20]; /*1=CONST,2=String,3=&,4=Name*/
int docall1() {int i; int nargs; int t0; int n0; 
  nargs=0; strcpy1(&procname, symbol);expect('(');
	if (istoken(')') ==0 ) {
	  do { nargs++;
	    if (nargs >6 ) error1("Max. 6 Parameter");  t0=0;
      if(istoken(T_CONST)) {t0=1; n0=lexval; }
      if(istoken(T_STRING)){t0=2; n0=nconst;
        eprs("\n"); eprs(fname); eprc(95);eprnum(nconst);eprs(" db ");
        eprc(34);eprs(symbol);eprc(34);eprs(",0"); nconst++; }
      if(istoken('&'))     {t0=3; name1(); n0=searchname();}
      if(istoken(T_NAME))  {t0=4; n0=searchname();
        p1=&GType; p1=p1+n0; if (*p1=='&') t0=3; }
      if (t0==0) error1("Parameter nicht erkannt (kein * erlaubt)");
      if (nargs==1) {part1=t0; parn1=n0; } if (nargs==2) {part2=t0; parn2=n0; }
      if (nargs==3) {part3=t0; parn3=n0; } if (nargs==4) {part4=t0; parn4=n0; }  
      if (nargs==5) {part5=t0; parn5=n0; } if (nargs==6) {part6=t0; parn6=n0; }
    } while (istoken(','));
  	expect(')');  i=nargs;
    do {
      if (i==1) {t0=part1; n0=parn1; }     if (i==2) {t0=part2; n0=parn2; }
      if (i==3) {t0=part3; n0=parn3; }     if (i==4) {t0=part4; n0=parn4; }      
      if (i==5) {t0=part5; n0=parn5; }     if (i==6) {t0=part6; n0=parn6; }      
      if(t0==1){ prs("\n push "); prnum(n0);}
      if(t0==2){ prs("\n push offset "); prs(fname);prc(95);prnum(n0);}
      if(t0==3){ prs("\n lea  ax, "); printName(n0); prs("\n push ax");}
      if(t0==4){ gettypes(n0); 
        if(wi) { prs("\n push "); printName(n0);}
        else { prs("\n mov al, byte ptr "); printName(n0); 
        prs("\n mov ah, 0\n push ax"); } }
   i--; } while (i > 0);  }
	 prs("\n call "); prs(&procname);
	 if (nargs>0) {prs("\n add  sp, "); nargs=nargs+nargs; prnum(nargs); } }
Esempio n. 2
0
TEST( Buffer, copy_with_pos_b ) {
	std::string name1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
	std::string name2( "rako" );
	std::string name3( "otrodddd" );

	util::Buffer buf( name1.c_str(), (int)name1.length() );
	ASSERT_TRUE( buf.length() == (int)name1.length() );
	ASSERT_TRUE( buf.capacity() == (int)name1.length() );
	ASSERT_TRUE( buf.blockSize() == 0 );
	ASSERT_TRUE( buf.buffer() != NULL );

	buf.copy( name2.c_str(), (int)name2.length() );
	ASSERT_TRUE( buf.length() == (int)name2.length() );
	ASSERT_TRUE( buf.capacity() == (int)name1.length() );
	ASSERT_TRUE( buf.blockSize() == 0 );
	ASSERT_TRUE( buf.buffer() != NULL );
	ASSERT_TRUE( strncmp(buf.buffer(),name2.c_str(),(int)name2.length()) == 0 );

	buf.copy( buf.length()+5, name3.c_str(), (int)name3.length() );
	int s = (int)(name2.length()+name3.length()+5);
	ASSERT_TRUE( buf.length() == s );
	ASSERT_TRUE( buf.capacity() == (int)name1.length() );
	ASSERT_TRUE( buf.blockSize() == 0 );
	ASSERT_TRUE( buf.buffer() != NULL );
	ASSERT_TRUE( strncmp(buf.buffer(),"rakoaaaaaotrodddd",buf.length()) == 0 );
}
Esempio n. 3
0
int typeName() { int m; /*0=V,1=*,2=&*/
  issign='S';
  if(istoken(T_SIGNED))   issign='S';    if(istoken(T_UNSIGNED)) issign='U';
  if(istoken(T_VOID))     error1("Void ist unbekannt");
  iswidth='W';
  if(istoken(T_CHAR))     iswidth='B';   if(istoken(T_INT))      iswidth='W';
  istype='V'; m=0;
  if(istoken('*'))  { istype='*'; m=1; } if(istoken('&'))  { istype='&'; m=2; }   
  name1(); return m; }
Esempio n. 4
0
int get_file_name(const char *path,string& name)
{
	string file(path);
	int i  = file.find_last_of("//");
	i++;
	string name1(file,i,(file.length()-i));
	name=name1;
	return 0;
}/*
Esempio n. 5
0
int sc_main(int argc, char* argv[])
{
	Name            name(0);
	Name            name1("");
	NoName          no_name;

	cout << name.name() << endl;
	cout << name1.name() << endl;
	cout << no_name.name() << endl;
	cout << "Program completed" << endl;
	return 0;
}
Esempio n. 6
0
// If this FileDecoder is associated with a JAR file, make sure when
// we try to use the file handle, we always have an active
// JarFileParser. See JarFileParser.cpp header for the gory details.
void FileDecoder::guarantee_jar_file_handle() {
#ifdef AZZERT
  if (jar_file_name() != NULL) {
    int seen = false;
    ForAllHandles (oop) {
      if (oop->not_null() && oop->is_jar_file_parser()) {
        JarFileParser::Raw parser = oop->obj();
        TypeArray::Raw name1 = parser().pathname();
        TypeArray::Raw name2 = jar_file_name();
        int len1 = name1().length();
        int len2 = name2().length();
        void *base1 = name1().base_address();
        void *base2 = name2().base_address();

        GUARANTEE(len1 == len2 && jvm_memcmp(base1, base2, len1) == 0,
                  "Only one active JarFileParser at any time");
        seen = true;
      }
    }
    GUARANTEE(seen, "JarFileParser associated with this FileDecoder must be "
                    "active on C stack");
  }
Esempio n. 7
0
int stmt() { int c;
       if(istoken('{'))     {while(istoken('}')==0) stmt();}
  else if(istoken(T_IF))    doif();
  else if(istoken(T_DO))    dodo();
  else if(istoken(T_WHILE)) dowhile();
  else if(istoken(T_GOTO))  {prs("\n jmp @@");name1();prs(symbol);expect(';');}
  else if(token==T_ASM)     {prs("\n"); c=next();
    while(c != '\n') { prc(c);	c=next(); }; token=getlex(); }
  else if(istoken(T_ASMBLOCK)) {prs("\n"); expect('{'); c=next();
    while(c!= '}') { prc(c); c=next(); };   token=getlex(); }
  else if(istoken(T_EMIT))  doemit();
  else if(istoken(';'))     { }
  else if(istoken(T_RETURN)){if (token!=';') expr();
    prs("\n jmp @@retn"); nreturn++; expect(';'); }
  else if(thechar==':')     {prs("\n@@"); /*Label*/
     prs(symbol); prc(':'); expect(T_NAME); expect(':'); }
  else                      {expr(); expect(';'); } }
Esempio n. 8
0
void ReadAlignChunk::chunkFilesCat(ostream *allOut, string filePrefix, uint &iC) {//concatenates a file into main output
            while (true) {
                ostringstream name1("");
                name1 << filePrefix <<iC;
                ifstream fileChunkIn(name1.str().c_str());
                if (fileChunkIn.good()) {
                    *allOut << fileChunkIn.rdbuf();
                    allOut->flush();
                    allOut->clear();
                    fileChunkIn.close();
                    fileChunkIn.clear();
                    remove(name1.str().c_str());    
                    iC++;
                } else {
                    fileChunkIn.close();
                    break;
                };
            };
};
Esempio n. 9
0
TEST( Buffer, copy_with_pos_c ) {
	std::string name1( "123456789" );
	std::string name2( "1234" );
	std::string res( "121234789" );

	util::Buffer buf( name1.c_str(), name1.length() );
	ASSERT_TRUE( buf.length() == (int)name1.length() );
	ASSERT_TRUE( buf.capacity() == (int)name1.length() );
	ASSERT_TRUE( buf.blockSize() == 0 );
	ASSERT_TRUE( buf.buffer() != NULL );
	ASSERT_TRUE( strncmp(buf.buffer(),name1.c_str(),(int)name1.length()) == 0 );

	buf.copy( 2, name2.c_str(), name2.length() );
	ASSERT_TRUE( buf.length() == (int)res.length() );
	ASSERT_TRUE( buf.capacity() == (int)res.length() );
	ASSERT_TRUE( buf.blockSize() == 0 );
	ASSERT_TRUE( buf.buffer() != NULL );
	ASSERT_TRUE( strncmp(buf.buffer(),res.c_str(),buf.length()) == 0 );
}
Esempio n. 10
0
static int
LoadFile(const char *filename)
{
    std::ifstream stream;

    stream.open(filename);
    if (!stream)
        exit(1);
    while (!stream.eof()) {
        char s[1024];

        stream.getline(s, sizeof(s));
        if (s[0] == 0)
            break;
        std::string name1(s);
        size_t n = name1.find_last_of("/");
        std::string name = name1.substr(n + 1);
        g_Cache[std::string(filename)].insert(name);
    }
    return 0;
}
Esempio n. 11
0
    void PropertyTest::testCanCreatePropertiesOfDifferentTypes()
    {
        string name1("prop1");
        string name2("prop2");
        string name3("prop3");
        string name4("prop4");
        string name5("prop5");
        
        bool ok = true;
        string someValue("name");
        int integer = 34;
        double d = 45.24;
        DateTime now;

        Property<string, bool> prop1(name1, ok);
        CPPUNIT_ASSERT_EQUAL(ok, prop1());
        CPPUNIT_ASSERT_EQUAL(ok, prop1.getValue());
        CPPUNIT_ASSERT_EQUAL(name1, prop1.getName());

        Property<string, string> prop2(name2, someValue);
        CPPUNIT_ASSERT_EQUAL(someValue, prop2());
        CPPUNIT_ASSERT_EQUAL(someValue, prop2.getValue());
        CPPUNIT_ASSERT_EQUAL(name2, prop2.getName());

        Property<string, int> prop3(name3, integer);
        CPPUNIT_ASSERT_EQUAL(integer, prop3());
        CPPUNIT_ASSERT_EQUAL(integer, prop3.getValue());
        CPPUNIT_ASSERT_EQUAL(name3, prop3.getName());

        Property<string, double> prop4(name4, d);
        CPPUNIT_ASSERT_EQUAL(d, prop4());
        CPPUNIT_ASSERT_EQUAL(d, prop4.getValue());
        CPPUNIT_ASSERT_EQUAL(name4, prop4.getName());
        
        Property<string, DateTime> prop5(name5, now);
        CPPUNIT_ASSERT_EQUAL(now.utcTime(), prop5().utcTime());
        CPPUNIT_ASSERT_EQUAL(now.utcTime(), prop5.getValue().utcTime());
        CPPUNIT_ASSERT_EQUAL(name5, prop5.getName());
    }
Esempio n. 12
0
int main() {

	Room* B111 = new Room("B111");
	Time atime;
	atime.d_year = 2015;
	atime.d_month = 9; 
	atime.d_day = 14;
	atime.d_hour = 4; 
	atime.d_minutes = 10;
	const char *names[] = { "Rodger", "Kate", "Willie", "Ben", "Brian" };
	vector<string> name1(names, end(names));
	vector<string> name2(names, end(names));
	vector<string> name3(names, end(names));
	vector<string> name4(names, end(names));
	vector<string> name5(names, end(names));
 	B111->add(new Meeting(true, name1, "Assignment1", atime, 56, 5));
	B111->print();
	B111->add(new Meeting(true, name2, "Midtern" , atime, 66, 0));
	B111->print();
	B111->add(new Meeting(true, name3, "FinalExam ", atime, 67, 7));
	B111->print();
	B111->add(new Meeting(true, name4, "Faculty Meeting", atime, 69, 3));
	B111->print();
	B111->add(new Meeting(true, name5, "TA Meeting ", atime, 70, 0));
	B111->print();
	Room* A111 = new Room("A111");
	B111 = new Room(*A111);
	B111->setName("B111");
	Meeting* getTogether = new Meeting(true, name2, "Assigment2", atime, 34, 0); 
	B111->add(getTogether); 
	B111->print(); 
	A111->print();
	delete A111; 
	B111->print();
	delete B111; 

	system("pause");
}
Esempio n. 13
0
int test_pair3()
{
	std::pair<std::string, int> name1("Som", 15);
	std::pair<std::string, int> name2(name1);
	std::cout << "name2: " << name2.first << "    " << name2.second << std::endl;
	
	std::pair<std::string, int> name3 = std::make_pair("Som", 15);
	if (name1 == name3) {
		std::cout << "they are the same people" << std::endl;
	} else {
		std::cout << "they are not the same people" << std::endl;
	}

	std::pair<std::string, int> name4;
	name4 = name1;
	std::cout << "name4: " << name4.first << "    " << name4.second << std::endl;

	std::pair<std::string, int> name5("Som", 16);
	if (name1 > name5) {
		std::cout << "name1 > name5" << std::endl;
	} else if (name1 < name5) {
		std::cout << "name1 < name5" << std::endl;
	} else {
		std::cout << "name1 == name5" << std::endl;
	}

	std::pair<std::string, int> name6("Take", 11);
	std::cout << "name1: " << name1.first << "    " << name1.second << std::endl;
	std::cout << "name6: " << name6.first << "    " << name6.second << std::endl;
	std::swap(name1, name6); // C++11::endl;
	std::cout << "after std::swap: " << std::endl;
	std::cout << "name1: " << name1.first << "    " << name1.second << std::endl;
	std::cout << "name6: " << name6.first << "    " << name6.second << std::endl;

	return 0;
}
Esempio n. 14
0
bool NMCFile::loadFile(const std::string& filename)
{
	FILE* handle = NULL;

	try{
		handle = fopen(filename.c_str(), "rb");
		if(handle == NULL) return false;

		std::unique_ptr<char> name1(new char[33]); // US-ASCII chars
		std::unique_ptr<char> name2(new char[33]);
		unsigned int len = 0;

		if(fread(name1.get(), sizeof(char), 32, handle) != 32){
			fclose(handle);
			return false;
		}

		if(fread(name2.get(), sizeof(char), 32, handle) != 32){
			fclose(handle);
			return false;
		}

		if(fread(&len, sizeof(unsigned int), 1, handle) != 1){ // assumes little endianess here...
			fclose(handle);
			return false;
		}

		if(len > 10000){ // sanity check [in practice values must be always "small"]
			fclose(handle);
			return false;
		}

		name1.get()[32] = '\0';
		name2.get()[32] = '\0';

		// next we read actual "program" data (floats)

		std::unique_ptr<float> program1(new float[len]); // 32bit floats [little endian]
		std::unique_ptr<float> program2(new float[len]);

		if(fread(program1.get(), sizeof(float), len, handle) != len){
			fclose(handle);
			return false;
		}

		if(fread(program2.get(), sizeof(float), len, handle) != len){
			fclose(handle);
			return false;
		}

		// all data has been successfully read, stores values to internal class variables
		signalName[0] = std::string(name1.get());
		signalName[1] = std::string(name2.get());

		// trimming
		signalName[0].erase(signalName[0].find_last_not_of(" ")+1);
		signalName[1].erase(signalName[1].find_last_not_of(" ")+1);

		program[0].resize(len);
		program[1].resize(len);

		for(unsigned int i=0;i<len;i++){
			program[0][i] = program1.get()[i];
			program[1][i] = program2.get()[i];
		}

		fclose(handle);
		return true;
	}
	catch(std::exception& e){
		return false;
	}



}
Esempio n. 15
0
void ReadAlignChunk::mapChunk() {//map one chunk. Input reads stream has to be setup in RA->readInStream[ii]
    RA->statsRA.resetN();       
    
    for (uint ii=0;ii<P->readNmates;ii++) {//clear eof and rewind the input streams
        RA->readInStream[ii]->clear();
        RA->readInStream[ii]->seekg(0,ios::beg);
    };
    
    if ( P->outSAMorder == "PairedKeepInputOrder" && P->runThreadN>1 ) {//open chunk file
        ostringstream name1("");
        name1 << P->outFileTmp + "/Aligned.tmp.sam.chunk"<<iChunkIn;
        chunkOutBAMfileName = name1.str();
        chunkOutBAMfile.open(chunkOutBAMfileName.c_str());
    };    
    
    int readStatus=0;
    while (readStatus==0) {//main cycle over all reads

        readStatus=RA->oneRead(); //map one read

        if (readStatus==0) {//there was a read processed
            RA->iRead++;
//         chunkOutBAMtotal=(uint) RA->outSAMstream->tellp();
            chunkOutBAMtotal+=RA->outBAMbytes;
            chunkOutBAMtotal1+=RA->outBAMbytes1;
//             uint ddd=(uint) RA->outSAMstream->tellp();            
        };

        //write SAM aligns to chunk buffer 
        if (P->outSAMbool) {
            if ( chunkOutBAMtotal > P->chunkOutBAMsizeBytes ) {//this should not happen!
                ostringstream errOut;
                errOut <<"EXITING because of fatal error: buffer size for SAM/BAM output is too small\n";
                errOut <<"Solution: increase input parameter --limitOutSAMoneReadBytes\n";
                exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_INPUT_FILES, *P);                      
            } else if ( chunkOutBAMtotal + P->limitOutSAMoneReadBytes > P->chunkOutBAMsizeBytes || (readStatus==-1 && noReadsLeft) ) {//write buffer to disk because it's almost full, or all reads are mapped
                if ( P->outSAMorder == "PairedKeepInputOrder" && P->runThreadN>1 ) {//output chunks into separate files
                    chunkOutBAMfile.write(chunkOutBAM,chunkOutBAMtotal);
                    chunkOutBAMfile.clear(); //in case 0 bytes were written which could set fail bit
                } else {//standard way, directly into Aligned.out.sam file
                    //SAM output
                    if (P->runThreadN>1) pthread_mutex_lock(&g_threadChunks.mutexOutSAM);    
                    P->inOut->outSAM->write(chunkOutBAM,chunkOutBAMtotal);
                    P->inOut->outSAM->clear();//in case 0 bytes were written which could set fail bit
                    if (P->runThreadN>1) pthread_mutex_unlock(&g_threadChunks.mutexOutSAM);
                };
                RA->outSAMstream->seekp(0,ios::beg); //rewind the chunk storage
                chunkOutBAMtotal=0;
            }; 
        };
        
        //collapse SJ buffer if needed
        if ( chunkOutSJ->N > P->limitOutSJcollapsed ) {//this means the number of collapsed junctions is larger than the chunks size
            ostringstream errOut;
            errOut <<"EXITING because of fatal error: buffer size for SJ output is too small\n";
            errOut <<"Solution: increase input parameter --limitOutSJoneRead\n";
            exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_INPUT_FILES, *P);                      
        } else if ( chunkOutSJ->N + P->limitOutSJoneRead > P->limitOutSJcollapsed || (readStatus==-1 && noReadsLeft) ) {//write buffer to disk because it's almost full, or all reads are mapped
            chunkOutSJ->collapseSJ();
            if ( chunkOutSJ->N + 2*P->limitOutSJoneRead > P->limitOutSJcollapsed ) {
                ostringstream errOut;
                errOut <<"EXITING because of fatal error: buffer size for SJ output is too small\n";
                errOut <<"Solution: increase input parameter --limitOutSJcollapsed\n";
                exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_INPUT_FILES, *P);                      
            };
        };            

        //collapse SJ1 buffer if needed
        if ( chunkOutSJ1->N > P->limitOutSJcollapsed ) {//this means the number of collapsed junctions is larger than the chunks size
            ostringstream errOut;
            errOut <<"EXITING because of fatal error: buffer size for SJ output is too small\n";
            errOut <<"Solution: increase input parameter --limitOutSJoneRead\n";
            exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_INPUT_FILES, *P);                      
        } else if ( chunkOutSJ1->N + P->limitOutSJoneRead > P->limitOutSJcollapsed || (readStatus==-1 && noReadsLeft) ) {//write buffer to disk because it's almost full, or all reads are mapped
            chunkOutSJ1->collapseSJ();
            if ( chunkOutSJ1->N + 2*P->limitOutSJoneRead > P->limitOutSJcollapsed ) {
                ostringstream errOut;
                errOut <<"EXITING because of fatal error: buffer size for SJ output is too small\n";
                errOut <<"Solution: increase input parameter --limitOutSJcollapsed\n";
                exitWithError(errOut.str(),std::cerr, P->inOut->logMain, EXIT_CODE_INPUT_FILES, *P);                      
            };
        };            

    }; //reads cycle

    if ( P->outSAMorder == "PairedKeepInputOrder" && P->runThreadN>1 ) {//write the remaining part of the buffer, close and rename chunk files
        chunkOutBAMfile.write(chunkOutBAM,chunkOutBAMtotal);
        chunkOutBAMfile.clear(); //in case 0 bytes were written which could set fail bit
        chunkOutBAMfile.close();
        RA->outSAMstream->seekp(0,ios::beg); //rewind the chunk storage
        chunkOutBAMtotal=0;
        ostringstream name2("");
        name2 << P->outFileTmp + "/Aligned.out.sam.chunk"<<iChunkIn;                
        rename(chunkOutBAMfileName.c_str(),name2.str().c_str());//marks files as completedly written
    };    
    
    //add stats, write progress if needed
    if (P->runThreadN>1) pthread_mutex_lock(&g_threadChunks.mutexStats);
    g_statsAll.addStats(RA->statsRA);
    g_statsAll.progressReport(P->inOut->logProgress);
    if (P->runThreadN>1) pthread_mutex_unlock(&g_threadChunks.mutexStats); 
};            
Esempio n. 16
0
/*static*/
int
mail_address::ExtractAddresses(const char* addr,
			       std::list<QString>& result,
			       std::list<QString>& result1)
{
  if (!addr)	// happens if addr is the result of QString::null.latin1();
    return 0;

  // result => emails
  // result1 => names
  const char* start_addr;
  const char* start1_addr;
  const char* end_addr;
  const char* end1_addr;
  int c;
  char enclose_char=0;

  int err=0;
  c=*addr++;
  while (c) {
    switch(c) {
    case ' ':
    case '\t':
    case '\n':
    case '\r':
    case ',':
      c=*addr++;
      break;			// address separator
    case '\0':
      break;
    case '<':
      // <*****@*****.**> expected
      start_addr=addr;
      c=*addr++;
      while (c && c!=' ' && c!='\t' && c!='>')
	c=*addr++;
      switch(c) {
      case '>':
	result.push_back (part_string (start_addr, addr-start_addr-1));
	result1.push_back(QString(""));
	c=*addr++;
	break;
      default:
	err=1;
	return err;
      }
      break;
    case '\'':
    case '"':
      enclose_char=c;
      start1_addr=addr;
      c=*addr++;
      while (c && c!=enclose_char)
	c=*addr++;
      if (!c) {
	err=1;
	return err;
      }
      result1.push_back (part_string (start1_addr,addr-start1_addr-1));
      c=*addr++;
      while (c==' ' || c=='\t')
	c=*addr++;
      if (!c) {			// empty address: \".*\"([ \t])*
	result.push_back(QString(""));
	break;
      }
      if (c!='<') {
	//err=2;  // "foo bar" not followed by <*****@*****.**>
	//return err;
	while ((c=*(++addr))!='<') {
	  if (!c) {
	    err=2;
	    return err;
	  }
	}
	addr++;
      }
      start_addr=addr;
      c=*addr++;
      while (c && c!='>')
	c=*addr++;
      if (!c) {
	err=1;
	return err;
      }
      result.push_back (part_string (start_addr, addr-start_addr-1));
      c=*addr++;
      break;
    default:
      int enclose=0; //(c=='\'');
      start_addr=addr-1;
      start1_addr=addr-1;
      c=*addr++;
      while (c && (enclose || c!=' ') && c!='\t' && c!=',') // && c!='\'')
	c=*addr++;
      if (!c || c==',') {
	// email alone
	result.push_back(part_string (start_addr, addr-start_addr-1));
	result1.push_back(QString(""));
      }
      else {
	//  'Name firstname <email>' or 'email (name firstname)'
	// addr
	end_addr = addr;
	c=*addr++;
	while (c==' ' || c=='\t')
	  c=*addr++;
	switch(c) {
	case '\0':
	  err=1;
	  return err;
	case '<':
	  {
	    QString name1(start1_addr);
	    name1.truncate(addr-start1_addr-1);
	    // strip trailing white spaces from the name
	    result1.push_back (name1.trimmed());
	  }
	  start_addr=addr;
	  c=*addr++;
	  while (c && c!='>')
	    c=*addr++;
	  if (!c) {
	    err=1;
	    return err;
	  }
	  result.push_back (part_string (start_addr, addr-start_addr-1));
	  c=*addr++;
	  break;
	case '(':
	  start1_addr=addr;
	  c=*addr++;
	  while (c && c!=')')
	    c=*addr++;
	  if (!c) {
	    err=1;
	    return err;
	  }
	  result.push_back(part_string(start_addr,end_addr-start_addr-1));
	  result1.push_back(part_string (start1_addr, addr-start1_addr-1));
	  c=*addr++;
	  break;
	default:	// Name firstname <email>
	  c=*addr++;
	  while (c && c!='<')
	    c=*addr++;
	  if (!c) {
	    err=1;
	    return err;
	  }
	  end1_addr=addr-1;
	  start_addr=addr;
	  c=*addr++;
	  while (c && c!='>')
	    c=*addr++;
	  if (!c) {
	    err=1;
	    return err;
	  }
	  result.push_back(part_string(start_addr,addr-start_addr-1));
	  result1.push_back(part_string(start1_addr, end1_addr-start1_addr-1));
	  c=*addr++;
	  break;
	}
      }
      break;
    }
  }
  return err;
}
Esempio n. 17
0
BOOL	CSmsLookCtorWnd::SubInitialize()
{
	//ini list
	
	m_list_base.SetID( MZ_IDC_SMSLOOKCTOR_LIST );
	AddUiWin( &m_list_base );
/////////////////////////////////////////////////////////////////	
//	ItemAttribute	clItemAttribute;
//	clItemAttribute.SetPsText1Param( 100, RGB(100, 100, 100), FW_MEDIUM, false, false, 
//							DT_TOP|DT_LEFT|DT_END_ELLIPSIS|DT_SINGLELINE|DT_NOPREFIX ); 

//	m_list_base.SetItemAttributeH( clItemAttribute );
///////////////////////////////////////////////////////////////////
	//ini alp
	m_AlpBar.SetID( MZ_IDC_SMSLOOKCTOR_ALPBAR );
	m_AlpBar.EnableZoomAlphabet( true );
	m_AlpBar.EnableNotifyMessage( true );
	m_AlpBar.SetPos( 350, 0, 50, GetHeight() );
	AddUiWin( &m_AlpBar );

	//ini toolbar
	m_toolBar_base.SetID( MZ_IDC_SMSLOOKCTOR_TOOLBAR );
	AddUiWin( &m_toolBar_base );


	/////////////test/////////////////////////////////////////////////////////////
	wchar_t	*pBuf		=	NULL;
	long	lSize		=	0;
	wchar_t	*pwcResult	=	NULL;

	HRESULT	hr	=	m_clCEasySmsUiCtrl.MakeCtorRltListReq( &pBuf, &lSize );
	if ( FAILED ( hr ) )									return	FALSE;

	CCoreService	*pCCoreService	=	CCoreService::GetInstance();
	if ( NULL == pCCoreService )							return	FALSE;

#ifdef	UI_TEST
		 pwcResult =	L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
							L"<result>"
								L"<data type = \"contactors\">"
									L"<data type = \"list\" count = \"2\">"
										L"<rec encode = \"true\">"
											L"<name>张三</name>"
											L"<pid>2</pid>"										
											L"<address>13600000001</address>"
											L"<smscount>9</smscount>"
										L"</rec>"
										L"<rec encode = \"true\">"
											L"<name>李四</name>"
											L"<pid>3</pid>"
											L"<address>13600000002</address>"
											L"<smscount>88</smscount>"
										L"</rec>"
									L"</data>"
								L"</data>"
							L"</result>";
#else
	hr	=	pCCoreService->Request( pBuf, &pwcResult );
	if ( FAILED ( hr ) )									return	FALSE;
#endif

	hr	=	m_clCEasySmsUiCtrl.MakeCtorRltList( m_list_base, pwcResult );
#if 0	
	CMzString name = L"姓名%d";
//	CMzString content = L"短信内容 SmsContent%d:";
	CMzString stime = L"Count: 100";

	CMzString name1(10);
	CMzString content1(30);
	for (int i = 0; i < 100; i++)
	{
		swprintf(name1.C_Str(),name.C_Str(),i);
//		swprintf(content1.C_Str(),content.C_Str(),i);
		ListItemEx* item = new ListItemEx;
		
//		ItemAttribute	clItemAttribute;
//		clItemAttribute.SetPsText1Param( 100, RGB(100, 100, 100), FW_MEDIUM, false, false, 
//									DT_TOP|DT_END_ELLIPSIS|DT_SINGLELINE|DT_NOPREFIX ); 
//		item->m_pSpecialItemAttr	=	&clItemAttribute;

		
		item->m_pData = (void*)i;
		item->m_textTitle = name1.C_Str();

		item->m_textPostscript1 = stime.C_Str();


 		item->m_pImgFirst = m_imgContainer_base.LoadImage(MzGetInstanceHandle(), IDR_PNG_CTR_LIST_READ, true);

		m_list_base.AddItem(item);
	}

#endif

	if ( NULL != pBuf )
	{
		delete	pBuf, pBuf	=	NULL;
	}
/////////////test/////////////////////////////////////////////////////////////

	return	TRUE;
}
int main(int argc, char **argv)
{
  if(argc < 2)
  {
    std::cout << "usage: iugui_imagewindow_test image_filename" << std::endl;
    exit(EXIT_FAILURE);
  }
  printf("start ImageWindow test\n");

  // we want to remove this!!!
  initGL(argc,argv);

  QApplication app(argc, argv);

  // First load the image, so we know what the size of the image (imageW and imageH)
  std::string in_file = argv[1];
  std::cout << "reading " << in_file << " into gpu memory." << std::endl;

  iu::ImageGpu_8u_C1* image_8u_C1 = iu::imread_cu8u_C1(in_file);
  iu::ImageGpu_32f_C1* image_32f_C1 = iu::imread_cu32f_C1(in_file);
  iu::ImageGpu_8u_C4* image_8u_C4 = iu::imread_cu8u_C4(in_file);
  iu::ImageGpu_32f_C4* image_32f_C4 = iu::imread_cu32f_C4(in_file);
  //  iu::imshow(image_8u_C4, "reference input image");

  double time = iu::getTime();
  iu::ImageWindow win_8u_C1;
  win_8u_C1.setWindowTitle("gpu 8u C1");
  win_8u_C1.setImage(image_8u_C1);

  // create overlays
  iu::ImageGpu_8u_C1 overlay_8u(image_8u_C1->size());
  {
    iu::setValue(0, &overlay_8u, overlay_8u.roi());
    IuRect roi(10,10,100,100);
    iu::setValue(64u, &overlay_8u, roi);
    roi = IuRect(110,110,200,200);
    iu::setValue(128u, &overlay_8u, roi);
  }
  iu::ImageGpu_32f_C1 overlay_32f(image_8u_C1->size());
  {
    iu::setValue(0, &overlay_32f, overlay_32f.roi());
    IuRect roi(10,10,100,100);
    iu::setValue(0.2f, &overlay_32f, roi);
    roi = IuRect(110,110,200,200);
    iu::setValue(0.5f, &overlay_32f, roi);
  }

  iu::LinearHostMemory_8u_C1 lut_values1_8u(2);
  *lut_values1_8u.data(0) = 64u;
  *lut_values1_8u.data(1) = 128u;
  iu::LinearHostMemory_8u_C4 lut_colors1_8u(2);
  *lut_colors1_8u.data(0) = make_uchar4(255,0,0,128);
  *lut_colors1_8u.data(1) = make_uchar4(0,0,255,128);
  iu::LinearHostMemory_32f_C1 lut_values2_32f(2);
  *lut_values2_32f.data(0) = 0.2f;
  *lut_values2_32f.data(1) = 0.5f;
  iu::LinearHostMemory_8u_C4 lut_colors2_8u(2);
  *lut_colors2_8u.data(0) = make_uchar4(0,0,255,128);
  *lut_colors2_8u.data(1) = make_uchar4(255,0,0,128);

  iu::LinearDeviceMemory_8u_C1 cu_lut_values1_8u(2);
  iu::LinearDeviceMemory_8u_C4 cu_lut_colors1_8u(2);
  iu::LinearDeviceMemory_32f_C1 cu_lut_values2_32f(2);
  iu::LinearDeviceMemory_8u_C4 cu_lut_colors2_8u(2);
  iu::copy(&lut_values1_8u, &cu_lut_values1_8u);
  iu::copy(&lut_values2_32f, &cu_lut_values2_32f);
  iu::copy(&lut_colors1_8u, &cu_lut_colors1_8u);
  iu::copy(&lut_colors2_8u, &cu_lut_colors2_8u);

  QString name1("overlay 1");
  win_8u_C1.addOverlay(name1, reinterpret_cast<iu::Image*>(&overlay_8u),
                       reinterpret_cast<iu::LinearMemory*>(&cu_lut_values1_8u), &cu_lut_colors1_8u, true);
  win_8u_C1.addOverlay(QString("overlay 2"), &overlay_32f, &cu_lut_values2_32f, &cu_lut_colors2_8u, false);

  win_8u_C1.show();
  std::cout << "display create/show takes " << (iu::getTime()-time) << "ms" << std::endl;

  //  time = iu::getTime();
  //  iu::QGLImageGpuWidget widget_8u_C1(0);
  //  widget_8u_C1.setWindowTitle("qgl widget: 8u_C1");
  //  widget_8u_C1.setImage(image_8u_C1);
  //  widget_8u_C1.show();
  //  std::cout << "display create/show takes " << (iu::getTime()-time) << "ms" << std::endl;


  //  // update test
  //  std::cout << "reading " << in_file2 << std::endl;
  //  iu::ImageCpu_8u_C1* image2_8u_C1 = iu::imread_8u_C1(in_file2);
  //  im_display_8u_C1.updateImage(image2_8u_C1);

  //  // check gpu widget
  //  iu::ImageGpu_8u_C1* image_cu8u_C1 = iu::imread_cu8u_C1(in_file);
  //  iu::ImageGpu_32f_C1* image_cu32f_C1 = iu::imread_cu32f_C1(in_file);
  //  iu::ImageGpu_8u_C4* image_cu8u_C4 = iu::imread_cu8u_C4(in_file);
  //  iu::ImageGpu_8u_C4* image2_cu8u_C4 = iu::imread_cu8u_C4(in_file2);
  //  iu::ImageGpu_32f_C4* image_cu32f_C4 = iu::imread_cu32f_C4(in_file);



  app.exec();

  delete(image_8u_C1);
  delete(image_8u_C4);
  delete(image_32f_C1);
  delete(image_32f_C4);

  cudaThreadExit();
  return(EXIT_SUCCESS);
}
Esempio n. 19
0
static void
hprf(const char *fmt, int mesg, FILE *f, int threaded, const char *attrlist)
{
	struct message	*mp = &message[mesg-1];
	char	*headline = NULL, *subjline, *name, *cp, *pbuf = NULL;
	struct headline	hl;
	size_t	headsize = 0;
	const char	*fp;
	int	B, c, i, n, s;
	int	headlen = 0;
	struct str	in, out;
	int	subjlen = scrnwidth, fromlen, isto = 0, isaddr = 0;
	FILE	*ibuf;

	if ((mp->m_flag & MNOFROM) == 0) {
		if ((ibuf = setinput(&mb, mp, NEED_HEADER)) == NULL)
			return;
		if ((headlen = readline(ibuf, &headline, &headsize)) < 0)
			return;
	}
	if ((subjline = hfield("subject", mp)) == NULL)
		subjline = hfield("subj", mp);
	if (subjline == NULL) {
		out.s = NULL;
		out.l = 0;
	} else {
		in.s = subjline;
		in.l = strlen(subjline);
		mime_fromhdr(&in, &out, TD_ICONV | TD_ISPR);
		subjline = out.s;
	}
	if ((mp->m_flag & MNOFROM) == 0) {
		pbuf = ac_alloc(headlen + 1);
		parse(headline, headlen, &hl, pbuf);
	} else {
		hl.l_from = /*fakefrom(mp);*/NULL;
		hl.l_tty = NULL;
		hl.l_date = fakedate(mp->m_time);
	}
	if (value("datefield") && (cp = hfield("date", mp)) != NULL)
		hl.l_date = fakedate(rfctime(cp));
	if (Iflag) {
		if ((name = hfield("newsgroups", mp)) == NULL)
			if ((name = hfield("article-id", mp)) == NULL)
				name = "<>";
		name = prstr(name);
	} else if (value("show-rcpt") == NULL) {
		name = name1(mp, 0);
		isaddr = 1;
		if (value("showto") && name && is_myname(skin(name))) {
			if ((cp = hfield("to", mp)) != NULL) {
				name = cp;
				isto = 1;
			}
		}
	} else {
		isaddr = 1;
		if ((name = hfield("to", mp)) != NULL)
			isto = 1;
	}
	if (name == NULL) {
		name = "";
		isaddr = 0;
	}
	if (isaddr) {
		if (value("showname"))
			name = realname(name);
		else {
			name = prstr(skin(name));
		}
	}
	for (fp = fmt; *fp; fp++) {
		if (*fp == '%') {
			if (*++fp == '-') {
				fp++;
			} else if (*fp == '+')
				fp++;
			while (digitchar(*fp&0377))
				fp++;
			if (*fp == '\0')
				break;
		} else {
#if defined (HAVE_MBTOWC) && defined (HAVE_WCWIDTH)
			if (mb_cur_max > 1) {
				wchar_t	wc;
				if ((s = mbtowc(&wc, fp, mb_cur_max)) < 0)
					n = s = 1;
				else {
					if ((n = wcwidth(wc)) < 0)
						n = 1;
				}
			} else
#endif  /* HAVE_MBTOWC && HAVE_WCWIDTH */
			{
				n = s = 1;
			}
			subjlen -= n;
			while (--s > 0)
				fp++;
		}
	}
	for (fp = fmt; *fp; fp++) {
		if (*fp == '%') {
			B = 0;
			n = 0;
			s = 1;
			if (*++fp == '-') {
				s = -1;
				fp++;
			} else if (*fp == '+')
				fp++;
			if (digitchar(*fp&0377)) {
				do
					n = 10*n + *fp - '0';
				while (fp++, digitchar(*fp&0377));
			}
			if (*fp == '\0')
				break;
			n *= s;
			switch (*fp) {
			case '%':
				putc('%', f);
				subjlen--;
				break;
			case '>':
			case '<':
				c = dot == mp ? *fp&0377 : ' ';
				putc(c, f);
				subjlen--;
				break;
			case 'a':
				c = dispc(mp, attrlist);
				putc(c, f);
				subjlen--;
				break;
			case 'm':
				if (n == 0) {
					n = 3;
					if (threaded)
						for (i=msgCount; i>999; i/=10)
							n++;
				}
				subjlen -= fprintf(f, "%*d", n, mesg);
				break;
			case 'f':
				if (n <= 0)
					n = 18;
				fromlen = n;
				if (isto)
					fromlen -= 3;
				fprintf(f, "%s%s", isto ? "To " : "",
						colalign(name, fromlen, 1));
				subjlen -= n;
				break;
			case 'd':
				if (n <= 0)
					n = 16;
				subjlen -= fprintf(f, "%*.*s", n, n, hl.l_date);
				break;
			case 'l':
				if (n == 0)
					n = 4;
				if (mp->m_xlines)
					subjlen -= fprintf(f, "%*ld", n,
							mp->m_xlines);
				else {
					subjlen -= n;
					while (n--)
						putc(' ', f);
				}
				break;
			case 'o':
				if (n == 0)
					n = -5;
				subjlen -= fprintf(f, "%*lu", n,
						(long)mp->m_xsize);
				break;
			case 'i':
				if (threaded)
					subjlen -= putindent(f, mp,
							scrnwidth - 60);
				break;
			case 'S':
				B = 1;
				/*FALLTHRU*/
			case 's':
				n = n>0 ? n : subjlen - 2;
				if (B)
					n -= 2;
				if (subjline != NULL && n >= 0) {
					/* pretty pathetic */
					fprintf(f, B ? "\"%s\"" : "%s",
						colalign(subjline, n, 0));
				}
				break;
			case 'U':
				if (n == 0)
					n = 9;
				subjlen -= fprintf(f, "%*lu", n, mp->m_uid);
				break;
			case 'e':
				if (n == 0)
					n = 2;
				subjlen -= fprintf(f, "%*u", n, threaded == 1 ?
						mp->m_level : 0);
				break;
			case 't':
				if (n == 0) {
					n = 3;
					if (threaded)
						for (i=msgCount; i>999; i/=10)
							n++;
				}
				fprintf(f, "%*ld", n, threaded ?
						mp->m_threadpos : mesg);
				subjlen -= n;
				break;
			case 'c':
				if (n == 0)
					n = 6;
				subjlen -= fprintf(f, "%*g", n, mp->m_score);
				break;
			}
		} else
			putc(*fp&0377, f);
	}
	putc('\n', f);
	if (out.s)
		free(out.s);
	if (headline)
		free(headline);
	if (pbuf)
		ac_free(pbuf);
}
Esempio n. 20
0
void XMLCompareEngine::compare(DOMNode* n1, DOMNode *n2) {
	if ((n1==NULL)&&(n2==NULL)) return;
	if (n1==NULL) FAILED(("first document has no more nodes here"));
	if (n2==NULL) FAILED(("second document has no more nodes here"));
	
	if (n1->getNodeType()!=n2->getNodeType()) FAILED(("nodes don't have the same type here left=%d, right=%d", (int)n1->getNodeType(), (int)n2->getNodeType()));
	
	switch(n1->getNodeType()) {
		
		/* -- Element Node -- */
		
		case DOMNode::ELEMENT_NODE:
		
			if (!XMLString::equals(n1->getNodeName(), n2->getNodeName())) {
				XyLatinStr name1(n1->getNodeName());
				FAILED(("<%s>: second document element has different name", name1.localForm() ));
				}
		
			if (!(flags&XMLCMP_IgnoreAttributes)) {
				DOMNamedNodeMap* attributes1 = n1->getAttributes();
				DOMNamedNodeMap* attributes2 = n2->getAttributes();
				if ((attributes1->getLength()>0)||(attributes2->getLength()>0)) {
					try {
						XMLCompareEngine::compareAttributes(attributes1, attributes2);
						}
					catch (const CompareFailed &e){
						XyLatinStr name1(n1->getNodeName());
						FAILED(("<%s>: %s", name1.localForm(), e.getMsg().c_str()));
						}
					}
				}
			
			if ((!n1->hasChildNodes())&&(!n2->hasChildNodes())) return;
			else if (!n1->hasChildNodes()) {
				XyLatinStr name1(n1->getNodeName());
				FAILED(("<%s>: second document has child node(s)", name1.localForm() ));
				}
			else if (!n2->hasChildNodes()) {
				XyLatinStr name1(n1->getNodeName());
				FAILED(("<%s>: second document has no child node", name1.localForm() ));
				}
			else {
				int childCount=1;
				DOMNode* child1 = n1->getFirstChild();
				DOMNode* child2 = n2->getFirstChild();
				if (flags&XMLCMP_IgnoreWhiteSpaces) {
					child1 = skipWhiteSpacesStartingAt(child1);
					child2 = skipWhiteSpacesStartingAt(child2);
					}
				while(child1!=NULL) {
					if (child2==NULL) {
						XyLatinStr name1(n1->getNodeName());
						FAILED(("<%s>: second document has not %d child nodes", name1.localForm(), (int)childCount ));
						}
					
					try {
						compare(child1, child2);
						}
					catch(const CompareFailed &e) {
						XyLatinStr name1(n1->getNodeName());
						const char *elName = name1.localForm();
						printf("elName=%s\n", elName);
						const char *msg = e.getMsg().c_str();
						printf("{msg=%s}\n", msg);
						FAILED(("/%s[position=%d]%s", elName, (int)childCount, msg ));
						}
					
					child1 = child1->getNextSibling();
					child2 = child2->getNextSibling();
					if (flags&XMLCMP_IgnoreWhiteSpaces) {
						child1 = skipWhiteSpacesStartingAt(child1);
						child2 = skipWhiteSpacesStartingAt(child2);
						}
					childCount++;
					}
				if (child2!=NULL) {
					XyLatinStr name1(n1->getNodeName());
					FAILED(("<%s>: second document has more than %d child nodes", name1.localForm(), childCount ));
					}
				else return;
			}
			THROW_AWAY(("internal error"));
			break;
			
		/* -- Text Node -- */
		
		case DOMNode::TEXT_NODE:
		case DOMNode::CDATA_SECTION_NODE:
			if ( (!XID_DOMDocument::isRealData(n1))
			   &&(!XID_DOMDocument::isRealData(n2))
				 &&(flags & XMLCMP_IgnoreWhiteSpaces) ) return;
			if (!XMLString::equals(n1->getNodeValue(), n2->getNodeValue())) {
				XyLatinStr v1(n1->getNodeValue());
				XyLatinStr v2(n2->getNodeValue());
				FAILED(("text value is different: <%s> vs. <%s>", v1.localForm(), v2.localForm()));
				}
			return;

		case DOMNode::COMMENT_NODE:
			if (flags&XMLCMP_IgnoreComments) return;
			else if (!XMLString::equals(n1->getNodeValue(), n2->getNodeValue())) {
				XyLatinStr v1(n1->getNodeValue());
				XyLatinStr v2(n2->getNodeValue());
				FAILED(("comment text is different: <%s> vs. <%s>", v1.localForm(), v2.localForm()));
				}
			return;

		/* -- Other Types -- */

		case DOMNode::ENTITY_REFERENCE_NODE:
			THROW_AWAY(("Unsupported node type Entity - can't compare"));
			break;

		default:
			THROW_AWAY(("Unknown node type %d - can't compare", (int)n1->getNodeType() ));
			break;
		
		}
	}