Skip to content

Commit

Permalink
fix: layout and pages
Browse files Browse the repository at this point in the history
  • Loading branch information
osmancoskun committed May 20, 2024
1 parent 56dc2ab commit ae555a4
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 37 deletions.
5 changes: 5 additions & 0 deletions src/routes/wiki/development/c/_module.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<svelte:head>
<title>C Programming</title>
<meta name="description" content="C Programming in Linux" />
</svelte:head>
<slot />
88 changes: 88 additions & 0 deletions src/routes/wiki/development/c/c-00-101.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#### 2024.05.20 - [Aliriza Keskin](https://github.com/sulincix)

# C gtk tutorial

C is one of the most fundamental programming languages.
Being a compiled language, it requires a compiler such as gcc or clang.

## Installing compiler

You can use `apt install gcc` command to install gcc.

```shell
$ apt install gcc
```

Or you can prefer clang:
You can use `apt install clang` command to install clang.

```shell
$ apt install clang
```

## Standard C Library (libc)

Every GNU/Linux distribution comes with a libc.
Libc is the most basic library on the system, and all programs, regardless of what they are written in, eventually call libc functions somewhere.
Writing programs without using libc functions is very difficult.

Pardus GNU/Linux prefer glibc as libc library.

You must install **libc6-dev** package for libc development files.

```shell
$ apt install libc6-dev
```

## Write Simple C application

Lets write simple hello world program:

```c
#include <stdio.h>

int main(int argc, char** argv){
printf("Hello World\n");
return 0;
}
```
### Explaining hello world
```c
#include <stdio.h>
```

- `#include <stdio.h>` This line is a preprocessor directive that tells the compiler to include the contents of the stdio.h header file.
This header file contains declarations for standard input/output functions like printf and scanf, which are used in the program.

```c
int main(int argc, char** argv) {
```
- `int main(int argc, char** argv) {` This line defines the main function of the program.
In C, every program must have a main function, which serves as the entry point of the program. It takes two arguments: argc, an integer representing the number of command-line arguments passed to the program, and argv, an array of strings containing the actual command-line arguments.
```c
printf("Hello World\n");
```

- `printf("Hello World\n");` This line uses the printf function to print the string "Hello World" to the standard output (usually the console).
The \n represents a newline character, which moves the cursor to the next line after printing "Hello World".

```c
}
```

- This closing curly brace marks the end of the main function block.
All the code within the main function is enclosed between `{` and `}`.

### Compile code

Compile code like this and run:

```shell
$ gcc main.c -o main
$ ./main
>>> Hello World
```
193 changes: 193 additions & 0 deletions src/routes/wiki/development/c/c-01-syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#### 2024.05.20 - [Aliriza Keskin](https://github.com/sulincix)

# C Syntax

C is a compiled programming language.
This means that the code needs to be translated into a form understandable by the computer it will run on.
We can compile using gcc or clang.

```shell
# Generate .o file from code
$ gcc -c main.c
# Generate executable file from .o file
$ gcc -o main main.o
# Run the code
$ ./main
-> Hello World
```

In the example above, we first generate a .o object file.
This file represents the compiled but not yet executable version of the code.
Therefore, we need to pass the .o files through the linking process to get the final executable.

Note: Our compiler can also directly compile without generating .o.

```shell
$ gcc -o main main.c
```

## Commenting

There are three ways to comment in C code:

for single-line comments:

```c
// This is a comment line.
```

for multi-line comments:

```c
/* This
is
a
comment */
```

`#if 0` for conditional comments:

```c
#if 0
This is a
comment
#endif
```

## Indentation

Blocks in C programming are denoted by `{}`.
Indentation is not necessary but improves readability.
You can use either 4 spaces or 1 tab for indentation.

A block has the following structure:

```c
aaaa (bbbb) {
cccc;
ddd;
}
```
Note: Each line must end with a semicolon (;).
## First Program
When C programs are executed, the main function is called.
Below is an example main function:
```c
int main(int argc, char** argv) {
return 0;
}
```

In int main, int is the return type, main is the function name.
argc specifies the number of arguments.
argv specifies the argument list.
return 0 statement exits with a status of 0.

In C, the main function can also be defined as void.
If not using arguments, they don't need to be defined:

```c
void main(){}
```

## Printing to Screen

First, we need to include stdio.h library.
Then, we can use the printf function to print to the screen.

The first parameter of printf is the format string, and the others specify the data to be printed.

```c
#include <stdio.h>

int main(int argc, char** argv) {
printf("%s\n", "Hello World!");
return 0;
}
```
In the include directive, the specified files are found in /usr/include directory.
In printf function, %s is for strings, %c is for characters, %d is for integers.
## Variables
Variables in C are declared as follows:
```c
...
int number = 12;
char* text = "test";
char character = 'c';
float number2 = 12.42;
...
```

Additionally, using #define, you can replace occurrences of specified values in the code before compilation.
These values are not treated as variables because they are replaced before compilation.

```c
#define number 12
...
printf("%d\n",number);
...
```
## Arrays
Arrays can be declared in two ways:
Using pointers, which allows dynamic sizing.
The length doesn't need to be specified at the beginning.
```c
int *array = {12, 22, 31};
```

Or, declaring with a specified length:

```c
int array[3] = {12, 22, 31};
```
C doesn't have a string data type.
Instead, character arrays are used.
```c
char *txt = "deneme123";
```

To access an element in an array:

```c
int *array = {12, 22, 31};
int c = array[1]; // the second element of the array
```
Note: Array indices start from 0.
To find the length of an array, you divide the total size of the array by the size of each element.
You can use the sizeof function for this.
```c
int *array = {11, 22, 31};
int l = sizeof(array) / sizeof(int);
```

## Input from Keyboard

To receive input from the keyboard, scanf function is used.
The first parameter is the format, and the rest specify the memory addresses of the variables.

```c
int number;
scanf("%d\n", &number);
```
Note: Using this method, invalid input can be entered.
If this happens, the variable will be assigned NULL, meaning it has no value.
This can cause issues in code execution.
Therefore, always check for NULL before using the variable.
3 changes: 3 additions & 0 deletions src/routes/wiki/development/c/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# C documentations

### This section provide C related documentations.
27 changes: 2 additions & 25 deletions src/routes/wiki/development/index.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
# Introduction to GTK Development with Python
# Development Area

GTK (GIMP Toolkit) is a popular toolkit for creating graphical user interfaces (GUIs) for desktop applications. It provides a set of libraries and tools to build interactive and visually appealing applications. In this introduction, we will focus on using GTK with Python, which provides a simple and elegant way to develop cross-platform GUI applications.

## Learning Resources

Below are some useful resources for learning GTK development with Python:

1. [GTK4 Official Documentation](https://docs.gtk.org/gtk4/)
> For the most comprehensive and up-to-date information, the official GTK4 documentation is the go-to resource. It covers all aspects of GTK4 development in detail, including widgets, layout management, event handling, and more.
2. [GTK4 Python (lazka) Documentation](https://lazka.github.io/pgi-docs/)
> This resource provides comprehensive documentation for the PyGObject library, which is the Python binding for GTK4. It includes detailed information on classes, methods, and properties available in GTK4, making it an essential reference for GTK development in Python.
3. [GTK4 Python (amoleenar) Documentation](https://amolenaar.pages.gitlab.gnome.org/pygobject-docs/)
> This documentation complements the official documentation by offering more insights into GTK4 development with Python. It can be particularly helpful in understanding specific examples and use cases.
4. [GTK3 Python (readthedocs) Tutorial](https://python-gtk-3-tutorial.readthedocs.io/en/latest/)
> Although this tutorial focuses on GTK3, it can still be valuable for beginners to understand the basic concepts of GTK development with Python. Many of the fundamental principles and functionalities remain consistent between GTK3 and GTK4, making this a good starting point for learning the basics.
5. [Style Classes (libadwaita)](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/style-classes.html)
> While developing GTK applications, understanding style classes and their usage is crucial for creating consistent and visually appealing UIs. This resource provides insight into libadwaita's style classes, a set of CSS-like style rules that can be applied to GTK widgets.
## Note: Updating Resources

We are committed to keeping this guide up-to-date with the latest resources. As new documentation or tutorials for GTK development with Python become available, we will review and add them to the list above. Be sure to check back regularly for new and improved learning materials!
### You can find various development documentation here.
6 changes: 6 additions & 0 deletions src/routes/wiki/development/python/_module.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<svelte:head>
<title>Python Programming</title>
<meta name="description" content="Python Programming in Linux" />
</svelte:head>

<slot />
26 changes: 26 additions & 0 deletions src/routes/wiki/development/python/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Introduction to GTK Development with Python

GTK (GIMP Toolkit) is a popular toolkit for creating graphical user interfaces (GUIs) for desktop applications. It provides a set of libraries and tools to build interactive and visually appealing applications. In this introduction, we will focus on using GTK with Python, which provides a simple and elegant way to develop cross-platform GUI applications.

## Learning Resources

Below are some useful resources for learning GTK development with Python:

1. [GTK4 Official Documentation](https://docs.gtk.org/gtk4/)
> For the most comprehensive and up-to-date information, the official GTK4 documentation is the go-to resource. It covers all aspects of GTK4 development in detail, including widgets, layout management, event handling, and more.
2. [GTK4 Python (lazka) Documentation](https://lazka.github.io/pgi-docs/)
> This resource provides comprehensive documentation for the PyGObject library, which is the Python binding for GTK4. It includes detailed information on classes, methods, and properties available in GTK4, making it an essential reference for GTK development in Python.
3. [GTK4 Python (amoleenar) Documentation](https://amolenaar.pages.gitlab.gnome.org/pygobject-docs/)
> This documentation complements the official documentation by offering more insights into GTK4 development with Python. It can be particularly helpful in understanding specific examples and use cases.
4. [GTK3 Python (readthedocs) Tutorial](https://python-gtk-3-tutorial.readthedocs.io/en/latest/)
> Although this tutorial focuses on GTK3, it can still be valuable for beginners to understand the basic concepts of GTK development with Python. Many of the fundamental principles and functionalities remain consistent between GTK3 and GTK4, making this a good starting point for learning the basics.
5. [Style Classes (libadwaita)](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/style-classes.html)
> While developing GTK applications, understanding style classes and their usage is crucial for creating consistent and visually appealing UIs. This resource provides insight into libadwaita's style classes, a set of CSS-like style rules that can be applied to GTK widgets.
## Note: Updating Resources

We are committed to keeping this guide up-to-date with the latest resources. As new documentation or tutorials for GTK development with Python become available, we will review and add them to the list above. Be sure to check back regularly for new and improved learning materials!
Loading

0 comments on commit ae555a4

Please sign in to comment.