コード例 #1
0
ファイル: sql_query.cpp プロジェクト: royratcliffe/ta-lib
void SQLQuery::parse() {
    string str = "";
    char num[3];
    long int n;
    char option;
    string name;
    char *s, *s0;
    s0 = s = preview_char();
    while (*s) {
        if (*s == '%') {
            s++;
            if (*s == '%') {
                str += *s++;
            } else if (*s >= '0' && *s <= '9') {
                num[0] = *s;
                s++;
                if (*s >= '0' && *s <= '9') {
                    num[1] = *s;
                    num[2] = 0;
                    s++;
                } else {
                    num[1] = 0;
                }
                n = strtol(num,NULL,10);
                option = ' ';
                if (*s == 'q' || *s == 'Q' || *s == 'r' || *s == 'R')
                    option = *s++;
                if (*s == ':') {
                    s++;
                    for (; (*s>='A' && *s<='Z') || *s=='_' || (*s>='a' && *s<='z'); s++) {
                        name += *s;
                    }
                    if (*s == ':') s++;
                    if (n >= (long int)parsed_names.size())
                        parsed_names.insert(parsed_names.end(),
                                            (vector<string>::size_type)(n+1)
                                            - parsed_names.size(), string());
                    parsed_names[n] = name;
                    parsed_nums[name] = n;
                }

                parsed.push_back( SQLParseElement(str,option,n) );
                str = "";
                name = "";
            } else {
                str += '%';
            }
        } else {
            str += *s++;
        }
    }
    parsed.push_back( SQLParseElement(str,' ',-1) );
    delete[] s0;
}
コード例 #2
0
ファイル: ex8.c プロジェクト: 128keaton/ltdc
// do the whole preview table and stuff :)
void do_preview(u_char* buf) {
	int asc, x, y, addr;
	u_char st;

	set_color(15, 4, 4);
	set_sprite_8(0, square);

	fill(MODE2_ATTR, 0xF0, MODE2_MAX);

	// start blitting buffer at pixel (16,16)
	addr = map_block(16, 16);

	// 16 chars of width (*8), 16 "lines", jump 256 in VRAM for each line
	blit_ram_vram(buf, addr, 16 * 8, 16, 16 * 8, 256);

	// fill yellow background
	blit_fill_vram(MODE2_ATTR + map_block(8, 8), 0x1A, 8 * 18, 18, 256);

	x = 0; y = 0;

	// preview loop
	while (!get_trigger(0)) {
		// move the cursor and set the zooming
		st = st_dir[get_stick(0)];

		x += (st & st_right) ? 1 : ((st & st_left) ? -1 : 0);
		y += (st & st_down) ? 1 : ((st & st_up) ? -1 : 0);

		x &= 15;
		y &= 15;
		asc = (y << 4) + x;
		put_sprite_8(0, (x + 2) << 3, (y + 2) << 3, 0, 9);

		preview_char(buf + (asc << 3));
	}	
}
コード例 #3
0
ファイル: query.cpp プロジェクト: ledusledus/meos
void
Query::parse()
{
	std::string str = "";
	char num[4];
	std::string name;
	char *s, *s0;
	s0 = s = preview_char();
	while (*s) {
		if (*s == '%') {
			// Following might be a template parameter declaration...
			s++;
			if (*s == '%') {
				// Doubled percent sign, so insert literal percent sign.
				str += *s++;
			}
			else if (isdigit(*s)) {
				// Number following percent sign, so it signifies a
				// positional parameter.  First step: find position
				// value, up to 3 digits long.
				num[0] = *s;
				s++;
				if (isdigit(*s)) {
					num[1] = *s;
					num[2] = 0;
					s++;
					if (isdigit(*s)) {
						num[2] = *s;
						num[3] = 0;
						s++;
					}
					else {
						num[2] = 0;
					}
				}
				else {
					num[1] = 0;
				}
				signed char n = atoi(num);

				// Look for option character following position value.
				char option = ' ';
				if (*s == 'q' || *s == 'Q' || *s == 'r' || *s == 'R') {
					option = *s++;
				}

				// Is it a named parameter?
				if (*s == ':') {
					// Save all alphanumeric and underscore characters
					// following colon as parameter name.
					s++;
					for (/* */; isalnum(*s) || *s == '_'; ++s) {
						name += *s;
					}

					// Eat trailing colon, if it's present.
					if (*s == ':') {
						s++;
					}

					// Update maps that translate parameter name to
					// number and vice versa.
					if (n >= static_cast<short>(parsed_names_.size())) {
						parsed_names_.insert(parsed_names_.end(),
								static_cast<std::vector<std::string>::size_type>(
										n + 1) - parsed_names_.size(),
								std::string());
					}
					parsed_names_[n] = name;
					parsed_nums_[name] = n;
				}

				// Finished parsing parameter; save it.
				parse_elems_.push_back(SQLParseElement(str, option, n));
				str = "";
				name = "";
			}
			else {
				// Insert literal percent sign, because sign didn't
				// precede a valid parameter string; this allows users
				// to play a little fast and loose with the rules,
				// avoiding a double percent sign here.
				str += '%';
			}
		}
		else {
			// Regular character, so just copy it.
			str += *s++;
		}
	}

	parse_elems_.push_back(SQLParseElement(str, ' ', -1));
	delete[] s0;
}