#include #include #include using namespace std; // version const char* versinfo = "Grim 0.0.2"; // improved argument handling thanks to arvind int main (int argc, char **argv) { // temporarily put here ofstream messagefile ("messages.txt", ios::app); ifstream messagefile2 ("testmsg.txt"); for (int i = 1; i < argc; i++) { // For each argument ... if (argv[i][0] == '-') { // Only if it's an option (starts with -) switch (argv[i][1]) { // Check char after "-". case 'c': cout << "Option C! "<< endl; if (argc > i + 1) { cout << "Argument: " << argv[i + 1] << endl; i++; } else { cout << "Expected argument. Found none." << endl; } break; case 'w': cout << "Message: "; char wholemsg[1000]; cin.getline(wholemsg, 1000); if (messagefile.is_open()) { messagefile << wholemsg << "\n"; messagefile.close(); } cout << "Added." << endl; break; case 'r': char buffer[1000]; char buffer1[1000]; char * msgtitle; char * msgdate; char * msgbody; char msgtitlebuffer[1000]; char msgbodybuffer[1000]; char msgdatebuffer[1000]; int i; if (! messagefile2.is_open()) { cout << "Error opening file"; exit (1); } while (! messagefile2.eof()) { messagefile2.getline(buffer,1000); strcat (buffer, "\n"); strcat (buffer1, buffer); } // duplicating buffer1 strcpy (msgtitlebuffer, buffer1); strcpy (msgbodybuffer, buffer1); strcpy (msgdatebuffer, buffer1); // message title stuff msgtitle = strstr (msgtitlebuffer, "Title:"); msgtitle = strtok (msgtitle, "\n"); msgtitle = msgtitle+7; // print message title cout << "----- " << msgtitle << " -----" << "\n"; // message body stuff msgbody = strstr (msgbodybuffer, "\%"); msgbody = strtok (msgbodybuffer, "\n"); msgbody = msgbody+1; // print message body cout << msgbody << "\n"; // message date stuff msgdate = strstr (msgdatebuffer, "Date:"); msgdate = strtok (msgdate, "\n"); msgdate = msgdate+6; // print message date cout << msgdate << "\n"; break; default: cout << "Unknown argument: " << argv[i][1] << endl; break; } } else { cout << "Extra arg: " << argv[i] << endl; } } return (0); }