Skip to content

Commit

Permalink
feat: added execution type ASYNC and SYNC.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuwynu23 committed Jan 25, 2023
1 parent 8a31b6d commit e5397b7
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin/**
*.exe
**.exe**
/bin
5 changes: 3 additions & 2 deletions bin/.autofile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
::SYNC
# This is a comment
- echo Hi
- echo hello
- echo Hello world!
- echo Bye
- echo Bye
Binary file modified bin/auto.exe
Binary file not shown.
17 changes: 14 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
#constants variable
BIN=bin/auto.exe


# icon resource
ICO=resources/icon.rc
RES=resources/resource.res

SRC=$(wildcard src/*.cpp)

# compiling source file
all:
c++ -std=c++11 -o $(BIN) -I include $(SRC)

# compiling source file
all: compile_icon compile_source
# running executable
run:
$(BIN)

compile_source:
c++ -std=c++11 $(RES) -o $(BIN) -I include $(SRC)

compile_icon:
windres $(ICO) -O coff -o $(RES)


# cleaning executable
clean:
Expand Down
Binary file added resources/auto.ico
Binary file not shown.
1 change: 1 addition & 0 deletions resources/icon.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
id ICON "auto.ico"
Binary file added resources/icon.rs
Binary file not shown.
Binary file added resources/resource.res
Binary file not shown.
73 changes: 64 additions & 9 deletions src/lib.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright (c) 2023
* All rights reserved.
*/
#include "lib.h"
#include <direct.h>
#include <fstream>
Expand All @@ -8,42 +12,93 @@
#include <vector>

// user functions
void __termExecute(std::string command) {
//function to execute the commands Concurrently
void __termExecuteSync(std::string command) {
std::mutex m;
std::thread t{[&] {
std::lock_guard<std::mutex> lock{m};
system(command.c_str());
}};
t.join();
}
void __termPrint(std::string str) {



//function to print the command in terminal in Parallel
void __termPrintSync(int type,std::string str) {
std::mutex m;
std::thread t{[&] {
std::lock_guard<std::mutex> lock{m};
cout << str.c_str() << endl;
cout <<" type: " << type <<" : " << str.c_str() << endl;
}};
t.join();
}



// function for executing command in Parallel
void __termExecuteAsync(std::string command) {
system(command.c_str());
}



//function for printing the command in terminal in Parallel
void __termPrintAsync(int type,std::string str) {
cout <<" type: "<< type << " : "<< str.c_str() << endl;
}



// function to read String in A Line
void __readStringLine(std::string fileName) {
std::fstream newfile;

newfile.open(fileName, std::ios::in);

int lineNumber = 1;
int executionType = 1;
if (newfile.is_open()) {
string tp;
cout << "Autofile: " << endl;
cout << " Start:\n " << endl;
while (getline(newfile, tp)) {


if(lineNumber == 1){
//check if first character of line 1 is contains :
if( tp.substr(0,2) == "::"){
//remove : from the first line
tp = tp.erase(0, 1);
cout << " type: "+tp << endl;
if(tp == "SYNC"){
executionType = 0;
}else if(tp == "ASYNC"){
executionType = 1;
}
}
}
//check if the autofile content length is not empty
if (tp.length() > 0) {
//if is not empty, check the first character in every line if
// not contains # because this is for commenting and
// it is contains - which is the first character of a executable command
// to be execute.
if (tp[0] != '#' && tp[0] == '-') {
__termPrint(tp);
if(executionType == 1){
//print the commands
__termPrintAsync(executionType,tp);
//remove the first character
tp = tp.erase(0, 1);
//execute the command with start -
__termExecuteAsync("start \"" + tp + "\" cmd /K " + tp);
}else if(executionType == 0){
//print the commands
__termPrintSync(executionType,tp);
//remove the first character
tp = tp.erase(0, 1);
__termExecute("start cmd /K " + tp);
//execute the command with start -
__termExecuteSync("start \"" + tp + "\" cmd /K " + tp);
}
}
}
lineNumber++;
}
cout << "\n End:\n " << endl;
newfile.close();
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright (c) 2023
* All rights reserved.
*/
#include "lib.h"

int main(int argc, char const **argv) {
Expand Down

0 comments on commit e5397b7

Please sign in to comment.