Example #1
0
static void init_scores(const int s[4][4], int **ss, int *gop,  int filler,
  int gap_op, int gap_ex) {
	int i, j, a, b, A, B, X, D;

	// first, fill in ss, the substitution-score matrix
	for (i = 0; i < NACHARS; ++i)
		for (j = 0; j < NACHARS; ++j)
			ss[i][j] = filler;
	for (i = 0; i < (signed)CLEN(nchars); ++i) {
		A = nchars[i];
		a = tolower(A);
		for (j = 0; j < (signed)CLEN(nchars); ++j) {
			B = nchars[j];
			b = tolower(B);
			ss[A][B] = ss[a][B] = ss[A][b] = ss[a][b] =
				s[i][j];
		}
	}
	for (i = 0; i < NACHARS; ++i)
		ss['-'][i] = ss[i]['-'] = -gap_ex;
	ss['-']['-'] = 0;

	// initialize the "gap-open penalty" array, for quasi-natural gap costs
	for (i = 0; i < 16; ++i)
		gop[i] = 0;
	D = 1;	// dash
	X = 0;	// anything other than '-'
	/* The six gap-open configurations are:
		xx	x-	x-	-x	-x	--
		x-	xx	-x	x-	--	-x
		 1	 2	 3	 4	 5	 6
	   The last two may result in a gap being counted twice, as with:
		xx-xx
		x---x
		 1 5
	   (A digit indicates the second column of a column-pair that conforms
	   to the indicated rule, 1-6.)
	   However, it permits a gap to be detected by inspection of adjacent
	   columns in a case like:
		x-----xx
		x------x
		      5
	   GAP's arguments give column 1, followed by column 2.
	*/
	GAP(X,X,X,D) = GAP(X,X,D,X) = GAP(X,D,D,X) =  GAP(D,X,X,D) =
	  GAP(D,D,X,D) = GAP(D,D,D,X) = gap_op;
	gap_extend = gap_ex;
}
Example #2
0
/* DNA_scores --------------------------  substitution scoring matrix for DNA */
static void DNA_scores(ss_t ss)
{
	int i, j, bad, a, b, A, B;

	for (i = 0; i < NACHARS; ++i)
		for (j = 0; j < NACHARS; ++j)
			ss[i][j] = -100;
	for (i = 0; i < (signed)CLEN(nchars); ++i) {
		A = nchars[i];
		a = tolower(A);
		for (j = 0; j < (signed)CLEN(nchars); ++j) {
			B = nchars[j];
			b = tolower(B);
			ss[A][B] = ss[a][B] = ss[A][b] = ss[a][b] =
				HOXD70_sym[i][j];
		}
	}
	bad = -1000;
	for (i = 0; i < NACHARS; ++i)
		ss['X'][i] = ss[i]['X'] = ss['x'][i] = ss[i]['x'] = bad;
}
Example #3
0
/* must include ent3f.h AFTER io3f.h */
#include <sys/stat.h>
#include "io3f.h"
#include "ent3f.h"

extern char *__fstr2cstr();
extern void __cstr_free();

int ENT3F(LSTAT64, lstat64)(DCHAR(nm), long long *statb DCLEN(nm))
{
  struct stat b;
  char *p;
  int i;

  p = __fstr2cstr(CADR(nm), CLEN(nm));
  if ((i = lstat(p, &b)))
    i = __io_errno();
  __cstr_free(p);
  statb[0] = b.st_dev;
  statb[1] = b.st_ino;
  statb[2] = b.st_mode;
  statb[3] = b.st_nlink;
  statb[4] = b.st_uid;
  statb[5] = b.st_gid;
  statb[6] = b.st_rdev;
  statb[7] = b.st_size;
  statb[8] = b.st_atime;
  statb[9] = b.st_mtime;
  statb[10] = b.st_ctime;
  statb[11] = b.st_blksize;
Example #4
0
/* clang-format off */

/*	renamefileqq3f.c - Implements DFLIB renamefileqq routine.  */

/* must include ent3f.h AFTER io3f.h */
#include "io3f.h"
#include "ent3f.h"

extern int rename();
extern char *__fstr2cstr();
extern void __cstr_free();

int ENT3F(RENAMEFILEQQ, renamefileqq)(DCHAR(from),
                                      DCHAR(to) DCLEN(from) DCLEN(to))
{
  int i;

  char *old, *new;

  old = __fstr2cstr(CADR(from), CLEN(from));
  new = __fstr2cstr(CADR(to), CLEN(to));
  i = rename(old, new);
  __cstr_free(old);
  __cstr_free(new);

  if (i == 0)  /* success */
    return -1; /* .true. */
  else         /* failure */
    return 0;  /* .false */
}
local int recmatch(ZCONST uch *p, ZCONST uch *s, int cs)
//ZCONST uch *p;  /* sh pattern to match */
//ZCONST uch *s;  /* string to match it to */
//int cs;         /* flag: force case-sensitive matching */
/* Recursively compare the sh pattern p with the string s and return 1 if
   they match, and 0 or 2 if they don't or if there is a syntax error in the
   pattern.  This routine recurses on itself no deeper than the number of
   characters in the pattern. */
{
  unsigned int c;       /* pattern char or start of range in [-] loop */
  /* Get first character, the pattern for new recmatch calls follows */
  c = *POSTINCSTR(p);

  /* If that was the end of the pattern, match if string empty too */
  if (c == 0)
    return *s == 0;

  /* '?' (or '%' or '#') matches any character (but not an empty string) */
#ifdef VMS
  if (c == '%')
#else /* !VMS */
# ifdef RISCOS
  if (c == '#')
# else /* !RISC OS */
  if (c == '?')
# endif
#endif /* ?VMS */
#ifdef WILD_STOP_AT_DIR
    return (*s && *s != '/') ? recmatch(p, s + CLEN(s), cs) : 0;
#else
    return *s ? recmatch(p, s + CLEN(s), cs) : 0;
#endif

  /* '*' matches any number of characters, including zero */
#ifdef AMIGA
  if (c == '#' && *p == '?')            /* "#?" is Amiga-ese for "*" */
    c = '*', p++;
#endif /* AMIGA */
  if (c == '*')
  {
    if (*p == 0)
      return 1;
#ifdef WILD_STOP_AT_DIR
    for (; *s && *s != '/'; INCSTR(s))
      if ((c = recmatch(p, s, cs)) != 0)
        return (int)c;
    return (*p == '/' || (*p == '\\' && p[1] == '/'))
      ? recmatch(p, s, cs) : 2;
#else /* !WILD_STOP_AT_DIR */
    for (; *s; INCSTR(s))
      if ((c = recmatch(p, s, cs)) != 0)
        return (int)c;
    return 2;           /* 2 means give up--shmatch will return false */
#endif /* ?WILD_STOP_AT_DIR */
  }

#ifndef VMS             /* No bracket matching in VMS */
  /* Parse and process the list of characters and ranges in brackets */
  if (c == '[')
  {
    int e;              /* flag true if next char to be taken literally */
    ZCONST uch *q;      /* pointer to end of [-] group */
    int r;              /* flag true to match anything but the range */

    if (*s == 0)                        /* need a character to match */
      return 0;
    p += (r = (*p == '!' || *p == '^')); /* see if reverse */
    for (q = p, e = 0; *q; q++)         /* find closing bracket */
      if (e)
        e = 0;
      else
        if (*q == '\\')
          e = 1;
        else if (*q == ']')
          break;
    if (*q != ']')                      /* nothing matches if bad syntax */
      return 0;
    for (c = 0, e = *p == '-'; p < q; p++)      /* go through the list */
    {
      if (e == 0 && *p == '\\')         /* set escape flag if \ */
        e = 1;
      else if (e == 0 && *p == '-')     /* set start of range if - */
        c = *(p-1);
      else
      {
        uch cc = (cs ? *s : case_map(*s));
        if (*(p+1) != '-')
          for (c = c ? c : (unsigned)*p; c <= (unsigned)*p; c++)
            /* compare range */
            if ((cs ? c : case_map(c)) == cc)
              return r ? 0 : recmatch(q + CLEN(q), s + CLEN(s), cs);
        c = e = 0;                      /* clear range, escape flags */
      }
    }
    return r ? recmatch(q + CLEN(q), s + CLEN(s), cs) : 0;
                                        /* bracket match failed */
  }
#endif /* !VMS */

  /* If escape ('\'), just compare next character */
  if (c == '\\')
    if ((c = *p++) == '\0')             /* if \ at end, then syntax error */
      return 0;

  /* Just a character--compare it */
  return (cs ? c == *s : case_map(c) == case_map(*s)) ?
          recmatch(p, s + CLEN(s), cs) : 0;
}
Example #6
0
/* ===========================================================================
 * Convert the external file name to an "internal" file name that
 * is valid to store in the ZIP archive, returning the malloc'ed
 * string, or NULL if not enough memory.
 * I.e. Strip the drive if present, strip the path if we don't want one
 * and change the name to 8.3 if needed.
 * Not inplemented, but also 'put in' change the short path to a long path.
	*x        :: External file name.
	*pdosflag :: Output: force MSDOS file attributes?
 */
char *ex2in( char *x, int *pdosflag, struct Globals *pG ) {
	char *n;              /* internal file name (malloc'ed)	*/
	char *t;              /* shortened name						*/
	char *x2;				 /* temporary x							*/
	int   dosflag;

	// sprintf( ewemsg,"in ex2in.  x=%s", x );
	// diag( ewemsg );

	dosflag = pG->dosify || IsFileSystemOldFAT( x, pG );
	if ( !pG->dosify && pG->use_longname_ea && (t = GetLongPathEA() ) != NULL ) {
		sprintf( pG->ewemsg, "replacing short name: %s with long name: %s", x, t );
		diag( pG->ewemsg, pG );
		x = t;
		dosflag = 0;
	}

	if ( (x2 = MALLOC( lstrlen( x ) + 1 )) == NULL ) return NULL;
	lstrcpy( x2, x );
	if ( pG->dosify )
		if ( (x2 = DOSName( x2, pG )) == NULL ) return NULL;	// We need a fully qualified path else this won't work. v1.55

	/* Find starting point in name before doing malloc */
	t = *x2 && isalpha((uch)*x2) && *(x2 + 1) == ':' ? x2 + 2 : x2;

	/* Strip "//host/share/" part of a UNC name v1.6017 */
	if ( !strncmp( x2, "\\\\", 2 ) && x2[2] != '\0' && x2[2] != '\\' ) {
		n = x2 + 2;
		while( *n != '\0' && *n != '\\' ) INCSTR( n );     /* strip host name    */
		if ( *n != '\0' ) {
			INCSTR( n );
			while( *n != '\0' && *n != '\\' ) INCSTR( n );  /* strip `share' name */
		}
		if (*n != '\0') t = n + CLEN( n );
	}

	/* Strip leading "\" to convert an absolute path into a relative path */
	while( *t == '\\' ) t++;

	/* Strip leading "./" as well as drive letter v1.6017*/
	while( *t == '.' && t[1] == '\\' ) t += 2;

	/* This is where the dirname gets stripped if user doesn't want it  */
	if ( !pG->pathput ) t = last( t, PATH_END );

	/* Malloc space for internal name and copy it */
	if ( (n = MALLOC( lstrlen( t ) + 1 )) == NULL ) {
		FREE( x2 );
		return NULL;
	}
	lstrcpy( n, t );

	/* set this return flag as needed */
	if ( pdosflag ) *pdosflag = dosflag;

	// sprintf( ewemsg, "ex2in returning: %s", n );
	// diag( ewemsg );

	FREE( x2 );

	/* Give the user a chance to change the internal name */
	user_callback( 7, 0, 0, n, pG );
	if ( pG->callbackdata.error_code ) {
		FREE( n );
		if ( (n = MALLOC( lstrlen( pG->callbackdata.filenameormsg ) + 1 )) == NULL )
			return NULL;
		lstrcpy( n, pG->callbackdata.filenameormsg );
	}
	/* Return the malloc'ed name */
	return n;
}