Example #1
0
int save_init(unsigned char num, unsigned char* addr_i, int length)
{
	unsigned char board[3], addr_c[length * 2 + 1];
	unsigned char buf[70];
	FILE *fd;
	board[0] = num;
	memcpy(addr_c, addr_i, length); //non-null terminated
	if((fd = fopen("/project/farm/file.ini", "w")) == NULL)
	{ 
		perror("open initial file fail: ");
		return -1;
	}
	itoc(board, 1);//null-terminated
	printf("init: %s\n",board);
	memset(buf, 0, 70);
	strncpy(buf,"board_num = ", 12);
	strncat(buf + 12, board, 2);
	buf[14] = '\n';
	buf[15] = '\0';
	fputs(buf, fd);
	fputs(buf, stdout);
	itoc(addr_c, length); //null_terminated
	printf("%s\n", addr_c);
	memset(buf, 0, 70);
	strncpy(buf, "address = ", 10);
	strncat(buf + 10, addr_c, length * 2);
	buf[10 + length * 2] = '\n';
	buf[10 + length * 2 + 1] = '\0';
	fputs(buf, fd);
	fputs(buf, stdout);
	printf("save init file\n");
	fclose(fd);
}
Example #2
0
    string addBinary(string a, string b) {
        int index1 = a.length()-1;
        int index2 = b.length()-1;
        string result = "";
        int carry = 0;
        int tempSum = 0;
        while (index1 >= 0 && index2 >= 0) {
            tempSum = ctoi(a[index1--]) + ctoi(b[index2--]) + carry;
            result = itoc(tempSum % 2) + result;
            carry = tempSum / 2;
        }
 
        while (index1 >= 0) {
            tempSum = ctoi(a[index1--]) + carry;
            result = itoc(tempSum % 2) + result;
            carry = tempSum / 2;
        }
 
        while (index2 >= 0) {
            tempSum = ctoi(b[index2--]) + carry;
            result = itoc(tempSum % 2) + result;
            carry = tempSum / 2;
        }
 
        if (carry > 0) { result = '1' + result; }
 
        return result;
    }
void print_maze(void)
{
    int i, j, k;
    for(i=1 ; i<10 ; i++) for(j=1 ; j<10 ; j++) for(k=0 ; k<4 ; k++){
        printf("(%d,%d,%c): ", i, j, itoc(k));
        int l;
        for(l=0 ; l<4 ; l++) if(maze[i][j][k].linked[l]) printf("%c ", itoc(l));
        printf("\n");
    }
}
Example #4
0
static char	*r_uitoa(unsigned short int nb, char *tmp, int base)
{
	char	*rt;

	if (nb > (unsigned short int)base - 1)
	{
		rt = r_uitoa(nb / base, tmp, base);
		*rt = itoc(nb % base);
		return (rt + 1);
	}
	else if (nb > 0)
		*tmp = itoc(nb);
	return (tmp + 1);
}
void CheckCharacter() {
	int i;
	char part[3];
	
	if(value == target_value) {
		/* Target reached - save the generated pattern */
		strcpy(pattern, "11110");
		for(i = 0; i < 11; i++) {
			part[0] = itoc(S[i]);
			part[1] = itoc(B[i]);
			part[2] = '\0';
			concat(pattern, part);
		}
	}
}
Example #6
0
int main(){
    int a,b;
    int m;
    long sum=1;
    double r;
    int bigNum[INIT_SIZE]={0};
    
    
    //a=2;  b=3;
    //r=(double)a/b;
    
    /*for(m=0;m<12;m++){
        sum=sum*11;
        printf("sum=%ld\n",sum);
    }*/
    
    /*m=99;
    a=m/100;
    
    pf("m=%d, a=%d\n",m,a);
    */
    
    m=11060219;
    itoc(m,bigNum);
    //pfci(bigNum);
    

    
    //printf("%f",r);
    
    system("pause");
    return 0;   
}
Example #7
0
void Euler_13_0()
{
	vector<string> nums;
	copy(&input[0], &input[num_input], back_inserter(nums));

	string result;

	for( int carry = 0; !nums.empty() || carry; )
	{
		int dsum = accumulate(nums.begin(), nums.end(), 0, [](int x, string & s) -> int
		{
			int ret = x + ctoi(s[s.length()-1]);
			s.erase(s.length()-1);
			return ret;
		});
		nums.erase(std::remove_if(nums.begin(), nums.end(), [](string const& s)
		{
			return s.empty();
		}),nums.end());
		
		int sum = carry + dsum;
		int digit = sum%10;
		carry = (sum-digit)/10;

		result += itoc(digit);
	}

	reverse(result.begin(), result.end());

	cout << result.substr(0,10) << endl;
}
//-----------------------------------------------------------------------------
CPUTMaterial *CPUTMaterialDX11::CloneMaterial(const cString &fileName, const CPUTModel *pModel, int meshIndex)
{
    CPUTMaterialDX11 *pMaterial = new CPUTMaterialDX11();

    // TODO: move texture to base class.  All APIs have textures.
    pMaterial->mpPixelShader    = mpPixelShader;    if(mpPixelShader)    mpPixelShader->AddRef();   
    pMaterial->mpComputeShader  = mpComputeShader;  if(mpComputeShader)  mpComputeShader->AddRef();
    pMaterial->mpVertexShader   = mpVertexShader;   if(mpVertexShader)   mpVertexShader->AddRef();
    pMaterial->mpGeometryShader = mpGeometryShader; if(mpGeometryShader) mpGeometryShader->AddRef();
    pMaterial->mpHullShader     = mpHullShader;     if(mpHullShader)     mpHullShader->AddRef();
    pMaterial->mpDomainShader   = mpDomainShader;   if(mpDomainShader)   mpDomainShader->AddRef();

    mPixelShaderParameters.CloneShaderParameters(    &pMaterial->mPixelShaderParameters );
    mComputeShaderParameters.CloneShaderParameters(  &pMaterial->mComputeShaderParameters );
    mVertexShaderParameters.CloneShaderParameters(   &pMaterial->mVertexShaderParameters );
    mGeometryShaderParameters.CloneShaderParameters( &pMaterial->mGeometryShaderParameters );
    mHullShaderParameters.CloneShaderParameters(     &pMaterial->mHullShaderParameters );
    mDomainShaderParameters.CloneShaderParameters(   &pMaterial->mDomainShaderParameters );

    pMaterial->mpShaderParametersList[0] =  &pMaterial->mPixelShaderParameters,
    pMaterial->mpShaderParametersList[1] =  &pMaterial->mComputeShaderParameters,
    pMaterial->mpShaderParametersList[2] =  &pMaterial->mVertexShaderParameters,
    pMaterial->mpShaderParametersList[3] =  &pMaterial->mGeometryShaderParameters,
    pMaterial->mpShaderParametersList[4] =  &pMaterial->mHullShaderParameters,
    pMaterial->mpShaderParametersList[5] =  &pMaterial->mDomainShaderParameters,
    pMaterial->mpShaderParametersList[6] =  NULL;

    pMaterial->mpRenderStateBlock = mpRenderStateBlock; if( mpRenderStateBlock ) mpRenderStateBlock->AddRef();

    pMaterial->mMaterialName      = mMaterialName + ptoc(pModel) + itoc(meshIndex);
    pMaterial->mMaterialNameHash  = CPUTComputeHash(pMaterial->mMaterialName);
    pMaterial->mConfigBlock       = mConfigBlock;
    pMaterial->mBufferCount       = mBufferCount;

    // For each of the shader stages, bind shaders and buffers
    for( CPUTShaderParameters **pCur = pMaterial->mpShaderParametersList; *pCur; pCur++ ) // Bind textures and buffersfor each shader stage
    {
        pMaterial->BindTextures(        **pCur, pModel, meshIndex );
        pMaterial->BindBuffers(         **pCur, pModel, meshIndex );
        pMaterial->BindUAVs(            **pCur, pModel, meshIndex );
        pMaterial->BindConstantBuffers( **pCur, pModel, meshIndex );
    }
    // Append this clone to our clone list
    if( mpMaterialNextClone )
    {
        // Already have a list, so add to the end of it.
        ((CPUTMaterialDX11*)mpMaterialLastClone)->mpMaterialNextClone = pMaterial;
    } else
    {
        // No list yet, so start it with this material.
        mpMaterialNextClone = pMaterial;
        mpMaterialLastClone = pMaterial;
    }
    pMaterial->mpModel    = pModel;
    pMaterial->mMeshIndex = meshIndex;
    return pMaterial;
}
Example #9
0
int main()
{
    char s[255];
    int n = 1;
    int l = 5;
    itoc(n, s, l);
    printf("%d -> %s\n", n, s);
    return 0;
}
Example #10
0
void itostr(char ai_string[], int ai_value)
{
	int thou, hund, ten, unit;
	char temp[2];

	strcpy(ai_string, "(");
	thou = ai_value / 1000;
	hund = (ai_value - (1000 * thou)) / 100;
	ten = (ai_value - ((1000 * thou) + (100 * hund))) / 10;
	unit = ai_value - ((1000 * thou) + (100 * hund) + (10 * ten));

	temp[1] = '\0';
	if(ai_value >= 1000) { temp[0] = itoc(thou); concat(ai_string, temp); }
	if(ai_value >= 100) { temp[0] = itoc(hund); concat(ai_string, temp); }
	temp[0] = itoc(ten);
	concat(ai_string, temp);
	temp[0] = itoc(unit);
	concat(ai_string, temp);
	concat(ai_string, ")");
}
Example #11
0
char*
itoc(int n, char *numstr)
{
	char ctos[2];

	if (n < 0) {
		strcat(numstr, STR_MINUS);
		itoc(-n, numstr);
	} else if (n < 10) {
		ctos[0] = '0' + n;
		ctos[1] = '\0';
		strcat(numstr, ctos);
	} else {
		itoc(n/10, numstr);
		ctos[0] = '0' + n % 10;
		ctos[1] = '\0';
		strcat(numstr, ctos); 
	}

	return numstr;
}
//-----------------------------------------------------------------------------
void CPUTMaterialDX11::BindTextures( CPUTShaderParameters &params, const CPUTModel *pModel, int meshIndex )
{
    CPUTAssetLibraryDX11 *pAssetLibrary = (CPUTAssetLibraryDX11*)CPUTAssetLibrary::GetAssetLibrary();

    for(params.mTextureCount=0; params.mTextureCount < params.mTextureParameterCount; params.mTextureCount++)
    {
        cString textureName;
        UINT textureCount = params.mTextureCount;
        cString tagName = params.mpTextureParameterName[textureCount];
        CPUTConfigEntry *pValue = mConfigBlock.GetValueByName(tagName);
        if( !pValue->IsValid() )
        {
            // We didn't find our property in the file.  Is it in the global config block?
            pValue = mGlobalProperties.GetValueByName(tagName);
        }
        ASSERT( pValue->IsValid(), L"Can't find texture '" + tagName + L"'." ); //  TODO: fix message
        textureName = pValue->ValueAsString();
        // If the texture name not specified.  Load default.dds instead
        if( 0 == textureName.length() ) { textureName = _L("default.dds"); }

        UINT bindPoint = params.mpTextureParameterBindPoint[textureCount]; 
        ASSERT( bindPoint < CPUT_MATERIAL_MAX_TEXTURE_SLOTS, _L("Texture bind point out of range.") );

        if( textureName[0] == '@' )
        {
            // This is a per-mesh value.  Add to per-mesh list.
            textureName += ptoc(pModel) + itoc(meshIndex);
        } else if( textureName[0] == '#' )
        {
            // This is a per-mesh value.  Add to per-mesh list.
            textureName += ptoc(pModel);
        }

        // Get the sRGB flag (default to true)
        cString SRGBName = tagName+_L("sRGB");
        CPUTConfigEntry *pSRGBValue = mConfigBlock.GetValueByName(SRGBName);
        bool loadAsSRGB = pSRGBValue->IsValid() ?  loadAsSRGB = pSRGBValue->ValueAsBool() : true;

        if( !mpTexture[textureCount] )
        {
            mpTexture[textureCount] = pAssetLibrary->GetTexture( textureName, false, loadAsSRGB );
            ASSERT( mpTexture[textureCount], _L("Failed getting texture ") + textureName);
        }

        // The shader file (e.g. .fx) can specify the texture bind point (e.g., t0).  Those specifications 
        // might not be contiguous, and there might be gaps (bind points without assigned textures)
        // TODO: Warn about missing bind points?
        params.mppBindViews[bindPoint] = ((CPUTTextureDX11*)mpTexture[textureCount])->GetShaderResourceView();
		params.mppBindViews[bindPoint]->AddRef();
    }
}
Example #13
0
void
makehdr(const char *filename, char *header)
{
	char	tmpstr[MAXLINE];
		// header format: "-h- filename size\n"
	clearstr(header);
	strcat(header, archdr);
	strcat(header, STR_BLANK);
	strcat(header, filename);
	strcat(header, STR_BLANK);
	clearstr(tmpstr);
	strcat(header, itoc(fsize(filename), tmpstr)); 
	strcat(header, STR_NEWLINE);
}
Example #14
0
/**
 * Yet another app gets born!
 */
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
	MSG msg;
	HACCEL hAccelTable;
	WSAData wsaData;
	if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
		MessageBox(NULL, "WSAStartup (sockets) failed.", "A FREAKING SERIOUS ERROR", MB_ICONEXCLAMATION | MB_OK);
		PostQuitMessage(0);
	}
	InitCommonControls();
	myRegisterClass(hInstance, "myWinClass", (WNDPROC)WndProc, IDC_WAAPIX);
	myRegisterClass(hInstance, "myAboutBoxClass", (WNDPROC)aboutBoxProc, 0);

	//creating the VAPIX object
	vapix = new Vapix();

	//struct for opening the browser
	memset(&execInfo, '\0', sizeof(execInfo));
	execInfo.nShow = SW_SHOWNORMAL;
	execInfo.cbSize = sizeof(execInfo);

	//creating the http handler
	httpReader = new HttpReader();

	if (!showMainWnd (hInstance, nCmdShow)) {
		MessageBox(NULL, strcat(itoc((int)GetLastError()), "\r\n\r\nError creating main window"), "Cataclysmic error!", MB_ICONEXCLAMATION | MB_OK);
		return FALSE;
	}

	//use for language files? or make own and remove this?
	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WAAPIX);

	//doing the same shit that's been done for 30 years
	while (GetMessage(&msg, NULL, 0, 0)) {
		if (IsDialogMessage(hWnd, &msg) != 0)
			continue;
		else if (IsDialogMessage(hWnd, &msg) != 0)
			continue;
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	//free up memory
	delete vapix;
	delete httpReader;

	//gerrarre!!!
	return (int) msg.wParam;
}
Example #15
0
/**
 * Create and show the about window
 */
void showAboutBox(HWND parentHandle) {
	HWND hWndControl;
	HFONT DisplayFont = CreateFont(15, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN, "Verdana");
	HWND hWndAB = CreateWindow("myAboutBoxClass", "About", WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION, CW_USEDEFAULT, 0, 300, 150, parentHandle, NULL, hInst, NULL);
	if (hWndAB == NULL) {
		MessageBox(NULL, itoc((int)GetLastError()), "döh", MB_OK);
		return;
	}
	char* staticText = (char*)malloc(sizeof(char)*200);
	sprintf(staticText, "Waapix v%s\nCopyright (C) 2011 by Andreas Bank,\[email protected]", WAAPIX_VERSION);
	hWndControl = CreateWindow("STATIC", staticText, WS_VISIBLE | WS_CHILD, 30, 10, 300, 100, hWndAB, NULL, hInst, NULL);
	SendMessage(hWndControl, WM_SETFONT, (WPARAM) DisplayFont, 0);
	hWndControl = CreateWindow("BUTTON", "OK?", WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_DEFPUSHBUTTON, 210, 75, 70, 30, hWndAB, (HMENU) IDC_BUTTON1, hInst, NULL);
	SendMessage(hWndControl, WM_SETFONT, (WPARAM) DisplayFont, 0);
	ShowWindow(hWndAB, SW_SHOWNORMAL);
	UpdateWindow(hWndAB);
}
Example #16
0
/*
 * Based off itoa from opensource apple com.
 */
string itos(int i, uint8 base) {
    /* Room for INT_DIGITS digits, - and '\0' */
    static char buf[INT_DIGITS + 2];
    string p = buf + INT_DIGITS + 1;  /* points to terminating '\0' */
    bool isNeg = false;
    if (i < 0) {
        isNeg = true;
        i = -i;
    }
    do {
        *--p = itoc(i % base);
        i /= base;
    } while (i != 0);
    if (isNeg) {
        *--p = '-';
    }
    return p;
}
Example #17
0
char upc_check(char source[])
{ /* Calculate the correct check digit for a UPC barcode */
	unsigned int i, count, check_digit;

	count = 0;

	for (i = 0; i < strlen(source); i++) {
		count += ctoi(source[i]);

		if (!(i & 1)) {
			count += 2 * (ctoi(source[i]));
		}
	}

	check_digit = 10 - (count%10);
	if (check_digit == 10) { check_digit = 0; }
	return itoc(check_digit);
}
Example #18
0
char isbn13_check(unsigned char source[]) /* For ISBN(13) only */
{
	unsigned int i, weight, sum, check, h;

	sum = 0;
	weight = 1;
	h = ustrlen(source) - 1;

	for(i = 0; i < h; i++)
	{
		sum += ctoi(source[i]) * weight;
		if(weight == 1) weight = 3; else weight = 1;
	}

	check = sum % 10;
	check = 10 - check;
	return itoc(check);
}
int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Pharmazentral Nummer (PZN) */
	
	int i, error_number, zeroes;
	unsigned int count, check_digit;
	char localstr[10];
	
	error_number = 0;

	count = 0;
	if(length > 6) {
		strcpy(symbol->errtxt, "Input wrong length");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	
	localstr[0] = '-';
	zeroes = 6 - length + 1;
	for(i = 1; i < zeroes; i++)
		localstr[i] = '0';
	strcpy(localstr + zeroes, (char *)source);
	
	for (i = 1; i < 7; i++) {
		count += (i + 1) * ctoi(localstr[i]);
	}
	
	check_digit = count%11;
	if (check_digit == 11) { check_digit = 0; }
	localstr[7] = itoc(check_digit);
	localstr[8] = '\0';
	if(localstr[7] == 'A') { 
		strcpy(symbol->errtxt, "Invalid PZN Data");
        return ERROR_INVALID_DATA1;
	}
	error_number = c39(symbol, (unsigned char *)localstr, strlen(localstr));
	ustrcpy(symbol->text, (unsigned char *)"PZN");
	uconcat(symbol->text, (unsigned char *)localstr);
	return error_number;
}
Example #20
0
char ean_check(char source[])
{ /* Calculate the correct check digit for a EAN-13 barcode */
	int i;
	unsigned int h, count, check_digit;

	count = 0;

	h = strlen(source);
	for (i = h - 1; i >= 0; i--) {
		count += ctoi(source[i]);

		if (i & 1) {
			count += 2 * ctoi(source[i]);
		}
	}
	check_digit = 10 - (count%10);
	if (check_digit == 10) { check_digit = 0; }
	return itoc(check_digit);
}
Example #21
0
/**
 * Register window class, this way ensures Win95 compatibility
 */
void myRegisterClass(HINSTANCE hInstance, char* className, WNDPROC classFunction, int classHMenu) {
	WNDCLASSEX wcex;
	wcex.cbSize			= sizeof(WNDCLASSEX); 
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= classFunction;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDC_MYICON);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW);
	wcex.lpszMenuName	= (LPCTSTR)classHMenu;
	wcex.lpszClassName	= className;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
	if (RegisterClassEx(&wcex) == 0) {
		MessageBox(NULL, strcat("Error registering window class.\r\n\r\nErr nr.: ", itoc((int)GetLastError())), "2012 domomsday kinda error", MB_ICONEXCLAMATION | MB_OK);
		PostQuitMessage(0);
	}
}
Example #22
0
static inline
void print_int(uint16_t data, uint8_t base)
{
    char buf[7] = {'\0'};
    char *p = &buf[6];
    if ((base & SIGNED) && (data & 0x8000)) {
        data = -data;
        buf[0] = '-';
    }
    base &= ~SIGNED;
    uint16_t n;
    do {
        n = data;
        data /= base;
        *(--p) = itoc(n - data*base);
    } while (data);
    if (buf[0]) *(--p) = buf[0];
    print_S(p);
}
Example #23
0
int nve_18(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* Add check digit if encoding an NVE18 symbol */
	int error_number, zeroes, i, nve_check, total_sum, sourcelen;
	unsigned char ean128_equiv[25];

	memset(ean128_equiv, 0, 25);
	sourcelen = length;

	if(sourcelen > 17) {
		strcpy(symbol->errtxt, "Input too long");
		return ZINT_ERROR_TOO_LONG;
	}

	error_number = is_sane(NEON, source, length);
	if(error_number == ZINT_ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	zeroes = 17 - sourcelen;
	strcpy((char *)ean128_equiv, "[00]");
	memset(ean128_equiv + 4, '0', zeroes);
	strcpy((char*)ean128_equiv + 4 + zeroes, (char*)source);

	total_sum = 0;
	for(i = sourcelen - 1; i >= 0; i--)
	{
		total_sum += ctoi(source[i]);

		if(!(i & 1)) {
			total_sum += 2 * ctoi(source[i]);
		}
	}
	nve_check = 10 - total_sum % 10;
	if(nve_check == 10) { nve_check = 0; }
	ean128_equiv[21] = itoc(nve_check);
	ean128_equiv[22] = '\0';

	error_number = ean_128(symbol, ean128_equiv, ustrlen(ean128_equiv));

	return error_number;
}
Example #24
0
char isbn_check(unsigned char source[]) /* For ISBN(10) and SBN only */
{
	unsigned int i, weight, sum, check, h;
	char check_char;

	sum = 0;
	weight = 1;
	h = ustrlen(source) - 1;

	for(i = 0; i < h; i++)
	{
		sum += ctoi(source[i]) * weight;
		weight++;
	}

	check = sum % 11;
	check_char = itoc(check);
	if(check == 10) { check_char = 'X'; }
	return check_char;
}
Example #25
0
int ean_14(struct zint_symbol *symbol, unsigned char source[], int length)
{
	/* EAN-14 - A version of EAN-128 */
	int i, count, check_digit;
	int error_number, zeroes;
	unsigned char ean128_equiv[20];

	if(length > 13) {
		strcpy(symbol->errtxt, "Input wrong length");
		return ZINT_ERROR_TOO_LONG;
	}

	error_number = is_sane(NEON, source, length);
	if(error_number == ZINT_ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid character in data");
		return error_number;
	}

	zeroes = 13 - length;
	strcpy((char*)ean128_equiv, "[01]");
	memset(ean128_equiv + 4, '0', zeroes);
	ustrcpy(ean128_equiv + 4 + zeroes, source);

	count = 0;
	for (i = length - 1; i >= 0; i--) {
		count += ctoi(source[i]);

		if (!(i & 1)) {
			count += 2 * ctoi(source[i]);
		}
	}
	check_digit = 10 - (count % 10);
	if (check_digit == 10) { check_digit = 0; }
	ean128_equiv[17] = itoc(check_digit);
	ean128_equiv[18] = '\0';

	error_number = ean_128(symbol, ean128_equiv, ustrlen(ean128_equiv));

	return error_number;
}
Example #26
0
int korea_post(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Korean Postal Authority */

	int total, loop, check, zeroes, error_number;
	char localstr[8], dest[80];

	error_number = 0;
	if(length > 6) { 
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	zeroes = 6 - length;
	memset(localstr, '0', zeroes);
	strcpy(localstr + zeroes, (char *)source);

	total = 0;
	for(loop = 0; loop < 6; loop++) {
		total += ctoi(localstr[loop]);
	}
	check = 10 - (total % 10);
	if(check == 10) { check = 0; }
	localstr[6] = itoc(check);
	localstr[7] = '\0';
	*dest = '\0';
	for(loop = 5; loop >= 0; loop--) {
		lookup(NEON, KoreaTable, localstr[loop], dest);
	}
	lookup(NEON, KoreaTable, localstr[6], dest);
	expand(symbol, dest);
	ustrcpy(symbol->text, (unsigned char*)localstr);
	return error_number;
}
Example #27
0
static inline char check_digit(unsigned int count)
{
	return itoc((10 - (count % 10)) % 10);
}
int code32(struct zint_symbol *symbol, unsigned char source[], int length)
{   /* Italian Pharmacode */
    int i, zeroes, error_number, checksum, checkpart, checkdigit;
    char localstr[10], risultante[7];
    long int pharmacode, remainder, devisor;
    int codeword[6];
    char tabella[34];

    /* Validate the input */
    if(length > 8) {
        strcpy(symbol->errtxt, "Input too long");
        return ERROR_TOO_LONG;
    }
    error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return error_number;
    }

    /* Add leading zeros as required */
    zeroes = 8 - length;
    memset(localstr, '0', zeroes);
    strcpy(localstr + zeroes, (char*)source);

    /* Calculate the check digit */
    checksum = 0;
    checkpart = 0;
    for(i = 0; i < 4; i++) {
        checkpart = ctoi(localstr[i * 2]);
        checksum += checkpart;
        checkpart = 2 * (ctoi(localstr[(i * 2) + 1]));
        if(checkpart >= 10) {
            checksum += (checkpart - 10) + 1;
        } else {
            checksum += checkpart;
        }
    }

    /* Add check digit to data string */
    checkdigit = checksum % 10;
    localstr[8] = itoc(checkdigit);
    localstr[9] = '\0';

    /* Convert string into an integer value */
    pharmacode = atoi(localstr);

    /* Convert from decimal to base-32 */
    devisor = 33554432;
    for(i = 5; i >= 0; i--) {
        codeword[i] = pharmacode / devisor;
        remainder = pharmacode % devisor;
        pharmacode = remainder;
        devisor /= 32;
    }

    /* Look up values in 'Tabella di conversione' */
    strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ");
    for(i = 5; i >= 0; i--) {
        risultante[5 - i] = tabella[codeword[i]];
    }
    risultante[6] = '\0';
    /* Plot the barcode using Code 39 */
    error_number = c39(symbol, (unsigned char*)risultante, strlen(risultante));
    if(error_number != 0) {
        return error_number;
    }

    /* Override the normal text output with the Pharmacode number */
    ustrcpy(symbol->text, (unsigned char*)"A");
    uconcat(symbol->text, (unsigned char*)localstr);

    return error_number;
}
Example #29
0
int hibc(struct zint_symbol *symbol, uint8_t source[], int length)
{
	int counter, error_number, i;
	char to_process[40], temp[2], check_digit;

	if(length > 36) {
		strcpy(symbol->errtxt, "Data too long for HIBC LIC");
		return ZERROR_TOO_LONG;
	}
	to_upper(source);
	error_number = is_sane(TECHNETIUM , source, length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	strcpy(to_process, "+");
	counter = 41;
	for(i = 0; i < length; i++) {
		counter += posn(TECHNETIUM, source[i]);
	}
	counter = counter % 43;

	if(counter < 10) {
		check_digit = itoc(counter);
	} else {
		if(counter < 36) {
			check_digit = (counter - 10) + 'A';
		} else {
			switch(counter) {
				case 36: check_digit = '-'; break;
				case 37: check_digit = '.'; break;
				case 38: check_digit = ' '; break;
				case 39: check_digit = '$'; break;
				case 40: check_digit = '/'; break;
				case 41: check_digit = '+'; break;
				case 42: check_digit = '%'; break;
				default: check_digit = ' '; break; /* Keep compiler happy */
			}
		}
	}

	temp[0] = check_digit;
	temp[1] = '\0';

	concat(to_process, (char *)source);
	concat(to_process, temp);
	length = strlen(to_process);

	switch(symbol->symbology) {
		case BARCODE_HIBC_QR:
			error_number = qr_code(symbol, (uint8_t *)to_process, length);
			break;
		case BARCODE_HIBC_PDF:
			error_number = pdf417enc(symbol, (uint8_t *)to_process, length);
			break;
		case BARCODE_HIBC_MICPDF:
			error_number = micro_pdf417(symbol, (uint8_t *)to_process, length);
			break;
	}

	return error_number;
}
int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 11 */

    int i;
	int h, c_digit, c_weight, c_count, k_digit, k_weight, k_count;
	int weight[128], error_number;
	char dest[1024]; /* 6 +  121 * 6 + 2 * 6 + 5 + 1 ~ 1024*/
	char checkstr[3];
	
	error_number = 0;

	if(length > 121) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(SODIUM, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	c_weight = 1;
	c_count = 0;
	k_weight = 1;
	k_count = 0;

	/* start character */
	strcpy(dest, "112211");

	/* Draw main body of barcode */
	for(i = 0; i < length; i++) {
		lookup(SODIUM, C11Table, source[i], dest);
		if(source[i] == '-')
			weight[i] = 10;
		else
			weight[i] = ctoi(source[i]);
	}

	/* Calculate C checksum */
	for(h = length - 1; h >= 0; h--) {
		c_count += (c_weight * weight[h]);
		c_weight++;

		if(c_weight > 10) {
			c_weight = 1;
		}
	}
	c_digit = c_count % 11;

	weight[length] = c_digit;

	/* Calculate K checksum */
	for(h = length; h >= 0; h--) {
		k_count += (k_weight * weight[h]);
		k_weight++;

		if(k_weight > 9) {
			k_weight = 1;
		}
	}
	k_digit = k_count % 11;

	checkstr[0] = itoc(c_digit);
	checkstr[1] = itoc(k_digit);
	if(checkstr[0] == 'A') { checkstr[0] = '-'; }
	if(checkstr[1] == 'A') { checkstr[1] = '-'; }
	checkstr[2] = '\0';
	lookup(SODIUM, C11Table, checkstr[0], dest);
	lookup(SODIUM, C11Table, checkstr[1], dest);
	
	/* Stop character */
	concat (dest, "11221");

	expand(symbol, dest);

	ustrcpy(symbol->text, source);
	uconcat(symbol->text, (unsigned char*)checkstr);
	return error_number;
}