source: rtems/tools/cpu/sh/shgen.c @ 5f5f681

4.104.115
Last change on this file since 5f5f681 was f4f96e9, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/31/06 at 05:49:12

2006-01-31 Ralf Corsepius <ralf.corsepius@…>

  • shgen.c: include <stdlib.h>.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Copyright (c) 1998,1999,2000, 2006 Ralf Corsepius, Ulm Germany.
3 *
4 * See the file COPYING for copyright notice.
5 */
6
7#include <stdio.h>
8#include <string.h>     /* strcmp, strerror */
9#include <stdlib.h>     /* exit */
10#include <errno.h>
11#include <getopt.h>
12
13#include "sci.h"
14
15static void usage( FILE* ofile, char *prog )
16{
17  fprintf( ofile, "Usage: %s [options] driver\n", prog );
18  fprintf( ofile, "\nOptions:\n" );
19  fprintf( ofile, "Processor frequency (default 20MHz):\n") ;
20  fprintf( ofile, "\t-M Phi      .. processor frequency [MHz]\n" );
21  fprintf( ofile, "\t-K Phi      .. processor frequency [KHz]\n" );
22  fprintf( ofile, "\t-H Phi      .. processor frequency [Hz]\n" );
23  fprintf( ofile, "Driver:\n" );
24  fprintf( ofile, "\tsci         .. bitrate table for sci\n" );
25
26  fprintf( ofile, "\nWritten by Ralf Corsepius <corsepiu@faw.uni-ulm.de>\n" );
27  fprintf( ofile, "\nCopyright (c) 1998,1999,2000\tRalf Corsepius\n" );
28}
29
30#if HAVE_GETOPT_LONG
31#define NOARG   0
32#define HASARG  1
33#define OPTARG  2
34
35static struct option long_options[] =
36{
37  { "version",          NOARG,  NULL, 'v' },
38  { "help",             NOARG,  NULL, 'h' },
39  { "mega-hertz",       HASARG, NULL, 'M' },
40  { "kilo-hertz",       HASARG, NULL, 'K' },
41  { "hertz",            HASARG, NULL, 'H' },
42  { 0, 0, 0, 0 }
43};
44#endif
45
46static void shgen_header( FILE *file )
47{
48  fprintf( file,
49    "/*\n * DO NOT EDIT - this file is automatically generated by shgen %s\n",
50    VERSION );
51  fprintf( file,
52    " * Copyright (c) 1998,1999,2000 Ralf Corsepius (corsepiu@faw.uni-ulm.de)\n */\n" );
53  fprintf( file,
54    "\n/* This file is not copyrighted */\n\n" );
55}
56
57int main( int argc, char *argv[] )
58{
59  double        Phi = 20000000.0 ;
60
61#if HAVE_GETOPT_LONG
62  int option_index = 0 ;
63  while( ( optopt = getopt_long( argc, argv, "M:K:H:hv",
64      long_options, &option_index ) ) > 0 )
65#else
66  while ( ( optopt = getopt( argc, argv, "M:K:H:hv" ) ) > 0 )
67#endif
68  {
69    switch ( optopt )
70    {
71    case 'M' :
72      sscanf( optarg, "%lf", &Phi );
73      Phi = Phi * 1000000.0;
74      break ;
75    case 'K' :
76      sscanf( optarg, "%lf", &Phi );
77      Phi = Phi * 1000.0;
78      break ;
79    case 'H' :
80      sscanf( optarg, "%lf", &Phi );
81      break ;
82    case 'h' :
83      usage( stdout, argv[0] );
84      exit(0);
85    case 'v' :
86      fprintf( stdout, "%s version %s\n", argv[0], VERSION );
87      exit(0);
88    default  :
89      usage( stderr, argv[0] );
90      exit(1);
91      break ;
92    }
93  }
94
95  if ( argc - optind != 1 )
96  {
97    fprintf( stderr, "%s: Missing argument: driver\n", argv[0] );
98    exit(1);
99  }
100
101  shgen_header( stdout );
102
103  if ( strcmp( argv[optind], "sci" ) == 0 )
104  {
105    shgen_gensci( stdout, Phi );
106  }
107  else
108  {
109    fprintf( stderr, "%s: Invalid argument: driver\n", argv[0] );
110    exit(1);
111  }
112
113  return 0 ;
114}
Note: See TracBrowser for help on using the repository browser.