Including files into executable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ad

    #1

    Including files into executable

    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


  • Mike Wahler

    #2
    Re: Including files into executable


    "Ad" <the.huckster@b topenworld.com> wrote in message
    news:dliuom$p3v $1@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com...[color=blue]
    > 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?[/color]

    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(i n, line))
    {
    out << '"' << line << '"' << ',';
    }

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


    // yoursimpleprogr am.cpp
    #include "ps.txt";
    /* etc */
    int main()
    {
    for(size_t i = 0 i < sizeof ps / sizeof *ps; ++i)
    print_routine(p s[i]);

    /* etc */
    }

    -Mike


    Comment

    • rf

      #3
      Re: Including files into executable

      Ad wrote:
      [color=blue]
      > 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?[/color]

      Include it as a resource.

      --
      Cheers, Richard.

      Comment

      • Jonathan Mcdougall

        #4
        Re: Including files into executable


        Mike Wahler wrote:[color=blue]
        > "Ad" <the.huckster@b topenworld.com> wrote in message
        > news:dliuom$p3v $1@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com...[color=green]
        > > 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?[/color]
        >
        > 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"[/color]

        ;
        [color=blue]
        > while(getline(i n, line))
        > {
        > out << '"' << line << '"' << ',';[/color]

        Aggregate initialization cannot end with a comma.
        [color=blue]
        > }
        >
        > out << "\n};\n";
        >
        >
        > // yoursimpleprogr am.cpp
        > #include "ps.txt";[/color]

        That should be "ps.cpp".
        [color=blue]
        > /* etc */
        > int main()
        > {
        > for(size_t i = 0 i < sizeof ps / sizeof *ps; ++i)
        > print_routine(p s[i]);
        >
        > /* etc */
        > }[/color]

        Well, it's *kinda* roughly :)


        Jonathan

        Comment

        • Mike Wahler

          #5
          Re: Including files into executable


          "Jonathan Mcdougall" <jonathanmcdoug all@gmail.com> wrote in message
          news:1132287174 .800134.59030@o 13g2000cwo.goog legroups.com...[color=blue]
          >
          > Mike Wahler wrote:[color=green]
          >> "Ad" <the.huckster@b topenworld.com> wrote in message
          >> news:dliuom$p3v $1@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com...[color=darkred]
          >> > 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?[/color]
          >>
          >> 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"[/color]
          >
          > ;
          >[color=green]
          >> while(getline(i n, line))
          >> {
          >> out << '"' << line << '"' << ',';[/color]
          >
          > Aggregate initialization cannot end with a comma.[/color]

          Actually, it can.
          [color=blue]
          >[color=green]
          >> }
          >>
          >> out << "\n};\n";
          >>
          >>
          >> // yoursimpleprogr am.cpp
          >> #include "ps.txt";[/color]
          >
          > That should be "ps.cpp".[/color]

          It should be whatever OP wants. ".cpp" or
          any other 'file name extension', or lack of
          one, has no significance to the language.
          [color=blue]
          >[color=green]
          >> /* etc */
          >> int main()
          >> {
          >> for(size_t i = 0 i < sizeof ps / sizeof *ps; ++i)
          >> print_routine(p s[i]);
          >>
          >> /* etc */
          >> }[/color]
          >
          > Well, it's *kinda* roughly :)[/color]

          Yup. :-)

          -Mike


          Comment

          • Marcus Kwok

            #6
            Re: Including files into executable

            Mike Wahler <mkwahler@mkwah ler.net> wrote:[color=blue]
            > Roughly:
            >
            > ifstream in("whatever.ps ");
            > ofstream out("ps.cpp");
            >
            > out << "const char *ps[] = {\n"
            >
            > while(getline(i n, line))
            > {
            > out << '"' << line << '"' << ',';
            > }
            >
            > out << "\n};\n";[/color]

            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

            Comment

            • Mike Wahler

              #7
              Re: Including files into executable


              "Marcus Kwok" <ricecake@gehen nom.net> wrote in message
              news:dlko1u$g2v $2@news-int2.gatech.edu ...[color=blue]
              > Mike Wahler <mkwahler@mkwah ler.net> wrote:[color=green]
              >> Roughly:
              >>
              >> ifstream in("whatever.ps ");
              >> ofstream out("ps.cpp");
              >>
              >> out << "const char *ps[] = {\n"
              >>
              >> while(getline(i n, line))
              >> {
              >> out << '"' << line << '"' << ',';
              >> }
              >>
              >> out << "\n};\n";[/color]
              >
              > 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?[/color]

              Yes it would. But I'd rather leave dealing with such
              details to the OP.
              [color=blue]
              >
              > Of course, you did say this was "rough" :)[/color]

              Very. :-)

              -Mike


              Comment

              Working...