
Raymond Toy pushed to branch issue-386-generate-def-unix-error at cmucl / cmucl Commits: 87a68573 by Raymond Toy at 2025-03-02T06:41:29-08:00 Copy things directly from the template Rearrangement of how create-errno.sh works. If we don't have a list of errno files, copy the template directly to the output since the template contains the default errno values. If we do, we can copy just the beginning and ending of the file, skipping the default values. The forms are auto-generated. We leave special markers in the template so we know what to copy. - - - - - 48dc62dc by Raymond Toy at 2025-03-02T06:47:06-08:00 Add some comments about special lines Add some comments not to modify the special lines used by bin/create-errno.sh. These are used by the script to figure out what to copy. - - - - - afdc7d7b by Raymond Toy at 2025-03-02T07:10:49-08:00 Add usage message and command line options Add -D and -S options to control how this script works. -D says to use the default instead of auto-generating. -S says to copy the result to stdout for quick viewing. These command line options are mostly for debugging the script. In any case, the file src/code/errno.lisp is always created. - - - - - 2 changed files: - bin/create-errno.sh - bin/errno-template.lisp Changes: ===================================== bin/create-errno.sh ===================================== @@ -5,34 +5,76 @@ # definitions of all the Unix errno values. # +usage () +{ + cat <<EOF +create-erno.sh [-h?DS] + -h This help + -? This help + -D Do not auto-generate; use default + + -S Show the resulting generated file; the file is still created. + +Auto-generates, if possible, the file src/code/errno.lisp that +contains the def-unix-error forms. +EOF + exit 0 +} + +while getopts "h?DS" arg +do + case $arg in + h) usage ;; + \?) usage ;; + D) DEFAULT=yes ;; + S) SHOW=yes ;; + esac +done + # Where the output should go. OUTPUT="src/code/errno.lisp" -# Copy the main errno template to the output. The template is a lisp -# file so we can read and modify it more easily. -cat bin/errno-template.lisp > $OUTPUT - -# Create appropriate DEF-UNIX-ERROR forms by reading header files -# containing the C definitions. +# Template file containing the default def-unix-error forms and other +# support code. +TEMPLATE="bin/errno-template.lisp" # Set ERRNO_FILES to the files where we can find errno definitions. -case `uname -s` in - Linux) ERRNO_FILES=/usr/include/asm-generic/errno*.h - ;; - Darwin) ERRNO_FILES=/usr/include/sys/errno.h - ;; - SunOS) ERRNO_FILES=/usr/include/sys/errno.h - ;; -esac - -awk -f bin/create-def-unix-error.awk ${ERRNO_FILES} >> $OUTPUT - -# The tail was also copied from code/unix.lisp. It's needed to tell -# Lisp about the errno values. -cat >>$OUTPUT <<EOF -;;; End auto-generated forms, if any. - -;;; -;;; And now for something completely different ... -(emit-unix-errors) +if [ -z "$DEFAULT" ]; then + case `uname -s` in + Linux) ERRNO_FILES=/usr/include/asm-generic/errno*.h + ;; + Darwin) ERRNO_FILES=/usr/include/sys/errno.h + ;; + SunOS) ERRNO_FILES=/usr/include/sys/errno.h + ;; + esac +fi + +if [ -z "$ERRNO_FILES" ]; then + # Copy the main errno template to the output. The template is a lisp + # file so we can read and modify it more easily. + cat "$TEMPLATE" > $OUTPUT +else + # We can autogenerate the def-unix-error forms. Copy just the + # initial part of the template, up to the first def-unix-error + # form. + sed '/^(def-unix-error ESUCCESS/q' "$TEMPLATE" > $OUTPUT + cat >> $OUTPUT <<EOF + +;; Autogenerated def-unix-error forms EOF + + # Create appropriate DEF-UNIX-ERROR forms by reading header files + # containing the C definitions. + + awk -f bin/create-def-unix-error.awk ${ERRNO_FILES} >> $OUTPUT + + # The tail was also copied from code/unix.lisp. It's needed to tell + # Lisp about the errno values. + sed '1,/^;;; End of default/d' "$TEMPLATE" >> $OUTPUT +fi + +# If -S option given, cat the output file to stdout +if [ -n "$SHOW" ]; then + cat $OUTPUT +fi ===================================== bin/errno-template.lisp ===================================== @@ -44,8 +44,11 @@ ;;; (def-unix-error ESUCCESS 0 _N"Successful") -#-(or linux darwin svr4) -(progn +;;; Do NOT modify the ESUCCESS form above. bin/create-errno.sh +;;; depends on it. + +;;; Default errno values. These are used only if we could not +;;; auto-generate these forms. (def-unix-error EPERM 1 _N"Operation not permitted") (def-unix-error ENOENT 2 _N"No such file or directory") (def-unix-error ESRCH 3 _N"No such process") @@ -138,7 +141,11 @@ ;;; VICE (def-unix-error EVICEERR 70 _N"Remote file system error _N") (def-unix-error EVICEOP 71 _N"syscall was handled by Vice") -) -;;; Auto-generated forms, if any, follow here. +;;; Do NOT modify the line below. bin/create-errno.sh depends on it. + +;;; End of default def-unix-error forms + +;;; And now for something completely different ... +(emit-unix-errors) View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/fc37bfe8d7644926ce41b21... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/fc37bfe8d7644926ce41b21... You're receiving this email because of your account on gitlab.common-lisp.net.