Пример #1
0
void XSDParser::PrintDocumentTree(void)
{
    cout << " === Namespaces ===" << endl;
    map<string,string>::const_iterator i;
    for (i = m_PrefixToNamespace.begin(); i != m_PrefixToNamespace.end(); ++i) {
        cout << i->first << ":  " << i->second << endl;
    }
    
    cout << " === Target namespace ===" << endl;
    cout << m_TargetNamespace << endl;
    
    cout << " === Element form default ===" << endl;
    cout << (m_ElementFormDefault ? "qualified" : "unqualified") << endl;
    cout << " === Attribute form default ===" << endl;
    cout << (m_AttributeFormDefault ? "qualified" : "unqualified") << endl;
    cout << endl;

    DTDParser::PrintDocumentTree();

    if (!m_MapAttribute.empty()) {
        cout << " === Standalone Attribute definitions ===" << endl;
        map<string,DTDAttribute>::const_iterator a;
        for (a= m_MapAttribute.begin(); a != m_MapAttribute.end(); ++ a) {
            PrintAttribute( a->second, false);
        }
    }
}
Пример #2
0
/**
 * Print a node, its attributes, and all its children recursively.
 */
void PrintNode(FbxNode* pNode) {
    PrintTabs();
    const char* nodeName = pNode->GetName();
    FbxDouble3 translation = pNode->LclTranslation.Get(); 
    FbxDouble3 rotation = pNode->LclRotation.Get(); 
    FbxDouble3 scaling = pNode->LclScaling.Get();

    // Print the contents of the node.
    printf("<node name='%s' translation='(%f, %f, %f)' rotation='(%f, %f, %f)' scaling='(%f, %f, %f)'>\n", 
        nodeName, 
        translation[0], translation[1], translation[2],
        rotation[0], rotation[1], rotation[2],
        scaling[0], scaling[1], scaling[2]
        );
    numTabs++;

    // Print the node's attributes.
    for(int i = 0; i < pNode->GetNodeAttributeCount(); i++)
        PrintAttribute(pNode->GetNodeAttributeByIndex(i));

    // Recursively print the children.
    for(int j = 0; j < pNode->GetChildCount(); j++)
        PrintNode(pNode->GetChild(j));

    numTabs--;
    PrintTabs();
    printf("</node>\n");
}
Пример #3
0
/**
* Print a node, its attributes, and all its children recursively.
*/
void FBXSceneImporter::PrintNode(FbxNode* pNode)
{
	PrintTabs();
	const char* nodeName = pNode->GetName();
	FbxDouble3 translation = pNode->LclTranslation.Get();
	FbxDouble3 rotation = pNode->LclRotation.Get();
	FbxDouble3 scaling = pNode->LclScaling.Get();

	// Print the contents of the node.
	myfile << "<node name= " << nodeName << "\n";

	numTabs++;

	// Print the node's attributes.
	for (int i = 0; i < pNode->GetNodeAttributeCount(); i++)
		PrintAttribute(pNode->GetNodeAttributeByIndex(i));


	// Recursively print the children.
	for (int j = 0; j < pNode->GetChildCount(); j++)
		PrintNode(pNode->GetChild(j));

	numTabs--;
	PrintTabs();
	myfile << "</node>\n" ;
}
void ARMAttributeParser::FP_HP_extension(AttrType Tag, const uint8_t *Data,
                                         uint32_t &Offset) {
  static const char *const Strings[] = { "If Available", "Permitted" };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
void ARMAttributeParser::CPU_unaligned_access(AttrType Tag, const uint8_t *Data,
                                              uint32_t &Offset) {
  static const char *const Strings[] = { "Not Permitted", "v6-style" };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #6
0
void ARMAttributeParser::ABI_PCS_R9_use(AttrType Tag, const uint8_t *Data,
                                        uint32_t &Offset) {
  static const char *Strings[] = { "v6", "Static Base", "TLS", "Unused" };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #7
0
void ARMAttributeParser::ABI_WMMX_args(AttrType Tag, const uint8_t *Data,
                                       uint32_t &Offset) {
  static const char *Strings[] = { "AAPCS", "iWMMX", "Custom" };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #8
0
void ARMAttributeParser::ABI_FP_16bit_format(AttrType Tag, const uint8_t *Data,
                                             uint32_t &Offset) {
  static const char *Strings[] = { "Not Permitted", "IEEE-754", "VFPv3" };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #9
0
void ARMAttributeParser::ABI_FP_rounding(AttrType Tag, const uint8_t *Data,
                                         uint32_t &Offset) {
  static const char *Strings[] = { "IEEE-754", "Runtime" };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #10
0
void ARMAttributeParser::T2EE_use(AttrType Tag, const uint8_t *Data,
                                  uint32_t &Offset) {
  static const char *Strings[] = { "Not Permitted", "Permitted" };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #11
0
void ARMAttributeParser::ABI_FP_denormal(AttrType Tag, const uint8_t *Data,
                                         uint32_t &Offset) {
  static const char *Strings[] = { "Unsupported", "IEEE-754", "Sign Only" };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
void ARMAttributeParser::ABI_PCS_wchar_t(AttrType Tag, const uint8_t *Data,
                                         uint32_t &Offset) {
  static const char *const Strings[] = {
    "Not Permitted", "Unknown", "2-byte", "Unknown", "4-byte"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #13
0
void ARMAttributeParser::Advanced_SIMD_arch(AttrType Tag, const uint8_t *Data,
                                            uint32_t &Offset) {
  static const char *Strings[] = {
    "Not Permitted", "NEONv1", "NEONv2+FMA", "ARMv8-a NEON"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #14
0
void ARMAttributeParser::ABI_PCS_RW_data(AttrType Tag, const uint8_t *Data,
                                         uint32_t &Offset) {
  static const char *Strings[] = {
    "Absolute", "PC-relative", "SB-relative", "Not Permitted"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
void ARMAttributeParser::ABI_enum_size(AttrType Tag, const uint8_t *Data,
                                       uint32_t &Offset) {
  static const char *const Strings[] = {
    "Not Permitted", "Packed", "Int32", "External Int32"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #16
0
void ARMAttributeParser::ABI_FP_number_model(AttrType Tag, const uint8_t *Data,
                                             uint32_t &Offset) {
  static const char *Strings[] = {
    "Not Permitted", "Finite Only", "RTABI", "IEEE-754"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #17
0
void ARMAttributeParser::ABI_HardFP_use(AttrType Tag, const uint8_t *Data,
                                        uint32_t &Offset) {
  static const char *Strings[] = {
    "Tag_FP_arch", "Single-Precision", "Reserved", "Tag_FP_arch (deprecated)"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #18
0
void ARMAttributeParser::PCS_config(AttrType Tag, const uint8_t *Data,
                                    uint32_t &Offset) {
  static const char *Strings[] = {
    "None", "Bare Platform", "Linux Application", "Linux DSO", "Palm OS 2004",
    "Reserved (Palm OS)", "Symbian OS 2004", "Reserved (Symbian OS)"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #19
0
void ARMAttributeParser::FP_arch(AttrType Tag, const uint8_t *Data,
                                 uint32_t &Offset) {
  static const char *Strings[] = {
    "Not Permitted", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4",
    "VFPv4-D16", "ARMv8-a FP", "ARMv8-a FP-D16"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #20
0
void ARMAttributeParser::Virtualization_use(AttrType Tag, const uint8_t *Data,
                                            uint32_t &Offset) {
  static const char *Strings[] = {
    "Not Permitted", "TrustZone", "Virtualization Extensions",
    "TrustZone + Virtualization Extensions"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #21
0
 //-----------------------------------------------------------------------------------
 static void PrintNode(FbxNode* node, int depth)
 {
     Console::instance->PrintLine(Stringf("%*sNode [%s]\n", depth, " ", node->GetName()));
     DebuggerPrintf("%*sNode [%s]\n", depth, " ", node->GetName());
     for (int i = 0; i < node->GetNodeAttributeCount(); ++i)
     {
         PrintAttribute(node->GetNodeAttributeByIndex(i), depth);
     }
     for (int i = 0; i < node->GetChildCount(); ++i)
     {
         PrintNode(node->GetChild(i), depth + 1);
     }
 }
Пример #22
0
void ARMAttributeParser::ABI_FP_optimization_goals(AttrType Tag,
                                                   const uint8_t *Data,
                                                   uint32_t &Offset) {
  static const char *Strings[] = {
    "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Accuracy",
    "Best Accuracy"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #23
0
void ARMAttributeParser::CPU_arch(AttrType Tag, const uint8_t *Data,
                                  uint32_t &Offset) {
  static const char *Strings[] = {
    "Pre-v4", "ARM v4", "ARM v4T", "ARM v5T", "ARM v5TE", "ARM v5TEJ", "ARM v6",
    "ARM v6KZ", "ARM v6T2", "ARM v6K", "ARM v7", "ARM v6-M", "ARM v6S-M",
    "ARM v7E-M", "ARM v8"
  };

  uint64_t Value = ParseInteger(Data, Offset);
  StringRef ValueDesc =
    (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
  PrintAttribute(Tag, Value, ValueDesc);
}
Пример #24
0
void PrintJournalInfoBlock(out_ctx* ctx, const JournalInfoBlock* record)
{
    /*
       struct JournalInfoBlock {
         uint32_t       flags;
         uint32_t       device_signature[8];  // signature used to locate our device.
         uint64_t       offset;               // byte offset to the journal on the device
         uint64_t       size;                 // size in bytes of the journal
         uuid_string_t   ext_jnl_uuid;
         char            machine_serial_num[48];
         char     reserved[JIB_RESERVED_SIZE];
       } __attribute__((aligned(2), packed));
       typedef struct JournalInfoBlock JournalInfoBlock;
     */

    BeginSection(ctx, "Journal Info Block");
    PrintRawAttribute(ctx, record, flags, 2);
    PrintUIFlagIfMatch(ctx, record->flags, kJIJournalInFSMask);
    PrintUIFlagIfMatch(ctx, record->flags, kJIJournalOnOtherDeviceMask);
    PrintUIFlagIfMatch(ctx, record->flags, kJIJournalNeedInitMask);
    _PrintRawAttribute(ctx, "device_signature", &record->device_signature[0], 32, 16);
    PrintDataLength(ctx, record, offset);
    PrintDataLength(ctx, record, size);

    char uuid_str[sizeof(uuid_string_t) + 1];
    (void)strlcpy(uuid_str, &record->ext_jnl_uuid[0], sizeof(uuid_str));
    PrintAttribute(ctx, "ext_jnl_uuid", uuid_str);

    char serial[49];
    (void)strlcpy(serial, &record->machine_serial_num[0], 49);
    PrintAttribute(ctx, "machine_serial_num", serial);

    // (uint32_t) reserved[32]

    EndSection(ctx);
}
Пример #25
0
void ARMAttributeParser::CPU_arch_profile(AttrType Tag, const uint8_t *Data,
                                          uint32_t &Offset) {
  uint64_t Encoded = ParseInteger(Data, Offset);

  StringRef Profile;
  switch (Encoded) {
  default:  Profile = "Unknown"; break;
  case 'A': Profile = "Application"; break;
  case 'R': Profile = "Real-time"; break;
  case 'M': Profile = "Microcontroller"; break;
  case 'S': Profile = "Classic"; break;
  case '0': Profile = "None"; break;
  }

  PrintAttribute(Tag, Encoded, Profile);
}
Пример #26
0
void ARMAttributeParser::ABI_align_needed(AttrType Tag, const uint8_t *Data,
                                          uint32_t &Offset) {
  static const char *Strings[] = {
    "Not Permitted", "8-byte alignment", "4-byte alignment", "Reserved"
  };

  uint64_t Value = ParseInteger(Data, Offset);

  std::string Description;
  if (Value < array_lengthof(Strings))
    Description = std::string(Strings[Value]);
  else if (Value <= 12)
    Description = std::string("8-byte alignment, ") + utostr(1 << Value)
                + std::string("-byte extended alignment");
  else
    Description = "Invalid";

  PrintAttribute(Tag, Value, Description);
}
Пример #27
0
INT CommandAttrib (LPTSTR param)
{
	LPTSTR *arg;
	INT    argc, i;
	TCHAR  szPath[MAX_PATH];
	TCHAR  szFileName [MAX_PATH];
	BOOL   bRecurse = FALSE;
	BOOL   bDirectories = FALSE;
	DWORD  dwAttrib = 0;
	DWORD  dwMask = 0;

	/* initialize strings */
	szPath[0] = _T('\0');
	szFileName[0] = _T('\0');

	/* print help */
	if (!_tcsncmp (param, _T("/?"), 2))
	{
		ConOutResPaging(TRUE,STRING_ATTRIB_HELP);
		return 0;
	}

  nErrorLevel = 0;

	/* build parameter array */
	arg = split (param, &argc, FALSE, FALSE);

	/* check for options */
	for (i = 0; i < argc; i++)
	{
		if (_tcsicmp (arg[i], _T("/s")) == 0)
			bRecurse = TRUE;
		else if (_tcsicmp (arg[i], _T("/d")) == 0)
			bDirectories = TRUE;
	}

	/* create attributes and mask */
	for (i = 0; i < argc; i++)
	{
		if (*arg[i] == _T('+'))
		{
			if (_tcslen (arg[i]) != 2)
			{
				error_invalid_parameter_format (arg[i]);
				freep (arg);
				return -1;
			}

			switch ((TCHAR)_totupper (arg[i][1]))
			{
				case _T('A'):
					dwMask   |= FILE_ATTRIBUTE_ARCHIVE;
					dwAttrib |= FILE_ATTRIBUTE_ARCHIVE;
					break;

				case _T('H'):
					dwMask   |= FILE_ATTRIBUTE_HIDDEN;
					dwAttrib |= FILE_ATTRIBUTE_HIDDEN;
					break;

				case _T('R'):
					dwMask   |= FILE_ATTRIBUTE_READONLY;
					dwAttrib |= FILE_ATTRIBUTE_READONLY;
					break;

				case _T('S'):
					dwMask   |= FILE_ATTRIBUTE_SYSTEM;
					dwAttrib |= FILE_ATTRIBUTE_SYSTEM;
					break;

				default:
					error_invalid_parameter_format (arg[i]);
					freep (arg);
					return -1;
			}
		}
		else if (*arg[i] == _T('-'))
		{
			if (_tcslen (arg[i]) != 2)
			{
				error_invalid_parameter_format (arg[i]);
				freep (arg);
				return -1;
			}

			switch ((TCHAR)_totupper (arg[i][1]))
			{
				case _T('A'):
					dwMask   |= FILE_ATTRIBUTE_ARCHIVE;
					dwAttrib &= ~FILE_ATTRIBUTE_ARCHIVE;
					break;

				case _T('H'):
					dwMask   |= FILE_ATTRIBUTE_HIDDEN;
					dwAttrib &= ~FILE_ATTRIBUTE_HIDDEN;
					break;

				case _T('R'):
					dwMask   |= FILE_ATTRIBUTE_READONLY;
					dwAttrib &= ~FILE_ATTRIBUTE_READONLY;
					break;

				case _T('S'):
					dwMask   |= FILE_ATTRIBUTE_SYSTEM;
					dwAttrib &= ~FILE_ATTRIBUTE_SYSTEM;
					break;

				default:
					error_invalid_parameter_format (arg[i]);
					freep (arg);
					return -1;
			}
		}
	}

	if (argc == 0)
	{
		DWORD len;

		len = GetCurrentDirectory (MAX_PATH, szPath);
		if (szPath[len-1] != _T('\\'))
		{
			szPath[len] = _T('\\');
			szPath[len + 1] = 0;
		}
		_tcscpy (szFileName, _T("*.*"));
		PrintAttribute (szPath, szFileName, bRecurse);
		freep (arg);
		return 0;
	}

	/* get full file name */
	for (i = 0; i < argc; i++)
	{
		if ((*arg[i] != _T('+')) && (*arg[i] != _T('-')) && (*arg[i] != _T('/')))
		{
			LPTSTR p;
			GetFullPathName (arg[i], MAX_PATH, szPath, NULL);
			p = _tcsrchr (szPath, _T('\\')) + 1;
			_tcscpy (szFileName, p);
			*p = _T('\0');

			if (dwMask == 0)
				PrintAttribute (szPath, szFileName, bRecurse);
			else
				ChangeAttribute (szPath, szFileName, dwMask,
						 dwAttrib, bRecurse, bDirectories);
		}
	}

	freep (arg);
	return 0;
}
Пример #28
0
void ARMAttributeParser::nodefaults(AttrType Tag, const uint8_t *Data,
                                    uint32_t &Offset) {
  uint64_t Value = ParseInteger(Data, Offset);
  PrintAttribute(Tag, Value, "Unspecified Tags UNDEFINED");
}
Пример #29
0
Файл: Main.c Проект: Rupan/HLLib
hlVoid EnterConsole(hlUInt uiPackage, hlUInt uiConsoleCommands, hlChar *lpConsoleCommands[])
{
    hlUInt i;

    hlChar lpBuffer[BUFFER_SIZE];	// Input string.
    hlChar lpCommand[BUFFER_SIZE];	// Input command  (i.e. first word in input string).
    hlChar lpArgument[BUFFER_SIZE];	// Input argument (i.e. rest of input string).
    hlChar *lpTemp;
    hlChar lpTempBuffer[BUFFER_SIZE];

    hlUInt16 uiColor;
    HLDirectoryItem *pItem = 0, *pSubItem = 0;

    hlBool bFound;
    hlUInt uiItemCount, uiFolderCount, uiFileCount;
    hlChar iChar;
    HLStream *pStream = 0;
    HLAttribute Attribute;
    HLPackageType ePackageType = HL_PACKAGE_NONE;
    hlUInt uiSubPackage = HL_ID_INVALID;

    pItem = hlPackageGetRoot();

    while(hlTrue)
    {
        uiColor = GetColor();
        SetColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);

        if(uiConsoleCommands > 0)
        {
            printf("%s>%s\n", hlItemGetName(pItem), *lpConsoleCommands);

            strncpy(lpBuffer, *lpConsoleCommands, sizeof(lpBuffer));
            lpBuffer[sizeof(lpBuffer) - 1] = '\0';

            uiConsoleCommands--;
            lpConsoleCommands++;
        }
        else
        {
            // Command prompt.
            printf("%s>", hlItemGetName(pItem));

            // Get and parse line.
            fgets(lpBuffer, sizeof(lpBuffer), stdin);
        }

        SetColor(uiColor);

        i = (hlUInt)strlen(lpBuffer);
        while(i > 0 && (lpBuffer[i - 1] == '\r' || lpBuffer[i - 1] == '\n'))
        {
            i--;
            lpBuffer[i] = '\0';
        }

        *lpCommand = *lpArgument = 0;

        strcpy(lpCommand, lpBuffer);
        lpTemp = strchr(lpCommand, ' ');
        if(lpTemp != 0)
        {
            strcpy(lpArgument, lpTemp + 1);
            *lpTemp = 0;
        }

        // Cycle through commands.

        //
        // Directory listing.
        // Good example of CDirectoryItem::GetType().
        //
#ifdef _WIN32
        if(stricmp(lpCommand, "dir") == 0)
#else
        if(stricmp(lpCommand, "ls") == 0)
#endif
        {
            uiItemCount = hlFolderGetCount(pItem);
            uiFolderCount = 0, uiFileCount = 0;

            *lpTempBuffer = 0;
            hlItemGetPath(pItem, lpTempBuffer, sizeof(lpTempBuffer));

            printf("Directory of %s:\n", lpTempBuffer);

            printf("\n");

            if(*lpArgument == 0)
            {
                // List all items in the current folder.
                for(i = 0; i < uiItemCount; i++)
                {
                    pSubItem = hlFolderGetItem(pItem, i);
                    if(hlItemGetType(pSubItem) == HL_ITEM_FOLDER)
                    {
                        uiFolderCount++;
                        printf("  <%s>\n", hlItemGetName(pSubItem));
                    }
                    else if(hlItemGetType(pSubItem) == HL_ITEM_FILE)
                    {
                        uiFileCount++;
                        printf("  %s\n", hlItemGetName(pSubItem));
                    }
                }
            }
            else
            {
                pSubItem = hlFolderFindFirst(pItem, lpArgument, HL_FIND_ALL | HL_FIND_NO_RECURSE);
                while(pSubItem)
                {
                    if(hlItemGetType(pSubItem) == HL_ITEM_FOLDER)
                    {
                        uiFolderCount++;
                        printf("  <%s>\n", hlItemGetName(pSubItem));
                    }
                    else if(hlItemGetType(pSubItem) == HL_ITEM_FILE)
                    {
                        uiFileCount++;
                        printf("  %s\n", hlItemGetName(pSubItem));
                    }

                    pSubItem = hlFolderFindNext(pItem, pSubItem, lpArgument, HL_FIND_ALL | HL_FIND_NO_RECURSE);
                }
            }

            printf("\n");

            // Could also have used hlFolderGetFolderCount() and
            // hlFolderGetFileCount().

            printf("Summary:\n");
            printf("\n");
            printf("  %u Folder%s.\n", uiFolderCount, uiFolderCount != 1 ? "s" : "");
            printf("  %u File%s.\n", uiFileCount, uiFileCount != 1 ? "s" : "");
            printf("\n");
        }
        //
        // Change directory.
        // Good example of CDirectoryFolder::GetParent() and item casting.
        //
        else if(stricmp(lpCommand, "cd") == 0)
        {
            if(*lpArgument == 0)
            {
                printf("No argument for command cd supplied.\n");
            }
            else
            {
                if(stricmp(lpArgument, ".") == 0)
                {

                }
                else if(stricmp(lpArgument, "..") == 0)
                {
                    if(hlItemGetParent(pItem) != 0)
                    {
                        pItem = hlItemGetParent(pItem);
                    }
                    else
                    {
                        printf("Folder does not have a parent.\n");
                    }
                }
                else
                {
                    bFound = hlFalse;
                    uiItemCount = hlFolderGetCount(pItem);
                    for(i = 0; i < uiItemCount; i++)
                    {
                        pSubItem = hlFolderGetItem(pItem, i);
                        if(hlItemGetType(pSubItem) == HL_ITEM_FOLDER && stricmp(lpArgument, hlItemGetName(pSubItem)) == 0)
                        {
                            bFound = hlTrue;
                            pItem = pSubItem;
                            break;
                        }
                    }

                    if(!bFound)
                    {
                        printf("%s not found.\n", lpArgument);
                    }
                }
            }
        }
        //
        // Go to the root folder.
        //
        else if(stricmp(lpCommand, "root") == 0)
        {
            pItem = hlPackageGetRoot();
        }
        //
        // Item information.
        // Good example of CPackageUtility helper functions.
        //
        else if(stricmp(lpCommand, "info") == 0)
        {
            if(*lpArgument == 0)
            {
                printf("No argument for command info supplied.\n");
            }
            else
            {
                pSubItem = hlFolderGetItemByPath(pItem, lpArgument, HL_FIND_ALL);

                if(pSubItem != 0)
                {
                    *lpTempBuffer = 0;
                    hlItemGetPath(pSubItem, lpTempBuffer, sizeof(lpTempBuffer));

                    printf("Information for %s:\n", lpTempBuffer);
                    printf("\n");

                    switch(hlItemGetType(pSubItem))
                    {
                    case HL_ITEM_FOLDER:
                        printf("  Type: Folder\n");
#ifdef _WIN32
                        printf("  Size: %I64u B\n", hlFolderGetSizeEx(pSubItem, hlTrue));
                        printf("  Size On Disk: %I64u B\n", hlFolderGetSizeOnDiskEx(pSubItem, hlTrue));
#else
                        printf("  Size: %llu B\n", hlFolderGetSizeEx(pSubItem, hlTrue));
                        printf("  Size On Disk: %llu B\n", hlFolderGetSizeOnDiskEx(pSubItem, hlTrue));
#endif
                        printf("  Folders: %u\n", hlFolderGetFolderCount(pSubItem, hlTrue));
                        printf("  Files: %u\n", hlFolderGetFileCount(pSubItem, hlTrue));
                        break;
                    case HL_ITEM_FILE:
                        printf("  Type: File\n");
                        printf("  Extractable: %s\n", hlFileGetExtractable(pSubItem) ? "True" : "False");
                        //printf("  Validates: %s\n", hlFileGetValidates(pSubItem) ? "True" : "False");
                        printf("  Size: %u B\n", hlFileGetSize(pSubItem));
                        printf("  Size On Disk: %u B\n", hlFileGetSizeOnDisk(pSubItem));
                        break;
                    }

                    uiItemCount = hlPackageGetItemAttributeCount();
                    for(i = 0; i < uiItemCount; i++)
                    {
                        if(hlPackageGetItemAttribute(pSubItem, i, &Attribute))
                        {
                            PrintAttribute("  ", &Attribute, "");
                        }
                    }

                    printf("\n");
                }
                else
                {
                    printf("%s not found.\n", lpArgument);
                }
            }
        }
        //
        // Extract item.
        // Good example of CPackageUtility extract functions.
        //
        else if(stricmp(lpCommand, "extract") == 0)
        {
            if(*lpArgument == 0)
            {
                printf("No argument for command extract supplied.\n");
            }
            else
            {
                if(stricmp(lpArgument, ".") == 0)
                {
                    pSubItem = pItem;
                }
                else
                {
                    pSubItem = hlFolderGetItemByName(pItem, lpArgument, HL_FIND_ALL);
                }

                if(pSubItem)
                {
                    // Extract the item.
                    // Item is extracted to cDestination\Item->GetName().
                    if(!bSilent)
                    {
                        printf("Extracting %s...\n", hlItemGetName(pSubItem));
                        printf("\n");
                    }

                    hlItemExtract(pSubItem, lpDestination);

                    if(!bSilent)
                    {
                        printf("\n");
                        printf("Done.\n");
                    }
                }
                else
                {
                    printf("%s not found.\n", lpArgument);
                }
            }
        }
        //
        // Validate item.
        // Validates the checksums of each item.
        //
        else if(stricmp(lpCommand, "validate") == 0)
        {
            if(*lpArgument == 0)
            {
                printf("No argument for command extract supplied.\n");
            }
            else
            {
                if(stricmp(lpArgument, ".") == 0)
                {
                    pSubItem = pItem;
                }
                else
                {
                    pSubItem = hlFolderGetItemByName(pItem, lpArgument, HL_FIND_ALL);
                }

                if(pSubItem)
                {
                    if(!bSilent)
                    {
                        printf("Validating %s...\n", hlItemGetName(pSubItem));
                        printf("\n");
                    }

                    Validate(pSubItem);

                    if(!bSilent)
                    {
                        printf("\n");
                        printf("Done.\n");
                    }
                }
                else
                {
                    printf("%s not found.\n", lpArgument);
                }
            }
        }
        //
        // Find items.
        // Good example of recursive directory navigation (Search() function).
        //
        else if(stricmp(lpCommand, "find") == 0)
        {
            if(*lpArgument == 0)
            {
                printf("No argument for command find supplied.\n");
            }
            else
            {
                // Search for the requested items.
                if(!bSilent)
                {
                    printf("Searching for %s...\n", lpArgument);
                    printf("\n");
                }

                uiItemCount = 0;
                pSubItem = hlFolderFindFirst(pItem, lpArgument, HL_FIND_ALL);
                while(pSubItem)
                {
                    hlItemGetPath(pSubItem, lpTempBuffer, sizeof(lpTempBuffer));

                    // Print the path.
                    uiItemCount++;
                    Print(hlItemGetType(pSubItem) == HL_ITEM_FILE ? FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY : GetColor(), "  Found %s: %s\n", hlItemGetType(pSubItem) == HL_ITEM_FOLDER ? "folder" : "file", lpTempBuffer);

                    pSubItem = hlFolderFindNext(pItem, pSubItem, lpArgument, HL_FIND_ALL);
                }

                if(!bSilent)
                {
                    if(uiItemCount != 0)
                    {
                        printf("\n");
                    }

                    printf("  %u item%s found.\n", uiItemCount, uiItemCount != 1 ? "s" : "");
                    printf("\n");
                }
            }
        }
        //
        // Type files.
        // Good example of reading files into memory.
        //
        else if(stricmp(lpCommand, "type") == 0)
        {
            if(*lpArgument == 0)
            {
                printf("No argument for command type supplied.\n");
            }
            else
            {
                pSubItem = hlFolderGetItemByName(pItem, lpArgument, HL_FIND_FILES);

                if(pSubItem)
                {
                    *lpTempBuffer = 0;
                    hlItemGetPath(pSubItem, lpTempBuffer, sizeof(lpTempBuffer));

                    if(!bSilent)
                    {
                        printf("Type for %s:\n", lpTempBuffer);
                        printf("\n");
                    }

                    if(hlFileCreateStream(pSubItem, &pStream))
                    {
                        if(hlStreamOpen(pStream, HL_MODE_READ))
                        {
                            uiColor = GetColor();
                            SetColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);

                            while(hlStreamReadChar(pStream, &iChar))
                            {
                                if((iChar >= ' ' && iChar <= '~') || iChar == '\n' || iChar == '\t')
                                {
                                    putc(iChar, stdout);
                                }
                            }

                            SetColor(uiColor);

                            hlStreamClose(pStream);
                        }
                        else
                        {
                            Print(FOREGROUND_RED | FOREGROUND_INTENSITY, "Error typing %s:\n%s\n", hlItemGetName(pSubItem), hlGetString(HL_ERROR_SHORT_FORMATED));
                        }

                        hlFileReleaseStream(pSubItem, pStream);
                        pStream = 0;
                    }
                    else
                    {
                        Print(FOREGROUND_RED | FOREGROUND_INTENSITY, "Error typing %s:\n%s\n", hlItemGetName(pSubItem), hlGetString(HL_ERROR_SHORT_FORMATED));
                    }

                    if(!bSilent)
                    {
                        printf("\n");
                        printf("Done.\n");
                    }
                }
                else
                {
                    printf("%s not found.\n", lpArgument);
                }
            }
        }
        //
        // Open item.
        // Good example of opening packages inside packages.
        //
        else if(stricmp(lpCommand, "open") == 0)
        {
            if(*lpArgument == 0)
            {
                printf("No argument for command open supplied.\n");
            }
            else
            {
                pSubItem = hlFolderGetItemByName(pItem, lpArgument, HL_FIND_FILES);

                if(pSubItem)
                {
                    if(hlFileCreateStream(pSubItem, &pStream))
                    {
                        if(hlStreamOpen(pStream, HL_MODE_READ))
                        {
                            ePackageType = hlGetPackageTypeFromStream(pStream);

                            if(hlCreatePackage(ePackageType, &uiSubPackage))
                            {
                                hlBindPackage(uiSubPackage);
                                if(hlPackageOpenStream(pStream, HL_MODE_READ))
                                {
                                    if(!bSilent)
                                        Print(FOREGROUND_GREEN | FOREGROUND_INTENSITY, "%s opened.\n", hlItemGetName(pSubItem));

                                    EnterConsole(uiSubPackage, uiConsoleCommands, lpConsoleCommands);

                                    hlPackageClose();

                                    if(!bSilent)
                                        Print(FOREGROUND_GREEN | FOREGROUND_INTENSITY, "%s closed.\n", hlItemGetName(pSubItem));
                                }
                                else
                                {
                                    Print(FOREGROUND_RED | FOREGROUND_INTENSITY, "Error opening %s:\n%s\n", hlItemGetName(pSubItem), hlGetString(HL_ERROR_SHORT_FORMATED));
                                }

                                hlDeletePackage(uiSubPackage);

                                hlBindPackage(uiPackage);
                            }
                            else
                            {
                                Print(FOREGROUND_RED | FOREGROUND_INTENSITY, "Error opening %s:\n%s\n", hlItemGetName(pSubItem), hlGetString(HL_ERROR_SHORT_FORMATED));
                            }

                            hlStreamClose(pStream);
                        }
                        else
                        {
                            Print(FOREGROUND_RED | FOREGROUND_INTENSITY, "Error opening %s:\n%s\n", hlItemGetName(pSubItem), hlGetString(HL_ERROR_SHORT_FORMATED));
                        }

                        hlFileReleaseStream(pSubItem, pStream);
                        pStream = 0;
                    }
                    else
                    {
                        Print(FOREGROUND_RED | FOREGROUND_INTENSITY, "Error opening %s:\n%s\n", hlItemGetName(pSubItem), hlGetString(HL_ERROR_SHORT_FORMATED));
                    }
                }
                else
                {
                    printf("%s not found.\n", lpArgument);
                }
            }
        }
        //
        // Clear screen.
        //
        else if(stricmp(lpCommand, "status") == 0)
        {
#ifdef _WIN32
            printf("Total size: %I64u B\n", hlGetUnsignedLongLong(HL_PACKAGE_SIZE));
#else
            printf("Total size: %llu B\n", hlGetUnsignedLongLong(HL_PACKAGE_SIZE));
#endif
            printf("Total mapping allocations: %u\n", hlGetUnsignedInteger(HL_PACKAGE_TOTAL_ALLOCATIONS));
#ifdef _WIN32
            printf("Total mapping memory allocated: %I64u B\n", hlGetUnsignedLongLong(HL_PACKAGE_TOTAL_MEMORY_ALLOCATED));
            printf("Total mapping memory used: %I64u B\n", hlGetUnsignedLongLong(HL_PACKAGE_TOTAL_MEMORY_USED));
#else
            printf("Total mapping memory allocated: %llu B\n", hlGetUnsignedLongLong(HL_PACKAGE_TOTAL_MEMORY_ALLOCATED));
            printf("Total mapping memory used: %llu B\n", hlGetUnsignedLongLong(HL_PACKAGE_TOTAL_MEMORY_USED));
#endif

            uiItemCount = hlPackageGetAttributeCount();
            for(i = 0; i < uiItemCount; i++)
            {
                if(hlPackageGetAttribute(i, &Attribute))
                {
                    PrintAttribute("", &Attribute, "");
                }
            }
        }
#ifdef _WIN32
        else if(stricmp(lpCommand, "cls") == 0)
        {
            system("cls");
        }
#endif
        else if(stricmp(lpCommand, "help") == 0)
        {
            printf("Valid commands:\n");
            printf("\n");
#ifdef _WIN32
            printf("dir <filter>    (Directory list.)\n");
#else
            printf("ls <filter>     (Directory list.)\n");
#endif
            printf("cd <folder>     (Change directroy.)\n");
            printf("info <item>     (Item information.)\n");
            printf("extract <item>  (Extract item.)\n");
            printf("validate <item> (Validate item.)\n");
            printf("find <filter>   (Find item.)\n");
            printf("type <file>     (Type a file.)\n");
            printf("open <file>     (Open a nested package.)\n");
            printf("root            (Go to the root folder.)\n");
            printf("status          (Package information.)\n");
#ifdef _WIN32
            printf("cls             (Clear the screen.)\n");
#endif
            printf("help            (Program help.)\n");
            printf("exit            (Quit program.)\n");
            printf("\n");
        }
        else if(stricmp(lpCommand, "exit") == 0)
        {
            break;
        }
        else
        {
            printf("Unkown command: %s\n", lpCommand);
        }
    }
}
Пример #30
0
static VOID
PrintAttribute (LPTSTR pszPath, LPTSTR pszFile, BOOL bRecurse)
{
	WIN32_FIND_DATA findData;
	HANDLE hFind;
	TCHAR  szFullName[MAX_PATH];
	LPTSTR pszFileName;

	/* prepare full file name buffer */
	_tcscpy (szFullName, pszPath);
	pszFileName = szFullName + _tcslen (szFullName);

	/* display all subdirectories */
	if (bRecurse)
	{
		/* append file name */
		_tcscpy (pszFileName, pszFile);

		hFind = FindFirstFile (szFullName, &findData);
		if (hFind == INVALID_HANDLE_VALUE)
		{
			ErrorMessage (GetLastError (), pszFile);
			return;
		}

		do
		{
			if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
				continue;

			if (!_tcscmp (findData.cFileName, _T(".")) ||
				!_tcscmp (findData.cFileName, _T("..")))
				continue;

			_tcscpy (pszFileName, findData.cFileName);
			_tcscat (pszFileName, _T("\\"));
			PrintAttribute (szFullName, pszFile, bRecurse);
		}
		while (FindNextFile (hFind, &findData));
		FindClose (hFind);
	}

	/* append file name */
	_tcscpy (pszFileName, pszFile);

	/* display current directory */
	hFind = FindFirstFile (szFullName, &findData);
	if (hFind == INVALID_HANDLE_VALUE)
	{
		ErrorMessage (GetLastError (), pszFile);
		return;
	}

	do
	{
		if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			continue;

		_tcscpy (pszFileName, findData.cFileName);

		ConOutPrintf (_T("%c  %c%c%c     %s\n"),
		              (findData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? _T('A') : _T(' '),
		              (findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? _T('S') : _T(' '),
		              (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? _T('H') : _T(' '),
		              (findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? _T('R') : _T(' '),
		              szFullName);
	}
	while (FindNextFile (hFind, &findData));
	FindClose (hFind);
}