Don't allow the start date to be later than the end date. If it is, modify whichever...
[fpdb-dooglus.git] / packaging / windows / fpdb_folder_check.c
blobdba8d03dcdc474e2e6cfcdd10f4ae857bbc1ec90
1 /*
3 fpdb_folder_check.c
5 Copyright 2011 Gimick (bbtgaf@googlemail.com)
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Affero General Public License as published by
9 the Free Software Foundation, version 3 of the License.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU Affero General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 In the "official" distribution you can find the license in agpl-3.0.txt.
21 /*
22 To compile this function, install mingw then DOS>fpdb_folder_check.c -o fpdb_folder_check.exe
25 /*
26 Function needed because py2exe python apps crashes horribly if the application is
27 in a non-us-ascii folder. (this is actually a windows python problem with "import")
29 this function is not coded to cleanly handle codepage/locale/UTF.
30 The value of argv is not necessarily exactly what was passed....instead.....
31 We will make two checks instead (yes, it is a hack):
32 1 a char-by-char examination of the passed parameter to ensure 32 >= char <= 127
33 2 A call to access() to check for folder exists (This check catches most situations
34 with accented chars but will obviously NOT fail if an accented and non-accented
35 folder actually exists.
37 In summary, this function is a hack and not 100% reliable, but hopefully will be
38 good enough to identify problems for most first-time users.
41 #include <unistd.h>
42 #include <stdio.h>
43 #include <windows.h>
45 int main(int argc, char **argv)
47 int debugmode=1;
49 if (argc != 2) {
50 printf ("A helper function to examine a directory passed in the first argument\n");
51 printf ("Returns 0 if the directory exists, and contains only ascii characters 32 to 127\n");
52 printf ("Returns 1 in all other cases\n");
53 return 1;
56 if (debugmode) {
57 printf (argv[1],"\n");
58 printf ("\nLength: %d ", strlen(argv[1]));
59 printf ("\nMAX_PATH: %d ", MAX_PATH);
60 printf ("\n");
63 char *c = argv[1];
64 int i;
66 for(i=0; c[i]; i++) {
67 /* this loop finishes when c[i]<>true which is end of string (null \0) */
68 if (debugmode) {printf(" %d ", c[i]);}
69 if ((c[i] < 32)||(c[i] > 127)) {
70 if (debugmode) {printf ("\nInvalid ASCII");}
71 return 1;
73 if (i > MAX_PATH-1) {
74 if (debugmode) {printf ("\nMAX_PATH (%d chars) exceeded", MAX_PATH);}
75 return 1;
79 if (debugmode) {printf ("\nascii OK\n");}
81 if (access(argv[1], F_OK) != 0) {
82 if (debugmode) {printf ("\naccess() fail: Folder does not not exist");}
83 return 1;
86 if (debugmode) {printf ("\naccess() OK");}
87 return 0;