ohcount
Functions
sourcefile.h File Reference
#include "loc.h"
#include "parsed_language.h"

Go to the source code of this file.

Functions

SourceFileohcount_sourcefile_new (const char *filepath)
 
void ohcount_sourcefile_set_diskpath (SourceFile *sourcefile, const char *diskpath)
 
void ohcount_sourcefile_set_contents (SourceFile *sourcefile, const char *contents)
 
char * ohcount_sourcefile_get_contents (SourceFile *sourcefile)
 
int ohcount_sourcefile_get_contents_size (SourceFile *sourcefile)
 
void ohcount_sourcefile_set_language (SourceFile *sourcefile, const char *language)
 
const char * ohcount_sourcefile_get_language (SourceFile *sourcefile)
 
void ohcount_sourcefile_parse (SourceFile *sourcefile)
 
ParsedLanguageListohcount_sourcefile_get_parsed_language_list (SourceFile *sourcefile)
 
void ohcount_sourcefile_parse_with_callback (SourceFile *sourcefile, void(*callback)(const char *, const char *, int, int, void *), void *userdata)
 
void ohcount_sourcefile_parse_entities_with_callback (SourceFile *sourcefile, void(*callback)(const char *, const char *, int, int, void *), void *userdata)
 
LicenseListohcount_sourcefile_get_license_list (SourceFile *sourcefile)
 
LocListohcount_sourcefile_get_loc_list (SourceFile *sourcefile)
 
LocDeltaListohcount_sourcefile_diff (SourceFile *from, SourceFile *to)
 
LocDeltaohcount_sourcefile_calc_loc_delta (SourceFile *from, const char *language, SourceFile *to)
 
void ohcount_sourcefile_free (SourceFile *sourcefile)
 
SourceFileListohcount_sourcefile_list_new ()
 
void ohcount_sourcefile_list_add_file (SourceFileList *list, const char *filepath)
 
void ohcount_sourcefile_list_add_directory (SourceFileList *list, const char *directory)
 
LocListohcount_sourcefile_list_analyze_languages (SourceFileList *list)
 
void ohcount_sourcefile_list_free (SourceFileList *list)
 

Function Documentation

◆ ohcount_sourcefile_calc_loc_delta()

LocDelta * ohcount_sourcefile_calc_loc_delta ( SourceFile from,
const char *  language,
SourceFile to 
)

Returns a LocDelta reflecting the changes from one revision of a SourceFile to another for a given language. The given language is not copied and may not be 'free'd. Use a language defined in src/languages.h. The returned pointer must be 'free'd.

Parameters
fromThe reference SourceFile created by ohcount_sourcefile_new().
languageThe language to calculate the LocDelta from.
toThe SourceFile to compare the reference SourceFile to (typically a later revision instead of a completely different SourceFile).
Returns
LocDelta

◆ ohcount_sourcefile_diff()

LocDeltaList * ohcount_sourcefile_diff ( SourceFile from,
SourceFile to 
)

Returns a LocDeltaList reflecting the changes from one revision of a SourceFile to another for all languages. The returned pointer must be 'free'd.

Parameters
fromThe reference SourceFile created by ohcount_sourcefile_new().
toThe SourceFile to compare the reference SourceFile to (typically a later revision instead of a completely different SourceFile).
Returns
LocDeltaList

◆ ohcount_sourcefile_free()

void ohcount_sourcefile_free ( SourceFile sourcefile)

Frees a SourceFile created by ohcount_sourcefile_new().

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().

◆ ohcount_sourcefile_get_contents()

char * ohcount_sourcefile_get_contents ( SourceFile sourcefile)

Returns the file contents of a given SourceFile. The returned pointer is used internally and may not be 'free'd.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
Returns
pointer to string file contents.

◆ ohcount_sourcefile_get_contents_size()

int ohcount_sourcefile_get_contents_size ( SourceFile sourcefile)

Returns the size of the file contents of a given SourceFile.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
Returns
size of the file's contents.

◆ ohcount_sourcefile_get_language()

const char * ohcount_sourcefile_get_language ( SourceFile sourcefile)

Returns the detected language of a given SourceFile. The returned pointer is used internally and may not be 'free'd.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
Returns
string language name.

◆ ohcount_sourcefile_get_license_list()

LicenseList * ohcount_sourcefile_get_license_list ( SourceFile sourcefile)

Returns a LicenseList of detected licenses in the given SourceFile. The returned list and its contents are used internally and may not be 'free'd.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
Returns
LicenseList

◆ ohcount_sourcefile_get_loc_list()

LocList * ohcount_sourcefile_get_loc_list ( SourceFile sourcefile)

Returns a LocList of total lines of code in each language in the given SourceFile. The returned list and its contents are used internally and may not be 'free'd.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
Returns
LocList

◆ ohcount_sourcefile_get_parsed_language_list()

ParsedLanguageList * ohcount_sourcefile_get_parsed_language_list ( SourceFile sourcefile)

Returns the ParsedLanguageList parsed out of the given SourceFile.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
Returns
ParsedLanguageList

◆ ohcount_sourcefile_list_add_directory()

void ohcount_sourcefile_list_add_directory ( SourceFileList list,
const char *  directory 
)

Adds the contents of a given directory to a SourceFileList. The given directory may be 'free'd immediately.

Parameters
listA SourceFileList created by ohcount_sourcefile_list_new().
directoryThe directory whose contents are to be added to the list.

◆ ohcount_sourcefile_list_add_file()

void ohcount_sourcefile_list_add_file ( SourceFileList list,
const char *  filepath 
)

Adds a given file to a SourceFileList. The given filepath is copied and may be 'free'd immediately.

Parameters
lista SourceFileList created by ohcount_sourcefile_list_new().
filepathThe full path to the file to be added to the list.

◆ ohcount_sourcefile_list_analyze_languages()

LocList * ohcount_sourcefile_list_analyze_languages ( SourceFileList list)

Returns a new LocList for all files in the given SourceFileList.

Parameters
listA SourceFileList created by ohcount_sourcefile_list_new().
Returns
LocList

◆ ohcount_sourcefile_list_free()

void ohcount_sourcefile_list_free ( SourceFileList list)

Frees the memory allocated for a given SourceFileList.

Parameters
listA SourceFileList created by ohcount_sourcefile_list_new().

◆ ohcount_sourcefile_list_new()

SourceFileList * ohcount_sourcefile_list_new ( )

Creates a new SourceFileList that is initially empty. Files can be added using ohcount_sourcefile_list_add_file(). Directories can be added using ohcount_sourcefile_list_add_directory().

Returns
SourceFileList

◆ ohcount_sourcefile_new()

SourceFile * ohcount_sourcefile_new ( const char *  filepath)

Creates and returns a new SourceFile from a given filepath. The given filepath is copied and may be 'free'd immediately.

Parameters
filepathThe path to a file on disk.
Returns
SourceFile

◆ ohcount_sourcefile_parse()

void ohcount_sourcefile_parse ( SourceFile sourcefile)

Parses the given SourceFile with the default callback that keeps track of the number of lines of code, comments, and blank lines.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().

◆ ohcount_sourcefile_parse_entities_with_callback()

void ohcount_sourcefile_parse_entities_with_callback ( SourceFile sourcefile,
void(*)(const char *, const char *, int, int, void *)  callback,
void *  userdata 
)

Parses the given SourceFile with a specific callback. The callback is called for each entity parsed, not line.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
callbackThe callback function to call for every entity parsed.
userdataUserdata to pass to the callback function.

◆ ohcount_sourcefile_parse_with_callback()

void ohcount_sourcefile_parse_with_callback ( SourceFile sourcefile,
void(*)(const char *, const char *, int, int, void *)  callback,
void *  userdata 
)

Parses the given SourceFile with a specific callback. The callback is called for each line parsed, not entity.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
callbackThe callback function to call for every line parsed.
userdataUserdata to pass to the callback function.

◆ ohcount_sourcefile_set_contents()

void ohcount_sourcefile_set_contents ( SourceFile sourcefile,
const char *  contents 
)

Sets the contents of the given SourceFile. The given contents are copied and may be 'free'd immediately.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
contentsThe contents to set for sourcefile.

◆ ohcount_sourcefile_set_diskpath()

void ohcount_sourcefile_set_diskpath ( SourceFile sourcefile,
const char *  diskpath 
)

Sets the filepath on the disk of the given SourceFile. This is only used if the SourceFile's filepath field is not accurate, typically only in language detection.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
diskpathThe real path to the file on disk.

◆ ohcount_sourcefile_set_language()

void ohcount_sourcefile_set_language ( SourceFile sourcefile,
const char *  language 
)

Sets the language of a given SourceFile. The given language copied and may be 'free'd immediately.

Parameters
sourcefileA SourceFile created by ohcount_sourcefile_new().
languageThe language to set the SourceFile to.