OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [tools/] [shdspout/] [shdspout.c] - Blame information for rev 314

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 306 hellwig
/*
2
 * shdspout.c -- show display output in readable format
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include <time.h>
10
#include <curses.h>
11
 
12
 
13
#define LINE_SIZE       200
14
#define MAX_TOKENS      20
15
 
16
 
17
int splitLine(char *line, char *tokens[], int maxTokens) {
18
  int n;
19
  char *p;
20
 
21
  n = 0;
22
  p = strtok(line, ", ");
23
  while (p != NULL) {
24
    if (n < maxTokens) {
25
      tokens[n] = p;
26
      n++;
27
    }
28
    p = strtok(NULL, ", ");
29
  }
30
  return n;
31
}
32
 
33
 
34
int main(int argc, char *argv[]) {
35
  FILE *inFile;
36
  char line[LINE_SIZE];
37
  char *tokens[MAX_TOKENS];
38
  int n;
39
  int x, y;
40
  unsigned char c;
41
  struct timespec delay;
42
 
43
  if (argc != 2) {
44
    printf("usage: %s <display output file>\n", argv[0]);
45
    exit(1);
46
  }
47
  inFile = fopen(argv[1], "r");
48
  if (inFile == NULL) {
49
    printf("error: cannot open input file '%s'\n", argv[1]);
50
    exit(1);
51
  }
52
  initscr();
53
  cbreak();
54
  noecho();
55
  nonl();
56
  intrflush(stdscr, FALSE);
57
  keypad(stdscr, TRUE);
58
  while (fgets(line, LINE_SIZE, inFile) != NULL) {
59
    n = splitLine(line, tokens, MAX_TOKENS);
60
    if (n != 12) {
61
      continue;
62
    }
63
    y = strtoul(tokens[2], NULL, 0);
64
    x = strtoul(tokens[5], NULL, 0);
65
    c = strtoul(tokens[11], NULL, 0);
66
    mvaddch(y, x, c);
67
    refresh();
68
    delay.tv_sec = 0;
69
    delay.tv_nsec = 100000000;
70
    nanosleep(&delay, NULL);
71
  }
72
  do {
73
    n = getch();
74
  } while (n == ERR);
75
  endwin();
76
  fclose(inFile);
77
  return 0;
78
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.