Beispiel #1
0
void test_attr_file__simple_read(void)
{
	git_attr_file *file;
	git_attr_assignment *assign;
	git_attr_rule *rule;

	cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr0")));

	cl_assert_equal_s(cl_fixture("attr/attr0"), file->key + 2);
	cl_assert(file->rules.length == 1);

	rule = get_rule(0);
	cl_assert(rule != NULL);
	cl_assert_equal_s("*", rule->match.pattern);
	cl_assert(rule->match.length == 1);
	cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);

	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule, 0);
	cl_assert(assign != NULL);
	cl_assert_equal_s("binary", assign->name);
	cl_assert(GIT_ATTR_TRUE(assign->value));

	git_attr_file__free(file);
}
Beispiel #2
0
void test_attr_file__simple_read(void)
{
	git_attr_file *file;
	git_attr_assignment *assign;
	git_attr_rule *rule;

	cl_git_pass(git_attr_file__new(&file));
	cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr0"), file));
	cl_assert_strequal(cl_fixture("attr/attr0"), file->path);
	cl_assert(file->rules.length == 1);

	rule = get_rule(0);
	cl_assert(rule != NULL);
	cl_assert_strequal("*", rule->match.pattern);
	cl_assert(rule->match.length == 1);
	cl_assert(rule->match.flags == 0);

	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule, 0);
	cl_assert(assign != NULL);
	cl_assert_strequal("binary", assign->name);
	cl_assert(assign->value == GIT_ATTR_TRUE);
	cl_assert(!assign->is_allocated);

	git_attr_file__free(file);
}
Beispiel #3
0
void test_attr_file__check_attr_examples(void)
{
	git_attr_file *file;
	git_attr_rule *rule;
	git_attr_assignment *assign;

	cl_git_pass(git_attr_file__new(&file));
	cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr3"), file));
	cl_assert_strequal(cl_fixture("attr/attr3"), file->path);
	cl_assert(file->rules.length == 3);

	rule = get_rule(0);
	cl_assert_strequal("*.java", rule->match.pattern);
	cl_assert(rule->assigns.length == 3);
	assign = git_attr_rule__lookup_assignment(rule, "diff");
	cl_assert_strequal("diff", assign->name);
	cl_assert_strequal("java", assign->value);
	assign = git_attr_rule__lookup_assignment(rule, "crlf");
	cl_assert_strequal("crlf", assign->name);
	cl_assert(GIT_ATTR_FALSE == assign->value);
	assign = git_attr_rule__lookup_assignment(rule, "myAttr");
	cl_assert_strequal("myAttr", assign->name);
	cl_assert(GIT_ATTR_TRUE == assign->value);
	assign = git_attr_rule__lookup_assignment(rule, "missing");
	cl_assert(assign == NULL);

	rule = get_rule(1);
	cl_assert_strequal("NoMyAttr.java", rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule, 0);
	cl_assert_strequal("myAttr", assign->name);
	cl_assert(assign->value == NULL);

	rule = get_rule(2);
	cl_assert_strequal("README", rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule, 0);
	cl_assert_strequal("caveat", assign->name);
	cl_assert_strequal("unspecified", assign->value);

	git_attr_file__free(file);
}
Beispiel #4
0
static void check_one_assign(
	git_attr_file *file,
	int rule_idx,
	int assign_idx,
	const char *pattern,
	const char *name,
	enum attr_expect_t expected,
	const char *expected_str)
{
	git_attr_rule *rule = get_rule(rule_idx);
	git_attr_assignment *assign = get_assign(rule, assign_idx);

	cl_assert_equal_s(pattern, rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	cl_assert_equal_s(name, assign->name);
	cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name));

	attr_check_expected(expected, expected_str, assign->value);
}
Beispiel #5
0
static void check_one_assign(
	git_attr_file *file,
	int rule_idx,
	int assign_idx,
	const char *pattern,
	const char *name,
	const char *value,
	int is_allocated)
{
	git_attr_rule *rule = get_rule(rule_idx);
	git_attr_assignment *assign = get_assign(rule, assign_idx);

	cl_assert_strequal(pattern, rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	cl_assert_strequal(name, assign->name);
	cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name));
	cl_assert(assign->is_allocated == is_allocated);
	if (is_allocated)
		cl_assert_strequal(value, assign->value);
	else
		cl_assert(assign->value == value);
}
Beispiel #6
0
/*------------------------------------------------------------------*/
static byte isdn_rc(ADAPTER *a,
		    byte Rc,
		    byte Id,
		    byte Ch,
		    word Ref,
		    dword extended_info_type,
		    dword extended_info)
{
	ENTITY *this;
	byte e_no;
	word i;
	int cancel_rc;
#ifdef USE_EXTENDED_DEBUGS
	{
		DBG_TRC(("<A%d Id=0x%x Rc=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, Id, Rc))
			}
#else
	dbug(dprintf("isdn_rc(Rc=%x,Id=%x,Ch=%x)", Rc, Id, Ch));
#endif
	/* check for ready interrupt                                */
	if (Rc == READY_INT) {
		xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, 0);
		if (a->ReadyInt) {
			a->ReadyInt--;
			return 0;
		}
		return 2;
	}
	/* if we know this Id ...                                   */
	e_no = a->IdTable[Id];
	if (e_no) {
		this = entity_ptr(a, e_no);
		xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, a->IdTypeTable[this->No]);
		this->RcCh = Ch;
		/* if it is a return code to a REMOVE request, remove the   */
		/* Id from our table                                        */
		if ((a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_REMOVE_PENDING) &&
		    (Rc == OK)) {
			if (a->IdTypeTable[e_no] == NL_ID) {
				if (a->RcExtensionSupported &&
				    (extended_info_type != DIVA_RC_TYPE_REMOVE_COMPLETE)) {
					dtrc(dprintf("XDI: N-REMOVE, A(%02x) Id:%02x, ignore RC=OK",
						     XDI_A_NR(a), Id));
					return (0);
				}
				if (extended_info_type == DIVA_RC_TYPE_REMOVE_COMPLETE)
					a->RcExtensionSupported = true;
			}
			a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_REMOVE_PENDING;
			a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_NO_RC_CANCELLING;
			free_entity(a, e_no);
			for (i = 0; i < 256; i++)
			{
				if (a->FlowControlIdTable[i] == Id)
					a->FlowControlIdTable[i] = 0;
			}
			a->IdTable[Id] = 0;
			this->Id = 0;
			/* ---------------------------------------------------------------
			   If we send N_DISC or N_DISK_ACK after we have received OK_FC
			   then the card will respond with OK_FC and later with RC==OK.
			   If we send N_REMOVE in this state we will receive only RC==OK
			   This will create the state in that the XDI is waiting for the
			   additional RC and does not delivery the RC to the client. This
			   code corrects the counter of outstanding RC's in this case.
			   --------------------------------------------------------------- */
			if ((this->More & XMOREC) > 1) {
				this->More &= ~XMOREC;
				this->More |= 1;
				dtrc(dprintf("XDI: correct MORE on REMOVE A(%02x) Id:%02x",
					     XDI_A_NR(a), Id));
			}
		}
		if (Rc == OK_FC) {
			a->FlowControlIdTable[Ch] = Id;
			a->FlowControlSkipTable[Ch] = false;
			this->Rc = Rc;
			this->More &= ~(XBUSY | XMOREC);
			this->complete = 0xff;
			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
			CALLBACK(a, this);
			return 0;
		}
		/*
		  New protocol code sends return codes that comes from release
		  of flow control condition marked with DIVA_RC_TYPE_OK_FC extended
		  information element type.
		  If like return code arrives then application is able to process
		  all return codes self and XDI should not cances return codes.
		  This return code does not decrement XMOREC partial return code
		  counter due to fact that it was no request for this return code,
		  also XMOREC was not incremented.
		*/
		if (extended_info_type == DIVA_RC_TYPE_OK_FC) {
			a->misc_flags_table[e_no] |= DIVA_MISC_FLAGS_NO_RC_CANCELLING;
			this->Rc = Rc;
			this->complete = 0xff;
			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
			DBG_TRC(("XDI OK_FC A(%02x) Id:%02x Ch:%02x Rc:%02x",
				 XDI_A_NR(a), Id, Ch, Rc))
				CALLBACK(a, this);
			return 0;
		}
		cancel_rc = !(a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_NO_RC_CANCELLING);
		if (cancel_rc && (a->FlowControlIdTable[Ch] == Id))
		{
			a->FlowControlIdTable[Ch] = 0;
			if ((Rc != OK) || !a->FlowControlSkipTable[Ch])
			{
				this->Rc = Rc;
				if (Ch == this->ReqCh)
				{
					this->More &= ~(XBUSY | XMOREC);
					this->complete = 0xff;
				}
				xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
				CALLBACK(a, this);
			}
			return 0;
		}
		if (this->More & XMOREC)
			this->More--;
		/* call the application callback function                   */
		if (((!cancel_rc) || (this->More & XMOREF)) && !(this->More & XMOREC)) {
			this->Rc = Rc;
			this->More &= ~XBUSY;
			this->complete = 0xff;
			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
			CALLBACK(a, this);
		}
		return 0;
	}
	/* if it's an ASSIGN return code check if it's a return     */
	/* code to an ASSIGN request from us                        */
	if ((Rc & 0xf0) == ASSIGN_RC) {
		e_no = get_assign(a, Ref);
		if (e_no) {
			this = entity_ptr(a, e_no);
			this->Id = Id;
			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 2, a->IdTypeTable[this->No]);
			/* call the application callback function                   */
			this->Rc = Rc;
			this->More &= ~XBUSY;
			this->complete = 0xff;
#if defined(DIVA_ISTREAM) /* { */
			if ((Rc == ASSIGN_OK) && a->ram_offset &&
			    (a->IdTypeTable[this->No] == NL_ID) &&
			    ((extended_info_type == DIVA_RC_TYPE_RX_DMA) ||
			     (extended_info_type == DIVA_RC_TYPE_CMA_PTR)) &&
			    extended_info) {
				dword offset = (*(a->ram_offset)) (a);
				dword tmp[2];
				extended_info -= offset;
#ifdef PLATFORM_GT_32BIT
				a->ram_in_dw(a, (void *)ULongToPtr(extended_info), (dword *)&tmp[0], 2);
#else
				a->ram_in_dw(a, (void *)extended_info, (dword *)&tmp[0], 2);
#endif
				a->tx_stream[Id]  = tmp[0];
				a->rx_stream[Id]  = tmp[1];
				if (extended_info_type == DIVA_RC_TYPE_RX_DMA) {
					DBG_TRC(("Id=0x%x RxDMA=%08x:%08x",
						 Id, a->tx_stream[Id], a->rx_stream[Id]))
						a->misc_flags_table[this->No] |= DIVA_MISC_FLAGS_RX_DMA;
				} else {
					DBG_TRC(("Id=0x%x CMA=%08x:%08x",
						 Id, a->tx_stream[Id], a->rx_stream[Id]))
						a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA;
					a->rx_pos[Id]     = 0;
					a->rx_stream[Id] -= offset;
				}
				a->tx_pos[Id]     = 0;
				a->tx_stream[Id] -= offset;
			} else {
				a->tx_stream[Id] = 0;
				a->rx_stream[Id] = 0;
				a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA;
			}
#endif /* } */
			CALLBACK(a, this);
			if (Rc == ASSIGN_OK) {
				a->IdTable[Id] = e_no;
			}
			else
			{
				free_entity(a, e_no);
				for (i = 0; i < 256; i++)
				{
					if (a->FlowControlIdTable[i] == Id)
						a->FlowControlIdTable[i] = 0;
				}
				a->IdTable[Id] = 0;
				this->Id = 0;
			}
			return 1;
		}
	}
	return 2;
}
Beispiel #7
0
void test_attr_file__match_variants(void)
{
	git_attr_file *file;
	git_attr_rule *rule;
	git_attr_assignment *assign;

	cl_git_pass(git_attr_file__new(&file));
	cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr1"), file));
	cl_assert_strequal(cl_fixture("attr/attr1"), file->path);
	cl_assert(file->rules.length == 10);

	/* let's do a thorough check of this rule, then just verify
	 * the things that are unique for the later rules
	 */
	rule = get_rule(0);
	cl_assert(rule);
	cl_assert_strequal("pat0", rule->match.pattern);
	cl_assert(rule->match.length == strlen("pat0"));
	cl_assert(rule->match.flags == 0);
	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule,0);
	cl_assert_strequal("attr0", assign->name);
	cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name));
	cl_assert(assign->value == GIT_ATTR_TRUE);
	cl_assert(!assign->is_allocated);

	rule = get_rule(1);
	cl_assert_strequal("pat1", rule->match.pattern);
	cl_assert(rule->match.length == strlen("pat1"));
	cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_NEGATIVE);

	rule = get_rule(2);
	cl_assert_strequal("pat2", rule->match.pattern);
	cl_assert(rule->match.length == strlen("pat2"));
	cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_DIRECTORY);

	rule = get_rule(3);
	cl_assert_strequal("pat3dir/pat3file", rule->match.pattern);
	cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_FULLPATH);

	rule = get_rule(4);
	cl_assert_strequal("pat4.*", rule->match.pattern);
	cl_assert(rule->match.flags == 0);

	rule = get_rule(5);
	cl_assert_strequal("*.pat5", rule->match.pattern);

	rule = get_rule(7);
	cl_assert_strequal("pat7[a-e]??[xyz]", rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule,0);
	cl_assert_strequal("attr7", assign->name);
	cl_assert(assign->value == GIT_ATTR_TRUE);

	rule = get_rule(8);
	cl_assert_strequal("pat8 with spaces", rule->match.pattern);
	cl_assert(rule->match.length == strlen("pat8 with spaces"));
	cl_assert(rule->match.flags == 0);

	rule = get_rule(9);
	cl_assert_strequal("pat9", rule->match.pattern);

	git_attr_file__free(file);
}
Beispiel #8
0
static
byte isdn_rc(ADAPTER * a,
             byte Rc,
             byte Id,
             byte Ch,
             word Ref)
{
  ENTITY  * this;
  byte e_no;

#ifdef	USE_EXTENDED_DEBUGS
	{
		ISDN_ADAPTER *io = (ISDN_ADAPTER *)a->io ;
		DPRINTF(("IDI: <A%d Id=0x%x Rc=0x%x", io->ANum, Id, Rc))
	}
#else
  DPRINTF(("IDI: <RC(Rc=%x,Id=%x,Ch=%x)",Rc,Id,Ch));
#endif

        /* check for ready interrupt                                */
  if(Rc==READY_INT) {
    if(a->ReadyInt) {
      a->ReadyInt--;
      return 0;
    }
    return 2;
  }

        /* if we know this Id ...                                   */
  e_no = a->IdTable[Id];
  if(e_no) {

    this = entity_ptr(a,e_no);

    this->RcCh = Ch;

        /* if it is a return code to a REMOVE request, remove the   */
        /* Id from our table                                        */
    if(this->Req==REMOVE && Rc==OK) {
      free_entity(a, e_no);
      a->IdTable[Id] = 0;
      this->Id = 0;
/**************************************************************/
      if ((this->More & XMOREC) > 1) {
        this->More &= ~XMOREC;
	this->More |= 1;
	DPRINTF(("isdn_rc, Id=%x, correct More on REMOVE", Id));
      }
    }

    if (Rc==OK_FC) {
      this->Rc = Rc;
      this->More = (this->More & (~XBUSY | XMOREC)) | 1;
      this->complete = 0xFF;
      CALLBACK(a, this);
      return 0;
    }
    if(this->More &XMOREC)
      this->More--;

        /* call the application callback function                   */
    if(this->More &XMOREF && !(this->More &XMOREC)) {
      this->Rc = Rc;
      this->More &=~XBUSY;
      this->complete=0xff;
      CALLBACK(a, this);
    }
    return 0;
  }

        /* if it's an ASSIGN return code check if it's a return     */
        /* code to an ASSIGN request from us                        */
  if((Rc &0xf0)==ASSIGN_RC) {

    e_no = get_assign(a, Ref);

    if(e_no) {

      this = entity_ptr(a,e_no);

      this->Id = Id;

        /* call the application callback function                   */
      this->Rc = Rc;
      this->More &=~XBUSY;
      this->complete=0xff;
      CALLBACK(a, this);

      if(Rc==ASSIGN_OK) {
        a->IdTable[Id] = e_no;
      }
      else
      {
        free_entity(a, e_no);
        a->IdTable[Id] = 0;
        this->Id = 0;
      }
      return 1;
    }
  }
  return 2;
}
Beispiel #9
0
int analyze_cndtl(char *s)
{
    char *p;
    char *q;
    char left[SMABUF];
    char right[SMABUF];
    char oper[SMABUF];
    int lint;
    int rint;
    int oper_flag = -1;

    /*
     * 1 = ==
     * 2 >
     * 3 >=
     * 4 <
     * 5 <=
     * 6 != <>
     * 7 !        test for empty string
     */
    p = skip_space(s);

    if (pattern_match(p, "* = *", pattern)
        || pattern_match(p, "* == *", pattern)) {
        oper_flag = 1;
    } else if (pattern_match(p, "* > *", pattern)) {
        oper_flag = 2;
    } else if (pattern_match(p, "* >= *", pattern)) {
        oper_flag = 3;
    } else if (pattern_match(p, "* < *", pattern)) {
        oper_flag = 4;
    } else if (pattern_match(p, "* <= *", pattern)) {
        oper_flag = 5;
    } else if (pattern_match(p, "* != *", pattern)
               || pattern_match(p, "* <> *", pattern)) {
        oper_flag = 6;
    }

    if (!*pattern1) {
        *left = '\0';
    } else {
        strcpy(left, pattern1);
    }

    if (!*pattern2) {
        *right = '\0';
    } else {
        strcpy(right, pattern2);
    }

    p = skip_space(left);
    remove_space_at_end(left);

    if (*p == '$') {
        q = get_assign(p + 1);

        if (q) {
            strcpy(left, q);
        } else {
            *left = '\0';
        }
    } else if (*p == '\"') {
        ++p;
        q = strchr(p, '\"');

        if (q) {
            *q = '\0';
        } else {
            msg("Error...need an ending quote");

            return 0;
        }
    }

    strcpy(oper, p);
    strcpy(left, oper);
    p = skip_space(right);
    remove_space_at_end(right);

    if (*p == '$') {
        q = get_assign(p + 1);
        strcpy(right, q);
    } else if (*p == '\"') {
        ++p;
        q = strchr(p, '\"');

        if (q) {
            *q = '\0';
        } else {
            msg("Error...need an ending quote");

            return 0;
        }
    }

    strcpy(oper, p);
    strcpy(right, oper);
    debug(2, "left: \'%s\'", left);
    debug(2, "right: \'%s\'", right);

    switch (oper_flag) {
    case 1:
        if (!strcmp(left, right)) {
            return 1;
        }

        break;
    case 2:
        lint = atoi(left);
        rint = atoi(right);

        if (lint > rint) {
            return 1;
        }

        break;
    case 3:
        lint = atoi(left);
        rint = atoi(right);

        if (lint >= rint) {
            return 1;
        }

        break;
    case 4:
        lint = atoi(left);
        rint = atoi(right);

        if (lint < rint) {
            return 1;
        }

        break;
    case 5:
        lint = atoi(left);
        rint = atoi(right);

        if (lint <= rint) {
            return 1;
        }

        break;
    case 6:
        if (strcmp(left, right)) {
            return 1;
        }

        break;
    default:
        msg("-- if: unknown oper_flag %d report to author", oper_flag);

        break;
    }

    return 0;
}