home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1997-1998, Tall Tree Software Co.
- *
- * This code is provided AS-IS, with no warranty expressed or implied.
- * in no way shall Tall Tree Software Co. be held liable for damages
- * brought about by the use of this software.
- */
-
-
- #include <afxwin.h>
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
-
- #include <Rewriter Hook.h>
-
- #include "resource.h"
- #include "Settings.h"
-
- // The purpose of this DLL is to remove unnecessary namespace qualifiers.
- // The "Settings" dialog allows users to enter the namespace prefixes they
- // want to remove and OnObjectFound does the deed.
-
-
- ///////////////////////////////////////////////////////////////////////
- // Preliminary junk
-
- static HookReportFunction nextOnObjectFound;
-
- extern "C" DLLEXPORT void SetNextOnObjectFound( HookReportFunction onObjectFound )
- {
- nextOnObjectFound = onObjectFound;
- }
-
- static const char *MatchNS( const char *ns, const char *objname )
- {
- while ( *ns != '\0' ) {
- if ( *ns == *objname ) {
- ++ns;
- ++objname;
- }
- else if ( *ns == '.' && objname[0] == ':' && objname[1] == ':' ) {
- ++ns;
- objname += 2;
- }
- else if ( ns[0] == ':' && ns[1] == ':' && objname[0] == '.' ) {
- ns += 2;
- ++objname;
- }
- else if ( ( ns[0] == '.' || ns[0] == ':' ) && objname[0] == '\0' ) {
- return( objname );
- }
- else
- return 0;
- }
- if ( *objname == '.' )
- return( objname+1 );
- else if ( objname[0] == ':' && objname[1] == ':' )
- return( objname+2 );
- else if ( objname[0] == '\0' )
- return objname;
- else
- return( 0 );
- }
-
- extern "C" DLLEXPORT void OnObjectFound( const char *p_sourceFile,
- unsigned int p_commentStartLine,
- unsigned int p_declStartLine,
- const char *p_objectName,
- const Subtype &p_subtype,
- const char *p_superclass,
- const char *p_declaration,
- const char *p_comment,
- const char *p_body,
- char const **p_extras )
- {
- assert( nextOnObjectFound != 0 );
- char *declaration = 0;
-
- for ( char **np = namespaces; *np != 0; ++np ) {
- const char *newName = MatchNS( *np, p_objectName );
- if ( newName != 0 && *newName == '\0' )
- return;
- else if ( newName != 0 ) {
- const char *dp = strstr( p_declaration, p_objectName );
- if ( dp != 0 ) {
- declaration = strdup( p_declaration );
- memmove( declaration + (dp-p_declaration),
- declaration + (dp-p_declaration) +
- (newName - p_objectName),
- strlen( p_declaration ) -
- ( dp - p_objectName ) - strlen( p_objectName ) );
- }
- p_objectName = newName;
- break;
- }
- }
- (*nextOnObjectFound)( p_sourceFile, p_commentStartLine, p_declStartLine,
- p_objectName, p_subtype, p_superclass,
- ( declaration == 0 ? p_declaration : declaration ),
- p_comment, p_body, p_extras );
- }
-
-