home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / kr2ansi / kr2ansi.1 < prev    next >
Text File  |  1993-10-23  |  10KB  |  302 lines

  1.  
  2.  
  3.  KR2ANSI (1)               Commands and Applications                KR2ANSI (1)
  4.  
  5.  
  6.  
  7.  
  8.  N✓NA✓AM✓ME✓E 
  9.       kr2ansi - generate function prototypes from K&R C files (Version 1.0) 
  10.  
  11.  S✓SY✓YN✓NO✓OP✓PS✓SI✓IS✓S 
  12.       kr2ansi [-p] [ [-r file1] | [usrdef1 ... usrdef20] ] file2 
  13.  
  14.  D✓DE✓ES✓SC✓CR✓RI✓IP✓PT✓TI✓IO✓ON✓N 
  15.       kr2ansi  reads  a  C  source  file  (written  in  the  programming  style
  16.       introduced  by Kernighan  and  Ritchie, in  "The C Programming Language",
  17.       1st  Edition),  and  writes  the  functions'  prototypes  on the standard
  18.       output.  Output  redirection, via sh (or any other shell), should be used
  19.       for sending the output to a text file.  
  20.  
  21.  O✓OP✓PT✓TI✓IO✓ON✓NS✓S 
  22.       The following command line options are available: 
  23.  
  24.       -p        Include parameter-names in protypes
  25.  
  26.       -r file   Read user-defined data-types from file. This option should
  27.                 be the last one, before the name of the C source file.
  28.  
  29.       usrdef1 ... usrdef20
  30.                 Up to 20 user-defined data-types can be specified in the
  31.                 command line, providing that option -r is not present
  32.  
  33.  N✓NO✓OT✓TE✓ES✓S 
  34.       C  programmers,  who  write  K & R code, may use kr2ansi to create header
  35.       files  with  ANSI prototypes, so their code can be compiled with any ANSI
  36.       compiler.   (kr2ansi  automatically  writes the word "extern" in front of
  37.       every  output  line,  thus making it easy to create header files which in
  38.       turn  can  be  included  (via  #include)  in existant K&R code ). All ten
  39.       standard  C-data-types  - namely: void, char, int, long, unsigned, short,
  40.       float,  double, and FILE (as well the combinations of unsigned, short and
  41.       long  with  int,  and the combination of register with any data-type) are
  42.       recognised  by  the  program.  In  addition,  the  user can specify up to
  43.       twenty  user-defined  types  in  the  command  line.  The program is very
  44.       sensitive  to  the  format of the source file, especially to comments; it
  45.       expects all functions to be declared in the following form: 
  46.  
  47.       function-type function-name(p1,p2,...,pn) /* COMMENTS */
  48.       /* ALSO YOU CAN HAVE ... */
  49.       /* ...MORE COMMENTS HERE */
  50.           parameter-type  p1,p2;      /* COMMENTS II */
  51.           /* ... OR HERE */
  52.           parameter-type  p4;         /* MORE COMMENTS */
  53.           parameter-type  p5,...,pn;  /* YET MORE COMMENTS */
  54.       {                       /* ... OR EVEN HERE */
  55.         function-body
  56.       }
  57.  
  58.  
  59.  
  60.  Tue October 1 16:24 1991                                                Page 1
  61.  
  62.  
  63.  KR2ANSI (1)               Commands and Applications                KR2ANSI (1)
  64.  
  65.  
  66.  
  67.  
  68.  D✓DI✓IA✓AG✓GN✓NO✓OS✓ST✓TI✓IC✓CS✓S 
  69.       kr2ansi  warns that something is wrong  by  displaying two error messages
  70.       in the output function-prototypes: 
  71.       1.   "U-N-D-E-F-I-N-E-D" means that either the data types of the specific
  72.            parameters  are undefined, or the words that describe the data types
  73.            are  too  long.  In the first case you should re-run kr2ansi, making
  74.            sure  that you type all user-defined types (used in the source file)
  75.            in  the  command  line.The  second case requires that you change the
  76.            names  of  all data-types that exceed  words' length limit (normally
  77.            set to 50 characters).  
  78.            *** IMPORTANT ***
  79.            Function-declaration   lines   with   undefined  data-type  for  the
  80.            functions,  are  completely  ignored.  (Unfortunately  this  case is
  81.            frequently found in functions of type int).  
  82.       2.   "<...>"   means  that  the  specified  functions  produce prototype-
  83.            lines   which  are   exceeding  lines' length limit (normally set to
  84.            255  characters).   Unfortunately there is no easy way to solve this
  85.            problem;the  best  one  is  to  edit  the output file manually. (the
  86.            other one is to re-compile kr2ansi.c  8*) 
  87.  
  88.  R✓RE✓ES✓ST✓TR✓RI✓IC✓CT✓TI✓IO✓ON✓NS✓S 
  89.       Although  white  characters  (i.e.  tabs,  newlines,  and spaces)  do not
  90.       affect  the  parsing,   extra attention should be given to comments. It's
  91.       possible  to  have  perfectly valid C code which is not handled correctly
  92.       by kr2ansi. The program gets very confused in the following cases: 
  93.  
  94.       o when a function-declaration does not include the data-type
  95.         (usually found in declarations of integer functions).
  96.       o when comments appear before or among words in a function's
  97.         (or parameter's) declaration line.
  98.       o when there are comments inside the parameter list.
  99.       o when comments open in a line and close in a different one.
  100.       o when a  semicolon in the parameter-declaration comes after
  101.         any commented string(s).
  102.       o when the function-declaration line contains a commented ';'
  103.       o when the character '{' is not the first non-blank char in a
  104.         separate line.
  105.  
  106.       Here's  an example of a valid C function declaration which drives kr2ansi
  107.       crazy: 
  108.  
  109.       foo(x,y /* integers */,z/* non-integer*/) /* call: foo(x,y,z);*/
  110.           int   x,       /* MY PROGRAMMING STYLE IS...
  111.                             ...SO UGLY, THAT I DO NOT ...
  112.       */        y        /* ...EXPECT kr2ansi, OR ANY OTHER... */ ;
  113.         char /* ...SIMILAR PROGRAM TO... */   * z[];
  114.         /* ...PARSE MY CODE CORRECTLY;...
  115.            ...UNLESS ITS AUTHOR IS A MAZOCHIST */ {
  116.         return(1);
  117.  
  118.  
  119.  
  120.  Tue October 1 16:24 1991                                                Page 2
  121.  
  122.  
  123.  KR2ANSI (1)               Commands and Applications                KR2ANSI (1)
  124.  
  125.  
  126.  
  127.       }
  128.  
  129.  E✓EX✓XA✓AM✓MP✓PL✓LE✓ES✓S 
  130.           Suppose we use cat to create a file called 'math.c' as follows:
  131.           % cat >math.c
  132.           >/* ------------------------------------ */
  133.           >#include <stdio.h>
  134.           >
  135.           >typedef int INTEGER;
  136.           >
  137.           >INTEGER main(argc, argv)
  138.           >    int   argc;
  139.           >    char  *argv[];
  140.           >{
  141.           >  void usage();
  142.           >  INTEGER add(), sub();
  143.           >  extern int strcmp();
  144.           >
  145.           >  if (argc < 4)
  146.           >    usage("math add/sub n1 n2");
  147.           >  else if ( !strcmp(argv[1],"add") )
  148.           >    printf("%d\n", add(argv[2],argv[3]) );
  149.           >  else if ( !strcmp(argv[1],"sub") )
  150.           >    printf("%d\n", sub(argv[2],argv[3]) );
  151.           >  else
  152.           >    usage(:math add/sub n1 n2");
  153.           >  return(0);
  154.           >}
  155.           >/* ------------------------------------ */
  156.           >void usage(s)
  157.           >   char *s;
  158.           >{
  159.           >  puts(s);
  160.           >  exit(1);
  161.           >}
  162.           >/* ------------------------------------ */
  163.           >INTEGER add(s1, s2)
  164.           >   char *s1, *s2;
  165.           >{
  166.           >  extern int atoi();
  167.           >
  168.           >  return( atoi(s1) + atoi(s2) );
  169.           >}
  170.           >/* ------------------------------------ */
  171.           >INTEGER sub(s1, s2)
  172.           >   char  *s1, *s2;
  173.           >{
  174.           >  extern int atoi();
  175.           >
  176.           >  return( atoi(s1) - atoi(s2) );
  177.  
  178.  
  179.  
  180.  Tue October 1 16:24 1991                                                Page 3
  181.  
  182.  
  183.  KR2ANSI (1)               Commands and Applications                KR2ANSI (1)
  184.  
  185.  
  186.  
  187.           >}
  188.           >/* ------------------------------------ */
  189.           >void dummy()
  190.           >{
  191.           >  /* empty */
  192.           >}
  193.           >/* ------------------------------------ */
  194.           >^D
  195.  
  196.       a)  Now we can generate an ANSI prototype-file 'math1.ans' by typing:
  197.           % kr2ansi INTEGER math.c > math1.ans
  198.  
  199.           The resulting file will look like this:
  200.           % cat math1.ans
  201.           extern INTEGER main(int, char **);
  202.           extern void usage(char *);
  203.           extern INTEGER add(char *, char *);
  204.           extern INTEGER sub(char *, char *);
  205.           extern void dummy(void);
  206.           %
  207.  
  208.       b)  If we want parameters to show in the prototypes, we type:
  209.           % kr2ansi -p INTEGER math.c > math2.ans
  210.  
  211.           to get:
  212.           %cat math2.ans
  213.           extern INTEGER main(int argc, char *argv[]);
  214.           extern void usage(char *s);
  215.           extern INTEGER add(char *s1, char *s2);
  216.           extern INTEGER sub(char *s1, char *s2);
  217.           extern void dummy(void);
  218.           %
  219.  
  220.       c)  Alternatively, we can create a file "types.txt"
  221.           % cat >types.txt
  222.           >INTEGER
  223.           >^D
  224.           %
  225.  
  226.           and use it for generating "math1.ans" and "math2.ans"
  227.           % kr2ansi -r types.txt math.c > math1.ans
  228.           % kr2ansi -p -r types.txt math.c > math2.ans
  229.  
  230.  
  231.  S✓SE✓EE✓E A✓AL✓LS✓SO✓O 
  232.       sh(1),  cat(1) 
  233.  
  234.  
  235.  V✓VE✓ER✓RS✓SI✓IO✓ON✓N 
  236.       kr2ansi ver 1.0  9/27/1991 
  237.  
  238.  
  239.  
  240.  Tue October 1 16:24 1991                                                Page 4
  241.  
  242.  
  243.  KR2ANSI (1)               Commands and Applications                KR2ANSI (1)
  244.  
  245.  
  246.  
  247.  
  248. A✓AU✓UT✓TH✓HO✓OR✓R 
  249.      Harry Karayiannis
  250.  
  251.      INTERnet:
  252.          harryk@bucsf.bu.edu   (OR nicos@bucsf.bu.edu)
  253.      BITnet:
  254.          cscrzcc@buacca.bu.edu (OR cscrzcc@buacca.BITNET)
  255.      Post:
  256.          15 North Beacon, #316
  257.          Allston, MA 02134
  258.          U.S.A.
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  Tue October 1 16:24 1991                                                Page 5
  301.  
  302.