/**************************************************************** * Name: export * * Synopsis: Prints the current query to file. * * Description: The export program, which starts with the * * main() function, will copy a data base to * * file in a format compatible with the convert * * utility. This enables you to export a data * * to ASCII format, edit it with your favorite * * word processing program, and load it back into * * Concordance. With some minor modification this * * program could be used to export Concordance * * files to STAIRS and other data base formats. * ****************************************************************/ /* Global variable are always declared */ /* outside of any function definitions. */ int gray; main() { int key, i, db, file; int document, DiskFull; text delimiter, AMenu[9]; char string[80]; /* Initialize screen and global variables, */ /* then get data base name and open it. */ gray = RGB(200, 200, 200); file = EOF; AMenu[0] = " Description of the Export.cpl Program" + newline() + newline() + "This program prints documents from a database search to a plain text file."+newline()+ "The format is compatible with the Convert.exe program described in the manual." + newline() + "This allows you to export the database to a word processor or other program" + newline() + "and bring it back into Concordance later."; /* Display the program discription in a menu box */ /* and exit if the user presses the [Esc] key */ key = messageBox(AMenu[0], program(), MB_OKCANCEL | MB_ICONINFORMATION); if (key == IDCANCEL) /* The user wishes to exit. */ return(0); if (db.documents < 0) { while((key <> CR) and (key <> ESC)) key = getfile("Export Database","*.dcb",string); if (key == ESC) return(0); else if ((db = opendb(string)) == EOF) return(messageBox("Couldn't find "+string, program(), MB_OK | MB_ICONEXCLAMATION)); } /* Database was successfully opened. Now get */ /* the name of the output file and open it. */ key = 0; string[0] = 0; while((key <> CR) and (key <> ESC)) { key = getfile("Output File","*.txt",string); if (key == CR) { if (exist(string)) { key = messageBox(string + " already exists." + newline() + newline() + "Replace it with new data?", program(), MB_ICONQUESTION | MB_YESNO); if (key == IDYES) key = CR; } } } if (key == ESC) return; if ((file = open(string,"w+")) == EOF) { return(messageBox("Couldn't open "+string, program(), MB_OK | MB_ICONEXCLAMATION)); } /* Enter the processing loop, read through the data base */ /* until the end of the file, or user hits the ESC key. */ document = 1; key = 0; DiskFull = 0; cycle( db ) { if(( key == ESC) or (DiskFull <> 0)) break; Message("Document: "+ trim(str(document,15,0,',')) + " of " + trim(str(count(db), 15, 0, ',')),0); /* Print a document delimiter for this record. */ delimiter = "*** "+str(document,7,0,'Z'); if (writeln(file,delimiter,i = len(delimiter)) < i) DiskFull = 1; /* Loop through each field in the data base. */ i = 1; while((i <= db.fields) and (key <> ESC) and (DiskFull == 0)) { if (db.access[i] & 1) DiskFull = printfield(db,i,file); i = i + 1; if (keypress()) key = getkey(); } document = document + 1; } close(file); if (DiskFull) { /* The disk became full while copying the data base. */ /* Give an error message and erase the output file. */ beep(0,0); messageBox("A disk full error was encountered. There wasn't enough room to save the file.", program(), MB_ICONEXCLAMATION | MB_OK); erase(string); } } /* main() */ /**************************************************************** * Name: printfield * * Synopsis: print a field to file, each field type is * * handled separately. The data base "ftype" * * variable tells which type of field it is. * * Process text and paragraph fields line by line. * * Ignore empty fields, only process fields with * * data. Start by printing the field's name * * followed by a colon and a space, then print the * * rest of the field. * ****************************************************************/ printfield(int db, field, file) { int offset, length, i, DiskFull; text line, szField; char string[120]; DiskFull = 0; switch(db.type[field]) { case 'P': case 'T': /* Handle fixed length Text and free text Paragraph fields here. */ if (len(db->field)) { szField = db->field; line = db.name[field]+": "; if (write(file,line,i = len(line)) < i) DiskFull = 1; offset = findline(szField ,1,length); /* This while loop prints the contents */ /* of a fixed length or free text field. */ while((offset) and (DiskFull == 0)) { if (writeln(file,addr(szField ,offset),length) < length) DiskFull = 1; offset = findnline(szField ,offset,length); } } case 'D': /* Handle date fields here. */ line = db.name[field]+": "+dtoc(db->field); if (writeln(file,line,i = len(line)) < i) DiskFull = 1; case 'N': /* Handle numeric fields here. */ line = db.name[field]+": "+str(db->field,35,5); if (writeln(file,line,i = len(line)) < i) DiskFull = 1; } return(DiskFull); } /* printfield() */ 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; cursoroff(); if (wait) screen = save(5,13,8,69); box(5,13,8,69, "3D", 0, gray); puts(6,14,pad(message,'C',53), 0, gray); if (wait) { key = getkey(); restore(5,13,screen); } return(asc(upper(chr(key)))); } /* Message() */