示例#1
0
CPVT_FloatRect CTypeset::Typeset() {
  ASSERT(m_pVT);
  m_pSection->m_LineArray.Empty();
  SplitLines(TRUE, 0.0f);
  m_pSection->m_LineArray.Clear();
  OutputLines();
  return m_rcRet;
}
示例#2
0
文件: Console.cpp 项目: noah-/d2bs
void Console::Draw(void) {
    static DWORD count = GetTickCount();
    EnterCriticalSection(&Vars.cConsoleSection);
    if (IsVisible()) {
        POINT size = GetScreenSize();
        int xsize = size.x;
        int ysize = size.y;
        size = CalculateTextLen("@", Vars.dwConsoleFont);
        int charwidth = size.x;
        int charheight = max(12, size.y / 2 + 2);
        // the default console height is 30% of the screen size
        int height = ((int)(((double)ysize) * .3) / charheight) * charheight + charheight;
        lineWidth = xsize - (2 * charwidth);
        lineCount = height / charheight;

        int cmdsize = 0;
        int cmdlines = 0;
        std::list<std::wstring> cmdsplit;
        if (IsEnabled()) {
            std::wstring cmdstr = cmd.str();
            if (cmdstr.length() > 0) {
                SplitLines(cmdstr, Console::MaxWidth(), L' ', cmdsplit);
                cmdsize = CalculateTextLen(cmdsplit.back().c_str(), Vars.dwConsoleFont).x;
                cmdlines += cmdsplit.size() - 1;
            }
        }

        Console::height = height + (cmdlines * charheight) + 6;
        // draw the box large enough to hold the whole thing
        D2GFX_DrawRectangle(0, 0, xsize, Console::height, 0xdf, 0);

        std::deque<std::wstring>::reverse_iterator it = lines.rbegin();
        if (scrollIndex == 0 && lines.size() == lineCount && IsEnabled()) // handle index 0, top of console
            it++;

        for (int i = lineCount - (int)IsEnabled(); i > 0 && it != lines.rend(); i--, it++)
            myDrawText(it->c_str(), charwidth, 4 + (i * charheight), 0, Vars.dwConsoleFont);

        if (IsEnabled()) {
            if (cmdsplit.size() > 0) {
                int dy = height + 3;
                for (std::list<std::wstring>::iterator it2 = cmdsplit.begin(); it2 != cmdsplit.end(); it2++, dy += charheight)
                    myDrawText(it2->c_str(), charwidth, dy, 0, Vars.dwConsoleFont);
            }

            myDrawText(L">", 1, Console::height - 3, 0, Vars.dwConsoleFont);
            DWORD tick = GetTickCount();
            if ((tick - count) < 600) {
                int lx = cmdsize + charwidth, ly = Console::height - (charheight / 3);
                D2GFX_DrawRectangle(lx, ly, lx + ((charwidth * 2) / 3), ly + 2, 0xFF, 0x07);
            } else if ((tick - count) > 1100)
                count = tick;
        }
    }
    LeaveCriticalSection(&Vars.cConsoleSection);
}
示例#3
0
文件: Console.cpp 项目: noah-/d2bs
void Console::AddLine(std::wstring line) {
    EnterCriticalSection(&Vars.cConsoleSection);
    std::list<std::wstring> buf;
    SplitLines(line, Console::MaxWidth(), L' ', buf);
    for (std::list<std::wstring>::iterator it2 = buf.begin(); it2 != buf.end(); it2++) {
        history.push_back(*it2);
    }

    while (history.size() > 300) // set history cap at 300
        history.pop_front();

    if (Vars.bLogConsole)
        LogNoFormat(line.c_str());

    scrollIndex = history.size() < lineCount ? 0 : history.size() - lineCount;
    Console::UpdateLines();

    LeaveCriticalSection(&Vars.cConsoleSection);
}
示例#4
0
bool HttpHeaders::Parse(const StringPiece& data, int* error)
{
    int error_placeholder;
    if (error == NULL)
        error = &error_placeholder;

    m_headers.clear();

    std::vector<std::string> lines;
    SplitLines(data, &lines);

    if (lines.size() < 1 || !lines[lines.size() - 1].empty()) {
        *error = HttpMessage::ERROR_MESSAGE_NOT_COMPLETE;
        return false;
    }

    // Skip the head line and the last line(empty but '\n')
    for (int i = 0; i < static_cast<int>(lines.size() - 1); ++i) {
        std::string::size_type pos = lines[i].find(":");
        if (pos != std::string::npos) {
            m_headers.push_back(std::pair<std::string, std::string>(
                    StringTrim(lines[i].substr(0, pos)),
                    StringTrim(lines[i].substr(pos + 1))));
        } else {
            if (!lines[i].empty()) {
                VLOG(3) << "Invalid http header" << lines[i] << ", ignore";
            } else {
                *error = HttpMessage::ERROR_FIELD_NOT_COMPLETE;
                m_headers.clear();
                return false;
            }
        }
    }

    *error = HttpMessage::SUCCESS;
    return true;
}
示例#5
0
void CDlgInput::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);

	if ( GetDlgItem(IDC_LABEL) == NULL || ! ::IsWindow( GetDlgItem(IDC_LABEL)->m_hWnd ) ) return;

	CRect pos;
    int   infoBottom;

	GetDlgItem( IDC_LABEL )->GetWindowRect( &pos );
	ScreenToClient( pos );
	if ( m_Label.IsEmpty() )
	{
		GetDlgItem( IDC_LABEL )->ShowWindow( SW_HIDE );
		infoBottom = 0;
	}
	else
	{
		HDC dc = ::GetWindowDC( GetDlgItem(IDC_LABEL)->m_hWnd );
		CStrArray lines;
		if ( m_Label.IsEmpty() )
		{
			lines.Add( L"" );
			GetDlgItem( IDC_LABEL )->SetWindowText(L"");
		}
		else
		{
			SplitLines( dc, (LPCTSTR)m_Label, lines, pos.Width() );
			CString infoWrapped;
			for ( int i=0; i<lines.GetSize(); i++ )
			{
				infoWrapped += lines[i];
				if ( i<lines.GetSize()-1 ) infoWrapped += "\n";
			}
			GetDlgItem( IDC_LABEL )->SetWindowText(infoWrapped);
			//UpdateData(FALSE);
		}
		SIZE size;
		GetTextExtentPoint( dc, L"W", 1, &size );
		pos.top   = 4;
		pos.left  = 4;
		pos.right = cx - 8;
		infoBottom = pos.bottom = pos.top + size.cy * lines.GetSize();
		::ReleaseDC( GetDlgItem(IDC_LABEL)->m_hWnd, dc );
		GetDlgItem( IDC_LABEL )->MoveWindow( pos );
		GetDlgItem( IDC_LABEL )->Invalidate();
	}


	//GetDlgItem(IDC_LABEL)->GetWindowRect( &pos );
	//ScreenToClient( &pos );
	//GetDlgItem(IDC_LABEL)->MoveWindow( &pos );

	if ( Multiline )
	{
		int height;

		GetDlgItem(IDOK)->GetWindowRect( &pos );
		ScreenToClient( &pos );
		height = pos.bottom-pos.top;
		pos.top = cy - height - 4;
		pos.bottom = cy - 4;
		pos.left  = 4;
		pos.right = cx/2 - 4;
		GetDlgItem(IDOK)->MoveWindow( &pos );

		GetDlgItem(IDCANCEL)->GetWindowRect( &pos );
		ScreenToClient( &pos );
		pos.top = cy - height - 4;
		pos.bottom = cy - 4;
		pos.left = cx/2 + 4;
		pos.right = cx - 8;
		GetDlgItem(IDCANCEL)->MoveWindow( &pos );

		GetDlgItem(IDC_EDIT)->GetWindowRect( &pos );
		ScreenToClient( &pos );
		pos.top   = infoBottom + 4;
		pos.bottom = cy - height - 8;
		pos.left  = 4;
		pos.right = cx - 8;
		GetDlgItem(IDC_EDIT)->MoveWindow( &pos );
	}
	else
	{
		int height;

		GetDlgItem(IDC_EDIT)->GetWindowRect( &pos );
		ScreenToClient( &pos );
		height = pos.Height();
		pos.top   = infoBottom + 4;
		pos.bottom = pos.top + height;
		pos.left  = 4;
		pos.right = cx - 8;
		GetDlgItem(IDC_EDIT)->MoveWindow( &pos );
		infoBottom = pos.bottom;

		((CEdit*)GetDlgItem(IDC_EDIT))->ModifyStyle( ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL, 0 );
#ifndef DESKTOP
		OSVERSIONINFO ver;
		GetVersionEx( &ver );
		if ( ver.dwMajorVersion < 5 )
		{
#endif
		GetDlgItem(IDOK)->GetWindowRect( &pos );
		ScreenToClient( &pos );
		height = pos.bottom-pos.top;
		pos.top   = infoBottom + 4;
		pos.bottom = pos.top + height;
		pos.left  = 4;
		pos.right = cx/2 - 4;
		GetDlgItem(IDOK)->MoveWindow( &pos );

		GetDlgItem(IDCANCEL)->GetWindowRect( &pos );
		ScreenToClient( &pos );
		pos.top   = infoBottom + 4;
		pos.bottom = pos.top + height;
		pos.left = cx/2 + 4;
		pos.right = cx - 8;
		GetDlgItem(IDCANCEL)->MoveWindow( &pos );
#ifndef DESKTOP
		}
		else
		{
			GetDlgItem( IDOK )->ShowWindow( SW_HIDE );
			GetDlgItem( IDCANCEL )->ShowWindow( SW_HIDE );
		}
#endif


		//((CEdit*)GetDlgItem(IDC_EDIT))->ModifyStyleEx( 0, ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL );

#ifdef DESKTOP
		CRect client;
		GetWindowRect( &pos );
		GetClientRect( &client );
		if ( infoBottom + height + 8 != client.Height() )
		{
			pos.bottom = pos.top + pos.Height() - client.Height() + infoBottom + height + 8;
			MoveWindow( &pos );
		}
#endif
	}
	
	((CEdit*)GetDlgItem(IDC_EDIT))->SetSel(0,0,FALSE);	
}
示例#6
0
int main(int argc, char **argv)
{
	GSM_Debug_Info *debug_info;
	GSM_Phone_ATGENData *Priv;
	GSM_Phone_Data *Data;
	unsigned char buffer[BUFFER_SIZE];
	FILE *f;
	size_t len;
	GSM_StateMachine *s;
	GSM_Protocol_Message msg;
	GSM_Error error;
	GSM_NetworkInfo	NetworkInfo;

	/* Check parameters */
	if (argc != 2) {
		printf("Not enough parameters!\nUsage: at-creg-reply comm.dump\n");
		return 1;
	}

	/* Open file */
	f = fopen(argv[1], "r");
	if (f == NULL) {
		printf("Could not open %s\n", argv[1]);
		return 1;
	}

	/* Read data */
	len = fread(buffer, 1, sizeof(buffer) - 1, f);
	if (!feof(f)) {
		printf("Could not read whole file %s\n", argv[1]);
		fclose(f);
		return 1;
	}
	/* Zero terminate data */
	buffer[len] = 0;

	/* Close file */
	fclose(f);

	/* Configure state machine */
	debug_info = GSM_GetGlobalDebug();
	GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
	GSM_SetDebugLevel("textall", debug_info);

	/* Allocates state machine */
	s = GSM_AllocStateMachine();
	test_result(s != NULL);
	debug_info = GSM_GetDebug(s);
	GSM_SetDebugGlobal(TRUE, debug_info);

	/* Initialize AT engine */
	Data = &s->Phone.Data;
	Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL);
	Data->NetworkInfo = &NetworkInfo;
  	Data->RequestID = ID_GetNetworkInfo;
	Priv = &s->Phone.Data.Priv.ATGEN;
	Priv->ReplyState = AT_Reply_OK;
	Priv->SMSMode = SMS_AT_PDU;
	Priv->Charset = AT_CHARSET_UCS2;

	/* Init message */
	msg.Type = 0;
	msg.Length = len;
	msg.Buffer = buffer;
	SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);

	/* Parse it */
	error = ATGEN_ReplyGetNetworkLAC_CID(msg, s);

	/* This is normally done by ATGEN_Terminate */
	FreeLines(&Priv->Lines);
	GetLineString(NULL, NULL, 0);

	/* Free state machine */
	GSM_FreeStateMachine(s);

	gammu_test_result(error, "ATGEN_ReplyGetCNMIMode");

	printf("Network: %d\nLAC: %s\nCID: %s\n", NetworkInfo.State, NetworkInfo.LAC, NetworkInfo.CID);

	return 0;
}
bool process_file(const char* file_name, bool is_std_file,
	Array* file_stack, Array* file_records,
	DoubleList* lines, DoubleList* file_binarys)
{
#if MG_PLATFORM_WINDOWS
	const char* header_search_dirs[] = {
		"D:/Microsoft Visual Studio 12.0/VC/crt/src",
		"D:/Microsoft Visual Studio 12.0/VC/include",
		"D:/Microsoft Visual Studio 12.0/VC/atlmfc/include",
		"C:/Program Files (x86)/Windows Kits/8.1/Include/um",
		"C:/Program Files (x86)/Windows Kits/8.1/Include/shared",
		"C:/Program Files (x86)/Windows Kits/8.1/Include/winrt",
	};
#else
	const char* header_search_dirs[] = {
		"/usr/include",
		"/usr/include/x86_64-linux-gnu",
		"/usr/include/linux",
		"/usr/local/include",
		"/usr/lib/gcc/x86_64-linux-gnu/4.8/include",
	};
#endif
	char* bytes = NULL;
	long byte_num = 0;
	size_t std_search_path_num = sizeof(header_search_dirs) / sizeof(char*);
	size_t index = 0;
	size_t file_path_len;
	char* p_file_path;
	char** pp_file_path;
	char file_path[MG_MAX_PATH];
	bool is_file_exist = false;

	// check file name length
	if (strlen(file_name) == 0)
	{
		MLOG("file name is null\n");
		MASSERT_MSG(0, "file name is null!\n");
		return false;
	}

	// ensure file is exist
	memset(file_path, 0, MG_MAX_PATH);
	sprintf_s(file_path, MG_MAX_PATH - 1, "%s", file_name);
	is_file_exist = File_IsExist(file_path);
	if (!is_file_exist)
	{
		if (is_std_file)
		{
			// try absolute path in std folder
			is_file_exist = SearchInStdFolder(file_name, std_search_path_num, header_search_dirs, file_path);

			// try absolute path in current process path
			if (!is_file_exist)
			{
				File_GetAbsolutePath(file_name, file_path);
				is_file_exist = File_IsExist(file_path);
			}
		}
		else
		{
			// try absolute path in current process path
			File_GetAbsolutePath(file_name, file_path);
			is_file_exist = File_IsExist(file_path);

			// try absolute path in std folder
			if (!is_file_exist)
			{
				is_file_exist = SearchInStdFolder(file_name, std_search_path_num, header_search_dirs, file_path);
			}
		}

		if (!is_file_exist)
		{
			MLOG("file %s is not exsit\n", file_name);
			MASSERT_MSG(0, "file is not exsit\n");
			return false;
		}
	}

	// detect file repeat in one step
	for (index = 0; index < ArrayUsed(file_stack); ++index)
	{
		char** p_address = (char**)ArrayGet(file_stack, index);
		if (strncmp(*p_address, file_path, MG_MAX_PATH) == 0)
		{
			return false;
		}
	}

	// detect file repeat in all step
	for (index = 0; index < ArrayUsed(file_records); ++index)
	{
		char** p_address = (char**)ArrayGet(file_records, index);
		if (strncmp(*p_address, file_path, MG_MAX_PATH) == 0)
		{
			return true;
		}
	}

	// read file
	if (!File_Read(file_path, &bytes, &byte_num))
	{
		MLOG("file %s is not exsit\n", file_path);
		MASSERT_MSG(0, "failed in read file\n");
		return false;
	}

	// push file path into file stack
	file_path_len = strlen(file_path) + 1;
	p_file_path = (char*)malloc(sizeof(char) * file_path_len);
	memcpy(p_file_path, file_path, file_path_len);
	ArrayPush(file_stack, &p_file_path);

	// push file path into file records
	p_file_path = (char*)malloc(sizeof(char) * file_path_len);
	memcpy(p_file_path, file_path, file_path_len);
	ArrayPush(file_records, &p_file_path);

	// save bytes
	DoubleListAdd(file_binarys, &bytes);
	if (byte_num == 0)
	{
		return true;
	}

	// split into lines
	SplitLines(bytes, lines);

	// parse each line
	if (!parse_lines(file_stack, file_records, lines, file_binarys))
	{
		MASSERT_MSG(0, "failed in parse lines");
		MLOG("failed in parse lines");
		return false;
	}

	// pop this file
	pp_file_path = ArrayGet(file_stack, ArrayUsed(file_stack) - 1);
	MASSERT(strncmp(*pp_file_path, p_file_path, MG_MAX_PATH) == 0);
	if (strncmp(*pp_file_path, p_file_path, MG_MAX_PATH) != 0)
	{
		return false;
	}
	free(*pp_file_path);
	ArrayPop(file_stack);

	return true;
}
示例#8
0
文件: Console.cpp 项目: ds-hwang/d2bs
void Console::Draw(void)
{
	static DWORD count = 0;
	EnterCriticalSection(&Vars.cConsoleSection);
	if(IsVisible())
	{
		POINT size = GetScreenSize();
		int xsize = size.x;
		int ysize = size.y;
		// the default console height is 30% of the screen size
		int height = (int)(((double)ysize)*.3);
		size = CalculateTextLen(">", 0);
		int charsize = size.x;
		int charheight = size.y-10;
		int cx = charsize+9;
		int linelen = 115;
		Console::height = height;

		int cmdsize = CalculateTextLen(cmd.str().c_str(), 0).x;
		if((cmdsize/xsize) > 0)
			Console::height += (cmdsize/xsize)*charheight + 1;

		// draw the box large enough to hold the whole thing
		D2GFX_DrawRectangle(0, 0, xsize, Console::height, 0xdf, 0);

		std::deque<std::string>::reverse_iterator it = lines.rbegin();
		for(int i = lineCount-1; i >= 0 && it != lines.rend(); i--, it++)
		{
			if(CalculateTextLen(it->c_str(), 0).x > (xsize - (2+charheight)*2))
			{
				std::list<std::string> buf;
				SplitLines(*it, linelen, ' ', buf);
				for(std::list<std::string>::iterator it = buf.begin(); it != buf.end(); it++)
					myDrawText(it->c_str(), 2+charheight, 2+charheight+((i--)*charheight), 0, 0);
			} else
				myDrawText(it->c_str(), 2+charheight, 2+charheight+(i*charheight), 0, 0);
		}

		if(IsEnabled())
		{
			myDrawText(">", 1, height, 0, 0);
			int lx = cx + cmdsize - charsize + 5,
				ly = height-charheight;
			if(count % 30)
				D2GFX_DrawLine(lx, ly, lx, height-2, 0xFF, 0xFF);

			std::string cmdstr = cmd.str();
			if(cmdstr.length() > 0)
			{
				if((cmdsize/xsize) > 0)
				{
					std::list<std::string> lines;
					SplitLines(cmdstr, linelen, ' ', lines);
					int i = 0;
					for(std::list<std::string>::iterator it = lines.begin(); it != lines.end(); it++, i++)
						myDrawText(it->c_str(), charsize+5, height+(charheight*i)+1, 0, 0);
				} else
					myDrawText(cmdstr.c_str(), charsize+5, height+1, 0, 0);
			}
		}
	}
	LeaveCriticalSection(&Vars.cConsoleSection);

	count++;
}
示例#9
0
size_t HttpHeaders::Parse(const StringPiece& data, int* error)
{
    int error_placeholder;
    if (error == NULL)
        error = &error_placeholder;

    // Starts with empty line means empty headers.
    if (StringStartsWith(data, "\n") || StringStartsWith(data, "\r\n")) {
        m_headers.clear();
        return (data[0] == '\r') + 1; // sizeof \n or \r\n
    }

    size_t end_pos;
    size_t tail_size;
    if ((end_pos = data.find("\r\n\r\n")) != std::string::npos) {
        tail_size = 4;
    } else if ((end_pos = data.find("\n\n")) != std::string::npos) {
        tail_size = 2;
    } else {
        *error = HttpMessage::ERROR_MESSAGE_NOT_COMPLETE;
        return 0;
    }

    std::vector<StringPiece> lines;
    SplitLines(data.substr(0, end_pos + tail_size), &lines);

    if (lines.empty()) {
        *error = HttpMessage::ERROR_MESSAGE_NOT_COMPLETE;
        return 0;
    }

    m_headers.clear();

    // Skip the head line and the last line(empty but '\n')
    for (int i = 0; i < static_cast<int>(lines.size() - 1); ++i) {
        StringPiece line = lines[i];
        size_t pos = line.find(':');
        if (pos != StringPiece::npos) {
            StringPiece name = line.substr(0, pos);
            StringPiece value = line.substr(pos + 1);
            StringTrim(&name);
            StringTrim(&value);
            // Push an empty element and modify it to avoid copy.
            m_headers.push_back(std::pair<std::string, std::string>());
            std::pair<std::string, std::string> &header = m_headers.back();
            name.copy_to_string(&header.first);
            value.copy_to_string(&header.second);
        } else {
            if (!lines[i].empty()) {
                VLOG(3) << "Invalid http header" << lines[i] << ", ignore";
            } else {
                *error = HttpMessage::ERROR_FIELD_NOT_COMPLETE;
                m_headers.clear();
                return 0;
            }
        }
    }

    *error = HttpMessage::SUCCESS;
    return end_pos + tail_size;
}
示例#10
0
bool FXmlFile::LoadFile(const FString& InFile, EConstructMethod::Type ConstructMethod)
{
	// Remove any file stuff if it already exists
	Clear();

	// So far no error (Early so it can be overwritten below by errors)
	ErrorMessage = NSLOCTEXT("XmlParser", "LoadSuccess", "XmlFile was loaded successfully").ToString();

	TArray<FString> Input;
	if(ConstructMethod == EConstructMethod::ConstructFromFile)
	{
		// Create file reader
		TUniquePtr<FArchive> FileReader(IFileManager::Get().CreateFileReader(*InFile));
		if(!FileReader)
		{
			ErrorMessage = NSLOCTEXT("XmlParser", "FileLoadFail", "Failed to load the file").ToString();
			ErrorMessage += TEXT("\"");
			ErrorMessage += InFile;
			ErrorMessage += TEXT("\"");
			return false;
		}

		// Create buffer for file input
		uint32 BufferSize = FileReader->TotalSize();
		void* Buffer = FMemory::Malloc(BufferSize);
		FileReader->Serialize(Buffer, BufferSize);

		// Parse file buffer into an array of lines
		if (!FindCharSizeAndSplitLines(Input, Buffer, BufferSize))
		{
			ErrorMessage = NSLOCTEXT("XmlParser", "InvalidFormatFail", "Failed to parse the file (Unsupported character encoding)").ToString();
			ErrorMessage += TEXT("\"");
			ErrorMessage += InFile;
			ErrorMessage += TEXT("\"");
			return false;
		}

		// Release resources
		FMemory::Free(Buffer);
	}
	else
	{
		// Parse input buffer into an array of lines
		SplitLines(Input, *InFile, *InFile + InFile.Len());
	}

	// Pre-process the input
	PreProcessInput(Input);

	// Tokenize the input
	TArray<FString> Tokens = Tokenize(Input);

	// Parse the input & create the nodes
	CreateNodes(Tokens);

	// All done with creation, set up necessary information
	if(bFileLoaded == true)
	{
		if(ConstructMethod == EConstructMethod::ConstructFromFile)
		{
			LoadedFile = InFile;
		}
	}
	else
	{
		LoadedFile = TEXT("");
		RootNode = nullptr;
	}

	// Now check the status flag of the creation. It may have actually failed, but given us a 
	// partially created representation
	if(bCreationFailed)
	{
		Clear();
	}

	return bFileLoaded;
}
示例#11
0
CFX_SizeF CTypeset::GetEditSize(FX_FLOAT fFontSize) {
  ASSERT(m_pSection);
  ASSERT(m_pVT);
  SplitLines(FALSE, fFontSize);
  return CFX_SizeF(m_rcRet.Width(), m_rcRet.Height());
}
示例#12
0
int main(int argc, char **argv)
{
	GSM_Debug_Info *debug_info;
	GSM_Phone_ATGENData *Priv;
	GSM_Phone_Data *Data;
	unsigned char buffer[BUFFER_SIZE];
	FILE *f;
	size_t len;
	GSM_StateMachine *s;
	GSM_Protocol_Message msg;
	GSM_Error error;
	GSM_MultiSMSMessage sms;
	GSM_SMSDConfig *smsd;
#if 0
	GSM_SMS_Backup bkp;
#endif

	/* Check parameters */
	if (argc != 2 && argc != 3) {
		printf("Not enough parameters!\nUsage: sms-at-parse comm.dump [PDU|TXT|TXTDETAIL]\n");
		return 1;
	}

	/* Open file */
	f = fopen(argv[1], "r");
	if (f == NULL) {
		printf("Could not open %s\n", argv[1]);
		return 1;
	}

	/* Read data */
	len = fread(buffer, 1, sizeof(buffer) - 1, f);
	if (!feof(f)) {
		printf("Could not read whole file %s\n", argv[1]);
		fclose(f);
		return 1;
	}

	smsd = SMSD_NewConfig("test");
	/* Zero terminate data */
	buffer[len] = 0;

	/* Close file */
	fclose(f);

	/* Configure state machine */
	debug_info = GSM_GetGlobalDebug();
	GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
	GSM_SetDebugLevel("textall", debug_info);

	/* Allocates state machine */
	s = GSM_AllocStateMachine();
	test_result(s != NULL);

	debug_info = GSM_GetDebug(s);
	GSM_SetDebugGlobal(TRUE, debug_info);

	/* Initialize AT engine */
	Data = &s->Phone.Data;
	Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL);
	Priv = &s->Phone.Data.Priv.ATGEN;
	Priv->ReplyState = AT_Reply_OK;
	Priv->Charset = AT_CHARSET_GSM;
	if (argc == 3 && strcmp(argv[2], "TXT") == 0) {
		Priv->SMSMode = SMS_AT_TXT;
		Priv->SMSTextDetails = FALSE;
	} else if (argc == 3 && strcmp(argv[2], "TXTDETAIL") == 0) {
		Priv->SMSMode = SMS_AT_TXT;
		Priv->SMSTextDetails = TRUE;
	} else {
		Priv->SMSMode = SMS_AT_PDU;
	}

	/* Init message */
	msg.Type = 0;
	msg.Length = len;
	msg.Buffer = buffer;
	SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);

	/* Pointer to store message */
	s->Phone.Data.GetSMSMessage = &sms;

	/* Parse it */
	error = ATGEN_ReplyGetSMSMessage(&msg, s);
	sms.SMS[0].Memory = MEM_SM;

#if 0
	bkp.SMS[0] = &sms.SMS[0];
	bkp.SMS[1] = NULL;

	GSM_AddSMSBackupFile("/tmp/back", &bkp);
#endif

	/* Display message */
	if (error == ERR_NONE) {
		DisplayMultiSMSInfo(&sms, FALSE, TRUE, NULL, NULL);
		DisplayMultiSMSInfo(&sms, TRUE, TRUE, NULL, NULL);
		printf("Parts: %d, count: %d, ID16: %d, ID8: %d\n", sms.SMS[0].UDH.AllParts, sms.Number, sms.SMS[0].UDH.ID16bit, sms.SMS[0].UDH.ID8bit);

		SMSD_RunOnReceiveEnvironment(&sms, smsd, "1");
	}

	/* This is normally done by ATGEN_Terminate */
	FreeLines(&Priv->Lines);
	GetLineString(NULL, NULL, 0);

	/* Free state machine */
	GSM_FreeStateMachine(s);

	gammu_test_result(error, "ATGEN_ReplyGetSMSMessage");

	return 0;
}
示例#13
0
int main(int argc, char **argv)
{
	GSM_Debug_Info *debug_info;
	GSM_Phone_ATGENData *Priv;
	GSM_Phone_Data *Data;
	unsigned char buffer[BUFFER_SIZE];
	FILE *f;
	size_t len;
	GSM_StateMachine *s;
	GSM_Protocol_Message msg;
	GSM_Error error;
	GSM_SMSC SMSC;

	/* Check parameters */
	if (argc != 2) {
		printf("Not enough parameters!\nUsage: get-smsc-at comm.dump\n");
		return 1;
	}

	/* Open file */
	f = fopen(argv[1], "r");
	test_result(f != NULL);

	/* Read data */
	len = fread(buffer, 1, sizeof(buffer) - 1, f);
	test_result(feof(f));

	/* Zero terminate data */
	buffer[len] = 0;

	/* Close file */
	fclose(f);

	/* Configure state machine */
	debug_info = GSM_GetGlobalDebug();
	GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
	GSM_SetDebugLevel("textall", debug_info);

	/* Allocates state machine */
	s = GSM_AllocStateMachine();
	test_result(s != NULL);
	debug_info = GSM_GetDebug(s);
	GSM_SetDebugGlobal(TRUE, debug_info);
	GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
	GSM_SetDebugLevel("textall", debug_info);

	/* Initialize AT engine */
	Data = &s->Phone.Data;
	Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL);
	Priv = &s->Phone.Data.Priv.ATGEN;
	Priv->ReplyState = AT_Reply_OK;
	Priv->SMSMode = SMS_AT_PDU;
	Priv->Charset = AT_CHARSET_UCS2;

	/* Init message */
	msg.Type = 0;
	msg.Length = len;
	msg.Buffer = buffer;
	SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);

	/* Pointer to store message */
	s->Phone.Data.SMSC = &SMSC;

	/* Parse it */
	error = ATGEN_ReplyGetSMSC(msg, s);

	/* This is normally done by ATGEN_Terminate */
	FreeLines(&Priv->Lines);
	GetLineString(NULL, NULL, 0);

	/* Free state machine */
	GSM_FreeStateMachine(s);

	printf("%s\n", GSM_ErrorString(error));

	return (error == ERR_NONE) ? 0 : 1;
}