Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot


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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2016-10-21 14:21 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.