Debian Codegraph @

biosig4c++/igor/tn003/TestWave.c

raw symbols SCIP
1
2 #include <ctype.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <stddef.h>
7
8 extern int DoReadTest(const char* filePath);
9 extern int DoWriteTest(const char* filePath);
10
11 static int
12 GetNextCommand(char* filePath)
13 {
14 char input[1024];
15 int command;
16 int i;
17
18 *filePath = 0;
19
20 while(1) {
21 printf("Command: ");
22 if (fgets(input, sizeof(input)-1, stdin) != NULL) {
23 char* p = strchr(input, '\n'); // Find new line character.
24 if (p != NULL)
25 *p = 0; // Remove new line character.
26 for(i=0; i<5; i++)
27 input[i] = toupper(input[i]); // Convert command to upper case.
28 if (strncmp(input, "READ ", 5) == 0) {
29 command = 1;
30 strcpy(filePath, input+5);
31 break;
32 }
33 if (strncmp(input, "WRITE ", 6) == 0) {
34 command = 2;
35 strcpy(filePath, input+6);
36 break;
37 }
38 if (strncmp(input, "QUIT", 4) == 0) {
39 command = 3;
40 break;
41 }
42 }
43 printf("\n\n");
44 }
45
46 return command;
47 }
48
49 int
50 main(void)
51 {
52 int command;
53 char filePath[1024];
54 char fullPathSample[32];
55 char partialPathSample[32];
56 int err;
57
58 #ifdef WIN32
59 strcpy(fullPathSample, "C:\\FolderA\\MyWave.ibw");
60 strcpy(partialPathSample, "..\\SamplesWin\\version2.ibw");
61 #else
62 strcpy(fullPathSample, "hd:FolderA:MyWave.ibw");
63 strcpy(partialPathSample, "::SamplesMac:version2.ibw");
64 #endif
65
66 printf("This program illustrates reading and writing Igor binary wave files.\n\n");
67 printf("To read a file, enter the following: Read <file path>\n\n");
68 printf("To write a file, enter the following: Write <file path>\n\n");
69 printf("<file path> can be either a full path (%s)\n", fullPathSample);
70 printf("or a partial path relative to the folder containing this program (%s)\n", partialPathSample);
71 printf("\n");
72 printf("Here are some sample commands:\n");
73 #ifdef WIN32
74 printf(" Read ..\\SamplesMac\\version2.ibw\n");
75 printf(" Read ..\\SamplesWin\\version5.ibw\n");
76 printf(" Write TestWave.ibw\n");
77 #else
78 printf(" Read ::SamplesMac:version2.ibw\n");
79 printf(" Read ::SamplesWin:version5.ibw\n");
80 printf(" Write TestWave.ibw\n");
81 #endif
82
83 #ifdef WIN32
84 printf("To quit the program, type Quit\n");
85 #else
86 printf("To quit the program, choose Quit from the file menu.\n");
87 #endif
88
89 while(1) {
90 printf("\n");
91 command = GetNextCommand(filePath);
92 if (command == 1)
93 err = DoReadTest(filePath);
94 if (command == 2)
95 err = DoWriteTest(filePath);
96 if (command == 3) {
97 #ifndef WIN32
98 printf("Now you must choose Quit from the File menu to quit.\n");
99 #endif
100 break;
101 }
102 }
103
104 return 0;
105 }
106