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

c2printf

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 mail@skamphausen.de http://www.skamphausen.de
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>) {
  chomp;
  $line = $_;
  for ($i=0;$i<$#rules;$i+=2) {
        $line =~ s($rules[$i])($rules[$i+1])g;
  }
  print "printf(\"$line\\n\");\n";
  
}

Comment on c2printf
Download Code
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

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://5092]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-09-21 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls