Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

c2printf

by Anonymous Monk
on Mar 09, 2000 at 16:38 UTC ( [id://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";
  
}
Replies are listed 'Best First'.
RE: c2printf
by vroom (His Eminence) on Mar 09, 2000 at 20:11 UTC
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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-16 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found