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