root/paper-tape-project/trunk/puncher/frontend.cli-simple.c

Revision 11, 1.7 kB (checked in by sven, 4 years ago)

The Windows backend works right now.

-- Sven @ XP Workstation

Line 
1/**
2 * abgespecktes frontend for testing purpose.
3 * C source.
4 *
5 **/
6 
7#include <stdio.h>
8#include <io.h>
9#include <stdlib.h>
10#include "backend.h"
11
12void puncher_frontend_visualize_byte(unsigned char buf) {
13        /* Draw a papertape byte (like the perl program) */
14        unsigned char against = 0x01;
15        unsigned char check;
16        int pos;
17       
18        printf("|");
19        for(pos=0; pos < 8; pos++) {
20                if(pos == 3) /* Streifenfuehrung */
21                        printf(".");
22                check = buf;
23                check >>= pos;
24               
25                if((check & against) == 0)
26                        printf(" "); /* bit nicht gesetzt */
27                else
28                        printf("*"); /* bit gesetzt */
29        } /*for */
30        printf("|");
31}
32
33 
34int main(int argc, char **argv) {
35        PuncherBackend *puncher;
36        int ret;
37
38        printf("Paper Tape Project -- Windows user mode puncher\n");
39       
40        puncher = puncher_backend_new(1);
41
42        for(int xy=0;;xy++) {
43                unsigned char buf; /* stdin 1 byte buffer */
44
45                ret = read(0, &buf, 1); /* 1 byte from stdin */
46                if(ret < 0) {
47                        printf("HARD READ IN EROR\n");
48                        puncher_backend_destroy(puncher);
49                        return 1;
50                }
51
52                if(ret == 0) {/* EOF, end of input, etc. */
53                        printf("EOF STDIN.\n");
54                        break;
55                }
56
57                /* Visualisation of the byte in a stdout line */
58                puncher_frontend_visualize_byte(buf);
59                printf(" 0x%02x=%03i ", buf, buf);
60
61        /* call the backend */
62        ret = puncher_backend_write_byte(puncher, buf);
63
64                if(ret < 0) {
65                        printf("BACKEND HARD ERROR: calling write backend\n");
66                        puncher_backend_destroy(puncher);
67                        return 1;
68                } else if(ret == 0) {
69                        printf("=)\n"); // everything okay
70                } else if(ret == 1) {
71                        printf(":-(\n"); // punch not okay, but go on.
72                }
73        } /* for stdin */
74
75        if(puncher_backend_destroy(puncher)) {
76                perror("finishing backend");
77                return 1;
78        } else
79                return 0;
80}
Note: See TracBrowser for help on using the browser.
© 2008 - 2010 Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License