/* * Concordance Programming Language * * Date Validation program. * * Dataflight Software, Inc. * 2337 Roscomare Road, Suite 11 * Los Angeles, CA 90077 * * 28-Apr-1999 * * Copyright (c) 1999 Dataflight Software, Inc. * ALL RIGHTS RESERVED. * Unauthorized distribution, adaptation or use may be * subject to civil and criminal penalties. * */ main() { int db, i, j, errors; char string[256]; text szText; szText = "This program checks every date field in every document in the current query "+ "for valid dates."+newline()+ newline()+ "It will not check dates with all zeros for either the year, "+ "the month, or the day. It will only check field where it has read access." +newline() + newline()+ 'Any invalid dates, such as February 30th, are tagged with the phrase "Invalid date in FIELD"'; if (messageBox(szText, "Date Validation", MB_OKCANCEL | MB_ICONINFORMATION) == IDOK) { cls(RGB(192, 192, 192)); cycle(db) { Message("Date validation "+trim(str(docno(db),10,0,','))+ " of "+trim( str( count(db), 10, 0, ',')), FALSE); for(i = 1; i <= db.fields; i = i + 1) { if ((db.type[i] == 'D') and (db.access[i] & 1)) { /* Check the date field for valid dates. */ /* Copy it to a string first, eight bytes. */ memcpy(string, db->i, 8); /* Don't bother checking totally empty date fields. */ if (string[0]) { /* Don't bother checking if the year is all zeros. */ if ((string[0] <> '0') or (string[1] <> '0') or (string[2] <> '0') or (string[3] <> '0')) { /* Don't bother checking if the month is all zeros. */ if ((string[4] <> '0') or (string[5] <> '0')) { /* Don't bother checking if the day is all zeros. */ if ((string[6] <> '0') or (string[7] <> '0')) { /* Copy the fixed field date, in YYYYMMDD format, to a string. */ /* Compare the numeric contents of the date to the text date we */ /* just copied. If date math changed the date, the it is invalid. */ szText = substr(string, 1, 4)+"/"+substr(string, 5, 2)+"/"+substr(string, 7, 2); if (szText <> dtoc(j = db->i,'Y')) { /* Tag the document with the field name and a bad date message. */ tag(db, 1, 'Invalid date in "'+db.name[i]+chr('"')); puts(0,0,"Date errors tagged: "+ trim(str(errors = errors + 1,10,0,',')), RGB(0,0,0), RGB(192, 192, 192)); } } } } } } } } /* Display an error or success message. */ if (errors) messageBox("There were "+trim(str(errors, 25, 0, ',')) + "invalid dates detected and tagged.", "Date Validation", MB_OK); else messageBox("All dates checked were valid.", "Date Validation", MB_OK); } } /* main() */ RGB(char red, grn, blu) { return(((blu & 255) * 65536) | ((grn & 255) * 256) | (red & 255)); } /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message; int wait) { text screen; int key; int fg, bk, tr, tc; if (wait) { eval('messageBox(message, "Concordance", 0);', key); if (key == 0) return; } tr = 8; tc = 13; bk = RGB(255,0,255); fg = RGB(160,0,160); cursoroff(); if (wait) screen = save(tr, tc, tr + 3, tc + 56); box(tr , tc , tr + 2, tc + 54,"3U", fg, bk); puts(tr + 1,tc + 1,pad(message,'C',53), RGB(255,255,255),bk); if (wait) { while(keypress()) getkey(); key = getkey(); restore(tr,tc,screen); } return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * Name: FileName * * Synopsis: Trims the path from the file name. * ****************************************************************/ FileName(text name) { int i; while(i = match(name,"\",1)) name = substr(name,i+1); return(name); } /* FileName() */ /**************************************************************** * Global Variable Declarations and Initialization * ****************************************************************/ /* findfirst() file attributes. _A_NORMAL 00 Normal file - No read/write restrictions _A_RDONLY 01 Read only file _A_HIDDEN 02 Hidden file _A_SYSTEM 04 System file _A_VOLID 08 Volume ID file _A_SUBDIR 16 Subdirectory _A_ARCH 32 Archive file edit() mode attributes. A // Alpha only mode. U // Upper case conversion. N // Numeric only mode. Y // Y mode for dates. M // M mode for dates. D // D mode for dates. C // Cut and paste mode. S // Scroll field left and right, no wordwrapping. E // Return on [Enter], no CR in data. T // Always edit from the top. B // Always edit from the bottom. @ // Display only this field. ! // Return when this field is entered, don't edit. N:99.99 */ int CTRLPGUP = 33792, F11 = 34048, F12 = 34304, EOF = -1; short LEFT = 19200, RIGHT = 19712, UP = 18432, DOWN = 20480, HOME = 18176, END = 20224, PGUP = 18688, PGDN = 20736, CTRLPGDN = 30208, F1 = 15104, F2 = 15360, F3 = 15616, F4 = 15872, F5 = 16128, F6 = 16384, F7 = 16640, F8 = 16896, F9 = 17152, F10 = 17408; char ESC = 27, CTRLP = 16, FALSE = 0, TRUE = 1, TAB = 9, CR = 13, LF = 10; /* Standard dialog button return values. */ int IDOK = 1; int IDCANCEL = 2; int IDABORT = 3; int IDRETRY = 4; int IDIGNORE = 5; int IDYES = 6; int IDNO = 7; /* MessageBox() display options. */ int MB_OK = 0; int MB_OKCANCEL = 1; int MB_ABORTRETRYIGNORE = 2; int MB_YESNOCANCEL = 3; int MB_YESNO = 4; int MB_RETRYCANCEL = 5; int MB_ICONHAND = 16; int MB_ICONQUESTION = 32; int MB_ICONEXCLAMATION = 48; int MB_ICONASTERISK = 64; int MB_ICONINFORMATION = MB_ICONASTERISK; int MB_ICONSTOP = MB_ICONHAND; int MB_DEFBUTTON1 = 0; int MB_DEFBUTTON2 = 256; int MB_DEFBUTTON3 = 512; int MB_APPLMODAL = 0; int MB_SYSTEMMODAL = 4096; int MB_TASKMODAL = 8192; int MB_NOFOCUS = 32768; /**********************************************************/ /* The first byte of every entry in the database.TRK file */ /* indicates the type of log entry and the type of event. */ /**********************************************************/ int LOGDELETION = 'D'; int LOGDELETION_OLD = 1 ; int LOGFIELDEDITED = 2 ; int LOGTAGADDED = 4 ; int LOGTAGDELETED = 8 ; int LOGEVENTSDELETED = 'P'; int LOGREINDEX = 'R'; int LOGSECURITYDELETION = 'S';