int sh2reg(char *str) { char *p,*p1; int flg=0; if(!str) return flg; strins(str,'^'); for(p1=p=str; *p ; p++) { p=stptok(p,0,0,"?*.[\\"); if(!*p) break; if(*p=='\\') { ++p; continue; } if(*p=='[') { p1=strchr(p,']'); if(p1) { flg=1; p=p1; continue; } } switch(*p) { case '?': *p='.'; flg=1; break; case '*': p=strins(p,'.'); flg=1; break; case '.': p=strins(p,'\\'); break; default: break; } } strcat(str,"$"); return flg; }
char* expndcoef(char* expr) { if (expr == NULL || *expr == '\0') return expr; //find indep var char* tok1; char* indeppos = (char*)memchr(expr, indep_var, strlen(expr)); if(indeppos == NULL) return expr; //check for coef where indep var is found and then add the rest. tok1 = strsub(expr,0,indeppos-expr); if(strpbrk(tok1+strlen(tok1)-2,"0123456789") != NULL) tok1 = strins(tok1, "*", indeppos-expr); char* tok2 = expndcoef(indeppos+1); strcat(tok1,tok2); return tok1; }
//#ifdef TEST int main (int argc, char **argv) { #define MAXBUFSIZE 32768 char buf[MAXBUFSIZE]; #if 0 const char *b = "123(123.32.21.44)214"; const char *s = "(xxx.xx.xx.xx)"; // const char *p = memmem2 (b, strlen (b), s, strlen (s), MEMCMP2_WCARD('*', 'x')); const char *p = memmem2 (b, strlen (b), s, strlen (s), MEMCMP2_WCARD('x')); printf ("%s\n", p); strcpy (buf, "1234567890"); strins (buf + 2, 6, "abc"); printf ("%s\n", buf); #else strcpy (buf, "12434akjgkjh56453fdsg"); stritrim_s (buf, "sg", "xx"); printf (buf); #endif return 0; }
char* inspare(char* expr) { //insert at begining and end of string char* newexpr; newexpr = strins(expr,"(",0); newexpr = strins(newexpr,")",strlen(newexpr)); //insert around pre-existing parenthesis int para_flag = ((char*)memchr(newexpr+1,'(',strlen(newexpr)))-newexpr; int epara_flag = 0; while(para_flag >= 0 ) { newexpr = strins(newexpr,"(",para_flag); epara_flag = ((char*)memchr(newexpr+para_flag,')',strlen(newexpr+para_flag+1)))-newexpr; if(epara_flag >= 0) newexpr = strins(newexpr,")",epara_flag); para_flag = ((char*)memchr(newexpr+epara_flag,'(',strlen(newexpr)))-newexpr; } //insert before and after '+' and/or '-' int p_flag = strpbrk(newexpr,"+-")-newexpr; while(p_flag >= 0) { newexpr = strins(newexpr,")",p_flag); newexpr = strins(newexpr,"(",p_flag+2); p_flag = strpbrk(newexpr+p_flag+2,"+-")-newexpr; } return newexpr; }
int main( int argc, char **argv ) { int i, j; FILE *fp, *infp; char **seq; int *grpseq; char *tmpseq; int **pointt; static char name[M][B]; static int nlen[M]; double **mtx; double **mtx2; double score, score0; static short *table1; char b[B]; arguments( argc, argv ); if( inputfile ) { infp = fopen( inputfile, "r" ); if( !infp ) { fprintf( stderr, "Cannot open %s\n", inputfile ); exit( 1 ); } } else infp = stdin; #if 0 PreRead( stdin, &njob, &nlenmax ); #else getnumlen( infp ); #endif rewind( infp ); if( njob < 2 ) { fprintf( stderr, "At least 2 sequences should be input!\n" "Only %d sequence found.\n", njob ); exit( 1 ); } tmpseq = AllocateCharVec( nlenmax+1 ); seq = AllocateCharMtx( njob, nlenmax+1 ); grpseq = AllocateIntVec( nlenmax+1 ); pointt = AllocateIntMtx( njob, nlenmax+1 ); mtx = AllocateDoubleMtx( njob, njob ); mtx2 = AllocateDoubleMtx( njob, njob ); pamN = NOTSPECIFIED; #if 0 FRead( infp, name, nlen, seq ); #else readData( infp, name, nlen, seq ); #endif fclose( infp ); constants( njob, seq ); if( dorp == 'd' ) tsize = (int)pow( 4, 6 ); else tsize = (int)pow( 6, 6 ); maxl = 0; for( i=0; i<njob; i++ ) { gappick0( tmpseq, seq[i] ); nlen[i] = strlen( tmpseq ); if( nlen[i] < 6 ) { fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nlen[i] ); exit( 1 ); } if( nlen[i] > maxl ) maxl = nlen[i]; if( dorp == 'd' ) /* nuc */ { seq_grp_nuc( grpseq, tmpseq ); makepointtable_nuc( pointt[i], grpseq ); } else /* amino */ { seq_grp( grpseq, tmpseq ); makepointtable( pointt[i], grpseq ); } } for( i=0; i<njob; i++ ) { table1 = (short *)calloc( tsize, sizeof( short ) ); if( !table1 ) ErrorExit( "Cannot allocate table1\n" ); if( i % 10 == 0 ) { fprintf( stderr, "%4d / %4d\r", i+1, njob ); } makecompositiontable_p( table1, pointt[i] ); for( j=i; j<njob; j++ ) { score = (double)commonsextet_p( table1, pointt[j] ); mtx[i][j] = score; } free( table1 ); } for( i=0; i<njob; i++ ) { score0 = mtx[i][i]; for( j=0; j<njob; j++ ) mtx2[i][j] = ( score0 - mtx[MIN(i,j)][MAX(i,j)] ) / score0 * 3.0; } for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) { #if TEST double jscore; jscore = mtx[i][j] / ( MIN( strlen( seq[i] ), strlen( seq[j] ) ) - 2 ); fprintf( stdout, "jscore = %f\n", jscore ); fprintf( stdout, "mtx2[%d][%d] = %f, mtx2[%d][%d] = %f\n", i, j, mtx2[i][j], j, i, mtx2[j][i] ); #endif mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] ); #if TEST fprintf( stdout, "sonokekka mtx2[%d][%d] %f\n", i, j, mtx2[i][j] ); #endif } if( disopt ) { for( i=0; i<njob; i++ ) { sprintf( b, "=lgth = %04d", nlen[i] ); strins( b, name[i] ); } } fp = fopen( "hat2", "w" ); if( !fp ) ErrorExit( "Cannot open hat2." ); WriteHat2( fp, njob, name, mtx2 ); fclose( fp ); fprintf( stderr, "\n" ); SHOWVERSION; exit( 0 ); }
// add a variable to the environment or alias to the alias list int add_list( char *envstr, PCH pchList ) { char *line; PCH feptr, env_arg, env_end, last_var; unsigned int length; int rval = 0; ULONG size; // size of environment or alias blocks // OS/2 & NT need semaphores to keep processes from simultaneously // writing the alias list HMTX SemHandle = 0; char szVarName[32]; if ( pchList == 0L ) pchList = glpEnvironment; line = envstr; if ( *line == '=' ) { return ( error( ERROR_4DOS_BAD_SYNTAX, envstr )); } for ( ; (( *line ) && ( *line != '=' )); line++ ) { if ( pchList == glpAliasList ) { if ( iswhite( *line )) { strcpy( line, skipspace( line ) ); break; } } else // ensure environment entry is in upper case *line = (unsigned char)_ctoupper( *line ); } if ( *line == '=' ) { // point to the first char of the argument line++; // collapse whitespace around '=' in aliases, but not in env // variables, for COMMAND.COM compatibility (set abc def= ghi) if ( pchList == glpAliasList ) strcpy( line, skipspace( line )); } else if ( *line ) { // add the missing '=' strins( line, "=" ); line++; } // removing single back quotes at the beginning and end of an alias // argument (they're illegal there; the user is probably making a // mistake with ALIAS /R) if (( *line == SINGLE_QUOTE ) && ( pchList == glpAliasList )) { // remove leading single quote strcpy( line, line + 1 ); // remove trailing single quote if ((( length = strlen( line )) != 0 ) && ( line[--length] == SINGLE_QUOTE )) line[length] = '\0'; } // block other processes & threads while updating alias list if ( pchList == glpAliasList ) { // disable signals temporarily HoldSignals(); // get & lock a semaphore RequestSemaphore( &SemHandle, SEMAPHORE_NAME ); } // get pointers to beginning & end of alias/environment space size = QueryMemSize( pchList ); env_end = pchList + ( size - 4 ); // get pointer to end of environment or alias variables last_var = end_of_env( pchList ); length = strlen( envstr ) + 1; // special case for BeginLIBPATH and EndLIBPATH sscanf( envstr, "%31[^=]", szVarName ); if (stricmp( szVarName, BEGINLIBPATH ) == 0) { if ((DosSetExtLIBPATH( line, BEGIN_LIBPATH ) == NO_ERROR)) return 0; return ERROR_EXIT; } if (stricmp( szVarName, ENDLIBPATH ) == 0) { if ((DosSetExtLIBPATH( line, END_LIBPATH ) == NO_ERROR)) return 0; return ERROR_EXIT; } // check for modification or deletion of existing entry if (( env_arg = get_list( envstr, pchList )) != 0L ) { // get the start of the alias or variable name for ( feptr = env_arg; (( feptr > pchList ) && ( feptr[-1] != '\0' )); feptr-- ) ; if ( *line == '\0' ) { // delete an alias or environment variable memmove( feptr, next_env( feptr ), (unsigned int)( last_var - next_env(feptr)) + 1); } else { // get the relative length (vs. the old variable) length = strlen( line ) - strlen( env_arg ); } } if ( *line != '\0' ) { // check for out of environment space if (( last_var + length ) >= env_end ) { // boost environment or alias list size if ( ReallocMem( pchList, size + ENVIRONMENT_SIZE ) == NULL) { rval = error((( pchList == glpAliasList ) ? ERROR_4DOS_OUT_OF_ALIAS : ERROR_4DOS_OUT_OF_ENVIRONMENT), NULL); goto add_bye; } // adjust the environment / alias list size size = QueryMemSize( pchList ); if ( pchList == glpEnvironment ) gpIniptr->EnvSize = (unsigned int)size; else if ( pchList == glpAliasList ) gpIniptr->AliasSize = (unsigned int)size; } if ( env_arg != 0L ) { // modify an existing alias or environment variable // adjust the space & insert new value feptr = next_env( feptr ); memmove(( feptr + length ), feptr, (unsigned int)( last_var - feptr) + 1 ); strcpy( env_arg, line ); } else { // put it at the end & add an extra null strcpy( last_var, envstr ); last_var[length] = '\0'; } } add_bye: if ( pchList == glpAliasList ) { // clear the semaphore FreeSemaphore( SemHandle ); EnableSignals(); } return rval; }
// add a variable to the environment or alias to the alias list int PASCAL add_list( LPTSTR pszVariable, TCHAR _far *pchList ) { LPTSTR pszLine; TCHAR _far *pszVarName, _far *pszArgument, _far *pszEndOfList, _far *pszLastVariable; unsigned int uLength; int nError = 0; if ( pchList == 0L ) pchList = glpEnvironment; pszLine = pszVariable; if ( *pszLine == _TEXT('=') ) { return ( error( ERROR_4DOS_BAD_SYNTAX, pszVariable )); } for ( ; (( *pszLine ) && ( *pszLine != _TEXT('=') )); pszLine++ ) { if ( pchList != glpEnvironment ) { if ( iswhite( *pszLine )) { strcpy( pszLine, skipspace( pszLine ) ); break; } } else // ensure environment entry is in upper case *pszLine = (unsigned char)_ctoupper( *pszLine ); } // stupid kludge to strip quotes from PATH for compatibility with // COMMAND.COM if (( fWin95 ) && ( pchList == glpEnvironment )) { char szVarName[8]; if (( uLength = ( pszLine - pszVariable )) > 7 ) uLength = 7; sprintf( szVarName, "%.*s", uLength, pszVariable ); if ( stricmp( szVarName, PATH_VAR ) == 0 ) StripQuotes( pszLine ); } if ( *pszLine == _TEXT('=') ) { // point to the first char of the argument pszLine++; // collapse whitespace around '=' in aliases, but not in env // variables, for COMMAND.COM compatibility (set abc def= ghi) if ( pchList != glpEnvironment ) strcpy( pszLine, skipspace( pszLine )); } else if ( *pszLine ) { // add the missing '=' strins( pszLine, _TEXT("=") ); pszLine++; } // removing single back quotes at the beginning and end of an alias // argument (they're illegal there; the user is probably making a // mistake with ALIAS /R) if (( *pszLine == SINGLE_QUOTE ) && ( pchList != glpEnvironment )) { // remove leading single quote strcpy( pszLine, pszLine + 1 ); // remove trailing single quote if ((( uLength = strlen( pszLine )) != 0 ) && ( pszLine[--uLength] == SINGLE_QUOTE )) pszLine[uLength] = _TEXT('\0'); } // block other processes & threads while updating list if ( pchList != glpEnvironment ) { // disable task switches under Windows and DESQview CriticalSection( 1 ); } // get pointers to beginning & end of list space pszEndOfList = pchList + ((( pchList == glpAliasList ) ? gpIniptr->AliasSize : gpIniptr->EnvSize ) - 4 ); // get pointer to end of environment or alias variables pszLastVariable = end_of_env( pchList ); uLength = strlen( pszVariable ) + 1; // check for modification or deletion of existing entry if (( pszArgument = get_list( pszVariable, pchList )) != 0L ) { // get the start of the alias or variable name for ( pszVarName = pszArgument; (( pszVarName > pchList ) && ( pszVarName[-1] != _TEXT('\0') )); pszVarName-- ) ; if ( *pszLine == _TEXT('\0') ) { // delete an alias or environment variable _fmemmove( pszVarName, next_env( pszVarName ), (unsigned int)( (ULONG_PTR)pszLastVariable - (ULONG_PTR)next_env(pszVarName)) + sizeof(TCHAR)); } else { // get the relative length (vs. the old variable) uLength = strlen( pszLine ) - _fstrlen( pszArgument ); } } if ( *pszLine != _TEXT('\0') ) { // check for out of space if (( pszLastVariable + ( uLength * sizeof(TCHAR) )) >= pszEndOfList ) { if ( pchList == glpAliasList ) nError = error( ERROR_4DOS_OUT_OF_ALIAS, NULL ); else if ( pchList == glpEnvironment ) nError = error( ERROR_4DOS_OUT_OF_ENVIRONMENT, NULL); else nError = error( ERROR_NOT_ENOUGH_MEMORY, NULL ); goto add_bye; } if ( pszArgument != 0L ) { // modify an existing value // adjust the space & insert new value pszVarName = next_env( pszVarName ); _fmemmove(( pszVarName + uLength ), pszVarName, (unsigned int)(( (ULONG_PTR)pszLastVariable - (ULONG_PTR)pszVarName ) + sizeof(TCHAR) )); _fstrcpy( pszArgument, pszLine ); } else { // put it at the end & add an extra null _fstrcpy( pszLastVariable, pszVariable ); pszLastVariable[uLength] = _TEXT('\0'); } } add_bye: if ( pchList != glpEnvironment ) { // re-enable task switches under Windows and DESQview CriticalSection( 0 ); } return nError; }
// create or display environment variables or aliases static int _fastcall __Set( LPTSTR pszCmdLine, TCHAR _far * pchList ) { LPTSTR pszArg; long fSet = 0L; TCHAR _far *lpszVars; init_page_size(); // set the pointer to the environment, alias, or function list // strip leading switches if (( pszCmdLine != NULL ) && ( *pszCmdLine == gpIniptr->SwChr )) { if ( GetSwitches( pszCmdLine, "AMPR", &fSet, 1 ) != 0 ) return USAGE_ERR; } // check for master environment set if (( pchList == glpEnvironment ) && ( fSet & SET_MASTER )) pchList = glpMasterEnvironment; // read environment or alias file(s) if ( fSet & SET_READ ) return ( SetFromFile( pszCmdLine, pchList, fSet & ( SET_DEFAULT | SET_SYSTEM | SET_USER | SET_VOLATILE ))); if ( setjmp( cv.env ) == -1 ) return CTRLC; // pause after each page if ( fSet & SET_PAUSE ) { gnPageLength = GetScrRows(); } if (( pszCmdLine == NULL ) || ( *(pszCmdLine = skipspace( pszCmdLine )) == _TEXT('\0'))) { // print all the variables or aliases for ( lpszVars = pchList; ( *lpszVars != _TEXT('\0') ); lpszVars = next_env( lpszVars ) ) { more_page( lpszVars, 0 ); } // return an error if no entries exist return (( lpszVars == pchList ) ? ERROR_LIST_EMPTY : 0 ); } if ( fSet & SET_EXPRESSION ) { if (( pszArg = strchr( pszCmdLine, _TEXT('=') )) != NULL ) { if (( pszArg > pszCmdLine ) && ( strchr( _TEXT("+-*/%&^|><"), pszArg[-1] ) != NULL )) { TCHAR szBuf[256]; // it's an assignment operator ("set /a test+=2") sscanf( pszCmdLine, _TEXT(" %[^ +-*/%&^|><=]"), szBuf ); strcpy( pszArg, pszArg+1 ); strins( pszCmdLine, _TEXT("=") ); strins( pszCmdLine, szBuf ); pszArg = pszCmdLine + strlen( szBuf ) + 1; } else pszArg = skipspace( pszArg+1 ); } else pszArg = pszCmdLine; StripQuotes( pszArg ); evaluate( pszArg ); if ( cv.bn < 0 ) { qputs( pszArg ); crlf(); } // create/modify/delete a variable return (( pszArg == pszCmdLine ) ? 0 : add_list( pszCmdLine, pchList )); } // display the current variable or alias argument? // (setting environment vars requires a '='; it's optional with aliases) if ((( pszArg = strchr( pszCmdLine, _TEXT('=') )) == NULL ) && (( pchList == 0L ) || ( ntharg( pszCmdLine, 0x8001 ) == NULL ))) { if (( lpszVars = get_list( pszCmdLine, pchList )) == 0L ) { return ERROR_NOT_IN_LIST; } printf( FMT_FAR_STR_CRLF, lpszVars ); return 0; } // create/modify/delete a variable or alias return ( add_list( pszCmdLine, pchList )); }