Debian Codegraph @

biosig4c++/igor/ptn003/PackedFileDemo.c

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