aboutsummaryrefslogtreecommitdiffstats
path: root/vorlesungsnotizen/bin
diff options
context:
space:
mode:
authorLordMcFungus <mceagle117@gmail.com>2022-03-08 15:04:08 +0100
committerGitHub <noreply@github.com>2022-03-08 15:04:08 +0100
commit83df2bd525918600dd37f10b0abeacb8e397c54d (patch)
tree4960c853c60a4e2237c8ec17ba4c4668c5089509 /vorlesungsnotizen/bin
parentimprove slides (diff)
parentfix buchcover (diff)
downloadSeminarSpezielleFunktionen-83df2bd525918600dd37f10b0abeacb8e397c54d.tar.gz
SeminarSpezielleFunktionen-83df2bd525918600dd37f10b0abeacb8e397c54d.zip
Merge pull request #1 from AndreasFMueller/master
update
Diffstat (limited to 'vorlesungsnotizen/bin')
-rw-r--r--vorlesungsnotizen/bin/Makefile12
-rw-r--r--vorlesungsnotizen/bin/numbered.tex33
-rw-r--r--vorlesungsnotizen/bin/numberpages.cpp173
3 files changed, 218 insertions, 0 deletions
diff --git a/vorlesungsnotizen/bin/Makefile b/vorlesungsnotizen/bin/Makefile
new file mode 100644
index 0000000..e3feff8
--- /dev/null
+++ b/vorlesungsnotizen/bin/Makefile
@@ -0,0 +1,12 @@
+#
+# Makefile to build numbering script
+#
+# (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
+#
+numberpages: numberpages.cpp
+ c++ -std=c++11 -g -Wall -o numberpages numberpages.cpp
+
+test: numberpages
+ ./numberpages --debug --section "Komplexe Funktionentheorie" \
+ --force \
+ "../MSE/1 - Komplexe Funktionen.pdf" blubb.pdf
diff --git a/vorlesungsnotizen/bin/numbered.tex b/vorlesungsnotizen/bin/numbered.tex
new file mode 100644
index 0000000..bba61b6
--- /dev/null
+++ b/vorlesungsnotizen/bin/numbered.tex
@@ -0,0 +1,33 @@
+%
+% numbered.tex
+%
+% (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
+%
+\documentclass[8pt,a4paper]{article}
+\usepackage[final]{pdfpages}
+\usepackage{geometry}
+\usepackage{times}
+\geometry{papersize={210mm,297mm},total={180mm,260mm},top=21mm}
+\usepackage{fancyhdr}
+
+%\topmargin 20pt
+%\oddsidemargin 20pt
+
+% from the TeXBook, page 308, exercise 7.7
+\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax}
+
+\pagestyle{fancy}
+\ifundefined{sectionnumber}
+\cfoot{\sffamily\Large\thepage}
+\else
+\cfoot{\sffamily\Large \sectionnumber{} -- \thepage}
+\fi
+\renewcommand {\headrulewidth}{0pt}
+
+\begin{document}
+\includepdfset{pagecommand=\thispagestyle{empty}}
+\includepdf[fitpaper=true,scale=0.95,pages={1}]{unnumbered.pdf}
+\setcounter{page}{1}
+\includepdfset{pagecommand=\thispagestyle{fancy}}
+\includepdf[fitpaper=true,scale=0.94,pages=2-]{unnumbered.pdf}
+\end{document}
diff --git a/vorlesungsnotizen/bin/numberpages.cpp b/vorlesungsnotizen/bin/numberpages.cpp
new file mode 100644
index 0000000..704a671
--- /dev/null
+++ b/vorlesungsnotizen/bin/numberpages.cpp
@@ -0,0 +1,173 @@
+/*
+ * numberpages.cpp -- driver program to number pages in a PDF, this was
+ * mainly necessary because the shell breaks blanks
+ * in the section option string
+ *
+ * (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
+ */
+#include <cstdio>
+#include <cstdlib>
+#include <getopt.h>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <sys/stat.h>
+
+void usage(char *progname) {
+ std::cout << "usage: " << progname << " [ -f ] [ -s section ] ";
+ std::cout << "<unnumbered.pdf> <numbered.pdf>" << std::endl;
+}
+
+struct option longoptions[] = {
+{ "debug", no_argument, NULL, 'd' },
+{ "section", required_argument, NULL, 's' },
+{ "force", no_argument, NULL, 'f' },
+{ NULL, no_argument, NULL, 0 }
+};
+
+int main(int argc, char *argv[]) {
+ bool force = false;
+ bool debug = false;
+ std::string section;
+ int c, longindex, rc;
+ while (EOF != (c = getopt_long(argc, argv, "dfhs:?", longoptions,
+ &longindex))) {
+ switch (c) {
+ case 'd':
+ debug = true;
+ break;
+ case 'f':
+ force = true;
+ break;
+ case 'h':
+ case '?':
+ usage(argv[0]);
+ return EXIT_SUCCESS;
+ case 's':
+ section = std::string(optarg);
+ if (debug) {
+ std::cout << "section string: " << section;
+ std::cout << std::endl;
+ }
+ break;
+ }
+ }
+
+ // remaining arguments are file names
+ if ((argc - optind) < 2) {
+ std::cerr << "not enough arguments" << std::endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+ std::string unnumbered = std::string(argv[optind++]);
+ std::string numbered = std::string(argv[optind++]);
+ if (debug) {
+ std::cout << "numbering " << unnumbered;
+ std::cout << ", sending output to " << unnumbered;
+ std::cout << std::endl;
+ }
+
+ // make sure input file does exist
+ struct stat sb;
+ rc = stat(unnumbered.c_str(), &sb);
+ if ((0 == rc) && S_ISREG(sb.st_mode)) {
+ if (debug) {
+ std::cout << "input file " << unnumbered << " found";
+ std::cout << std::endl;
+ }
+ } else {
+ std::cerr << "cannot find " << unnumbered << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // make sure the "unnumbered.pdf" file does not exist
+ rc = stat("unnumbered.pdf", &sb);
+ if (0 == rc) {
+ std::cerr << "file unnumbered.pdf exists, clean up first";
+ std::cerr << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // test for existence of output file
+ rc = stat(numbered.c_str(), &sb);
+ if ((!force) && (0 == rc)) {
+ std::cerr << "output file exists, use --force option";
+ std::cerr << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // make sure the numbered.tex is present
+ rc = stat("numbered.tex", &sb);
+ if ((0 != rc) || (!S_ISREG(sb.st_mode))) {
+ std::cerr << "file 'numbered.tex' is missing" << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // remove the "numbered.pdf" if it exists
+ if (debug) {
+ std::cout << "removing numbered.pdf" << std::endl;
+ }
+ unlink("numbered.pdf");
+
+ // copy the file
+ {
+ std::ostringstream out;
+ out << "cp '" << unnumbered << "' unnumbered.pdf";
+ out.flush();
+ std::string copycommand = out.str();
+ rc = system(copycommand.c_str());
+ if (0 != rc) {
+ std::cerr << "could not copy " << unnumbered;
+ std::cerr << " to unnumbered.pdf: " << rc << std::endl;
+ return EXIT_FAILURE;
+ }
+ if (debug) {
+ std::cout << "file " << unnumbered << " copied to ";
+ std::cout << "unnumbered.pdf" << std::endl;
+ }
+ }
+
+ // prepare command line
+ std::ostringstream out;
+ out << "pdflatex ";
+ if (section.size() > 0) {
+ out << "\\\\def\\\\sectionnumber{" << section << "} ";
+ out << "\\\\input{numbered.tex}";
+ } else {
+ out << unnumbered;
+ }
+ if (debug) {
+ std::cout << "command line: " << out.str() << std::endl;
+ }
+
+ // run the command
+ rc = system(out.str().c_str());
+ if (0 != rc) {
+ std::cerr << "pdflatex failed: " << rc << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // check for the existence of the output file
+ rc = stat("numbered.pdf", &sb);
+ if ((0 != rc) || (!S_ISREG(sb.st_mode))) {
+ std::cerr << "output file 'numbered.pdf' not found";
+ std::cerr << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // rename the output file
+ rc = rename("numbered.pdf", numbered.c_str());
+ if (rc != 0) {
+ std::string error(strerror(errno));
+ std::cerr << "cannot rename file to '" << numbered << ": ";
+ std::cerr << error << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ // perform some cleanup
+ unlink("unnumbered.pdf");
+ unlink("numbered.log");
+ unlink("numbered.aux");
+
+ return EXIT_SUCCESS;
+}