-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommand.cpp
97 lines (91 loc) · 2.85 KB
/
command.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h> // standard input / output functions
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h> // tolower()
#include "command.h"
//-----------------------------------------------------------------------------
int check_command_file(char *filename, int *rotInc)
//-----------------------------------------------------------------------------
// Return value n:
// n=0: no command file available
// n<0: file name is returned in filename
// n>0: internal GIF file #n
//
{
const struct GifFile {
const char *name;
const int rotinc;
const int rotval;
} gifFiles[] = {
{ "banana.jpg", 0, 10 },
{ "candle.jpg", 0, 10 },
{ "couple.jpg", 0, 10 },
{ "dog.jpg", 0, 10 },
{ "dog_and_smileys.jpg", 2, 10 },
{ "eye_smiley.jpg", 0, 10 },
{ "groupwave.jpg", 1, 10 },
{ "joke.jpg", 0, 10 },
{ "lawn_mower.jpg", 0, 10 },
{ "laughing_smiley.jpg", 0, 10 },
{ "massbounce.jpg", 1, 10 },
{ "pov.jpg", 0, 10 },
{ "pov_banana.jpg", 0, 10 },
{ "pov_candle.jpg", 0, 10 },
{ "smiley_sport.jpg", 0, 10 },
{ "tantrum.jpg", 0, 10 },
{ "text1.jpg", 1, 10 },
{ "text2.jpg", 1, 10 },
{ "text3.jpg", 1, 10 },
{ "text4.jpg", 1, 10 },
{ "text5.jpg", 1, 10 },
{ "tooth_smiley.jpg", 0, 10 },
{ "twilight.jpg", 0, 10 },
{ "wallbash.jpg", 0, 10 },
{ "xmas.jpg", 0, 10 },
{ "", 0, 0 }};
int i;
char tmp_filename[256];
FILE *fp = fopen(CCF_COMMANDFILE, "r");
if (fp==NULL) return CCF_ERROR;
i = fscanf(fp, "%s", tmp_filename);
if (i!=1) {
fclose(fp);
return CCF_ERROR;
}
// check for internal file name
for (i=0; i<25; i++)
{
if (strcmp(gifFiles[i].name, tmp_filename)==0)
{
*rotInc = gifFiles[i].rotinc;
fclose(fp);
unlink(CCF_COMMANDFILE);
return i;
}
}
fclose(fp);
unlink(CCF_COMMANDFILE);
// convert to linux file name
if (tmp_filename[1] != ':') return CCF_ERROR;
if (tmp_filename[2] != '\\') return CCF_ERROR;
sprintf(filename, "/cygdrive/%c/%s", tolower(tmp_filename[0]), tmp_filename+3);
for (i=0; filename[i]; i++) {
if (filename[i] == '\\') filename[i]='/';
}
return CCF_EXTERNAL_GIF;
}
#if 0
int main(void)
{
char filename[80];
filename[0]=0;
while (1)
{
int i=check_command_file(filename);
if (i!=ERROR) printf("\nFile: %s i=%d\n", filename, i);
//else printf(".");
}
return 0;
}
#endif