@@ -891,7 +891,7 @@ void DocRef::parse()
891891
892892// ---------------------------------------------------------------------------
893893
894- DocCite::DocCite (DocParser *parser,DocNodeVariant *parent,const QCString &target,const QCString &) : DocNode(parser,parent)
894+ DocCite::DocCite (DocParser *parser,DocNodeVariant *parent,const QCString &target,const QCString &, int opt ) : DocNode(parser,parent)
895895{
896896 size_t numBibFiles = Config_getList (CITE_BIB_FILES).size ();
897897 // printf("DocCite::DocCite(target=%s)\n",qPrint(target));
@@ -900,17 +900,17 @@ DocCite::DocCite(DocParser *parser,DocNodeVariant *parent,const QCString &target
900900 const CitationManager &ct = CitationManager::instance ();
901901 const CiteInfo *cite = ct.find (target);
902902 // printf("cite=%p text='%s' numBibFiles=%d\n",cite,cite?qPrint(cite->text):"<null>",numBibFiles);
903+ m_option = opt;
904+ m_target = target;
903905 if (numBibFiles>0 && cite && !cite->text ().isEmpty ()) // ref to citation
904906 {
905- m_text = cite->text ();
906907 m_ref = " " ;
907908 m_anchor = ct.anchorPrefix ()+cite->label ();
908909 m_file = convertNameToFile (ct.fileName (),FALSE ,TRUE );
909910 // printf("CITE ==> m_text=%s,m_ref=%s,m_file=%s,m_anchor=%s\n",
910911 // qPrint(m_text),qPrint(m_ref),qPrint(m_file),qPrint(m_anchor));
911912 return ;
912913 }
913- m_text = target;
914914 if (numBibFiles==0 )
915915 {
916916 warn_doc_error (parser->context .fileName ,parser->tokenizer .getLineNr ()," \\ cite command found but no bib files specified via CITE_BIB_FILES!" );
@@ -927,6 +927,27 @@ DocCite::DocCite(DocParser *parser,DocNodeVariant *parent,const QCString &target
927927 }
928928}
929929
930+ QCString DocCite::getText () const
931+ {
932+ QCString txt;
933+ int opt = m_option;
934+ const CitationManager &ct = CitationManager::instance ();
935+ const CiteInfo *citeInfo = ct.find (m_target);
936+
937+ if (!(opt & CiteInfo::NOPAR_BIT)) txt += " [" ;
938+
939+ if (citeInfo)
940+ {
941+ if (opt & CiteInfo::NUMBER) txt += citeInfo->text ();
942+ else if (opt & CiteInfo::SHORTAUTHOR) txt += citeInfo->shortAuthor ();
943+ else if (opt & CiteInfo::YEAR) txt += citeInfo->year ();
944+ }
945+
946+ if (!(opt & CiteInfo::NOPAR_BIT)) txt += " ]" ;
947+ return txt;
948+ }
949+
950+
930951// ---------------------------------------------------------------------------
931952
932953DocLink::DocLink (DocParser *parser,DocNodeVariant *parent,const QCString &target) : DocCompoundNode(parser,parent)
@@ -3295,31 +3316,102 @@ Token DocPara::handleParamSection(const QCString &cmdName,
32953316void DocPara::handleCite (char cmdChar,const QCString &cmdName)
32963317{
32973318 AUTO_TRACE ();
3319+ QCString saveCmdName = cmdName;
32983320 // get the argument of the cite command.
32993321 Token tok=parser ()->tokenizer .lex ();
3300- if (!tok.is (TokenRetval::TK_WHITESPACE))
3322+
3323+ int option = CiteInfo::UNKNOWN;
3324+ bool nopar_bit = false ;
3325+ bool nocite_bit = false ;
3326+ if (tok.is (TokenRetval::TK_WORD) && parser ()->context .token ->name ==" {" )
3327+ {
3328+ parser ()->tokenizer .setStateOptions ();
3329+ parser ()->tokenizer .lex ();
3330+ StringVector optList=split (parser ()->context .token ->name .str ()," ," );
3331+ for (auto const &opt : optList)
3332+ {
3333+ if (opt == " number" )
3334+ {
3335+ if (option != CiteInfo::UNKNOWN)
3336+ {
3337+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Multiple options specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3338+ }
3339+ else
3340+ {
3341+ option = CiteInfo::NUMBER;
3342+ }
3343+ }
3344+ else if (opt == " year" )
3345+ {
3346+ if (option != CiteInfo::UNKNOWN)
3347+ {
3348+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Multiple options specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3349+ }
3350+ else
3351+ {
3352+ option = CiteInfo::YEAR;
3353+ }
3354+ }
3355+ else if (opt == " shortauthor" )
3356+ {
3357+ if (option != CiteInfo::UNKNOWN)
3358+ {
3359+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Multiple options specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3360+ }
3361+ else
3362+ {
3363+ option = CiteInfo::SHORTAUTHOR;
3364+ }
3365+ }
3366+ else if (opt == " nopar" ) nopar_bit = true ;
3367+ else if (opt == " nocite" ) nocite_bit = true ;
3368+ else
3369+ {
3370+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Unkown option specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3371+ }
3372+ }
3373+
3374+ if (option == CiteInfo::UNKNOWN) option = CiteInfo::NUMBER;
3375+ if (nopar_bit) option |= CiteInfo::NOPAR_BIT;
3376+ if (nocite_bit) option |= CiteInfo::NOCITE_BIT;
3377+
3378+ parser ()->tokenizer .setStatePara ();
3379+ tok=parser ()->tokenizer .lex ();
3380+ if (!tok.is (TokenRetval::TK_WHITESPACE))
3381+ {
3382+ warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," expected whitespace after \\ {} command" ,
3383+ saveCmdName);
3384+ return ;
3385+ }
3386+ }
3387+ else if (!tok.is (TokenRetval::TK_WHITESPACE))
33013388 {
33023389 warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," expected whitespace after '{:c}{}' command" ,
3303- cmdChar,cmdName );
3390+ cmdChar,saveCmdName );
33043391 return ;
33053392 }
3393+ else
3394+ {
3395+ option = CiteInfo::NUMBER;
3396+ }
3397+
33063398 parser ()->tokenizer .setStateCite ();
33073399 tok=parser ()->tokenizer .lex ();
33083400 if (tok.is_any_of (TokenRetval::TK_NONE,TokenRetval::TK_EOF))
33093401 {
3310- warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," unexpected end of comment block while parsing the "
3311- " argument of command '{:c}{}'" ,cmdChar,cmdName );
3402+ warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," THE ONE unexpected end of comment block while parsing the "
3403+ " argument of command '{:c}{}'" ,cmdChar,saveCmdName );
33123404 return ;
33133405 }
33143406 else if (!tok.is_any_of (TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
33153407 {
33163408 warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," unexpected token {} as the argument of '{:c}{}'" ,
3317- tok.to_string (),cmdChar,cmdName );
3409+ tok.to_string (),cmdChar,saveCmdName );
33183410 return ;
33193411 }
33203412 parser ()->context .token ->sectionId = parser ()->context .token ->name ;
33213413 children ().append <DocCite>(
3322- parser (),thisVariant (),parser ()->context .token ->name ,parser ()->context .context );
3414+ parser (),thisVariant (),parser ()->context .token ->name ,parser ()->context .context ,option );
33233415
33243416 parser ()->tokenizer .setStatePara ();
33253417}
0 commit comments