Ejemplo n.º 1
0
		bool install_(const std::string& key, const T& value)
		{
			std::string fpath;
			if(!create_full_path(key, fpath)) {
				return false;
			}

			bool f = false;
			utils::strings ss = split_text(fpath, "/");
			std::string p;
			for(uint32_t i = 0; i < ss.size(); ++i) {
				p += '/';
				p += ss[i];
				unit_t u;
				u.value = value;
				u.set_id(serial_id_);
				std::pair<unit_map_it, bool> ret = unit_map_.insert(unit_pair(p, u));
				if(ret.second) {
					++serial_id_;
					auto prev = utils::get_file_path(p);
					if(p != prev) {
						unit_map_it it = unit_map_.find(prev);
						if(it != unit_map_.end()) {
							unit_t& t = it->second;
							t.install_child(utils::get_file_name(p));
						}
					}
					f = true;
				} else {
					f = false;
				}
			}
			return f;
		}
Ejemplo n.º 2
0
size_t text_surface::height() const
{
	if (h_ == -1) {
		if(chunks_.empty())
			chunks_ = split_text(str_);
		measure();
	}
	return h_;
}
Ejemplo n.º 3
0
size_t text_surface::width() const
{
	if (w_ == -1) {
		if(chunks_.empty())
			chunks_ = split_text(str_);
		measure();
	}
	return w_;
}
Ejemplo n.º 4
0
bool CSSInlineLayoutAlignLine::node(CSSInlineGeneratedBox *cur)
{
	cur->x += offset_x;
	cur->y = baseline_y - cur->ascent;
	if (cur->layout_node && (cur->layout_node->is_replaced() || cur->layout_node->get_element_node()->is_inline_block_level()))
	{
		cur->layout_node->set_root_block_position(cur->x, cur->y);
	}

	if (word_count != 0)
	{
		CSSBoxNode *node = cur->box_node;
		CSSBoxText *text = dynamic_cast<CSSBoxText*>(node);
		if (text)
		{
			for (size_t j = cur->text_start; j < cur->text_end; j++)
			{
				if (text->processed_text[j] == ' ')
				{
					prev_space = true;
				}
				else
				{
					if (prev_space && !start_of_line)
					{
						split_text(cur, j, graphics, resources);
						cur = cur->next_sibling;

						CSSActualValue v1 = extra_total * word_index / word_count;
						CSSActualValue v2 = extra_total * (word_index + 1) / word_count;
						CSSActualValue word_offset_x = v2-v1;
						word_index++;

						cur->x += word_offset_x;
						if (cur->parent)
							expand_box(cur->parent, word_offset_x);
						offset_x += word_offset_x;

						prev_space = false;
						start_of_line = false;
						break;
					}
					else
					{
						prev_space = false;
						start_of_line = false;
					}
				}
			}
		}
	}
	return true;
}
Ejemplo n.º 5
0
void set_char_type(const char *type, char *ch)
{
  assert(ch != 0);
  int st = lookup_spacing_type(type);
  int ft = lookup_font_type(type);
  if (st < 0 && ft < 0) {
    error("bad character type `%1'", type);
    a_delete ch;
    return;
  }
  box *b = split_text(ch);
  b->handle_char_type(st, ft);
  delete b;
}
Ejemplo n.º 6
0
int send_as_sms(struct sms_msg *sms_messg, struct modem *mdm)
{
	static char   buf[MAX_SMS_LENGTH];
	unsigned int  buf_len;
	unsigned char len_array_1[256], len_array_2[256], *len_array;
	unsigned int  nr_chunks_1,  nr_chunks_2, nr_chunks;
	unsigned int  use_nice;
	str  text;
	char *p, *q;
	int  ret_code;
	int  i;

	text.s   = sms_messg->text.s;
	text.len = sms_messg->text.len;

	nr_chunks_1 = split_text( &text, len_array_1, 0);
	nr_chunks_2 = split_text( &text, len_array_2, 1);
	if (nr_chunks_1==nr_chunks_2) {
		len_array = len_array_2;
		nr_chunks = nr_chunks_2;
		use_nice = 1;
	} else {
		len_array = len_array_1;
		nr_chunks = nr_chunks_1;
		use_nice = 0;
	}

	sms_messg->ref = 1;
	for(i=0,p=text.s ; i<nr_chunks&&i<max_sms_parts ; p+=len_array[i++]) {
		if (use_nice) {
			q = buf;
			if (nr_chunks>1 && i)  {
				append_str(q,SMS_EDGE_PART,SMS_EDGE_PART_LEN);
				*(q-2)=nr_chunks+'0';
				*(q-4)=i+1+'0';
			}
			append_str(q,p,len_array[i]);
			if (nr_chunks>1 && !i)  {
				append_str(q,SMS_EDGE_PART,SMS_EDGE_PART_LEN);
				*(q-2)=nr_chunks+'0';
				*(q-4)=i+1+'0';
			}
			buf_len = q-buf;
		} else {
			q = buf;
			append_str(q,p,len_array[i]);
			buf_len = len_array[i];
		}
		if (i+1==max_sms_parts && i+1<nr_chunks) {
			/* simply override the end of the last allowed part */
			buf_len += SMS_TRUNCATED_LEN+SMS_FOOTER_LEN;
			if (buf_len>MAX_SMS_LENGTH) buf_len = MAX_SMS_LENGTH;
			q = buf + (buf_len-SMS_TRUNCATED_LEN-SMS_FOOTER_LEN);
			append_str(q,SMS_TRUNCATED,SMS_TRUNCATED_LEN);
			append_str(q,SMS_FOOTER,SMS_FOOTER_LEN);
			p += buf_len-SMS_TRUNCATED_LEN-SMS_FOOTER_LEN-SMS_EDGE_PART_LEN;
			send_error(sms_messg, ERR_TRUNCATE_TEXT, ERR_TRUNCATE_TEXT_LEN,
				p, text.len-(p-text.s)-SMS_FOOTER_LEN);
		}
		LM_DBG("---%d--<%d><%d>--\n|%.*s|\n", i, len_array[i], buf_len,
										(int)buf_len, buf);
		sms_messg->text.s   = buf;
		sms_messg->text.len = buf_len;
		if ( (ret_code=putsms(sms_messg,mdm))<0)
			goto error;
		if (sms_report_type!=NO_REPORT)
			add_sms_into_report_queue(ret_code,sms_messg,
				p-use_nice*(nr_chunks>1)*SMS_EDGE_PART_LEN,len_array[i]);
	}

	sms_messg->ref--;
	/* put back the pointer to the beginning of the message*/
	sms_messg->text.s = text.s;
	sms_messg->text.len = text.len;
	/* remove the sms if nobody points to it */
	if (!sms_messg->ref){
		shm_free(sms_messg);
	}
	return 1;
error:
	if (ret_code==-1)
		/* bad number */
		send_error(sms_messg, sms_messg->to.s, sms_messg->to.len,
			ERR_NUMBER_TEXT, ERR_NUMBER_TEXT_LEN);
	else if (ret_code==-2)
		/* bad modem */
		send_error(sms_messg, ERR_MODEM_TEXT, ERR_MODEM_TEXT_LEN,
			text.s+SMS_HDR_BF_ADDR_LEN+sms_messg->from.len+SMS_HDR_AF_ADDR_LEN,
			text.len-SMS_FOOTER_LEN-SMS_HDR_BF_ADDR_LEN-sms_messg->from.len-
			SMS_HDR_AF_ADDR_LEN );

	if (!(--(sms_messg->ref)))
		shm_free(sms_messg);
	return -1;
}
Ejemplo n.º 7
0
void scrawl_text(std::string txt, int alignment, VSFrameRef *frame, const VSAPI *vsapi) {
    const VSFormat *frame_format = vsapi->getFrameFormat(frame);
    int width = vsapi->getFrameWidth(frame, 0);
    int height = vsapi->getFrameHeight(frame, 0);

    const int margin_h = 16;
    const int margin_v = 16;

    sanitise_text(txt);

    stringlist lines = split_text(txt, width - margin_h*2, height - margin_v*2);

    int start_x = 0;
    int start_y = 0;

    switch (alignment) {
    case 7:
    case 8:
    case 9:
        start_y = margin_v;
        break;
    case 4:
    case 5:
    case 6:
        start_y = (height - static_cast<int>(lines.size())*character_height) / 2;
        break;
    case 1:
    case 2:
    case 3:
        start_y = height - static_cast<int>(lines.size())*character_height - margin_v;
        break;
    }

    for (const auto &iter : lines) {
        switch (alignment) {
        case 1:
        case 4:
        case 7:
            start_x = margin_h;
            break;
        case 2:
        case 5:
        case 8:
            start_x = (width - static_cast<int>(iter.size())*character_width) / 2;
            break;
        case 3:
        case 6:
        case 9:
            start_x = width - static_cast<int>(iter.size())*character_width - margin_h;
            break;
        }

        for (size_t i = 0; i < iter.size(); i++) {
            int dest_x = start_x + static_cast<int>(i)*character_width;
            int dest_y = start_y;

            if (frame_format->colorFamily == cmRGB) {
                for (int plane = 0; plane < frame_format->numPlanes; plane++) {
                    uint8_t *image = vsapi->getWritePtr(frame, plane);
                    int stride = vsapi->getStride(frame, plane);

                    if (frame_format->sampleType == stInteger) {
                        scrawl_character_int(iter[i], image, stride, dest_x, dest_y, frame_format->bitsPerSample);
                    } else {
                        scrawl_character_float(iter[i], image, stride, dest_x, dest_y);
                    }
                }
            } else {
                for (int plane = 0; plane < frame_format->numPlanes; plane++) {
                    uint8_t *image = vsapi->getWritePtr(frame, plane);
                    int stride = vsapi->getStride(frame, plane);

                    if (plane == 0) {
                        if (frame_format->sampleType == stInteger) {
                            scrawl_character_int(iter[i], image, stride, dest_x, dest_y, frame_format->bitsPerSample);
                        } else {
                            scrawl_character_float(iter[i], image, stride, dest_x, dest_y);
                        }
                    } else {
                        int sub_w = character_width  >> frame_format->subSamplingW;
                        int sub_h = character_height >> frame_format->subSamplingH;
                        int sub_dest_x = dest_x >> frame_format->subSamplingW;
                        int sub_dest_y = dest_y >> frame_format->subSamplingH;
                        int y;

                        if (frame_format->bitsPerSample == 8) {
                            for (y = 0; y < sub_h; y++) {
                                memset(image + (y+sub_dest_y)*stride + sub_dest_x, 128, sub_w);
                            }
                        } else if (frame_format->bitsPerSample <= 16) {
                            for (y = 0; y < sub_h; y++) {
                                vs_memset16(reinterpret_cast<uint16_t *>(image) + (y+sub_dest_y)*stride/2 + sub_dest_x, 128 << (frame_format->bitsPerSample - 8), sub_w);
                            }
                        } else {
                            for (y = 0; y < sub_h; y++) {
                                vs_memset_float(reinterpret_cast<float *>(image) + (y+sub_dest_y)*stride/4 + sub_dest_x, 0.0f, sub_w);
                            }
                        }
                    } // if plane
                } // for plane in planes
            } // if colorFamily
        } // for i in line
        start_y += character_height;
    } // for iter in lines
}
Ejemplo n.º 8
0
void BinAsm::save(const std::string& filename)
{
	uint32_t allocsize=0x10000;
	uint32_t filesize=0;
	int error_count=0;
	uint16_t* buff = new uint16_t[allocsize];
	unsigned int lc = 0;
	uint16_t opcode = 0;
	std::vector<std::string> lines=split_text(_src);
	std::vector<std::string>::iterator lit = lines.begin();
	for (;lit!=lines.end();lit++)
	{
	    lc++;
		std::string err = std::string();
		std::vector<std::string> w=split_line(*lit);
		if (!w.size()) continue;
		opcode = 0;
		
		if (filesize  > allocsize - lit->size() - 3)
		{
			std::cerr << "fatal error: assembling file is too big";
			std::cerr << "cannot be used on dcpu-16" << std::endl;
			break;
		}
		
		if (w[0].size() && (w[0][w[0].size()-1] == ':' || w[0][0] == ':'))
		{
			continue;
		}
		
		if ((opcode = get_op(w[0])))
		{
			if (w.size() != 3)
			{
				err = "instruction " + w[0];
				err += " need 2 arguments";
			}
			else
			{
				uint16_t a_word=0, b_word=0;
				opcode |= ((get_b(w[1],b_word,err) & 0x1F) << 5);
				if (err.size())
				{
					print_error(lc,false,err);
					error_count++;
				}
				opcode |= (get_a(w[2],a_word,err) << 10);
				buff[filesize]=opcode;
				filesize++;
				if (a_word)
				{
					buff[filesize]=a_word;
					filesize++;
				}
				if (b_word)
				{
					buff[filesize]=b_word;
					filesize++;
			    }
			}
		}
		else if ((opcode=get_sop(w[0],err)) && !err.size())
		{
			
			if (w.size() != 2)
			{
				err = "special instruction " + w[0];
				err += " need 1 argument";
			}
			else
			{
				uint16_t a_word=0;
				opcode = ((opcode & 0x1F) << 5);
				opcode |= (get_a(w[1],a_word,err) << 10);
				buff[filesize]=opcode;
				filesize++;
				if (a_word)
				{
					buff[filesize]=a_word;
					filesize++;
				}
			}
		} 
		else {
			if (w[0]=="dat"||w[0]==".dat"||w[0]=="DAT"||w[0]==".DAT")
				err="";
			filesize += get_data(*lit, &(buff[filesize]),err);
		}
		if (err.size())
		{
			print_error(lc,false,err);
			error_count++;
		}
		
	}
	
	
	
	if (error_count)
	{
		std::cerr << "assembling terminated with " << error_count; 
		std::cerr << " error(s)" << std::endl;
	}
	else
	{
		FILE* f = fopen(filename.c_str(), "wb");
		if (!f)
		std::cerr << "error: cannot open output file " << filename << std::endl;
		fswitchendian(buff, filesize);
		fwrite(buff,2,filesize,f);
		fclose(f);
		std::cout << "assembling " << filename;
		std::cout << " terminated final size " << filesize*2;
		std::cout << " bytes" << std::endl;
	}
	delete buff;
}
Ejemplo n.º 9
0
bool BinAsm::finds_labels()
{
	unsigned int lc = 0;
	unsigned int errc = 0;
	unsigned int offset = 0;
	uint16_t opd = 0;
	std::string err = "";
	std::vector<std::string> lines=split_text(_src);
	std::vector<std::string>::iterator lit = lines.begin();
	for (;lit!=lines.end();lit++)
	{
	    lc++;
		std::vector<std::string> w=split_line(*lit);
		if (!w.size()) continue;
		if (get_op(w[0]))
		{
			offset++;
			if (w.size() < 3) continue;
			opd=0;
			get_b(w[1],opd,err);
			if (opd) offset++;
			opd=0;
			get_a(w[2],opd,err);
			if (opd) offset++;
			
		}
		else if (get_sop(w[0],err) && !err.size())
		{
			offset++;
			if (w.size() < 2) continue;
			opd=0;
			get_a(w[1],opd,err);
			if (opd) offset++;
		}
		else
		{
			std::vector<std::string>::iterator wit = w.begin();
			Label l;
			l.line = lc;
			l.offset = offset;
			l.name = std::string();
			for (;wit!=w.end();wit++)
			{
				if (wit->size() < 2) continue;
				if ((*wit)[wit->size()-1] == ':')
				{
					l.name = wit->substr(0,wit->size()-1);
					break;
				}
				else if ((*wit)[0] == ':')
				{
					l.name = wit->substr(1,wit->size());
					break;
				}
			}
			if (_labels.find(l.name)!=_labels.end())
			{
				err="label " + l.name + " redefined";
				print_error(lc, false,err);
				errc++;
			}
			else if (l.name.size())
			{
				_labels[l.name]=l;
			}
		}
		uint16_t* data = new uint16_t[lit->size()]; 
		offset += get_data(*lit, data,err);
		delete data;
	}
	
	return !errc;
}