Changed stuct variables to private in oop.rs
Fixed multi-threading?
This commit is contained in:
parent
b0e8e352c8
commit
c7b34a0ca1
2 changed files with 215 additions and 74 deletions
135
src/main.rs
135
src/main.rs
|
@ -3,54 +3,92 @@ use std::thread::{self, JoinHandle};
|
|||
use clap::Parser;
|
||||
use roxmltree::{self, Document};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
/*#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
#[arg(short, long)]
|
||||
dir: String
|
||||
}
|
||||
}*/
|
||||
|
||||
fn main() {
|
||||
let arg = Args::parse();
|
||||
//let arg = Args::parse();
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
|
||||
|
||||
let mut objects_filenames: Vec<String> = Vec::new();
|
||||
let mut messages_filenames: Vec<String> = Vec::new();
|
||||
let handles: Vec<thread::JoinHandle<()>> = Vec::new();
|
||||
let mut file_names: Vec<String> = Vec::new();
|
||||
|
||||
let mut text: Vec<String> = args[1..].to_vec();
|
||||
//let text = std::fs::read_to_string(&args[1..]).unwrap();
|
||||
|
||||
let opt = roxmltree::ParsingOptions {
|
||||
allow_dtd: true,
|
||||
..roxmltree::ParsingOptions::default()
|
||||
};
|
||||
|
||||
let paths = std::fs::read_dir(arg.dir.clone()).expect("No directory found.");
|
||||
let paths2 = std::fs::read_dir(arg.dir.clone()).expect("No directory found.");
|
||||
//let paths = std::fs::read_dir(arg.dir.clone()).expect("No directory found.");
|
||||
//let paths2 = std::fs::read_dir(arg.dir.clone()).expect("No directory found.");
|
||||
let mut temp:Vec<JoinHandle<()>> = Vec::new();
|
||||
for path in paths2 {
|
||||
match path {
|
||||
for path in text{
|
||||
file_names.push(path.to_string());
|
||||
objects_filenames.push(file_names.last().unwrap().trim_end_matches(".xml").to_string() + "_objects.rs");
|
||||
messages_filenames.push(file_names.last().unwrap().trim_end_matches(".xml").to_string() + "_messages.rs");
|
||||
|
||||
temp.push(thread::spawn(move || {
|
||||
//let file_names2: &str;
|
||||
//println!("{:?}", path.as_ref().unwrap().file_name().to_string_lossy());
|
||||
println!("{:?}", path);
|
||||
if path.to_string().contains(".xml") {
|
||||
/*match path {
|
||||
Ok(real_path) => {
|
||||
file_names2 = real_path.path().file_name().unwrap().to_string_lossy().to_string();
|
||||
},
|
||||
Err(_) => {panic!("Bad file path.")}
|
||||
};*/
|
||||
let contents = std::fs::read_to_string(path).expect("read_to_string didn't work");
|
||||
let doc = roxmltree::Document::parse_with_options(&contents, opt);
|
||||
println!("{:?}", doc);
|
||||
match doc {
|
||||
Ok(doc_good) => {
|
||||
output(parse(&doc_good));
|
||||
},
|
||||
Err(doc_bad) => {
|
||||
println!("{:?}", doc_bad);
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
};
|
||||
/*match path {
|
||||
Ok(real_path) => {
|
||||
file_names.push(real_path.path().to_string_lossy().to_string());
|
||||
},
|
||||
Err(_) => {panic!("Bad file path.")}
|
||||
};
|
||||
objects_filenames.push(file_names.last().unwrap().trim_end_matches(".xml").to_string() + "_objects.rs");
|
||||
messages_filenames.push(file_names.last().unwrap().trim_end_matches(".xml").to_string() + "_messages.rs");
|
||||
}
|
||||
for path in paths {
|
||||
};*/
|
||||
|
||||
/*for path in text {
|
||||
temp.push(thread::spawn(move || {
|
||||
let file_names2;
|
||||
match path {
|
||||
Ok(real_path) => {
|
||||
file_names2 = real_path.path().to_string_lossy().to_string();
|
||||
},
|
||||
Err(_) => {panic!("Bad file path.")}
|
||||
};
|
||||
let doc = roxmltree::Document::parse_with_options(&file_names2.as_str(), opt).unwrap();
|
||||
output(parse(&doc));
|
||||
let file_names2: &str;
|
||||
//println!("{:?}", path.as_ref().unwrap().file_name().to_string_lossy());
|
||||
if path.to_string().contains(".xml") {
|
||||
/*match path {
|
||||
Ok(real_path) => {
|
||||
file_names2 = real_path.path().file_name().unwrap().to_string_lossy().to_string();
|
||||
},
|
||||
Err(_) => {panic!("Bad file path.")}
|
||||
};*/
|
||||
println!("{:?}", path);
|
||||
let doc = roxmltree::Document::parse_with_options(path, opt);
|
||||
println!("{:?}", doc);
|
||||
output(parse(&doc.expect("Thread couldn't spawn")));
|
||||
}
|
||||
}));
|
||||
}
|
||||
}*/
|
||||
|
||||
for handle in handles {
|
||||
for handle in temp {
|
||||
handle.join().unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +107,7 @@ fn parse(doc: &Document) -> oop::Family{
|
|||
if attr.name() != "comment" {
|
||||
print!("{:?}={:?} " , attr.name(), attr.value());
|
||||
if attr.name() == "name" {
|
||||
family.name = attr.value().to_string();
|
||||
family.clone().set_name(attr.value().to_string());
|
||||
}
|
||||
else {
|
||||
panic!("No family name found. Failed to initialize data structure.")
|
||||
|
@ -104,7 +142,7 @@ fn parse(doc: &Document) -> oop::Family{
|
|||
if child4.is_element() {
|
||||
print!("\n {:?}: {:?}={:?} {:?}={:?}", child4.tag_name(), child4.attribute_node("name").unwrap().name().to_string(), child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("defaultvalue").unwrap().name().to_string(), child4.attribute_node("defaultvalue").unwrap().value().to_string());
|
||||
if child4.tag_name().name().to_string().as_str() == "SPECIES" {
|
||||
family.genera.last_mut().unwrap().push(oop::Species::new(child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("defaultvalue").unwrap().value().to_string(), Vec::new()));
|
||||
family.clone().get_genera().last_mut().unwrap().push_species(oop::Species::new(child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("defaultvalue").unwrap().value().to_string(), Vec::new()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,14 +159,14 @@ fn parse(doc: &Document) -> oop::Family{
|
|||
}
|
||||
}
|
||||
if let Some(f) = child2.attribute_node("family") {
|
||||
if f.value() == family.name {
|
||||
for genus in family.genera.as_mut_slice() {
|
||||
if f.value() == family.clone().get_name() {
|
||||
for genus in family.clone().get_genera().as_mut_slice() {
|
||||
if let Some(g) = child2.attribute_node("genus") {
|
||||
if g.value() == genus.name {
|
||||
for species in genus.species.as_mut_slice() {
|
||||
if g.value() == genus.clone().get_name() {
|
||||
for species in genus.clone().get_species().as_mut_slice() {
|
||||
if let Some(s) = child2.attribute_node("species") {
|
||||
if s.value() == species.name {
|
||||
species.push(oop::Object::new(child2.attribute_node("class").unwrap().value().to_string(), child2.attribute_node("abrv").unwrap().value().to_string(), child2.attribute_node("version").unwrap().value().to_string(), Vec::new()))
|
||||
if s.value() == species.clone().get_name() {
|
||||
species.push_object(oop::Object::new(child2.attribute_node("class").unwrap().value().to_string(), child2.attribute_node("abrv").unwrap().value().to_string(), child2.attribute_node("version").unwrap().value().to_string(), Vec::new()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,15 +196,15 @@ fn parse(doc: &Document) -> oop::Family{
|
|||
}
|
||||
if child4.tag_name().name().to_string().as_str() == "MEMBER" {
|
||||
if let Some(s) = child2.attribute_node("family") {
|
||||
if s.value() == family.name{
|
||||
for genus in family.genera.as_mut_slice() {
|
||||
if s.value() == family.clone().get_name(){
|
||||
for genus in family.clone().get_genera().as_mut_slice() {
|
||||
if let Some(g) = child2.attribute_node("genus") {
|
||||
if g.value() == genus.name {
|
||||
for species in genus.species.as_mut_slice() {
|
||||
if g.value() == genus.clone().get_name() {
|
||||
for species in genus.clone().get_species().as_mut_slice() {
|
||||
if let Some(s) = child2.attribute_node("species") {
|
||||
if s.value() == species.name {
|
||||
for object in species.objects.as_mut_slice() {
|
||||
object.push(oop::ObjectMember::new(child4.attribute_node("type").unwrap().value().to_string(), child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("minversion").unwrap().value().to_string(), child4.attribute_node("maxversion").unwrap().value().to_string(), Vec::new()));
|
||||
if s.value() == species.clone().get_name() {
|
||||
for object in species.clone().get_objects().as_mut_slice() {
|
||||
object.push_object_member(oop::ObjectMember::new(child4.attribute_node("type").unwrap().value().to_string(), child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("minversion").unwrap().value().to_string(), child4.attribute_node("maxversion").unwrap().value().to_string(), Vec::new()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -199,22 +237,22 @@ fn parse(doc: &Document) -> oop::Family{
|
|||
}
|
||||
if child4.tag_name().name().to_string().as_str() == "ENUM" {
|
||||
if let Some(f) = child2.attribute_node("family") {
|
||||
if f.value() == family.name {
|
||||
for genus in family.genera.as_mut_slice() {
|
||||
if f.value() == family.clone().get_name() {
|
||||
for genus in family.clone().get_genera().as_mut_slice() {
|
||||
if let Some(g) = child2.attribute_node("genus") {
|
||||
if g.value() == genus.name {
|
||||
for species in genus.species.as_mut_slice() {
|
||||
if g.value() == genus.clone().get_name() {
|
||||
for species in genus.clone().get_species().as_mut_slice() {
|
||||
if let Some(s) = child2.attribute_node("species") {
|
||||
if s.value() == species.name {
|
||||
for object in species.objects.as_mut_slice() {
|
||||
for member in object.members.as_mut_slice() {
|
||||
if s.value() == species.clone().get_name() {
|
||||
for object in species.clone().get_objects().as_mut_slice() {
|
||||
for member in object.clone().get_members().as_mut_slice() {
|
||||
if let Some(m) = child3.attribute_node("name") {
|
||||
if m.value() == member.name {
|
||||
if m.value() == member.clone().get_name() {
|
||||
if child4.has_attribute("defaultvalue") {
|
||||
member.enumerations.push(oop::MemberEnumeration::new(child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("defaultvalue").unwrap().value().to_string()));
|
||||
member.clone().get_enumerations().push(oop::MemberEnumeration::new(child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("defaultvalue").unwrap().value().to_string()));
|
||||
}
|
||||
else {
|
||||
member.enumerations.push(oop::MemberEnumeration::new(child4.attribute_node("name").unwrap().value().to_string(), String::new()));
|
||||
member.clone().get_enumerations().push(oop::MemberEnumeration::new(child4.attribute_node("name").unwrap().value().to_string(), String::new()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -267,6 +305,7 @@ fn parse(doc: &Document) -> oop::Family{
|
|||
}
|
||||
}
|
||||
family.push_messages(messages);
|
||||
println!("{:?}", family);
|
||||
return family;
|
||||
}
|
||||
|
||||
|
|
154
src/oop.rs
154
src/oop.rs
|
@ -9,11 +9,11 @@ const MESSAGETYPE: phf::OrderedMap<&'static str, &'static str> = phf_ordered_map
|
|||
"Stream" => "streams",
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Family {
|
||||
pub name: String,
|
||||
pub genera: Vec<Genus>,
|
||||
pub messages: Vec<Vec<String>>,
|
||||
name: String,
|
||||
genera: Vec<Genus>,
|
||||
messages: Vec<Vec<String>>,
|
||||
}
|
||||
|
||||
impl Family {
|
||||
|
@ -21,6 +21,24 @@ impl Family {
|
|||
Self { name, genera, messages }
|
||||
}
|
||||
|
||||
pub fn get_name(self) -> String{
|
||||
return self.name
|
||||
}
|
||||
|
||||
pub fn set_name(mut self, name: String){
|
||||
if self.name.len() == 0 {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_genera(self) -> Vec<Genus>{
|
||||
return self.genera
|
||||
}
|
||||
|
||||
pub fn get_messages(self) -> Vec<Vec<String>>{
|
||||
return self.messages
|
||||
}
|
||||
|
||||
pub fn push_genus(&mut self, genus: Genus) {
|
||||
self.genera.push(genus);
|
||||
}
|
||||
|
@ -34,10 +52,10 @@ impl Family {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Genus {
|
||||
pub name: String,
|
||||
pub species: Vec<Species>,
|
||||
name: String,
|
||||
species: Vec<Species>,
|
||||
}
|
||||
|
||||
impl Genus {
|
||||
|
@ -45,16 +63,24 @@ impl Genus {
|
|||
Self { name, species }
|
||||
}
|
||||
|
||||
pub fn push(&mut self, species: Species) {
|
||||
pub fn get_name(self) -> String{
|
||||
return self.name
|
||||
}
|
||||
|
||||
pub fn get_species(self) -> Vec<Species>{
|
||||
return self.species
|
||||
}
|
||||
|
||||
pub fn push_species(&mut self, species: Species) {
|
||||
self.species.push(species);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Species {
|
||||
pub name: String,
|
||||
name: String,
|
||||
default_value: String,
|
||||
pub objects: Vec<Object>,
|
||||
objects: Vec<Object>,
|
||||
}
|
||||
|
||||
impl Species {
|
||||
|
@ -62,17 +88,29 @@ impl Species {
|
|||
Self { name, default_value, objects }
|
||||
}
|
||||
|
||||
pub fn push(&mut self, object: Object) {
|
||||
pub fn get_name(self) -> String{
|
||||
return self.name
|
||||
}
|
||||
|
||||
pub fn get_default_value(self) -> String{
|
||||
return self.default_value
|
||||
}
|
||||
|
||||
pub fn get_objects(self) -> Vec<Object>{
|
||||
return self.objects
|
||||
}
|
||||
|
||||
pub fn push_object(&mut self, object: Object) {
|
||||
self.objects.push(object);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Object {
|
||||
pub name: String,
|
||||
name: String,
|
||||
abrv: String,
|
||||
version: String,
|
||||
pub members: Vec<ObjectMember>,
|
||||
members: Vec<ObjectMember>,
|
||||
}
|
||||
|
||||
impl Object {
|
||||
|
@ -80,18 +118,34 @@ impl Object {
|
|||
Self { name, abrv, version, members }
|
||||
}
|
||||
|
||||
pub fn push(&mut self, member: ObjectMember) {
|
||||
pub fn get_name(self) -> String{
|
||||
return self.name
|
||||
}
|
||||
|
||||
pub fn get_abrv(self) -> String{
|
||||
return self.abrv
|
||||
}
|
||||
|
||||
pub fn get_version(self) -> String{
|
||||
return self.version
|
||||
}
|
||||
|
||||
pub fn get_members(self) -> Vec<ObjectMember>{
|
||||
return self.members
|
||||
}
|
||||
|
||||
pub fn push_object_member(&mut self, member: ObjectMember) {
|
||||
self.members.push(member);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ObjectMember {
|
||||
member_type: String,
|
||||
pub name: String,
|
||||
name: String,
|
||||
minversion: String,
|
||||
maxversion: String,
|
||||
pub enumerations: Vec<MemberEnumeration>,
|
||||
enumerations: Vec<MemberEnumeration>,
|
||||
}
|
||||
|
||||
impl ObjectMember {
|
||||
|
@ -99,12 +153,32 @@ impl ObjectMember {
|
|||
Self { member_type, name, minversion, maxversion, enumerations }
|
||||
}
|
||||
|
||||
pub fn push(&mut self, enumeration: MemberEnumeration) {
|
||||
pub fn get_name(self) -> String{
|
||||
return self.name
|
||||
}
|
||||
|
||||
pub fn get_member_type(self) -> String{
|
||||
return self.member_type
|
||||
}
|
||||
|
||||
pub fn get_minversion(self) -> String{
|
||||
return self.minversion
|
||||
}
|
||||
|
||||
pub fn get_maxversion(self) -> String{
|
||||
return self.maxversion
|
||||
}
|
||||
|
||||
pub fn get_enumerations(self) -> Vec<MemberEnumeration>{
|
||||
return self.enumerations
|
||||
}
|
||||
|
||||
pub fn push_member_enumeration(&mut self, enumeration: MemberEnumeration) {
|
||||
self.enumerations.push(enumeration);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MemberEnumeration {
|
||||
name: String,
|
||||
default_value: String,
|
||||
|
@ -114,15 +188,23 @@ impl MemberEnumeration {
|
|||
pub fn new(name: String, default_value: String) -> Self {
|
||||
Self { name, default_value }
|
||||
}
|
||||
|
||||
pub fn get_name(self) -> String{
|
||||
return self.name
|
||||
}
|
||||
|
||||
pub fn get_default_value(self) -> String{
|
||||
return self.default_value
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Messages {
|
||||
pub requests: Vec<String>,
|
||||
pub responses: Vec<String>,
|
||||
pub commands: Vec<String>,
|
||||
pub statuses: Vec<String>,
|
||||
pub streams: Vec<String>,
|
||||
requests: Vec<String>,
|
||||
responses: Vec<String>,
|
||||
commands: Vec<String>,
|
||||
statuses: Vec<String>,
|
||||
streams: Vec<String>,
|
||||
error: String,
|
||||
}
|
||||
|
||||
|
@ -131,6 +213,26 @@ impl Messages {
|
|||
Self { requests, responses, commands, statuses, streams, error: String::from("") }
|
||||
}
|
||||
|
||||
pub fn get_requests(self) -> Vec<String>{
|
||||
return self.requests
|
||||
}
|
||||
|
||||
pub fn get_responses(self) -> Vec<String>{
|
||||
return self.responses
|
||||
}
|
||||
|
||||
pub fn get_commands(self) -> Vec<String>{
|
||||
return self.commands
|
||||
}
|
||||
|
||||
pub fn get_statuses(self) -> Vec<String>{
|
||||
return self.statuses
|
||||
}
|
||||
|
||||
pub fn get_streams(self) -> Vec<String>{
|
||||
return self.streams
|
||||
}
|
||||
|
||||
pub fn push(&mut self, message: Node<'_, '_>) {
|
||||
if let Some(t) = message.attribute_node("type") {
|
||||
let message_type = t.value();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue