Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling


by Anonymous Monk
on Mar 09, 2000 at 16:38 UTC ( #5092=sourcecode: print w/replies, xml ) Need Help??
Category: utilities
Author/Contact Info Stefan Kamphausen
Description: This script takes a C source code file as input and converts it to C source code that will printf exactly that file. I uses an array of translation rules so it should be expandable (and maybe they're not complete yet?). If you use this together with a little elisp snippet that puts the output of a programm into the current buffer it is quite useful.
#!/usr/bin/perl -w

$usage = "$0 c-source-file\n".
  "Converts a C source into printf's for another C File.\n";

die $usage unless $ARGV[0];

$cfile = $ARGV[0];

@rules = ('\x5C' => "\x5C"."\x5C",
                  '"' => '\"',
                  "'" => "\'",
                 '%' => '%%');
open(C,"<$cfile") or die "Couldn't open source file.\n$!";

while (<C>) {
  $line = $_;
  for ($i=0;$i<$#rules;$i+=2) {
        $line =~ s($rules[$i])($rules[$i+1])g;
  print "printf(\"$line\\n\");\n";
Replies are listed 'Best First'.
RE: c2printf
by Anonymous Monk on Mar 09, 2000 at 16:40 UTC
    I'm sorry that the code got messed up. I didn't know that it the \ns would be converted. How do I give correct code? regards stefan
RE: c2printf
by vroom (Pope) on Mar 09, 2000 at 20:11 UTC
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://5092]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2018-06-18 10:11 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.