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