By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,945 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,945 IT Pros & Developers. It's quick & easy.

Including files into executable

P: n/a
Ad
Hello,

I've written a simple program that sends a postscript snippet file to a
printer via LPT1. I want to include the file within the executable however.
How would I go about this?

Adrian
Nov 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"Ad" <th**********@btopenworld.com> wrote in message
news:dl**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hello,

I've written a simple program that sends a postscript snippet file to a
printer via LPT1. I want to include the file within the executable
however. How would I go about this?


Write a simple 'code generator', i.e.
write a short program that reads this file and writes
a source code file which defines an array or container
containing the text of the postscript file.
Use an #include directive at an appropriate place
in your orignal program to insert the generated
source code.

Roughly:

ifstream in("whatever.ps");
ofstream out("ps.cpp");

out << "const char *ps[] = {\n"

while(getline(in, line))
{
out << '"' << line << '"' << ',';
}

out << "\n};\n";
// yoursimpleprogram.cpp
#include "ps.txt";
/* etc */
int main()
{
for(size_t i = 0 i < sizeof ps / sizeof *ps; ++i)
print_routine(ps[i]);

/* etc */
}

-Mike
Nov 22 '05 #2

P: n/a
rf
Ad wrote:
Hello,

I've written a simple program that sends a postscript snippet file to a
printer via LPT1. I want to include the file within the executable however.
How would I go about this?


Include it as a resource.

--
Cheers, Richard.
Nov 22 '05 #3

P: n/a

Mike Wahler wrote:
"Ad" <th**********@btopenworld.com> wrote in message
news:dl**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hello,

I've written a simple program that sends a postscript snippet file to a
printer via LPT1. I want to include the file within the executable
however. How would I go about this?
Write a simple 'code generator', i.e.
write a short program that reads this file and writes
a source code file which defines an array or container
containing the text of the postscript file.
Use an #include directive at an appropriate place
in your orignal program to insert the generated
source code.

Roughly:

ifstream in("whatever.ps");
ofstream out("ps.cpp");

out << "const char *ps[] = {\n"


;
while(getline(in, line))
{
out << '"' << line << '"' << ',';
Aggregate initialization cannot end with a comma.
}

out << "\n};\n";
// yoursimpleprogram.cpp
#include "ps.txt";
That should be "ps.cpp".
/* etc */
int main()
{
for(size_t i = 0 i < sizeof ps / sizeof *ps; ++i)
print_routine(ps[i]);

/* etc */
}


Well, it's *kinda* roughly :)
Jonathan

Nov 22 '05 #4

P: n/a

"Jonathan Mcdougall" <jo***************@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...

Mike Wahler wrote:
"Ad" <th**********@btopenworld.com> wrote in message
news:dl**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
> Hello,
>
> I've written a simple program that sends a postscript snippet file to a
> printer via LPT1. I want to include the file within the executable
> however. How would I go about this?
Write a simple 'code generator', i.e.
write a short program that reads this file and writes
a source code file which defines an array or container
containing the text of the postscript file.
Use an #include directive at an appropriate place
in your orignal program to insert the generated
source code.

Roughly:

ifstream in("whatever.ps");
ofstream out("ps.cpp");

out << "const char *ps[] = {\n"


;
while(getline(in, line))
{
out << '"' << line << '"' << ',';


Aggregate initialization cannot end with a comma.


Actually, it can.
}

out << "\n};\n";
// yoursimpleprogram.cpp
#include "ps.txt";
That should be "ps.cpp".


It should be whatever OP wants. ".cpp" or
any other 'file name extension', or lack of
one, has no significance to the language.
/* etc */
int main()
{
for(size_t i = 0 i < sizeof ps / sizeof *ps; ++i)
print_routine(ps[i]);

/* etc */
}


Well, it's *kinda* roughly :)


Yup. :-)

-Mike
Nov 22 '05 #5

P: n/a
Mike Wahler <mk******@mkwahler.net> wrote:
Roughly:

ifstream in("whatever.ps");
ofstream out("ps.cpp");

out << "const char *ps[] = {\n"

while(getline(in, line))
{
out << '"' << line << '"' << ',';
}

out << "\n};\n";


I'm not familiar with the PS format so the point may be moot, but won't
this mess up if there is an embedded double-quote in the line?

Of course, you did say this was "rough" :)

--
Marcus Kwok
Nov 22 '05 #6

P: n/a

"Marcus Kwok" <ri******@gehennom.net> wrote in message
news:dl**********@news-int2.gatech.edu...
Mike Wahler <mk******@mkwahler.net> wrote:
Roughly:

ifstream in("whatever.ps");
ofstream out("ps.cpp");

out << "const char *ps[] = {\n"

while(getline(in, line))
{
out << '"' << line << '"' << ',';
}

out << "\n};\n";
I'm not familiar with the PS format so the point may be moot, but won't
this mess up if there is an embedded double-quote in the line?


Yes it would. But I'd rather leave dealing with such
details to the OP.

Of course, you did say this was "rough" :)


Very. :-)

-Mike
Nov 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.