From 98524eef690bdc903e424dc707d3dc42fd9d7f2d Mon Sep 17 00:00:00 2001
From: pierre <pierre@freepascal.org>
Date: Fri, 7 Oct 2011 18:41:35 +0000
Subject: [PATCH]  * Script to check system call numbers

git-svn-id: trunk@19404 -
---
 .gitattributes           |  1 +
 rtl/openbsd/check_sys.sh | 48 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100755 rtl/openbsd/check_sys.sh

diff --git a/.gitattributes b/.gitattributes
index e76bc63ff7..75cea2ea96 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -7833,6 +7833,7 @@ rtl/objpas/varutilh.inc svneol=native#text/plain
 rtl/objpas/varutils.inc svneol=native#text/plain
 rtl/openbsd/Makefile svneol=native#text/plain
 rtl/openbsd/Makefile.fpc svneol=native#text/plain
+rtl/openbsd/check_sys.sh svneol=native#text/plain
 rtl/openbsd/classes.pp svneol=native#text/plain
 rtl/openbsd/errno.inc svneol=native#text/plain
 rtl/openbsd/errnostr.inc svneol=native#text/plain
diff --git a/rtl/openbsd/check_sys.sh b/rtl/openbsd/check_sys.sh
new file mode 100755
index 0000000000..18c80cd3b0
--- /dev/null
+++ b/rtl/openbsd/check_sys.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+# Script to test fpc to system syscall numbers
+
+# Location of syscall header in system
+
+syscall_header=/usr/include/sys/syscall.h
+
+verbose=0
+
+# Sustitution made to pass from fpc syscall number
+# to system define 
+fpc_syscall_prefix=syscall_nr_
+syscall_prefix=SYS_
+
+# You should only need to change the varaibles above
+
+sed -n "s:${fpc_syscall_prefix}\\([_a-zA-Z0-9]*\\)[ \t]*=[ \t]*\\([0-9]*\\).*:check_syscall_number ${syscall_prefix}\1 \2:p" sysnr.inc > check_sys_list.sh
+
+function check_syscall_number ()
+{
+  sys=$1
+  value=$2
+  if [ $verbose -ne 0 ] ; then
+    echo Testing $sys value $value
+  fi
+  found=`sed -n "/#define.*${sys}[^A-Za-z0-9_]/p" ${syscall_header}`
+  val=`sed -n "s:#define.*${sys}[^A-Za-z0-9_]*\([0-9]*\).*:\1:p" ${syscall_header}`
+  if [ $verbose -ne 0 ] ; then
+    echo Test for $sys found \"${found}\" \"${value}\" \"${val}\"
+  fi
+  if [ "${val}" == "${value}" ] ; then
+    if [ $verbose -ne 0 ] ; then
+      echo ${sys} value ${val} is correct
+    fi
+  else
+    if [ "${val}" == "" ] ; then
+      found=`sed -n "/#define.*[^A-Za-z0-9_]${value}$/p" ${syscall_header}`
+      if [ "${found}" == "" ] ; then
+        found=`sed -n "s|/\\*.* ${value} is compat|${value} is compat|p" ${syscall_header}`
+      fi
+    fi
+    echo problem for ${sys} expected ${value} line is \"${found}\"
+  fi
+}
+
+source ./check_sys_list.sh
+