home *** CD-ROM | disk | FTP | other *** search
-
- #define _ENTRY_
-
- #ifdef __TURBOC__
- #include <conio.h>
- #else
- #include <graph.h>
- #endif
- #include <io.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "db_lsc.h"
- #include "db_types.h"
- #include "db_conio.h"
- #include "db_dos.h"
- #include "db_file.h"
- #include "extfhc.h"
- #include "db_heap.h"
- #include "db_gvar.h"
- #include "db_key.h"
- #include "db_pswd.h"
- #include "db_sets.h"
- #include "db_str.h"
- #include "db_funcs.h"
- #include "db_date.h"
- #include "db_tree.h"
- ⁿUSESⁿ
-
- typedef uchar str12[13];
- typedef long recnotyp[16+1]; /* Zeroth element not used */
-
- unsigned _stklen = 0x4000; /* Default stack of 16 K */
-
- string _tts, _tranString; /* _tranString for internal generator use only */
-
- /********************************* TYPES **********************************/
-
- #define maxfilno ⁿmaxfilnoⁿ
- #define maxkeyno ⁿmaxkeynoⁿ
-
- str12 dbnames[maxfilno+1][maxkeyno+1] = /* [1.. ,0.. ] */
- ⁿdbnamesⁿ;
- byte keymode[maxfilno+1][maxkeyno+1] = /* [1.. ,1.. ] */
- ⁿkeymodeⁿ;
- byte keylen[maxfilno+1][maxkeyno+1] = /* [1.. ,1.. ] */
- ⁿkeylenⁿ;
- bool filinuse[maxfilno+1] =
- ⁿfilinuseⁿ;
-
- bool menudriven = ⁿmenudrivenⁿ;
-
- /******************************* VARIABLES ********************************/
-
- bool fok;
- int filno, dbsize[maxfilno+1];
- datafile *datf[maxfilno+1];
- indexfile *idxkey[maxfilno+1][maxkeyno+1];
- recnotyp recno;
-
- uchar autoMode; /* what is the program being asked to do */
- string textFileName; /* read/write information from/to this file */
- int searchByKey; /* if "getting" which key to search by */
- keystr searchFor; /* locate the record by looking for this */
-
- ⁿRECMODⁿ
-
- ⁿFUNCMODⁿ
-
- strptr makekey(strptr sout, int fno, int kno)
- {
- string ks, ts;
-
- ks[0] = '\0';
-
- ⁿmakekeyⁿ
-
- strcpy(sout,ks);
- return(sout);
- }
-
- strptr keyexpr(strptr sout, int fno, int kno, string kvar)
- {
- string ts, ks;
- byte tlen;
-
- strcpy(ks,kvar);
- tlen = strlen(ks);
-
- ⁿkeyexprⁿ
-
- ks[tlen] = Nul;
- strcpy(sout,ks);
- return(sout);
- }
-
- strptr getakey(strptr sout, int fno, int kno)
- {
- string tsout;
-
- keyexpr(sout,fno,kno,makekey(tsout,fno,kno));
- return(sout);
- }
-
- void simpleGetRec(int fno)
- /*
- Read a record from file "fno" into the record buffer for that file. The
- record to read is determined by the value stored in the "recno[fno]", which
- is a global variable.
- */
- {
- switch (fno) {
- ⁿgetrecⁿ
- }
- }
-
- void simpleAddRec(int filno)
- /*
- Add a record to file "filno".
-
- Note that is function does not do any error checking when adding to the
- index file. If a key that does not allow duplicates has an attempt to
- add a duplicate key, (OK == False after "addkey()"), then not attempt
- to correct the situation is made.
- */
- {
- int keyno;
- keystr ks;
-
- switch (filno) {
- ⁿADDRECⁿ
- }
- for (keyno=1; keyno<=maxkeyno; keyno++) {
- if (keylen[filno,keyno] > 0) {
- getakey(ks,filno,keyno);
- addkey(idxkey[filno][keyno],&recno[filno],ks);
- }
- }
- }
-
- void openfiles(void)
- {
- int i, j, fo_i, fo_j;
- string prepend;
- int tlen;
- string ts;
-
- fo_i = fo_j = 0;
-
- ⁿSIZESⁿ;
-
- strip(prepend,""); /*MOD*/ /* Can only open file in current directory. */
- tlen = strlen(prepend);
- if ((tlen > 0) && (prepend[tlen-1] != '\\')) {
- prepend[tlen] = '\\';
- prepend[tlen+1] = '\0';
- }
-
- fok = True;
- for (i=1;i <= maxfilno; i++)
- if (fok) {
- datf[i] = db_malloc(sizeof(datafile));
- strconcat(ts,prepend,dbnames[i][0],NULL);
- openfile(datf[i],ts,dbsize[i]);
- fok = (bool)(fok && ok);
- if (fok) {
- fo_i = i;
- fo_j = 0;
- for (j=1; j <= maxkeyno; j++)
- if (fok && (keylen[i][j] > 0)) {
- idxkey[i][j] = db_malloc(sizeof(indexfile));
- strconcat(ts,prepend,dbnames[i][j],NULL);
- openindex(idxkey[i][j],ts,keylen[i][j],keymode[i][j]);
- fok = (bool)(fok && ok);
- if (fok) fo_j = j;
- }
- }
- else if (filinuse[i]) {
- strconcat(ts,prepend,dbnames[i][0],NULL);
- makefile(datf[i],ts,dbsize[i]);
- fok = ok;
- if (fok) {
-
- ⁿIFDEF MUSERⁿ
- closefile(datf[i]);
- strconcat(ts,prepend,dbnames[i][0],NULL);
- openfile(datf[i],ts,dbsize[i]);
- ⁿENDDEFⁿ
-
- fo_i = i; fo_j = 0;
- for (j=1; j <= maxkeyno; j++)
- if (fok && (keylen[i][j] > 0)) {
- idxkey[i][j] = db_malloc(sizeof(indexfile));
- strconcat(ts,prepend,dbnames[i][j],NULL);
- makeindex(idxkey[i][j],ts,keylen[i][j],keymode[i][j]);
- fok = (bool)(fok && ok);
- if (fok) {
-
- ⁿIFDEF MUSERⁿ
- closeindex(idxkey[i][j]);
- strconcat(ts,prepend,dbnames[i][j],NULL);
- openindex(idxkey[i][j],ts,keylen[i][j],keymode[i][j]);
- fo_j = j;
- ⁿELSEDEFⁿ
- fo_j = j;
- ⁿENDDEFⁿ
-
- }
- }
- }
- }
- }
- if (!fok)
- for (i=1; i <= maxfilno; i++)
- if (i <= fo_i) {
- closefile(datf[i]);
- db_free(datf[i]);
- for (j=1; j <= maxkeyno; j++)
- if ((i < fo_i) || (j <= fo_j))
- if (keylen[i][j] > 0) {
- closeindex(idxkey[i][j]);
- db_free(idxkey[i][j]);
- }
- }
- }
-
- void closefiles(void)
- {
- int i,j;
-
- for (i=1; i <= maxfilno; i++) {
- closefile(datf[i]); db_free(datf[i]);
- for (j=1; j <= maxkeyno; j++) if (keylen[i][j] > 0) {
- closeindex(idxkey[i][j]);
- db_free(idxkey[i][j]);
- }
- }
- }
-
- void initialize(void)
- {
- for (filno = 1; filno <= maxfilno; filno++) {
- recno[filno] = 0;
- }
- filno = 1;
- searchByKey = 1;
- autoMode = ' ';
- strcpy(textFileName,"TEST.TXT");
- }
-
- void on_error(void)
- {
- closefiles();
- }
-
- void lookforparameters(void)
- {
- int i;
- string ts;
-
- for (i = 1; i < paramcount(); i++) {
- strcpy(ts,paramstr(i));
- if ((*ts == '-') || (*ts == '/')) {
- strdelete(ts,0,1);
-
- if (ts[0] == 'I') autoMode = 'I'; /* Import a new record */
-
- if (ts[0] == 'E') autoMode = 'E'; /* Export a record */
-
- if (ts[0] == 'D') { /* Change the name of the text file */
- strdelete(ts,0,1); /* Remove the "D" */
- strcpy(textFileName,ts); /* store the text file name */
- }
-
- if (ts[0] == 'F') { /* Change the file number */
- strdelete(ts,0,1); /* Remove the "F" */
- filno = ival(ts); /* store the new file number to read/write */
- }
-
- if (ts[0] == 'S') { /* Search by key number */
- strdelete(ts,0,1); /* Remove the "S" */
- searchByKey = ival(ts);/* store the number of the key to search by */
- }
-
- if (ts[0] == 'L') { /* Locate using string */
- strdelete(ts,0,1); /* Remove the "L" */
- strcpy(searchFor,ts); /* store the string to search for */
- }
-
- }
- }
- }
-
- void inputRecord(void)
- {
- FILE *textFile;
- string ts;
-
- textFile = fopen(textFileName,"rt");
- if (textFile != NULL) {
-
- fgets(ts,256,textFile); /* read in a string */
- ts[strlen(ts)-1] = '\0'; /* remove the "newline" character */
- pad(ts,ts,8,Right); /* pad it to match the input picture */
- strcopy(SIMPLE1.TRAN_DATE,ts,0,8); /* move data to the field */
-
- fgets(ts,256,textFile); /* read in a string */
- ts[strlen(ts)-1] = '\0'; /* remove the "newline" character */
- pad(ts,ts,10,Right); /* pad it to match the input picture */
- strcopy(SIMPLE1.TRAN_ITEM,ts,0,10); /* move data to the field */
-
- fgets(ts,256,textFile); /* read in a string */
- ts[strlen(ts)-1] = '\0'; /* remove the "newline" character */
- pad(ts,ts,40,Right); /* pad it to match the input picture */
- strcopy(SIMPLE1.TRAN_COMMENT,ts,0,40); /* move data to the field */
-
- fclose(textFile);
-
- SIMPLE1.recstat = 0; /* record status flag set to "in use" */
- simpleAddRec(filno);
- }
- }
-
- void outputRecord(void)
- {
- FILE *textFile;
-
- /* find first record with a key >= "searchFor" and print it */
- searchkey(idxkey[filno][searchByKey],&recno[filno],searchFor);
- if (ok) {
- simpleGetRec(filno);
-
- textFile = fopen(textFileName,"w+t");
- if (textFile != NULL) {
- fprintf(textFile,"%s\n",SIMPLE1.TRAN_DATE);
- fprintf(textFile,"%s\n",SIMPLE1.TRAN_ITEM);
- fprintf(textFile,"%s\n",SIMPLE1.TRAN_COMMENT);
- fclose(textFile);
- }
- }
- }
-
- void do_something(void)
- {
- lookforparameters();
- if ((filno >= 1) &&
- (filno <= maxfilno) &&
- (searchByKey >= 1) &&
- (searchByKey <= maxkeyno) &&
- (keylen[filno][searchByKey] != 0)) {
- switch (autoMode) {
- case 'I' : inputRecord(); break;
- case 'E' : outputRecord(); break;
- } /* end switch */
- }
- }
-
- void main(void)
- {
- extfhc_init();
- db_heap_init();
- db_gvar_init();
- db_key_init();
- db_date_init();
- db_funcs_init();
- db_tree_init();
- ⁿIFDEF MUSERⁿ
- multiuser = True;
- ⁿELSEDEFⁿ
- multiuser = False;
- ⁿENDDEFⁿ
- initindex();
- openfiles();
- if (fok) {
- shutdown = on_error;
- initialize();
- do_something();
- closefiles();
- }
- }