#include "everything.hpp" // Get tab length at a certain position count_type get_tab_length(count_type c) { return TAB_SIZE - (c % TAB_SIZE); } // Substitute tab characters into regular tabs string substitute_tabs(string s) { string ret = ""; for(count_type i = 0; i < s.size(); ++i) { if(s[i] == '\t') { count_type this_tab_length = get_tab_length(ret.size()); for(count_type j = 0; j < this_tab_length; j++) ret += ' '; } else ret += s[i]; } return ret; } // Get how much tabs changed position on a row count_type get_tab_offset(count_type c, string text) { count_type tab_offset = 0; for(count_type i = 0; i + tab_offset < c; ++i) { if(text[i] == '\t') tab_offset += get_tab_length(i+tab_offset) - 1; if(i + tab_offset > c) tab_offset -= i + tab_offset - c; } return tab_offset; } int main(int argc, char* argv[]) { // Check argument if(argc <= 1) { std::cerr << "No input filename\n"; return 1; } string filename = argv[1]; // Check existing file std::ifstream infile(filename); if(!infile.good()) { std::cerr << "Bad input filename\n"; return 1; } // Load file Treap file; string line; while (std::getline(infile, line)) file.insert(file.size(), line); // Init initscr(); refresh(); Editor ed(filename, file); // Main loop while(ed.take_action()) refresh(); // End endwin(); return 0; }