HPGL-distiller in C++

Status
Niet open voor verdere reacties.

Herbs

Nieuwe gebruiker
Lid geworden
23 jul 2009
Berichten
4
Hallo allemaal,

Ik heb een misschien ongebruikelijke vraag voor dit forum.

Mijn snijplotter maakt gebruik van HPGL-bestanden om vormen uit te snijden. Deze HPGL-bestanden worden geëxporteerd vanuit een tekenprogramma.
Het probleem met deze geëxporteerde bestanden is, dat ze de plotter niet efficiënt laten werken. Er zit veel overbodige code in.
Nu heb ik op internet een programma (freeware) gevonden, HPGL-distiller genaamd, dat onnodige code uit een HPGL-bestand kan halen.
Mijn probleem is nu dat het programma een C++ bestand is. Ik weet nagenoeg niks van programmeren in C++ en heb ook geen programma waar ik het mee kan openen.
Mijn vraag is nu of iemand van deze C++ code een voor mij te gebruiken programma kan maken.

Mocht het zo zijn dat deze vraag om wat voor reden dan ook niet toegestaan is, dan heb ik daar begrip voor.

Alvast bedankt.

Hieronder volgt de code:

/**
* hpgl-distiller HPGL Distiller
*
* Written and maintained by Paul L Daniels [ pldaniels at pldaniels com ]
*
* This purpose of this program is to strip out non-applicable HPGL commands
* of which may confuse various plotters/cutters.
*
* Original version written: Wednesday December 27th, 2006
*
*
* Process description:
*
* Generating distillered HPGL from a SVG/DXF/PS/EPS/(all formats supported by pstoedit)
* is a multistep process at this stage.
*
* 1. Generate the full HPGL output via pstoedit
* pstoedit -f plot-hpgl somefile.eps output.hpgl
*
* 2. Distill the full HPGL
* hpgl-distiller -i output.hpgl -o distillered.hpgl
*
* 3. Send the HPGL to the printer
* cat distillered.hpgl > /dev/ttyS1 (for a serial port cutter)
*
**/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>


#define HPGLD_VERSION "0.9.0"
#define HPGLD_DEFAULT_INIT_STRING "IN;PU;" // Initialize and Pen-up
char HPGLD_HELP[]="hpgl-distiller: HPGL Distiller (for vinyl cutters)\n"
"Written by Paul L Daniels.\n"
"Distributed under the BSD Revised licence\n"
"This software is available at http://pldaniels.com/hpgl-distiller\n"
"\n"
"Usage: hpgl-distiller -i <input HPGL> -o <output file> [-v] [-d] [-I <initialization string>] [-h]\n"
"\n"
"\t-i <input HPGL> : Specifies which file contains the full HPGL file that is to be distilled.\n"
"\t-o <output file> : specifies which file the distilled HPGL is to be saved to.\n"
"\t-I <initialization string> : Specifies a HPGL sequence to be prepended to the output file.\n"
"\n"
"\t-v : Display current software version\n"
"\t-d : Enable debugging output (verbose)\n"
"\t-h : Display this help.\n"
"\n";

struct hpgld_glb {
int status;
int debug;
char *init_string;
char *input_filename;
char *output_filename;
};

/**
* HPGLD_show_version
*
* Display the current HPGL-Distiller version
*/
int HPGLD_show_version( struct hpgld_glb *glb ) {
fprintf(stderr,"%s\n", HPGLD_VERSION);
return 0;
}

/**
* HPGLD_show_help
*
* Display the help data for this program
*/
int HPGLD_show_help( struct hpgld_glb *glb ) {
HPGLD_show_version(glb);
fprintf(stderr,"%s\n", HPGLD_HELP);

return 0;

}

/**
* HPGLD_init
*
* Initializes any variables or such as required by
* the program.
*/
int HPGLD_init( struct hpgld_glb *glb )
{
glb->status = 0;
glb->debug = 0;
glb->init_string = HPGLD_DEFAULT_INIT_STRING;
glb->input_filename = NULL;
glb->output_filename = NULL;

return 0;
}

/**
* HPGLD_parse_parameters
*
* Parses the command line parameters and sets the
* various HPGL-Distiller settings accordingly
*/
int HPGLD_parse_parameters( int argc, char **argv, struct hpgld_glb *glb )
{

char c;

do {
c = getopt(argc, argv, "I:i:o:dvh");
switch (c) {
case EOF: /* finished */
break;

case 'i':
glb->input_filename = strdup(optarg);
break;

case 'o':
glb->output_filename = strdup(optarg);
break;

case 'I':
glb->init_string = strdup(optarg);
break;

case 'd':
glb->debug = 1;
break;

case 'h':
HPGLD_show_help(glb);
exit(1);
break;

case 'v':
HPGLD_show_version(glb);
exit(1);
break;

case '?':
break;

default:
fprintf(stderr, "internal error with getopt\n");
exit(1);

} /* switch */
} while (c != EOF); /* do */
return 0;
}



/**
* HPGL-Distiller, main body
*
* This program inputs an existing HPGL file which
* may contain many spurilous commands that aren't relevant
* to the device that the HPGL is being sent to.
*
* One such device is a vinyl cutter. There's no
* relevance for commands like Pen-width, line type
* etc, it's all simple Pen-down and move cuts.
*
*/
int main(int argc, char **argv) {

struct hpgld_glb glb;
FILE *fi, *fo;
char *data, *p;
struct stat st;
int stat_result;
size_t file_size;
size_t read_size;



/* Initialize our global data structure */
HPGLD_init(&glb);


/* Decyper the command line parameters provided */
HPGLD_parse_parameters(argc, argv, &glb);

/* Check the fundamental sanity of the variables in
the global data structure to ensure that we can
actually perform some meaningful work
*/
if ((glb.input_filename == NULL)) {
fprintf(stderr,"Error: Input filename is NULL.\n");
exit(1);
}
if ((glb.output_filename == NULL)) {
fprintf(stderr,"Error: Output filename is NULL.\n");
exit(1);
}

/* Check to see if we can get information about the
input file. Specifically we'll be wanting the
file size so that we can allocate enough memory
to read in the whole file at once (not the best
method but it's certainly a lot easier than trying
to read in line at a time when the file can potentially
contain non-ASCII chars
*/
stat_result = stat(glb.input_filename, &st);
if (stat_result) {
fprintf(stderr,"Cannot stat '%s' (%s)\n", argv[1], strerror(errno));
return 1;
}

/* Get the filesize and attempt to allocate a block of memory
to hold the entire file
*/
file_size = st.st_size;
data = malloc(sizeof(char) *(file_size +1));
if (data == NULL) {
fprintf(stderr,"Cannot allocate enough memory to read input HPGL file '%s' of size %d bytes (%s)\n", glb.input_filename, file_size, strerror(errno));
return 2;
}

/* Attempt to open the input file as read-only
*/
fi = fopen(glb.input_filename,"r");
if (!fi) {
fprintf(stderr,"Cannot open input file '%s' for reading (%s)\n", glb.input_filename, strerror(errno));
return 3;
}

/* Attempt to open the output file in write mode
(no appending is done, any existing file will be
overwritten
*/
fo = fopen(glb.output_filename,"w");
if (!fo) {
fprintf(stderr,"Cannot open input file '%s' for writing (%s)\n", glb.output_filename, strerror(errno));
return 4;
}

/* Read in the entire input file .
Compare the size read with the size
of the file as a double check.
*/
read_size = fread(data, sizeof(char), file_size, fi);
fclose(fi);
if (read_size != file_size) {
fprintf(stderr,"Error, the file size (%d bytes) and the size of the data read (%d bytes) do not match.\n", file_size, read_size);
return 5;
}


/* Put a terminating '\0' at the end of the data so
that our string tokenizing functions won't overrun
into no-mans-land and cause segfaults
*/
data[file_size] = '\0';

/* Generate any preliminary intializations to the output
file first.
*/
fprintf(fo,"%s\n", glb.init_string);

/* Go through the entire data block read from the
input file and break it off one piece at a time
as delimeted/tokenized by ;, \r or \n characters.
*/
p = strtok(data, ";\n\r");
while (p) {

if (glb.debug) printf("in: %s ",p);

/* Compare the segment of data obtained
from the tokenizing process to the list
of 'valid' HPGL commands that we want to
accept. Anything not in this list we
simply discard.
*/
if (
(strncmp(p,"IN",2)==0)
||(strncmp(p,"PA",2)==0)
||(strncmp(p,"PD",2)==0)
||(strncmp(p,"PU",2)==0)
||(strncmp(p,"PG",2)==0)
||(strncmp(p,"PM",2)==0)
||(strncmp(p,"!PG",3)==0)
) {

/* Write the token to the output file */
fprintf(fo,"%s;\n",p);

if (glb.debug) printf("good\n");
} else {


if (glb.debug) printf("ignored\n");
} /* if strncmp... */

/* Get the next block of data from the input data
*/
p = strtok(NULL,";\n\r");


} /** while more tokenizing **/

/* Close the output file */
fclose(fo);

/* Release the memory we allocated to hold the input HPGL file */
free(data);

return 0;
}

/** END **/
 
Laatst bewerkt:
Dit bestand kan alleen op linux gecompileerd (en dus gebruikt) worden. Ik heb helaas geen linux tot mijn beschikking.
 
Ik heb er op dit moment nogal weinig tijd voor, maar ik heb oa linux en wil dat wel eens compileren. Ik wil ook kijken of ik het programma kan omschrijven naar windows, maar dat zal allemaal pas voor na dit weekend zijn..
 
Bedankt voor de reacties en bedankt Johantrax dat je het programma eventueel wil omschrijven naar windows.
Ik wacht het met veel belangstelling af.
 
Een omgeschreven versie voor Win32 kan je hier downloaden. Dit programma is geschreven naar de originele versie 0.9.1

Gebruiken via commandline, typ best eerst eens HPGLdistiller.exe -h om een helptekst te krijgen over de parameters. In dit programma worden enkel volgende commando's behouden:
  • IN -> Initialize
  • PA -> Plot Absolute
  • PD -> Pen Down
  • PU -> Pen Up
  • PG -> Page Feed
  • PR -> Plot Relative
  • !PG
Als je aangeeft welke commando's jouw plotter begrijpt, dan pas ik het programma aan zodat enkel die voor jouw plotter behouden blijven.

Ook wordt aan het begin van elke file IN;PU; toegevoegd. Commando's die genegeerd worden zorgen wel nog voor lege lijnen in de file, maar ik vermoed niet direct dat dit voor problemen gaat zorgen, anders hoor ik het wel.

Hierbij nog eens de code zoals die nu is:
Code:
/**
  * hpgl-distiller HPGL Distiller
  *
  * Windowsport of version 0.9.1 by jeetee [ jeetee  at jeetee dot net]
  * 
  * Written and maintained by Paul L Daniels [ pldaniels at pldaniels com ]
  *
  * This purpose of this program is to strip out non-applicable HPGL commands
  * of which may confuse various plotters/cutters.
  *
  * Original version written: Wednesday December 27th, 2006
  *
  **/


/*//#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>*/
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;

#define HPGLD_VERSION "0.9.1"
#define HPGLD_DEFAULT_INIT_STRING "IN;PU;" // Initialize and Pen-up
const string HPGLD_HELP = 
	"hpgl-distiller: HPGL Distiller (for vinyl cutters)\n"
	"Written by Paul L Daniels. Ported to Win32 by jeetee\n"
	"Distributed under the BSD Revised licence\n"
	"The original software is available at http://pldaniels.com/hpgl-distiller\n"
	"\n"
	"Usage: hpgl-distiller [-i <input HPGL>] [-o <output file>] [-v] [-d] [-I <initialization string>] [-h]\n"
	"\n"
	"\t-i <input HPGL> : Specifies which file contains the full HPGL file that is to be distilled.\n"
	"\t-o <output file> : Specifies which file the distilled HPGL is to be saved to.\n"
	"\t-I <initialization string> : Specifies a HPGL sequence to be prepended to the output file.\n"
	"\n"
	"\t-v : Display current software version\n"
	"\t-d : Enable debugging output (verbose)\n"
	"\t-h : Display this help.\n"
	"\n";

int main(int argc, char** argv)
{
	bool debug = false;
	string init_string = HPGLD_DEFAULT_INIT_STRING;
	string input_filename = "";
	string output_filename = "";
	
	/* Decyper the command line parameters provided */
	int i = 0;
	stringstream dbgs("");
	while(++i < argc) {
		dbgs << "Reading argument " << i << ": " << argv[i] << endl;
		if (argv[i][0] == '-') {
			//argumenttype
			dbgs << "  ...indicates a type" << endl;
			switch (argv[i][1]) {
				case 'i': { dbgs << "\tinputfile:\t";
						input_filename = argv[++i];
						dbgs << input_filename << endl;
					} break;
				case 'o': { dbgs << "\toutputfile:\t";
						output_filename = argv[++i];
						dbgs << output_filename << endl;
					} break;
				case 'v': { dbgs << "\trequesting version:\t";
					dbgs << "HPGL-distiller: Running Version: " << HPGLD_VERSION << endl;
					cout << "HPGL-distiller: Running Version: " << HPGLD_VERSION << endl;
					} break;
				case 'd': { dbgs << "\tenabling debugmode:\t";
						debug = true;
						dbgs << "DONE." << endl;
					} break;
				case 'I': { dbgs << "\tinitialisation string:\t";
						init_string = argv[++i];
						dbgs << init_string << endl;
					} break;
				case 'h': { dbgs << "\thelp needed:\t";
						cout << "HPGL-distiller v" << HPGLD_VERSION << " --- Helpfile\n---\n" << endl;
						cout << HPGLD_HELP << endl;
						dbgs << "help printed, press any key to quit... " << endl;
						if (cin.peek()) {
						    string rest;
						    getline(cin, rest);
						}
						cin.get();
						exit(EXIT_SUCCESS);
					} break;
				default: {
						dbgs << "\tunknown type.. ignoring" << endl;
					} break;
			}
		} else {
			dbgs << "random unknown argument with content\n'" << argv[i] << "' ... ignoring" << endl;
		}
	}
	if (debug) {
		cout << dbgs.str() << endl;
	}
	dbgs.str("");

	while (input_filename == "") {
		cout << "No inputfile was specified, please provide a file or type q to quit" << endl;
		getline(cin, input_filename);
	}
	if (input_filename == "q") {
		//exit
		return 0;
	}
	if (output_filename == "") {
		output_filename = input_filename + ".d.hpgl";
		if (debug)
			cout << "No outputfile has been specified, defaulting to " << output_filename << endl;
	}

	// Attempt to open the input file as read-only
	ifstream fi(input_filename.c_str());
	if (!fi.is_open()) {
		cout << "Failed opening inputfile, please check that the file exists, is not in use and readable." << endl;
		if (debug)
			cout << "input filename was: " << input_filename << endl;
		return 0;
	}

	// Attempt to open the output file in (over)write mode
	ofstream fo(output_filename.c_str());
	if (!fo.is_open()) {
		cout << "Failed creating outputfile, please verify writing permission in the specified folder." << endl;
		if (debug)
			cout << "output_filename was: " << output_filename << endl;
		return 0;
	}

	/// Generate any preliminary intializations to the output file first.
	fo << init_string << endl;

	// Commands are seperated by ';', '\r' or '\n', so we should scan for these
	// while reading in the file, line by line
	string line;
	while (!fi.eof()) {
		getline(fi, line);
		if (debug)
			cout << "fi: " << line << endl;
		//split the line into segments and process those
		stringstream ss("");
		ss << line;
		string token = "";
		while (getline(ss, token, ';') && !ss.eof()) {
			/* Compare the segment of data obtained	from the tokenizing process to the list
				of 'valid' HPGL commands that we want to accept. Anything not in this list we
				simply discard.
			*/
			if (debug)
				cout << "Extracted: " << token << "...\t";
			if (!(
				token.compare(0, 2, "IN")		// Initialize
				&& token.compare(0, 2, "PA")	// Plot Absolute
				&& token.compare(0, 2, "PD")	// Pen Down
				&& token.compare(0, 2, "PU")	// Pen Up
				&& token.compare(0, 2, "PG")	// Page Feed
	//			&& token.compare(0, 2, "PM")
				&& token.compare(0, 2, "PR")	// Plot Relative
				&& token.compare(0, 3, "!PG"))
			) {
				// Write the token to the output file
				fo << token << ';';
				if (debug)
					cout << "good" << endl;
			} else if (debug) {
				cout << "ignored" << endl;
			}
		} //while more tokens on line
		fo << endl;
		if (debug)
			cout << endl;
	} //while more lines
	
	// Close the output file
	if (debug)
		cout << endl << "Closing outputfile...\t";
	fo.close();
	if (debug)
		cout << "DONE" << endl << "Closing inputfile...\t";
	fi.close();
	if (debug)
		cout << "DONE" << endl;
	
	cout << "File successfully extracted to:" << endl
		 << output_filename << endl;
	
	if (cin.peek()) {
	    string rest;
	    getline(cin, rest);
	}
	cout << "Press any key to quit... ";
	cin.get();
	return 0;
}

Ik hoop dat dit je wat geholpen heeft :)
 
Laatst bewerkt:
Geweldig Johantrax, bedankt voor het programma.
Van de genoemde commando's kent mijn plotter de volgende:

* IN -> Initialize
* PA -> Plot Absolute
* PD -> Pen Down
* PU -> Pen Up
* PR -> Plot Relative

Dit gaat mij zeker verder helpen!
 
Een beetje later dan gehoopt, maar hier is een bijgewerkte versie (0.9.1.1) voor jouw plotter.

Ik heb ook nog een extra optie toegevoegd -c <0 of 1> waarmee je de compacte modus kan aan- of uitzetten (standaard staat die aan).
Wanneer die aanstaat zal de outputfile uit slechts 2 regels bestaan, de eerste is de initialisatieregel (standaard IN;PU;, in te stellen via -I (hoofdletter i)), de tweede bevat dan de gestripte versie van je inputfile.
De reden daarvoor is dat ik las dat sommige plotters ook kunnen blijven hangen op de karakters voor nieuwe lijnen.

Als je echter een leesbare versie wil, kan je best -c 0 gebruiken, omdat dan de nieuwe lijnen van de inputfile behouden blijven (bij het negeren van commando's ontstaan dan lege lijnen, net zoals in de vorige versie).


En zoals de licentie het voorschrijft, hierbij de code van het programma:
Code:
/**
  * hpgl-distiller HPGL Distiller
  *
  * Windowsport of version 0.9.1 with adaptations for 'Herbs' by jeetee [ jeetee  at jeetee dot net]
  * 
  * Written and maintained by Paul L Daniels [ pldaniels at pldaniels com ]
  *
  * This purpose of this program is to strip out non-applicable HPGL commands
  * of which may confuse various plotters/cutters.
  *
  * Original version written: Wednesday December 27th, 2006
  *
  **/

#include <iostream>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;

#define HPGLD_VERSION "0.9.1.1"
#define HPGLD_DEFAULT_INIT_STRING "IN;PU;" // Initialize and Pen-up
const string HPGLD_HELP = 
	"hpgl-distiller: HPGL Distiller (for vinyl cutters)\n"
	"Written by Paul L Daniels. Ported to Win32 by jeetee\n"
	"Distributed under the BSD Revised licence\n"
	"The original software is available at http://pldaniels.com/hpgl-distiller\n"
	"\n"
	"Usage: hpgl-distiller [-i <input HPGL>] [-o <output file>] [-c 1|0] [-v] [-d] [-I <initialization string>] [-h]\n"
	"\n"
	"\t-i <input HPGL> : Specifies which file contains the full HPGL file that is to be distilled.\n"
	"\t-o <output file> : Specifies which file the distilled HPGL is to be saved to.\n"
	"\t-c [1|0] : Enable or Disable compact mode. In compact-mode, newlines (CR and/or LF) are\n"
	"\t\t ignored. The default is 1.\n"
	"\t-I <initialization string> : Specifies a HPGL sequence to be prepended to the output file.\n"
	"\n"
	"\t-v : Display current software version\n"
	"\t-d : Enable debugging output (verbose)\n"
	"\t-h : Display this help.\n"
	"\n";

int main(int argc, char** argv)
{
	bool debug = false;
	string init_string = HPGLD_DEFAULT_INIT_STRING;
	string input_filename = "";
	string output_filename = "";
	bool compact = true;
	
	/* Decyper the command line parameters provided */
	int i = 0;
	stringstream dbgs("");
	while(++i < argc) {
		dbgs << "Reading argument " << i << ": " << argv[i] << endl;
		if (argv[i][0] == '-') {
			//argumenttype
			dbgs << "  ...indicates a type" << endl;
			switch (argv[i][1]) {
				case 'i': { dbgs << "\tinputfile:\t";
						input_filename = argv[++i];
						dbgs << input_filename << endl;
					} break;
				case 'o': { dbgs << "\toutputfile:\t";
						output_filename = argv[++i];
						dbgs << output_filename << endl;
					} break;
				case 'c': { dbgs << "\tcompactswitch:\t";
						if (*argv[++i] == '0') {
							compact = false;
							dbgs << "disabled";
						} else {
							compact = true;
							dbgs << "enabled";
						}
						dbgs << endl;
					} break;
				case 'v': { dbgs << "\trequesting version:\t";
					dbgs << "HPGL-distiller: Running Version: " << HPGLD_VERSION << endl;
					cout << "HPGL-distiller: Running Version: " << HPGLD_VERSION << endl;
					} break;
				case 'd': { dbgs << "\tenabling debugmode:\t";
						debug = true;
						dbgs << "DONE." << endl;
					} break;
				case 'I': { dbgs << "\tinitialisation string:\t";
						init_string = argv[++i];
						dbgs << init_string << endl;
					} break;
				case 'h': { dbgs << "\thelp needed:\t";
						cout << "HPGL-distiller v" << HPGLD_VERSION << " --- Helpfile\n---\n" << endl;
						cout << HPGLD_HELP << endl;
						dbgs << "help printed, press any key to quit... " << endl;
						if (cin.peek()) {
						    string rest;
						    getline(cin, rest);
						}
						cin.get();
						exit(EXIT_SUCCESS);
					} break;
				default: {
						dbgs << "\tunknown type.. ignoring" << endl;
					} break;
			}
		} else {
			dbgs << "random unknown argument with content\n'" << argv[i] << "' ... ignoring" << endl;
		}
	}
	if (debug) {
		cout << dbgs.str() << endl;
	}
	dbgs.str("");

	while (input_filename == "") {
		cout << "No inputfile was specified, please provide a file or type q to quit" << endl;
		getline(cin, input_filename);
	}
	if (input_filename == "q") {
		//exit
		return 0;
	}
	if (output_filename == "") {
		output_filename = input_filename + ".d.hpgl";
		if (debug)
			cout << "No outputfile has been specified, defaulting to " << output_filename << endl;
	}

	// Attempt to open the input file as read-only
	ifstream fi(input_filename.c_str());
	if (!fi.is_open()) {
		cout << "Failed opening inputfile, please check that the file exists, is not in use and readable." << endl;
		if (debug)
			cout << "input filename was: " << input_filename << endl;
		return 0;
	}

	// Attempt to open the output file in (over)write mode
	ofstream fo(output_filename.c_str());
	if (!fo.is_open()) {
		cout << "Failed creating outputfile, please verify writing permission in the specified folder." << endl;
		if (debug)
			cout << "output_filename was: " << output_filename << endl;
		return 0;
	}

	/// Generate any preliminary intializations to the output file first.
	fo << init_string << endl;

	// Commands are seperated by ';', '\r' or '\n', so we should scan for these
	// while reading in the file, line by line
	string line;
	while (!fi.eof()) {
		getline(fi, line);
		if (debug)
			cout << "fi: " << line << endl;
		//split the line into segments and process those
		stringstream ss("");
		ss << line;
		string token = "";
		while (getline(ss, token, ';') && !ss.eof()) {
			/* Compare the segment of data obtained	from the tokenizing process to the list
				of 'valid' HPGL commands that we want to accept. Anything not in this list we
				simply discard.
			*/
			if (debug)
				cout << "Extracted: " << token << "...\t";
			if (!(
				token.compare(0, 2, "IN")		// Initialize
				&& token.compare(0, 2, "PA")	// Plot Absolute
				&& token.compare(0, 2, "PD")	// Pen Down
				&& token.compare(0, 2, "PU")	// Pen Up
				&& token.compare(0, 2, "PR"))	// Plot Relative
			) {
				// Write the token to the output file
				fo << token << ';';
				if (debug)
					cout << "good" << endl;
			} else if (debug) {
				cout << "ignored" << endl;
			}
		} //while more tokens on line
		if (!compact)
			fo << endl;
		if (debug)
			cout << endl;
	} //while more lines
	
	// Close the output file
	if (debug)
		cout << endl << "Closing outputfile...\t";
	fo.close();
	if (debug)
		cout << "DONE" << endl << "Closing inputfile...\t";
	fi.close();
	if (debug)
		cout << "DONE" << endl;
	
	cout << "File successfully extracted to:" << endl
		 << output_filename << endl;
	
/*	if (cin.peek()) {
	    string rest;
	    getline(cin, rest, '\n');
	}*/
	cout << "Press any key to quit... ";
	cin.get();
	return 0;
}

Veel succes!
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan