Esempio n. 1
0
U_CAPI int32_t U_EXPORT2
uspoof_areConfusableUTF8(const USpoofChecker *sc,
                         const char *s1, int32_t length1,
                         const char *s2, int32_t length2,
                         UErrorCode *status) {

    SpoofImpl::validateThis(sc, *status);
    if (U_FAILURE(*status)) {
        return 0;
    }

    UChar    s1Buf[USPOOF_STACK_BUFFER_SIZE];
    int32_t  lengthS1U;
    UChar   *s1U = convertFromUTF8(s1Buf, USPOOF_STACK_BUFFER_SIZE, &lengthS1U, s1, length1, status);

    UChar    s2Buf[USPOOF_STACK_BUFFER_SIZE];
    int32_t  lengthS2U;
    UChar   *s2U = convertFromUTF8(s2Buf, USPOOF_STACK_BUFFER_SIZE, &lengthS2U, s2, length2, status);

    int32_t results = uspoof_areConfusable(sc, s1U, lengthS1U, s2U, lengthS2U, status);
    
    if (s1U != s1Buf) {
        uprv_free(s1U);
    }
    if (s2U != s2Buf) {
        uprv_free(s2U);
    }
    return results;
}
Esempio n. 2
0
void ARRAY_TEXT::appendUTF8String(const uint8_t* pString, uint32_t len){

	CUTF8String u8 = CUTF8String(pString, len);
	CUTF16String u16;
	convertFromUTF8(&u8, &u16);
	this->_CUTF16StringArray->push_back(u16);		
}
Esempio n. 3
0
int CPaymentHistory::Populate_PmtHistory(int parent,int tracking_id,int tracking_id_serv)
{
	int							status = SUCCESS;
	ArmGuiPaymentHistory			iArmGuiPaymentHistory;
	GAL_ERROR					hError;	
	GAL_ARMGUIPAYMENTHISTORY					lpSelectedObjects;
	GAL_ARMGUIPAYMENTHISTORY					lpCurrentObject;
	CArborCurrency      acEnterAmount(0);
	CArborCurrency		acBalance(0);
	int currency_code;
	long balance_due_in_long;
	int balance;
	ROWNUM row;
	DTCOLORSTRUCT ColorStruct;
	int nSelected = 0;
	char String4[20]="";
	Arb_date			acEntrydate;
	Arb_date			acTransdate;
	int write_off_type_code = 0;

		
	if (galGetPaymentHistory(m_lpAccountData->GetHandle(),parent,tracking_id,tracking_id_serv,
                              &lpSelectedObjects, &hError))
		
	{
		GuiError(__FILE__, __LINE__, "Could not display 'WriteOffs'.");
		return FAILURE;
	}


	memset(&iArmGuiPaymentHistory.charge_date_tm, 0, sizeof(tm));
	memset(&iArmGuiPaymentHistory.transaction_date_tm, 0, sizeof(tm));
	strcpy(iArmGuiPaymentHistory.amount,"");
	strcpy(iArmGuiPaymentHistory.balance,"");
	strcpy(iArmGuiPaymentHistory.type_descr,"");

	int count=0;
	


	for (lpCurrentObject = lpSelectedObjects;	  
		 lpCurrentObject;
		 lpCurrentObject = (GAL_ARMGUIPAYMENTHISTORY) galNextObject(lpCurrentObject))
	{
			if ((galGetArmGuiPaymentHistory_bmf_tracking_id(lpCurrentObject,
								&iArmGuiPaymentHistory.bmf_tracking_id,
								&hError) != GAL_SUCCESS) ||
			    (galGetArmGuiPaymentHistory_bill_ref_no(lpCurrentObject,
								&iArmGuiPaymentHistory.bill_ref_no, 
								&hError) != GAL_SUCCESS) ||
				(galGetArmGuiPaymentHistory_bill_ref_resets(lpCurrentObject,
								&iArmGuiPaymentHistory.bill_ref_resets, 
								&hError) != GAL_SUCCESS) ||
			    (galGetArmGuiPaymentHistory_writeoff_type_code(lpCurrentObject,
								&write_off_type_code, 
								&hError) != GAL_SUCCESS) || 
				(galGetArmGuiPaymentHistory_currency_code(lpCurrentObject, 
								&currency_code,
								&hError) != GAL_SUCCESS)||
			    (galGetArmGuiPaymentHistory_amount(lpCurrentObject,
								acEnterAmount.GetNumeric(),
								&hError) != GAL_SUCCESS)||

			    (galGetArmGuiPaymentHistory_charge_date(lpCurrentObject, 
													&acEntrydate,
													&hError) != GAL_SUCCESS)||
													
				(galGetArmGuiPaymentHistory_transaction_date(lpCurrentObject, 
													&acTransdate,
													&hError) != GAL_SUCCESS)||	
													
				(galGetArmGuiPaymentHistory_source(lpCurrentObject,
								iArmGuiPaymentHistory.source, 
								&hError) != GAL_SUCCESS)||

				(galGetArmGuiPaymentHistory_balance(lpCurrentObject,
								acBalance.GetNumeric(),
								&hError) != GAL_SUCCESS)) 							
					    
				{
					GuiError(__FILE__, __LINE__, "Error getting Group detail fields");
					continue;
				}

		 	if (write_off_type_code == 2)
				strcpy( iArmGuiPaymentHistory.type_descr, resobj.LoadString(IDS_WRITEOFF));
			else if (write_off_type_code == 3)
				strcpy( iArmGuiPaymentHistory.type_descr, resobj.LoadString(IDS_WRITE_RECV));
			else if (write_off_type_code == 4)
				strcpy( iArmGuiPaymentHistory.type_descr, resobj.LoadString(IDS_RECV_REV));
			else if (write_off_type_code == 5)
				strcpy( iArmGuiPaymentHistory.type_descr, resobj.LoadString(IDS_REV_WRITEOFF)); 
			else
			    strcpy(iArmGuiPaymentHistory.type_descr,"");

			acEnterAmount.SetCurrencyCode(currency_code);
			strcpy(iArmGuiPaymentHistory.amount, acEnterAmount.GetFormattedString());
            convert_to_long1(iArmGuiPaymentHistory.amount,&balance_due_in_long,currency_code);


	 	 	if(write_off_type_code == 2)
			{
			
			acBalance.SetCurrencyCode(currency_code);
			strcpy(iArmGuiPaymentHistory.balance, acBalance.GetFormattedString());
            //convert_to_long1(iArmGuiPaymentHistory.bala,&balance_due_in_long,currency_code);
			}

			else

			{
				
			strcpy(iArmGuiPaymentHistory.balance, "N/A");

			}
  
			
			// Calcualation of charge_date
			gui_Arbdate_to_tm( acEntrydate, iArmGuiPaymentHistory.charge_date_tm );

			long year, month, day, hour;
			year = Arbdate_year(&acEntrydate);
			month = Arbdate_month(&acEntrydate);
			day = Arbdate_day(&acEntrydate);
			hour = Arbdate_hour(&acEntrydate);
	
			nSelected++;

			if(nSelected==2)
				iArmGuiPaymentHistory.date_in_int = (Arbdate_to_mins_since_1_1_1900(&acEntrydate)*60) + Arbdate_second(&acEntrydate)+nSelected;
			else
				iArmGuiPaymentHistory.date_in_int = (Arbdate_to_mins_since_1_1_1900(&acEntrydate)*60) + Arbdate_second(&acEntrydate);


			// Calcualation of transaction_date

			gui_Arbdate_to_tm( acTransdate, iArmGuiPaymentHistory.transaction_date_tm );

			year = Arbdate_year(&acTransdate);
			month = Arbdate_month(&acTransdate);
			day = Arbdate_day(&acTransdate);
			hour = Arbdate_hour(&acTransdate);
	
			if(nSelected==2)
				iArmGuiPaymentHistory.date_in_int = (Arbdate_to_mins_since_1_1_1900(&acTransdate)*60) + Arbdate_second(&acTransdate)+nSelected;
			else
				iArmGuiPaymentHistory.date_in_int = (Arbdate_to_mins_since_1_1_1900(&acTransdate)*60) + Arbdate_second(&acTransdate);


			m_pPaymentHistoryDT->SetAccessPos((COLNUM) 0, (ROWNUM) DTPOS_AFTERLAST);

			convertFromUTF8(iArmGuiPaymentHistory);			
			
			m_pPaymentHistoryDT->InsertRow (DTA_ACCESS, (LPArmGuiPaymentHistory) &iArmGuiPaymentHistory);							

										
	}

	m_pPaymentHistoryDT->SetAccessPos(0,DTPOS_HEADINGS);
	m_pPaymentHistoryDT->SelRow(FALSE,0);
	itoa(nSelected,String4,10);
	strcat(String4,resobj.LoadString(IDS_STATUSBAR_ROWS));
	m_wndSBC.SetText(String4, 0, 0);
	galDeleteObjects(lpSelectedObjects);

	return SUCCESS;	
}	
Esempio n. 4
0
intptr_t
j9process_create(OMRPortLibrary *portLibrary, const char *command[], uintptr_t commandLength, const char *dir, uint32_t options, OMRProcessHandle *processHandle)
{
	OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
	intptr_t rc = 0;
	OMRProcessHandleStruct *processHandleStruct = NULL;

#if defined(WIN32)
	STARTUPINFOW sinfo;
	PROCESS_INFORMATION pinfo;
	SECURITY_ATTRIBUTES sAttrib;
	wchar_t *unicodeDir = NULL;
	wchar_t *unicodeCmdline = NULL;
	wchar_t *unicodeEnv = NULL;
	OMRProcessWin32Pipes pipes;
	DWORD dwMode = PIPE_NOWAIT;	/* it's only used if OMRPORT_PROCESS_NONBLOCKING_IO is set */

	if (0 == commandLength) {
		return OMRPROCESS_ERROR;
	}

	processHandleStruct = (OMRProcessHandleStruct *)omrmem_allocate_memory(sizeof(OMRProcessHandleStruct), OMRMEM_CATEGORY_PORT_LIBRARY);

	ZeroMemory(&sinfo, sizeof(sinfo));
	ZeroMemory(&pinfo, sizeof(pinfo));
	ZeroMemory(&sAttrib, sizeof(sAttrib));

	sinfo.cb = sizeof(sinfo);
	sinfo.dwFlags = STARTF_USESTDHANDLES;

	/* Allow handle inheritance */
	sAttrib.bInheritHandle = 1;
	sAttrib.nLength = sizeof(sAttrib);

	ZeroMemory(&pipes, sizeof(OMRProcessWin32Pipes));

	// Create input pipe
	if (0 == CreatePipe(&(pipes.inR), &(pipes.inW), &sAttrib, 512)) {
		closeAndDestroyPipes(&pipes);
		return OMRPROCESS_ERROR;
	} else {
		if (0 == DuplicateHandle(GetCurrentProcess(), pipes.inW, GetCurrentProcess(),
								 &(pipes.inDup), 0, FALSE, DUPLICATE_SAME_ACCESS)) {
			closeAndDestroyPipes(&pipes);
			return OMRPROCESS_ERROR;
		}
		if (0 == CloseHandle(pipes.inW)) {
			closeAndDestroyPipes(&pipes);
			return OMRPROCESS_ERROR;
		}
		pipes.inW = NULL;
	}
	sinfo.hStdInput = pipes.inR;
	processHandleStruct->inHandle = (intptr_t)pipes.inDup;

	if (OMRPROCESS_DEBUG == options) {
		processHandleStruct->outHandle = OMRPROCESS_INVALID_FD;
		if (sinfo.dwFlags == STARTF_USESTDHANDLES) {
			sinfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
		}
		processHandleStruct->errHandle = OMRPROCESS_INVALID_FD;
		if (sinfo.dwFlags == STARTF_USESTDHANDLES) {
			sinfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
		}
	} else {
		// Create output pipe
		if (0 == CreatePipe(&(pipes.outR), &(pipes.outW), &sAttrib, 512)) {
			closeAndDestroyPipes(&pipes);
			return OMRPROCESS_ERROR;
		} else {
			if (0 == DuplicateHandle(GetCurrentProcess(), pipes.outR, GetCurrentProcess(),
									 &(pipes.outDup), 0, FALSE, DUPLICATE_SAME_ACCESS)) {
				closeAndDestroyPipes(&pipes);
				return OMRPROCESS_ERROR;
			}
			if (0 == CloseHandle(pipes.outR)) {
				closeAndDestroyPipes(&pipes);
				return OMRPROCESS_ERROR;
			}
			pipes.outR = NULL;
		}
		processHandleStruct->outHandle = (intptr_t)pipes.outDup;
		sinfo.hStdOutput = pipes.outW;

		// create error pipe
		if (0 == CreatePipe(&(pipes.errR), &(pipes.errW), &sAttrib, 512)) {
			closeAndDestroyPipes(&pipes);
			return OMRPROCESS_ERROR;
		} else {
			if (0 == DuplicateHandle(GetCurrentProcess(), pipes.errR, GetCurrentProcess(),
									 &(pipes.errDup), 0, FALSE, DUPLICATE_SAME_ACCESS)) {
				closeAndDestroyPipes(&pipes);
				return OMRPROCESS_ERROR;
			}
			if (NULL != pipes.errR) {
				if (0 == CloseHandle(pipes.errR)) {
					closeAndDestroyPipes(&pipes);
					return OMRPROCESS_ERROR;
				}
			}
			pipes.errR = NULL;
		}
		processHandleStruct->errHandle = (intptr_t)pipes.errDup;
		sinfo.hStdError = pipes.errW;
	}

	if (0 == rc) {
		rc = getUnicodeCmdline(OMRPORTLIB, command, commandLength, &unicodeCmdline);
		if (0 == rc) {
			if (NULL != dir) {
				size_t length = strlen(dir);
				unicodeDir = (wchar_t *)omrmem_allocate_memory((length + 1) * 2, OMRMEM_CATEGORY_PORT_LIBRARY);
				if (NULL == unicodeDir) {
					rc = OMRPROCESS_ERROR;
				} else {
					convertFromUTF8(OMRPORTLIB, dir, unicodeDir, length + 1);
				}
			}

			if (0 == rc) {
				DWORD creationFlags = CREATE_UNICODE_ENVIRONMENT;

				if (0 == CreateProcessW( /* CreateProcessW returns 0 upon failure */
						NULL,
						unicodeCmdline,
						NULL,
						NULL,
						TRUE,
						creationFlags,		/* add DEBUG_ONLY_THIS_PROCESS for smoother debugging */
						unicodeEnv,
						unicodeDir,
						&sinfo,
						&pinfo)				/* Pointer to PROCESS_INFORMATION structure; */
				) {
					rc = OMRPROCESS_ERROR;
				} else {
					processHandleStruct->procHandle = (intptr_t) pinfo.hProcess;
					/* Close Handles passed to child if there is any */
					CloseHandle(pipes.inR);
					if (OMRPROCESS_DEBUG != options) {
						CloseHandle(pipes.outW);
						CloseHandle(pipes.errW);
					}
					CloseHandle(pinfo.hThread);	/* Implicitly created, a leak otherwise*/
				}
			}
		}
	}

	if (NULL != unicodeCmdline) {
		omrmem_free_memory(unicodeCmdline);
	}
	if (NULL != unicodeDir) {
		omrmem_free_memory(unicodeDir);
	}
	if (NULL != unicodeEnv) {
		omrmem_free_memory(unicodeEnv);
	}

	if (0 != rc) {
		/* If an error occurred close all handles */
		closeAndDestroyPipes(&pipes);
	} else {
		*processHandle = processHandleStruct;
	}

	return rc;
#else /* defined(WIN32) */
	const char *cmd = NULL;
	int grdpid;
	unsigned int i;
	int newFD[3][2];
	int forkedChildProcess[2];
	int pipeFailed = 0;
	int errorNumber = 0;
	char **newCommand;
	uintptr_t newCommandSize;

	if (0 == commandLength) {
		return OMRPROCESS_ERROR;
	}

	for (i = 0; i < 3; i += 1) {
		newFD[i][0] = OMRPROCESS_INVALID_FD;
		newFD[i][1] = OMRPROCESS_INVALID_FD;
	}
	/* Build the new io pipes (in/out/err) */
	if (-1 == pipe(newFD[0])) {
		pipeFailed = 1;
	}
	if (OMRPROCESS_DEBUG != options) {
		if (-1 == pipe(newFD[1])) {
			pipeFailed = 1;
		}
		if (-1 == pipe(newFD[2])) {
			pipeFailed = 1;
		}
	}
	if (-1 == pipe(forkedChildProcess)) { /* pipe for synchronization */
		forkedChildProcess[0] = OMRPROCESS_INVALID_FD;
		forkedChildProcess[1] = OMRPROCESS_INVALID_FD;
		pipeFailed = 1;
	}

	if (pipeFailed) {
		for (i = 0; i < 3; i++) {
			if (OMRPROCESS_INVALID_FD != newFD[i][0]) {
				if (-1 != rc) {
					rc = close(newFD[i][0]);
				}
				if (-1 != rc) {
					rc = close(newFD[i][1]);
				}
			}
		}
		if (OMRPROCESS_INVALID_FD != forkedChildProcess[0]) {
			if (-1 != rc) {
				rc = close(forkedChildProcess[0]);
			}
			if (-1 != rc) {
				rc = close(forkedChildProcess[1]);
			}
		}
		return OMRPROCESS_ERROR;
	}

	if (-1 != rc) {
		rc = setFdCloexec(forkedChildProcess[0]);
	}
	if (-1 != rc) {
		rc = setFdCloexec(forkedChildProcess[1]);
	}

	/* Create a NULL terminated array to contain the command for call to execv[p|e]()
	 * We could do this in the child, but if mem_allocate_memory fails, it's easier to diagnose
	 * failure in parent. Remember to free the memory
	 */
	newCommandSize = (commandLength + 1) * sizeof(uintptr_t);
	newCommand = (char **)omrmem_allocate_memory(newCommandSize, OMRMEM_CATEGORY_PORT_LIBRARY);
	if (NULL == newCommand) {
		return OMRPROCESS_ERROR;
	}
	memset(newCommand, 0, newCommandSize);

	for (i = 0 ; i < commandLength; i += 1) {
#if defined(OSX)
		newCommand[i] = (char *)omrmem_allocate_memory(strlen(command[i]) + 1, OMRMEM_CATEGORY_PORT_LIBRARY);
		omrstr_printf(newCommand[i], strlen(command[i]) + 1, command[i]);
#else /* defined(OSX) */
		intptr_t translateStatus = translateModifiedUtf8ToPlatform(OMRPORTLIB, command[i], strlen(command[i]), &(newCommand[i]));
		if (0 != translateStatus) {
			unsigned int j = 0;
			/* most likely out of memory, free the strings we just converted. */
			for (j = 0; j < i; j += 1) {
				if (NULL != newCommand[j]) {
					omrmem_free_memory(newCommand[j]);
				}
			}
			return translateStatus;
		}
#endif /* defined(OSX) */
	}
	cmd = newCommand[0];

	newCommand[commandLength] = NULL;

	grdpid = fork();
	if (grdpid == 0) {
		/* Child process */
		char dummy = '\0';

		/* Redirect pipes so grand-child inherits new pipes */
		rc = dup2(newFD[0][0], 0);
		if (-1 != rc) {
			if (OMRPROCESS_DEBUG != options) {
				rc = dup2(newFD[1][1], 1);
				if (-1 != rc) {
					rc = dup2(newFD[2][1], 2);
				}
			}
		}

		/* tells the parent that that very process is running */
		rc = write(forkedChildProcess[1], (void *) &dummy, 1);

		if ((-1 != rc) && dir) {
			rc = chdir(dir);
		}

		if (-1 != rc) {
			/* Try to perform the execv; on success, it does not return */
			rc = execvp(cmd, newCommand);
		}

		/* If we get here, tell the parent that the execv failed! Send the error number. */
		if (-1 != rc) {
			rc = write(forkedChildProcess[1], &errno, sizeof(errno));
		}
		if (-1 != rc) {
			rc = close(forkedChildProcess[0]);
		}
		if (-1 != rc) {
			rc = close(forkedChildProcess[1]);
		}
		/* If the exec failed, we must exit or there will be two VM processes running. */
		exit(rc);
	} else {
		/* In the parent process */
		char dummy;

		for (i = 0; i < commandLength; i++) {
			if (NULL != newCommand[i]) {
				omrmem_free_memory(newCommand[i]);
			}
		}
		omrmem_free_memory(newCommand);

		if ((OMRPROCESS_INVALID_FD != newFD[0][0]) && (-1 != rc)) {
			rc = close(newFD[0][0]);
		}
		if ((OMRPROCESS_INVALID_FD != newFD[1][1]) && (-1 != rc)) {
			rc = close(newFD[1][1]);
		}
		if ((OMRPROCESS_INVALID_FD != newFD[2][1]) && (-1 != rc)) {
			rc = close(newFD[2][1]);
		}

		if (grdpid == -1) { /* the fork failed */
			/* close the open pipes */
			if (-1 != rc) {
				rc = close(forkedChildProcess[0]);
			}
			if (-1 != rc) {
				rc = close(forkedChildProcess[1]);
			}
			if ((OMRPROCESS_INVALID_FD != newFD[0][1]) && (-1 != rc)) {
				rc = close(newFD[0][1]);
			}
			if ((OMRPROCESS_INVALID_FD != newFD[1][0]) && (-1 != rc)) {
				rc = close(newFD[1][0]);
			}
			if ((OMRPROCESS_INVALID_FD != newFD[2][0]) && (-1 != rc)) {
				rc = close(newFD[2][0]);
			}
			return OMRPROCESS_ERROR;
		}

		/* Store the rw handles to the childs io */
		processHandleStruct = (OMRProcessHandleStruct *)omrmem_allocate_memory(sizeof(OMRProcessHandleStruct), OMRMEM_CATEGORY_PORT_LIBRARY);
		processHandleStruct->inHandle = (intptr_t)newFD[0][1];
		if (OMRPROCESS_DEBUG == options) {
			processHandleStruct->outHandle = OMRPROCESS_INVALID_FD;
			processHandleStruct->errHandle = OMRPROCESS_INVALID_FD;
		} else {
			processHandleStruct->outHandle = (intptr_t)newFD[1][0];
			processHandleStruct->errHandle = (intptr_t)newFD[2][0];
		}

		processHandleStruct->procHandle = (intptr_t)grdpid;
		processHandleStruct->pid = (int32_t)grdpid;

		/* let the forked child start. */
		rc = close(forkedChildProcess[1]);
		if (-1 != rc) {
			rc = read(forkedChildProcess[0], &dummy, 1);
		}

		/* [PR CMVC 143339]
		 * Instead of using timeout to determine if child process has been created successfully,
		 * a single block read/write pipe call is used, if process creation failed, errorNumber
		 * with sizeof(errno) will be returned, otherwise, read will fail due to pipe closure.
		 */
		if (-1 != rc) {
			rc = read(forkedChildProcess[0], &errorNumber, sizeof(errno));
		}
		if (-1 != rc) {
			rc = close(forkedChildProcess[0]);
		}

		if (rc == sizeof(errno)) {
			return OMRPROCESS_ERROR;
		}
		*processHandle = processHandleStruct;
		return rc;
	}

	return OMRPROCESS_ERROR;
#endif /* defined(WIN32) */
}
Esempio n. 5
0
/**
 * Converts command string array into a single unicode string command line
 *
 * @returns 0 upon success, negative portable error code upon failure
 */
static intptr_t
getUnicodeCmdline(struct OMRPortLibrary *portLibrary, const char *command[], uintptr_t commandLength, wchar_t **unicodeCmdline)
{
	char *needToBeQuoted = NULL;
	size_t length, l;
	intptr_t rc = 0;
	intptr_t i;
	char *ptr = NULL;
	const char *argi = NULL;
	char *commandAsString = NULL;
	OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);

	/*
	 * Windows needs a char* command line unlike regular C exec* functions
	 * Therefore we need to rebuild the line that has been sliced in java...
	 * Subtle : if a token embbeds a <space>, the token will be quoted (only
	 * 			if it hasn't been quoted yet) The quote char is "
	 * Note (see "XXX references in the code)
		 * Our CDev scanner/parser does not handle '"' correctly. A workaround is to close
		 * the '"' with another " , embedded in a C comment.
	 */
	needToBeQuoted = (char *)omrmem_allocate_memory(commandLength, OMRMEM_CATEGORY_PORT_LIBRARY);
	if (NULL == needToBeQuoted) {
		rc = OMRPROCESS_ERROR;
	} else {
		memset(needToBeQuoted, '\0', commandLength);

		length = commandLength; /*add 1 <blank> between each token + a reserved place for the last NULL*/
		for (i = (intptr_t)commandLength; --i >= 0;) {
			intptr_t j;
			size_t commandILength;
			const char *commandStart;
			commandILength = strlen(command[i]);
			length += commandILength;
			/* check_for_embbeded_space */
			if (commandILength > 0) {
				commandStart = command[i];
				if (commandStart[0] != '"' /*"XXX*/) {
					for (j = 0; j < (intptr_t)commandILength ; j += 1) {
						if (commandStart[j] == ' ') {
							needToBeQuoted[i] = '\1'; /* a random value, different from zero though*/
							length += 2; /* two quotes are added */
							if (commandILength > 1 && commandStart[commandILength - 1] == '\\'
								&& commandStart[commandILength - 2] != '\\') {
								length++;    /* need to double slash */
							}
							break;
						}
					}
				}
			} /* end of check_for_embedded_space */
		}

		ptr = commandAsString = (char *)omrmem_allocate_memory(length, OMRMEM_CATEGORY_PORT_LIBRARY);
		if (NULL == commandAsString) {
			omrmem_free_memory(needToBeQuoted);
			rc = OMRPROCESS_ERROR;
		} else {
			uintptr_t k;

			for (k = 0; k < commandLength ; k += 1) {
				l = strlen(argi = command[k]);
				if (needToBeQuoted[k]) {
					*ptr++ = '"' /*"XXX*/ ;
				}
				memcpy(ptr, argi, l);
				ptr += l;
				if (needToBeQuoted[k]) {
					if (l > 1 && *(ptr - 1) == '\\' && *(ptr - 2) != '\\') {
						*ptr++ = '\\';
					}
					*ptr++ = '"' /*"XXX*/ ;
				}
				*ptr++ = ' '; /* put a <blank> between each token */
			}
			*(ptr - 1) = '\0'; /*commandLength > 0 ==> valid operation*/
			omrmem_free_memory(needToBeQuoted);

			*unicodeCmdline = (wchar_t *)omrmem_allocate_memory((length + 1) * 2, OMRMEM_CATEGORY_PORT_LIBRARY);
			if (NULL == *unicodeCmdline) {
				rc = OMRPROCESS_ERROR;
			} else {
				convertFromUTF8(OMRPORTLIB, commandAsString, *unicodeCmdline, length + 1);
				omrmem_free_memory(commandAsString);
			}
		}
	}

	return rc;
}
Esempio n. 6
0
void ARRAY_TEXT::appendUTF8String(CUTF8String* pString)
{
	CUTF16String u16;	
	convertFromUTF8(pString, &u16);
	this->_CUTF16StringArray->push_back(u16);		
}
Esempio n. 7
0
void
CNotesDlg::ProcessFSCResults(GAL_FILTER_SORT_CRITERIA lpFSC)
{
	GAL_ERROR		hError;
	int			nSelectedObjects;
	GAL_NOTE		lpSelectedObjects;
	GAL_NOTE		lpCurrentObject;
	NOTE_ROWINFO	NoteRowInfo;

	//
	// 'CMF_NOTES' fields
	//
	TCHAR		szSubscrLevelExternalId[GAL_NOTE_EQUIP_EXTERNAL_ID_LEN];
	TCHAR		comments[GAL_NOTE_COMMENTS_LEN];
	TCHAR		note_text[GAL_NOTE_TEXT_LENGTH];
	int			permanent_flag;

	// for the comment splitting guy...
	int  iCommentLen;
	int  iTextLen;
	int  iIncRowHt = 0;
	int  iRowNumb;
	int  iRowHeight;
	int iTextRowCount = 1, iCommentRowCount = 1;

	// Delete DataTable data.
	CDataTbl* pNoteDT = (CDataTbl*) GetDlgItem(IDC_NOTE_DT);
	pNoteDT->ResetData();

	if (galListNote(m_hAPI, lpFSC,
				  &nSelectedObjects, &lpSelectedObjects,
				  &hError) == GAL_FAILURE)
	{
		GuiError(__FILE__, __LINE__, "Could not select 'Note'.");
		m_sStatusBar.Format(GetIntlString(IDS_NOTE_SELECT_FAILED));
		UpdateData(FALSE);
		return;
	}
	else
	{
		for ( lpCurrentObject = lpSelectedObjects;
			  lpCurrentObject;
			  lpCurrentObject = (GAL_NOTE) galNextObject(lpCurrentObject), iIncRowHt = 0 )
		{
			if (galGetNote_chg_date(lpCurrentObject, &NoteRowInfo.chg_date,
														 &hError) == GAL_FAILURE ||
			  galGetNote_note_code(lpCurrentObject, NoteRowInfo.note_code,
														 &hError) == GAL_FAILURE ||
			  galGetNote_equip_external_id(lpCurrentObject, szSubscrLevelExternalId,
														 &hError) == GAL_FAILURE ||
			  galGetNote_permanent_flag(lpCurrentObject, &permanent_flag,
														 &hError) == GAL_FAILURE ||
			  galGetNote_chg_who(lpCurrentObject, NoteRowInfo.chg_who,
														 &hError) == GAL_FAILURE ||
			  galGetNote_note_text(lpCurrentObject, note_text, 
														 &hError) == GAL_FAILURE ||
			  galGetNote_comments(lpCurrentObject, comments,
														 &hError) == GAL_FAILURE)
			{
			  GuiError(__FILE__, __LINE__,
				   "Could not 'galGetNote_' some data.");
			}

			gui_Arbdate_to_tm( NoteRowInfo.chg_date, NoteRowInfo.chg_date_tm );

			NoteRowInfo.permanent_flag = permanent_flag;
			
			sprintf( NoteRowInfo.equip_external_id, "%s", szSubscrLevelExternalId );

			iTextRowCount = 1;
			// New line wrapping code
			strcpy(note_text, ArbI18N::translateFromUTF8(note_text));
			if ((iTextLen = strlen(note_text)) <= MAX_NOTE_TEXT)
				sprintf( NoteRowInfo.note_text,"%s", note_text );
			else	// begin wrapping
			{
				TCHAR ListString[ GAL_NOTE_TEXT_LENGTH ];
				int i, j, iColumnCount;

				for (i = 0, j = 0, iColumnCount = 0; i < iTextLen && j < GAL_NOTE_TEXT_LENGTH - 1; ) {
					if (iColumnCount > MAX_NOTE_TEXT) { // wrap line
						ListString[j++] = '\n';
						iColumnCount = 0;
						iTextRowCount++;
					}
					if (note_text[i] == '\n') { // existing newline
						ListString[j++] = note_text[i++];
						iColumnCount = 0;
						iTextRowCount++;
					} else if (IsDBCSLeadByte(note_text[i])) {
						ListString[j++] = note_text[i++];
						ListString[j++] = note_text[i++];
						iColumnCount += 2;
					} else {
						ListString[j++] = note_text[i++];
						iColumnCount += 1;
					}
				} // for loop
				ListString[j] = '\0';
				strcpy(NoteRowInfo.note_text, ListString);
			} // wrapping
			strcpy(NoteRowInfo.note_text, ArbI18N::translateToUTF8(NoteRowInfo.note_text));

			// do the comment wrapping stuff here....
			iCommentRowCount = 1;
			/*CAMqa78687*/
			int enter = '\n';
			strcpy(comments, ArbI18N::translateFromUTF8(comments));
			if (((iCommentLen = strlen(comments)) <= STRING_LEN) && (strchr(comments,enter)) == NULL)
				sprintf( NoteRowInfo.comments,"%s", comments );
			else	// begin wrapping
			{
				TCHAR ListString[ GAL_NOTE_COMMENTS_LENGTH ];
				int i,j, iColumnCount;

				for (i = 0, j = 0, iColumnCount = 0; i < iCommentLen && j < GAL_NOTE_COMMENTS_LENGTH - 1; ) {
					if (iColumnCount > STRING_LEN) { // wrap line
						ListString[j++] = '\n';
						iColumnCount = 0;
						iCommentRowCount++;
					}
					if (comments[i] == '\n') { // existing newline
						ListString[j++] = comments[i++];
						iColumnCount = 0;
						iCommentRowCount++;
					} else if (IsDBCSLeadByte(comments[i])) {
						ListString[j++] = comments[i++];
						ListString[j++] = comments[i++];
						iColumnCount += 2;
					} else {
						ListString[j++] = comments[i++];
						iColumnCount += 1;
					}
				} // for loop
				ListString[j] = '\0';
				strcpy(NoteRowInfo.comments, ListString);
			} // wrapping
			strcpy(NoteRowInfo.comments, ArbI18N::translateToUTF8(NoteRowInfo.comments));

			// we want to set the tallest column height
			iIncRowHt = MAX(iTextRowCount, iCommentRowCount);

			// Display in datatable on dialog box
			pNoteDT->SetAccessPos((COLNUM) 0, (ROWNUM) DTPOS_AFTERLAST);
			convertFromUTF8(NoteRowInfo);
			iRowNumb = pNoteDT->InsertRow (DTA_ACCESS, (LPNOTE_ROWINFO) &NoteRowInfo);

			if( iIncRowHt > 0 )
			{
				pNoteDT->SetAccessPos((COLNUM) 0, (ROWNUM) iRowNumb );
				iRowHeight = pNoteDT->GetRowHeight( DTA_ACCESS );
				pNoteDT->SetRowHeight( DTA_ACCESS, ((iIncRowHt)*iRowHeight) );
			}
		}	// next row
	}	// end else

	galDeleteObjects(lpSelectedObjects);

	UpdateData(FALSE);     // transfer member variable values to the screen
}
Esempio n. 8
0
void CBillReview::PopulateDataTable( void )
{
  GAL_FILTER_SORT_CRITERIA   lpFSC;
  GAL_ERROR                  hError;
  int            nSelectedObjects;
  GAL_INVSUMMARY  lpSelectedObjects;
  GAL_INVSUMMARY lpCurrent;
  int status;
  BILL_ROWINFO BillRowInfo;

  // get the filter sort structure allocated....   
  lpFSC = galNewFilterSortCriteria(GAL_INVSUMMARY_TYPE);

  // Delete DataTable data.
  m_pBillRev_DT->ResetData();

  /* set the filter criteria..... */
  if( galFilterInvSummary_account_no( lpFSC,
                                      GetAccountNO(),
                                      GAL_FILTER_EQUAL,
                                      &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__, 
		   "Account ID Filter failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }

  if( galFilterInvSummary_prep_error_code(lpFSC,
                                          0,
                                          GAL_FILTER_IS_NULL,
                                          &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__, 
		   "Bill Error Code Filter failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }

  if( galFilterInvSummary_backout_status( lpFSC,
                                       PREP_STAT_BACKOUT_COMPLETE,
                                       GAL_FILTER_NOT_EQUAL,
                                       &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__,
		   "Prep_Status Filter - COMPLETE failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }

  if( galFilterInvSummary_prep_status( lpFSC,
                                       PREP_STAT_BACKOUT_COMPLETE,
                                       GAL_FILTER_NOT_EQUAL,
                                       &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__,
		   "Prep_Status Filter - COMPLETE failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }


  if( galFilterInvSummary_prep_status( lpFSC,
                                       PREP_STAT_BACKOUT_SELECT,
                                       GAL_FILTER_NOT_EQUAL,
                                       &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__,
		   "Prep_Status Filter - SELECT failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }
  
   //CAMqa70255 - Filter Proforma Invoices

  if( galFilterInvSummary_prep_status( lpFSC,
                                       PREP_STAT_PRO_FORMA,
                                       GAL_FILTER_NOT_EQUAL,
                                       &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__,
		   "Prep_Status Filter - SELECT failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }

  //DENqa10129 - Filter Incomplete Invoices, if the prep_error_code is NULL
  if( galFilterInvSummary_prep_status( lpFSC,
                                       PREP_STAT_INCOMPLETE,
                                       GAL_FILTER_NOT_EQUAL,
                                       &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__,
		   "Prep_Status Filter - SELECT failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }

  // make sure and sort on statment_date Descending.....
  if( galSortInvSummary_statement_date(lpFSC,
                                       GAL_SORT_DESCENDING,
                                       &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__,
		   "Sort on statement_date failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }
   
/* Beg Add CAMqa47793 */
  if( galSortInvSummary_bill_ref_resets(lpFSC,
                                       GAL_SORT_DESCENDING,
                                       &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__,
		   "Sort on bill_ref_resets failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }

  if( galSortInvSummary_bill_ref_no(lpFSC,
                                       GAL_SORT_DESCENDING,
                                       &hError) != GAL_SUCCESS )
  {
	  GuiError(__FILE__, __LINE__,
		   "Sort on bill_ref_no failed!!\n" );
	  galDeleteFilterSortCriteria(lpFSC);
	  return;
  }
/* End Add CAMqa47793 */   

  // list all the great records that matched the criteria...
  if ((galListInvSummary( m_hAPI,
					               lpFSC,
					               &nSelectedObjects,
					               &lpSelectedObjects,
					               &hError		) != GAL_SUCCESS))
  {
     GuiError(__FILE__, __LINE__,
	      "BillReview List failed!!\n" );
     galDeleteFilterSortCriteria(lpFSC);
  }
   
  galDeleteFilterSortCriteria(lpFSC);

  if( nSelectedObjects <= 0 )
  {
	   // MRH : should just put some message in the Status line.
	   return;
  }

	for ( status = GAL_SUCCESS, lpCurrent = lpSelectedObjects; 
	      lpCurrent; 
	      lpCurrent = galNextObject(lpCurrent) )
	{
    CArborCurrency acAmount;
    int            iCurrencyCode, iFormatStatus, iImageDone;
    Arb_date       dtDate;

		if((galGetInvSummary_bill_ref_no(lpCurrent, &BillRowInfo.bill_ref_no, &hError) != GAL_SUCCESS) || 
		   (galGetInvSummary_bill_ref_resets(lpCurrent, &BillRowInfo.bill_ref_resets, &hError) != GAL_SUCCESS) || 			
		   (galGetInvSummary_statement_date(lpCurrent, &dtDate, &hError) != GAL_SUCCESS) || 			
       (galGetInvSummary_amount(lpCurrent, acAmount.GetNumeric(), &hError) != GAL_SUCCESS)   	||
       (galGetInvSummary_format_status(lpCurrent, &iFormatStatus, &hError) != GAL_SUCCESS)  ||
       (galGetInvSummary_image_done(lpCurrent, &iImageDone, &hError) != GAL_SUCCESS)  ||
       (galGetInvSummary_currency_code(lpCurrent, &iCurrencyCode, &hError) != GAL_SUCCESS) )
		{
			// Let the caller post the error?
			status = GAL_FAILURE;
			break;
		}

    BillRowInfo.online = ((iFormatStatus == 2) && (iImageDone));
    acAmount.SetCurrencyCode(iCurrencyCode);
    strcpy(BillRowInfo.new_charges, acAmount.GetFormattedString());
    gui_Arbdate_to_tm(dtDate, BillRowInfo.statement_date_tm);
    m_pBillRev_DT->SetAccessPos((COLNUM) 0, (ROWNUM) DTPOS_AFTERLAST);
    convertFromUTF8(BillRowInfo);
    m_pBillRev_DT->InsertRow (DTA_ACCESS, (LPBILL_ROWINFO) &BillRowInfo);

	}

	galDeleteObjects(lpSelectedObjects);
}