MiscSupport.h
资源名称:warftpd.zip [点击查看]
上传用户:surprise9
上传日期:2007-01-04
资源大小:426k
文件大小:10k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // This is part of the WAR SOFTWARE SERIES initiated by Jarle Aase
- // Copyright 1996 by Jarle Aase. All rights reserved.
- // See the "War Software Series Licende Agreement" for details concerning
- // use and distribution.
- // ---
- // This source code, executables and programs containing source code or
- // binaries or proprietetary technology from the War Software Series are
- // NOT alloed used, viewed or tested by any governmental agencies in
- // any countries. This includes the government, departments, police,
- // military etc.
- // ---
- // This file is intended for use with Tab space = 2
- // Created and maintained in MSVC Developer Studio
- // ---
- // NAME : MiscSupport.h
- // PURPOSE : Misc. support functions
- // PROGRAM :
- // DATE : Sept. 21 1996
- // AUTHOR : Jarle Aase
- // ---
- // REVISION HISTORY
- //
- #ifndef __MISCSUPPORTH
- #define __MISCSUPPORTH
- ////////////////////////////////////////////////////////////////////////////////
- // Some basic datatypes
- typedef unsigned __int64 FLEN;
- #define FLEN_MAX ULONG_MAX
- #define INVALID_FLEN_VALUE (FLEN)(0xffffffffffffffff)
- typedef int USER;
- #define INVALID_USER_VALUE 0
- /////////////////////////////////////////////////////////////////////////////////
- // 64 bit interger macros
- #define HIDWORD(i64bit) (DWORD)((i64bit >> 32) & 0xffffffff)
- #define LODWORD(i64bit) (DWORD)(i64bit & 0xffffffff)
- ////////////////////////////////////////////////////////////////////////////////
- // Generic data manipulation
- class DLL_WAR_SOFTWARE_ CLinkedListItem : public CObject
- {
- DECLARE_DYNCREATE(CLinkedListItem)
- public:
- CLinkedListItem();
- ~CLinkedListItem();
- CLinkedListItem *m_Next;
- CLinkedListItem *m_Prev;
- LPVOID m_Ptr; // Data
- };
- class DLL_WAR_SOFTWARE_ CLinkedList : public CObject
- {
- DECLARE_DYNCREATE(CLinkedList)
- private:
- CLinkedListItem *m_First;
- CLinkedListItem *m_Last;
- protected:
- int m_NumItems; // Number of items in list
- public:
- CLinkedList();
- ~CLinkedList();
- virtual void Kill(); // KillAll + delete the this pointer
- virtual void KillAll(); // Kill all items, including the pointer.
- CLinkedListItem *First();
- CLinkedListItem *Last();
- LPVOID FirstPtr();
- LPVOID LastPtr();
- LPVOID Ptr(CLinkedListItem *Item);
- CLinkedListItem *Next(CLinkedListItem *Item);
- CLinkedListItem *Prev(CLinkedListItem *Item);
- CLinkedListItem *FindPtr(LPVOID Ptr);
- BOOL DeletePtr(LPVOID Ptr);
- void DeleteItem(CLinkedListItem *Item);
- void AddFirst(LPVOID Ptr);
- void AddLast(LPVOID Ptr);
- void AddPtr(CLinkedListItem *Next, CLinkedListItem *Prev, LPVOID Ptr);
- LPVOID GetAndDeleteFirst();
- LPVOID GetAndDeleteLast();
- void Sort(int (*SortFunc)(const void *, const void *));
- int GetItemCount() {return m_NumItems;}
- void Empty();
- void Cat(CLinkedList& List);
- void operator = (CLinkedList &List);
- void operator += (CLinkedList &List) {Cat(List);}
- };
- // Simple class to store a number of items, and trash the oldest whhen
- // the number is reached.
- class DLL_WAR_SOFTWARE_ CHistory : public CLinkedList
- {
- public:
- void Add(LPVOID Ptr, int MaxItems, BOOL DeletePtr = TRUE);
- void Add(LPCSTR Ptr, int MaxItems);
- virtual void KillAll(); // Kill all items, including the pointer.
- };
- // Support class for CLookupList
- class CLookupListItem : public CObject
- {
- public:
- LPSTR m_Name;
- DWORD m_Number;
- LPVOID m_Ptr;
- int m_DataType;
- public:
- CLookupListItem(LPVOID Ptr, DWORD NumSymbol, LPCSTR TextSymbol, int DataType);
- ~CLookupListItem();
- LPVOID Ptr() {return m_Ptr;}
- LPCSTR GetData(CString& cBuf);
- };
- // Simple class to store a pointer together with a name and a number that can
- // be used for lookup.
- class DLL_WAR_SOFTWARE_ CLookupList
- {
- private:
- CLinkedList m_List;
- public:
- ~CLookupList();
- void AddItem(LPVOID Ptr, DWORD NumSymbol, LPCSTR TextSymbol, int DataType);
- LPVOID Find(DWORD NumSymbol, LPCSTR TextSymbol);
- void DeleteItem(DWORD NumSymbol, LPCSTR TextSymbol);
- CLinkedListItem *First();
- CLinkedListItem *Next(CLinkedListItem *Item);
- CLookupListItem *LookupPtr(CLinkedListItem *Item);
- LPVOID Ptr(CLookupListItem *LookupItem);
- LPVOID Ptr(CLinkedListItem *LookupItem);
- LPCSTR GetData(CLinkedListItem *LookupItem, CString& cBuf);
- LPCSTR GetData(CLookupListItem *LookupItem, CString& cBuf);
- CLinkedListItem *FindItem(DWORD NumSymbol, LPCSTR TextSymbol);
- void KillAll();
- };
- ////////////////////////////////////////////////////////////////////////////////
- // Timer functions
- // CWarTimer
- // Used to test for millisecond based timers
- class DLL_WAR_SOFTWARE_ CWarTimer
- {
- public:
- DWORD m_TimerVal;
- public:
- CWarTimer(); // Initializes to current system tick
- void Reset(); // Set the internal value to current system tick
- BOOL TimeOut(DWORD Milliseconds); // Check for timeout
- DWORD TimeDiff(); // Difference in ms between the stored and the current time
- DWORD TimeDiff(DWORD Milliseconds); // // Difference in ms between the stored and the given time
- DWORD TimeLeft(DWORD Milliseconds); // Time left before timeout in ms
- };
- ////////////////////////////////////////////////////////////////////////////////
- // System query functions
- DLL_WAR_SOFTWARE_ BOOL IsNT();
- DLL_WAR_SOFTWARE_ LPCSTR OsName();
- DLL_WAR_SOFTWARE_ BOOL HasShell();
- ////////////////////////////////////////////////////////////////////////////////
- // CString derived class to handle va_list argList
- class DLL_WAR_SOFTWARE_ CWarString : public CString
- {
- public:
- void FormatVaList(LPCTSTR lpszFormat, va_list argList);
- void FormatCat(LPCTSTR lpszFormat, ...);
- int FormatCatV(LPCTSTR lpszFormat, va_list argList);
- };
- ////////////////////////////////////////////////////////////////////////////////
- // Safe string array
- DLL_WAR_SOFTWARE_ LPCSTR SafeStringIndexExp(LPCSTR File, int Line, LPCSTR *StrIndex, int Index, int Limit);
- #define SafeStringIndex(StrIndex, Index, Limit)
- SafeStringIndexExp(__FILE__, __LINE__, (LPCSTR *)StrIndex, Index, Limit)
- ////////////////////////////////////////////////////////////////////////////////
- // CCmdArgs
- // Used to handle command line arguments to other modules,
- // and arguments from the parser.
- class DLL_WAR_SOFTWARE_ CCmdArgs : public CObject
- {
- public:
- int m_argc;
- LPSTR *m_argv;
- int m_argc_max;
- BOOL IsReInitialized;
- public:
- CCmdArgs();
- CCmdArgs(LPCSTR Name, LPCSTR CommandLine, CCommandParser& Parser);
- ~CCmdArgs();
- void AssertValid();
- LPCSTR AddArg(LPCSTR Arg, int Len = 0);
- LPCSTR Arg(int Index);
- void PrepereNew();
- LPCSTR Insert(int Index, LPCSTR Arg, int Len = 0);
- LPCSTR Replace(int Index, LPCSTR Arg, int Len = 0);
- int operator = (CCmdArgs& Arg);
- LPCSTR operator [] (int n) {return Arg(n); }
- void operator += (LPCSTR Str) {AddArg(Str); }
- private:
- void Empty();
- void Initialize();
- void Check();
- };
- ////////////////////////////////////////////////////////////////////////////////
- // GetData() - return pointer (or value) for use in printf.
- // Returns a copy of the data stored in cBuf.
- DLL_WAR_SOFTWARE_ LPCSTR GetData(LPVOID Ptr, int DataType, CString& cBuf);
- DLL_WAR_SOFTWARE_ BOOL PutData(LPVOID Ptr, int DataType, LPCSTR Value);
- ////////////////////////////////////////////////////////////////////////////////
- // GetlastErrorText()
- DLL_WAR_SOFTWARE_ CString GetLastErrorText();
- DLL_WAR_SOFTWARE_ CString GetLastErrorText(int Errno);
- ////////////////////////////////////////////////////////////////////////////////
- // MySscanf()
- DLL_WAR_SOFTWARE_ int MySscanf(LPCSTR buf, LPCSTR Format, ...);
- ////////////////////////////////////////////////////////////////////////////////
- // PatternMatchesName()
- DLL_WAR_SOFTWARE_ BOOL PatternMatchesName(LPCSTR OrgName, LPCSTR Pattern);
- ////////////////////////////////////////////////////////////////////////////////
- // LoadString()
- DLL_WAR_SOFTWARE_ LPCSTR LoadString(UINT nID, CString& cBuf);
- ////////////////////////////////////////////////////////////////////////////////
- // LoGetLineParam()
- DLL_WAR_SOFTWARE_ LPCSTR GetLineParam(LPCSTR Tag, CString &cValue, LPCSTR Default);
- ////////////////////////////////////////////////////////////////////////////////
- // ExpandStringMacros()
- class CDaemonStatus;
- DLL_WAR_SOFTWARE_ LPCSTR ExpandStringMacros(LPCSTR Str, CString& cValue, CDaemonStatus *Stat = NULL);
- ////////////////////////////////////////////////////////////////////////////////
- // ExpandStringMacros()
- DLL_WAR_SOFTWARE_ BOOL ExpandPath(LPCSTR Path);
- ////////////////////////////////////////////////////////////////////////////////
- // GetFreeDiskSpace
- DLL_WAR_SOFTWARE_ __int64 GetFreeDiskSpace(LPCSTR Path);
- ////////////////////////////////////////////////////////////////////////////////
- // Get the starrtup dir
- DLL_WAR_SOFTWARE_ CString GetStartupPath();
- ////////////////////////////////////////////////////////////////////////////////
- // Time conversion
- DLL_WAR_SOFTWARE_ __int64 CTimeToDate(const CTime& ct);
- DLL_WAR_SOFTWARE_ __int64 FiletimeToDate(const FILETIME& ft);
- DLL_WAR_SOFTWARE_ CTime DateToCTime(const __int64 dt);
- DLL_WAR_SOFTWARE_ FILETIME DateToFiletime(const __int64 dt);
- DLL_WAR_SOFTWARE_ int GetMonthFromLiteral(LPCSTR Month);
- ////////////////////////////////////////////////////////////////////////////////
- // Prepere a string for multiline windows display
- DLL_WAR_SOFTWARE_ CString PrepereForWnd(LPCSTR Text);
- ////////////////////////////////////////////////////////////////////////////////
- // Map the string so that sprintf( str) can be called
- DLL_WAR_SOFTWARE_ CString MapStringValid(LPCSTR Text);
- ////////////////////////////////////////////////////////////////////////////////
- // Does a buffer contain more than one line of text?
- DLL_WAR_SOFTWARE_ BOOL IsMultiline(LPCSTR Text);
- #endif __MISCSUPPORTH