Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C header gen: optional extra text directly after the include guard #199

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/headers/_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ match_! {(
/// ```
guard: &'__ str,

/// Text included after the include guard of the header file
///
/// It defaults to an empty string
text_after_guard: &'__ str,

/// Sets up the banner of the generated C header file.
///
/// It defaults to:
Expand Down Expand Up @@ -362,11 +367,13 @@ impl Builder<'_, WhereTo> {
let lang = self.language.unwrap_or(Language::C);

let guard = self.guard();
let text_after_guard = self.text_after_guard();

match lang {
| Language::C => writeln!(definer.out(),
include_str!("templates/c/_prelude.h"),
guard = guard,
include_str!("templates/c/_prelude.h"),
guard = guard,
text_after_guard = text_after_guard,
),

| Language::CSharp => writeln!(definer.out(),
Expand Down Expand Up @@ -449,6 +456,15 @@ impl Builder<'_, WhereTo> {
)
}

fn text_after_guard(&'_ self)
-> String
{
match self.text_after_guard {
None => String::new(),
Some(s) => format!("\n\n{}\n", s)
}
}

/// Return the library name
fn lib_name ()
-> String
Expand Down
2 changes: 1 addition & 1 deletion src/headers/templates/c/_prelude.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef {guard}
#define {guard}
#define {guard}{text_after_guard}
#ifdef __cplusplus
extern "C" {{
#endif
Loading