void CBC_QRCoderMatrixUtil::EmbedTimingPatterns(CBC_CommonByteMatrix* matrix,
                                                int32_t& e) {
  if (!matrix) {
    e = BCExceptionNullPointer;
    BC_EXCEPTION_CHECK_ReturnVoid(e);
  }
  for (int32_t i = 8; i < matrix->GetWidth() - 8; i++) {
    int32_t bit = (i + 1) % 2;
    if (!IsValidValue(matrix->Get(i, 6))) {
      e = BCExceptionInvalidateImageData;
      BC_EXCEPTION_CHECK_ReturnVoid(e);
    }
    if (IsEmpty(matrix->Get(i, 6))) {
      matrix->Set(i, 6, bit);
    }
    if (!IsValidValue(matrix->Get(6, i))) {
      e = BCExceptionInvalidateImageData;
      BC_EXCEPTION_CHECK_ReturnVoid(e);
    }
    if (IsEmpty(matrix->Get(6, i))) {
      matrix->Set(6, i, bit);
    }
  }
}
Exemple #2
0
bool EdiDocument::IsValid(bool doLog) const {
    bool result = IsHeaderValid(doLog); 
    if (result || doLog) {
        for ( size_t row = 0; row < GetNumberRows(); row++ ) {
            for ( size_t col = 0; col < GetColCount(); col++ ) {
                if ( !IsValidValue(row, col, doLog) ) {
                    if ( !doLog )  {
                      return false;
                    } else {
                      result = false;
                    }
                } 
            }
        }
    }
    return result;
};
Exemple #3
0
void AddToMap(TCHAR* pszArg)
{
	ENSURE(pszArg != NULL);
	TCHAR* psz = _tcsdup(pszArg);
	if (psz == NULL)
	{
		AfxThrowMemoryException();
	}
	ASSERT(_tcschr(psz, _T(',')) != NULL);

	TCHAR* pszPrefixFrom;
	TCHAR* pszPrefixTo;
	TCHAR* pszAddTo;
	DWORD dwAddTo;
	CMapInfo* pInfo;
	TCHAR* pContext=NULL;

	// parse each field out of the argument.
	pszPrefixFrom = _tcstok_s(psz, _T(","), &pContext);
	pszPrefixTo = _tcstok_s(NULL, _T(","), &pContext);
	if (pszPrefixTo == NULL)
		goto ParmError;
	pszAddTo = _tcstok_s(NULL, _T(","), &pContext);
	if (pszAddTo == NULL)
		goto ParmError;

	// make sure they are valid symbols/values.
	if (!IsValidSymbol(pszPrefixFrom) || !IsValidSymbol(pszPrefixTo))
		goto ParmError;
	if (!IsValidValue(pszAddTo, dwAddTo))
		goto ParmError;

	// add them to the map.
	pInfo = new CMapInfo;
	ASSERT(pInfo);
	pInfo->pszPrefixFrom = pszPrefixFrom;
	pInfo->pszPrefixTo = pszPrefixTo;
	pInfo->dwAddTo = dwAddTo;
	aMap.Add(pInfo);
	return;

ParmError:
	UsageErr(_T("parameter \"%s\" not correctly formed."), pszArg);
	ASSERT(FALSE);
}
Exemple #4
0
/**
  Add new section entry and entry value into Section head.

  @param[in]      Buffer          Section entry data buffer.
  @param[in]      BufferSize      Size of section entry.
  @param[in, out] SectionHead     Section item head entry.

  @retval EFI_OUT_OF_RESOURCES   No enough memory is allocated.
  @retval EFI_SUCCESS            Section entry is added.
  @retval EFI_NOT_FOUND          Section entry is not found.
  @retval EFI_INVALID_PARAMETER  Section entry is invalid.

**/
EFI_STATUS
ProfileGetEntry (
  IN      UINT8                         *Buffer,
  IN      UINTN                         BufferSize,
  IN OUT  SECTION_ITEM                  **SectionHead
  )
{
  EFI_STATUS                            Status;
  SECTION_ITEM                          *SectionItem;
  SECTION_ITEM                          *PtrSection;
  UINTN                                 Length;
  UINT8                                 *PtrBuf;
  UINT8                                 *PtrEnd;

  Status      = EFI_SUCCESS;
  PtrBuf      = Buffer;
  PtrEnd      = (UINT8 *) ((UINTN)Buffer + BufferSize - 1);

  //
  // First search for '='
  //
  while (PtrBuf <= PtrEnd) {
    if (*PtrBuf == '=') {
      break;
    }
    PtrBuf++;
  }
  if (PtrBuf > PtrEnd) {
    //
    // Not found. Invalid line
    //
    return EFI_NOT_FOUND;
  }
  if (PtrBuf <= Buffer) {
    // Empty name
    return EFI_NOT_FOUND;
  }

  //
  // excluding the tailing '='
  //
  Length      = PtrBuf - Buffer;
  ProfileTrim (
    Buffer,
    &Length
  );

  //
  // Invalid line if the entry name is null
  //
  if (Length == 0) {
    return EFI_NOT_FOUND;
  }

  if (!IsValidName((CHAR8 *)Buffer, Length)) {
    return EFI_INVALID_PARAMETER;
  }

  //
  // Omit this line if no section header has been found before
  //
  if (*SectionHead == NULL) {
    return Status;
  }
  PtrSection  = *SectionHead;

  SectionItem = AllocatePool (sizeof (SECTION_ITEM));
  if (SectionItem == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  SectionItem->PtrSection = NULL;
  SectionItem->PtrEntry   = NULL;
  SectionItem->PtrValue   = NULL;
  SectionItem->SecNameLen = PtrSection->SecNameLen;
  SectionItem->PtrNext    = *SectionHead;
  *SectionHead            = SectionItem;

  //
  // SectionName, add a trailing '\0'
  //
  SectionItem->PtrSection = AllocatePool (PtrSection->SecNameLen + 1);
  if (SectionItem->PtrSection == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }
  CopyMem (SectionItem->PtrSection, PtrSection->PtrSection, PtrSection->SecNameLen + 1);

  //
  // EntryName, add a trailing '\0'
  //
  SectionItem->PtrEntry = AllocatePool (Length + 1);
  if (SectionItem->PtrEntry == NULL) {
    FreePool(SectionItem->PtrSection);
    return EFI_OUT_OF_RESOURCES;
  }
  CopyMem (SectionItem->PtrEntry, Buffer, Length);
  *(SectionItem->PtrEntry + Length) = '\0';

  //
  // Next search for '#' or ';'
  //
  PtrBuf      = PtrBuf + 1;
  Buffer      = PtrBuf;
  while (PtrBuf <= PtrEnd) {
    if (*PtrBuf == '#' || *PtrBuf == ';') {
      break;
    }
    PtrBuf++;
  }
  if (PtrBuf <= Buffer) {
    // Empty name
    FreePool(SectionItem->PtrEntry);
    FreePool(SectionItem->PtrSection);
    return EFI_NOT_FOUND;
  }
  Length      = PtrBuf - Buffer;
  ProfileTrim (
    Buffer,
    &Length
  );

  //
  // Invalid line if the entry value is null
  //
  if (Length == 0) {
    FreePool(SectionItem->PtrEntry);
    FreePool(SectionItem->PtrSection);
    return EFI_NOT_FOUND;
  }

  if (!IsValidValue((CHAR8 *)Buffer, Length)) {
    FreePool(SectionItem->PtrEntry);
    FreePool(SectionItem->PtrSection);
    return EFI_INVALID_PARAMETER;
  }

  //
  // EntryValue, add a trailing '\0'
  //
  SectionItem->PtrValue = AllocatePool (Length + 1);
  if (SectionItem->PtrValue == NULL) {
    FreePool(SectionItem->PtrEntry);
    FreePool(SectionItem->PtrSection);
    return EFI_OUT_OF_RESOURCES;
  }
  CopyMem (SectionItem->PtrValue, Buffer, Length);
  *(SectionItem->PtrValue + Length) = '\0';

  return EFI_SUCCESS;
}
Exemple #5
0
BOOL MapLine(CString& strLine, BOOL fHTMLFormat )
{
	static TCHAR szWhiteSpace1[] = _T("\t ");
	static TCHAR szWhiteSpace2[] = _T("\t\n ");
	static TCHAR szDefine[] = _T("#define");

	TCHAR* pszCopy = _tcsdup(strLine);
	if (pszCopy == NULL)
	{
		AfxThrowMemoryException();
	}

	TCHAR* psz;
	TCHAR* pszSymbol;
	TCHAR* pszValue;
	DWORD dwValue;
	CString strNewName;
	TCHAR* pContext=NULL;

	// '//{{NOHELP}}' can be placed on the line and it will not be included
	if (_tcsstr(strLine, _T("//{{NOHELP}}")) != NULL)
		goto RetFalse;

	psz = _tcstok_s(pszCopy, szWhiteSpace1, &pContext);
	if (psz == NULL)
		goto RetFalse;
	if (_tcscmp(psz, szDefine) != 0)
		goto RetFalse;
	pszSymbol = _tcstok_s(NULL, szWhiteSpace1, &pContext);
	if (pszSymbol == NULL)
		goto RetFalse;
	pszValue = _tcstok_s(NULL, szWhiteSpace2, &pContext);
	if (pszValue == NULL)
		goto RetFalse;

	if (!IsValidSymbol(pszSymbol))
		goto RetFalse;
	if (!IsValidValue(pszValue, dwValue))
		goto RetFalse;
	if (!MapNameValue(pszSymbol, strNewName, dwValue))
		goto RetFalse;

	//BLOCK: format output line
	{
		CString strPad(_T(' '), 40-strNewName.GetLength());
		if (strPad.IsEmpty())
			strPad = _T('\t');
		if( fHTMLFormat )
			strLine = _T("#define ") + strNewName + strPad + StringFromDword(dwValue) + _T("\n");
		else
			strLine = strNewName + strPad + StringFromDword(dwValue) + _T("\n");
	}

	ASSERT(pszCopy != NULL);
	free(pszCopy);
	return TRUE;

RetFalse:
	ASSERT(pszCopy != NULL);
	free(pszCopy);
	return FALSE;
}