Last active
November 30, 2016 02:43
-
-
Save bitnetwork/6ce105b9b0ceb36c00a7b3c75dca959e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <stdio.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
using namespace std; | |
int main(int argLen, char * argVec[]) { | |
if (argLen <= 1 or strcmp(argVec[1], "--help") == 0) { | |
cout << "bitkit [command] [params]\ncommand: can be one of the following:\n sleep [delay]\n length [string]\n fread [file]\n fwrite [file] [contents]\n shell [command]" << endl; | |
return 0; | |
} | |
//cout << argVec[1] << endl; | |
//cout << strlen(argVec[1]) << endl; | |
if (strcmp(argVec[1], "sleep") == 0) { | |
if (argLen <= 2 or strcmp(argVec[2], "--help") == 0) { | |
cout << "bitkit sleep [delay]\ndelay: delay of the program, in milliseconds." << endl; | |
return 0; | |
} | |
char * temp; | |
int delay = strtol(argVec[2], &temp, 10); | |
if (* temp != '\0') { | |
cout << "Error! Delay must be suppiled. See bitkit sleep --help." << endl; | |
exit(0); | |
} | |
if (delay < 0) { | |
cout << "Error! Delay cannot be negative. See bitkit sleep --help." << endl; | |
exit(0); | |
} | |
usleep(delay * 1000); | |
return 0; | |
} | |
if (strcmp(argVec[1], "length") == 0) { | |
if (argLen <= 2 or strcmp(argVec[2], "--help") == 0) { | |
cout << "bitkit length [string]\nstring: string to deterime length of." << endl; | |
return 0; | |
} | |
cout << strlen(argVec[2]) << endl; | |
return 0; | |
} | |
if (strcmp(argVec[1], "fread") == 0) { | |
if (argLen <= 2 or strcmp(argVec[2], "--help") == 0) { | |
cout << "bitkit fread [file]\nfile: file to read to stdout." << endl; | |
return 0; | |
} | |
string line; | |
ifstream file (argVec[2]); | |
if (file.is_open()) { | |
while (getline(file, line)) { | |
cout << line << "\n"; | |
} | |
file.close(); | |
} else { | |
cout << "Error! Unable to open file." << endl; | |
exit(0); | |
} | |
return 0; | |
} | |
if (strcmp(argVec[1], "fwrite") == 0) { | |
if (argLen <= 2 or strcmp(argVec[2], "--help") == 0) { | |
cout << "bitkit fwrite [file] [contents]\nfile: file to write to.\ncontents: the contents to write." << endl; | |
return 0; | |
} | |
ofstream file (argVec[2]); | |
if (file.is_open()) { | |
file << argVec[3]; | |
file.close(); | |
} else { | |
cout << "Error! Unable to open file." << endl; | |
exit(0); | |
} | |
return 0; | |
} | |
if (strcmp(argVec[1], "shell") == 0) { | |
if (argLen <= 2 or strcmp(argVec[2], "--help") == 0) { | |
cout << "bitkit shell [command]\ncommand: shell command to run" << endl; | |
return 0; | |
} | |
cout << system(argVec[2]) << endl; | |
return 0; | |
} | |
/*for (int i = 1; i < argLen; i++) { | |
if (strcmp(argVec[i], "-s") == 0) { | |
supressOutput = true; | |
} else if (strcmp(argVec[i], "-silent") == 0) { | |
supressOutput = true; | |
} | |
} | |
if (!supressOutput) { | |
cout << "BitKit installer." << endl; | |
for (int i = 0; i < 100; i++) { | |
cout << "\r" << i << "% completed. " << flush; | |
usleep(1000000); | |
} | |
}*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment