akaros/scripts/make_syscall_tbl.sh
<<
>>
Prefs
   1#!/bin/bash
   2# Barret Rhoden <brho@cs.berkeley.edu>
   3# Builds a syscall table, an array of strings of syscall names.
   4# Used by parlib.
   5
   6if [ $# -ne 2 ]
   7then
   8        echo "Need syscall.h and output file args!"
   9        exit -1
  10fi
  11
  12SYSLIST=$1
  13SYSCALL_TBL=$2
  14
  15echo "// This was automatically generated with make_syscall_tbl.sh, do not edit" > $SYSCALL_TBL
  16echo ""                                    >> $SYSCALL_TBL
  17echo "const char *const __syscall_tbl[] =" >> $SYSCALL_TBL
  18echo "{"                                   >> $SYSCALL_TBL
  19
  20# Read lines formatted as:
  21#
  22#  #define      SYS_foo         1
  23#  #define      SYS_bar         3
  24#
  25# And output them as:
  26#
  27#  [ 1 ] = "foo",
  28#  [ 3 ] = "bar",
  29#
  30# Here's the guts of it.  Get the #define SYS_'s, compress the whitespace, cut
  31# to drop the #define, drop the SYS_, then awk it.
  32
  33cat $SYSLIST | grep "^#define SYS_" \
  34             | sed 's/\s\+/\t/g' \
  35             | cut -f 2- \
  36             | sed 's/SYS_//' \
  37             | awk '{printf "\t[ %s ] = \"%s\",\n", $2, $1}' \
  38             >> $SYSCALL_TBL
  39
  40echo "};"                                 >> $SYSCALL_TBL
  41echo ""                                   >> $SYSCALL_TBL
  42echo "const int __syscall_tbl_sz = sizeof (__syscall_tbl) / sizeof (__syscall_tbl[0]);" >> $SYSCALL_TBL
  43