Split the codebase into a managable tree

This commit is contained in:
caskd 2019-10-18 18:25:31 +02:00
parent 2a678c087a
commit d7ad1d229b
No known key found for this signature in database
GPG Key ID: 79DB21404E300A27
30 changed files with 601 additions and 327 deletions

View File

@ -23,6 +23,224 @@ checkPerformance=true
checkPortability=true
checkStyle=true
[Filters]
size=43
[Filters][0]
inclusive=0
pattern=.*
targets=3
[Filters][1]
inclusive=1
pattern=.gitignore
targets=1
[Filters][10]
inclusive=1
pattern=.clang-format
targets=1
[Filters][11]
inclusive=1
pattern=.circleci
targets=2
[Filters][12]
inclusive=0
pattern=.git
targets=2
[Filters][13]
inclusive=0
pattern=CVS
targets=2
[Filters][14]
inclusive=0
pattern=.svn
targets=2
[Filters][15]
inclusive=0
pattern=_svn
targets=2
[Filters][16]
inclusive=0
pattern=SCCS
targets=2
[Filters][17]
inclusive=0
pattern=_darcs
targets=2
[Filters][18]
inclusive=0
pattern=.hg
targets=2
[Filters][19]
inclusive=0
pattern=.bzr
targets=2
[Filters][2]
inclusive=1
pattern=.gitmodules
targets=1
[Filters][20]
inclusive=0
pattern=__pycache__
targets=2
[Filters][21]
inclusive=0
pattern=*.o
targets=1
[Filters][22]
inclusive=0
pattern=*.a
targets=1
[Filters][23]
inclusive=0
pattern=*.so
targets=1
[Filters][24]
inclusive=0
pattern=*.so.*
targets=1
[Filters][25]
inclusive=0
pattern=*.obj
targets=1
[Filters][26]
inclusive=0
pattern=*.lib
targets=1
[Filters][27]
inclusive=0
pattern=*.dll
targets=1
[Filters][28]
inclusive=0
pattern=*.exp
targets=1
[Filters][29]
inclusive=0
pattern=*.pdb
targets=1
[Filters][3]
inclusive=1
pattern=.pre-commit-config.yaml
targets=1
[Filters][30]
inclusive=0
pattern=moc_*.cpp
targets=1
[Filters][31]
inclusive=0
pattern=*.moc
targets=1
[Filters][32]
inclusive=0
pattern=ui_*.h
targets=1
[Filters][33]
inclusive=0
pattern=*.qmlc
targets=1
[Filters][34]
inclusive=0
pattern=qrc_*.cpp
targets=1
[Filters][35]
inclusive=0
pattern=*~
targets=1
[Filters][36]
inclusive=0
pattern=*.orig
targets=1
[Filters][37]
inclusive=0
pattern=.*.kate-swp
targets=1
[Filters][38]
inclusive=0
pattern=.*.swp
targets=1
[Filters][39]
inclusive=0
pattern=*.pyc
targets=1
[Filters][4]
inclusive=1
pattern=.gitlab-ci.yml
targets=1
[Filters][40]
inclusive=0
pattern=*.pyo
targets=1
[Filters][41]
inclusive=0
pattern=/learningc
targets=1
[Filters][42]
inclusive=0
pattern=/build/learningc
targets=1
[Filters][5]
inclusive=1
pattern=.travis.yml
targets=1
[Filters][6]
inclusive=1
pattern=.editorconfig
targets=1
[Filters][7]
inclusive=1
pattern=.pep8
targets=1
[Filters][8]
inclusive=1
pattern=.prettierignore
targets=1
[Filters][9]
inclusive=1
pattern=.prettierrc*
targets=1
[Launch]
Launch Configurations=Launch Configuration 0

View File

@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.0)
project(learningc LANGUAGES C)
add_executable(learningc main.c)
set(CHAPTER 1)
set(EXERCISE 21)
add_executable(learningc chapters/${CHAPTER}/exercises/${EXERCISE}.c)
install(TARGETS learningc RUNTIME DESTINATION bin)

5
chapters/1/exercises/1.c Normal file
View File

@ -0,0 +1,5 @@
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}

17
chapters/1/exercises/10.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdio.h>
int main() {
int c;
while ((c = getchar()) != EOF) {
if (c == '\t') {
printf("\\t");
} else if (c == '\b') {
printf("\\b"); // Needs literal backspace due to line buffer
} else if (c == '\\') {
printf("\\\\");
} else {
putchar(c);
}
}
return 0;
}

13
chapters/1/exercises/12.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main() {
int c;
while ((c = getchar()) != EOF) {
if (c == ' ' || c == '\n' || c == '\t') {
printf("\n");
} else {
putchar(c);
}
}
return 0;
}

13
chapters/1/exercises/13.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main() {
int c;
while ((c = getchar()) != EOF) {
if (c == ' ' || c == '\n' || c == '\t') {
printf("\n");
} else {
printf("#");
}
}
return 0;
}

33
chapters/1/exercises/14.c Normal file
View File

@ -0,0 +1,33 @@
#include <stdio.h>
#include "shared/limits.h"
int main() {
int c;
int count[MAXLINE];
for (int i = 0; i < MAXLINE; i++) {
count[i] = 0;
}
while ((c = getchar()) != EOF) {
count[c]++;
}
printf("\n");
for (int i = 0; i < MAXLINE; i++) {
if (count[i] != 0) {
if (i == '\n') {
printf("\\n");
} else if (i == '\t') {
printf("\\t");
} else if (i == '\"') {
printf("\\\"");
} else {
putchar(i);
}
printf("\t: ");
for (int z = 0; z < count[i]; z++) {
printf("#");
}
printf("\n");
}
}
return 0;
}

14
chapters/1/exercises/15.c Normal file
View File

@ -0,0 +1,14 @@
#include <stdio.h>
#include "shared/tempsteps.h"
#include "shared/functions.h"
#include "shared/functions/convert2cels.c"
int main() {
float celsius = LOWER;
printf("%s", "Temperature conversion table (F to C):\n");
while (celsius <= UPPER) {
printf("%3.0f %6.1f\n", celsius, convert2cels(celsius));
celsius = celsius + STEP;
}
return 0;
}

24
chapters/1/exercises/16.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include "shared/functions.h"
#include "shared/limits.h"
#include "shared/functions/getlines.c"
int main() {
int len;
/* current line length */
int max;
/* maximum length seen so far */
char line[MAXLINE];
/* current input line */
char longest[MAXLINE];
/* longest line saved here */
max = 0;
while ((len = getlines(line, MAXLINE)) > 0)
if (len > max) {
max = len;
copy(longest, line);
}
if (max > 0) /* there was a line */
printf("Character count: %d\n%s", max, longest);
return 0;
}

13
chapters/1/exercises/17.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
#include "shared/limits.h"
#include "shared/functions.h"
#include "shared/functions/getlines.c"
int main() {
char line[MAXLINE];
int len;
while ((len = getlines(line,MAXLINE)) > 0) {
if (len > 80)
printf("%s", line);
}
}

20
chapters/1/exercises/18.c Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
#include "shared/limits.h"
#include "shared/functions.h"
#include "shared/functions/getlines.c"
int main() {
char line[MAXLINE], prostr[MAXLINE];
int len;
int skip = 0;
while ((len = getlines(line, MAXLINE)) > 0) {
for (int i=len; !(i < 0); --i) {
if (skip != 0 || !(line[i] == ' ' || line[i] == '\n' || line[i] == '\t' || line[i] == '\0')) {
prostr[i] = line[i];
skip = 1;
}
}
}
printf("\"%s\"\n", prostr);
return 0;
}

15
chapters/1/exercises/19.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include "shared/limits.h"
#include "shared/functions.h"
#include "shared/functions/getlines.c"
#include "shared/functions/reverse.c"
int main() {
char d[MAXLINE];
char line[MAXLINE];
int len;
while ((len = getlines(line,MAXLINE)) > 0) {
reverse(line, d);
printf("\nOriginal: %s\nReversed: %s\n", line, d);
}
}

12
chapters/1/exercises/20.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
#include "shared/limits.h"
#include "shared/functions.h"
#include "shared/functions/detab.c"
int main() {
int len;
char line[MAXLINE];
while ((len = detab(line,MAXLINE,8)) > 0) {
printf("%s", line);
}
}

12
chapters/1/exercises/21.c Normal file
View File

@ -0,0 +1,12 @@
#include<stdio.h>
#include "shared/limits.h"
#include "shared/functions.h"
#include "shared/functions/entab.c"
int main() {
int len;
char line[MAXLINE];
while ((len = entab(line,MAXLINE,8)) > 0) {
printf("%s", line);
}
}

15
chapters/1/exercises/3.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include "shared/tempsteps.h"
int main() {
float fahr, celsius;
fahr = LOWER;
printf("%s", "Temperature conversion table (F to C):\n");
while (fahr <= UPPER) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + STEP;
}
return 0;
}

17
chapters/1/exercises/4.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdio.h>
int main() {
float fahr, celsius, lower, upper, step;
lower = -40;
upper = 300;
step = 20;
celsius = lower;
printf("%s", "Temperature conversion table (C to F):\n");
while (celsius <= upper) {
fahr = celsius * (9.0/5.0) + 32.0;
printf("%3.0f %6.1f\n", celsius, fahr);
celsius = celsius + step;
}
return 0;
}

12
chapters/1/exercises/5.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
#include "shared/tempsteps.h"
int main() {
float fahr = UPPER;
printf("%s", "Temperature conversion table (F to C):\n");
while (fahr >= LOWER) {
printf("%3.0f %6.1f\n", fahr, (5.0/9.0) * (fahr-32.0));
fahr = fahr - STEP;
}
return 0;
}

9
chapters/1/exercises/6.c Normal file
View File

@ -0,0 +1,9 @@
#include <stdio.h>
int main() {
int c;
while ((c = getchar()) != EOF) {
putchar(c);
}
return 0;
}

6
chapters/1/exercises/7.c Normal file
View File

@ -0,0 +1,6 @@
#include <stdio.h>
int main() {
printf("%d\n",EOF);
return 0;
}

18
chapters/1/exercises/8.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
int main() {
int c, tabc, blankc, nl;
tabc = blankc = nl = 0;
while ((c = getchar()) != EOF) {
if (c == '\t') {
tabc++;
} else if (c == ' ') {
blankc++;
} else if (c == '\n') {
nl++;
}
}
printf ("\nSpecial character count:\n");
printf ("Newlines: %d\nBlanks: %d\nTabs: %d\n", nl, blankc, tabc);
return 0;
}

View File

@ -0,0 +1,8 @@
#include <string.h>
#include "limits.h"
float convert2cels(int fahr);
void reverse(char s[MAXLINE], char d[strlen(s)]);
void copy(char to[], char from[]);
int getlines(char line[], int maxline);
int detab(char s[],int lim, int col);
int entab(char s[], int lim, int col);

View File

@ -0,0 +1,3 @@
float convert2cels(int fahr) {
return (5.0/9.0) * (fahr-32.0);
}

View File

@ -0,0 +1,6 @@
void copy(char to[], char from[]) {
int i;
i = 0;
while ((to[i] = from[i]) != '\0')
++i;
}

View File

@ -0,0 +1,30 @@
#include <stdio.h>
int detab(char s[],int lim, int col)
/*s is the string we need to replace, lim is the character limit
* and col is the size of a tab (8 characters usually so we use that)*/
{
int c, i; /*c is the character i0nteger representation and i is the column we are on*/
for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n';)
if (c == '\t') {
int sp=col-i%col; /*Amount of spaces to replace the tab with*/
int st=i; /*Starting point*/
for (int co = 0; co<=sp && i < lim-1; co++ && i++) {
/*For each space we need to add, we increase the column count and add it
*to the array at position (starting point + spaces added so far)
* and we increase the spaces added so far*/
s[st+co] = ' ';
}
} else {
s[i] = c;
++i;
}
if (c == '\n')
/*If it is the end of the string, represented by a new line,
* add that new line and increase it for the \0 addition*/ {
s[i] = c;
}
/*Add the string end and return it to the previous context*/
s[i+1] = '\0';
return i;
}

View File

@ -0,0 +1,37 @@
#include <stdio.h>
int entab(char s[], int lim, int col) {
int c, i, t;
for (i=0,t=0; i < lim-1 && (c=getchar())!=EOF && c!='\n';i++,t++) {
/*
* c is the character representation as integer
* i is the current column on the copied string
* t is the current column on the original string
*
* t is used to count tab stops because i goes back when spaces are replaced by tabs.
* i and t are both modified, however only i changes in contexts other than the routinal increase.
* c is set to i's position and t is only used in tab stop counting
*/
if (t >= col && t%col == 0 && s[i-1] == ' ' && s[i-2] == ' ') {
int x;
for (x = i; s[x-1] == ' ' && i-col < x; x--);
s[x] = '\t';
i = ++x;
}
s[i] = c;
}
if (c == '\n')
/*
* If it is the end of the string, represented by a new line,
* add that new line and increase it for the \0 addition
*/ {
s[i] = c;
}
/*Add the string end and return it to the previous context*/
if (lim-1 > i) {
s[i+1] = '\0';
} else {
s[lim-1] = '\0';
}
return i;
}

View File

@ -0,0 +1,13 @@
#include <stdio.h>
int getlines(char s[],int lim) {
int c, i;
for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
s[i] = c;
if (c == '\n') {
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}

View File

@ -0,0 +1,10 @@
#include <string.h>
#include "../limits.h"
void reverse(char s[MAXLINE], char d[strlen(s)+1]) {
int len = strlen(s);
for (int i=--len; i >= 0; --i) {
d[len-i] = s[i];
d[len+1] = '\0';
}
}

View File

@ -0,0 +1 @@
#define MAXLINE 1000

View File

@ -0,0 +1,3 @@
#define LOWER 0
#define UPPER 300
#define STEP 20

326
main.c
View File

@ -1,326 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// // PART OF 1-5, 1-15
// #define LOWER 0
// #define UPPER 300
// #define STEP 20
// // PART OF 1-15
// float convert2cels(int fahr);
// // PART OF 1-16, 1-17, 1-18, 1-19, 1-20,1-21
#define MAXLINE 1000
// int getlines(char line[], int maxline);
// int detab(char s[],int lim, int col);
int entab(char s[], int lim, int col);
// void reverse(char s[MAXLINE], char d[strlen(s)]);
// void copy(char to[], char from[]);
int main() {
// // 1-1
// printf("Hello, World!\n");
// // 1-3
// float fahr, celsius, lower, upper, step;
//
// lower = 0;
// upper = 300;
// step = 20;
//
// fahr = lower;
// printf("%s", "Temperature conversion table (F to C):\n");
// while (fahr <= upper) {
// celsius = (5.0/9.0) * (fahr-32.0);
// printf("%3.0f %6.1f\n", fahr, celsius);
// fahr = fahr + step;
// }
// // 1-4
// float fahr, celsius, lower, upper, step;
//
// lower = -40;
// upper = 300;
// step = 20;
//
// celsius = lower;
// printf("%s", "Temperature conversion table (C to F):\n");
// while (celsius <= upper) {
// fahr = celsius * (9.0/5.0) + 32.0;
// printf("%3.0f %6.1f\n", celsius, fahr);
// celsius = celsius + step;
// }
// // 1-5
// float fahr = UPPER;
// printf("%s", "Temperature conversion table (F to C):\n");
// while (fahr >= LOWER) {
// printf("%3.0f %6.1f\n", fahr, (5.0/9.0) * (fahr-32.0));
// fahr = fahr - STEP;
// }
// // 1-6
// int c;
// while ((c = getchar()) != EOF) {
// putchar(c);
// }
// // 1-7
// printf("%d\n",EOF);
// // 1-8
// int c, tabc, blankc, nl;
// tabc = blankc = nl = 0;
// while ((c = getchar()) != EOF ) {
// if (c == '\t') {
// tabc++;
// } else if (c == ' ') {
// blankc++;
// } else if (c == '\n') {
// nl++;
// }
// }
// printf ("\nSpecial character count:\n");
// printf ("Newlines: %d\nBlanks: %d\nTabs: %d\n", nl, blankc, tabc);
// // 1-9 TODO
//
// // 1-10
// int c;
// while ((c = getchar()) != EOF) {
// if (c == '\t') {
// printf("\\t");
// } else if (c == '\b') {
// printf("\\b"); // Needs literal backspace due to line buffer
// } else if (c == '\\') {
// printf("\\\\");
// } else {
// putchar(c);
// }
// }
// // 1-12
// int c;
// while ((c = getchar()) != EOF) {
// if (c == ' ' || c == '\n' || c == '\t') {
// printf("\n");
// } else {
// putchar(c);
// }
// }
// // 1-13
// int c;
// while ((c = getchar()) != EOF) {
// if (c == ' ' || c == '\n' || c == '\t') {
// printf("\n");
// } else {
// printf("#");
// }
// }
// // 1-14
// int c;
// int count[1024];
// for (int i = 0; i < 1024; i++) {
// count[i] = 0;
// }
// while ((c = getchar()) != EOF) {
// count[c]++;
// }
// printf("\n");
// for (int i = 0; i < 1024; i++) {
// if (count[i] != 0) {
// if (i == '\n') {
// printf("\\n");
// } else if (i == '\t') {
// printf("\\t");
// } else if (i == '\"') {
// printf("\\\"");
// } else {
// putchar(i);
// }
// printf("\t: ");
// for (int z = 0; z < count[i]; z++) {
// printf("#");
// }
// printf("\n");
// }
// }
// // 1-15
// float celsius = LOWER;
// printf("%s", "Temperature conversion table (F to C):\n");
// while (celsius <= UPPER) {
// printf("%3.0f %6.1f\n", celsius, convert2cels(celsius));
// celsius = celsius + STEP;
// }
// // 1-16
// int len;
// /* current line length */
// int max;
// /* maximum length seen so far */
// char line[MAXLINE];
// /* current input line */
// char longest[MAXLINE];
// /* longest line saved here */
// max = 0;
// while ((len = getlines(line, MAXLINE)) > 0)
// if (len > max) {
// max = len;
// copy(longest, line);
// }
// if (max > 0) /* there was a line */
// printf("Character count: %d\n%s", max, longest);
// // 1-17
// char line[MAXLINE];
// int len;
// while ((len = getlines(line,MAXLINE)) > 0) {
// if (len > 80)
// printf("%s", line);
// }
// // 1-18
// char line[MAXLINE], prostr[MAXLINE];
// int len;
// int skip = 0;
// while ((len = getlines(line, MAXLINE)) > 0) {
// for (int i=len; !(i < 0); --i) {
// if (skip != 0 || !(line[i] == ' ' || line[i] == '\n' || line[i] == '\t' || line[i] == '\0')) {
// prostr[i] = line[i];
// skip = 1;
// }
// }
// }
// printf("\"%s\"\n", prostr);\
// // 1-19
// char d[MAXLINE];
// char line[MAXLINE];
// int len;
// while ((len = getlines(line,MAXLINE)) > 0) {
// reverse(line, d);
// printf("\nOriginal: %s\nReversed: %s\n", line, d);
// }
// // 1-20
// int len;
// char line[MAXLINE];
// while ((len = detab(line,MAXLINE,8)) > 0) {
// printf("%s", line);
// }
// 1-21
int len;
char line[MAXLINE];
while ((len = entab(line,MAXLINE,8)) > 0) {
printf("%s", line);
}
return 0;
}
// // PART OF 1-15
// float convert2cels(int fahr) {
// return (5.0/9.0) * (fahr-32.0);
// }
// // PART OF 1-16, 1-17, 1-18, 1-19
// int getlines(char s[],int lim) {
// int c, i;
// for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
// s[i] = c;
// if (c == '\n') {
// s[i] = c;
// ++i;
// }
// s[i] = '\0';
// return i;
// }
// // PART OF 1-20
// int detab(char s[],int lim, int col)
// /*s is the string we need to replace, lim is the character limit
// * and col is the size of a tab (8 characters usually so we use that)*/
// {
// int c, i; /*c is the character integer representation and i is the column we are on*/
// for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n';)
// if (c == '\t') {
// int sp=col-i%col; /*Amount of spaces to replace the tab with*/
// int st=i; /*Starting point*/
// for (int co = 0; co<=sp && i < lim-1; co++ && i++) {
// /*For each space we need to add, we increase the column count and add it
// *to the array at position (starting point + spaces added so far)
// * and we increase the spaces added so far*/
// s[st+co] = ' ';
// }
// } else {
// s[i] = c;
// ++i;
// }
// if (c == '\n')
// /*If it is the end of the string, represented by a new line,
// * add that new line and increase it for the \0 addition*/ {
// s[i] = c;
// }
// /*Add the string end and return it to the previous context*/
// s[i+1] = '\0';
// return i;
// }
// PART OF 1-21
int entab(char s[], int lim, int col) {
int c, i, t;
for (i=0,t=0; i < lim-1 && (c=getchar())!=EOF && c!='\n';i++,t++) {
/*
* c is the character representation as integer
* i is the current column on the copied string
* t is the current column on the original string
*
* t is used to count tab stops because i goes back when spaces are replaced by tabs.
* i and t are both modified, however only i changes in contexts other than the routinal increase.
* c is set to i's position and t is only used in tab stop counting
*/
if (t >= col && t%col == 0 && s[i-1] == ' ' && s[i-2] == ' ') {
int x;
for (x = i; s[x-1] == ' ' && i-col < x; x--);
s[x] = '\t';
i = ++x;
}
s[i] = c;
}
if (c == '\n')
/*
* If it is the end of the string, represented by a new line,
* add that new line and increase it for the \0 addition
*/ {
s[i] = c;
}
/*Add the string end and return it to the previous context*/
if (lim-1 > i) {
s[i+1] = '\0';
} else {
s[lim-1] = '\0';
}
return i;
}
// /* copy: copy 'from' into 'to'; assume to is big enough */
// void copy(char to[], char from[]) {
// int i;
// i = 0;
// while ((to[i] = from[i]) != '\0')
// ++i;
// }
// // PART OF 1-19
// void reverse(char s[MAXLINE], char d[strlen(s)+1]) {
// int len = strlen(s);
// for (int i=--len; i >= 0; --i) {
// d[len-i] = s[i];
// d[len+1] = '\0';
// }
// }