Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<stdlib.h>
- #include<string.h>
- using namespace std;
- int main(int argc, char * argv[])
- {
- cout << "CAUTION: This will probably not work with advanced bash scripts. dos, dones and fis only please!\n";
- if (argc != 3)
- {
- cout << "Usage: " << argv[0] << " /path/to/bash.script /path/to/output.file" << endl;
- return 1;
- }
- ifstream FileInput;
- FileInput.open(argv[1]);
- if (FileInput.is_open() == false)
- {
- cout << "Could not find input file \"" << argv[1] << "\", exiting..." << endl;
- return 1;
- }
- ofstream FileOutput;
- FileOutput.open(argv[2], ofstream::trunc);
- FileOutput.close();
- FileOutput.open(argv[2], ofstream::app);
- if (FileOutput.is_open() == false)
- {
- cout << "Could not find output file \"" << argv[2] << "\", creating..." << endl;
- }
- string Buffer;
- while (FileInput.eof() == false)
- {
- getline(FileInput,Buffer);
- if(Buffer[0] != '#')FileOutput << Buffer;
- if(Buffer.size() > 1)
- {
- if (Buffer != "do" && Buffer != "then" && Buffer != "done" && Buffer != "fi" ) FileOutput << ";";
- else if (Buffer.size() >= 4)
- { //Screw you this kind of works
- if (
- Buffer.substr(Buffer.size() - 2,2) != "do" &&
- Buffer.substr(Buffer.size() - 2,2) != "fi" &&
- Buffer.substr(Buffer.size() - 4,4) != "done" &&
- Buffer.substr(Buffer.size() - 4,4) != "then")
- FileOutput << ";";
- }
- }
- }
- if(FileOutput.fail() == true)
- {
- cout << "Writing probably failed! Have fun guessing why! ( ͡° ͜ʖ ͡°)" << endl;
- return 1;
- }
- FileInput.close();
- FileOutput.close();
- cout << "File (hopefully) converted successfully! New one line equivalent is located at " << argv[2] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment