Exemplo n.º 1
0
void 
GatherOutPut_ls(FILE *fp)
{
	char *line = NULL;
	void *new_space;
	int y = 0, is_expand = 0;
	char type[32];
	char size[32];

	line = (char *)malloc(sizeof(char) * LS_LINELEN);
	if(line == NULL)
		T_ERR("cannot malloc space for line");
	
	lsview = malloc(sizeof(struct LS_view));
	lsview->fileinfo =(struct fileinfo *)malloc(sizeof(struct fileinfo) * 128);
	if(lsview->fileinfo == NULL)
		T_ERR("cannot malloc space for lsview");
	lsview->fileno = 0;
	
	while(fgets(line,LS_LINELEN,fp) != NULL)
	{
		if(y == 0){  /*ignore the total line*/
			y++;
			continue;
		}
		GenerateFileInfo(line);
		lsview->fileno++;
		if(is_expand == 0 && lsview->fileno > 128)
		{	
			new_space = realloc(lsview->fileinfo, sizeof(struct fileinfo) * 128);	
			if(new_space == NULL)
				T_ERR("cannot realloc more space for lsview");
			lsview->fileinfo =(struct fileinfo *) new_space;
			is_expand = 1;
		}
	}
	/*when all the input is saved into*/
	Draw_LS_OutPut();
	refresh();
}
//--------------------------------------------------------------------
// @mfunc Initialization routine, opens file specified and creates
// buffers
//
// @rdesc BOOL
//      @flag S_OK | Succeeded
//      @flag E_FAIL | Failed to Initialize
//
BOOL CParseInitFile::Init(WCHAR* pwszFileName)
{
	//memory allocated in the ctor
	ASSERT(m_pvInput);
	ASSERT(pwszFileName);

	TRACE_CALL(L"PRIVLIB: CParseInitFile::Init.\n");

	// convert to ANSI
	m_pszFileName = (CHAR*)PROVIDER_ALLOC(wcslen(pwszFileName) + sizeof(CHAR));
	ASSERT(m_pszFileName);
	ConvertToMBCS(pwszFileName, m_pszFileName, (int)(wcslen(pwszFileName) + sizeof(CHAR)));
	
    //Open the File (allow share_read mode)
#if (_MSC_VER >= 1330) && !defined (_NT_TOOLS)
	open(m_pszFileName, ios::in | ios::_Nocreate);
#else
	open(m_pszFileName, ios::in | ios::nocreate, 05000/*filebuf::sh_read*/);
#endif


    if(!is_open())
	{
		odtLog << L"ERROR:  Unable to open or find INI <File:" << m_pszFileName << ">" << ENDL;
        return FALSE;
	}
	
	//set mode filebuf::binary, so there is no translation of 
	//special characters, expecially line-feeds and carrigae returns...
//	setmode(0x4000/*filebuf::text*/);
	
	// Obtain the Column Names, Data Types,
    // for each of the rows
    if(!GenerateFileInfo())
        return FALSE;

	return TRUE;
}