Skip to content

Commit

Permalink
C header gen: optional extra text directly after the include guard (#199
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pixsperdavid authored Jan 31, 2024
1 parent cfd329c commit 370f8b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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

0 comments on commit 370f8b0

Please sign in to comment.