From 85ba03dd696d12477259e29a0b25e85a68108ca0 Mon Sep 17 00:00:00 2001
From: Silvino Silva Create patch files to target branch/tag/ref; Last commit that affected current path Same using diff tool; Query last commit that affected current file path Variable names, functions, data types and preprocessor macros.
+ Are allowed letters, decimal digits and underscore. Reserved identifiers part of C language.; auto break case char const continue default do double else enum
+ extern float for goto if int long register return short signed
+ sizeof static struct switch typedef union unsigned void volatile
+ while restrict inline _Bool _Complex _Imaginary __FUNCTION__ __PRETTY_FUNCTION__ __alignof __alignof__ __asm
+ __asm__ __attribute __attribute__ __builtin_offsetof __builtin_va_arg
+ __complex __complex__ __const __extension__ __func__ __imag __imag__
+ __inline __inline__ __label__ __null __real __real__
+ __restrict __restrict__ __signed __signed__ __thread __typeof
+ __volatile __volatile__ Constants are identifiers with fixed values that can't change
+ during execution. Data types of constants; integer, character,
+ double, strings. Operators do operations such as; addition or subtraction. Language elements separators;
+ {} [] () ; , . : White space is ignored except when separating elements.
+ This is part of the c9-doc Manual.
+ Copyright (C) 2018
+ c9 team.
+ See the file Gnu Free Documentation License
+ for copying conditions. Create file hello.c with;
- GDB Quick Start,
- Learning C with GDB
- and Memory Layout and the Stack
- are great sources of introductory information.
- To use gdb you need to compile program with -g flag. To
- debug a program; Compile; If the program needs arguments you can set it; Run; To start the program you can type run, this way gdb
- will try to run the program until the end. If program
- crash, gdb will stop it for debuging. To organize code in multiple files split above
+ example in main.c, hello.c and hello.h. Content of
+ main.c;
- Header file contains declaration of the function hello,
+ content of hello.h; When new thread is created you receive
- a notification. To get information about
- threads; Implementation of hello function in hello.c; To select thread; Compile; Make reads a Makefile by default on current directory,
+ Makefile defines targets, for example executables and their
+ dependencies, for example object files and source files.
+
+ Create Makefile; Stopping and Starting
- multi-thread programs To use gdb you need to compile program with -g flag. Change
+ Makefile Set break point; To start the program you can type run, this way gdb
+ will try to run the program until the end. If program
+ crash, gdb will stop it for debuging. Start program; Step in next line; Execute next line; To start gdb in TUI mode press; Run again and step in hello function, to print
+ variable "name" value and type; Print variable name type;
- This is part of the c9-doc Manual.
- Copyright (C) 2016
- c9 team.
- See the file Gnu Free Documentation License
- for copying conditions. Variable is a string constant,
+ continue reading Elements.
+ This is part of the c9-doc Manual.
+ Copyright (C) 2016
+ c9 team.
+ See the file Gnu Free Documentation License
+ for copying conditions.2.2. Logs and commits
+ 2.2. Logs, diff commits
+ $ diff orig file > file.patch
+
+
+
$ git rev-list -n 1 HEAD -- .
--
cgit
From 5d7a23e5d38048d72243a18b60b6f5f7f3d805d2 Mon Sep 17 00:00:00 2001
From: Silvino Silva Types & Elements
+
+ Types
+
+
+
+
+ Identifiers
+
+ Keywords
+
+ Constants
+
+ Operators
+
+ Separators
+
+ White Space
+
+ C & GDB
+ C & GDB
-
+ Hello World
-
- $ touch NEWS README AUTHORS ChangeLog
- $ mkdir -p src/bin src/lib
-
+
+ #include <stdio.h>
-
-
- gdb program
-
+
+ $ gcc -Wall hello.c -o hello
+
-
- (gdb)set args -parameter1 -parameter2
-
+
+ $./hello
+ Hello World!
+
-
- (gdb) run
-
+ Multiple Sources
-
- n - execute next line
- s - step in next line
- b - backtrace
- info locals
- print
- x
-
+ SysCalls
+
+ #include "hello.h"
-
- catch syscall open
+ int main() {
+ hello("world");
+ return 0;
+ }
+ Threads
+
+ void hello(const char* name);
+
-
- info threads
-
+
+ #include <stdio.h>
+ #include "hello.h"
-
+
+
- thread 1
-
+ void hello(const char* name) {
+ printf("Hello, %s!\n", name);
+ }
+
+ $ gcc -Wall main.c hello.c -o hello
+
+
+ Makefile
+
+
+ CC=gcc
+ CFLAGS=-Wall
+
+ hello: main.o hello.o
-
+
+
+ $ touch NEWS README AUTHORS ChangeLog
+
+
+ Debug
+
+
+ CC=gcc
+ CFLAGS=-Wall -g
+
+ hello: main.o hello.o
+
+ clean:
+ rm -f hello main.o hello.o
+
+
+
+ $ gdb hello
+
+
+
+ (gdb) break main
+
+
+
+ (gdb) run
+
+
+
+ (gdb) s
+
+
+
+ (gdb) n
+
+
+
+
+
+
- break linespec thread threadno
+ (gdb) print name
+ $1 = 0x4005b0 "world"
+ (gdb)
- Strace
+
- strace -c ./program
+ (gdb) ptype name
+ type = const char *
+ (gdb)
- Development Index
-
+ This is part of the c9-doc Manual. + Copyright (C) 2018 + c9 team. + See the file Gnu Free Documentation License + for copying conditions.
+ + diff --git a/dev/c/debugging.html b/dev/c/debugging.html new file mode 100644 index 0000000..d1f425b --- /dev/null +++ b/dev/c/debugging.html @@ -0,0 +1,67 @@ + + + + +If the program needs arguments you can set it;
+ ++ (gdb)set args -parameter1 -parameter2 ++ + +
+ b - backtrace + info locals + print + x + catch syscall open ++ +
When new thread is created you receive + a notification. To get information about + threads;
+ ++ info threads ++ +
To select thread;
+ ++ thread 1 ++ +
+ break linespec thread threadno ++ +
+ strace -c ./program ++ + +
C program with autotools + GDB Quick Start, + Learning C with GDB + and Memory Layout and the Stack + are great sources of introductory information. + Stopping and Starting + multi-thread programs
+ + Development Index + ++ This is part of the c9-doc Manual. + Copyright (C) 2018 + c9 team. + See the file Gnu Free Documentation License + for copying conditions.
+ + diff --git a/dev/index.html b/dev/index.html index 2dcc209..d84fa36 100644 --- a/dev/index.html +++ b/dev/index.html @@ -77,6 +77,7 @@Allowed types are char and int;
+Real numbers are fractional numbers, all floating points + are signed. Check float.h.
+ +
+ enum colors {black, orange, blue} color;
+ enum colors color;
+
+
+ union accounts {
+ int id;
+ float value;
+ } first_account, second_account;
+
+
+ struct point {
+ int x, y;
+ } first_point;
+ struct point second_point;
+
+
+ int account_array[9];
+ int account_array[] = {0, 1, 2, 3};
+ int account_array[] = {0, 1, 2, [9] = 9};
+
+
+
+ int account_array[2][9] { {1,2,3},{9,8,7} }
+
+
+ Initializing string with individual characters the + null character must be defined;
+ +
+ char black[] = {'b', 'l', 'a', 'c', 'k', '\0'}
+
+
+ + char black[] = "black"; ++ +
+ union accounts {
+ int id;
+ float value;
+ };
+ union accounts accounts_array[9];
+ accounts_array[0].id = 8;
+
+
+
+ struct point {
+ int x, y;
+ };
+ struct point point_array[9];
+ point_array[0].x=2;
+ point_array[0].y=3;
+
+
- This is part of the c9-doc Manual. +
This is part of the c9 Manual. Copyright (C) 2018 c9 team. See the file Gnu Free Documentation License for copying conditions.
+ diff --git a/dev/c/debugging.html b/dev/c/debugging.html index d1f425b..4e5931f 100644 --- a/dev/c/debugging.html +++ b/dev/c/debugging.html @@ -15,10 +15,42 @@ (gdb)set args -parameter1 -parameter2 +To start gdb in TUI mode press;
+ ++ (gdb) info win + (gdb) fs next + (gdb) fs SRC ++
b - backtrace
info locals
+ display
print
x
catch syscall open
diff --git a/dev/c/elements.html b/dev/c/elements.html
index d6950d2..c5eb87e 100644
--- a/dev/c/elements.html
+++ b/dev/c/elements.html
@@ -2,27 +2,12 @@
- Types & Elements
+ Elements
Development Index
- Types & Elements
-
- Types
-
- Execute next line;
- -- (gdb) n -- -
To start gdb in TUI mode press;
- -Run again and step in hello function, to print - variable "name" value and type;
+Print variable "name" value;
(gdb) print name
@@ -175,7 +143,7 @@
(gdb)
- Print variable name type;
+Print variable "name" type;
(gdb) ptype name
@@ -183,8 +151,12 @@
(gdb)
- Variable is a string constant, - continue reading Elements.
+Variable is a string constant. + Execute next line to end;
+ ++ (gdb) n +Development Index
diff --git a/dev/c/lib.html b/dev/c/lib.html new file mode 100644 index 0000000..d1c9c28 --- /dev/null +++ b/dev/c/lib.html @@ -0,0 +1,167 @@ + + +
+ ++ mode Description + "r" Opens a file for reading. The file must exist. + "w" Creates an empty file for writing. If a file with the same name already exists, its content is erased and the file is considered as a new empty file. + "a" Appends to a file. Writing operations, append data at the end of the file. The file is created if it does not exist. + "r" Opens a file to update both reading and writing. The file must exist. + "w" Creates an empty file for both reading and writing. + "a" Opens a file for reading and appending. ++ +
+ // ERROR: result == NULL (also when EOF is reached) + char *fgets(char *str, int strlen, FILE *stream); + + // ERROR: result == NULL + FILE *fopen(const char *filename, const char *mode); + + // result == EOF when finished reading the stream + // SUCCESS: number of matched items on success + int fscanf(FILE *stream, const char *format, ...); + + // ERROR: result == EOF + // SUCCESS: result == 0 + int fclose(FILE *stream); + + // ERROR: result == -1 + // SUCCESS: number of bytes written + ssize_t write(int fildes, const void *buf, size_t nbyte); + + // ERROR: result == -1 + // EOF when finished reading + // SUCCESS: number of bytes read + ssize_t read(int fildes, void *buf, size_t nbyte); + + // SUCCESS: result > 0 + // ERROR: result == EOF + int fputs(const char *restrict s, FILE *restrict stream); ++ +
+ // SUCCESS: pointer to destination string + char *strcpy(char *dest, const char *src); + + // result == 0 -> strings are equal + // result < 0 -> str1 less than str2 + // result > 0 -> str2 less than str1 + int strcmp(const char *str1, const char *str2);; + + + // result == NULL -> no tokens left to retrieve + // else: pointer to last token found + char *strtok(char *str, const char *delim); + + // NULL if no match + // else: pointer to first occurence in string + char *strstr(const char *string, const char *substring); + + // ERROR: result == 0 + int atoi(const char *str); ++ +
+ // ERROR: result == -1 + // example: sock = socket(AF_INET, SOCK_STREAM, 0); + int socket(int domain, int type, int protocol); + + // sockaddr_in struct (man ip 4) + struct sockaddr_in server; + server.sin_family = PF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(8080); + + // ERROR: result < 0 + // SUCCESS: result == 0 + // example: bind(sock, (struct sockaddr *) &server, sizeof(server)) + int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen); + + // ERROR: result < 0 + // SUCCESS: filedeskriptor for accepted socket + // example: fd = accept(sock, (struct sockaddr *) &client, &client_len); + int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); + + // SUCCESS: result == 0 + // ERROR: result == -1 + int listen(int socket, int backlog); ++ + Development Index + +
+ This is part of the c9-doc Manual. + Copyright (C) 2018 + c9 team. + See the file Gnu Free Documentation License + for copying conditions.
+ + diff --git a/dev/index.html b/dev/index.html index afd147e..ab00a3e 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,164 +1,178 @@ - -Tools for development and debugging
- -Git is a distributed version control system, this document is meant to be distributed using git.
- -C is functional compiled language created by Dennis Ritchie. BSD, Linux and Minix kernels use this language - as primary language.
- -Script files that start with "#!/bin/sh" use dash (in crux), - /bin/sh is a link to dash, while files that start with "#!/bin/bash" - use bash;
- -- This is part of the c9-doc Manual. - Copyright (C) 2017 - c9 team. - See the file Gnu Free Documentation License - for copying conditions.
- - + Documentation Index +Tools for development and debugging
+ +Git is a distributed version control system, this document is meant to be distributed using git.
+ +C is functional compiled language created by Dennis Ritchie. BSD, Linux and Minix kernels use this language + as primary language.
+ +Script files that start with "#!/bin/sh" use dash (in crux), + /bin/sh is a link to dash, while files that start with "#!/bin/bash" + use bash;
+ ++ This is part of the c9-doc Manual. + Copyright (C) 2017 + c9 team. + See the file Gnu Free Documentation License + for copying conditions.
-- cgit From 7867e4ea5ca255b610d69a4f47d45083717ac542 Mon Sep 17 00:00:00 2001 From: Silvino Silva+ // seed with current time: + // time_t t; + // srand(time(&t)); + void srand(unsigned seed); --- mode Description - "r" Opens a file for reading. The file must exist. - "w" Creates an empty file for writing. If a file with the same name already exists, its content is erased and the file is considered as a new empty file. - "a" Appends to a file. Writing operations, append data at the end of the file. The file is created if it does not exist. - "r" Opens a file to update both reading and writing. The file must exist. - "w" Creates an empty file for both reading and writing. - "a" Opens a file for reading and appending. -+ int rand(void); +
- // ERROR: result == NULL (also when EOF is reached) - char *fgets(char *str, int strlen, FILE *stream); ++Signals
- // ERROR: result == NULL - FILE *fopen(const char *filename, const char *mode); ++ sig_t signal(int sig, sig_t func); - // result == EOF when finished reading the stream - // SUCCESS: number of matched items on success - int fscanf(FILE *stream, const char *format, ...); + int raise(int sig); - // ERROR: result == EOF - // SUCCESS: result == 0 - int fclose(FILE *stream); + int kill(pid_t pid, int sig); +- // ERROR: result == -1 - // SUCCESS: number of bytes written - ssize_t write(int fildes, const void *buf, size_t nbyte); +Sorting
- // ERROR: result == -1 - // EOF when finished reading - // SUCCESS: number of bytes read - ssize_t read(int fildes, void *buf, size_t nbyte); ++ void qsort(void* values, size_t num_items, size_t item_size, int (*comparefunc)(const void*, const void*)); +- // SUCCESS: result > 0 - // ERROR: result == EOF - int fputs(const char *restrict s, FILE *restrict stream); -
+ // SUCCESS: pointer to destination string + char *strcpy(char *dest, const char *src); -- -- // SUCCESS: pointer to destination string - char *strcpy(char *dest, const char *src); + // result == 0 -> strings are equal + // result < 0 -> str1 less than str2 + // result > 0 -> str2 less than str1 + int strcmp(const char *str1, const char *str2);; - // result == 0 -> strings are equal - // result < 0 -> str1 less than str2 - // result > 0 -> str2 less than str1 - int strcmp(const char *str1, const char *str2);; + // result == NULL -> no tokens left to retrieve + // else: pointer to last token found + char *strtok(char *str, const char *delim); + + // NULL if no match + // else: pointer to first occurence in string + char *strstr(const char *string, const char *substring); + + // ERROR: result == 0 + int atoi(const char *str); ++ +Inter Process Communication
++ // ERROR: result < 0 + // result = 0 inside child + // result > 0 inside parent + pid_t fork(void); + + // ERROR: result < 0 + // SUCCESS: result == 0 + int pipe(int fd[2]); ++ +File IO
+File Modes
+ ++ mode Description + "r" Opens a file for reading. The file must exist. + "w" Creates an empty file for writing. If a file with the same name already exists, its content is erased and the file is considered as a new empty file. + "a" Appends to a file. Writing operations, append data at the end of the file. The file is created if it does not exist. + "r" Opens a file to update both reading and writing. The file must exist. + "w" Creates an empty file for both reading and writing. + "a" Opens a file for reading and appending. ++ ++ // ERROR: result == NULL (also when EOF is reached) + char *fgets(char *str, int strlen, FILE *stream); + + // ERROR: result == NULL + FILE *fopen(const char *filename, const char *mode); + + // result == EOF when finished reading the stream + // SUCCESS: number of matched items on success + int fscanf(FILE *stream, const char *format, ...); + + // ERROR: result == EOF + // SUCCESS: result == 0 + int fclose(FILE *stream); + + // ERROR: result == -1 + // SUCCESS: number of bytes written + ssize_t write(int fildes, const void *buf, size_t nbyte); + + // ERROR: result == -1 + // EOF when finished reading + // SUCCESS: number of bytes read + ssize_t read(int fildes, void *buf, size_t nbyte); + + // SUCCESS: result > 0 + // ERROR: result == EOF + int fputs(const char *restrict s, FILE *restrict stream); +- // result == NULL -> no tokens left to retrieve - // else: pointer to last token found - char *strtok(char *str, const char *delim); +Shared Memory
- // NULL if no match - // else: pointer to first occurence in string - char *strstr(const char *string, const char *substring); - - // ERROR: result == 0 - int atoi(const char *str); -
- // ERROR: result == -1 - // example: sock = socket(AF_INET, SOCK_STREAM, 0); - int socket(int domain, int type, int protocol); - - // sockaddr_in struct (man ip 4) - struct sockaddr_in server; - server.sin_family = PF_INET; - server.sin_addr.s_addr = INADDR_ANY; - server.sin_port = htons(8080); - - // ERROR: result < 0 - // SUCCESS: result == 0 - // example: bind(sock, (struct sockaddr *) &server, sizeof(server)) - int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen); - - // ERROR: result < 0 - // SUCCESS: filedeskriptor for accepted socket - // example: fd = accept(sock, (struct sockaddr *) &client, &client_len); - int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); - - // SUCCESS: result == 0 - // ERROR: result == -1 - int listen(int socket, int backlog); -- - Development Index - -
- This is part of the c9-doc Manual. - Copyright (C) 2018 - c9 team. - See the file Gnu Free Documentation License - for copying conditions.
++ // ERROR: result < 0 + // SUCCESS: result == shmid + int shmget(key_t key, size_t size, int shmflg); + + // ERROR: result == NULL + void *shmat(int shmid, const void *shmaddr, int shmflg); + + // ERROR: result < 0 + // SUCCESS: result == 0 + int shmdt(const void *shmaddr); ++ +
+ $ pkginfo -o socket.h ++ +
+ #include "<sys/socket.h>" ++ +
+ // ERROR: result == -1 + // example: sock = socket(AF_INET, SOCK_STREAM, 0); + int socket(int domain, int type, int protocol); + + // sockaddr_in struct (man ip 4) + struct sockaddr_in server; + server.sin_family = PF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(8080); + + // ERROR: result < 0 + // SUCCESS: result == 0 + // example: bind(sock, (struct sockaddr *) &server, sizeof(server)) + int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen); + + // ERROR: result < 0 + // SUCCESS: filedeskriptor for accepted socket + // example: fd = accept(sock, (struct sockaddr *) &client, &client_len); + int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); + + // SUCCESS: result == 0 + // ERROR: result == -1 + int listen(int socket, int backlog); ++ +
+ // ERROR: result > 0 + // SUCCESS: res == 0 + // example: pthread_create(&threads[t], NULL, printHello, (void*)t); + int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void *), void *restrict arg); + + // SUCCESS: result == 0 + // ERROR: result > 0 + int pthread_join(pthread_t tid, void **ret); + + void pthread_exit(void *value_ptr); ++ + Development Index + +
+ This is part of the c9-doc Manual. + Copyright (C) 2018 + c9 team. + See the file Gnu Free Documentation License + for copying conditions.
diff --git a/dev/index.html b/dev/index.html index ab00a3e..1f11b84 100644 --- a/dev/index.html +++ b/dev/index.html @@ -80,6 +80,8 @@Open your browser and browse http://localhost:8000, you should see "Hello World".
+Create folder tests for phpunit files with settings, inside + create another called tests to create tests to be performed on + the code.
+ ++ $ mkdir -p tests/tests + $ cd tests ++ +
Create a test tests/EngineTest.php;
+ +
+ <?php
+ declare(strict_types=1);
+
+ use PHPUnit\Framework\TestCase;
+
+ final class EngineTest extends TestCase {
+
+ public function testCanBeCreated(){
+
+ $engine = new engine();
+
+ $this->assertInstanceOf(engine::class, $engine);
+
+ }
+ }
+
+
+ Create phpunit.xml;
+ ++ $ phpunit --generate-configuration ++ +
Run the test;
+ ++ $ phpunit ++ Development Index
This is part of the c9-doc Manual. -- cgit