@@ -900,7 +900,7 @@ void DocRef::parse()
900900
901901// ---------------------------------------------------------------------------
902902
903- DocCite::DocCite (DocParser *parser,DocNodeVariant *parent,const QCString &target,const QCString &) : DocNode(parser,parent)
903+ DocCite::DocCite (DocParser *parser,DocNodeVariant *parent,const QCString &target,const QCString &, int opt ) : DocNode(parser,parent)
904904{
905905 size_t numBibFiles = Config_getList (CITE_BIB_FILES).size ();
906906 // printf("DocCite::DocCite(target=%s)\n",qPrint(target));
@@ -909,17 +909,17 @@ DocCite::DocCite(DocParser *parser,DocNodeVariant *parent,const QCString &target
909909 const CitationManager &ct = CitationManager::instance ();
910910 const CiteInfo *cite = ct.find (target);
911911 // printf("cite=%p text='%s' numBibFiles=%d\n",cite,cite?qPrint(cite->text):"<null>",numBibFiles);
912+ m_option = opt;
913+ m_target = target;
912914 if (numBibFiles>0 && cite && !cite->text ().isEmpty ()) // ref to citation
913915 {
914- m_text = cite->text ();
915916 m_ref = " " ;
916917 m_anchor = ct.anchorPrefix ()+cite->label ();
917918 m_file = convertNameToFile (ct.fileName (),FALSE ,TRUE );
918919 // printf("CITE ==> m_text=%s,m_ref=%s,m_file=%s,m_anchor=%s\n",
919920 // qPrint(m_text),qPrint(m_ref),qPrint(m_file),qPrint(m_anchor));
920921 return ;
921922 }
922- m_text = target;
923923 if (numBibFiles==0 )
924924 {
925925 warn_doc_error (parser->context .fileName ,parser->tokenizer .getLineNr ()," \\ cite command found but no bib files specified via CITE_BIB_FILES!" );
@@ -936,6 +936,27 @@ DocCite::DocCite(DocParser *parser,DocNodeVariant *parent,const QCString &target
936936 }
937937}
938938
939+ QCString DocCite::getText () const
940+ {
941+ QCString txt;
942+ int opt = m_option;
943+ const CitationManager &ct = CitationManager::instance ();
944+ const CiteInfo *citeInfo = ct.find (m_target);
945+
946+ if (!(opt & CiteInfo::NOPAR_BIT)) txt += " [" ;
947+
948+ if (citeInfo)
949+ {
950+ if (opt & CiteInfo::NUMBER) txt += citeInfo->text ();
951+ else if (opt & CiteInfo::SHORTAUTHOR) txt += citeInfo->shortAuthor ();
952+ else if (opt & CiteInfo::YEAR) txt += citeInfo->year ();
953+ }
954+
955+ if (!(opt & CiteInfo::NOPAR_BIT)) txt += " ]" ;
956+ return txt;
957+ }
958+
959+
939960// ---------------------------------------------------------------------------
940961
941962DocLink::DocLink (DocParser *parser,DocNodeVariant *parent,const QCString &target) : DocCompoundNode(parser,parent)
@@ -3304,31 +3325,102 @@ Token DocPara::handleParamSection(const QCString &cmdName,
33043325void DocPara::handleCite (char cmdChar,const QCString &cmdName)
33053326{
33063327 AUTO_TRACE ();
3328+ QCString saveCmdName = cmdName;
33073329 // get the argument of the cite command.
33083330 Token tok=parser ()->tokenizer .lex ();
3309- if (!tok.is (TokenRetval::TK_WHITESPACE))
3331+
3332+ int option = CiteInfo::UNKNOWN;
3333+ bool nopar_bit = false ;
3334+ bool nocite_bit = false ;
3335+ if (tok.is (TokenRetval::TK_WORD) && parser ()->context .token ->name ==" {" )
3336+ {
3337+ parser ()->tokenizer .setStateOptions ();
3338+ parser ()->tokenizer .lex ();
3339+ StringVector optList=split (parser ()->context .token ->name .str ()," ," );
3340+ for (auto const &opt : optList)
3341+ {
3342+ if (opt == " number" )
3343+ {
3344+ if (option != CiteInfo::UNKNOWN)
3345+ {
3346+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Multiple options specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3347+ }
3348+ else
3349+ {
3350+ option = CiteInfo::NUMBER;
3351+ }
3352+ }
3353+ else if (opt == " year" )
3354+ {
3355+ if (option != CiteInfo::UNKNOWN)
3356+ {
3357+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Multiple options specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3358+ }
3359+ else
3360+ {
3361+ option = CiteInfo::YEAR;
3362+ }
3363+ }
3364+ else if (opt == " shortauthor" )
3365+ {
3366+ if (option != CiteInfo::UNKNOWN)
3367+ {
3368+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Multiple options specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3369+ }
3370+ else
3371+ {
3372+ option = CiteInfo::SHORTAUTHOR;
3373+ }
3374+ }
3375+ else if (opt == " nopar" ) nopar_bit = true ;
3376+ else if (opt == " nocite" ) nocite_bit = true ;
3377+ else
3378+ {
3379+ warn (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," Unkown option specified with \\ {}, discarding '{}'" , saveCmdName, opt);
3380+ }
3381+ }
3382+
3383+ if (option == CiteInfo::UNKNOWN) option = CiteInfo::NUMBER;
3384+ if (nopar_bit) option |= CiteInfo::NOPAR_BIT;
3385+ if (nocite_bit) option |= CiteInfo::NOCITE_BIT;
3386+
3387+ parser ()->tokenizer .setStatePara ();
3388+ tok=parser ()->tokenizer .lex ();
3389+ if (!tok.is (TokenRetval::TK_WHITESPACE))
3390+ {
3391+ warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," expected whitespace after \\ {} command" ,
3392+ saveCmdName);
3393+ return ;
3394+ }
3395+ }
3396+ else if (!tok.is (TokenRetval::TK_WHITESPACE))
33103397 {
33113398 warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," expected whitespace after '{:c}{}' command" ,
3312- cmdChar,cmdName );
3399+ cmdChar,saveCmdName );
33133400 return ;
33143401 }
3402+ else
3403+ {
3404+ option = CiteInfo::NUMBER;
3405+ }
3406+
33153407 parser ()->tokenizer .setStateCite ();
33163408 tok=parser ()->tokenizer .lex ();
33173409 if (tok.is_any_of (TokenRetval::TK_NONE,TokenRetval::TK_EOF))
33183410 {
3319- warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," unexpected end of comment block while parsing the "
3320- " argument of command '{:c}{}'" ,cmdChar,cmdName );
3411+ warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," THE ONE unexpected end of comment block while parsing the "
3412+ " argument of command '{:c}{}'" ,cmdChar,saveCmdName );
33213413 return ;
33223414 }
33233415 else if (!tok.is_any_of (TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
33243416 {
33253417 warn_doc_error (parser ()->context .fileName ,parser ()->tokenizer .getLineNr ()," unexpected token {} as the argument of '{:c}{}'" ,
3326- tok.to_string (),cmdChar,cmdName );
3418+ tok.to_string (),cmdChar,saveCmdName );
33273419 return ;
33283420 }
33293421 parser ()->context .token ->sectionId = parser ()->context .token ->name ;
33303422 children ().append <DocCite>(
3331- parser (),thisVariant (),parser ()->context .token ->name ,parser ()->context .context );
3423+ parser (),thisVariant (),parser ()->context .token ->name ,parser ()->context .context ,option );
33323424
33333425 parser ()->tokenizer .setStatePara ();
33343426}
0 commit comments