Skip to content

Commit

Permalink
use the new hlabel command to properly create links in PDFs
Browse files Browse the repository at this point in the history
fixes #44
  • Loading branch information
vladak committed Nov 5, 2023
1 parent 98ea2b5 commit 88d774a
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 147 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Install pre-requisites for spell check
working-directory: master
run: ./dev/install-spellcheck.sh
- name: Check labels
working-directory: master
run: ./dev/check-label.sh
- name: Run spellcheck
working-directory: master
run: make spellcheck
Expand Down
4 changes: 4 additions & 0 deletions common.tex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
\renewcommand{\slidelabel}{}
\setlength{\textwidth}{0.9\textwidth}

% This command has to be used throught the sources instead of \label
% for hyperref to be able to create valid links.
\newcommand{\hlabel}{\phantomsection\label}

\newcommand{\sltitle}[1]{{\centering\textbf{\Large #1}
\vskip 2em plus 0pt minus 2em\par}} % Slide title

Expand Down
10 changes: 10 additions & 0 deletions dev/check-label.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if grep '\\label{.*}' *.tex >/tmp/label-err.out; then
echo "Some of the *.tex files contain the \\label command."
echo "This is unwanted as this leads to invalid links in PDFs."
echo "Use \\hlabel instead."
echo ""
cat /tmp/label-err.out
exit 1
fi
34 changes: 17 additions & 17 deletions file-api.tex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
\end{center}
\end{slide}

\label{OPENFILETABLES}
\hlabel{OPENFILETABLES}

\begin{itemize}
\item This is a simplified view of the kernel tables that deal with files. It
Expand Down Expand Up @@ -113,7 +113,7 @@
\end{itemize}
\end{slide}

\label{OPEN}
\hlabel{OPEN}

\begin{itemize}
\item The first available file descriptor is always used.
Expand Down Expand Up @@ -145,7 +145,7 @@
reading.
\item \texttt{O\_NOCTTY} \dots{} when opening a terminal by a process without a
controlling terminal, the terminal being opened does not become one.
\item \label{O_NONBLOCK} \texttt{O\_NONBLOCK} \dots{} if reading or writing
\item \hlabel{O_NONBLOCK} \texttt{O\_NONBLOCK} \dots{} if reading or writing
cannot be satisfied right away, calls \texttt{read}/\texttt{write} will fail
instead of getting blocked and waiting for the completion. \texttt{errno} is
set to \texttt{EAGAIN} in such a case.
Expand Down Expand Up @@ -187,8 +187,8 @@
\end{itemize}
\end{slide}

\label{MKFIFO}
\label{CREAT}
\hlabel{MKFIFO}
\hlabel{CREAT}

\begin{itemize}
\item The \texttt{open} call allows opening of a regular file, device, or named
Expand Down Expand Up @@ -230,7 +230,7 @@
\end{itemize}
\end{slide}

\label{READCALL}
\hlabel{READCALL}

\begin{itemize}
\setlength{\itemsep}{0.8\itemsep}
Expand Down Expand Up @@ -306,7 +306,7 @@
and it is a long living process, a daemon perhaps, depending on the system
configuration you may hit memory starvation as the system memory will be filled
with an ever growing file descriptor table.
\item \label{SIMPLE_CAT} A very simple \texttt{cat(1)} program:
\item \hlabel{SIMPLE_CAT} A very simple \texttt{cat(1)} program:
\example{read/cat.c}
\end{itemize}

Expand Down Expand Up @@ -386,7 +386,7 @@
\end{itemize}
\end{slide}

\label{NAMEDPIPE}
\hlabel{NAMEDPIPE}

\begin{itemize}
\item A named pipe is created using the system call \texttt{mkfifo}, see page
Expand Down Expand Up @@ -491,7 +491,7 @@
\end{slide}

\begin{itemize}
\item \label{LSEEK} The first byte is at position 0. If it makes sense, you may
\item \hlabel{LSEEK} The first byte is at position 0. If it makes sense, you may
use a negative number for setting the \emph{offset}. Example:
\example{read/lseek.c}.
\item It is legal to move beyond the end of the file. If data is written there,
Expand All @@ -505,7 +505,7 @@
\item You can obviously use the return value of \texttt{lseek} not only for
subsequent calls to \texttt{read} and \texttt{write} but also for another call
to \texttt{lseek}.
\item \label{BIG_FILE} Beware of files with holes as it may lead to problems
\item \hlabel{BIG_FILE} Beware of files with holes as it may lead to problems
with backing up the data. Example: \example{read/big-file.c} demonstrates that
moving a sparse file may end up in an actual storage data occupation increase.
It greatly depends on the system you run, what archiving utility is used, and
Expand Down Expand Up @@ -568,7 +568,7 @@
\end{itemize}
\end{slide}

\label{DUP_CALL}
\hlabel{DUP_CALL}

\begin{itemize}
\item We already know that the first available file descriptor is used when
Expand Down Expand Up @@ -610,7 +610,7 @@
\begin{itemize}
\item Note the flag \texttt{O\_APPEND} used to implement a redirection
\texttt{>>}.
\item \label{REDIRECT} Another example of \texttt{dup} use will be provided when
\item \hlabel{REDIRECT} Another example of \texttt{dup} use will be provided when
we start working with pipes. The first redirection example from the slide
(without \texttt{stderr}) is in \example{read/redirect.c}. In that example, the
\texttt{execl} call replaces the current process image with the
Expand Down Expand Up @@ -682,7 +682,7 @@
\end{itemize}
\end{slide}

\label{FCNTL}
\hlabel{FCNTL}

\begin{itemize}
\item Example: close standard error output on program execution (exec call):\\
Expand Down Expand Up @@ -790,7 +790,7 @@
last modification of the inode.
\item The UNIX norm does not specify the ordering of the \texttt{struct stat}
members, nor does it prohibit adding new ones.
\item \label{STAT} Example: \example{stat/stat.c}
\item \hlabel{STAT} Example: \example{stat/stat.c}
\item You can call \texttt{fstat} on file descriptors 0, 1, and 2 as well. Unless
redirected before, you will get information on the underlying terminal device
(e.g. \texttt{/dev/ttys011} on macOS). Example: \example{stat/stat012.c}.
Expand Down Expand Up @@ -897,7 +897,7 @@
\emph{path2} to file \emph{path1}. Hard links cannot span filesystems (use
\funnm{symlink} for that).
\end{itemize}
\label{UNLINK} \texttt{ int \funnm{unlink}(const char *\emph{path});}
\hlabel{UNLINK} \texttt{ int \funnm{unlink}(const char *\emph{path});}
\begin{itemize}
\item deletes a name (i.e. a directory entry) and after deleting the last link to
the file and after closing the file by all processes, deletes the file data.
Expand Down Expand Up @@ -1028,7 +1028,7 @@
mountpoint; this member contains the i-node number of the directory where the
filesystem is mounted and not the root of the mounted filesystem as one might
expect.
\item \label{D_TYPE} Some system have a \texttt{struct dirent} member
\item \hlabel{D_TYPE} Some system have a \texttt{struct dirent} member
\texttt{d\_type}. It can have values of \texttt{DT\_REG}, \texttt{DT\_DIR},
\texttt{DT\_FIFO} etc., see the man page for \texttt{dirent}. It was a BSD
specific thing and subsequently copied by other systems, including Linux.
Expand All @@ -1038,7 +1038,7 @@
to remove all entries before you can delete a directory. You can use
\texttt{system("rm -r xxx")} etc. but be careful to sanitize the environment and
the directory name to avoid any security implications.
\item \label{REMOVE} The specification also defines \texttt{remove} which
\item \hlabel{REMOVE} The specification also defines \texttt{remove} which
behaves like \texttt{unlink} for files and as \texttt{rmdir} for directories.
\end{itemize}

Expand Down
4 changes: 2 additions & 2 deletions files.tex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
\end{itemize}
\end{slide}

\label{DEVFS}
\hlabel{DEVFS}

\begin{itemize}
\item Devices, files in \texttt{/proc}, terminals, memory etc. are of one type
Expand Down Expand Up @@ -433,7 +433,7 @@

%%%%%

\label{VFS}
\hlabel{VFS}
\pdfbookmark[1]{Virtual File System}{VFS}

\begin{slide}
Expand Down
36 changes: 18 additions & 18 deletions intro.tex
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
\end{itemize}
\end{slide}

\label{UNIXSTANDARDS}
\hlabel{UNIXSTANDARDS}

\begin{itemize}
\item The very basic information is that the area of UNIX standards is very
Expand Down Expand Up @@ -244,7 +244,7 @@
\end{itemize}
\end{slide}

\label{POSIX}
\hlabel{POSIX}

\begin{itemize}
\item The first document is \emph{IEEE Std POSIX1003.1-1988}, formerly simply
Expand Down Expand Up @@ -346,7 +346,7 @@
\end{enumerate}
\end{slide}

\label{REF_PROGRAMMING}
\hlabel{REF_PROGRAMMING}

\begin{enumerate}
\item One of the best book on programming in Unix environment. Does not cover
Expand All @@ -362,7 +362,7 @@
recommended.
\item UNIX specifications.
\item Detailed descriptions of system calls and functions.
\item \label{POSIX4} A book that did not fit the slide and covers topics outside
\item \hlabel{POSIX4} A book that did not fit the slide and covers topics outside
of the scope of this class: Gall\-meis\-ter, B. R.: \emsl{POSIX.4 Programmers
Guide: Programming for the Real World}, O'Reilly; \nth{1} edition, 1995. A great
book on real-time POSIX extensions with a beautiful cover. See also pages
Expand Down Expand Up @@ -410,7 +410,7 @@
%%%%%

\pdfbookmark[1]{The C Programming Language}{C}
\label{C_LANGUAGE}
\hlabel{C_LANGUAGE}

\begin{slide}
\sltitle{The C Programming Language}
Expand Down Expand Up @@ -499,7 +499,7 @@
\end{itemize}
\end{slide}

\label{BYTE_ORDERING}
\hlabel{BYTE_ORDERING}

\begin{itemize}
\item Be careful when using tools like \texttt{hexdump} that by default print
Expand Down Expand Up @@ -551,7 +551,7 @@
\end{itemize}
\end{slide}

\label{NEWLINECHAR}
\hlabel{NEWLINECHAR}

\begin{itemize}
\item \emsl{LF}, \emph{line feed}, sometimes also referred to as \emph{new
Expand Down Expand Up @@ -1092,7 +1092,7 @@
\end{minipage}
\end{slide}

\label{MAKE}.
\hlabel{MAKE}.

\begin{itemize}
\item You could compile and link the program via one invocation of a compiler,
Expand Down Expand Up @@ -1268,7 +1268,7 @@
\end{itemize}
\end{slide}

\label{RUNTIMELINKER}
\hlabel{RUNTIMELINKER}

\begin{itemize}
\item An ELF object format is explained on page \pageref{ELF}.
Expand Down Expand Up @@ -1365,7 +1365,7 @@
\item You can also edit ELF objects via \texttt{elfedit(1)} on Solaris. You can
change \texttt{RUNPATH}, for example.
\end{itemize}
\item \label{EVIL_LDLIBPATH} In general, you should not use
\item \hlabel{EVIL_LDLIBPATH} In general, you should not use
\texttt{LD\_LIBRARY\_PATH} for anything else than debugging during the
development or when moving libraries between directories. You can find lots of
articles on ``why is \texttt{LD\_LIBRARY\_PATH} evil?'' etc. For example,
Expand Down Expand Up @@ -1413,7 +1413,7 @@
\end{itemize}
\end{slide}

\label{API_ABI}
\hlabel{API_ABI}

\begin{itemize}
\item In short -- an API is source code based while an ABI is binary based.
Expand Down Expand Up @@ -1482,7 +1482,7 @@
-1077941135
\end{verbatim}

\item \label{ABI_MAIN} Example: \example{lib-abi/abi-main.c} (see the block
\item \hlabel{ABI_MAIN} Example: \example{lib-abi/abi-main.c} (see the block
comment in the file on how to use other files located in the same directory).
\item To change an ABI safely, you need library versioning -- if the library
ABI change is not backward compatible, a bumped up version needs to prevent
Expand Down Expand Up @@ -1867,7 +1867,7 @@
different from an empty string.
\item To go through all the command line arguments, you can either use
\emph{argc} or test for \texttt{NULL} in \texttt{argv[i]}.
\item \label{SHELL_ARGV0} \texttt{argv[0]} is sometimes a source of additional
\item \hlabel{SHELL_ARGV0} \texttt{argv[0]} is sometimes a source of additional
information. For example, commands \texttt{cp}, \texttt{mv}, and \texttt{ln} may
be linked to the same executable (Solaris). The value of \texttt{argv[0]} then
tells the process what function it is supposed to perform. Another example -- if
Expand Down Expand Up @@ -1912,7 +1912,7 @@
prog && echo "success" || echo "failure"
\end{verbatim}
Example: \example{main/return-256.c}.
\item \label{RETURN255} Never use \texttt{return (-1)} in \texttt{main} nor
\item \hlabel{RETURN255} Never use \texttt{return (-1)} in \texttt{main} nor
\texttt{exit(-1)}. Based on the information in the previous paragraph,
from \texttt{-1} you will get \texttt{255} as the return value you get in the
shell in \texttt{\$?}. It just creates confusion.
Expand All @@ -1927,7 +1927,7 @@
\emsl{without} printing a new line), and calls functions registered via
\texttt{atexit()}, and possibly other actions based on a specific system.
Example: \example{exit/exit.c} and \example{exit/atexit-abort.c}
\item \label{MAIN_C} Example on printing out command line arguments:
\item \hlabel{MAIN_C} Example on printing out command line arguments:
\example{main/print-argv.c}
\item If a process is killed by a signal, you can get the signal number from its
return value as presented by the shell. See page
Expand Down Expand Up @@ -2175,7 +2175,7 @@
processing.
\item When a undefined option is used, \texttt{getopt} will print an error;
this can be suppressed by setting the \texttt{opterr} variable to 0.
\item \label{GETOPT} Example: shell script \example{getopt/getopts.sh}
\item \hlabel{GETOPT} Example: shell script \example{getopt/getopts.sh}
rewritten to C language using the \texttt{getopt} function:
\example{getopt/getopt.c}
\end{itemize}
Expand Down Expand Up @@ -2499,7 +2499,7 @@
\item Many \texttt{libc} functions and functions from other libraries set
\texttt{errno} on failure as well. You always need to consult the relevant
documentation.
\item \label{ERRNO} It is common nowadays that \texttt{errno} is in reality
\item \hlabel{ERRNO} It is common nowadays that \texttt{errno} is in reality
defined in \texttt{libc} as a dereferenced pointer to an integer returned by a
function (returned pointer is specific to a userland thread) and the value is
set right after the instruction for the system call. For example, on the i386
Expand Down Expand Up @@ -2557,7 +2557,7 @@
%%%%%

\begin{itemize}
\label{ERR}
\hlabel{ERR}
\item The \funnm{errx}() function behaves as \funnm{err}() but does not use
\texttt{errno} to print that extra error message. Similarly, \funnm{warnx}().
\item These functions are very handy especially for smaller programs as they are
Expand Down
Loading

0 comments on commit 88d774a

Please sign in to comment.