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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iliya.saroukha
create-prog-app
Commits
43b5154e
Commit
43b5154e
authored
2 years ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
finished algo template function, everything works but looks like a mess
parent
d882ff3c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+47
-14
47 additions, 14 deletions
src/main.rs
with
47 additions
and
14 deletions
src/main.rs
+
47
−
14
View file @
43b5154e
...
@@ -4,6 +4,8 @@ mod to_stdout;
...
@@ -4,6 +4,8 @@ mod to_stdout;
use
std
::
fs
::{
create_dir
,
File
};
use
std
::
fs
::{
create_dir
,
File
};
use
std
::
io
::
Write
;
use
std
::
io
::
Write
;
/// # Working function
/// ## Consider refactoring this mess
fn
algo_template
()
{
fn
algo_template
()
{
let
struct_dir
=
"struct"
;
let
struct_dir
=
"struct"
;
let
slash
=
"/"
;
let
slash
=
"/"
;
...
@@ -12,47 +14,79 @@ fn algo_template() {
...
@@ -12,47 +14,79 @@ fn algo_template() {
let
dir_name
=
from_stdin
::
input_from_stdin
();
let
dir_name
=
from_stdin
::
input_from_stdin
();
// Creating root path string
// Creating root path string
let
root_dir_name
=
&
(
dir_name
.
trim
()
.
to_owned
()
+
slash
);
let
root_dir_name
=
&
(
dir_name
.to_owned
()
+
slash
);
// Creating root directory using std::fs
// Creating root directory using std::fs
create_dir
(
&
root_dir_name
)
.expect
(
&
format!
(
"Failed at creating {} directory"
,
root_dir_name
));
create_dir
(
&
root_dir_name
)
.expect
(
&
format!
(
"Failed at creating {} directory"
,
root_dir_name
));
print!
(
"
\n
Please specify the name of the main file (w/ the extension): "
);
print!
(
"
\n
Please specify the name of the main file (w/ the extension): "
);
let
main_name
=
from_stdin
::
input_from_stdin
();
let
main_name
=
from_stdin
::
input_from_stdin
();
let
main_path
=
&
(
root_dir_name
.to_owned
()
+
main_name
.trim
());
let
main_path
=
&
(
root_dir_name
.to_owned
()
+
main_name
.as_str
());
// Creating struct dir
let
struct_path
=
&
(
root_dir_name
.to_owned
()
+
struct_dir
+
slash
);
// Creating string for header file path
let
header_file_name
=
&
(
dir_name
.to_owned
()
+
".h"
);
// Creating implementation
let
impl_file_name
=
&
(
dir_name
.to_owned
()
+
".c"
);
let
data_struct_header
=
&
(
struct_path
.to_owned
()
+
header_file_name
);
// Create main file in root dir
// Create main file in root dir
let
mut
main_file
=
let
mut
main_file
=
File
::
create
(
&
main_path
)
.expect
(
&
format!
(
"Cannot create '{}' file"
,
main_path
.trim
()));
File
::
create
(
&
main_path
)
.expect
(
&
format!
(
"Cannot create '{}' file"
,
main_path
));
let
mut
makefile
=
File
::
create
(
&
(
root_dir_name
.to_owned
()
+
"Makefile"
))
.expect
(
"Cannot create Makefile"
);
// Storing code template for main file into variable
// Storing code template for main file into variable
let
main_template
=
code_templates
::
template_for_main
()
.to_string
();
let
main_template
=
code_templates
::
template_for_main
(
struct_dir
.to_owned
()
+
slash
+
header_file_name
)
.to_string
();
let
make_template
=
code_templates
::
template_for_makefile_algo
(
&
mut
header_file_name
.clone
(),
&
mut
main_name
.clone
(),
)
.to_string
();
// Writing to main file
// Writing to main file
main_file
main_file
.write_all
(
main_template
.as_bytes
())
.write_all
(
main_template
.as_bytes
())
.expect
(
&
format!
(
"Not able to write to {}"
,
main_path
.trim
()
));
.expect
(
&
format!
(
"Not able to write to {}"
,
main_path
));
// Creating struct dir
makefile
let
struct_path
=
&
(
root_dir_name
.trim
()
.to_owned
()
+
struct_dir
+
slash
);
.write_all
(
make_template
.as_bytes
())
.expect
(
"Not able to write to Makefile"
);
create_dir
(
&
struct_path
)
.expect
(
&
format!
(
"Failed at creating {} directory"
,
struct_path
));
create_dir
(
&
struct_path
)
.expect
(
&
format!
(
"Failed at creating {} directory"
,
struct_path
));
// Creating string for header file path
let
header_file_name
=
&
(
dir_name
.trim
()
.to_owned
()
+
".h"
);
let
data_struct_header
=
&
(
struct_path
.to_owned
()
+
header_file_name
);
// Creating header file in struct dir
// Creating header file in struct dir
let
mut
header_file
=
File
::
create
(
&
data_struct_header
)
let
mut
header_file
=
File
::
create
(
&
data_struct_header
)
.expect
(
&
format!
(
"Cannot create '{}' file"
,
data_struct_header
));
.expect
(
&
format!
(
"Cannot create '{}' file"
,
data_struct_header
));
let
data_struct_impl
=
&
(
struct_path
.to_owned
()
+
impl_file_name
);
// Creating implementation file in struct dir
let
mut
impl_file
=
File
::
create
(
&
data_struct_impl
)
.expect
(
&
format!
(
"Cannot create '{}' file"
,
data_struct_impl
));
// Storing code template for header file into variable
// Storing code template for header file into variable
let
header_template
=
code_templates
::
template_for_header
(
header_file_name
)
.to_string
();
let
header_template
=
code_templates
::
template_for_header
(
&
mut
header_file_name
.clone
())
.to_string
();
let
impl_template
=
code_templates
::
template_for_implementation
(
&
mut
impl_file_name
.clone
())
.to_string
();
// Writing to header file
// Writing to header file
header_file
header_file
.write_all
(
header_template
.as_bytes
())
.write_all
(
header_template
.as_bytes
())
.expect
(
&
format!
(
"Not able to write to {}"
,
data_struct_header
))
.expect
(
&
format!
(
"Not able to write to {}"
,
data_struct_header
));
impl_file
.write_all
(
impl_template
.as_bytes
())
.expect
(
&
format!
(
"Not able to write to {}"
,
data_struct_impl
));
}
}
fn
exam_template
()
{}
fn
exam_template
()
{}
...
@@ -63,7 +97,6 @@ fn main() {
...
@@ -63,7 +97,6 @@ fn main() {
print!
(
"What's your choice: "
);
print!
(
"What's your choice: "
);
match
from_stdin
::
input_from_stdin
()
match
from_stdin
::
input_from_stdin
()
.trim
()
.parse
::
<
u8
>
()
.parse
::
<
u8
>
()
.expect
(
"Please input an integer"
)
.expect
(
"Please input an integer"
)
{
{
...
...
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