Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 18, 2023
1 parent cd87e92 commit 683ba37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 84 deletions.
45 changes: 3 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,58 +239,19 @@ $ make
```c
#include "tbox/tbox.h"

int main(int argc, char** argv)
{
// init tbox
int main(int argc, char** argv) {
if (!tb_init(tb_null, tb_null)) return 0;

// trace
tb_trace_i("hello tbox");

// init vector
tb_vector_ref_t vector = tb_vector_init(0, tb_element_str(tb_true));
if (vector)
{
// insert item
if (vector) {
tb_vector_insert_tail(vector, "hello");
tb_vector_insert_tail(vector, "tbox");

// dump all items
tb_for_all (tb_char_t const*, cstr, vector)
{
// trace
tb_for_all (tb_char_t const*, cstr, vector) {
tb_trace_i("%s", cstr);
}

// exit vector
tb_vector_exit(vector);
}

// init stream
tb_stream_ref_t stream = tb_stream_init_from_url("http://www.xxx.com/file.txt");
if (stream)
{
// open stream
if (tb_stream_open(stream))
{
// read line
tb_long_t size = 0;
tb_char_t line[TB_STREAM_BLOCK_MAXN];
while ((size = tb_stream_bread_line(stream, line, sizeof(line))) >= 0)
{
// trace
tb_trace_i("line: %s", line);
}
}

// exit stream
tb_stream_exit(stream);
}

// wait
tb_getchar();

// exit tbox
tb_exit();
return 0;
}
Expand Down
45 changes: 3 additions & 42 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,58 +246,19 @@ $ make
```c
#include "tbox/tbox.h"

int main(int argc, char** argv)
{
// init tbox
int main(int argc, char** argv) {
if (!tb_init(tb_null, tb_null)) return 0;

// trace
tb_trace_i("hello tbox");

// init vector
tb_vector_ref_t vector = tb_vector_init(0, tb_element_str(tb_true));
if (vector)
{
// insert item
if (vector) {
tb_vector_insert_tail(vector, "hello");
tb_vector_insert_tail(vector, "tbox");

// dump all items
tb_for_all (tb_char_t const*, cstr, vector)
{
// trace
tb_for_all (tb_char_t const*, cstr, vector) {
tb_trace_i("%s", cstr);
}

// exit vector
tb_vector_exit(vector);
}

// init stream
tb_stream_ref_t stream = tb_stream_init_from_url("http://www.xxx.com/file.txt");
if (stream)
{
// open stream
if (tb_stream_open(stream))
{
// read line
tb_long_t size = 0;
tb_char_t line[TB_STREAM_BLOCK_MAXN];
while ((size = tb_stream_bread_line(stream, line, sizeof(line))) >= 0)
{
// trace
tb_trace_i("line: %s", line);
}
}

// exit stream
tb_stream_exit(stream);
}

// wait
tb_getchar();

// exit tbox
tb_exit();
return 0;
}
Expand Down

0 comments on commit 683ba37

Please sign in to comment.