Set the motion transform id in the collection step.
[flightgear.git] / tests / test-text.cxx
blobdec0c85fd9562b98df91d5bc5e9e7af7cfdfcda7
1 // do some non-destructive read tests relating text files
3 #include <stdio.h>
4 #include <string.h>
6 static void readchars( FILE *fd ) {
7 int c;
8 while ( (c = fgetc(fd)) != EOF ) {
9 printf("c = %d", c);
10 if ( c == 10 ) {
11 printf(" LF \\n");
13 if ( c == 13 ) {
14 printf(" CR \\r");
16 printf("\n");
21 static void readlines( FILE *fd ) {
22 char line[256];
23 while ( fgets(line, 255, fd) != NULL ) {
24 int len = strlen(line);
25 printf("line = %s", line);
26 if ( len >= 2 ) {
27 printf(" char[n - 1] = %d char[n] = %d\n",
28 line[len-2], line[len-1]);
29 } else if ( len >= 1 ) {
30 printf(" char[n] = %d\n",line[len-1]);
31 } else {
32 printf("empty string\n");
38 int main( int argc, char **argv ) {
39 // check usage
40 if ( argc != 2 ) {
41 printf("usage: %s file\n", argv[0]);
42 return -1;
45 char file[256];
46 strcpy( file, argv[1] );
47 FILE *fd;
49 // open a file in (default) text mode
50 printf("TEXT MODE (DEFAULT) by character\n\n");
51 fd = fopen( file, "r" );
52 if ( fd != NULL ) {
53 readchars( fd );
54 fclose(fd);
55 } else {
56 printf("Cannot open %s\n", file);
58 printf("\n");
60 // open a file in (explicit) text mode
61 printf("TEXT MODE (EXPLICIT) by character\n\n");
62 fd = fopen( file, "rt" );
63 if ( fd != NULL ) {
64 readchars( fd );
65 fclose(fd);
66 } else {
67 printf("Cannot open %s\n", file);
69 printf("\n");
71 // open a file in (explicit) binary mode
72 printf("BINARY MODE (EXPLICIT) by character\n\n");
73 fd = fopen( file, "rb" );
74 if ( fd != NULL ) {
75 readchars( fd );
76 fclose(fd);
77 } else {
78 printf("Cannot open %s\n", file);
80 printf("\n");
82 // open a file in (default) text mode
83 printf("TEXT MODE (DEFAULT) by line\n\n");
84 fd = fopen( file, "r" );
85 if ( fd != NULL ) {
86 readlines( fd );
87 fclose(fd);
88 } else {
89 printf("Cannot open %s\n", file);
91 printf("\n");
93 // open a file in (explicit) text mode
94 printf("TEXT MODE (EXPLICIT) by line\n\n");
95 fd = fopen( file, "rt" );
96 if ( fd != NULL ) {
97 readlines( fd );
98 fclose(fd);
99 } else {
100 printf("Cannot open %s\n", file);
102 printf("\n");
104 // open a file in (explicit) binary mode
105 printf("BINARY MODE (EXPLICIT) by line\n\n");
106 fd = fopen( file, "rb" );
107 if ( fd != NULL ) {
108 readlines( fd );
109 fclose(fd);
110 } else {
111 printf("Cannot open %s\n", file);
113 printf("\n");
115 return 0;