static int scanSCREEN(IOStr *io,const char *what,int sn){ int rv; int nl; int di; rv = getInt4(io,"WINDOW/root"); rv = getInt4(io,"COLORMAP/default-colormap"); rv = getInt4(io,"CARD32/white-pixel"); rv = getInt4(io,"CARD32/black-pixel"); rv = getInt4(io,"SETofEVENT/corrent-input-masks"); rv = getInt2(io,"CARD16/width-in-pixels"); rv = getInt2(io,"CARD16/height-in-pixels"); rv = getInt2(io,"CARD16/width-in-millimeters"); rv = getInt2(io,"CARD16/height-in-millimeters"); rv = getInt2(io,"CARD16/min-installed-maps"); rv = getInt2(io,"CARD16/max-installed-maps"); rv = getInt4(io,"VISUALID/root-visual"); rv = getInt1(io,"VISUALID/backing-stores"); rv = getInt1(io,"VISUALID/save-unders"); rv = getInt1(io,"VISUALID/root-depth"); nl = getInt1(io,"VISUALID/number-of-DEPTHs-in-allowed-depth"); for( di = 0; di < nl; di++ ){ if( remLeng(io) <= 0 ){ return EOF; } rv = scanDEPTH(io,"LISTofDEPTH/allowed-depath"); } return 0; }
static int relayFillPoly(XFlash *Xf,FILE *fc,FILE *ts,int len){ IOStr iob,*io = &iob; IStr(buf,32*1024); int rcc; int wcc; int rv; int nl; int d,g,s,m,x,y; IStr(poly,1024); refQStr(pp,poly); rcc = fread(buf,1,(len-1)*4,fc); IOinit(io,Xf," cs FP",buf,rcc); fprintf(stderr," ----\n"); d = rv = getInt4(io,"DRAWABLE/drawable"); g = rv = getInt4(io,"GCONTEXT/gc"); s = rv = getInt1(io,"shape"); m = rv = getInt1(io,"coordinate-mode"); rv = getInt2(io,"unused"); while( 4 <= remLeng(io) ){ x = rv = getInt2(io,"INT16/x"); y = rv = getInt2(io,"INT16/y"); if( poly < pp ){ setVStrPtrInc(pp,','); } sprintf(pp,"%d/%d",x,y); pp += strlen(pp); } toFlash(Xf,"FillPoly gc=%d poly={%s}",g,poly); wcc = fwrite(buf,1,rcc,ts); return 0; }
static int scanFORMAT(IOStr *io,const char *what){ int rv; rv = getInt1(io,"CARD8/depth"); rv = getInt1(io,"CARD8/bits-per-pixel"); rv = getInt1(io,"CARD8/scanline-pad"); rv = getInt1(io,"Pad"); rv = getInt4(io,"Pad"); return 0; }
/* X11R6.7DRAFT p.122 */ static int scanVISUALTYPE(IOStr *io,const char *what){ int rv; rv = getInt4(io,"VISUALID/visual-id"); rv = getInt1(io,"class"); rv = getInt1(io,"CARD8/bits-per-rgb-value"); rv = getInt2(io,"CARD16/colormap-entries"); rv = getInt4(io,"CARD32/red-mask"); rv = getInt4(io,"CARD32/green-mask"); rv = getInt4(io,"CARD32/blue-mask"); rv = getPadN(io,"unused",4); return 0; }
bool getTotalCharge( char *pqrFile, double *tCharge ) { FILE *fp; fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } *tCharge = 0; char line[ 101 ]; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 101 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; //i = getInt( line, i, &j ); // get atom number, and ignore //i = getString( line, i, tmp ); // get atom name, and ignore // don't use these either? getString1( line, tmp, 17, 3 ); // get residue name getInt1( line, &j, 22, 4 ); // get residue number double v; //i = getDouble( line, i, &v ); // get X coordinate //i = getDouble( line, i, &v ); // get Y coordinate //i = getDouble( line, i, &v ); // get Z coordinate getDouble1( line, &v, 54, 9 ); // get charge *tCharge += v; //i = getDouble( line, i, &v ); // get radius } fclose( fp ); return true; }
bool countResidues( char *pqrFile, int res, int *count, int *total ) { FILE *fp; fp = fopen( pqrFile, "rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } *count = *total = 0; char line[ 101 ]; int l = -1; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; getString1( line, tmp, 0, 6 ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; //getInt1( line, &j,6, 5 ); // get atom number, and ignore //getString1( line, tmp ,12, 4); // get atom name, and ignore getString1( line, tmp, 17, 3 ); // get residue name getInt1( line, &j, 22, 4 ); // get residue number if ( j != l ) { if ( getResidueID( tmp ) == res ) ( *count )++; ( *total )++; } l = j; } fclose( fp ); return true; }
static int scanDEPTH(IOStr *io,const char *what){ int di; int rv; int nl; int iv; rv = getInt1(io,"CARD8/depth"); rv = getPadN(io,"unused",1); nl = getInt2(io,"number-of-VISUALTYPES-in-visuls"); rv = getPadN(io,"unused",4); for( iv = 0; iv < nl; iv++ ){ if( remLeng(io) <= 0 ){ return EOF; } scanVISUALTYPE(io,"Visual"); } return 0; }
static int relayInitialResp(IOStr *io,int op){ int rv; int vl; int sl; int nl; int fi; rv = getInt1(io,"Sucess"); rv = getPadN(io,"unused",1); rv = getInt2(io,"major_version"); rv = getInt2(io,"minor_version"); rv = getInt2(io,"length/4"); rv = getInt4(io,"release-number"); rv = getInt4(io,"resource-id-base"); rv = getInt4(io,"resource-id-mask"); rv = getInt4(io,"motion-bufffer-size"); vl = getInt2(io,"length-of-vendor"); rv = getInt2(io,"maximum-request-length"); sl = getInt1(io,"number-of-SCREENs-in-roots"); nl = getInt1(io,"number-for-FORMATs-in-pixmap-formats"); rv = getInt1(io,"image-byte-order"); rv = getInt1(io,"bitmap-format-bit-order"); rv = getInt1(io,"bitmap-format-scanline-unit"); rv = getInt1(io,"bitmap-format-scanline-pad"); rv = getInt1(io,"min-keycode"); rv = getInt1(io,"max-keycode"); rv = getPadN(io,"unused",4); rv = getSTRING8(io,"Vendor",vl); rv = skipPad(io,"unused-Padding",4); for( fi = 0; fi < nl; fi++ ){ rv = scanFORMAT(io,"Format"); } rv = scanSCREEN(io,"Screen",sl); rv = skipPad(io,"Pad",8); return 0; }
bool readGlycines( char *pqrFile, int *nAtm, double **atm ) { int nRes = 0, nChn = 0; RESIDUE *res = NULL; int *chn = NULL; if ( !readResidues( pqrFile, &nRes, &res, &nChn, &chn ) ) { freeMem( res ); freeMem( chn); return false; } FILE *fp; fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int numAtoms = 0; char line[ 101 ]; int k = -1, l = -1; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; numAtoms++; } fclose( fp ); *nAtm = numAtoms; ( *atm ) = ( double * ) malloc( 5 * ( *nAtm ) * sizeof( double ) ); if ( *atm == NULL ) { printError( (char *)"Failed to allocate memory!" ); return false; } fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int n = 0; k = -1; l = -1; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; //i = getInt( line, i, &j ); // get atom number, and ignore //i = getString( line, i, tmp ); // get atom name, and ignore getString1( line, tmp, 17, 3 ); // get residue name getInt1( line, &j, 22, 4 ); // get residue number if ( j != l ) { k++; l = j; } if ( isGXY( nRes, res, k ) || isYXG( nRes, res, k ) || ( ( k >= 1 ) && ( isGXY( nRes, res, k - 1 ) || isYXG( nRes, res, k - 1 ) ) ) || ( ( k >= 2 ) && ( isGXY( nRes, res, k - 2 ) || isYXG( nRes, res, k - 2 ) ) ) ) { double v; getDouble1( line, &v, 30, 8 ); // get X coordinate ( *atm )[ 5 * n + 0 ] = v; getDouble1( line, &v, 38, 8); // get Y coordinate ( *atm )[ 5 * n + 1 ] = v; getDouble1( line, &v, 46, 8 ); // get Z coordinate ( *atm )[ 5 * n + 2 ] = v; getDouble1( line, &v, 54, 9 ); // get charge ( *atm )[ 5 * n + 3 ] = v; getDouble1( line, &v, 63, 7 ); // get radius ( *atm )[ 5 * n + 4 ] = v; n++; } } *nAtm = n; fclose( fp ); freeMem( res ); freeMem( chn); return true; }
bool readAtomsWithResidueInfo( char *pqrFile, int *nAtm, double **atm ) { FILE *fp; fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int numRes = 0; char line[ 101 ]; int l = -1, r = -1; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; //i = getInt( line, i, &j ); // get atom number, and ignore //i = getString( line, i, tmp ); // get atom name, and ignore getString1( line, tmp, 17, 3 ); // get residue name int resID = getResidueID( tmp ); getInt1( line, &j, 22, 4 ); // get residue number if ( ( j != l ) || ( resID != r ) ) numRes++; l = j; r = resID; } fclose( fp ); printf( (char *)"\nnumRes = %d\n", numRes ); fflush( stdout ); *nAtm = numRes; ( *atm ) = ( double * ) malloc( 5 * ( *nAtm ) * sizeof( double ) ); if ( *atm == NULL ) { printError( (char *)"Failed to allocate memory!" ); return false; } fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int n = 0; l = -1; r = -1; bool done = false; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ], atn[ 100 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; //i = getInt( line, i, &j ); // get atom number, and ignore getString1( line, atn, 12, 4 ); // get atom name getString1( line, tmp, 17, 3 ); // get residue name int resID = getResidueID( tmp ); getInt1( line, &j, 22, 4 ); // get residue number if ( ( j != l ) || ( resID != r ) ) done = false; l = j; r = resID; // arand: changed "CA" to " CA " and "CB" to " CB " to match the new method of reading data... if ( !done && ( resID != NONE ) && ( ( ( resID == GLY ) && !strcmp( atn, (char *)" CA " ) ) || ( ( resID != GLY ) && !strcmp( atn, (char *)" CB " ) ) ) ) { double v; getDouble1( line, &v, 30, 8 ); // get X coordinate ( *atm )[ 5 * n + 0 ] = v; getDouble1( line, &v, 38, 8 ); // get Y coordinate ( *atm )[ 5 * n + 1 ] = v; getDouble1( line, &v, 46, 8 ); // get Z coordinate ( *atm )[ 5 * n + 2 ] = v; ( *atm )[ 5 * n + 3 ] = resID - 1; ( *atm )[ 5 * n + 4 ] = j; n++; done = true; } } *nAtm = n; fclose( fp ); return true; }
bool readAtomsOnly( char *pqrFile, int *nAtm, double **atm ) { FILE *fp; fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int numAtoms = 0; char line[ 101 ]; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; numAtoms++; } fclose( fp ); *nAtm = numAtoms; ( *atm ) = ( double * ) malloc( 5 * ( *nAtm ) * sizeof( double ) ); if ( *atm == NULL ) { printError( (char *)"Failed to allocate memory!" ); return false; } fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int n = 0; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; //i = getInt( line, i, &j ); // get atom number, and ignore //i = getString( line, i, tmp ); // get atom name, and ignore getString1( line, tmp, 17, 3 ); // get residue name getInt1( line, &j, 22, 4 ); // get residue number double v; getDouble1( line, &v, 30, 8); // get X coordinate ( *atm )[ 5 * n + 0 ] = v; getDouble1( line, &v, 38, 8 ); // get Y coordinate ( *atm )[ 5 * n + 1 ] = v; getDouble1( line, &v, 46, 8 ); // get Z coordinate ( *atm )[ 5 * n + 2 ] = v; getDouble1( line, &v, 54, 9 ); // get charge ( *atm )[ 5 * n + 3 ] = v; getDouble1( line, &v, 63, 7 ); // get radius ( *atm )[ 5 * n + 4 ] = v; n++; } fclose( fp ); return true; }
bool readAtomsAndResidues( char *pqrFile, int *nAtm, double **atm, int *nRes, RESIDUE **res, int *nChn, int **chn ) { FILE *fp; fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int numAtoms = 0, numRes = 0, numChains = 1; char line[ 101 ]; int l = -1; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; char tmp1[ 100 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; //i = getInt( line, i, &j ); // get atom number, and ignore //i = getString( line, i, tmp ); // get atom name, and ignore //i = getAlphaString( line, i, tmp ); // get residue name, and ignore //i = getAlphaString( line, i, tmp1 ); // get residue name, and ignore getInt1( line, &j, 22, 4 ); // get residue number numAtoms++; if ( j != l ) numRes++; if ( j < l ) numChains++; l = j; } fclose( fp ); *nAtm = numAtoms; *nRes = numRes; *nChn = numChains; ( *atm ) = ( double * ) malloc( 7 * ( *nAtm ) * sizeof( double ) ); ( *res ) = ( RESIDUE * ) malloc( ( *nRes ) * sizeof( RESIDUE ) ); ( *chn ) = ( int * ) malloc( ( *nChn + 1 ) * sizeof( int ) ); if ( ( *atm == NULL ) || ( *res == NULL ) || ( *chn == NULL ) ) { printError( (char *)"Failed to allocate memory!" ); return false; } fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int k = 0, n = 0, c = 1; l = -1; ( *chn )[ 0 ] = 0; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; char tmp1[ 100 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; //i = getInt( line, i, &j ); // get atom number, and ignore //i = getString( line, i, tmp ); // get atom name, and ignore getString1( line, tmp, 17, 3 ); // get residue name getInt1( line, &j, 22, 4 ); // get residue number if ( j != l ) { if ( j < l ) ( *chn )[ c++ ] = k; ( *res )[ k ].resNum = j; ( *res )[ k ].chainID = c; ( *res )[ k ].resID = getResidueID( tmp ); k++; l = j; } double v; getDouble1( line, &v, 30, 8 ); // get X coordinate ( *atm )[ 7 * n + 0 ] = v; getDouble1( line, &v, 38, 8 ); // get Y coordinate ( *atm )[ 7 * n + 1 ] = v; getDouble1( line, &v, 46, 8 ); // get Z coordinate ( *atm )[ 7 * n + 2 ] = v; getDouble1( line, &v, 54, 9 ); // get charge ( *atm )[ 7 * n + 3 ] = v; getDouble1( line, &v, 63, 7 ); // get radius ( *atm )[ 7 * n + 4 ] = v; ( *atm )[ 7 * n + 5 ] = j; // residue number ( *atm )[ 7 * n + 6 ] = c; // chain number n++; } ( *chn )[ c ] = k; fclose( fp ); return true; }
bool readResidues( char *pqrFile, int *nRes, RESIDUE **res, int *nChn, int **chn ) { FILE *fp; fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int numRes = 0, numChains = 1; char line[ 101 ]; int l = -1; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; char tmp1[ 100 ]; getString1( line, tmp, 0, 6 ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; //i = getInt( line, i, &j ); // get atom number, and ignore //i = getString( line, i, tmp ); // get atom name, and ignore getString1( line, tmp, 17, 3 ); // get residue name, and ignore getInt1( line, &j, 22, 4 ); // get residue number if ( j != l ) numRes++; if ( j < l ) numChains++; l = j; } fclose( fp ); *nRes = numRes; *nChn = numChains; ( *res ) = ( RESIDUE * ) malloc( ( *nRes ) * sizeof( RESIDUE ) ); ( *chn ) = ( int * ) malloc( ( *nChn + 1 ) * sizeof( int ) ); if ( ( *res == NULL ) || ( *chn == NULL ) ) { printError( (char *)"Failed to allocate memory!" ); return false; } fp = fopen( pqrFile, (char *)"rt" ); if ( fp == NULL ) { printError( (char *)"Failed to open PQR file (%s)!", pqrFile ); return false; } int k = 0, c = 1; l = -1; ( *chn )[ 0 ] = 0; while ( fgets( line, 100, fp ) != NULL ) { int i = 0, j; char tmp[ 100 ]; char tmp1[ 100 ]; i = getAlphaString( line, i, tmp ); // get 'ATOM'/'HETATM', and ignore if ( tmp[ 0 ] != 'A' ) continue; // old //i = getInt( line, i, &j ); // get atom number, and ignore //i = getString( line, i, tmp ); // get atom name, and ignore getString1( line, tmp, 17, 3 ); // get residue name getInt1( line, &j, 22, 4 ); // get residue number if ( j != l ) { if ( j < l ) ( *chn )[ c++ ] = k; ( *res )[ k ].resNum = j; ( *res )[ k ].chainID = c; ( *res )[ k ].resID = getResidueID( tmp ); k++; l = j; } } ( *chn )[ c ] = k; fclose( fp ); return true; }
static int scanresp(IOStr *io,int op,int seq,OpQue *qop,const char *resp,int rcc){ int rv; int nl; if( op == OP_InitialResp ){ relayInitialResp(io,op); }else if( resp[0] == EV_KeyPress ){ fprintf(stderr," seq=%d\n",seq); rv = getInt1(io,"evcode"); rv = getInt1(io,"KEYCODE"); toFlash(io->in_Xf,"KeyPress code=%d",rv); rv = getInt2(io,"CARD16/Seq#"); /* if( resp[0] == EV_KeyPress ){ rv = getInt4(io,"TIMESTAMP/time"); rv = getInt4(io,"WINDOW/root"); rv = getInt4(io,"WINDOW/event"); rv = getInt4(io,"WINDOW/child"); rv = getInt2(io,"INT16/root-x"); rv = getInt2(io,"INT16/root-y"); rv = getInt2(io,"INT16/event-x"); rv = getInt2(io,"INT16/event-y"); rv = getInt2(io,"SETofKEYBUTMASK/state"); rv = getInt1(io,"BOOL/same-screen"); } */ }else{ fprintf(stderr," seq=%d\n",seq); rv = getInt1(io,"Reply"); rv = getInt1(io,"opt"); rv = getInt2(io,"CARD16/Seq#"); if( op == OP_QueryExtension ){ rv = getInt4(io,"CARD32/length"); rv = getInt1(io,"BOOL/present"); rv = getInt1(io,"CARD8/major-opcode"); fprintf(stderr,"------------- #%d got opcode=%d, put it into Op Table\n",qop?qop->oq_seq:0,rv); //addop(rv); rv = getInt1(io,"CARD8/first-event"); rv = getInt1(io,"CARD8/first-error"); }else if( op == OP_InternAtom ){ rv = getInt4(io,"CARD32/length"); rv = getInt4(io,"ATOM/atom"); }else if( op == OP_GetProperty ){ rv = getInt4(io,"CARD32/length"); rv = getInt4(io,"ATOM/atom"); rv = getInt4(io,"CARD32/bytes-after"); rv = getInt4(io,"CARD32/length-of-value-in-format-units"); rv = getPadN(io,"unused",12); }else if( op == OP_QueryPointer ){ rv = getInt4(io,"CARD32/length"); rv = getInt4(io,"WINDOW/root"); rv = getInt4(io,"WINDOW/child"); rv = getInt2(io,"INT16/root-x"); rv = getInt2(io,"INT16/root-y"); rv = getInt2(io,"INT16/win-x"); rv = getInt2(io,"INT16/win-y"); rv = getInt2(io,"SETofKEYBUTMASK/mask"); } } return 0; }