/* * Concordance Programming Language Text Date Conversion Program * * Copyright (c) 1993 Dataflight Software, Inc. * ALL RIGHTS RESERVED. * 2337 Roscomare Road, Suite 11 * Los Angeles, CA 90077 * * Unauthorized distribution, adaptation or use may be * subject to civil and criminal penalties. * * You may incorporate this program into your own programs * ONLY if you incorporate the following copyright notice: * * Copyright (c) 1993 YOUR NAME. ALL RIGHTS RESERVED. * Portions copyright (c) 1993 Dataflight Software, Inc. * * Re: Converting date in text field to a date field. * This program preserves "illegal" dates, i.e., * 12/00/92 or 00/00/00. All dates are assumed to * be in MM/DD/YY format. */ main() { int db, i, month, day, year; int source, destination; char string[50]; opendb("C:\language\data\legal"); cls(); Status(db); if (db.documents < 0) return(Message("Please open a database first.")); puts(0,10,string = "Specify field with date as TEXT string",MenuColor_ | 128); sleep(2000); puts(0,10,string,MenuColor_); if ((source = GetField(db, 1)) <= 0) return; Status(db); if ((db.type[source] <> 'P') and (db.type[source] <> 'T')) return(Message("I need a Text or Paragraph for the source.")); puts(0,10,string = "Specify destination DATE field",MenuColor_ | 128); sleep(2000); puts(0,10,string,MenuColor_); if ((destination = GetField(db, source)) <= 0) return; Status(db); if (db.type[destination] <> 'D') return(Message("I need a Date field for the destination!")); if (source == destination) return(Message("Can't use the same field for both!")); if (Message("Copy text "+db.name[source]+" to date field "+db.name[destination]+" Y/N?") == 'Y') { cycle(db) { if (keypress()) { if (getkey() == ESC) if (Message("Cancel processing Y/N?") == 'Y') break; } /* Isolate each component of the date: month, day and year. */ day = month = year = 0; string = db->source; month = num(string); if (i = match(string,"/",1)) { string = substr(string,i+1); day = num(string); if (i = match(string,"/",1)) { string = substr(string,i+1); if (year = num(string)) if (year < 1900) year = year + 1900; } } /* Create a date string formatted for a Concordance date field. */ /* Copy it to the date field using memcpy() to avoid type conversion. */ string = str(year,4,0,'z')+str(month,2,0,'z')+str(day,2,0,'z'); memcpy(db->destination,string,8); puts(0,10,"Document "+str(docno(db),10,0,','),MenuColor_); } } } /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message) { text screen; int key; cursoroff(); screen = save(5,13,8,69); box(5,13,8,69, "DD", MenuColor_); puts(6,14,pad(message,'C',53),MenuColor_); key = getkey(); restore(5,13,screen); return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * Name: GetField * * Synopsis: Prompt user for field name. * ****************************************************************/ GetField(int db, next) { int i, n; text field[101]; text screen; screen = save(5,25,21,52); field[0] = "Field Type "; for(i = 1; i <= db.fields; i = i +1) switch(db.type[i]) { case 'T' : field[i] = pad(db.name[i],'L',13)+ "Text "; break; case 'P' : field[i] = pad(db.name[i],'L',13)+ "Paragraph"; break; case 'N' : field[i] = pad(db.name[i],'L',13)+ "Numeric "; break; case 'D' : field[i] = pad(db.name[i],'L',13)+ "Date "; break; } i = db.fields + 1; while(i > db.fields) i = menu(5, 25, 21, 52, field, next,""); restore(5,25,screen); return(i); } /* GetField() */ /**************************************************************** * Summary: status * * Synopsis: Initializes the first two line on the screen. * ****************************************************************/ Status(int db) { puts(0,0,rep(' ',80),MenuColor_); puts(1,0,rep('Í',80),MenuColor_); puts(0,8,"³",MenuColor_); puts(1,8,"Ï",MenuColor_); if (db.documents >= 0) puts(0,0,FileName(db.database),MenuColor_); } /* Status() */ /**************************************************************** * Name: FileName * * Synopsis: Trims the path from the file name. * ****************************************************************/ FileName(text name) { int i; if (i = match(name,":",1)) name = substr(name,i+1); 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, CR = 13, LF = 10;