/* * Concordance Programming Language * * Copyright (c) 2000 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) 1994 YOUR NAME. ALL RIGHTS RESERVED. * Portions copyright (c) 1994 Dataflight Software, Inc. */ text namearray[102]; int db; int CR = 13; int ESC = 27; int EOF = -1; /******************************************************** * Name: Field sort program * Synopsis: Sorts field entries ********************************************************/ main() { char string[125], fname[12], szTempFile[128]; text screen; text newlist; int i, a, f, fieldLength, offset, length, error, lines, btree; cls(); /* open a database if one isn't open. */ if( db.fields <= 0 ) { if( getfile('Database',"*.DCB",string) == CR ) { closedb( db ); first( db = opendb( string )); } } /* Return if the database isn't open. */ if( db.fields <= 0 ) return; InitMenu(); /* Avoid ending the loop with a function key. */ cls(); i = db.fields + 2; while( i > db.fields+1 ) i = menu( 2,22,20,47,namearray,a ); if( i == 0 ) return; fname = db.name[i]; cls(); szTempFile = mkuniq(".\", ".TMP"); cycle( db ) { fieldLength = len(db->fname); erase(szTempFile); if (exist(szTempFile)) return(messageBox("Couldn't erase temporary file "+szTempFile, program(), MB_OK)); if ((btree = btcreate(szTempFile, 0)) < 0) return(messageBox("Couldn't create temporary file "+szTempFile, program(), MB_OK)); wrap(db->fname, sizeof(string) - 2); offset = match(db->fname, ";", f = 1); puts( 2, 1, "Alphabetizing..." ); puts( 4, 1, "Document: "+str(docno(db))+" of "+str(count(db)) ); while ((offset > 0) and (f < fieldLength)) { string = trim(substr( db->fname, f, offset - f)); if (btinsert( btree, string, 0 ) == -2) tag(db, TRUE, "Duplicate name in field "+fname); if ((offset = match(db->fname, ";", f = offset + 1)) == 0) offset = fieldLength + 1; } btclose( btree ); if (erase(szTempFile)) return(Message("Error erasing file: "+szTempFile, TRUE)); if( keypress() ) if( getkey() == ESC ) break; } /* cycle */ } /** main() **/ /**************************************************************** * Name: Normalize * * Synopsis: Remove underscores and capitalize field names. * * Return: Name of a field. * ****************************************************************/ normalize(text name) { char string[20]; int a, LastChar; string = name; for(a = 1; string[a]; a = a + 1) { if(string[a] == '_') string[a] = ' '; else if (LastChar <> ' ') string[a] = lower(string[a]); LastChar = string[a]; } return(string); } /** Normalize() **/ /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message; int pause) { text screen; int key; cursoroff(); screen = save(5,13,8,69); box(5,13,8,69,"3D", MenuColor_); puts(6,14,pad(message,'C',53),MenuColor_); if (pause) { key = getkey(); restore(5,13,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() */ /**************************************************************** * Name: mkuniq * * Synopsis: Creates a unique file name. * ****************************************************************/ mkuniq(text dosPath, ext) { char string[128]; int i; for(i = 0; i < 10000; i = i + 1) if (exist(string = dosPath + str(i) + ext) == 0) break; return(string); } /* mkuniq() */ /**************************************************************** * Name: Path * * Synopsis: Returns the path up to the last \ and without * * the file's name. * ****************************************************************/ Path(text dosPath) { int i, j; if ((i = match(dosPath,":",1)) == 0) i = match(dosPath,"\",1); while(j = match(dosPath,"\",i+1)) i = j; return(substr(dosPath,1,i)); } /* Path() */ /**************************************************************** * Name: InitMenu * * Synopsis: Initialize the field selection menu. * ****************************************************************/ InitMenu() { int i; for(i = 1; i <= db.fields; i = i +1) switch(db.type[i]) { case 'T' : namearray[i] = pad(normalize(db.name[i]),'L',13)+ "Text "; case 'P' : namearray[i] = pad(normalize(db.name[i]),'L',13)+ "Full Text"; case 'N' : namearray[i] = pad(normalize(db.name[i]),'L',13)+ "Numeric "; case 'D' : namearray[i] = pad(normalize(db.name[i]),'L',13)+ "Date "; } /* Clear out the last menu item and set the menu title. */ namearray[i] = ""; namearray[0] = "Field Type "; } /** InitMenu() **/