void CPSRawDlg::OnRead() 
{
	uint16 data[256];
	uint16 len;
	uint16 key_num;
	key_num = m_spin_key.GetPos();
	if (m_helper->psbc_get_pres_or_raw(key_num, data, 256, &len))
	{
		ichar str[1024];
		int i;
		str[0] =II('\0');
		ASSERT(len < 100);
		for (i = 0; i < len; i++)
		{
			isprintf(str + istrlen(str), 1024 - istrlen(str), II("%04x") , data[i]);
			if (i < len - 1)
	  		    isprintf(str + istrlen(str), 1024 - istrlen(str), II(" "));

		}
		m_ed_str.SetWindowText(str);
		m_changed = false;
		m_raw_len = len;
		m_present = true;
	}
	else
	{
		m_present = false;
		m_ed_str.SetWindowText(II("0000"));

	}
	m_caption_present.ShowWindow(!m_present);
		
}		
double iatof(const ichar *string)
{
    double value;
#ifdef UNICODE__ICHAR_WIDE
    /*
        **  using swscanf fails... dunno why, but work around it (AJH)
        **  if (swscanf(string, L"%f", &value) != 1) value = 0.0;
        */
        char * mbc_string;
        size_t need = wcstombs(0, string, istrlen(string));
        /* allocate on the stack */
        mbc_string = malloc ( need );
        if ( mbc_string )
        {
            wcstombs(mbc_string, string, istrlen(string));
            value = atof(mbc_string);
            free ( mbc_string );
        }
        else
            value = 0.0;
#else
    value = atof(string);
#endif
    return value;
}
Example #3
0
DWORD CSubAction::SendMessageInfo::GetData(BYTE* pData_) const
{
	BYTE* pData=pData_;
	
	*((WORD*)pData)=0xFFEB;
	pData+=sizeof(WORD);
    *((DWORD*)pData)=nMessage;
	pData+=sizeof(DWORD);

	if (szWindow!=NULL)
	{
        DWORD dwUsed=(istrlen(szWindow)+1)*2;
		CopyMemory(pData,szWindow,dwUsed);
		pData+=dwUsed;
	}
	else
	{
		*(pData++)='\0';
		*(pData++)='\0';
	}
		
	
	if (szWParam!=NULL)
	{
        DWORD dwUsed=(istrlen(szWParam)+1)*2;
		CopyMemory(pData,szWParam,dwUsed);
		pData+=dwUsed;
	}
	else
	{
		*(pData++)='\0';
		*(pData++)='\0';
	}

	
	if (szLParam!=NULL)
	{
        DWORD dwUsed=(istrlen(szLParam)+1)*2;
		CopyMemory(pData,szLParam,dwUsed);
		pData+=dwUsed;
	}
	else
	{
		*(pData++)='\0';
		*(pData++)='\0';
	}	

	return DWORD(pData-pData_);
}
Example #4
0
DWORD Network::GetComputerNameFromIDList(LPITEMIDLIST lpiil,LPSTR szName,DWORD dwBufferLen)
{
	// May be computer?
	IShellFolder *psf;
	
	if (!SUCCEEDED(SHGetDesktopFolder(&psf)))
		return 0;

	SHDESCRIPTIONID di;
	if (!SUCCEEDED(SHGetDataFromIDList(psf,lpiil,SHGDFIL_DESCRIPTIONID,&di,sizeof(SHDESCRIPTIONID))))
	{
		psf->Release();
		return 0;
	}

	if (di.clsid!=CLSID_NetworkPlaces)
	{
		psf->Release();
		return 0;
	}

	STRRET str;
	if (!SUCCEEDED(psf->GetDisplayNameOf(lpiil,SHGDN_FORPARSING,&str)))
	{
		psf->Release();
		return 0;
	}
	psf->Release();

	if (ShellFunctions::StrRetToStr(str,lpiil,szName,dwBufferLen))
		return istrlen(szName);
	return 0;
}
Example #5
0
int main() {
  char *str1 = istring_mk(NULL);
  char *str2 = istring_mk("Anders");  
  char *str3 = istring_mk("Alander");  
  char *str4 = istring_mk(" ");  
  char *str9 = istring_to_string(str2);
  char *str5 = istrcat(str9,str4);  
  char *str11 = istring_to_string(str5);
  char *str6 = istrcat(str11, str3);
  char *str7 = istring_to_string(str6);
  char *str8 = istring_mk("Erik");
  char *str10 = istring_to_string(str5);
  char *str12 = "Anders Ă…lander";
  char *str13 = istrncat(str9, str3,2);

  printf("An empty istring has length %zu\n", istrlen(str1));
  printf("My first name is %s\n",str2);
  printf("My last  name is %s\n",str3);
  printf("My name concatenated is %s\n", str6);
  printf("%s concatenated with the first %d chars from %s is %s\n", str2, 2, str3, str13);
  printf("%s has length %zu\n", str6, istrlen(str6));
  printf("%s is my name stored as normal string, it also has length %zu\n", str7, strlen(str7));
  printf("An istring's length can be changed without touching the string itself. %s has length %zu\n", str2, istrlen(str2));
  str2 = istrslen(str2, 15);
  printf("but we can change it to %zu\n", istrlen(str2));
  printf("Returns a pointer to the first given character in %s, for example a pointer to 's'gives %s\n", str2, istrchr(str2,'s'));
  printf("Same as above but from the end of %s. Pointer to 's' gives %s\n", str2, istrrchr(str2, 's'));
  printf("Are the strings %s and %s equal? %s\n", str2, str3, istrcmp(str2,str3)?"no":"yes");
  printf("Which one of %s and %s is greatest? %s\n", str2, str3, istrcmp(str2,str3)<0?str2:str3);
  printf("Compares the first %d characters in %s and %s. The substring of %s is greatest\n", 3, str2, str3, istrncmp(str2, str3, 3) > 0?str3:str2);
  printf("The result of copying %s into %s is %s\n", str8, str12, istrcpy(str7, str8));
  printf("The result of copying %d chars from %s into %s is %s\n", 3, str8, str12, istrncpy(str7,str8,3));

  istring_rm(str1);
  istring_rm(str2);
  istring_rm(str3);
  istring_rm(str4);
  istring_rm(str5);
  istring_rm(str6);
  free(str7);
  istring_rm(str8);
  free(str9);
  free(str10);
  free(str11);
  istring_rm(str13);
  return 0;
}
Example #6
0
DWORD CShortcut::GetDataLength() const
{
	DWORD dwLen=sizeof(WORD)+28 /*sizeof(CShortcut)*/;
	if ((m_dwFlags&sfKeyTypeMask)!=sfLocal)
	{
		if (m_pClass!=NULL && m_pClass!=LPSTR(-1))
			dwLen+=DWORD(istrlen(m_pClass)+1);

		if (m_pTitle!=NULL)
			dwLen+=DWORD(istrlen(m_pTitle)+1);
	}

	for (int i=0;i<m_apActions.GetSize();i++)
		dwLen+=m_apActions[i]->GetDataLength();

	return dwLen;
}
Example #7
0
/* This function strips the path and ext from the nameBuffer that correspond to the given path.
 * It will do nothing if the path and ext do not match the one given to it in the path parameter.
 */
void FileName::stripSpecificPathAndExt (Path path, char* nameBuffer, int nameBufferLength)
{
	//-- warning: this function modifies the buffer of the argument
    NOT_NULL(nameBuffer);

    int len = istrlen(nameBuffer);
    char* start = nameBuffer;
    char* end = nameBuffer + len;
    char buffer[1000];

        //string compare nameBuffer to path.path for strlen(path.path)-1 to make sure it is correct.
		//-1 because we don't care about the slash (could be back or forward)
        //@todo these compares could be debug only.
    if (strncmp(nameBuffer, pathTable[path].path, strlen(pathTable[path].path) - 1) != 0)
    {
        DEBUG_REPORT_LOG(true, ("Error in stripSpecificPathAndExt...nameBuffer does not match path\n"));
        return;
    }

        //correct path, now check extension.
        //first make sure this path has an extension
    if (strlen(pathTable[path].ext) > 0)
    {
        end = strrchr(nameBuffer, '.');
            //make sure to compare strings starting just after the dot
        if (!end || strncmp(end + 1, pathTable[path].ext, strlen(pathTable[path].ext)) != 0)
        {
            DEBUG_REPORT_LOG(true, ("Error in stripSpecificPathAndExt...nameBuffer does not match path\n"));
            return;
        }
        *end = '\0'; //End points to '.'  Strip the extension
    }
    else //We aren't supposed to have an ext.  Make sure we don't
    {
        char* tmp = strrchr(nameBuffer, '.');
        if (tmp)
        {
            DEBUG_REPORT_LOG(true, ("Error in stripSpecificPathAndExt...nameBuffer does not match path\n"));
            return;
        }
    }


        //correct extension.  End is set to the correct place...just before the dot.
        //or in the case of no extension, the last character in the string.

        //advance start to after path.  Make sure to skip slashes.
    start += strlen(pathTable[path].path);

    while (*start == '\\' || *start == '/')
        start++;

        //copy from start to end (which is \0) into tmp buffer
    strncpy (buffer, start, 1000);
        //move temp buffer into return.
    strncpy (nameBuffer, buffer, nameBufferLength);
}
HTREEITEM CTreeCtrl::FindItem(LPCWSTR pText,BOOL bBackwardDirection,BOOL bPartial,HTREEITEM hItem,HTREEITEM hEnd) const
{
	TV_ITEMW ti;
	WCHAR szBuffer[1000];
	ti.mask=TVIF_TEXT;
	ti.hItem=hItem;
	ti.pszText=szBuffer;
	ti.cchTextMax=1000;

	LPWSTR pTextMod;
	
	if (bPartial)
	{
		int iStrLen=istrlen(pText);
		pTextMod=new WCHAR[iStrLen+3];
		if (pText[0]!='*')
		{
			pTextMod[0]='*';
			MemCopyW(pTextMod+1,pText,iStrLen++);
		}
		else
			MemCopyW(pTextMod,pText,iStrLen);
		if (pTextMod[iStrLen-1]!='*')
			pTextMod[iStrLen++]='*';
		pTextMod[iStrLen]='\0';
		MakeLower(pTextMod);
	}
		
	while ((ti.hItem=bBackwardDirection?GetPrevItem(ti.hItem):GetNextItem(ti.hItem))!=NULL)
	{
		// Get next item
		if (ti.hItem==hEnd)
			return NULL;

		// Check text
		if (!GetItem(&ti))
			continue;

		

		if (bPartial)
		{
			MakeLower(szBuffer);
			if (ContainString(szBuffer,pTextMod))
			{
				delete[] pTextMod;
				return ti.hItem;
			}
		}
		else if (_wcsicmp(szBuffer,pText)==0)
			return ti.hItem;		
	}

	if (bPartial)
		delete[] pTextMod;
	return NULL;
}
Example #9
0
int strcasecmp(LPCSTR s1,LPCSTR s2)
{
	CHAR *tmp1,*tmp2;	
	int ret;
	DWORD nLen1=(DWORD)istrlen(s1);
	DWORD nLen2=(DWORD)istrlen(s2);
	
	tmp1=new CHAR[nLen1+2];
	if (tmp1==NULL)
		SetHFCError(HFC_CANNOTALLOC);
	CopyMemory(tmp1,s1,nLen1+1);
	
	tmp2=new CHAR[nLen2+2];
	if (tmp2==NULL)
		SetHFCError(HFC_CANNOTALLOC);
	CopyMemory(tmp2,s2,nLen2+1);
	
	CharLowerBuff(tmp1,nLen1);
	CharLowerBuff(tmp2,nLen2);
	ret=strcmp(tmp1,tmp2);
	delete[] tmp1;
	delete[] tmp2;
	return ret;
}
Example #10
0
void CDateTimeCtrlEx::SetRelativeDate(int nNewPos,DWORD dwFlags)
{
	m_dwFlags|=DontSendNotifications;
	
	if (!(dwFlags&DTXF_NOMODECHANGE))
		ChangeMode(TRUE);

	WCHAR szStringBuffer[100];
	int nLen=-1;
	if (nNewPos==0)
		LoadString(IDS_DATETODAY,szStringBuffer,100);
	else if (nNewPos==1)
		LoadString(IDS_DATEDAY,szStringBuffer,100);
	else
	{
		if (_itow_s(nNewPos,szStringBuffer,100,10)!=0)
			szStringBuffer[0]='\0';
		nLen=istrlen(szStringBuffer);
		
		if (nLen+1<100)
		{
			szStringBuffer[nLen]=L' ';
			LoadString(IDS_DATENDAYS,szStringBuffer+nLen+1,100-nLen-1);
		}
	}

	if (IsUnicodeSystem())
		::SendMessageW(m_hEditWnd,WM_SETTEXT,0,(LPARAM)szStringBuffer);
	else
		::SendMessage(m_hEditWnd,WM_SETTEXT,0,(LPARAM)(LPCSTR)W2A(szStringBuffer));

	//::SendMessage(m_hEditWnd,EM_SETSEL,0,nLen);

	if (!(dwFlags&DTXF_NOSPINCHANGE))
		::SendMessage(m_hSpinWnd,UDM_SETPOS32,0,nNewPos);

	m_dwFlags&=~DontSendNotifications;
}
Example #11
0
void FileName::stripPathAndExt (char* nameBuffer, int nameBufferLength)
{
	NOT_NULL (nameBuffer);

	//-- warning: this function modifies the buffer of the argument
	char  buffer [1000];

	int   len   = istrlen (nameBuffer);
	char* start = nameBuffer;
	char* end   = nameBuffer + len;
	char* curr  = end;

	//-- start from end of string and search backward for '\' or '/'
	while (curr != start && !(*curr == '\\' || *curr == '/'))
		curr--;

	//-- start from curr and search to the end for '.'
	if (*curr == '\\' || *curr == '/')
		curr++;

	start = curr;
	while (curr < end && *curr != '.')
		curr++;

	//-- copy string
	end  = curr;
	curr = start;
	len  = end - start;
	int i;
	for (i = 0; i < len && i < nameBufferLength; i++)
		buffer [i] = *curr++;

	buffer [i] = 0;

	strncpy (nameBuffer, buffer, nameBufferLength);
}
Example #12
0
void FileName::stripPath (char* nameBuffer, int nameBufferLength)
{
	NOT_NULL (nameBuffer);

	//-- warning: this function modifies the buffer of the argument
	char  buffer [1000];

	int   len   = istrlen (nameBuffer);
	char* start = nameBuffer;
	char* end   = nameBuffer + len;
	char* curr  = end;

	//-- start from end of string and search backward for '\' or '/'
	while (curr != start && !(*curr == '\\' || *curr == '/'))
		curr--;

	if (curr != start && (*curr == '\\' || *curr == '/'))
		curr++;

	//-- copy string
	start = curr;
	len  = end - start;
	int i;
	for (i = 0; i < len && i < nameBufferLength; i++)
		buffer [i] = *curr++;

	if (i >= nameBufferLength)
		i--;

	DEBUG_FATAL (i < 0, ("i < 0"));

	buffer [i] = 0;

	strncpy (nameBuffer, buffer, nameBufferLength);
	nameBuffer [nameBufferLength - 1] = 0;
}
Example #13
0
int main(int argc,char* argv[])
{
    printf("str lenth is %u\n",istrlen("this is a function\0"));
}
Example #14
0
void FileName::stripPathAndExt (void)
{
	stripPathAndExt (fullName, istrlen (fullName));
}
Example #15
0
DWORD CShortcut::GetData(BYTE* _pData) const
{
	BYTE* pData=_pData;
	
	*((WORD*)pData)=0xFFED; // Start mark
	pData+=sizeof(WORD);

	// Flags
	*((WORD*)pData)=m_dwFlags;

	// Virtual key
	*(pData+2)=m_bVirtualKey;
	
	// Modfiers
	*(pData+3)=m_bModifiers;

	// Class
	if (m_pClass==LPSTR(-1))
		*((DWORD*)(pData+4))=DWORD(-1);
	else
		*((DWORD*)(pData+4))=(DWORD)min(ULONG_PTR(m_pClass),MAXDWORD);
	
	// Title
	*((DWORD*)(pData+8))=(DWORD)min(ULONG_PTR(m_pTitle),MAXDWORD);
	
	// Delay
	*((DWORD*)(pData+12))=m_nDelay;

	
	// Array
	*((DWORD*)(pData+24))=m_apActions.GetSize();
		
	
	
	pData+=28 /*sizeof(CShortcut)*/;


	if ((m_dwFlags&sfKeyTypeMask)!=sfLocal)
	{
		if (m_pClass!=NULL && m_pClass!=LPSTR(-1))
		{
			int iUsed=istrlen(m_pClass)+1;
			CopyMemory(pData,m_pClass,iUsed);
			pData+=iUsed;
		}

		if (m_pTitle!=NULL)
		{
            int iUsed=istrlen(m_pTitle)+1;
			CopyMemory(pData,m_pTitle,iUsed);
			pData+=iUsed;
		}
	}

	for (int i=0;i<m_apActions.GetSize();i++)
	{
		pData+=m_apActions[i]->GetData(pData);
	}

	return DWORD(pData-_pData);
}
Example #16
0
void FileName::stripPath (void)
{
	stripPath (fullName, istrlen (fullName));
}
Example #17
0
void CSubAction::DoMisc()
{
	if (m_nMisc==ExecuteCommandMisc)
	{
		if (m_szCommand!=NULL)
			CLocateDlg::ExecuteCommand(m_szCommand);
		return;
	}
	else if (m_nMisc==InsertAsterisks)
	{
		CLocateDlg* pLocateDlg=GetLocateDlg();
		if (pLocateDlg==NULL)
			return;

		CStringW Text;
		pLocateDlg->m_NameDlg.m_Name.GetText(Text);
		DWORD dwSelStart=pLocateDlg->m_NameDlg.m_Name.GetEditSel();
		WORD wSelEnd=HIWORD(dwSelStart);
		dwSelStart&=0xFFFF;

		// If asterisks are already at the beginning and the end, replace spaces
		if (Text[0]==L'*' && Text.LastChar()==L'*')
			Text.ReplaceChars(L' ',L'*');
		else 
		{
			if (Text[0]!=L'*')
			{
				Text.InsChar(0,L'*');
				
				// Update selection
				if (dwSelStart==wSelEnd)
				{
					dwSelStart++;
					wSelEnd++;
				}
				else 
				{
					if (dwSelStart>0)
						dwSelStart++;
					wSelEnd++;
				}
			}
			
			if (Text.LastChar()!=L'*')
			{
				// Update selection first
				if (wSelEnd==Text.GetLength())
				{
					if (dwSelStart==wSelEnd)
						dwSelStart++;
					wSelEnd++; 
				}

				Text.Append(L'*');
			}
		}

		pLocateDlg->m_NameDlg.m_Name.SetText(Text);
		pLocateDlg->m_NameDlg.m_Name.SetEditSel(dwSelStart,wSelEnd);
		pLocateDlg->OnFieldChange(CLocateDlg::isNameChanged);
		return;
	}
	

	// Send/Post Message

	BOOL bFreeWParam=FALSE,bFreeLParam=FALSE;
	
	HWND hWnd=NULL;
	WPARAM wParam=NULL,lParam=NULL;

	if (m_pSendMessage->szWindow[0]=='0')
	{
		if (m_pSendMessage->szWindow[1]=='x' || 
			m_pSendMessage->szWindow[1]=='X')
		{
			// Hex value
			LPWSTR szTemp;
			hWnd=(HWND)wcstoul(m_pSendMessage->szWindow+2,&szTemp,16);
		}
	}
	else if (strcasecmp(m_pSendMessage->szWindow,L"HWND_BROADCAST")==0)
		hWnd=HWND_BROADCAST;
	else if (GetLocateDlg()!=NULL && strcasecmp(m_pSendMessage->szWindow,L"LOCATEDLG")==0)
		hWnd=*GetLocateDlg();
	else if (strcasecmp(m_pSendMessage->szWindow,L"LOCATEST")==0)
		hWnd=*GetTrayIconWnd();
	else if (wcsncmp(m_pSendMessage->szWindow,L"Find",4)==0)
	{
		int nIndex=(int)FirstCharIndex(m_pSendMessage->szWindow,L'(');
		if (nIndex!=-1)
		{
			LPCWSTR pText=m_pSendMessage->szWindow+nIndex+1;
			LPWSTR pClassAndWindow[3]={NULL,NULL,NULL};
			
			nIndex=(int)FirstCharIndex(pText,L',');
			if (nIndex==-1)
			{
				nIndex=(int)FirstCharIndex(pText,L')');
				if (nIndex==-1)
					pClassAndWindow[0]=alloccopy(pText);
				else
					pClassAndWindow[0]=alloccopy(pText,nIndex);
			}
			else
			{
				pClassAndWindow[0]=alloccopy(pText,nIndex);
				pText+=nIndex+1;

				nIndex=(int)FirstCharIndex(pText,L')');
				pClassAndWindow[1]=alloccopy(pText,nIndex);
			}

			EnumWindows(WindowEnumProc,LPARAM(pClassAndWindow));

			// Third cell is handle to window
			hWnd=(HWND)pClassAndWindow[2];

			delete[] pClassAndWindow[0];
			if (pClassAndWindow[1])
				delete[] pClassAndWindow[1];
		}
	}
	


	// Parse wParam
	if (m_pSendMessage->szWParam!=NULL)
	{
		if (m_pSendMessage->szWParam[0]=='0')
		{
			if (m_pSendMessage->szWParam[1]=='x' || 
				m_pSendMessage->szWParam[1]=='X')
			{
				// Hex value
				LPWSTR szTemp;
				wParam=(WPARAM)wcstoul(m_pSendMessage->szWParam+2,&szTemp,16);
			}
			else if (m_pSendMessage->szWParam[1]!='\0')
			{
				DWORD dwLength;
				wParam=(WPARAM)dataparser(m_pSendMessage->szWParam,istrlen(m_pSendMessage->szWParam),gmalloc,&dwLength);
				*((BYTE*)wParam+dwLength)=0;
				bFreeWParam=TRUE;
			}
		}
		else if ((wParam=_wtoi(m_pSendMessage->szWParam))==0)
		{
			DWORD dwLength;
			wParam=(WPARAM)dataparser(m_pSendMessage->szWParam,istrlen(m_pSendMessage->szWParam),gmalloc,&dwLength);
			*((BYTE*)wParam+dwLength)=0;
			bFreeWParam=TRUE;
		}
	}

	// Parse lParam
	if (m_pSendMessage->szLParam!=NULL)
	{
		if (m_pSendMessage->szLParam[0]=='0')
		{
			if (m_pSendMessage->szLParam[1]=='x' || 
				m_pSendMessage->szLParam[1]=='X')
			{
				// Hex value
				LPWSTR szTemp;
				lParam=(WPARAM)wcstoul(m_pSendMessage->szLParam+2,&szTemp,16);
			}
			else if (m_pSendMessage->szLParam[1]!='\0')
			{
				DWORD dwLength;
				lParam=(WPARAM)dataparser(m_pSendMessage->szLParam,istrlen(m_pSendMessage->szLParam),gmalloc,&dwLength);
				*((BYTE*)lParam+dwLength)=0;
				bFreeLParam=TRUE;
			}
		}
		else if ((lParam=_wtoi(m_pSendMessage->szLParam))==0)
		{
			DWORD dwLength;
			lParam=(WPARAM)dataparser(m_pSendMessage->szLParam,istrlen(m_pSendMessage->szLParam),gmalloc,&dwLength);
			*((BYTE*)lParam+dwLength)=0;
            bFreeLParam=TRUE;
		}
	}

	if (hWnd!=NULL)
	{
		if (m_nMisc==PostMessage)
			::PostMessage(hWnd,m_pSendMessage->nMessage,wParam,lParam);
		else
			::SendMessage(hWnd,m_pSendMessage->nMessage,wParam,lParam);
	}

	if (bFreeWParam)
		GlobalFree((HANDLE)wParam);
	if (bFreeLParam)
		GlobalFree((HANDLE)lParam);

}
Example #18
0
void FileName::stripSpecificPathAndExt (Path path)
{
    stripSpecificPathAndExt (path, fullName, istrlen (fullName));
}
Example #19
0
static void	*sendItems(void *parm)
{
	SenderThreadParms	*stp = (SenderThreadParms *) parm;
	Sdr			sdr;
	char			buffer[MAX_LINE_LEN + 1];
	int			length;
	Object			extent;
	Object			item = 0;

	snooze(3);	/*	Let sda_run get started.		*/
	sdr = getIonsdr();
	while (stp->running)
	{
		if (fgets(buffer, MAX_LINE_LEN, stdin) == NULL)
		{
			sda_interrupt();
			stp->running = 0;
			continue;	/*	End of file, and test.	*/
		}

		length = istrlen(buffer, MAX_LINE_LEN) + 1;

		/*	Send NULL-terminated text line as an SDA item.	*/

		CHKNULL(sdr_begin_xn(sdr));
		extent = sdr_insert(sdr, buffer, length);
		if (extent)
		{
			item = ionCreateZco(ZcoSdrSource, extent, 0, length,
					0, 0, ZcoOutbound, NULL);
		}

		if (sdr_end_xn(sdr) < 0 || item == 0 || item == (Object) ERROR)
		{
			putErrmsg("Service data item insertion failed.", NULL);
			sda_interrupt();
			stp->running = 0;
			continue;
		}

		if (sda_send(stp->destEngineId, SDA_TEST_CLIENT, item) < 0)
		{
			putErrmsg("Service data item sending failed.", NULL);
			sda_interrupt();
			stp->running = 0;
			continue;
		}

		CHKNULL(sdr_begin_xn(sdr));
		zco_destroy(sdr, item);
		if (sdr_end_xn(sdr) < 0)
		{
			putErrmsg("Service data item deletion failed.", NULL);
			sda_interrupt();
			stp->running = 0;
			continue;
		}
	}

	writeErrmsgMemos();
	writeMemo("[i] sdatest sender thread has ended.");
	return NULL;
}
Example #20
0
int main(int argc, char *argv[]) {
	FILE *fp, *out;
	char line[256];
	struct input_t * doc = (struct input_t *) malloc(sizeof(struct input_t));

	char *line_pointer;

	int line_already_counted;
	int multi_line_comment;
	int total_lines;
	int lines_of_code;
	int code, port = 0;
	int list_s; /*  listening socket          */
	int conn_s; /*  connection socket         */
	char * szPort = SERVER_PORT;

	unsigned char i;

	char * input_name = NULL;
	char * output_name = NULL;
	uint16_t len;

	struct sockaddr_in sin;

	//input_t * doc;
	int opts = 1;

	extern char *optarg;
	extern int optind;

	for (;;) {
		int c = getopt(argc, argv, "hp:o:");
		if (c == -1)
			break;
		switch (c) {
		case 'h':
			usage(argv[0]);
			return 0;
		case 'o':
			output_name = optarg;
			break;
		case 'p':
			szPort = optarg;
			break;
		}
	}

	/* SMC - avoid NULL deref if output name isn't provided. */
	if (output_name == NULL) {
		fprintf(stderr, "No output file specified with -o option\n");
		exit(EXIT_FAILURE);
	}

	if ((port = atoi(szPort)) == 0) {
		fprintf(stderr, "Error reading port value with -p option\n");
		exit(EXIT_FAILURE);
	}

	/*Initialize socket values*/
	memset(&sin, 0, sizeof(sin));
	sin.sin_family = AF_INET;
	sin.sin_addr.s_addr = INADDR_ANY;
	sin.sin_port = htons(port);

	/*Create server listening socket*/
	if ((list_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
		fprintf(stderr, "socket failed with error\n");
		exit(EXIT_FAILURE);
	}

	/*Allow this port to be reused*/
	if (setsockopt(list_s, SOL_SOCKET, SO_REUSEADDR, (char *) &opts,
			sizeof(opts)) < 0) {
		fprintf(stderr, "setsockopt failed with error\n");
		exit(EXIT_FAILURE);
	}

	/*Bind to the specified port and address*/
	if (bind(list_s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
		fprintf(stderr, "bind failed with an error\n");
		perror("ERROR");
		exit(EXIT_FAILURE);
	}

	/*Listen for incoming connections*/
	if (listen(list_s, LISTENQ) < 0) {
		fprintf(stderr, "listen failed with error\n");
		exit(EXIT_FAILURE);
	}

	fprintf(stderr, "Socket created.  Ready to accept on port %d.\n", port);
	fflush(stderr);

	fprintf(stderr, "WAVESRV: waiting for a connection\n");
	fflush(stderr);

	/*  Wait for a connection, then accept() it  */

	if ((conn_s = accept(list_s, NULL, NULL)) < 0) {
		fprintf(stderr, "ECHOSERV: Error calling accept()\n");
		exit(EXIT_FAILURE);
	}

	fprintf(stderr, "WAVESRV: Connected!\n");
	fflush(stderr);

	/*  Retrieve an input line from the connected socket
	 then simply write it back to the same socket.     */
	doc = ReceiveFile(conn_s); // STONESOUP:DATA_FLOW:ADDRESS_AS_A_FUNCTION_RETURN_VALUE

	/*  Close the connected socket  */

	if (close(conn_s) < 0) {
		fprintf(stderr, "WAVESRV: Error calling close()\n");
		exit(EXIT_FAILURE);
	}

	if (doc == NULL) {
		fprintf(stderr, "No valid document received\n");
		exit(EXIT_FAILURE);
	}

	// Open the output file.

	//fp = openFile(input_name, "r");
	out = openFile(output_name, "w+");


	// After initializing variables, loop through each line of the file using fgets().  The function
	// fgets(str, num, fp) reads up to num - 1 characters from the file stream fp and dumps them
	// into str. fgets() will stop when it reaches the end of a line, in which case str will be
	// terminated with a newline. If fgets() reaches num - 1 characters or encounters the EOF,
	// str will be null-terminated. fgets() returns str on success, and NULL on an error.

	multi_line_comment = 0;
	total_lines = 0;
	lines_of_code = 0;

	memset(line, '\0', 256);

	for (; doc != NULL; doc = (struct input_t *) doc->next_line) {
		strcpy(line, doc->data);
		total_lines++;

		// We are reading a new line so we need to reset the line_already_counted flag since
		// it obviously hasn't been counted yet.

		line_already_counted = 0;

		// Since fgets() may terminate a string with a newline ... we need to strip any trailing
		// '\n' and replace it with a NULL character.

		if (line[strlen(line) - 1] == '\n')
			line[strlen(line) - 1] = '\0';

		// Set the line_pointer to the first character of the line.

		line_pointer = line;

		// We are now ready to parse the line character by character.

		while (*line_pointer != '\0') {
			// If we are currently in a multi line scenario, then we need to check if we have hit
			// an end tag.  Otherwise we just advance the pointer and keep looping.

			if (multi_line_comment == 1) {
				if (*line_pointer == '*') {
					// Advance the line_pointer.  We need to check for the NULL character
					// and break if found. If we don't do this, then the next line_pointer++
					//call (before the start of the next iteration) will advance us out of bounds.

					line_pointer++;
					if (*line_pointer == '\0')
						break;

					if (*line_pointer == '/') {
						// An end tag has been found!  Reset the multi_line_comment.
						// Note that we still need to advance the pointer and continue
						// the loop.

						multi_line_comment = 0;
					}
				}

				line_pointer++;
				continue;
			}

			// If the current character is a whitespace, then skip it and continue the loop
			// inorder to examine the next character.

			if (isspace(*line_pointer) != 0) {
				line_pointer++;
				continue;
			}

			// If the current character is a slash, then we need to look at the following
			// character to see if the line is a Java comment.  If we are looking at a Java
			// comment line, then just break out of the loop without incrementing the
			// line counter.

			if (*line_pointer == '/') {
				// Advance the line_pointer.  We need to check for the NULL character
				// and break if found. If we don't do this, then the next line_pointer++
				//call (before the start of the next iteration) will advance us out of bounds.

				line_pointer++;
				if (*line_pointer == '\0')
					break;

				// If the next character is a slash as well, then a single line comment has
				// been found.  The rest of this line is not code, so break out of this loop.

				if (*line_pointer == '/')
					break;

				// If the next character is an asterisk, then a multi-line comment has been
				// found.  We now need to skip every line until the end of the comment. To
				// do this, we will turn on the multi_line_comment flag and continue
				// processing this line (and any following line) looking for the closing tag.
				//Note that the end of the comment may contain code on the rest of the
				// line after the closing comment tag.

				if (*line_pointer == '*') {
					multi_line_comment = 1;
					line_pointer++;
					continue;
				}

				// Note that if we reach here, a Java comment was NOT found, so we should
				// fall through to the default processing and count the current line as a
				// valid line of code.
			}

			// A line of Java code has been found!  If the line has not already been counted, then
			// increment the line counter.

			if (line_already_counted == 0) {
				if (DEBUG)
					printf("DEBUG: %s\n", line_pointer);
				lines_of_code++;
				line_already_counted = 1;
				len = istrlen(line) + 1;
				char * lineout = (char *) malloc(len);
				memcpy(lineout, line, len);
				printf("3\n");
				strcat(lineout, "\n");
				fputs(lineout, out);
			}

			// copy this line to the output


			// Move the line pointer to the next character in the line so that the next
			// iteration of the current loop doesn't try to process the same character.

			line_pointer++;
		}
	}

	// We are done with the file so close it.

	if (fclose(out)) {
		printf("\nERROR: File close error.\n");
		return (EXIT_FAILURE);
	}

	// We have finished looking at each line in the file, and now have the line count.  So print it!!

	if (DEBUG)
		printf(
				"\nDEBUG: The file '%s' contains %d total lines, of which %d are code.\n\n",
				input_name, total_lines, lines_of_code);
	printf("\nRESULT: %d", lines_of_code);

	return (EXIT_SUCCESS);
}
Example #21
0
static void
load_one_catalogue(catalog_file * file)
{ FILE *src = wfopen(file->file, "r");
  ichar buffer[2 * FILENAME_MAX];
  ichar base[2 * FILENAME_MAX];
  ichar *p;
  int t;
  catalogue_item_ptr this_item;
  int override = 0;

  if ( !src )
  { gripe(NULL, ERC_NO_CATALOGUE, file->file);
    return;
  }

  (void) istrcpy(base, file->file);
  p = base + istrlen(base);
  while (p != base && !isDirSep(p[-1]))
    p--;

  for (;;)
  { t = scan(src, buffer, sizeof(buffer), 1);
    switch (t)
    { case CAT_BASE:
	if (scan(src, buffer, sizeof(buffer), 0) == EOF)
	  break;
	(void) istrcpy(base, buffer);
	p = base + istrlen(base);
	if (p != base && !isDirSep(p[-1]))
	  *p++ = '/';
	continue;
      case CAT_OVERRIDE:
	if (scan(src, buffer, sizeof(buffer), 0) == EOF)
	  break;
	override = towlower(buffer[0]) == 'y' ? CAT_OVERRIDE : 0;
	continue;
      case CAT_PUBLIC:
      case CAT_SYSTEM:
      case CAT_ENTITY:
      case CAT_DOCTYPE:
	this_item = sgml_malloc(sizeof *this_item);
	if (scan(src, buffer, sizeof buffer, 0) == EOF)
	  break;
	if (t == CAT_PUBLIC)
	  squish(buffer);
	this_item->next = 0;
	this_item->kind = t == CAT_SYSTEM ? t : t + override;
	this_item->target = istrdup(buffer);

	if (scan(src, buffer, sizeof buffer, 0) == EOF)
	  break;

	if (is_absolute_path(buffer) || p == base)
	{ this_item->replacement = istrdup(buffer);
	} else
        { (void) istrcpy(p, buffer);
          this_item->replacement = istrdup(base);
        }

	if (file->first_item == 0)
	{ file->first_item = this_item;
	} else
	{ file->last_item->next = this_item;
	}

	file->last_item = this_item;
	continue;
      case EOF:
	break;
      default:
	continue;
    }
    break;
  }
Example #22
0
LPWSTR GetDefaultFileLocation(LPCWSTR szFileName,BOOL bMustExists,DWORD* lpdwSize)
{
	int nFileNameLen=istrlen(szFileName);
	
	// Check first that is there 
	PFNSHGETFOLDERPATH pGetFolderPath=(PFNSHGETFOLDERPATH)GetProcAddress(GetModuleHandle("shell32.dll"),"SHGetFolderPathW");
	if (pGetFolderPath!=NULL)
	{
		WCHAR szAppDataPath[MAX_PATH];
		if (SUCCEEDED(pGetFolderPath(NULL,CSIDL_APPDATA,NULL,
			SHGFP_TYPE_CURRENT,szAppDataPath)))
		{
			int nPathLen=istrlen(szAppDataPath);

			// Insert \\ if already not there
			if (szAppDataPath[nPathLen-1]!=L'\\')
				szAppDataPath[nPathLen++]=L'\\';
			
			// Buffer for default path
			LPWSTR pStr=new WCHAR[nPathLen+9+nFileNameLen+1];
			MemCopyW(pStr,szAppDataPath,nPathLen);
			MemCopyW(pStr+nPathLen,L"Locate32",9);
			nPathLen+=8;

			// Now pStr contains X:\UsersFolder\AppPath\Locate32

			// Check whether directory exists
			if (FileSystem::IsDirectory(pStr))
			{
				// Directory does exist
				// Copy file name part at tail 
				pStr[nPathLen++]='\\';
				MemCopyW(pStr+nPathLen,szFileName,nFileNameLen+1);
				if (lpdwSize!=NULL)
					*lpdwSize=nPathLen+nFileNameLen;
				
				if (!bMustExists)
					return pStr;	

				// Checking file
				if (FileSystem::IsFile(pStr))
					return pStr;
			}
			else
			{
				// Create directory if does not already exists 
				// and bMustExists is not set (this function is called
				// for default databases with bMustExists=FALSE)
				if (!bMustExists)
				{
					FileSystem::CreateDirectory(pStr);
					// Copy file name part at tail 
					pStr[nPathLen++]='\\';
					MemCopyW(pStr+nPathLen,szFileName,nFileNameLen+1);
					if (lpdwSize!=NULL)
						*lpdwSize=nPathLen+nFileNameLen;
					
					return pStr;
				}	
			
			}
				

			delete[] pStr;
		}
	}

	// Check also Locate32's directory, maybe there is that file
	int iLen;
	LPWSTR pStr;
	WCHAR szExeName[MAX_PATH];
	FileSystem::GetModuleFileName(NULL,szExeName,MAX_PATH);
	iLen=LastCharIndex(szExeName,L'\\')+1;
	pStr=new WCHAR[iLen+nFileNameLen+1];
	MemCopyW(pStr,szExeName,iLen);
	
	MemCopyW(pStr+iLen,szFileName,nFileNameLen+1);
	if (lpdwSize!=NULL)
		*lpdwSize=iLen+nFileNameLen;

	if (!bMustExists)
		return pStr;	

	if (FileSystem::IsFile(pStr))
		return pStr;

	// Return NULL
	delete[] pStr;
	return NULL;
}
Example #23
0
static vast	getLengthOfItem(unsigned int clientId, unsigned char *buffer,
			vast bufferLength)
{
	return 1 + istrlen((char *) buffer, bufferLength);
}
Example #24
0
// The WinProc
LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
    char buff[256] = {0}; // A character string for "filling" with text to print
		
	switch(message)
    {
		// This message gets sent if a "command item" from a menu is selected 
		// (it also gets sent for other stuff but this is what we care about)
		case WM_COMMAND:
		
			switch(LOWORD(wparam)) // The LOWORD(wparam) will equal the "identifier" of
			{					   // of whatever was selected -- These are #defined in 
								   // resource.h
								   // **NOTE**  If using VC++6.0 these are given to you when you
								   // "make a resource script"  So I didn't come up with
								   // these names (I could change 'em) but I'm using the
								   // defaults

				
				case ID_QUIT: // If they select "Quit" -- quit the program
				
					SendMessage(hwnd, WM_CLOSE, 0, 0); // Send the message that tells Windows to
						break;						  // close the window
						
				
				// The user selected "Green" under the "PrintText" menu
				case ID_PRINTTEXT_GREEN:

					// This fills the rect we just got completely to white
					// (effectively "erasing" any text that may have previously been there)
					FillRect(gHDC,&gRect,(HBRUSH)GetStockObject(WHITE_BRUSH));

					sprintf(buff,"This is green"); // Fill buff with appropriate message

					SetTextColor(gHDC,RGB(0,200,0)); // Set the text color to green
					TextOut(gHDC,kXStart,kYStart,buff,istrlen(buff)); // Print out the "green text"
						break;

				// The user selected "Blue" under the "PrintText" menu
				case ID_PRINTTEXT_BLUE:

					// This fills the rect we just got completely to white
					// (effectively "erasing" any text that may have previously been there)
					FillRect(gHDC,&gRect,(HBRUSH)GetStockObject(WHITE_BRUSH));

					sprintf(buff,"This is blue"); // Fill buff with appropriate message

					SetTextColor(gHDC,RGB(0,0,200)); // Set the text color to blue
					TextOut(gHDC,kXStart,kYStart,buff,istrlen(buff)); // Print out the "green text"
						break;

				// The user selected "Bright" off of the "Red" under the "PrintText" menu
				case ID_PRINTTEXT_RED_BRIGHT:

					// This fills the rect we just got completely to white
					// (effectively "erasing" any text that may have previously been there)
					FillRect(gHDC,&gRect,(HBRUSH)GetStockObject(WHITE_BRUSH));

					sprintf(buff,"This is bright red"); // Fill buff with appropriate message

					SetTextColor(gHDC,RGB(250,45,45)); // Set the text color to bright red
					TextOut(gHDC,kXStart,kYStart,buff,istrlen(buff)); // Print out "bright red text"
						break;

				// The user selected "Dark" off of the "Red" under the "PrintText" menu
				case ID_PRINTTEXT_RED_DARK:

					// This fills the rect we just got completely to white
					// (effectively "erasing" any text that may have previously been there)
					FillRect(gHDC,&gRect,(HBRUSH)GetStockObject(WHITE_BRUSH));

					sprintf(buff,"This is dark red"); // Fill buff with appropriate message

					SetTextColor(gHDC,RGB(140,10,30)); // Set the text color to dark red
					TextOut(gHDC,kXStart,kYStart,buff,istrlen(buff)); // Print out "dark red text"
						break;

			} // end of switch(LOWORD(wparam))
			
			return 0;
		
		case WM_DESTROY:

			ReleaseDC(hwnd, gHDC); // Free up the global HDC
			DestroyMenu(gMenu); // This frees the menu that we created
			PostQuitMessage(0); // Post message to quit application
				return 0;
    
	} // end of switch(message)

    return DefWindowProc(hwnd, message, wparam, lparam);
}