| 1 | #! /bin/sh |
| 2 | # |
| 3 | # |
| 4 | # This script completes the constants.c_pre file with the |
| 5 | # the list of defines needed to build the adasockets constant |
| 6 | # package. |
| 7 | # |
| 8 | # This file is part of Adasockets for RTEMS. |
| 9 | # |
| 10 | |
| 11 | if [ $# -ne 2 ] ; then |
| 12 | echo $0: constantsFile outputFile |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | constantListFile=$1 |
| 17 | outputFile=$2 |
| 18 | |
| 19 | cat >${outputFile} <<EOF |
| 20 | /* |
| 21 | * This is an incomplete C program preamble aimed to extract |
| 22 | * constants' values. The complete source is generated by |
| 23 | * create_constants_c.sh. |
| 24 | * |
| 25 | * NOTE: THIS CODE IS SPECIFIC TO RTEMS |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | #include <stdlib.h> |
| 30 | #include <stdio.h> |
| 31 | #include <string.h> |
| 32 | #include <errno.h> |
| 33 | #include <ctype.h> |
| 34 | #include <sys/fcntl.h> |
| 35 | #include <sys/ioccom.h> |
| 36 | #include <sys/filio.h> |
| 37 | |
| 38 | #include <netdb.h> |
| 39 | #include <netinet/in.h> |
| 40 | #include <netinet/tcp.h> |
| 41 | #include <arpa/inet.h> |
| 42 | #include <sys/socket.h> |
| 43 | #include <net/if.h> |
| 44 | |
| 45 | |
| 46 | static char * |
| 47 | capitalize (char *name) |
| 48 | { |
| 49 | int beginning = 1; |
| 50 | char *result = (char *) malloc (strlen (name) + 1); |
| 51 | char *ptr; |
| 52 | for (ptr = result; *name; ptr++, name++) { |
| 53 | *ptr = *name; |
| 54 | if (beginning) { |
| 55 | beginning = 0; |
| 56 | } else if (*ptr == '_') { |
| 57 | beginning = 1; |
| 58 | } else if (isupper(*ptr)) { |
| 59 | *ptr = tolower(*ptr); |
| 60 | } |
| 61 | } |
| 62 | *ptr = '\0'; |
| 63 | return result; |
| 64 | } |
| 65 | |
| 66 | static void |
| 67 | output (char *name, int value) |
| 68 | { |
| 69 | char *capitalized = capitalize (name); |
| 70 | if (value != -1) { |
| 71 | printf (" %-20s : constant := 16#%04X#;\n", capitalized, value); |
| 72 | } else { |
| 73 | printf (" %-20s : constant := %d;\n", capitalized, value); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void print_body(void); |
| 78 | |
| 79 | void print_socket_constants_ads( void ) |
| 80 | { |
| 81 | printf( |
| 82 | "-- This file has been generated automatically by\n" |
| 83 | "-- the constants.c file generated by create_constants_c.sh.\n" |
| 84 | "--\n" |
| 85 | "-- This file is part of adasockets port to RTEMS.\n" |
| 86 | "--\n" |
| 87 | "\n" |
| 88 | "package sockets.constants is\n" |
| 89 | ); |
| 90 | print_body(); |
| 91 | printf( "end sockets.constants;\n"); |
| 92 | } |
| 93 | |
| 94 | void print_body() |
| 95 | { |
| 96 | EOF |
| 97 | |
| 98 | # |
| 99 | # Now generate the body of the function that acr |
| 100 | # |
| 101 | while read line |
| 102 | do |
| 103 | echo "#ifdef ${line}" |
| 104 | echo " output( \"${line}\", ${line});" |
| 105 | echo "#else" |
| 106 | echo " output( \"${line}\", -1);" |
| 107 | echo "#endif" |
| 108 | done < ${constantListFile} >>${outputFile} |
| 109 | |
| 110 | echo "}" >>${outputFile} |
| 111 | exit 0 |