Permalink
Browse files

glib: work on layout for chapter on GLib.

  • Loading branch information...
chergert committed Nov 12, 2012
1 parent 683225a commit 125db5aaad99bded5bb4aa8f9198ba09dd8a6135
Showing with 76 additions and 350 deletions.
  1. +5 −1 Makefile.am
  2. +0 −349 tex/chapter1.tex
  3. +7 −0 tex/glib_ch1.tex
  4. +32 −0 tex/glib_ch2.tex
  5. +15 −0 tex/glib_ch3.tex
  6. +8 −0 tex/glib_ch4.tex
  7. +4 −0 tex/glib_ch5.tex
  8. +5 −0 tex/gnome-desktop-programming.tex
View
@@ -7,7 +7,11 @@ pdfdata_DATA += gnome-desktop-programming.pdf
# TEX input files
############################################################################
TEX_FILES =
-TEX_FILES += tex/chapter1.tex
+TEX_FILES += tex/glib_ch1.tex
+TEX_FILES += tex/glib_ch2.tex
+TEX_FILES += tex/glib_ch3.tex
+TEX_FILES += tex/glib_ch4.tex
+TEX_FILES += tex/glib_ch5.tex
TEX_FILES += tex/commands.tex
TEX_FILES += tex/gnome-desktop-programming.tex
TEX_FILES += tex/introduction.tex
View
@@ -1,349 +0,0 @@
-\chapter{The Basics}
-
-The C programming language may seem complex or mysterious. Many have heard
-horror stories about how difficult pointers can be. While it is indeed a
-difficult subject, it is perfectly within your reach. This chapter will
-familiarize you with the basics of C. You will write your first C program and
-learn to express yourself in this unfamiliar language.
-
-Occasionally, we will gloss over some details to focus the area of learning.
-Future chapters may feel repetitious as we reinforce previous teachings in the
-light of new understanding.
-
-\section{Hello, World!}
-
-In the example below you will see the first program that everyone writes in C.
-If you've learned another programming language then you've probably written
-something similar.
-
-Create a new text file containing the following C code and save it as
-\file{hello.c}. The line numbers to the left of the margin are for readability
-within this book and are not to be copied.
-
-\begin{code}{hello.c}
-#include <stdio.h>
-
-int
-main (void)
-{
- printf ("Hello, World!\n");
- return 0;
-}
-\end{code}
-
-Navigate with your terminal to the directory containing \file{hello.c}. Type in
-the following command. It will instruct the program called \file{cc} (the C
-Compiler) to translate your source code into machine code. The resulting
-machine code is what can be executed by your computer.
-
-\begin{Terminal}
-cc hello.c -Wall
-\end{Terminal}
-
-If everything worked, the \file{cc} command will exit silently and a new
-executable file named \file{a.out} will have been placed in your current
-directory. If instead there was an error, carefully check that each character in
-\file{hello.c} matches the C code above and try again.
-
-Once you have successfully compiled \file{hello.c}, we can execute the program
-from the terminal by prefixing \verb|./| to the filename to tell the terminal
-to execute a file within the current directory.
-
-\begin{Terminal}
-./a.out
-Hello, World!
-\end{Terminal}
-
-There you have it, your very first C program!
-
-Lets now analyze the anatomy of this simple C program. The very first line,
-\verb|#include <stdio.h>| tells the compiler that we would like to use the
-\ident{stdio} library. A \textbf{library} is a set of useful, reusable
-routines. In this case, the \ident{stdio} library contains routines to
-interface with the standard input and output of your terminal\footnote{Run
-\ttfamily{man stdio} \rmfamily in your terminal for more information on the
-stdio library.}. This allows your program to output text to the terminal and
-input text from it.
-
-The line following \verb|#include| is simply an empty line. Empty lines do
-not affect the program. In some languages, this does matter. However, C is not
-one of those languages. You may use empty lines liberally to make your code
-more readable.
-
-Next, we have \verb|main ()|. This tells the compiler that we have a function
-named \verb|main|. The \verb|main| function is the beginning of the program.
-Every program has one. Lastly, \verb|()| denotes the argument list for the
-function. Our \verb|main| function takes no arguments and so it has none
-specified\footnote{This isn't technically true, but that will be covered in a
-later chapter.}. Do not worry if this seems mysterious, we will cover it
-in detail in a later chapter.
-
-After the line defining our function \ident{main}, we have a \verb|{|. This
-denotes the beginning of the body of the function. There is a corresponding
-\verb|}| at the end of the function. Inside of these curly braces is the crux
-of our program.
-
-\verb|printf ("Hello, World!\n");| is a function call to the \ident{printf}
-function (part of the \ident{stdio} library). You can tell it is a function
-call because the function name is followed by a parenthesized argument list.
-In this case, our function call has a single argument,
-\verb|"Hello, World!\n"|. Information can be shared between functions in
-a couple different ways. This way, through the argument list, is the most
-common.
-
-Our \verb|"Hello, World!\n"| argument is what we call a "string". A string
-is a sequence of characters. At the end of this string you will see \verb|\n|.
-This means that the string should contain a line break at the end of it.
-
-We denote the end of a \ident{statement} in C with a semicolon \ident{;}. What
-exactly a \ident{statement} is will be vague for now, but it will become
-clear as we continue.
-
-\section{Integers}
-
-Writing a Hello World program is always fun in a new language, but it wont
-exactly win us any awards. Lets try to print out some interesting numbers
-using our program as a base.
-
-Lets create a new text file with the following and save it as \file{answer.c}.
-
-\begin{code}{answer.c}
-#include <stdio.h>
-
-int
-main (void)
-{
- int answer = 42;
-
- printf ("The answer is %d, but what is the question?\n", answer);
-
- return 0;
-}
-\end{code}
-
-Once again, lets use \ident{cc} to compile the program. You will get very
-used to this in no time!
-
-\begin{Terminal}
-cc answer.c
-\end{Terminal}
-
-And again, lets run it.
-
-\begin{Terminal}
-./a.out
-The answer is 42, but what is the question?
-\end{Terminal}
-
-Since we have covered the anatomy of the \ident{main} function earlier in this
-chapter, lets skip to the two lines inside the body of the function.
-
-Lets look at the first line, \verb|int answer = 42;|. This line declares a new
-variable named \verb|again| of the type \verb|int|. Variables are always
-defined in the format \verb|type| followed by \verb|name|. \verb|int| is short
-for \verb|integer|. You might remember that an integer is an "whole" number,
-such as 1, 2, or -20. There are no decimal points in an integer. So if you
-tried to store the number \verb|12.5| in an integer, it would simply be 12. The
-second half of this statement, \verb|= 42| initialized the variable
-\verb|again| to the value \verb|42|.
-
-The second line should look familiar. It again is calling the \verb|printf|
-function. However, this time there are two arguments. We will cover this in
-more detail in a later chapter, but there are a few important things to take
-from this example. First, notice the comma \verb|,| used to separate the
-two arguments provided to \verb|printf|. In C, arguments are separated by
-commas. Also, note the \verb|%d| inside of the first parameter. This is a
-magic value that \verb|printf| will replace with the value of the second
-parameter.
-
-\section{Multiplication}
-
-Integers don't seem to be all that useful when used by themselves like this.
-Lets take a look how multiplication of integers works with an example. Type
-the following code into a new text file named \file{multiply.c}.
-
-\begin{code}{multiply.c}
-#include <stdio.h>
-
-int
-main (void)
-{
- int a = 42;
- int b = 32;
-
- printf ("%d * %d = %d\n", a, b, a * b);
-
- return 0;
-}
-\end{code}
-
-And, again, we compile and run it.
-
-\begin{Terminal}
-cc multiply.c
-./a.out
-42 * 32 = 1344
-\end{Terminal}
-
-In this example, we have two variables defined, \verb|a| and \verb|b|
-initialized with the values 42 and 32 respectively. Following that, like before
-we call the function \verb|printf|. This time, there are four arguments. You can
-see that there are three \verb|%d|s used in the first argument to \verb|printf|.
-One for each of the arguments following it. The following two arguments,
-unsurprisingly, cause the values 42 and 32 to be placed into the printed line.
-However, the last argument, \verb|a * b| performs the multiplication of the
-variables \verb|a| and \verb|b| as denoted by the multiplication operator
-\verb|*|. The result of this multiplication is placed in the location of the
-last \verb|%d| when printing to the screen.
-
-\section{Addition, Subtraction, Division and Modulus}
-
-Multiplication might have been obvious. How about we take a look at a few other
-arithmetic operators. See table 1.1 for the list of arithmetic operators.
-Operators always follow the \verb|left operator right| pattern. The operator
-operates on a value to the left and a value to the right.
-
-So for the multiplication example above, that would be:
-
-\begin{center}
-\begin{tabular}{r c l}
-left & operator & right \\
-\verb|a| & \verb|*| & \verb|b| \\
-\end{tabular}
-\end{center}
-
-As you can imagine, we can simply substitute the multiplication \verb|*|
-operator out for one of the others. The table below gives you our available
-arithmetic operators.
-
-\begin{center}
-\begin{tabular}{r l}
-\hline
-\verb|+| & Addition of two numbers \verb|(a + b)| \\
-\verb|-| & Subtraction of two numbers \verb|(a - b)| \\
-\verb|*| & Multiplication of two numbers \verb|(a * b)| \\
-\verb|/| & Division of two numbers \verb|(a / b)| \\
-\verb|%| & Modulus (remainder) of integer division \verb|(a % b)| \\
-\hline
-\end{tabular}
-\end{center}
-
-Lets modify the code above to perform division and save it into a new file
-called \file{divide.c}.
-
-\begin{code}{divide.c}
-#include <stdio.h>
-
-int
-main ()
-{
- int a = 221;
- int b = 13;
-
- printf ("%d / %d = %d\n", a, b, a / b);
-
- return 0;
-}
-\end{code}
-
-Now we compile \file{divide.c} and run it (you'll see a pattern here).
-
-\begin{Terminal}
-cc divide.c
-./a.out
-221 / 13 = 17
-\end{Terminal}
-
-Simple, right?
-
-Now I don't think we need to do this for addition and subtraction, but how about
-modulus? The modulus \verb|%| operator divides the \verb|left| by the
-\verb|right| and returns the remainder. So if we performed the following
-division using normal algebra, we would get a fractional result.
-
-\begin{center}
-\begin{math}
-10 / 3 = 3.3333...
-\end{math}
-\end{center}
-
-However, what modulus does is try to divide the number as many times as it can
-and then return the remainder. Those that have performed division the "long way"
-will understand this as the same remainder. So if we were to perform the
-modulus, we would get the following.
-
-\begin{center}
-\verb|10 % 3 = 10 - 3 - 3 - 3 = 1|
-\end{center}
-
-Just to verify our logic, lets modify the previous example in a new file
-called \file{modulus.c}.
-
-\begin{code}{modulus.c}
-#include <stdio.h>
-
-int
-main (void)
-{
- int a = 42;
- int b = 32;
-
- printf ("%d %% %d = %d\n", a, b, a % b);
-
- return 0;
-}
-\end{code}
-
-Now we compile \file{modulus.c} and run it.
-
-\begin{Terminal}
-cc modulus.c
-./a.out
-42 % 32 = 10
-\end{Terminal}
-
-\section{Student Exercise}
-
-Use what you have learned in this chapter to print the multiplication of
-the numbers provided by the user. The \verb|scanf()| function is provided for
-you to receive input from the terminal. It will be covered in a later chapter.
-
-\begin{code}{student1.c}
-#include <stdio.h>
-
-int
-main (void)
-{
- int a;
- int b;
-
- printf ("Enter two numbers to multiply: ");
- scanf ("%d %d", &a, &b);
-
- /* TODO: Print the multiplication of a and b. */
-}
-\end{code}
-
-When complete, the output should look like the following.
-
-\begin{Terminal}
-cc student1.c
-./a.out
-Enter two numbers to multiply: 10 20
-10 * 20 = 200
-./a.out
-Enter two numbers to multiply: 73 81
-73 * 81 = 5913
-./a.out
-Enter two numbers to multiply: 100 0
-100 * 0 = 0
-\end{Terminal}
-
-
-\subsection{Extra Credit}
-
-\begin{enumerate}
-\item The type \verb|int| cannot hold every number known. Research the minumum
-and maximum values that can be stored in an \verb|int|.
-\item Research to discover how many bytes are used in an \verb|int|.
-\end{enumerate}
View
@@ -0,0 +1,7 @@
+\chapter{What is GLib?}
+
+\begin{itemize}
+\item What is GLib.
+\item Where did GLib come from.
+\item How to compile and link against GLib.
+\end{itemize}
Oops, something went wrong.

0 comments on commit 125db5a

Please sign in to comment.