+/*!
+ * Check if the proposed file name conforms to the directory structure layed out
+ * as a file tree. It is used to check if the file name enumerated while scanning
+ * a directory content may have been created by sarg running with IndexTree set to
+ * INDEX_TREE_FILE.
+ */
+bool IsTreeFileDirName(const char *Name)
+{
+ char DateFormat;
+ int i;
+
+ // start year (date format u) or start day (date format e)
+ if (!isdigit(Name[0]) || !isdigit(Name[1])) return(false);
+
+ if (isdigit(Name[2]) && isdigit(Name[3]))
+ {
+ // date format is either u or w
+ if (Name[4]=='.')
+ {
+ // date format is w
+ if (!isdigit(Name[5]) || !isdigit(Name[6])) return(false);
+ return(true);//date format w is confirmed
+ }
+
+ // date format is u
+ Name+=4;
+
+ // start month
+ if (!isalpha(Name[0]) || !isalpha(Name[1]) || !isalpha(Name[2])) return(false);
+ for (i=11 ; i>=0 && memcmp(mtab1[i],Name,3) ; i--);
+ if (i<0) return(false);
+ Name+=3;
+
+ // start day
+ if (!isdigit(Name[0]) || !isdigit(Name[1])) return(false);
+ Name+=2;
+
+ DateFormat='u';
+ }
+ else if (isalpha(Name[2]) && isalpha(Name[3]) && isalpha(Name[4]))
+ {
+ // date format is e
+ Name+=2;
+
+ // start month
+ if (!isalpha(Name[0]) || !isalpha(Name[1]) || !isalpha(Name[2])) return(false);
+ for (i=11 ; i>=0 && memcmp(mtab1[i],Name,3) ; i--);
+ if (i<0) return(false);
+ Name+=3;
+
+ // start day
+ if (!isdigit(Name[0]) || !isdigit(Name[1]) || !isdigit(Name[2]) || !isdigit(Name[3])) return(false);
+ Name+=4;
+
+ DateFormat='e';
+ }
+ else
+ return(false);
+
+ if (Name[0]!='-') return(false);
+ Name++;
+
+ if (DateFormat=='u')
+ {
+ if (!isdigit(Name[0]) || !isdigit(Name[1]) || !isdigit(Name[2]) || !isdigit(Name[3])) return(false);
+ Name+=4;
+
+ if (!isalpha(Name[0]) || !isalpha(Name[1]) || !isalpha(Name[2])) return(false);
+ for (i=11 ; i>=0 && memcmp(mtab1[i],Name,3) ; i--);
+ if (i<0) return(false);
+ Name+=3;
+
+ if (!isdigit(Name[0]) || !isdigit(Name[1])) return(false);
+ Name+=2;
+ }
+ else //DateFormat=='e'
+ {
+ if (!isdigit(Name[0]) || !isdigit(Name[1])) return(false);
+ Name+=2;
+
+ if (!isalpha(Name[0]) || !isalpha(Name[1]) || !isalpha(Name[2])) return(false);
+ for (i=11 ; i>=0 && memcmp(mtab1[i],Name,3) ; i--);
+ if (i<0) return(false);
+ Name+=3;
+
+ if (!isdigit(Name[0]) || !isdigit(Name[1]) || !isdigit(Name[2]) || !isdigit(Name[3])) return(false);
+ Name+=4;
+ }
+ /*
+ * The directory name may contains additional characters such as a counter if
+ * a previous report is never overwritten.
+ */
+ return(true);
+}
+
+/*!
+ * Check if the proposed file name can be the year part of a report tree build with
+ * IndexTree set to INDEX_TREE_DATE.
+ */
+bool IsTreeYearFileName(const char *Name)
+{
+ if (!isdigit(Name[0]) || !isdigit(Name[1]) || !isdigit(Name[2]) || !isdigit(Name[3])) return(false);
+ Name+=4;
+ if (Name[0]=='-')
+ {
+ Name++;
+ if (!isdigit(Name[0]) || !isdigit(Name[1]) || !isdigit(Name[2]) || !isdigit(Name[3])) return(false);
+ Name+=4;
+ }
+ if (Name[0]) return(false);
+ return(true);
+}
+
+/*!
+ * Check if the proposed file name can be the month part of a report tree build with
+ * IndexTree set to INDEX_TREE_DATE.
+ */
+bool IsTreeMonthFileName(const char *Name)
+{
+ int m;
+
+ if (!isdigit(Name[0]) || !isdigit(Name[1])) return(false);
+ m=(Name[0]-'0')*10+(Name[1]-'0');
+ if (m<1 || m>12) return(false);
+ Name+=2;
+ if (Name[0]=='-')
+ {
+ Name++;
+ if (!isdigit(Name[0]) || !isdigit(Name[1])) return(false);
+ m=(Name[0]-'0')*10+(Name[1]-'0');
+ if (m<1 || m>12) return(false);
+ Name+=2;
+ }
+ if (Name[0]) return(false);
+ return(true);
+}
+
+/*!
+ * Check if the proposed file name can be the day part of a report tree build with
+ * IndexTree set to INDEX_TREE_DATE.
+ */
+bool IsTreeDayFileName(const char *Name)
+{
+ int d;
+
+ if (!isdigit(Name[0]) || !isdigit(Name[1])) return(false);
+ d=(Name[0]-'0')*10+(Name[1]-'0');
+ if (d<1 || d>31) return(false);
+ if (Name[2]=='-')
+ {
+ Name+=3;
+ if (!isdigit(Name[0]) || !isdigit(Name[1])) return(false);
+ d=(Name[0]-'0')*10+(Name[1]-'0');
+ if (d<1 || d>31) return(false);
+ }
+ /*
+ * The directory name may contains additional characters such as a counter if
+ * a previous report is never overwritten.
+ */
+ return(true);
+}
+
+/*!
+ * Create a directory to generate a report for the specified connection data
+ * and populate it with the a <tt>sarg-date</tt> file containing the current
+ * date.
+ *
+ * The function also create an <tt>images</tt> directory in \a dir and copy all
+ * the files from the <tt>SYSCONFDIR/images</tt> into that directory.
+ *
+ * \param per1 The date range in the form: YYYYMMMDD-YYYYMMMDD or DDMMMYYYY-DDMMMYYYY depending on the value of
+ * ::DateFormat.
+ * \param addr The ip address or host name to which the report is limited. If the string is empty, all the addresses are accepted.
+ * \param site The destination site to which the report is limited. If the string is empty, all the sites are accepted.
+ * \param us The user to whom the report is limited. It is an empty string if all the users are accepted.
+ */
+int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us)