Skip to content
This repository was archived by the owner on Oct 26, 2021. It is now read-only.

Commit c6c5afa

Browse files
author
nashinium
committed
first commit
0 parents  commit c6c5afa

File tree

1,938 files changed

+353633
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,938 files changed

+353633
-0
lines changed

Chapter02/Makefile

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#
2+
# This is a common Makefile for code examples from the book
3+
# "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
4+
#
5+
6+
#
7+
# Usage:
8+
# make - Build all examples
9+
# make clean - Clean all examples
10+
# make test - Run the test suite
11+
#
12+
13+
INCLUDES =
14+
LIBS = -lstdc++
15+
CXXFLAGS = $(INCLUDES) -Wall -time -O3 -DNDEBUG
16+
LIBFLAGS =
17+
AR = ar
18+
19+
.SUFFIXES: .cpp .o
20+
21+
# Create a list of source files.
22+
SOURCES = $(shell ls *.cpp)
23+
# Create a list of object files from the source file lists.
24+
OBJECTS = ${SOURCES:.cpp=.o}
25+
# Create a list of targets.
26+
TARGETS = ${SOURCES:.cpp=.exe}
27+
28+
# Build all targets by default
29+
all: $(TARGETS)
30+
31+
# Files with extension .no-link.cpp are not intended for linking
32+
%.no-link.exe: %.no-link.o
33+
@echo Linking skipped for $@
34+
@echo ================================================================================
35+
@echo Done building $@
36+
@echo ================================================================================
37+
@echo
38+
@echo
39+
40+
# A rule to build .exe file out of a .o file
41+
%.exe: %.o
42+
$(CXX) -o $@ $(LIBFLAGS) $< $(LIBS)
43+
@echo ================================================================================
44+
@echo Done building $@
45+
@echo ================================================================================
46+
@echo
47+
@echo
48+
49+
# A rule to build .o file out of a .cpp file
50+
%.o: %.cpp
51+
$(CXX) $(CXXFLAGS) -o $@ -c $<
52+
53+
# A rule to clean all the intermediates and targets
54+
clean:
55+
rm -rf $(TARGETS) $(OBJECTS) *.out *.stackdump
56+
57+
# A rule to run set of tests
58+
test:
59+
@for file in *.exe; do \
60+
name=`basename $$file .exe` ; \
61+
name=`basename $$name .crash` ; \
62+
if (ls $$name.crash.exe >/dev/null 2>&1) ; then \
63+
continue ; \
64+
fi ; \
65+
echo ======================================== [ $$file ] ; \
66+
if (ls $$name.*in >/dev/null 2>&1) ; then \
67+
for f in $$name.*in; do \
68+
echo ; \
69+
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { "$$f" } ; \
70+
cat "$$f" ; \
71+
echo ; \
72+
echo ---------------------------------------- ; \
73+
./$$file < "$$f" ; \
74+
done ; \
75+
else \
76+
./$$file ; \
77+
fi \
78+
done ; \
79+
echo -n

Chapter02/build.bat

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
@echo off
2+
3+
rem //
4+
rem // This is a MS Visual C++ build script for examples from
5+
rem // "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
6+
rem //
7+
8+
9+
rem Usage:
10+
rem build - Build all examples using the most recent MS VC++ compiler
11+
rem build clean - Clean all examples
12+
rem build test - Test all built examples
13+
rem build [ msvc90 | msvc80 | msvc71 ] - Build with a given version of MS VC++
14+
15+
if "%1" == "clean" del *.obj *.exe build.log *.out && goto END
16+
if "%1" == "test" goto TEST
17+
if "%1" == "msvc90" shift && call :SET_VS_VARS msvc90 && goto PROCEED
18+
if "%1" == "msvc80" shift && call :SET_VS_VARS msvc80 && goto PROCEED
19+
if "%1" == "msvc71" shift && call :SET_VS_VARS msvc71 && goto PROCEED
20+
21+
rem Use the highest version available
22+
if not "%VS90COMNTOOLS%" == "" call :SET_VS_VARS msvc90 && goto PROCEED
23+
if not "%VS80COMNTOOLS%" == "" call :SET_VS_VARS msvc80 && goto PROCEED
24+
if not "%VS71COMNTOOLS%" == "" call :SET_VS_VARS msvc71 && goto PROCEED
25+
26+
echo ERROR: Unable to find installation of MS Visual C++ on this computer
27+
goto END
28+
29+
:SET_VS_VARS
30+
31+
if not "%VSVARSCOMPLETE%"=="" goto END
32+
if "%1" == "msvc90" call "%VS90COMNTOOLS%vsvars32.bat" > build.log && echo Using MS Visual C++ 9.0
33+
if "%1" == "msvc80" call "%VS80COMNTOOLS%vsvars32.bat" > build.log && echo Using MS Visual C++ 8.0
34+
if "%1" == "msvc71" call "%VS71COMNTOOLS%vsvars32.bat" > build.log && echo Using MS Visual C++ 7.1
35+
set VSVARSCOMPLETE=1
36+
goto END
37+
38+
:PROCEED
39+
40+
set CLFLAGS=/W4 /EHsc /O2 /Za
41+
42+
if "%1" == "" goto BUILD_ALL
43+
44+
:BUILD_ARG
45+
46+
rem Iterate through all the arguments that were passed and build them
47+
for %%i in (%1) do call :SUB_BUILD_FILE "%%i"
48+
shift
49+
if "%1" == "" goto END
50+
goto BUILD_ARG
51+
52+
:BUILD_ALL
53+
54+
rem User didn't provide any arguments, assume all .cpp files in the current folder
55+
for %%i in (*.cpp *.cxx *.c) do call :SUB_BUILD_FILE "%%i"
56+
echo Build log has been saved to build.log
57+
goto END
58+
59+
:TEST
60+
61+
for %%i in (*.exe) do call :SUB_TEST_FILE "%%i"
62+
goto END
63+
64+
:SUB_TEST_FILE
65+
66+
set execution=%~n1
67+
set execution=%execution:~-5%
68+
if "%execution%"=="crash" goto END
69+
echo.
70+
echo ======================================== [ %1 ]
71+
if not exist %~n1.*in %1
72+
if exist %~n1.*in for %%i in (%~n1.*in) do echo. && echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { "%%i" } && type "%%i" && echo. && echo ---------------------------------------- && %1 < "%%i"
73+
goto END
74+
75+
:SUB_BUILD_FILE
76+
77+
rem Subroutine that builds a particular file
78+
echo Building %1
79+
echo ======================================== [ %1 ] >> build.log
80+
set requirelink=%~n1
81+
set requirelink=%requirelink:~-7%
82+
if not "%requirelink%"=="no-link" cl.exe %CLFLAGS% %1 /link >> build.log 2>&1 && if ERRORLEVEL 1 echo Error(s): %ERRORLEVEL%
83+
if "%requirelink%"=="no-link" cl.exe /c %CLFLAGS% %1 >> build.log 2>&1 && if ERRORLEVEL 1 echo Error(s): %ERRORLEVEL%
84+
if exist %~n1.obj del %~n1.obj
85+
if exist %~n1.exe.manifest del %~n1.exe.manifest
86+
87+
:END
88+

Chapter02/chapter.2.2-minimal.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
//
3+
// This is example code from Chapter 2.2 "The classic first program" of
4+
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
5+
//
6+
7+
//------------------------------------------------------------------------------
8+
9+
// The minimal C++ program is simply
10+
11+
int main() { }
12+
13+
//------------------------------------------------------------------------------

Chapter02/chapter.2.2.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
//
3+
// This is example code from Chapter 2.2 "The classic first program" of
4+
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
5+
//
6+
7+
// This program outputs the message "Hello, World!" to the monitor
8+
9+
#include "std_lib_facilities.h"
10+
11+
//------------------------------------------------------------------------------
12+
13+
int main() // C++ programs start by executing the function main
14+
{
15+
cout << "Hello, World!\n"; // output "Hello, World!"
16+
return 0;
17+
}
18+
19+
//------------------------------------------------------------------------------

Chapter02/chapter.2.3.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
//
3+
// This is example code from Chapter 2.3 "Compilation" of
4+
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
5+
//
6+
7+
// error: no #include here
8+
// #include "std_facilities.h" // error: unable to locate header file
9+
#include "std_lib_facilities.h"
10+
11+
//------------------------------------------------------------------------------
12+
13+
//integer main() // error: unknown type integer
14+
int main()
15+
{
16+
//cout << "Hello, World!\n; // error: unterminated string constant
17+
//cout < "Hello, World!\n";// error: no operator < defined
18+
//cout << 'Hello, World!\n';// error: invalid delimiter for strings
19+
//cout << "Hello, World!\n" // error: no semicolon
20+
cout << "Hello, World!\n";
21+
return 0;
22+
}
23+
24+
//------------------------------------------------------------------------------

Chapter02/chapter.2.6.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
//
3+
// This is example code from Chapter 2.6 "Drill" of
4+
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
5+
//
6+
7+
#include "std_lib_facilities.h"
8+
9+
//------------------------------------------------------------------------------
10+
11+
int main() // C++ programs start by executing the function main
12+
{
13+
cout << "Hello, World!\n"; // output "Hello, World!"
14+
keep_window_open(); // wait for a character to be entered
15+
return 0;
16+
}
17+
18+
//------------------------------------------------------------------------------

Chapter02/chapter.2.6.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
y

Chapter02/std_lib_facilities.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
//
3+
// This is a standard library support code to the chapters of the book
4+
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
5+
//
6+
7+
#ifndef STD_LIB_FACILITIES_GUARD
8+
#define STD_LIB_FACILITIES_GUARD 1
9+
10+
#include <iostream>
11+
12+
using namespace std;
13+
14+
//------------------------------------------------------------------------------
15+
16+
// The call to keep_window_open() is needed on some Windows machines to prevent
17+
// them from closing the window before you have a chance to read the output.
18+
inline void keep_window_open()
19+
{
20+
cin.get();
21+
}
22+
23+
//------------------------------------------------------------------------------
24+
25+
#endif // STD_LIB_FACILITIES_GUARD

Chapter03/Makefile

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#
2+
# This is a common Makefile for code examples from the book
3+
# "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
4+
#
5+
6+
#
7+
# Usage:
8+
# make - Build all examples
9+
# make clean - Clean all examples
10+
# make test - Run the test suite
11+
#
12+
13+
INCLUDES =
14+
LIBS = -lstdc++
15+
CXXFLAGS = $(INCLUDES) -Wall -time -O3 -DNDEBUG
16+
LIBFLAGS =
17+
AR = ar
18+
19+
.SUFFIXES: .cpp .o
20+
21+
# Create a list of source files.
22+
SOURCES = $(shell ls *.cpp)
23+
# Create a list of object files from the source file lists.
24+
OBJECTS = ${SOURCES:.cpp=.o}
25+
# Create a list of targets.
26+
TARGETS = ${SOURCES:.cpp=.exe}
27+
28+
# Build all targets by default
29+
all: $(TARGETS)
30+
31+
# Files with extension .no-link.cpp are not intended for linking
32+
%.no-link.exe: %.no-link.o
33+
@echo Linking skipped for $@
34+
@echo ================================================================================
35+
@echo Done building $@
36+
@echo ================================================================================
37+
@echo
38+
@echo
39+
40+
# A rule to build .exe file out of a .o file
41+
%.exe: %.o
42+
$(CXX) -o $@ $(LIBFLAGS) $< $(LIBS)
43+
@echo ================================================================================
44+
@echo Done building $@
45+
@echo ================================================================================
46+
@echo
47+
@echo
48+
49+
# A rule to build .o file out of a .cpp file
50+
%.o: %.cpp
51+
$(CXX) $(CXXFLAGS) -o $@ -c $<
52+
53+
# A rule to clean all the intermediates and targets
54+
clean:
55+
rm -rf $(TARGETS) $(OBJECTS) *.out *.stackdump
56+
57+
# A rule to run set of tests
58+
test:
59+
@for file in *.exe; do \
60+
name=`basename $$file .exe` ; \
61+
name=`basename $$name .crash` ; \
62+
if (ls $$name.crash.exe >/dev/null 2>&1) ; then \
63+
continue ; \
64+
fi ; \
65+
echo ======================================== [ $$file ] ; \
66+
if (ls $$name.*in >/dev/null 2>&1) ; then \
67+
for f in $$name.*in; do \
68+
echo ; \
69+
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { "$$f" } ; \
70+
cat "$$f" ; \
71+
echo ; \
72+
echo ---------------------------------------- ; \
73+
./$$file < "$$f" ; \
74+
done ; \
75+
else \
76+
./$$file ; \
77+
fi \
78+
done ; \
79+
echo -n

0 commit comments

Comments
 (0)