Skip to content

Commit 4dbec59

Browse files
committed
make it clear when the program doesn't compile
1 parent 42c9672 commit 4dbec59

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.0.0beta4 (April 8, 2017)
4+
5+
* In the [Multiple lines](http://viewsourcecode.org/snaptoken/kilo/04.aTextViewer.html#multiple-lines)
6+
section, make it clearer that the program doesn't compile for those steps.
7+
(Thanks @mapleray and @agentultra)
8+
39
## 1.0.0beta3 (April 7, 2017)
410

511
* In `editorPrompt()`, change `!iscntrl(c)` to `!iscntrl(c) && c < 128`, so

doc/04.aTextViewer.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ empty.
9999

100100
To store multiple lines, let's make `E.row` an array of `erow` structs. It will
101101
be a dynamically-allocated array, so we'll make it a pointer to `erow`, and
102-
initialize the pointer to `NULL`.
102+
initialize the pointer to `NULL`. (This will break a bunch of our code that
103+
doesn't expect `E.row` to be a pointer, so the program will fail to compile for
104+
the next few steps.)
103105

104106
{{erow-array}}
105107

@@ -109,6 +111,9 @@ function called `editorAppendRow()`. We'll also put it under a new section,
109111

110112
{{append-row}}
111113

114+
Notice that we renamed the `line` and `linelen` variables to `s` and `len`,
115+
which are now arguments to `editorAppendRow()`.
116+
112117
We want `editorAppendRow()` to allocate space for a new `erow`, and then copy
113118
the given string to a new `erow` at the end of the `E.row` array. Let's do that
114119
now.
@@ -118,9 +123,8 @@ now.
118123
We have to tell `realloc()` how many bytes we want to allocate, so we multiply
119124
the number of bytes each `erow` takes (`sizeof(erow)`) and multiply that by the
120125
number of rows we want. Then we set `at` to the index of the new row we want to
121-
initialize, and replace each occurrence of `E.row` with `E.row[at]`. We also
122-
make sure to use the argument names `s` and `len` instead of `line` and
123-
`linelen`. Lastly, we change `E.numrows = 1` to `E.numrows++`.
126+
initialize, and replace each occurrence of `E.row` with `E.row[at]`. Lastly, we
127+
change `E.numrows = 1` to `E.numrows++`.
124128

125129
Next, let's update `editorDrawRows()` to use `E.row[y]` instead of `E.row`,
126130
when printing out the current line.

leg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
:name: kilo
3-
:version: "1.0.0beta3"
3+
:version: "1.0.0beta4"
44
:title: Build Your Own Text Editor
55
:rouge_theme: github
66
:bold_weight: 500

steps.diff

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,10 +1606,10 @@ diff --git a/kilo.c b/kilo.c
16061606
+/*** row operations ***/
16071607
+
16081608
+void editorAppendRow(char *s, size_t len) {
1609-
+ E.row.size = linelen;
1610-
+ E.row.chars = malloc(linelen + 1);
1611-
+ memcpy(E.row.chars, line, linelen);
1612-
+ E.row.chars[linelen] = '\0';
1609+
+ E.row.size = len;
1610+
+ E.row.chars = malloc(len + 1);
1611+
+ memcpy(E.row.chars, s, len);
1612+
+ E.row.chars[len] = '\0';
16131613
+ E.numrows = 1;
16141614
+}
16151615
+
@@ -1638,10 +1638,10 @@ diff --git a/kilo.c b/kilo.c
16381638
/*** row operations ***/
16391639

16401640
void editorAppendRow(char *s, size_t len) {
1641-
- E.row.size = linelen;
1642-
- E.row.chars = malloc(linelen + 1);
1643-
- memcpy(E.row.chars, line, linelen);
1644-
- E.row.chars[linelen] = '\0';
1641+
- E.row.size = len;
1642+
- E.row.chars = malloc(len + 1);
1643+
- memcpy(E.row.chars, s, len);
1644+
- E.row.chars[len] = '\0';
16451645
- E.numrows = 1;
16461646
+ E.row = realloc(E.row, sizeof(erow) * (E.numrows + 1));
16471647
+

0 commit comments

Comments
 (0)