ohcount: /Users/andy/dev/ohcount/src/sourcefile.h File Reference

# /Users/andy/dev/ohcount/src/sourcefile.h File Reference

`#include "loc.h"`
`#include "parsed_language.h"`

Go to the source code of this file.

## Functions
SourceFile * | ohcount_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)
ParsedLanguageList * | ohcount_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)
LicenseList * | ohcount_sourcefile_get_license_list (SourceFile *sourcefile)
LocList * | ohcount_sourcefile_get_loc_list (SourceFile *sourcefile)
LocDeltaList * | ohcount_sourcefile_diff (SourceFile *from, SourceFile *to)
LocDelta * | ohcount_sourcefile_calc_loc_delta (SourceFile *from, const char *language, SourceFile *to)
void | ohcount_sourcefile_set_filenames (SourceFile *sourcefile, char **filenames)
char ** | ohcount_sourcefile_get_filenames (SourceFile *sourcefile)
void | ohcount_sourcefile_free (SourceFile *sourcefile)
SourceFileList * | ohcount_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)
LocList * | ohcount_sourcefile_list_analyze_languages (SourceFileList *list)
void | ohcount_sourcefile_list_free (SourceFileList *list)

## Function Documentation

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:

  | from | The reference SourceFile created by ohcount_sourcefile_new().
  | language | The language to calculate the LocDelta from.
  | to | The SourceFile to compare the reference SourceFile to (typically a later revision instead of a completely different SourceFile).

Returns:
  LocDelta

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:

  | from | The reference SourceFile created by ohcount_sourcefile_new().
  | to | The SourceFile to compare the reference SourceFile to (typically a later revision instead of a completely different SourceFile).

Returns:
  LocDeltaList

void ohcount_sourcefile_free | ( | SourceFile * | sourcefile | ) |

Frees a SourceFile created by ohcount_sourcefile_new().

Parameters:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().

Returns:
  pointer to string file contents.

int ohcount_sourcefile_get_contents_size | ( | SourceFile * | sourcefile | ) |

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

Parameters:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().

Returns:
  size of the file's contents.

char** ohcount_sourcefile_get_filenames | ( | SourceFile * | sourcefile | ) |

Returns a string array of the given SourceFile's directory contents. If the existing 'filenames' field is NULL, the directory is accessed and its listing is returned. The returned pointer and its contents are used internally and must not be 'free'd.

Parameters:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().

Returns:
  pointer to a list of filenames (NULL-pointer terminated).

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().

Returns:
  string language name.

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().

Returns:
  LicenseList

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().

Returns:
  LocList

ParsedLanguageList* ohcount_sourcefile_get_parsed_language_list | ( | SourceFile * | sourcefile | ) |

Returns the ParsedLanguageList parsed out of the given SourceFile.

Parameters:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().

Returns:
  ParsedLanguageList

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:

  | list | A SourceFileList created by ohcount_sourcefile_list_new().
  | directory | The directory whose contents are to be added to the list.

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:

  | list | a SourceFileList created by ohcount_sourcefile_list_new().
  | filepath | The full path to the file to be added to the list.

LocList* ohcount_sourcefile_list_analyze_languages | ( | SourceFileList * | list | ) |

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

Parameters:

  | list | A SourceFileList created by ohcount_sourcefile_list_new().

Returns:
  LocList

void ohcount_sourcefile_list_free | ( | SourceFileList * | list | ) |

Frees the memory allocated for a given SourceFileList.

Parameters:

  | list | A SourceFileList created by 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

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:

  | filepath | The path to a file on disk.

Returns:
  SourceFile

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().
  | callback | The callback function to call for every entity parsed.
  | userdata | Userdata to pass to the callback function.

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().
  | callback | The callback function to call for every line parsed.
  | userdata | Userdata to pass to the callback function.

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().
  | contents | The contents to set for sourcefile.

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().
  | diskpath | The real path to the file on disk.

void ohcount_sourcefile_set_filenames | ( | SourceFile * | sourcefile,
|  | char ** | filenames |
| ) |  |  |

Sets the given SourceFile's directory contents to the string array given. The given array is copied and may be 'free'd immediately.

Parameters:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().
  | filenames | String array of filenames. If NULL, the next call to ohcount_sourcefile_get_filenames will access the SourceFile's directory.

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:

  | sourcefile | A SourceFile created by ohcount_sourcefile_new().
  | language | The language to set the SourceFile to.