int main() { FILE *Read; int x = 1, y = 1; char str[32]; char data_ch; char state; Read = fopen("text2.txt", "r"); while (0 == feof(Read)){ data_ch = fgetc(Read); state = 1; switch (data_ch){ case 'i': data_ch = fgetc(Read); state++; if (data_ch == 'f'){ data_ch = fgetc(Read); state++; if (data_ch == ' '){ emit(Ch_Flag, x++, y, "IF"); } else if (data_ch != '\n'){ memset(str, '\0', sizeof(str)); Read_Str(state, Read, str); emit(Ch_NoFlag, x++, y, str); } } else if ((data_ch >= 'a') && (data_ch <= 'z') || (data_ch >= 'A') && (data_ch <= 'Z') || (data_ch >= '0') && (data_ch <= '9')){ memset(str, '\0', sizeof(str)); Read_Str(state, Read, str); emit(Ch_NoFlag, x++, y, str); } break; case '\n': y++; x = 1; break; case ' ': break; default: if ((data_ch >= 'a') && (data_ch <= 'z') ){ memset(str, '\0', sizeof(str)); Read_Str(state, Read, str); emit(Ch_NoFlag, x++, y, str); } break; } } List_reverse_print(all); while (1); return 0; }
int CEQUFile::ReadFileInfo() { int ret; char tmpheader[256]; ZeroMemory( tmpheader, sizeof( char ) * 256 ); ret = Read_Str( &m_equbuf, "<FileInfo>", "</FileInfo>", tmpheader, 256 ); if( ret ){ DbgOut( "EQUFile : ReadFileInfo : Read_Str tmpheader error !!!\n" ); _ASSERT( 0 ); return 1; } int cmp; cmp = strcmp( tmpheader, "RokDeBone2 equ file ver1001 type00" ); if( cmp != 0 ){ DbgOut( "EQUFile : ReadFileInfo : FileHeader error !!!\n" ); _ASSERT( 0 ); return 1; } return 0; }
int CEQUFile::ReadBoneAnim( EQUBUF* bonebuf, int animno, int bano ) { int ret; _ASSERT( m_animdat ); ANIMDAT* curanimdat = m_animdat + animno; _ASSERT( curanimdat->badat ); BADAT* curbadat = curanimdat->badat + bano; ret = Read_Str( bonebuf, "<BoneName>", "</BoneName>", curbadat->bonename, 256 ); if( ret ){ DbgOut( "EQUFile : ReadBoneAnim : Read_Str BoneName error !!!\n" ); _ASSERT( 0 ); return 1; } ret = Read_Int( bonebuf, "<KeyNum>", "</KeyNum>", &(curbadat->keynum) ); if( ret || (curbadat->keynum < 0) ){ DbgOut( "EQUFile : ReadBoneAnim : Read_Int KeyNum error !!!\n" ); _ASSERT( 0 ); return 1; } if( curbadat->keynum == 0 ){ return 0; } KEYDAT* keydat = (KEYDAT*)malloc( sizeof( KEYDAT ) * curbadat->keynum ); if( !keydat ){ DbgOut( "EQUFile : ReadBoneAnim : keydat alloc error !!!\n" ); _ASSERT( 0 ); return 1; } ZeroMemory( keydat, sizeof( KEYDAT ) * curbadat->keynum ); curbadat->keydat = keydat; int keycnt; for( keycnt = 0; keycnt < curbadat->keynum; keycnt++ ){ if( bonebuf->pos >= bonebuf->bufleng ){ DbgOut( "EQUFile : ReadBoneAnim : pos overflow error !!!\n" ); _ASSERT( 0 ); return 1; } char* startptr = 0; char* endptr = 0; startptr = strstr( bonebuf->buf + bonebuf->pos, "<AnimKey>" ); if( startptr ){ startptr += (int)strlen( "<AnimKey>" ); } endptr = strstr( bonebuf->buf + bonebuf->pos, "</AnimKey>" ); if( endptr ){ endptr += (int)strlen( "</AnimKey>" ); } if( !startptr || !endptr ){ DbgOut( "EQUFile : ReadBoneAnim : section pattern not found error !!!\n" ); _ASSERT( 0 ); return 1; } int chkendpos; chkendpos = (int)( endptr - bonebuf->buf ); if( (chkendpos >= (int)bonebuf->bufleng) || (endptr < startptr) ){ DbgOut( "EQUFile : ReadBoneAnim : endmark error !!!\n" ); _ASSERT( 0 ); return 1; } EQUBUF keybuf; ZeroMemory( &keybuf, sizeof( EQUBUF ) ); keybuf.buf = startptr; keybuf.pos = 0; keybuf.bufleng = (int)( endptr - startptr ); keybuf.isend = 0; ret = ReadAnimKey( &keybuf, animno, bano, keycnt ); if( ret ){ DbgOut( "EQUFile : LoadBoneAnim : ReadAnimKey error !!!\n" ); _ASSERT( 0 ); return 1; } bonebuf->pos = chkendpos; } return 0; }
int CEQUFile::ReadAnimation( EQUBUF* animbuf, int animno ) { int ret; ANIMDAT* curanimdat = m_animdat + animno; _ASSERT( curanimdat ); ret = Read_Str( animbuf, "<AnimName>", "</AnimName>", curanimdat->animname, 256 ); if( ret ){ DbgOut( "EQUFile : ReadAnimation : Read_Str AnimName error !!!\n" ); _ASSERT( 0 ); return 1; } ret = Read_Int( animbuf, "<FrameLeng>", "</FrameLeng>", &(curanimdat->frameleng) ); if( ret || (curanimdat->bonenum < 0) ){ DbgOut( "EQUFile : ReadAnimation : Read_Int BoneAnimNum error !!!\n" ); _ASSERT( 0 ); return 1; } ret = Read_Int( animbuf, "<BoneAnimNum>", "</BoneAnimNum>", &(curanimdat->bonenum) ); if( ret || (curanimdat->bonenum < 0) ){ DbgOut( "EQUFile : ReadAnimation : Read_Int BoneAnimNum error !!!\n" ); _ASSERT( 0 ); return 1; } if( curanimdat->bonenum == 0 ){ return 0; } BADAT* badat = (BADAT*)malloc( sizeof( BADAT ) * curanimdat->bonenum ); if( !badat ){ DbgOut( "EQUFile : ReadAnimation : badat alloc error !!!\n" ); _ASSERT( 0 ); return 1; } ZeroMemory( badat, sizeof( BADAT ) * curanimdat->bonenum ); curanimdat->badat = badat; int bacnt; for( bacnt = 0; bacnt < curanimdat->bonenum; bacnt++ ){ if( animbuf->pos >= animbuf->bufleng ){ DbgOut( "EQUFile : ReadAnimation : pos overflow error !!!\n" ); _ASSERT( 0 ); return 1; } char* startptr = 0; char* endptr = 0; startptr = strstr( animbuf->buf + animbuf->pos, "<BoneAnim>" ); if( startptr ){ startptr += (int)strlen( "<BoneAnim>" ); } endptr = strstr( animbuf->buf + animbuf->pos, "</BoneAnim>" ); if( endptr ){ endptr += (int)strlen( "</BoneAnim>" ); } if( !startptr || !endptr ){ DbgOut( "EQUFile : ReadAnimation : section pattern not found error !!!\n" ); _ASSERT( 0 ); return 1; } int chkendpos; chkendpos = (int)( endptr - animbuf->buf ); if( (chkendpos >= (int)animbuf->bufleng) || (endptr < startptr) ){ DbgOut( "EQUFile : ReadAnimation : endmark error !!!\n" ); _ASSERT( 0 ); return 1; } EQUBUF babuf; ZeroMemory( &babuf, sizeof( EQUBUF ) ); babuf.buf = startptr; babuf.pos = 0; babuf.bufleng = (int)( endptr - startptr ); babuf.isend = 0; ret = ReadBoneAnim( &babuf, animno, bacnt ); if( ret ){ DbgOut( "EQUFile : LoadAnimation : ReadBoneAnim error !!!\n" ); _ASSERT( 0 ); return 1; } animbuf->pos = chkendpos; } return 0; }
int CCameraFile::ReadCameraKey( CAMBUF* animbuf, int camno ) { int ret; char* startptr = 0; char* endptr = 0; startptr = strstr( animbuf->buf + animbuf->pos, strcamkeystart ); endptr = strstr( animbuf->buf + animbuf->pos, strcamkeyend ); if( !startptr || !endptr ){ DbgOut( "CameraFile : ReadCameraKey : key section pattern not found error !!!\n" ); _ASSERT( 0 ); return 1; } int chkendpos; chkendpos = (int)( endptr - animbuf->buf ); if( (chkendpos >= (int)animbuf->bufleng) || (endptr < startptr) ){ DbgOut( "CameraFile : ReadCameraKey : endmark error !!!\n" ); _ASSERT( 0 ); return 1; } CAMBUF keybuf; keybuf.buf = startptr; keybuf.bufleng = (int)( endptr - startptr ); keybuf.pos = 0; keybuf.isend = 0; int frameno = 0; ret = Read_Int( &keybuf, "frameno ", &frameno ); if( ret || (frameno < 0) || (frameno > m_anim->m_maxframe) ){ DbgOut( "CameraFile : ReadCameraKey : Read_Int frameno error !!!\n" ); _ASSERT( 0 ); return 1; } char tmpinterp[20]; ZeroMemory( tmpinterp, sizeof( char ) * 20 ); ret = Read_Str( &keybuf, "interp ", tmpinterp, 20 ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : Read_Str interp error !!!\n" ); _ASSERT( 0 ); return 1; } int chkinterp; int interp = INTERPOLATION_SLERP; for( chkinterp = INTERPOLATION_SLERP; chkinterp <= INTERPOLATION_SQUAD; chkinterp++ ){ int cmp; cmp = strcmp( tmpinterp, &(strinterp[chkinterp][0]) ); if( cmp == 0 ){ interp = chkinterp; break; } } int tmpcalcup = 0; int calcup = 0; ret = Read_Int( &keybuf, "CalcUp ", &tmpcalcup ); if( ret ){ calcup = 0; }else{ if( tmpcalcup == 0 ){ calcup = 0; }else{ calcup = 1; } } if( calcup == 1 ){ interp += 100; } char tmplooktype[20]; ZeroMemory( tmplooktype, sizeof( char ) * 20 ); ret = Read_Str( &keybuf, "looktype ", tmplooktype, 20 ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : Read_Str looktype error !!!\n" ); _ASSERT( 0 ); return 1; } int chklooktype; int looktype = CAML_NORMAL; for( chklooktype = CAML_NORMAL; chklooktype <= CAML_LOCK; chklooktype++ ){ int cmp; cmp = strcmp( tmplooktype, &(strlooktype[chklooktype][0]) ); if( cmp == 0 ){ looktype = chklooktype; break; } } D3DXVECTOR3 pos( 0.0f, 0.0f, 0.0f ); ret = Read_Vec3( &keybuf, "pos ", &pos ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : Read_Vec3 pos error !!!\n" ); _ASSERT( 0 ); return 1; } D3DXVECTOR3 target( 0.0f, 0.0f, -5000.0f ); ret = Read_Vec3( &keybuf, "target ", &target ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : Read_Vec3 target error !!!\n" ); _ASSERT( 0 ); return 1; } D3DXVECTOR3 up( 0.0f, 1.0f, 0.0f ); ret = Read_Vec3( &keybuf, "up ", &up ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : Read_Vec3 up error !!!\n" ); _ASSERT( 0 ); return 1; } float dist = 5000.0f; ret = Read_Float( &keybuf, "dist ", &dist ); if( ret || (dist < 0.0f) ){ DbgOut( "CameraFile : ReadCameraKey : Read_Float dist error !!!\n" ); _ASSERT( 0 ); return 1; } int hsid = -1; ret = Read_Int( &keybuf, "hsid ", &hsid ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : Read_Int hsid error !!!\n" ); _ASSERT( 0 ); return 1; } int boneno = -1; ret = Read_Int( &keybuf, "boneno ", &boneno ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : Read_Int boneno error !!!\n" ); _ASSERT( 0 ); return 1; } float nearz; ret = Read_Float( &keybuf, "nearz ", &nearz ); if( ret || (nearz < 0.0f) ){ DbgOut( "CameraFile : ReadCameraKey : Read_Float nearz error !!!\n" ); _ASSERT( 0 ); return 1; } float farz; ret = Read_Float( &keybuf, "farz ", &farz ); if( ret || (farz <= 0.0f) ){ DbgOut( "CameraFile : ReadCameraKey : Read_Float farz error !!!\n" ); _ASSERT( 0 ); return 1; } float fov; ret = Read_Float( &keybuf, "fov ", &fov ); if( ret || (fov < 30.0f) || (fov > 80.0f) ){ DbgOut( "CameraFile : ReadCameraKey : Read_Float fov error !!!\n" ); _ASSERT( 0 ); return 1; } int ortho; float orthosize; if( m_loadversion < 1002 ){ ortho = 0; orthosize = 3000.0f; }else{ ret = Read_Int( &keybuf, "orthoflag ", &ortho ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : Read_Int ortho error !!!\n" ); _ASSERT( 0 ); return 1; } ret = Read_Float( &keybuf, "orthosize ", &orthosize ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : Read_Float orthosize error !!!\n" ); _ASSERT( 0 ); return 1; } if( orthosize < 500.0f ){ orthosize = 500.0f; } } CAMERAELEM setce; ZeroMemory( &setce, sizeof( CAMERAELEM ) ); setce.looktype = looktype; setce.pos = pos; setce.target = target; setce.up = up; setce.dist = dist; setce.hsid = hsid; setce.boneno = boneno; setce.nearz = nearz; setce.farz = farz; setce.fov = fov; setce.ortho = ortho; setce.orthosize = orthosize; ret = m_anim->SetCameraKey( camno, frameno, setce, interp ); if( ret ){ DbgOut( "CameraFile : ReadCameraKey : ca SetCameraKey error !!!\n" ); _ASSERT( 0 ); return 1; } int nextpos; nextpos = chkendpos + (int)strlen( strcamkeyend ); animbuf->pos = nextpos;//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! /*** #CameraKey Start frameno 0 interp "LINEAR" //"LINEAR", "SPLINE" looktype "NORMAL" //"NORMAL", "LOOKONECE", "LOCK" pos 0.0, 0.0, 0.0 target 0.0, 0.0, -5000.0 up 0.0, 1.0, 0.0 dist 5000.0 hsid -1 boneno -1 nearz 1000.0 farz 40000.0 fov 45.0 #CameraKey End ***/ return 0; }
int CCameraFile::ReadAnimInfo( CCameraAnimHandler* srccah ) { int ret; char* startptr = 0; char* endptr = 0; startptr = strstr( m_cambuf.buf, stranimstart ); endptr = strstr( m_cambuf.buf, stranimend ); if( !startptr || !endptr ){ DbgOut( "CameraFile : ReadAnimInfo : section pattern not found error !!!\n" ); _ASSERT( 0 ); return 1; } int chkendpos; chkendpos = (int)( endptr - m_cambuf.buf ); if( (chkendpos >= (int)m_cambuf.bufleng) || (endptr < startptr) ){ DbgOut( "CameraFile : ReadAnimInfo : endmark error !!!\n" ); _ASSERT( 0 ); return 1; } CAMBUF infobuf; infobuf.buf = startptr; infobuf.bufleng = (int)( endptr - startptr ); infobuf.pos = 0; infobuf.isend = 0; char strname[256]; ZeroMemory( strname, sizeof( char ) * 256 ); ret = Read_Str( &infobuf, "name ", strname, 256 ); if( ret ){ DbgOut( "CameraFile : ReadAnimInfo : Read_Str name error !!!\n" ); _ASSERT( 0 ); return 1; } int frameleng = 0; ret = Read_Int( &infobuf, "frameleng ", &frameleng ); if( ret || (frameleng <= 0) ){ DbgOut( "CameraFile : ReadAnimInfo : Read_Int frameleng error !!!\n" ); _ASSERT( 0 ); return 1; } char strtype[20]; ZeroMemory( strtype, sizeof( char ) * 20 ); ret = Read_Str( &infobuf, "animtype ", strtype, 20 ); if( ret ){ DbgOut( "CameraFile : ReadAnimInfo : Read_Str animtype error !!!\n" ); _ASSERT( 0 ); return 1; } int animtype = MOTION_CLAMP; int chktype; for( chktype = MOTION_STOP; chktype <= MOTION_JUMP; chktype++ ){ int cmp; cmp = strcmp( strtype, &(stranimtype[chktype][0]) ); if( cmp == 0 ){ animtype = chktype; break; } } int animstep = 0; ret = Read_Int( &infobuf, "animstep ", &animstep ); if( ret || (animstep <= 0) ){ DbgOut( "CameraFile : ReadAnimInfo : Read_Int animstep error !!!\n" ); _ASSERT( 0 ); return 1; } int motjump = 0; ret = Read_Int( &infobuf, "motjump ", &motjump ); if( ret || (motjump < 0) || (motjump >= frameleng) ){ DbgOut( "CameraFile : ReadAnimInfo : Read_Int motjump error !!!\n" ); _ASSERT( 0 ); return 1; } m_anim = srccah->AddAnim( strname, animtype, frameleng, motjump ); if( !m_anim ){ DbgOut( "CameraFile : ReadAnimInfo : cah AddAnim error !!!\n" ); _ASSERT( 0 ); return 1; } m_anim->m_animstep = animstep; /*** #AnimInfo Start name "camera_1" frameleng 60 animtype "CLAMP" //"STOP", "CLAMP", "ROUND", "INV", "JUMP" animstep 1 motjump 0 #AnimInfo End ***/ return 0; }