Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
create-prog-app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iliya.saroukha
create-prog-app
Commits
d882ff3c
Commit
d882ff3c
authored
2 years ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
created template for algo makefile
parent
668d1062
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/code_templates/mod.rs
+63
-9
63 additions, 9 deletions
src/code_templates/mod.rs
with
63 additions
and
9 deletions
src/code_templates/mod.rs
+
63
−
9
View file @
d882ff3c
use
simplegen
::
CodeBuffer
;
pub
fn
template_for_header
(
filename
:
&
str
)
->
CodeBuffer
{
pub
fn
template_for_header
(
filename
:
&
mut
String
)
->
CodeBuffer
{
let
mut
buffer
=
CodeBuffer
::
new
(
4
);
let
mut
mod_filename
=
filename
.to_string
();
// Removing extension from filename
for
_
in
0
..
2
{
mod_
filename
.pop
();
filename
.pop
();
}
buffer
.println
(
format!
(
"#ifndef _{}_H_"
,
mod_
filename
.to_uppercase
())
.as_str
());
buffer
.println
(
format!
(
"#define _{}_H_"
,
mod_
filename
.to_uppercase
())
.as_str
());
buffer
.println
(
format!
(
"#ifndef _{}_H_"
,
filename
.to_uppercase
())
.as_str
());
buffer
.println
(
format!
(
"#define _{}_H_"
,
filename
.to_uppercase
())
.as_str
());
buffer
.println
(
""
);
buffer
.println
(
format!
(
"typedef struct _{}_t"
,
mod_
filename
.to_lowercase
())
.as_str
());
buffer
.println
(
format!
(
"typedef struct _{}_t"
,
filename
.to_lowercase
())
.as_str
());
buffer
.println
(
"{"
);
buffer
.println
(
""
);
buffer
.println
(
format!
(
"}} {}_t;"
,
mod_
filename
.to_lowercase
())
.as_str
());
buffer
.println
(
format!
(
"}} {}_t;"
,
filename
.to_lowercase
())
.as_str
());
buffer
.println
(
""
);
buffer
.println
(
"#endif"
);
return
buffer
;
}
pub
fn
template_for_main
()
->
CodeBuffer
{
pub
fn
template_for_implementation
(
hfile_name
:
&
mut
String
)
->
CodeBuffer
{
let
mut
buffer
=
CodeBuffer
::
new
(
4
);
for
_
in
0
..
1
{
hfile_name
.pop
();
}
buffer
.println
(
format!
(
"#include
\"
{}h
\"
"
,
hfile_name
.to_lowercase
())
.as_str
());
return
buffer
;
}
pub
fn
template_for_main
(
path_to_hfile
:
String
)
->
CodeBuffer
{
let
mut
buffer
=
CodeBuffer
::
new
(
4
);
buffer
.println
(
"#include <stdio.h>"
);
buffer
.println
(
"#include <stdlib.h>"
);
buffer
.println
(
format!
(
"#include
\"
{}
\"
"
,
path_to_hfile
)
.as_str
());
buffer
.println
(
""
);
buffer
.println
(
"int main()"
);
buffer
.println
(
"{"
);
...
...
@@ -37,3 +48,46 @@ pub fn template_for_main() -> CodeBuffer {
return
buffer
;
}
pub
fn
template_for_makefile_algo
(
hfile_name
:
&
mut
String
,
main_name
:
&
mut
String
)
->
CodeBuffer
{
let
mut
buffer
=
CodeBuffer
::
new
(
4
);
// Removing extensions
for
_
in
0
..
2
{
hfile_name
.pop
();
main_name
.pop
();
}
buffer
.println
(
"# This file was automatically generated by `create-prog-app`"
);
buffer
.println
(
"CC:=gcc"
);
buffer
.println
(
"CFLAGS:=-Wall -Wextra -g -pedantic -fsanitize=address -fsanitize=leak -lm"
);
buffer
.println
(
"VPATH:=struct"
);
buffer
.println
(
"# Due to the oddity of MAKE and the fact you cannot generate
\"
true
\"
tabs,"
);
buffer
.println
(
"# the
\"
tab
\"
character is replaced by spaces."
);
buffer
.println
(
"# `create-prog-app` STRONGLY advises you not to change/modify the line below"
);
buffer
.println
(
".RECIPEPREFIX:=$(.RECIPEPREFIX) "
);
buffer
.println
(
""
);
buffer
.println
(
format!
(
"{}: {}.o {}.o"
,
main_name
.to_lowercase
(),
main_name
.to_lowercase
(),
hfile_name
.to_lowercase
()
)
.as_str
(),
);
buffer
.println_right
(
"$(CC) $(CFLAGS) $^ -o $@"
);
buffer
.println_left
(
""
);
buffer
.println
(
format!
(
"{0}.o: {0}.c"
,
main_name
.to_lowercase
())
.as_str
());
buffer
.println_right
(
"$(CC) $(CFLAGS) -c $<"
);
buffer
.println_left
(
""
);
buffer
.println
(
format!
(
"{0}.o: {0}.c {0}.h"
,
hfile_name
.to_lowercase
())
.as_str
());
buffer
.println_right
(
"$(CC) $(CFLAGS) -c $<"
);
buffer
.println_left
(
""
);
buffer
.println
(
"clean:"
);
buffer
.println_right
(
format!
(
"rm -f *.o {}"
,
main_name
.to_lowercase
())
.as_str
());
buffer
.println_left
(
""
);
buffer
.println
(
format!
(
"rebuild: clean {}"
,
main_name
.to_lowercase
())
.as_str
());
return
buffer
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment