File: ftest.cc

package info (click to toggle)
sdcc 3.8.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 99,212 kB
  • sloc: ansic: 918,594; cpp: 69,526; makefile: 56,790; sh: 29,616; asm: 12,364; perl: 12,136; yacc: 7,179; lisp: 1,672; python: 812; lex: 773; awk: 495; sed: 89
file content (101 lines) | stat: -rw-r--r-- 1,556 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <stdio.h>
#include <unistd.h>

#include "fiocl.h"
#include "utils.h"
#include "charscl.h"


void
regular_ftest(char *fn)
{
  int i;
  class cl_f *f;

  printf("Testing regular file access: %s\n", fn);
  printf("Write test\n");
  f= mk_io(fn, cchars("w"));
  f->init();
  f->write_str("proba\n");

  printf("Read test\n");
  f->open(fn, cchars("r"));
  while (f->input_avail())
    {
      char buf[100];
      i= f->read(buf, 99);
      printf("read=%d\n", i);
      if (i)
	buf[i]= 0;
      else
	break;
      printf("data:%s\n", buf);
    }
  f->close();

  delete f;
}

void
stdin_ftest()
{
  class cl_f *f= mk_io(NULL, chars(""));
  char buf[100];
  int i, p= 0, done= 0;

  printf("STDIN test\n");
  f->use_opened(0, (char*)"r");
  printf("istty= %d\n", f->tty);
  i= f->read(buf, 99);
  buf[i]= '\0';
  printf("Got: %s\n", buf);
  while (done<10)
    {
      p= 0;
      while (f->input_avail())
	{
	  char c;
	  i= f->read(&c, 1);
	  printf("read=%d\n", i);
	  if ((c == '\n') ||
	      (c == '\r'))
	    break;
	  if (i == 0)
	    break;
	  if (p<99)
	    buf[p++]= c;
	}
      buf[p]= '\0';
      printf("data:%s\n", buf);
      //done= strcmp(buf, "exit") == 0;
      done++;
    }
  delete f;
}

int
main(int argc, char *argv[])
{
  char *fn;

  if (argc > 1)
    fn= argv[1];
  else
    fn= (char*)"ftest.txt";
  regular_ftest(fn);
  stdin_ftest();
  
  double last= dnow();
  int cnt= 0;
  while (1)
    {
      if (dnow() - last > 0.5)
	{
	  last= dnow();
	  printf("HUKK\n");
	  if (++cnt > 5)
	    return 0;
	}
    }
  return 0;
}