#include "DesignManifestLine.h" DesignManifestLine::DesignManifestLine(char * szLine) : LineType(0) , ElementType(0) { bool bIsEnd; // Indicator that an end-element is being processed char *pCurrentPosition; // Position in the input line char *pAtom; // Pointer into an atom char *pValueAtom; // Pointer into an atom char *pNativeValue; // Pointer into native case value char szAtom[MAX_DM_VALUE]; // Atom extracted from the line char szValueAtom[MAX_DM_VALUE]; // Value extracted as an atom char szNativeValue[MAX_DM_VALUE]; // Value in native case // Constructor szName[0] = '\0'; szValue[0] = '\0'; szVersion[0] = '\0'; // Eliminate Null Lines if (strlen(szLine) == 0) return; // Find the start of significant text pCurrentPosition = szLine; while ((*pCurrentPosition == ' ') || (*pCurrentPosition == '\x09')) { pCurrentPosition++; } // Eliminate Null Lines if (*pCurrentPosition == '\0') return; // Determine if this is a value rather than an XML Element if (*pCurrentPosition != '<') { LineType = DM_LINE_VALUE; // show it is a value strcpy_s(szValue, MAX_DM_VALUE, pCurrentPosition); // store the value return; } pCurrentPosition++; // Check that line is still valid if (*pCurrentPosition == '\0') { LineType = DM_LINE_INVALID; // show that line is invalid return; } // Flag XML structure or comment if (*pCurrentPosition == '?') { LineType = DM_LINE_STRUCT; // show XML structure return; } if (*pCurrentPosition == '!') { LineType = DM_LINE_COMMENT; // show XML comment return; } // Line should be an XML Element or end of an Element - determine which one bIsEnd = false; if (*pCurrentPosition == '/') { bIsEnd = true; pCurrentPosition++; } // Extract the element name as an Atom pAtom = szAtom; while ((*pCurrentPosition != ' ') && (*pCurrentPosition != '\0') && (*pCurrentPosition != '>')) { *pAtom = toupper(*pCurrentPosition); pAtom++; pCurrentPosition++; } *pAtom = '\0'; // Determine which element if (strcmp(szAtom, DM_NODE_DM) == 0) { if (bIsEnd) { // /DesignManifest LineType = DM_LINE_MANIFEST_END; // Show /DesignManifest return; } else { // DesignManifest LineType = DM_LINE_MANIFEST; // Show DesignManifest } } else { if (strcmp(szAtom, DM_NODE_DS) == 0) { if (bIsEnd) { // /DesignSet LineType = DM_LINE_SET_END; // Show /DesignSet return; } else { // DesignSet LineType = DM_LINE_SET; // Show DesignSet } } else { if (strcmp(szAtom, DM_NODE_DE) == 0) { if (bIsEnd) { // /DesignElement LineType = DM_LINE_ELEMENT_END; // Show /DesignElement return; } else { // DesignElement LineType = DM_LINE_ELEMENT; // Show DesignElement } } else { // Element is invalid LineType = DM_LINE_INVALID; // Show Invalid return; } } } // Extract any Attributes that are present in the element while ((*pCurrentPosition != '>') && (*pCurrentPosition != '\0')) { // Eliminate white space while (*pCurrentPosition == ' ') { pCurrentPosition++; } // Identify the Attribute pAtom = szAtom; while ((*pCurrentPosition != '=') && (*pCurrentPosition != ' ') && (*pCurrentPosition != '\0') && (*pCurrentPosition != '>')) { *pAtom = toupper(*pCurrentPosition); pAtom++; pCurrentPosition++; } *pAtom = '\0'; // check for an invalid format if (*pCurrentPosition != '=') { LineType = DM_LINE_INVALID; // Show Invalid return; } pCurrentPosition++; if (*pCurrentPosition != '"') { LineType = DM_LINE_INVALID; // Show Invalid return; } // Extract the value pCurrentPosition++; pValueAtom = szValueAtom; pNativeValue = szNativeValue; while ((*pCurrentPosition != '"') && (*pCurrentPosition != '\0') && (*pCurrentPosition != '>')) { *pValueAtom = toupper(*pCurrentPosition); *pNativeValue = *pCurrentPosition; pValueAtom++; pNativeValue++; pCurrentPosition++; } *pValueAtom = '\0'; *pNativeValue = '\0'; // Check for valid termination if (*pCurrentPosition != '"') { LineType = DM_LINE_INVALID; // Show Invalid return; } pCurrentPosition++; // Determine which attribute was found if (strcmp(szAtom, DM_ATTR_NAME) == 0) { strcpy_s(szName, MAX_DM_NAME, szNativeValue); } else { if (strcmp(szAtom, DM_ATTR_VERSION) == 0) { strcpy_s(szVersion, MAX_DM_VERSION, szValueAtom); } else { if (strcmp(szAtom, DM_ATTR_TYPE) == 0) { ElementType = EncodeElementType(szValueAtom); if (ElementType == DM_ELEMENT_NONE) { LineType = DM_LINE_INVALID; return; } } } } } // Check for invalid termination if (*pCurrentPosition == '\0') { LineType = DM_LINE_INVALID; } } DesignManifestLine::~DesignManifestLine(void) { // Destructor } int DesignManifestLine::EncodeElementType(char * szType) { char *pSrc; // Pointer to source string char *pTarg; // Pointer to target string char szElement[MAX_DM_VALUE]; // Element // Convert to upper case for compare pSrc = szType; pTarg = szElement; while (*pSrc != '\0') { *pTarg = *pSrc; pTarg++; pSrc++; } // Check for type if (strcmp(szType, DM_TYPE_PAGE) == 0) return DM_ELEMENT_PAGE; if (strcmp(szType, DM_TYPE_VIEW) == 0) return DM_ELEMENT_VIEW; if (strcmp(szType, DM_TYPE_FORM) == 0) return DM_ELEMENT_FORM; if (strcmp(szType, DM_TYPE_SFORM) == 0) return DM_ELEMENT_SFORM; if (strcmp(szType, DM_TYPE_FSET) == 0) return DM_ELEMENT_FSET; if (strcmp(szType, DM_TYPE_AGENT) == 0) return DM_ELEMENT_AGENT; if (strcmp(szType, DM_TYPE_IMAGE) == 0) return DM_ELEMENT_IMAGE; if (strcmp(szType, DM_TYPE_SFIELD) == 0) return DM_ELEMENT_SFIELD; if (strcmp(szType, DM_TYPE_SACTION) == 0) return DM_ELEMENT_SACTION; if (strcmp(szType, DM_TYPE_LIB) == 0) return DM_ELEMENT_LIB; if (strcmp(szType, DM_TYPE_FOLDER) == 0) return DM_ELEMENT_FOLDER; if (strcmp(szType, DM_TYPE_OUTLINE) == 0) return DM_ELEMENT_OUTLINE; if (strcmp(szType, DM_TYPE_DBICON) == 0) return DM_ELEMENT_DBICON; if (strcmp(szType, DM_TYPE_SHCOL) == 0) return DM_ELEMENT_SHCOL; if (strcmp(szType, DM_TYPE_HABOUT) == 0) return DM_ELEMENT_HABOUT; if (strcmp(szType, DM_TYPE_HUSING) == 0) return DM_ELEMENT_HUSING; return DM_ELEMENT_NONE; }