Index: src/fortranscanner.l
@@ -463,9 +463,8 @@
 
                                           // extract generic name
                                           QCString name = QCString(yytext).stripWhiteSpace();
-                                          name = name.right(name.length() - 9).stripWhiteSpace();
+                                          name = name.right(name.length() - 9).stripWhiteSpace().lower();
                                           addInterface(name, ifType);
-
                                           startScope(last_entry);
                                         }
 }
@@ -689,7 +688,7 @@
                                             addModule(NULL); 
                                             yy_push_state(ModuleBody); //anon program
                                           }
-					  argType = QCString(yytext).simplifyWhiteSpace();
+					  argType = QCString(yytext).simplifyWhiteSpace().lower();
 					  yy_push_state(AttributeList);
                                         }
   /*  Dimitri: macro expansion should already be done during preprocessing not here!
Index: src/fortrancode.l
===================================================================
--- src/fortrancode.l	(revision 813)
+++ src/fortrancode.l	(working copy)
@@ -388,11 +388,13 @@
   {
     UseEntry *use;
     for (UseSDict::Iterator di(*usedict); (use=di.current()); ++di)
-      if ((cd= Doxygen::classSDict->find(use->module+"::"+tname))) 
+    {
+      if ((cd= Doxygen::classSDict->find(use->module+"::"+tname)))
       {
  	//cout << "===  type found in used module" << endl;
         return TRUE;
       }
+    }
   }
 
   return FALSE;
@@ -420,6 +422,10 @@
 
   // search for function
   MemberName *mn = Doxygen::functionNameSDict->find(memberName);
+  if (!mn)
+  {
+    mn = Doxygen::memberNameSDict->find(memberName);
+  }
 
   if (mn) // name is known
   {
@@ -463,7 +469,9 @@
                  {
                    //cout << " search in only: " << moduleName << ":: " << memberName << "==" << (*it)<<  endl;
 		   if (memberName == (*it).utf8())
+	           {
                      return TRUE; // found in ONLY-part of use list
+	           }
 	         }
 	       }
              }
@@ -527,7 +535,7 @@
 {
   ClassDef *cd=0;
   QCString tmp = lname;
-  tmp = tmp.lower();
+  tmp = removeRedundantWhiteSpace(tmp.lower());
  
   // check if lowercase lname is a linkable type or interface
   if ( (getFortranTypeDefs(tmp, currentModule, cd, useMembers)) && cd->isLinkable() )
@@ -656,7 +664,7 @@
 LOG_OPER  (\.and\.|\.eq\.|\.eqv\.|\.ge\.|\.gt\.|\.le\.|\.lt\.|\.ne\.|\.neqv\.|\.or\.|\.not\.)
 KIND      {ARGS}
 CHAR      (CHARACTER{ARGS}?|CHARACTER{BS}"*"({BS}[0-9]+|{ARGS}))
-TYPE_SPEC (({NUM_TYPE}({BS}"*"{BS}[0-9]+)?)|({NUM_TYPE}{KIND})|DOUBLE{BS_}COMPLEX|DOUBLE{BS_}PRECISION|{CHAR}|TYPE{ARGS})
+TYPE_SPEC (({NUM_TYPE}({BS}"*"{BS}[0-9]+)?)|({NUM_TYPE}{KIND})|DOUBLE{BS_}COMPLEX|DOUBLE{BS_}PRECISION|{CHAR})
 
 INTENT_SPEC intent{BS}"("{BS}(in|out|in{BS}out){BS}")"
 ATTR_SPEC (ALLOCATABLE|DIMENSION{ARGS}|EXTERNAL|{INTENT_SPEC}|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PRIVATE|PUBLIC|SAVE|TARGET|RECURSIVE|PURE|ELEMENTAL)
@@ -687,6 +695,7 @@
 %x DeclContLine
 %x Parameterlist
 %x String
+%x Subprogend
 
 %%
  /*==================================================================*/
@@ -712,20 +721,27 @@
 
  /*-------- use statement -------------------------------------------*/
 <Start>"use"{BS_}                       { 
+  					  startFontClass("keyword"); 
   					  codifyLines(yytext);
+					  endFontClass();
                                           yy_push_state(YY_START);
 					  BEGIN(Use);     
                                         }
 <Use>{ID}                               {
-  					  startFontClass("keywordflow");
-  					  codifyLines(yytext);
-					  endFontClass();
+                                          QCString tmp = yytext;
+                                          tmp = tmp.lower();
+					  g_insideBody=TRUE;
+                                          generateLink(*g_code, yytext);
+					  g_insideBody=FALSE;
 
 					  /* append module name to use dict */
                                           useEntry = new UseEntry();
-					  useEntry->module = yytext;
-                                          useMembers->append(yytext, useEntry);
-					  addUse(yytext);
+					  //useEntry->module = yytext;
+                                          //useMembers->append(yytext, useEntry);
+					  //addUse(yytext);
+					  useEntry->module = tmp;
+                                          useMembers->append(tmp, useEntry);
+					  addUse(tmp);
                                         }           
 <Use>,{BS}"ONLY"                        { // TODO: rename
  					  codifyLines(yytext);
@@ -753,7 +769,11 @@
 	                                  if (!stricmp(yytext,"module")) currentModule="module";
 					}
 <ClassName>{ID}               	        {
-	                                  if (currentModule == "module") currentModule=yytext;
+	                                  if (currentModule == "module")
+                                          {
+                                            currentModule=yytext;
+                                            currentModule = currentModule.lower();
+                                          }
 					  generateLink(*g_code,yytext);
                                           yy_pop_state();
  					}
@@ -765,13 +785,6 @@
                                           currentModule=0;
 					  REJECT;
                                         }
-<Start>^{BS}"end"({BS}("program"|"module"|"type"|"interface")({BS_}{ID})?)?{BS}/(\n|!) {  //
-                                          endScope();
- 					  startFontClass("keyword"); 
-  					  codifyLines(yytext);
-					  endFontClass();
-                                        }
-
  /*-------- subprog definition -------------------------------------*/
 <Start>{TYPE_SPEC}{BS}/{SUBPROG}{BS_}  {   // TYPE_SPEC is for old function style function result
    					  startFontClass("keyword");
@@ -793,18 +806,31 @@
 <Subprog>"(".*                          { // ignore rest of line 
  					  codifyLines(yytext);
                                         }
-<Subprog>"\n"                           { codifyLines(yytext);
+<Subprog,Subprogend>"\n"                { codifyLines(yytext);
                                           yy_pop_state();
                                         }
-<Start>^{BS}"end"({BS}{SUBPROG}({BS_}{ID})?)?{BS}/(\n|!) {  // Fortran subroutine or function ends
+<Start>^{BS}"end"{BS}({SUBPROG}|"module"|"program"|"type"|"interface"){BS}     {  // Fortran subroutine or function ends
                                           //cout << "===> end function " << yytext << endl;
                                           endScope();
    					  startFontClass("keyword");
   					  codifyLines(yytext);
 					  endFontClass();
+                                          yy_push_state(YY_START);
+                                          BEGIN(Subprogend);
                                         }
+<Subprogend>{ID}/{BS}(\n|!)             {
+					  generateLink(*g_code,yytext);
+                                          yy_pop_state();
+                                        }
+<Start>^{BS}"end"{BS}({SUBPROG}|"module"|"program"|"type"|"interface"){BS}/(\n|!) {  // Fortran subroutine or function ends
+                                          //cout << "===> end function " << yytext << endl;
+                                          endScope();
+   					  startFontClass("keyword");
+  					  codifyLines(yytext);
+					  endFontClass();
+                                        }
  /*-------- variable declaration ----------------------------------*/
-<Start>"TYPE"{BS}"("                    {
+<Start>"type"{BS}"("                    {
                                           yy_push_state(YY_START);
 					  BEGIN(TypeDecl);
    					  startFontClass("keywordtype");
