Esempio n. 1
0
/* Build a textual presenation of the provided scope stack taking the
   Java keyword identifier translation into account. Further the function
   equals "idl_scopeStack".
*/
c_char *
idl_scopeStackJava (
    idl_scope scope,
    const char *scopeSepp,
    const char *name)
{
    c_long si;
    c_long sz;
    c_char *scopeStack;
    c_char *Id;

    if(orgLastSubstituted) {
        os_free(orgLastSubstituted);
        orgLastSubstituted = NULL;
    }

    if(tarLastSubstituted) {
        os_free(tarLastSubstituted);
        tarLastSubstituted = NULL;
    }

    si = 0;
    sz = idl_scopeStackSize(scope);
    if (si < sz) {
        /* The scope stack is not empty */
        /* Copy the first scope element name */
        scopeStack = os_strdup(idl_javaId(idl_scopeJavaElementName(idl_scopeIndexed(scope, si))));
        si++;
        while (si < sz) {
            /* Translate the scope name to a C identifier */
            Id = idl_javaId(idl_scopeJavaElementName(idl_scopeIndexed(scope, si)));
            /* allocate space for the current scope stack + the separator
               and the next scope name
             */
            /* QAC EXPECT 5007; will not use wrapper */
            scopeStack = os_realloc(scopeStack, (size_t)(
                             (int)strlen(scopeStack)+
                             (int)strlen(scopeSepp)+
                             (int)strlen(Id)+1));
           /* Concatenate the separator */
           /* QAC EXPECT 5007; will not use wrapper */
           os_strcat(scopeStack, scopeSepp);
           /* Concatenate the scope name */
           /* QAC EXPECT 5007; will not use wrapper */
           os_strcat (scopeStack, Id);
           si++;
        }
        if(strlen(scopeStack) > 0)
        {
            os_char* ptr;
            os_char* ptr2;
            os_char* ptr3;

            /* es, dds1540: The following code is not pretty, but time limitations
             * required it's implementation. To ensure
             * proper substitution of for example package name 'Chat' with
             * 'org.opensplice.Chat' without substitution class names like
             * 'ChatMessage' to 'org.opensplice.ChatMessage' we need to take some
             * special arrangements. We need to allow the user to state he wants to
             * replace 'Chat.' with ''org.opensplice.Chat.', as this would resolve
             * the previously stated problem.
             * However this function for getting the scope stack is called in a
             * special way if only the package names are required (without the
             * specific class at the end). In these cases package Chat would become
             * in string format 'Chat' instead of 'Chat.'. And this would cause
             * problems when doing the substitution for the directory names and
             * package directives. So to ensure substitution always goes correctly
             * we added the scopeSepp to the end of the scopeStack and input that
             * into the substitution algorithm. After the algorithm we remove the
             * added scopeSepp again.
             * So not that nicely solved, but lack of time to do it more nicely
             * (which would be to support regular expression type things) --> No.
             */
            ptr = os_malloc(strlen(scopeStack)+ strlen(scopeSepp) + 1);
            os_strcpy(ptr, scopeStack);
            os_strncat(ptr, scopeSepp, strlen(scopeSepp));
            ptr2 = idl_genJavaHelperApplyPackageSubstitute(ptr, scopeSepp);
            memset(ptr, 0, strlen(ptr));
            os_free(ptr);
            ptr3 = strrchr(ptr2, *scopeSepp);
            if(ptr3)
            {
                *ptr3 = '\0';
            }
            ptr = os_strdup(ptr2);
            memset(ptr2, 0, strlen(ptr2));
            os_free(ptr2);
            memset(scopeStack, 0, strlen(scopeStack));
            os_free(scopeStack);
            scopeStack = ptr;
        }

        if (name) {
            /* A user identifier is specified */
            /* Translate the user identifier to a Java identifier */
            Id = idl_javaId(name);
            /* allocate space for the current scope stack + the separator
               and the user identifier
             */
            /* QAC EXPECT 5007; will not use wrapper */
            scopeStack = os_realloc(scopeStack, (size_t)(
                             (int)strlen(scopeStack)+
                             (int)strlen(scopeSepp)+
                             (int)strlen(Id)+1));
           /* Concatenate the separator */
           /* QAC EXPECT 5007; will not use wrapper */
           os_strcat(scopeStack, scopeSepp);
           /* Concatenate the user identifier */
           /* QAC EXPECT 5007; will not use wrapper */
           os_strcat (scopeStack, Id);
        }
     } else {
        /* The stack is empty */
        if (name) {
            /* A user identifier is specified */
            scopeStack = os_strdup(idl_javaId(name));
        } else {
            /* make the stack represenation empty */
            scopeStack = os_strdup("");
        }
    }
    /* return the scope stack representation */
    return scopeStack;
}
Esempio n. 2
0
/* Build a textual presentation of the provided scope stack taking the
 * Java keyword identifier translation into account. Further the function
 * equals "idl_scopeStack".
 */
c_char *
idl_scopeStackJava (
    idl_scope scope,
    const char *scopeSepp,
    const char *name)
{
    c_long si;
    c_long sz;
    c_char *scopeStack = NULL;
    c_char *Id;
    os_char *substitute;
    os_char *module, *package;
    os_uint32 cnt, rlen;
    idl_packageRedirect redirect;

    assert (scopeSepp != NULL);
    scopeStack = os_strdup ("");

    for (si = 0, sz = idl_scopeStackSize(scope); si < sz; si++) {
        size_t slen;

        /* Translate the scope name to a C identifier */
        Id = idl_javaId(idl_scopeJavaElementName(idl_scopeIndexed(scope, si)));
        /* allocate space for the current scope stack + the separator
         *and the next scope name
         */
        /* QAC EXPECT 5007; will not use wrapper */
        slen = strlen (scopeStack) + strlen (scopeSepp) + strlen (Id);
        scopeStack = os_realloc(scopeStack, slen + 1);
        /* Concatenate the separator */
        /* QAC EXPECT 5007; will not use wrapper */
        if (strlen(scopeStack)) {
            os_strcat(scopeStack, scopeSepp);
        }
        /* Concatenate the scope name */
        /* QAC EXPECT 5007; will not use wrapper */
        os_strcat (scopeStack, Id);
    }

    /* idl_genJavaHelperPackageRedirects must be sorted */
    substitute = scopeStack;
    rlen = os_iterLength (idl_genJavaHelperPackageRedirects);
    for (cnt = 0; cnt < rlen && substitute == scopeStack; cnt++) {
        redirect = idl_packageRedirect (
            os_iterObject (idl_genJavaHelperPackageRedirects, cnt));
        assert (redirect != NULL);

        package = os_str_replace (redirect->package, ".", scopeSepp, 0);
        if (package != NULL) {
            if (redirect->module != NULL) {
                module = os_str_replace (redirect->module, ".", scopeSepp, 0);
                if (module == NULL) {
                    substitute = NULL;
                } else {
                    substitute = os_str_word_replace (
                        scopeStack, scopeSepp, module, package, 1);

                    if (module != redirect->module) {
                        os_free (module);
                    }
                }
            } else {
                substitute = os_malloc (
                    strlen (package) +
                    strlen (scopeSepp) +
                    strlen (scopeStack) +
                    1 /* '\0' */);
                if (substitute != NULL) {
                    (void)strcpy (substitute, package);
                    if (strlen (scopeStack)) {
                        (void)os_strcat (substitute, scopeSepp);
                        (void)os_strcat (substitute, scopeStack);
                    }
                }
            }

            if (package != redirect->package) {
                os_free (package);
            }
        }
    }

    if (substitute != scopeStack) {
        os_free (scopeStack);
        scopeStack = substitute;
    }

    if (name) {
        /* A user identifier is specified */
        /* Translate the user identifier to a Java identifier */
        Id = idl_javaId(name);
        /* allocate space for the current scope stack + the separator
         * and the user identifier
         */
        /* QAC EXPECT 5007; will not use wrapper */
        scopeStack = os_realloc(scopeStack, strlen(scopeStack)+strlen(scopeSepp)+strlen(Id)+1);
        /* Concatenate the separator */
        /* QAC EXPECT 5007; will not use wrapper */
        if (strlen(scopeStack)) {
            os_strcat(scopeStack, scopeSepp);
        }
        /* Concatenate the user identifier */
        /* QAC EXPECT 5007; will not use wrapper */
        os_strcat (scopeStack, Id);
    }

    /* return the scope stack representation */
    return scopeStack;
}