Skip to content

Commit

Permalink
add option to disable alphabetical sorting of ckdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAday committed Jun 19, 2024
1 parent f8f68db commit 70ad20c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
47 changes: 39 additions & 8 deletions src/core/ulib_doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ CK_DLL_CTRL( CKDoc_examplesRoot_set );
CK_DLL_CGET( CKDoc_examplesRoot_get );
CK_DLL_CTRL( CKDoc_outputFormat_set );
CK_DLL_CGET( CKDoc_outputFormat_get );
CK_DLL_MFUN( CKDoc_sort_set );
CK_DLL_MFUN( CKDoc_sort_get );
CK_DLL_MFUN( CKDoc_genIndex );
CK_DLL_MFUN( CKDoc_genCSS );
CK_DLL_MFUN( CKDoc_genGroups );
Expand Down Expand Up @@ -172,6 +174,17 @@ DLL_QUERY ckdoc_query( Chuck_DL_Query * QUERY )
func->doc = "Set which output format is selected; see CKDoc.HTML, CKDoc.TEXT, CKDoc.MARKDOWN, CKDoc.JSON.";
if( !type_engine_import_mfun( env, func ) ) goto error;

// CKDoc disable sort
func = make_new_mfun( "int", "disableSort", CKDoc_sort_set );
func->add_arg("int", "disable");
func->doc = "Disable alphabetical sorting of the documentation.";
if( !type_engine_import_mfun( env, func ) ) goto error;

// CKDoc get sort status
func = make_new_mfun( "int", "disableSort", CKDoc_sort_get );
func->doc = "Get the current status of alphabetical sorting.";
if( !type_engine_import_mfun( env, func ) ) goto error;

// genIndex
func = make_new_mfun( "string", "genIndex", CKDoc_genIndex );
func->add_arg( "string", "indexTitle" );
Expand Down Expand Up @@ -811,6 +824,8 @@ CKDoc::CKDoc( Chuck_VM * vm )
// reset
m_format = FORMAT_NONE;
m_output = NULL;
// enable alphabetical sorting by default
m_disable_sort = false;

// default
setOutputFormat( FORMAT_HTML );
Expand Down Expand Up @@ -1025,7 +1040,7 @@ t_CKBOOL CKDoc::setOutputFormat( t_CKINT which )
// name: getOutputFormat()
// desc: get output format
//-----------------------------------------------------------------------------
t_CKINT CKDoc::getOutpuFormat() const
t_CKINT CKDoc::getOutputFormat() const
{
return m_format;
}
Expand Down Expand Up @@ -1316,12 +1331,15 @@ string CKDoc::genType( Chuck_Type * type, t_CKBOOL clearOutput )
}
}

// @kellyyyyyyyyyyyyyyyy @azaday make alphabetical sorting optional
// sort
sort( svars.begin(), svars.end(), ck_comp_value );
sort( mvars.begin(), mvars.end(), ck_comp_value );
sort( sfuncs.begin(), sfuncs.end(), ck_comp_func );
sort( mfuncs.begin(), mfuncs.end(), ck_comp_func );
sort( ctors.begin(), ctors.end(), ck_comp_func_args );
if (!m_disable_sort) {
sort( svars.begin(), svars.end(), ck_comp_value );
sort( mvars.begin(), mvars.end(), ck_comp_value );
sort( sfuncs.begin(), sfuncs.end(), ck_comp_func );
sort( mfuncs.begin(), mfuncs.end(), ck_comp_func );
sort( ctors.begin(), ctors.end(), ck_comp_func_args );
}

// whether to potentially insert a default constructor | 1.5.2.0
t_CKBOOL insertDefaultCtor = type_engine_has_implicit_def_ctor( type );
Expand Down Expand Up @@ -1731,14 +1749,27 @@ CK_DLL_CTRL( CKDoc_outputFormat_set )
// attempt to set
ckdoc->setOutputFormat( format );
// return (could be different than requested)
RETURN->v_int = ckdoc->getOutpuFormat();
RETURN->v_int = ckdoc->getOutputFormat();
}

CK_DLL_CGET( CKDoc_outputFormat_get )
{
CKDoc * ckdoc = (CKDoc *)OBJ_MEMBER_UINT(SELF, CKDoc_offset_data);
// return
RETURN->v_int = ckdoc->getOutpuFormat();
RETURN->v_int = ckdoc->getOutputFormat();
}

CK_DLL_MFUN( CKDoc_sort_set )
{
CKDoc * ckdoc = (CKDoc *)OBJ_MEMBER_UINT(SELF, CKDoc_offset_data);
ckdoc->m_disable_sort = GET_NEXT_INT(ARGS);
RETURN->v_int = ckdoc->m_disable_sort;
}

CK_DLL_MFUN( CKDoc_sort_get )
{
CKDoc * ckdoc = (CKDoc *)OBJ_MEMBER_UINT(SELF, CKDoc_offset_data);
RETURN->v_int = ckdoc->m_disable_sort;
}

CK_DLL_MFUN( CKDoc_genIndex )
Expand Down
4 changes: 3 additions & 1 deletion src/core/ulib_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class CKDoc
// set output format: CKDoc.HTML, CKDoc.TEXT, CKDoc.MARKDOWN, CKDoc.JSON
t_CKBOOL setOutputFormat( t_CKINT which );
// get output format
t_CKINT getOutpuFormat() const;
t_CKINT getOutputFormat() const;
// set base examples root path
void setExamplesRoot( const std::string & path );
// get base examples root path
Expand All @@ -196,6 +196,8 @@ class CKDoc
static const t_CKINT FORMAT_TEXT; // same as help
static const t_CKINT FORMAT_MARKDOWN; // not implemented
static const t_CKINT FORMAT_JSON; // not implemented
// sorting flag
bool m_disable_sort;

protected:
// write string to file
Expand Down

0 comments on commit 70ad20c

Please sign in to comment.