Ejemplo n.º 1
0
/* added */
int GetArray(char*& p, int e[], int add, int dc) {
	aint val;
	int t = 0;
	while ('o') {
		SkipBlanks(p);
		if (!*p) {
			Error("Expression expected", 0, SUPPRESS); break;
		}
		if (t == 128) {
			Error("Too many arguments", p, SUPPRESS); break;
		}
		if (*p == '"') {
			p++;
			do {
				if (!*p || *p == '"') {
					Error("Syntax error", p, SUPPRESS); e[t] = -1; return t;
				}
				if (t == 128) {
					Error("Too many arguments", p, SUPPRESS); e[t] = -1; return t;
				}
				GetCharConstChar(p, val); check8(val); e[t++] = (val + add) & 255;
			} while (*p != '"');
			++p; if (dc && t) {
				 	e[t - 1] |= 128;
				 }
			/* (begin add) */
		} else if ((*p == 0x27) && (!*(p+2) || *(p+2) != 0x27)) {
		  	p++;
			do {
				if (!*p || *p == 0x27) {
					Error("Syntax error", p, SUPPRESS); e[t] = -1; return t;
				}
				if (t == 128) {
		  			Error("Too many arguments", p, SUPPRESS); e[t] = -1; return t;
				}
		  		GetCharConstCharSingle(p, val); check8(val); e[t++] = (val + add) & 255;
			} while (*p != 0x27);
		  	++p;
			if (dc && t) {
				 e[t - 1] |= 128;
			}
		  	/* (end add) */
		} else {
			if (ParseExpression(p, val)) {
				check8(val); e[t++] = (val + add) & 255;
			} else {
				Error("Syntax error", p, SUPPRESS); break;
			}
		}
		SkipBlanks(p); if (*p != ',') {
					   	break;
					   } ++p;
	}
	e[t] = -1; return t;
}
Ejemplo n.º 2
0
int main()
{
      int tmp;
      long int len;
      long int i;
      long int ctr;
      char str[256];
      while (scanf("%s", str) != EOF) {
            int arr[10] = {0};
            len = strlen(str);
            ctr = 0;
            if (len < 2) {
                  printf("1\n");
                  continue;
            }
            arr[1] = 1;
            arr[2] = ((str[len-1]-'0')%2 == 0);
            arr[3] = (check3(str));
            arr[4] = (((str[len-1] - '0') + (str[len-2] - '0')*10)%4 == 0);
            arr[5] = ((str[len-1]-'0')%5 == 0);
            arr[6] = (!(!(((str[len-1]-'0')%2 == 0 ) && arr[3])));
            arr[7] = check7(str);
            arr[8] = (check8(str));
            arr[9] = (check9(str));

            for (i =0 ;i<len; i++) {
                  tmp = (str[i] - '0');
                  ctr = ctr + arr[tmp];
            }
            printf("%ld\n", ctr);
      }
      return 0;
}
Ejemplo n.º 3
0
bool Control::check(std::vector<int> &n)
{
    getOutCard(n);

    bool result=false;
    switch (n.size())
    {
    case 1:
        result=check1();
        break;
    case 2:
        result=check2();
        break;
    case 3:
        result=check3();
        break;
    case 4:
        result=check4();
        break;
    case 5:
        result=check5();
        break;
    case 6:
        result=check6();
        break;
    case 7:
    case 11:
    case 13:
        result=check7();
        break;
    case 8:
        result=check8();
        break;
    case 9:
        result=check9();
        break;
    case 10:
        result=check10();
        break;
    case 12:
        result=check12();
        break;
    case 14:
        result=check14();
        break;
    case 15:
        result=check15();
        break;
    case 16:
        result=check16();
        break;
    }
    return result;
}
int check(int length1, float *number3, int *oper3){
	if (length1 == 1)
		return check1(number3,oper3);
	if (length1 == 2)
		return check2(number3,oper3);
	if (length1 == 3)
		return check3(number3,oper3);
	if (length1 == 4)
		return check4(number3,oper3);
	if (length1 == 5)
		return check5(number3,oper3);
	if (length1 == 6)
		return check6(number3,oper3);
	if (length1 == 7)
		return check7(number3,oper3);
	if (length1 == 8)
		return check8(number3,oper3);
	if (length1 == 9)
		return check9(number3,oper3);
	if (length1 == 10)
		return check10(number3,oper3);
	return 0;
}
Ejemplo n.º 5
0
/* Wake the scanner, detect it, and fill sp with stuff */
int sanei_canon_pp_initialise(scanner_parameters *sp, int mode)
{
	unsigned char scanner_info[12];
	const struct scanner_id *cur_id;
	const struct scanner_hardware_desc *hw;

	/* Hopefully take the scanner out of transparent mode */
	if (sanei_canon_pp_wake_scanner(sp->port, mode))
	{
		DBG(10, "initialise: could not wake scanner\n");
		return 1;
	}

	/* This block of code does something unknown but necessary */
	DBG(50, "initialise: >> scanner_init\n");
	if (sanei_canon_pp_scanner_init(sp->port))
	{
		/* If we're using an unsupported ieee1284 mode here, this is 
		 * where it will fail, so fall back to nibble. */
		sanei_canon_pp_set_ieee1284_mode(M1284_NIBBLE);
		if (sanei_canon_pp_scanner_init(sp->port))
		{
			DBG(10, "initialise: Could not init scanner.\n");
			return 1;
		}
	}
	DBG(50, "initialise: << scanner_init\n");

	/* Read Device ID */
	memset(sp->id_string, 0, sizeof sp->id_string);
	if (send_command(sp->port, cmd_readid, 10, 10000, 100000))
		return -1;
	sanei_canon_pp_read(sp->port, 38, (unsigned char *)(sp->id_string));

	/* Read partially unknown data */
	if (send_command(sp->port, cmd_readinfo, 10, 10000, 100000))
		return -1;
	sanei_canon_pp_read(sp->port, 12, scanner_info);

	if (check8(scanner_info, 12))
	{
		DBG(10, "initialise: Checksum error reading Info Block.\n");
		return 2;
	}

	sp->scanheadwidth = (scanner_info[2] << 8) | scanner_info[3];

	/* Set up various known values */
	cur_id = scanner_id_table;
	while (cur_id->id)
	{
		if (!strncmp(sp->id_string+8, cur_id->id, strlen(cur_id->id)))
			break;
		cur_id++;
	}

	if (cur_id->id)
	{
		hw = cur_id->hw;
	}
	else if (sp->scanheadwidth == 5104) 
	{
		/* Guess 600dpi scanner */
		hw = &hw_alien600;
	}
	else if (sp->scanheadwidth == 2552) 
	{
		/* Guess 300dpi scanner */
		hw = &hw_alien300;
	}
	else
	{
		/* Guinea Pigs :) */
		hw = &hw_alien;
	}

	strcpy(sp->name, hw->name);
	sp->natural_xresolution = hw->natural_xresolution;	
	sp->natural_yresolution = hw->natural_yresolution;	
	sp->scanbedlength = hw->scanbedlength;
	if (hw->scanheadwidth)
		sp->scanheadwidth = hw->scanheadwidth;
	sp->type = hw->type;

	return 0;	
}
Ejemplo n.º 6
0
int sanei_canon_pp_init_scan(scanner_parameters *sp, scan_parameters *scanp)
{
	/* Command for: Initialise and begin the scan procedure */
	unsigned char command_b[56];

	/* Buffer for buffer info block */
	unsigned char buffer_info_block[6];

	/* The image size the scanner says we asked for 
	   (based on the scanner's replies) */
	int true_scanline_size, true_scanline_count;

	/* The image size we expect to get (based on *scanp) */
	int expected_scanline_size, expected_scanline_count;

	/* Set up the default scan command packet */
	memcpy(command_b, cmd_initscan, 10);
	memcpy(command_b+10, cmd_scan, 45);

	/* Load the proper settings into it */
	scanner_setup_params(command_b+10, sp, scanp);

	/* Add checksum byte */
	command_b[55] = check8(command_b+10, 45);

	if (send_command(sp->port, command_b, 56, 50000, 1000000))
		return -1;
		
	/* Ask the scanner about the buffer */
	if (send_command(sp->port, cmd_buf_status, 10, 50000, 1000000))
		return -1;

	/* Read buffer information block */
	sanei_canon_pp_read(sp->port, 6, buffer_info_block);

	if (check8(buffer_info_block, 6)) 
		DBG(1, "init_scan: ** Warning: Checksum error reading buffer "
				"info block.\n");

	expected_scanline_count = scanp->height;

	switch(scanp->mode)
	{
		case 0: /* greyscale; 10 bits per pixel */
			expected_scanline_size = scanp->width * 1.25; break;
		case 1: /* true-colour; 30 bits per pixel */
			expected_scanline_size = scanp->width * 3.75; break;
		default: 
			DBG(1, "init_scan: Illegal mode %i requested in "
					"init_scan().\n", scanp->mode);
			DBG(1, "This is a bug. Please report it.\n");
			return -1;
	}

	/* The scanner's idea of the length of each scanline in bytes */
	true_scanline_size = (buffer_info_block[0]<<8) | buffer_info_block[1]; 
	/* The scanner's idea of the number of scanlines in total */
	true_scanline_count = (buffer_info_block[2]<<8) | buffer_info_block[3]; 

	if ((expected_scanline_size != true_scanline_size) 
			|| (expected_scanline_count != true_scanline_count))
	{
		DBG(10, "init_scan: Warning: Scanner is producing an image "
				"of unexpected size:\n");
		DBG(10, "expected: %i bytes wide, %i scanlines tall.\n", 
				expected_scanline_size, 
				expected_scanline_count);
		DBG(10, "true: %i bytes wide, %i scanlines tall.\n", 
				true_scanline_size, true_scanline_count);

		if (scanp->mode == 0)
			scanp->width = true_scanline_size / 1.25;
		else
			scanp->width = true_scanline_size / 3.75;				

		scanp->height = true_scanline_count;
	}
	return 0;	
}