00001 ## 00002 # 00003 # Converts a text file into a C function called manpage that prints 00004 # the indicated text to a stream. 00005 # 00006 # Copyright (C) 2002 GDS Software 00007 # 00008 # This program is free software; you can redistribute it and/or 00009 # modify it under the terms of the GNU General Public License as 00010 # published by the Free Software Foundation; either version 2 of 00011 # the License, or (at your option) any later version. 00012 # 00013 # This program is distributed in the hope that it will be useful, 00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 # GNU General Public License for more details. 00017 # 00018 # You should have received a copy of the GNU General Public 00019 # License along with this program; if not, write to the Free 00020 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00021 # MA 02111-1307 USA 00022 # 00023 # See http://www.gnu.org/licenses/licenses.html for more details. 00024 # 00025 00026 import sys, string 00027 __version__ = "$Id: man2c.py,v 1.4 2002/08/21 17:37:39 donp Exp $" 00028 00029 def GetLines(): 00030 ifp = open(sys.argv[1]) 00031 lines = ifp.readlines() 00032 ifp.close() 00033 TransformLines(lines) 00034 return lines 00035 00036 def PrintHeader(): 00037 print '''/* Automatically generated by man2c.py */\n 00038 #include <stdio.h> 00039 00040 void manpage(FILE *ofp) 00041 { 00042 fprintf(ofp, 00043 ''' 00044 00045 def PrintLines(lines): 00046 for line in lines: 00047 print line 00048 00049 def PrintTrailer(): 00050 print " );" 00051 print "\n}\n" 00052 00053 ## 00054 # Escape the characters so that they printf OK. This includes 00055 # double quotes, backslashes, tabs, and % characters. 00056 def TransformLines(lines): 00057 for ix in xrange(len(lines)): 00058 line = string.rstrip(lines[ix]) 00059 line = string.replace(line, "\\", r"\\") 00060 line = string.replace(line, "\"", r"\"") 00061 line = string.replace(line, "%", "%%") 00062 line = string.replace(line, "\t", r"\t") 00063 line = "\"" + line + "\\n\"" 00064 lines[ix] = line 00065 00066 def main(): 00067 if (len(sys.argv) != 2): 00068 sys.stderr.write("Usage: man2c file\n") 00069 sys.exit(1) 00070 lines = GetLines() 00071 PrintHeader() 00072 PrintLines(lines) 00073 PrintTrailer() 00074 00075 main() 00076 00077
© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."
Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.
122,241 lines of code and growing...