static void out_vformat(Out& o, const char* format, va_list args) {
  int nn = 0;

  for (;;) {
    int mm;
    int padZero = 0;
    int padLeft = 0;
    char sign = '\0';
    int width = -1;
    int prec = -1;
    size_t bytelen = sizeof(int);
    int slen;
    char buffer[32]; /* temporary buffer used to format numbers */

    char c;

    /* first, find all characters that are not 0 or '%' */
    /* then send them to the output directly */
    mm = nn;
    do {
      c = format[mm];
      if (c == '\0' || c == '%') break;
      mm++;
    } while (1);

    if (mm > nn) {
      o.Send(format + nn, mm - nn);
      nn = mm;
    }

    /* is this it ? then exit */
    if (c == '\0') break;

    /* nope, we are at a '%' modifier */
    nn++;  // skip it

    /* parse flags */
    for (;;) {
      c = format[nn++];
      if (c == '\0') { /* single trailing '%' ? */
        c = '%';
        o.Send(&c, 1);
        return;
      } else if (c == '0') {
        padZero = 1;
        continue;
      } else if (c == '-') {
        padLeft = 1;
        continue;
      } else if (c == ' ' || c == '+') {
        sign = c;
        continue;
      }
      break;
    }

    /* parse field width */
    if ((c >= '0' && c <= '9')) {
      nn--;
      width = static_cast<int>(parse_decimal(format, &nn));
      c = format[nn++];
    }

    /* parse precision */
    if (c == '.') {
      prec = static_cast<int>(parse_decimal(format, &nn));
      c = format[nn++];
    }

    /* length modifier */
    switch (c) {
      case 'h':
        bytelen = sizeof(short);
        if (format[nn] == 'h') {
          bytelen = sizeof(char);
          nn += 1;
        }
        c = format[nn++];
        break;
      case 'l':
        bytelen = sizeof(long);
        if (format[nn] == 'l') {
          bytelen = sizeof(long long);
          nn += 1;
        }
        c = format[nn++];
        break;
      case 'z':
        bytelen = sizeof(size_t);
        c = format[nn++];
        break;
      case 't':
        bytelen = sizeof(ptrdiff_t);
        c = format[nn++];
        break;
      default:;
    }

    /* conversion specifier */
    const char* str = buffer;
    if (c == 's') {
      /* string */
      str = va_arg(args, const char*);
      if (str == NULL) {
        str = "(null)";
      }
    } else if (c == 'c') {
Esempio n. 2
0
int main()
{
    {
        std::regex phone_numbers("\\d{3}-\\d{4}");
        const char phone_book[] = "555-1234, 555-2345, 555-3456";
        typedef output_iterator<char*> Out;
        typedef bidirectional_iterator<const char*> Bi;
        char buf[100] = {0};
        Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
                                    Bi(std::end(phone_book)-1), phone_numbers,
                                    "123-$&");
        assert(r.base() == buf+40);
        assert(buf == std::string("123-555-1234, 123-555-2345, 123-555-3456"));
    }
    {
        std::regex phone_numbers("\\d{3}-\\d{4}");
        const char phone_book[] = "555-1234, 555-2345, 555-3456";
        typedef output_iterator<char*> Out;
        typedef bidirectional_iterator<const char*> Bi;
        char buf[100] = {0};
        Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
                                    Bi(std::end(phone_book)-1), phone_numbers,
                                    "123-$&",
                                    std::regex_constants::format_sed);
        assert(r.base() == buf+43);
        assert(buf == std::string("123-$555-1234, 123-$555-2345, 123-$555-3456"));
    }
    {
        std::regex phone_numbers("\\d{3}-\\d{4}");
        const char phone_book[] = "555-1234, 555-2345, 555-3456";
        typedef output_iterator<char*> Out;
        typedef bidirectional_iterator<const char*> Bi;
        char buf[100] = {0};
        Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
                                    Bi(std::end(phone_book)-1), phone_numbers,
                                    "123-&",
                                    std::regex_constants::format_sed);
        assert(r.base() == buf+40);
        assert(buf == std::string("123-555-1234, 123-555-2345, 123-555-3456"));
    }
    {
        std::regex phone_numbers("\\d{3}-\\d{4}");
        const char phone_book[] = "555-1234, 555-2345, 555-3456";
        typedef output_iterator<char*> Out;
        typedef bidirectional_iterator<const char*> Bi;
        char buf[100] = {0};
        Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
                                    Bi(std::end(phone_book)-1), phone_numbers,
                                    "123-$&",
                                    std::regex_constants::format_no_copy);
        assert(r.base() == buf+36);
        assert(buf == std::string("123-555-1234123-555-2345123-555-3456"));
    }
    {
        std::regex phone_numbers("\\d{3}-\\d{4}");
        const char phone_book[] = "555-1234, 555-2345, 555-3456";
        typedef output_iterator<char*> Out;
        typedef bidirectional_iterator<const char*> Bi;
        char buf[100] = {0};
        Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
                                    Bi(std::end(phone_book)-1), phone_numbers,
                                    "123-$&",
                                    std::regex_constants::format_first_only);
        assert(r.base() == buf+32);
        assert(buf == std::string("123-555-1234, 555-2345, 555-3456"));
    }
    {
        std::regex phone_numbers("\\d{3}-\\d{4}");
        const char phone_book[] = "555-1234, 555-2345, 555-3456";
        typedef output_iterator<char*> Out;
        typedef bidirectional_iterator<const char*> Bi;
        char buf[100] = {0};
        Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
                                    Bi(std::end(phone_book)-1), phone_numbers,
                                    "123-$&",
                                    std::regex_constants::format_first_only |
                                    std::regex_constants::format_no_copy);
        assert(r.base() == buf+12);
        assert(buf == std::string("123-555-1234"));
    }
}
Esempio n. 3
0
void Graph::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
	CLogicSimulatorDoc* pDoc = (CLogicSimulatorDoc *)pFrame->GetActiveDocument();
	dc.SetBkMode(TRANSPARENT);

	if (previousInput < 0)
		previousInput = pDoc->currBox->NumInput;
	else if (previousInput != pDoc->currBox->NumInput) {
		UpdateGraph = 1;
		previousInput = pDoc->currBox->NumInput;
	}
		
	dc.DrawText(_T("입력핀"), CRect(0, 0, 50, 50), DT_LEFT);
	int input = 0 , curr =20;
	for (int i = 0; i < pDoc->currBox->logicInfo.size(); i++)
	{
		CString Fornumber;

		if (pDoc->currBox->logicInfo.at(i)->objectName == PIN) {
			Pin* PT = (Pin*)pDoc->currBox->logicInfo.at(i);
			Fornumber.Format(_T("ID : %d, Label : %s"), PT->getConNum(), PT->label);
			if (PT->getConNum() >= 0)
				inputValue[PT->getConNum()] = PT->getOutput();

			dc.TextOutW(0, curr, Fornumber);
			curr += 50;
		}
	}
	
	dc.TextOutW(0, curr, _T("출력핀"));
	curr += 20;
	for (int i = 0; i < pDoc->currBox->logicInfo.size(); i++)
	{
		CString Fornumber;

		if (pDoc->currBox->logicInfo.at(i)->objectName == OUTPIN) {
			Out* PT = (Out*)pDoc->currBox->logicInfo.at(i);
			Fornumber.Format(_T("ID : %d, Label : %s"), PT->getConNum(), PT->label);
			if (PT->getConNum() >= 0)
				outputValue[PT->getConNum()] = PT->getOutput();

			dc.TextOutW(0, curr, Fornumber);
			curr += 50;
		}
	}

	int i ,final_i;
	CPen pen;
	pen.CreatePen(PS_SOLID, 3, RGB(255, 0, 0));    // 빨간색 펜 생성
	dc.SelectObject(&pen);

	for (i = 0; i < pDoc->currBox->NumInput; i++)
	{
		for (int j = 1; j < (count < 200 ? count : 200); j++)
		{
			inputline[i][j - 1].x += 5;
		}
		for (int j = (count < 200 ? count : 200); j >= 1; j--)
		{
			inputline[i][j].x = inputline[i][j - 1].x;
			inputline[i][j].y = inputline[i][j - 1].y;
		}
		//그리기
		if (inputValue[i])
		{
			inputline[i][0].x = 0;
			inputline[i][0].y = 45 + 50 * i;
		}
		else {
			inputline[i][0].x = 0;
			inputline[i][0].y = 60 + 50 * i;
		}

		dc.Polyline(inputline[i], (count < 200 ? count : 200));
		
	}

	final_i = i;

	if (UpdateGraph) {
		for (i = 0; i < 10; i++)
		{
			for (int j = 0; j < 250; j++)
			{
				outputline[i][j].y = 80 + 50 * (i + final_i);
			}
		}
		UpdateGraph = false;
	}
	pen.DeleteObject();


	pen.CreatePen(PS_SOLID, 3, RGB(0, 0, 255));  // 파란색 펜 생성
	dc.SelectObject(&pen);

	for (i = 0; i < pDoc->currBox->NumOuput; i++)
	{
		for (int j = 1; j < (count < 200 ? count : 200); j++)
		{
			outputline[i][j - 1].x += 5;
		}
		for (int j = (count < 200 ? count : 200); j >= 1; j--)
		{
			outputline[i][j].x = outputline[i][j - 1].x;
			outputline[i][j].y = outputline[i][j - 1].y;
		}
		//그리기

		if (outputValue[i])
		{
			outputline[i][0].x = 0;
			outputline[i][0].y = 65 + 50 * (i + final_i);
		}
		else {
			outputline[i][0].x = 0;
			outputline[i][0].y = 80 + 50 * (i + final_i);
		}
		dc.Polyline(outputline[i], (count < 200 ? count : 200));
		
	}
	//dc.Rectangle(10, 10, 10, 100);
}