home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / c / ccua_dbc.zip / CCUA.SKL < prev    next >
Text File  |  1992-09-11  |  60KB  |  2,476 lines

  1.  
  2.  
  3. #define _ENTRY_
  4.  
  5. #ifdef __TURBOC__
  6.     #include <conio.h>
  7. #else
  8.     #include <graph.h>
  9. #endif
  10. #include <io.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include "db_lsc.h"
  15. #include "db_types.h"
  16. #include "db_conio.h"
  17. #include "db_curs.h"
  18. #include "db_date.h"
  19. #include "db_dos.h"
  20. #include "db_file.h"
  21. #include "extfhc.h"
  22. #include "db_funcs.h"
  23. #include "db_heap.h"
  24. #include "db_gvar.h"
  25. #include "db_key.h"
  26. #include "db_pswd.h"
  27. #include "db_sets.h"
  28. #include "db_str.h"
  29. #include "db_win.h"
  30. #include "db_mnu.h"
  31. #include "db_util.h"
  32. #include "db_work.h"
  33. #include "db_tree.h"
  34. #include "db_list.h"
  35. ⁿUSESⁿ
  36. ⁿIFDEF MANUALⁿ
  37. #include "db_man.h"
  38. ⁿENDDEFⁿ
  39. ⁿIFDEF MEMOSⁿ
  40. #include "db_memo.h"
  41. ⁿENDDEFⁿ
  42.  
  43. unsigned _stklen = 0x4000;  /* Default stack of 16 K */
  44.  
  45. string _tts, _tranString;   /* _tranString for internal generator use only */
  46.  
  47. /*********************************  TYPES  **********************************/
  48.  
  49. typedef struct {
  50.     char exeid[9];
  51.     byte anchor;
  52.    int  deltat;
  53. } defaultrec;
  54.  
  55. typedef enum {Cmd_No_Command,
  56.           Cmd_Next_Record,
  57.           Cmd_Prev_Record,
  58.           Cmd_Find_Record,
  59.           Cmd_Top_Record,
  60.           Cmd_Last_Record,
  61.           Cmd_Edit_Record,
  62.           Cmd_Add_Record,
  63.           Cmd_Copy_Record,
  64.           Cmd_Delete_Record,
  65.           Cmd_Next_File,
  66.           Cmd_Prev_File,
  67.           Cmd_Swap_Menu
  68. }commandtyp;
  69.  
  70. ⁿIFDEF LINKEDⁿ
  71. typedef struct {
  72.     byte  f;
  73.     byte  k;
  74.     byte  l;
  75.     uchar t;
  76. } lback;
  77. ⁿENDDEFⁿ
  78.  
  79. typedef struct savmtyp {
  80.     pathstr savnam;
  81.     byte savno;
  82.     char savprompt[81];
  83.     pathstr savpath;
  84.     struct savmtyp *savprv;
  85. } savmtyp, *savmptr;
  86.  
  87. /*************************  INITIALIZED VARIABLES  **************************/
  88.  
  89. defaultrec def1 = {"öDBPSKL_",0,150};
  90.  
  91. namestr applname = "ⁿMODNAMEⁿ";
  92. pathstr localmenu = "ⁿMENUNAMEⁿ";
  93.  
  94. #define maxfilno ⁿmaxfilnoⁿ
  95. #define maxkeyno ⁿmaxkeynoⁿ
  96.  
  97. str12 dbnames[maxfilno+1][maxkeyno+1] =     /* [1.. ,0.. ] */
  98.                     ⁿdbnamesⁿ;
  99. long maxrec[maxfilno+1] =
  100.                     ⁿmaxrecⁿ;
  101. byte keymode[maxfilno+1][maxkeyno+1] =       /* [1.. ,1.. ] */
  102.                     ⁿkeymodeⁿ;
  103. byte keylen[maxfilno+1][maxkeyno+1] =        /* [1.. ,1.. ] */
  104.                     ⁿkeylenⁿ;
  105. byte keyseg1len[maxfilno+1][maxkeyno+1] =
  106.            ⁿkeyseg1lenⁿ;
  107. char keyuse[maxfilno+1][maxkeyno+1] =       /* [1.. ,1.. ] */
  108.                     ⁿkeyuseⁿ;
  109. char keytype[maxfilno+1][maxkeyno+1] =      /* [1.. ,1.. ] */
  110.                     ⁿkeytypeⁿ;
  111. byte keyfld[maxfilno+1][maxkeyno+1] =       /* [1.. ,1.. ] */
  112.                     ⁿKeyFldⁿ;
  113. findwtyp findscrpos[maxfilno+1][maxkeyno+1] = /* [1.. ,1.. ] */
  114.                     ⁿfindscrposⁿ;
  115. bool filinuse[maxfilno+1] =
  116.                     ⁿfilinuseⁿ;
  117. byte winforfile[maxfilno+1] =
  118.                     ⁿwinforfileⁿ;
  119.  
  120. ⁿIFDEF ADJUSTⁿ
  121. int afteradj[maxfilno+1][maxfilno+1] =
  122.                     ⁿafteradjⁿ;
  123. ⁿENDDEFⁿ
  124.  
  125. ⁿIFDEF TABLESⁿ
  126. byte tabsize[maxfilno+1] =
  127.                     ⁿTableSizesⁿ;
  128. ⁿENDDEFⁿ
  129.  
  130. ⁿIFDEF LINKEDⁿ
  131. lback linkback[maxfilno+1] =
  132.                     ⁿnewlinkbackⁿ;
  133. ⁿENDDEFⁿ
  134.  
  135. str20 keynamtab[maxfilno+1][maxkeyno+1] =
  136.                     ⁿkeynamtabⁿ;
  137.  
  138. bool menudriven = ⁿmenudrivenⁿ;
  139.  
  140. /*******************************  VARIABLES  ********************************/
  141.  
  142. ⁿIFDEF TABLESⁿ
  143. bool            switchtab,leaveclear;
  144. recnotyp        tabrecno;
  145. byte            tabidx[maxfilno+1];
  146. byte            tabused[maxfilno+1];
  147. ⁿENDDEFⁿ
  148.  
  149. bool            pathSwap;
  150. savmptr         smc, svm;
  151. string          tempString;
  152. byte            menuanchor;
  153. bool            quit,fok,cleartop,scrn_active, listAndAdd;
  154. int             keynum,_trace,filno,scrno,dispsno;
  155. long            nextrec;
  156. keystr          key,skey,tempkey;
  157. mnufrec         dm;
  158. winfrec         uw,hw;
  159. winptr          twinp;
  160. int             dbsize[maxfilno+1];
  161. datafile        *datf[maxfilno+1];
  162. indexfile       *idxkey[maxfilno+1][maxkeyno+1];
  163. keystr          tkeytab[maxkeyno+1], savkey[maxkeyno+1];
  164. fldtyp          *keyseg1fld[maxfilno + 1][maxkeyno + 1];
  165.  
  166. ⁿIFDEF LINKEDⁿ
  167. string          savelnk[maxfilno+1];
  168. ⁿENDDEFⁿ
  169.  
  170. ⁿIFDEF MUSERⁿ
  171. bool            lockByDel[maxfilno+1];
  172. ⁿENDDEFⁿ
  173.  
  174. int             tv;
  175. char            lastrecop;
  176. commandtyp      command;
  177.  
  178. ⁿRECMODⁿ
  179.  
  180. bool   custom_key(int scr, int fno, int *fld, uchar *key);
  181. void   getarec(int fno);
  182. void   putarec(int fno);
  183. void   displayrec(int fno, int sno);
  184. void   clear_rec(int fno);
  185. strptr list(strptr sout, int fno, int kno, keystr ks);
  186. strptr listadd(strptr sout, int fno, int kno, keystr aKey);
  187.  
  188. void tandk(int x, int y, winptr w)
  189. {
  190.     string ts;
  191.  
  192.     while (!kpressed()) {
  193.         if (mtime.x) writewxy(get_time(ts,(_timemode)(mtime.m)),0,mtime.x,mtime.y,NULL);
  194.         if (mksta.x) writewxy(keystat(ts,0),0,mksta.x,mksta.y,NULL);
  195.     }
  196. }
  197.  
  198. bool found(int fno, int kno, keystr chkkey)
  199. {
  200.     bool tok;
  201.     bool tfound;
  202.    keystr aKey;                                             /* SN 3.5 */
  203.  
  204.     tok = ok;
  205.     if ((fno != filno) && (keylen[fno][kno] > 0)) {
  206.       strcpy(aKey,chkkey);                                  /* SN 3.5 */
  207.       searchkey(idxkey[fno][kno], &recno[fno], aKey);       /* SN 3.5 */
  208.       ok = (bool)(ok && (strsearch(aKey, chkkey) == aKey)); /* SN 3.5 */
  209.         if (ok) switch (fno) {
  210.             ⁿgetrecⁿ
  211.         }
  212.         tfound = ok;
  213.     }
  214.     else tfound = False;
  215.  
  216.     ok = tok;
  217.    recavail[fno] = tfound;
  218.     return(tfound);
  219. }
  220.  
  221. ⁿFUNCMODⁿ
  222. ⁿSCRNMODⁿ
  223.  
  224. void openfiles(void)
  225. {
  226.     int    i, j, fo_i, fo_j;
  227.     string prepend;
  228.     int    tlen;
  229.     string ts;
  230.  
  231.     fo_i = fo_j = 0;
  232.  
  233.     ⁿSIZESⁿ;
  234.  
  235.     strip(prepend,datapath);
  236.     tlen = strlen(prepend);
  237.     if ((tlen > 0) && (prepend[tlen-1] != '\\')) {
  238.         prepend[tlen]   = '\\';
  239.       prepend[tlen+1] = '\0';
  240.     }
  241.  
  242.     fok = True;
  243.     for (i=1;i <= maxfilno; i++)
  244.         if (fok) {
  245.             datf[i] = db_malloc(sizeof(datafile));
  246.             strconcat(ts,prepend,dbnames[i][0],NULL);
  247.             openfile(datf[i],ts,dbsize[i]);
  248.             fok = (bool)(fok && ok);
  249.             if (fok) {
  250.                 fo_i = i;
  251.                 fo_j = 0;
  252.                 for (j=1; j <= maxkeyno; j++)
  253.                     if (fok && (keylen[i][j] > 0)) {
  254.                         idxkey[i][j] = db_malloc(sizeof(indexfile));
  255.                         strconcat(ts,prepend,dbnames[i][j],NULL);
  256.                         openindex(idxkey[i][j],ts,keylen[i][j],keymode[i][j]);
  257.                         fok = (bool)(fok && ok);
  258.                         if (fok) fo_j = j;
  259.                     }
  260.             }
  261.             else if (filinuse[i]) {
  262.                 strconcat(ts,prepend,dbnames[i][0],NULL);
  263.                 makefile(datf[i],ts,dbsize[i]);
  264.                 fok = ok;
  265.                 if (fok) {
  266.  
  267. ⁿIFDEF MUSERⁿ
  268.                     closefile(datf[i]);
  269.                     strconcat(ts,prepend,dbnames[i][0],NULL);
  270.                     openfile(datf[i],ts,dbsize[i]);
  271. ⁿENDDEFⁿ
  272.  
  273.                     fo_i = i;  fo_j = 0;
  274.                     for (j=1; j <= maxkeyno; j++)
  275.                         if (fok && (keylen[i][j] > 0)) {
  276.                             idxkey[i][j] = db_malloc(sizeof(indexfile));
  277.                             strconcat(ts,prepend,dbnames[i][j],NULL);
  278.                             makeindex(idxkey[i][j],ts,keylen[i][j],keymode[i][j]);
  279.                             fok = (bool)(fok && ok);
  280.                             if (fok) {
  281.  
  282. ⁿIFDEF MUSERⁿ
  283.                                 closeindex(idxkey[i][j]);
  284.                                 strconcat(ts,prepend,dbnames[i][j],NULL);
  285.                                 openindex(idxkey[i][j],ts,keylen[i][j],keymode[i][j]);
  286.                                 fo_j = j;
  287. ⁿELSEDEFⁿ
  288.                                 fo_j = j;
  289. ⁿENDDEFⁿ
  290.  
  291.                             }
  292.                         }
  293.                 }
  294.             }
  295.         }
  296.     if (!fok)
  297.         for (i=1; i <= maxfilno; i++)
  298.             if (i <= fo_i) {
  299.                 closefile(datf[i]);
  300.                 db_free(datf[i]);
  301.                 for (j=1; j <= maxkeyno; j++)
  302.                     if ((i < fo_i) || (j <= fo_j))
  303.                         if (keylen[i][j] > 0) {
  304.                             closeindex(idxkey[i][j]);
  305.                             db_free(idxkey[i][j]);
  306.                         }
  307.             }
  308. }
  309.  
  310. void closefiles(void)
  311. {
  312.     int i,j;
  313.  
  314.     for (i=1; i <= maxfilno; i++) {
  315.         closefile(datf[i]); db_free(datf[i]);
  316.         for (j=1; j <= maxkeyno; j++) if (keylen[i][j] > 0) {
  317.             closeindex(idxkey[i][j]);
  318.      db_free(idxkey[i][j]);
  319.         }
  320.     }
  321. }
  322.  
  323. ⁿIFDEF MUSERⁿ
  324. void must_secure_rec(int fno, long rno, int m)
  325. {
  326.     if (multiuser)
  327.         do {
  328.             tv = lock_datf(datf[fno],rno,Lock);
  329.             if (tv == -1)
  330.                 switch (m) {
  331.            case 1 : dspmsge(LSC_Warning,LSC_LinkedRecInUse,4.0);break;
  332.            case 2 : dspmsge(LSC_Warning,LSC_StatusRecLocked,4.0);break;
  333.                 }
  334.         } while (tv);
  335. }
  336.  
  337. bool chkabortretry(strptr instr)
  338. {
  339.     return((bool)((*instr == _Abort) || (*instr == _Retry)));
  340. }
  341.  
  342. void must_secure_index(int fno, int kno, byte lck)
  343. {
  344.     int tmp,count;
  345.     uchar again[2],retry[2],tpic[2];
  346.  
  347.     count = 0;
  348.     if (multiuser)
  349.         do {
  350.             count++;
  351.             if (count >= 1000) {
  352.                 dbgetstr(again,_Ch,LSC_Complications,chstr(retry,_Retry),chstr(tpic,Pic_U),"",chkabortretry,nohelp);
  353.                 if (*again == _Retry) count = 0;
  354.                 else {
  355.                     closefiles();
  356.                     exit(0);
  357.                 }
  358.             }
  359.             tmp = lock_indexf(idxkey[fno][kno],-1L,lck);
  360.         } while (tmp);
  361. }
  362. ⁿENDDEFⁿ
  363.  
  364. strptr makekey(strptr sout, int fno, int kno)
  365. {
  366.     string ks, ts;
  367.    string tempString;
  368.  
  369.     ks[0] = '\0';
  370.  
  371.     ⁿmakekeyⁿ
  372.  
  373.     strcpy(sout,ks);
  374.     return(sout);
  375. }
  376.  
  377. strptr keyexpr(strptr sout, int fno, int kno, string kvar)
  378. {
  379.     string ts, ks;
  380.     byte   tlen;
  381.  
  382.     strcpy(ks,kvar);
  383.     tlen = strlen(ks);
  384.  
  385.     ⁿkeyexprⁿ
  386.  
  387.     ks[tlen] = Nul;
  388.     strcpy(sout,ks);
  389.     return(sout);
  390. }
  391.  
  392. strptr getakey(strptr sout, int fno, int kno)
  393. {
  394.     keyexpr(sout,fno,kno,makekey(sout,fno,kno));
  395.     return(sout);
  396. }
  397.  
  398. ⁿIFDEF LINKEDⁿ
  399. strptr getlink(strptr sout, int fno)
  400. {
  401.     string tkey;
  402.  
  403.     tkey[0] = '\0';
  404.  
  405.     ⁿGetKLinkⁿ
  406.  
  407.     strcopy(sout,tkey,0,linkback[fno].l);
  408.     return(sout);
  409. }
  410. ⁿENDDEFⁿ
  411.  
  412. void edit_rec(int fld)
  413. {
  414.     edthook = tandk;
  415.  
  416. ⁿIFDEF TABLESⁿ
  417.     ⁿMODNAMEⁿ_edt(filno,fld,tabidx[filno] - 1);
  418. ⁿELSEDEFⁿ
  419.     ⁿMODNAMEⁿ_edt(filno,fld,0);
  420. ⁿENDDEFⁿ
  421.  
  422.     edthook = NULL;
  423. }
  424.  
  425. bool status_ok(int fno)
  426. {
  427.     bool tok;
  428.     keystr tk1, tk2;
  429.  
  430.     tok = (bool)(usedrecs(datf[fno]) > 0);
  431.  
  432. ⁿIFDEF LINKEDⁿ
  433.     if (linkback[fno].f > 0) {
  434.         getlink(tk1,fno);
  435.         strcopy(tk2,getakey(tk2,fno,1),0,linkback[fno].l);
  436.         tok = (bool)(tok && recavail[linkback[fno].f] && (strcmp(tk1,tk2) == 0));
  437.     }
  438. ⁿENDDEFⁿ
  439.  
  440.    recavail[fno] = tok;
  441.     return(tok);
  442. }
  443.  
  444. void clearbuf(ptr fb)
  445. {
  446.     word    w;
  447.     string  tpic;
  448.     fldblk *fblk;
  449.     fldtyp *ftp;
  450.  
  451.     fblk = fb;
  452.     for (w=0; w < fblk->numf; w++) {
  453.         ftp = &(*fblk->farr)[w];
  454.         expand(tpic,ftp->pic);
  455.         switch (ftp->typ) {
  456.             case _Ch   : fillstr(ftp->faddr,piclen(tpic,ftp->typ),' '); break;
  457.             case _Num  : fstr(ftp->faddr,0.0,_calc_int(tpic),_calc_frac(tpic)); break;
  458.  
  459. ⁿIFDEF MEMOSⁿ
  460.             case _Memo : memset(ftp->faddr,0,4); break;
  461. ⁿENDDEFⁿ
  462.  
  463.         }
  464.     }
  465. }
  466.  
  467. ⁿIFDEF MEMOSⁿ
  468. void clearmemo(ptr fb)
  469. {
  470.     word w;
  471.     fldblk *fblk;
  472.     bool memofile;
  473.     fldtyp *ftp;
  474.  
  475.     fblk = fb;
  476.     memofile = False;
  477.     for (w=0; w < fblk->numf; w++) {
  478.         ftp = &(*fblk->farr)[w];
  479.         if (ftp->typ == _Memo) {
  480.             memofile = True;
  481.             memset(ftp->faddr,0,4);
  482.         }
  483.     }
  484.     if (memofile)   displayrec(filno,scrno);
  485. }
  486. ⁿENDDEFⁿ
  487.  
  488. void clear_rec(int fno)
  489. {
  490.  
  491. ⁿIFDEF LINKEDⁿ
  492.     int i;
  493.  
  494.     if (link == Up_N_Down)
  495.         for (i=1; i <= maxfilno; i++)
  496.             if (linkback[i].f == (byte)fno) clear_rec(i);
  497. ⁿELSEDEFⁿ
  498. ⁿENDDEFⁿ
  499.  
  500.     if (cleartop || (fno != filno)) {
  501.         switch (fno) {
  502.             ⁿCLEARBUFⁿ
  503.         }
  504.         displayrec(fno,scrno);
  505.     }
  506. }
  507.  
  508. /* SN 3.5 - the whole function was created for this version 3.5 */
  509.  
  510. long add2CodeFile(int fileNumber)
  511. {
  512.    bool    saveOk,
  513.             aOk;
  514.    byte    keyNumber, keyNumberCount;
  515.    keystr  aKey;
  516.    char   *aBufferPtr,
  517.            *aFieldPtr,
  518.             errorMessage[256];
  519.  
  520.  
  521.  
  522.    saveOk                = ok;
  523.    *(recno + fileNumber) = 0;
  524.  
  525.    switch(fileNumber) {
  526.  
  527.       ⁿCODEFILEBUFⁿ
  528.  
  529.       default :
  530.           aBufferPtr = aFieldPtr = 0;
  531.           break;
  532.    }
  533.  
  534.    if (aBufferPtr) {
  535.       clearbuf(aFieldPtr);
  536.       memmove(aBufferPtr, &recno[fileNumber], 4);
  537.       do {
  538.           ok = False;
  539.           editdefaultdata(fileNumber, aFieldPtr);
  540.           if (exitcode != QitKey) {
  541. ⁿIFDEF MUSERⁿ
  542.              must_secure_rec(fileNumber, 0, 2);
  543. ⁿENDDEFⁿ
  544.              addrec(datf[fileNumber], &recno[fileNumber], aBufferPtr);
  545. ⁿIFDEF MUSERⁿ
  546.              tv = lock_datf(datf[fileNumber], recno[fileNumber], Lock);
  547.              tv = lock_datf(datf[fileNumber], 0, UnLock);
  548. ⁿENDDEFⁿ
  549.              keyNumber = 0;
  550.              ok        = True;
  551.              while (ok && (keyNumber < maxkeyno)) {
  552.                    keyNumber++;
  553.                    if (keylen[fileNumber][keyNumber]) {
  554.                        getakey(aKey, fileNumber, keyNumber);
  555. ⁿIFDEF MUSERⁿ
  556.                        must_secure_index(fileNumber, keyNumber, Lock);
  557.                        addkey(idxkey[fileNumber][keyNumber], &recno[fileNumber], aKey);
  558.                        must_secure_index(fileNumber, keyNumber, UnLock);
  559. ⁿELSEDEFⁿ
  560.                        addkey(idxkey[fileNumber][keyNumber], &recno[fileNumber], aKey);
  561. ⁿENDDEFⁿ
  562.                    }
  563.              }
  564.              if (!ok) {
  565.                 audible(Error);
  566.                 dspmsge(LSC_BaseError, strconcat(errorMessage, LSC_KeyExists, "(", keynamtab[fileNumber][keyNumber], ")"), 4);
  567.                 for (keyNumberCount = 1; keyNumberCount < keyNumber; keyNumberCount++) {
  568.                    if (keylen[fileNumber][keyNumberCount]) {
  569.                      getakey(aKey, fileNumber, keyNumberCount);
  570. ⁿIFDEF MUSERⁿ
  571.                              must_secure_index(fileNumber, keyNumberCount, Lock);
  572.                      deletekey(idxkey[fileNumber][keyNumberCount], &recno[fileNumber], aKey);
  573.                      must_secure_index(fileNumber, keyNumberCount, UnLock);
  574. ⁿELSEDEFⁿ
  575.                      deletekey(idxkey[fileNumber][keyNumberCount], &recno[fileNumber], aKey);
  576. ⁿENDDEFⁿ
  577.                        }
  578.                 }
  579.  
  580. ⁿIFDEF MUSERⁿ
  581.                 must_secure_rec(fileNumber, 0, 2);
  582.                 deleterec(datf[fileNumber], recno[fileNumber]);
  583.                 tv = lock_datf(datf[fileNumber], 0, UnLock);
  584. ⁿELSEDEFⁿ
  585.                 deleterec(datf[fileNumber], recno[fileNumber]);
  586. ⁿENDDEFⁿ
  587.  
  588.                 ok = False;
  589.              }
  590.  
  591. ⁿIFDEF MUSERⁿ
  592.              tv = lock_datf(datf[fileNumber], recno[fileNumber], UnLock);
  593. ⁿENDDEFⁿ
  594.           }
  595.       }while (!ok && (exitcode != QitKey));
  596.  
  597.       if (exitcode == QitKey) {
  598.           clearbuf(aFieldPtr);
  599.           recno[fileNumber] = 0;
  600.       }
  601.    }
  602.  
  603.    ok       = saveOk;
  604.    exitcode = Nul;
  605.    return(recno[fileNumber]);
  606. }
  607.  
  608. bool skip(char dirn, int fno)
  609. {
  610.     bool fval;
  611.     string ts;
  612.  
  613.     fval = True;
  614.     if (dirn == _Next) nextkey(idxkey[fno][1],&recno[fno],key);
  615.     else               prevkey(idxkey[fno][1],&recno[fno],key);
  616.  
  617. ⁿIFDEF LINKEDⁿ
  618.     if (linkback[fno].f > 0) ok = (bool)(ok && (strsearch(key,getlink(ts,fno)) == key));
  619. ⁿENDDEFⁿ
  620.  
  621.     if (!ok) {
  622.         fval = False;
  623.         if (dirn == _Next) prevkey(idxkey[fno][1],&recno[fno],key);
  624.         else               nextkey(idxkey[fno][1],&recno[fno],key);
  625.     }
  626.     return(fval);
  627. }
  628.  
  629. void getarec(int fno)
  630. {
  631.     int i;
  632.     string tkey;
  633.     string ts;
  634.  
  635. ⁿIFDEF LINKEDⁿ
  636. ⁿIFDEF TABLESⁿ
  637.     bool tb;
  638. ⁿENDDEFⁿ
  639. ⁿENDDEFⁿ
  640.  
  641.     tkey[0] = '\0';
  642.     recavail[fno] = ok;
  643.     if (ok)
  644.         switch (fno) {
  645.             ⁿGETRECⁿ
  646.         }
  647. ⁿIFDEF LINKEDⁿ
  648.     if ((!recavail[fno]) ||
  649.             ((link != No_Link) && (_trace != fno) && !status_ok(fno))) {
  650. ⁿIFDEF TABLESⁿ
  651.         tb          = scrn_active;
  652.         scrn_active = False;
  653.         clear_rec(fno);
  654.         scrn_active = tb;
  655. ⁿELSEDEFⁿ
  656.         clear_rec(fno);
  657. ⁿENDDEFⁿ
  658.         recavail[fno] = False;
  659.     }
  660.     if (link != No_Link) {
  661. ⁿIFDEF TABLESⁿ
  662.         if ((tabsize[fno] > 1) && (fno != filno) && !switchtab) {
  663.             tabrecno[fno] = recno[fno]; tabidx[fno] = 1;
  664.         }
  665. ⁿENDDEFⁿ
  666.         for (i=1; i <= maxfilno; i++)
  667.             if (linkback[i].f == (byte)fno)
  668.                 if (!status_ok(i)) {
  669.                     getlink(tkey,i);
  670.                     searchkey(idxkey[i][1],&recno[i],tkey);
  671.                     ok = (bool)(ok && (strsearch(tkey,getlink(ts,i)) == tkey));
  672.                     getarec(i); /* recursion */
  673.                 }
  674.     }
  675. ⁿELSEDEFⁿ
  676.     if (!recavail[fno] || !status_ok(fno)) {
  677.         clear_rec(fno);
  678.         recavail[fno] = False;
  679.     }
  680. ⁿENDDEFⁿ
  681.     if (fno == filno) ok = recavail[fno];
  682. }
  683.  
  684. void putarec(int fno)
  685. {
  686.    if (recavail[fno]) {
  687.        switch (fno) {
  688.                ⁿPUTRECⁿ
  689.        }
  690.    }
  691. }
  692.  
  693. void top_record(void)
  694. {
  695. ⁿIFDEF LINKEDⁿ
  696.     if (!linkback[filno].f) {
  697.         clearkey(idxkey[filno][1]);
  698.         nextkey(idxkey[filno][1],&recno[filno],key);
  699.     }
  700.     else {
  701.         getlink(tempkey,filno);
  702.         strcpy(skey,tempkey);
  703.         searchkey(idxkey[filno][1],&recno[filno],tempkey);
  704.         ok = (bool)(ok && (strsearch(tempkey,skey) == tempkey));
  705.     }
  706. ⁿELSEDEFⁿ
  707.     clearkey(idxkey[filno][1]);
  708.     nextkey(idxkey[filno][1],&recno[filno],key);
  709. ⁿENDDEFⁿ
  710.     if (ok)
  711.         getarec(filno);
  712.     else {
  713.         clear_rec(filno);
  714.         recavail[filno] = False;
  715.     }
  716. ⁿIFDEF TABLESⁿ
  717.     if (tabsize[filno] > 1) {
  718.         tabrecno[filno] = recno[filno]; tabidx[filno] = 1;
  719.     }
  720. ⁿENDDEFⁿ
  721.     displayrec(filno,scrno);
  722. }
  723.  
  724. void findmulti(int fno, long *recn, strptr key2find)
  725. {
  726.     long saverecn;
  727.     keystr savk2f;
  728.  
  729.     saverecn = *recn;
  730.     strcpy(savk2f,key2find);
  731.     searchkey(idxkey[fno][1],recn,key2find);
  732.     ok = (bool)(ok && (strsearch(key2find,savk2f) == key2find));
  733.     while ((*recn != saverecn) && ok) {
  734.         nextkey(idxkey[fno][1],recn,key2find);
  735.         ok = (bool)(ok && (strsearch(key2find,savk2f) == key2find));
  736.     }
  737. }
  738.  
  739. ⁿIFDEF TABLESⁿ
  740. void gettabrec(byte fno)
  741. {
  742.     switch (fno) {
  743.         ⁿGetTabRecⁿ
  744.     }
  745. }
  746.  
  747. void disptab(byte fno)
  748. {
  749.     byte incy;
  750.     long srec;
  751.     bool rec_ok;
  752.     string tk;
  753.  
  754.     if (tabsize[fno] < 2) {
  755.         incy = tabidx[fno]-1;
  756.         ⁿMODNAMEⁿ_dsp(fno,dispsno,incy);
  757.     }
  758.     else {
  759.         incy = 0;
  760.         rec_ok = recavail[fno];
  761.         if (rec_ok) {
  762.             srec = recno[fno];
  763. ⁿIFDEF LINKEDⁿ
  764.             if (!leaveclear || (linkback[fno].f != (byte)filno)) gettabrec(fno);
  765. ⁿELSEDEFⁿ
  766.             if (!leaveclear) gettabrec(fno);
  767. ⁿENDDEFⁿ
  768.             getakey(tk,fno,1);
  769.             findmulti(fno,&tabrecno[fno],tk);
  770.             if (!ok) {
  771.                 scrn_active = False;
  772.                 clear_rec(fno);
  773.                 scrn_active = True;
  774.                 rec_ok = False;
  775.             }
  776.             if ((tabidx[fno] > tabsize[fno]) && (skip(_Next,fno))) {
  777.                 tabidx[fno] = tabsize[fno];
  778.                 tabrecno[fno] = recno[fno];
  779.                 gettabrec(fno);
  780.             }
  781.             if ((tabidx[fno] == 0) && (skip(_Prev,fno))) {
  782.                 tabidx[fno] = 1;
  783.                 tabrecno[fno] = recno[fno];
  784.                 gettabrec(fno);
  785.             }
  786.         }
  787.         (uw.wa[dispsno])->disp = False;
  788.         tabused[fno] = 0;
  789.         do {
  790.             ⁿMODNAMEⁿ_dsp(fno,dispsno,incy);
  791.             incy++;
  792.             if (rec_ok && (incy < tabsize[fno])) {
  793.                 tabused[fno] = incy;
  794.                 link = No_Link;
  795. ⁿIFDEF LINKEDⁿ
  796.                 if ((!leaveclear || (linkback[fno].f != (byte)filno)) && recavail[fno]) {
  797. ⁿELSEDEFⁿ
  798.                 if (!leaveclear && recavail[fno]) {
  799. ⁿENDDEFⁿ
  800.                     if (skip(_Next,fno)) getarec(fno);
  801.                     else {
  802.                         scrn_active = False;
  803.                         clear_rec(fno);
  804.                         scrn_active = True;
  805.                         rec_ok = False;
  806.                     }
  807.                 }
  808.                 else {
  809.                     scrn_active = False;
  810.                     clear_rec(fno);
  811.                     scrn_active = True;
  812.                     rec_ok = False;
  813.                 }
  814.                 link = Up_N_Down;
  815.             }
  816.         } while (incy < tabsize[fno]);
  817.         (uw.wa[dispsno])->disp = True; dispwindow(uw.wa[dispsno]);
  818.         if (recavail[fno]) {
  819.             recno[fno] = srec;
  820. ⁿIFDEF LINKEDⁿ
  821.             if (!leaveclear || (linkback[fno].f != (byte)filno)) getarec(fno);
  822. ⁿELSEDEFⁿ
  823.             if (!leaveclear) getarec(fno);
  824. ⁿENDDEFⁿ
  825.             else {
  826.                 link = No_Link;
  827.                 getarec(fno);
  828.                 link = Up_N_Down;
  829.             }
  830.             getakey(tk,fno,1);
  831.             findmulti(fno,&srec,tk);
  832.         }
  833.     }
  834. }
  835. ⁿENDDEFⁿ
  836.  
  837. void dispfields(int fno, int sno)
  838. {
  839. ⁿIFDEF TABLESⁿ
  840.     dispsno = sno;
  841. ⁿENDDEFⁿ
  842.     switch (sno) {
  843.         ⁿDispFieldsⁿ
  844.     }
  845. }
  846.  
  847. void displayrec(int fno, int sno)
  848. {
  849.     if (scrn_active) dispfields(fno,sno);
  850. }
  851.  
  852. void switch_file(char mode)
  853. {
  854.     int fno,incr;
  855.  
  856.     scrn_active = True;
  857.     if (mode == '+')      incr = 1;
  858.    else if (mode == '-') incr = -1;
  859.     else             incr = 0;
  860.     fno = filno;
  861.     do {
  862.         filno += incr;
  863.         if ((filno < 1) || (filno > maxfilno)) {
  864.             incr = -incr; filno += incr;
  865.             audible(Warning);
  866.         }
  867.     } while (!filinuse[filno] && (filno != fno));
  868.  
  869.     if (scrno < winforfile[filno]) displayrec(filno,scrno);
  870.     while (scrno > winforfile[filno]) {
  871.         hidewin(T_OFF,uw.wa[scrno]);
  872.       scrno--;
  873.     }
  874.  
  875.     while (scrno < winforfile[filno]) {
  876.         scrno++;
  877.       hidewin(T_ON,uw.wa[scrno]);
  878.     }
  879.  
  880.     if (!status_ok(filno)) top_record(); else ok = True;
  881. ⁿIFDEF TABLESⁿ
  882.     switchtab = True;
  883.     displayrec(filno,scrno);
  884.     switchtab = False;
  885. ⁿELSEDEFⁿ
  886.     displayrec(filno,scrno);
  887. ⁿENDDEFⁿ
  888. }
  889.  
  890. ⁿIFDEF LINKEDⁿ
  891. void traceback(int fno)
  892. {
  893.     string tk,sk;
  894.     int f,k;
  895.  
  896.     f = linkback[fno].f;
  897.     k = linkback[fno].k;
  898.     _trace = f;
  899.     if (recavail[fno]) {
  900.         strcopy(tk,getakey(tk,fno,1),0,linkback[fno].l); strcpy(sk,tk);
  901.         searchkey(idxkey[f][k],&recno[f],tk);
  902.         ok = (bool)(ok && (strsearch(tk,sk) == tk));
  903.         if (ok) {
  904.             getarec(f);
  905.             ok = status_ok(fno);
  906. ⁿIFDEF TABLESⁿ
  907.             if (tabsize[f] > 1) {
  908.                 tabrecno[f] = recno[f]; tabidx[f] = 1;
  909.             }
  910. ⁿENDDEFⁿ
  911.             if (ok && (k > 1)) {
  912.                 getakey(tk,f,1);
  913.                 findmulti(f,&recno[f],tk);
  914.             }
  915.         }
  916.     }
  917.     else ok = True;
  918.  
  919.     if (!ok) {
  920.         audible(Error);
  921.         dspmsge(LSC_BaseError,LSC_TracebackFailed,4.0);
  922.         filno = 1;
  923.         switch_file(' ');
  924.         top_record();
  925.     }
  926.     else
  927.         if (linkback[f].f > 0)
  928.             traceback(f);
  929.     _trace = 0;
  930.     ok = status_ok(fno);
  931. }
  932. ⁿENDDEFⁿ
  933.  
  934. ⁿIFDEF TABLESⁿ
  935. void align_tab(int fno)
  936. {
  937.     byte count;
  938.     long srno;
  939.     string ts;
  940.  
  941.     getakey(tempkey,fno,1);
  942.     strcpy(skey,tempkey);
  943.     srno = recno[fno];
  944.     count = 1;
  945.     do {
  946.         prevkey(idxkey[fno][1],&recno[fno],tempkey);
  947. ⁿIFDEF LINKEDⁿ
  948.         ok = (bool)(ok && (strsearch(tempkey,getlink(ts,fno)) == tempkey));
  949. ⁿENDDEFⁿ
  950.         if (ok) count++;
  951.     } while ((count <= tabsize[fno]) && ok);
  952.  
  953.     if (!ok) nextkey(idxkey[fno][1],&recno[fno],tempkey);
  954.     tabidx[fno]   = count;
  955.    tabrecno[fno] = recno[fno];
  956.     recno[fno]    = srno;
  957.     findmulti(filno,&recno[fno],skey);
  958. }
  959. ⁿENDDEFⁿ
  960.  
  961. void displayall(void)
  962. {
  963.     int i;
  964.  
  965.     for (i=1; i <= filno; i++) (uw.wa[winforfile[i]])->disp = False;
  966. ⁿIFDEF TABLESⁿ
  967.     link = No_Link;
  968.     for (i=1; i <= scrno; i++) displayrec(0,i);
  969.     link = Up_N_Down;
  970. ⁿELSEDEFⁿ
  971.     for (i=1; i <= scrno; i++) displayrec(filno,i);
  972. ⁿENDDEFⁿ
  973.     for (i=1; i <= filno; i++) hidewin(T_ON,uw.wa[winforfile[i]]);
  974. }
  975.  
  976. void align_rec(long oldr)
  977. {
  978.     int i;
  979.  
  980.     ok           = True;
  981.     _trace       = filno;
  982.     recno[filno] = oldr;
  983.     scrn_active  = False;
  984.     if (oldr > 0) getarec(filno);
  985.    else          recavail[filno] = False;
  986.  
  987.     if (recavail[filno]) {
  988.         getakey(skey,filno,1);
  989.         findmulti(filno,&oldr,skey);
  990.         if (!ok) {
  991.             audible(Error);
  992.             dspmsge(LSC_BaseError,LSC_Mismatch,4.0);
  993. ⁿIFDEF MUSERⁿ
  994.             filno = 1; scrno = 1;
  995. ⁿENDDEFⁿ
  996.             top_record();
  997.         }
  998.     }
  999.     else top_record();
  1000. ⁿIFDEF LINKEDⁿ
  1001.     if (linkback[filno].f > 0) traceback(filno);
  1002. ⁿENDDEFⁿ
  1003. ⁿIFDEF TABLESⁿ
  1004.     if (tabsize[filno] > 1) align_tab(filno);
  1005. ⁿENDDEFⁿ
  1006.     _trace = 0;
  1007.     scrn_active = True;
  1008.     displayall();
  1009. }
  1010.  
  1011. void next_record(char dirn)
  1012. {
  1013.     long savr;
  1014.  
  1015.     if (status_ok(filno)) {
  1016.         savr = recno[filno];
  1017.         if (skip(dirn,filno)) {
  1018.             getarec(filno);
  1019. ⁿIFDEF TABLESⁿ
  1020.             if (tabsize[filno] > 1)
  1021.                 if (dirn == _Next) tabidx[filno]++; else tabidx[filno]--;
  1022. ⁿENDDEFⁿ
  1023.             if (!recavail[filno]) align_rec(savr);
  1024.             else                  displayrec(filno,scrno);
  1025.         }
  1026.         else audible(Warning);
  1027.         if (!ok) top_record();
  1028.     }
  1029.     else audible(Warning);
  1030. }
  1031.  
  1032. ⁿIFDEF TABLESⁿ
  1033. void next_tab_page(char dirn)
  1034. {
  1035.     byte count;
  1036.  
  1037.     if ((tabsize[filno] > 1) && status_ok(filno)) {
  1038.         count = 1;
  1039.         while ((count < tabsize[filno]) && skip(dirn,filno)) count++;
  1040.         getarec(filno);
  1041.         align_tab(filno);
  1042.         displayrec(filno,scrno);
  1043.     }
  1044. }
  1045. ⁿENDDEFⁿ
  1046.  
  1047. void last_record(void)
  1048. {
  1049.     long savr;
  1050.  
  1051.     if (status_ok(filno)) {
  1052.         savr = recno[filno];
  1053. ⁿIFDEF LINKEDⁿ
  1054.         if (linkback[filno].f == 0) {
  1055.             clearkey(idxkey[filno][1]);
  1056.             prevkey(idxkey[filno][1],&recno[filno],key);
  1057.         }
  1058.         else {
  1059.             getlink(tempkey,filno);
  1060.             strcpy(skey,tempkey);
  1061.             searchkey(idxkey[filno][1],&recno[filno],tempkey);
  1062.             ok = (bool)(ok && (strsearch(tempkey,skey) == tempkey));
  1063.             if (ok) {
  1064.                 while (ok) {
  1065.                     nextkey(idxkey[filno][1],&recno[filno],tempkey);
  1066.                     ok = (bool)(ok && (strsearch(tempkey,skey) == tempkey));
  1067.                 }
  1068.                 prevkey(idxkey[filno][1],&recno[filno],tempkey);
  1069.             }
  1070.         }
  1071. ⁿELSEDEFⁿ
  1072.         clearkey(idxkey[filno][1]);
  1073.         prevkey(idxkey[filno][1],&recno[filno],key);
  1074. ⁿENDDEFⁿ
  1075.         if (!ok) top_record();
  1076.         else {
  1077.             getarec(filno);
  1078. ⁿIFDEF TABLESⁿ
  1079.             if (tabsize[filno] > 1) align_tab(filno);
  1080. ⁿENDDEFⁿ
  1081.             if (!recavail[filno]) align_rec(savr);
  1082.             else                  displayrec(filno,scrno);
  1083.         }
  1084.     }
  1085.     else audible(Warning);
  1086. }
  1087.  
  1088. strptr horizrec(strptr sout, uchar mode, byte fno, byte kno)
  1089. {
  1090.     string ts;
  1091.  
  1092.    strcpy(ts, "~");
  1093.     if (mode == _Header) {
  1094.         switch (fno) {
  1095.             ⁿSELHEADERⁿ
  1096.         }
  1097.         if (ts[0] == '~') strconcat(ts,LSC_DispSequence," ",keynamtab[fno][kno],NULL);
  1098.     }
  1099.     else {
  1100.         switch (fno) {
  1101.             ⁿSELDETAILⁿ
  1102.         }
  1103.     }
  1104.     pad(sout,ts,255,Right);
  1105.     return(sout);
  1106. }
  1107.  
  1108. void display_the_find(long trecno, long oldnum)
  1109. {
  1110.     align_rec(trecno ? trecno : oldnum);
  1111. }
  1112.  
  1113. void find_record(void)
  1114. {
  1115.     int    tpos,i, dsplen;
  1116.     bool   tb,abort;
  1117.     char   temp_pic[DB_Klen+1];
  1118.     long   trecno,oldnum;
  1119.     char   chosen[21];
  1120.     string numstr, choosestr;
  1121.     string ts;
  1122.    string aPictureField;
  1123.    uchar  aFieldType;
  1124.  
  1125.    exitcode = ' ';
  1126.     if ((usedrecs(datf[filno]) > 0) && (filinuse[filno])) {
  1127.         oldnum = (recavail[filno]) ? recno[filno] : 0;
  1128.         if ((keynum > maxkeyno) || (keylen[filno][keynum] == 0)) keynum = 1;
  1129.         abort = False;
  1130.       dsplen       = 0;                                                                   /* SN 3.5 */
  1131.       for (i = 1; i <= maxkeyno; ++i) dsplen += strlen(keynamtab[filno][i]);              /* SN 3.5 */
  1132.       dsplen = (dsplen > 255) ? 14 : 20;                                                  /* SN 3.5 */
  1133.        i            = keynum;
  1134.       choosestr[0] = '\0';
  1135.       numstr[0]    = '\0';
  1136.         do {
  1137.            if ((keylen[filno][i] != 0) && (keynamtab[filno][i][0] != '\0')) {
  1138.                 strconcat(numstr,numstr,istr(ts,(long)i,2),"|",NULL);
  1139.                 strconcat(choosestr,choosestr,pad(ts,keynamtab[filno][i],dsplen,Right),"|",NULL);  /* SN 3.5 */
  1140.             }
  1141.             i++;
  1142.             if (i > maxkeyno) i = 1;
  1143.         } while (i != keynum);
  1144.         gotoxy((scrwid-20)/2,scrhgt-maxkeyno-4);
  1145.         tb        = permitesc;
  1146.       permitesc = True;
  1147.  
  1148.       i         = strlen(numstr);
  1149.       if (!i) exitcode = QitKey;
  1150.       else    if (i == 3) strcopy(chosen, numstr, 0, 2);
  1151.           else        choose(key, numstr, choosestr, chosen);
  1152.  
  1153.         permitesc = tb;
  1154.         if (chosen[0] != 0) keynum = (int) ival(chosen);
  1155.         abort = (bool)(exitcode == QitKey);
  1156.         if (!abort) {
  1157.             strconcat(ts," ",LSC_EnterTheKey," : ",trim(ts,keynamtab[filno][keynum])," ",NULL);
  1158.             if (openwin(0,2,scrhgt-2,78,1,31,31,8,"─┐│┘─└│┌",TopCnt,ts)) {
  1159.                 twinp = curwin;
  1160.         twinp->disp = True;
  1161.         dispwindow(twinp);
  1162.                 fillstr(key,DB_Klen,' ');
  1163.                 strchcat(strip(temp_pic,istr(temp_pic,(long)DB_Klen,3)),Pic_X);
  1164.                 tpos = (78-(strlen(LSC_EnterOrEsc)+DB_Klen+2))/2;
  1165.                 writewxy(LSC_EnterOrEsc,31,(byte)tpos,1,twinp);
  1166.                 tpos = tpos + strlen(LSC_EnterOrEsc) + 1;
  1167.  
  1168. /* Written by SN 3.5 - Start */
  1169.  
  1170.         strcpy(aPictureField, keyseg1fld[filno][keynum]->pic);
  1171.         aFieldType = keyseg1fld[filno][keynum]->typ;
  1172.  
  1173.         expand(choosestr, aPictureField);
  1174.         switch (aFieldType) {
  1175.            case _Ch   : {
  1176.                    fillstr(choosestr, piclen(choosestr, aFieldType), ' ');
  1177.                    break;
  1178.                 }
  1179.            case _Num  : {
  1180.                    fstr(choosestr, 0.0, _calc_int(choosestr), _calc_frac(choosestr));
  1181.                    break;
  1182.                 }
  1183.         }
  1184.  
  1185.                 dsp_fld(tpos,1,choosestr, aFieldType, aPictureField, 1, 40, 0, twinp);
  1186.                 edt_fld(tpos,1,choosestr, aFieldType, aPictureField, 40, 0, twinp);
  1187.                 *skey = '\0';
  1188.         strcopy(key,choosestr,0,keyseg1len[filno][keynum]);
  1189.         if (aFieldType == _Num && (valu(key) == 0)) *key = '\0';
  1190.         pic_fld(choosestr, choosestr, aFieldType, 0, 0, aPictureField);
  1191.  
  1192. /* Written by SN 3.5 - Finish */
  1193.  
  1194.                 closewin(&twinp);
  1195.                 if (exitcode == Esc) goto Find_Exit;
  1196.                 if (!empty(key)) {
  1197.                     trim(key,keyexpr(key,filno,keynum,key));
  1198.            strcpy(skey,key);
  1199.                 }
  1200.                 searchkey(idxkey[filno][keynum],&recno[filno],key);
  1201.                 if ((!ok) || (strsearch(key,skey) != key)) {
  1202.                     audible(Warning);
  1203.            strconcat(ts, LSC_NoExactMatch, choosestr, NULL);
  1204.            strcopy (ts, ts, 0, 76);
  1205.            dspmsge("",ts,4.0);
  1206.                 }
  1207.                 tempkey[0] = '\0';
  1208.                 if (ok) {
  1209.                     nextkey(idxkey[filno][keynum],&recno[filno],key);
  1210.                     if (ok) strcpy(tempkey,key);
  1211.                     prevkey(idxkey[filno][keynum],&recno[filno],key);
  1212.                 }
  1213.                 else prevkey(idxkey[filno][keynum],&recno[filno],key);
  1214.                 if (!skey[0] || (strsearch(key,skey) != key) || (strsearch(tempkey,skey) == tempkey)) {
  1215.                     trecno = list_n_choose((byte)filno,(byte)keynum,key,idxkey[filno][keynum],findscrpos[filno][keynum]);
  1216.                     display_the_find(trecno,oldnum);
  1217.                 }
  1218.                 else align_rec(recno[filno]);
  1219.             }
  1220.         }
  1221.     }
  1222.     else audible(Warning);
  1223. Find_Exit : ;
  1224.    exitcode = ' ';
  1225. }
  1226.  
  1227. strptr list(strptr sout, int fno, int kno, keystr ks)
  1228. {
  1229.     long trecno;
  1230.     keystr lastks;
  1231.     bool tok;
  1232. ⁿIFDEF TABLESⁿ
  1233.     byte stabsiz;
  1234. ⁿENDDEFⁿ
  1235.  
  1236.     if (!listAndAdd) listing = True;
  1237.     if ((fno != filno) && (keylen[fno][kno] > 0)) {
  1238.         tok         = ok;
  1239.         scrn_active = False;
  1240.         strcpy(lastks,ks);
  1241.         clearkey(idxkey[fno][kno]);
  1242.         nextkey(idxkey[fno][kno],&recno[fno],lastks);
  1243.         lastks[0] = '\0';
  1244.       trecno = -1;
  1245.         if (ok) trecno = list_n_choose((byte)fno,(byte)kno,lastks,idxkey[fno][kno],findscrpos[fno][kno]);
  1246.       if (trecno == 0 && listAndAdd) trecno = add2CodeFile(fno);
  1247.         if (trecno > 0) {
  1248.             ok         = True;
  1249.             recno[fno] = trecno;
  1250.             link       = No_Link;
  1251.             getarec(fno);
  1252.             link       = Up_N_Down;
  1253.             strcopy(ks,makekey(lastks,fno,kno),0,strlen(ks));
  1254.         }
  1255.         else clear_rec(fno);
  1256.  
  1257.         ok          = tok;
  1258.         scrn_active = True;
  1259. ⁿIFDEF TABLESⁿ
  1260.         stabsiz = tabsize[filno];
  1261.         tabsize[filno] = 1;
  1262.         displayrec(filno,scrno);
  1263.         tabsize[filno] = stabsiz;
  1264. ⁿELSEDEFⁿ
  1265.         displayrec(filno,scrno);
  1266. ⁿENDDEFⁿ
  1267.     }
  1268.     fldnum--;
  1269.     listing = False;
  1270.     sout[0] = '\0';
  1271.     return(sout);
  1272. }
  1273.  
  1274. /* SN 3.5 - The complete Function was created for 3.5 */
  1275.  
  1276. strptr listadd(strptr sout, int fno, int kno, keystr aKey)
  1277. {
  1278.    listAndAdd = True;
  1279.    list(sout, fno, kno, aKey);
  1280.    listAndAdd = False;
  1281.    return(sout);
  1282. }
  1283.  
  1284. ⁿIFDEF ADJUSTⁿ
  1285. void afteradjdisp(int fno)
  1286. {
  1287.     int i;
  1288.  
  1289.     for (i = 1; i <= fno; i++) if (afteradj[fno][i] > 0) {
  1290.         (uw.wa[winforfile[i]])->disp = False;
  1291. ⁿIFDEF TABLESⁿ
  1292.         link = No_Link;
  1293.         displayrec(0,winforfile[i]);
  1294.         link = Up_N_Down;
  1295. ⁿELSEDEFⁿ
  1296.         displayrec(filno,winforfile[i]);
  1297. ⁿENDDEFⁿ
  1298.         afteradjdisp(i);
  1299.         hidewin(T_ON,uw.wa[winforfile[i]]);
  1300.     }
  1301. }
  1302.  
  1303. void updatekeys(int f)
  1304. {
  1305.     int i;
  1306.     keystr key;
  1307.  
  1308.     for (i=1; i <= maxkeyno; i++) {
  1309.         getakey(key,f,i);
  1310. ⁿIFDEF MUSERⁿ
  1311.         must_secure_index(f,i,Lock);
  1312.         deletekey(idxkey[f][i],&recno[f],tkeytab[i]);
  1313.         addkey(idxkey[f][i],&recno[f],key);
  1314.         must_secure_index(f,1,UnLock);
  1315. ⁿELSEDEFⁿ
  1316.         deletekey(idxkey[f][i],&recno[f],tkeytab[i]);
  1317.         addkey(idxkey[f][i],&recno[f],key);
  1318. ⁿENDDEFⁿ
  1319.         if (!ok) dberrm(LSC_BadAdjust);
  1320.     }
  1321. }
  1322.  
  1323. void adjust(int fno, uchar mode)
  1324. {
  1325.     int i;
  1326.  
  1327.     switch (fno) {
  1328.         ⁿadjustⁿ
  1329.     }
  1330. }
  1331. ⁿENDDEFⁿ
  1332.  
  1333. ⁿIFDEF LINKEDⁿ
  1334. void setlinkage(int fno)
  1335. {
  1336.     switch (fno) {
  1337.         ⁿsetlinkⁿ
  1338.     }
  1339. }
  1340. ⁿENDDEFⁿ
  1341.  
  1342. void remove_keys(int badkey)
  1343. {
  1344.     long recd;
  1345.     int keyno;
  1346.  
  1347.     for (keyno = 1; keyno <= (badkey-1); keyno++)
  1348.         if (strcmp(savkey[keyno],tkeytab[keyno]) != 0) {
  1349.             recd = recno[filno];
  1350. ⁿIFDEF MUSERⁿ
  1351.             must_secure_index(filno,keyno,Lock);
  1352.             deletekey(idxkey[filno][keyno],&recd,tkeytab[keyno]);
  1353.             must_secure_index(filno,keyno,UnLock);
  1354. ⁿELSEDEFⁿ
  1355.             deletekey(idxkey[filno][keyno],&recd,tkeytab[keyno]);
  1356. ⁿENDDEFⁿ
  1357.         }
  1358. }
  1359.  
  1360. ⁿIFDEF LINKEDⁿ
  1361. void putlink(int nummer)
  1362. {
  1363.     string tkey;
  1364.     long trecno;
  1365.     int tf;
  1366.  
  1367.     do {
  1368.         strcpy(key,savelnk[nummer]);
  1369.         strcpy(tkey,key);
  1370.         searchkey(idxkey[nummer][1],&recno[nummer],key);
  1371.         ok = (bool)(ok && (strsearch(key,tkey) == key));
  1372.         if (ok) {
  1373. ⁿIFDEF MUSERⁿ
  1374.             must_secure_rec(nummer,recno[nummer],1);
  1375. ⁿENDDEFⁿ
  1376.             link = No_Link;
  1377.             getarec(nummer);
  1378.             link = Up_N_Down;
  1379.             for (tf = 1; tf <= maxkeyno; tf++)
  1380.                 getakey(savkey[tf],nummer,tf);
  1381.             for (tf = 1; tf <= maxfilno; tf++)
  1382.                 if (linkback[tf].f == nummer) getlink(savelnk[tf],tf);
  1383.             setlinkage(nummer);
  1384.             putarec(nummer);
  1385.             for (tf = 1; tf <= maxkeyno; tf++) {
  1386.                 getakey(tkey,nummer,tf);
  1387.                 if (strcmp(savkey[tf],tkey) != 0) {
  1388. ⁿIFDEF MUSERⁿ
  1389.                     must_secure_index(nummer,tf,Lock);
  1390.                     deletekey(idxkey[nummer][tf],&recno[nummer],savkey[tf]);
  1391.                     addkey(idxkey[nummer][tf],&recno[nummer],tkey);
  1392.                     must_secure_index(nummer,tf,UnLock);
  1393. ⁿELSEDEFⁿ
  1394.                     deletekey(idxkey[nummer][tf],&recno[nummer],savkey[tf]);
  1395.                     addkey(idxkey[nummer][tf],&recno[nummer],tkey);
  1396. ⁿENDDEFⁿ
  1397.                 }
  1398.             }
  1399.             for (tf = 1; tf <= maxfilno; tf++)
  1400.                 if ((linkback[tf].f == nummer) &&       filinuse[tf] &&
  1401.                         (strcmp(savelnk[tf],getlink(tkey,tf)) != 0)) putlink(tf);
  1402. ⁿIFDEF MUSERⁿ
  1403.             tv = lock_datf(datf[nummer],recno[nummer],UnLock);
  1404. ⁿENDDEFⁿ
  1405.         }
  1406.     } while (ok);
  1407.     ok = True;
  1408. }
  1409. ⁿENDDEFⁿ
  1410.  
  1411. void edit_record(void)
  1412. {
  1413.     bool changedkey;
  1414.     int fno,tf,keyno;
  1415.     long trecno;
  1416.     keystr tk;
  1417.  
  1418. ⁿIFDEF MEMOSⁿ
  1419.    editmode = True;
  1420. ⁿENDDEFⁿ
  1421.  
  1422.    lastrecop = _Edit;
  1423.  
  1424. ⁿIFDEF MUSERⁿ
  1425.     ok = True;
  1426.    tf = filno;
  1427.    trecno = recno[filno];
  1428. ⁿIFDEF LINKEDⁿ
  1429.     if (linkback[filno].f > 0) traceback(filno); else {
  1430.         getakey(key,filno,1);
  1431.         findmulti(filno,&recno[filno],key);
  1432.     }
  1433. ⁿELSEDEFⁿ
  1434.     getakey(key,filno,1);
  1435.     findmulti(filno,&recno[filno],key);
  1436. ⁿENDDEFⁿ
  1437.     displayrec(filno,scrno);
  1438.     if ((filno != tf) || (recno[filno] != trecno) || !ok) {
  1439.         dspmsge(LSC_Warning,LSC_SomeoneDeleted,4.0);
  1440.         return;
  1441.     }
  1442.     if (lock_datf(datf[filno],recno[filno],Lock) != 0) {
  1443.         audible(Error);
  1444.         dspmsge(LSC_Warning,LSC_EditRecInUse,4.0);
  1445.     }
  1446.     else if (status_ok(filno)) {
  1447. ⁿELSEDEFⁿ
  1448.     if (status_ok(filno)) {
  1449. ⁿENDDEFⁿ
  1450.         getarec(filno);
  1451.         displayrec(filno,scrno);
  1452.         for (keyno = 1; keyno <= maxkeyno; keyno++)
  1453.              getakey(savkey[keyno],filno,keyno);
  1454. ⁿIFDEF LINKEDⁿ
  1455.         for (fno = 1; fno <= maxfilno; fno++) if (linkback[fno].f == filno)
  1456.             getlink(savelnk[fno],fno);
  1457. ⁿENDDEFⁿ
  1458. ⁿIFDEF ADJUSTⁿ
  1459.         adjust(filno,'D');
  1460. ⁿENDDEFⁿ
  1461.         edit_rec(0);
  1462.         changedkey = False;
  1463. ⁿIFDEF ADJUSTⁿ
  1464. ⁿIFDEF LINKEDⁿ
  1465. ⁿIFDEF MUSERⁿ
  1466.         for (fno = 1; fno <= maxfilno; fno++)
  1467.             if ((linkback[fno].f == filno) && filinuse[fno] && multiuser &&
  1468.                     (strcmp(savelnk[fno],getlink(tk,fno)) != 0)) {
  1469.                 dberrm(LSC_PreserveLink);
  1470.                 exitcode = QitKey;
  1471.             }
  1472. ⁿENDDEFⁿ
  1473. ⁿENDDEFⁿ
  1474. ⁿENDDEFⁿ
  1475.         if (exitcode != QitKey) {
  1476.             keyno = 1;
  1477.             while ((keyno <= maxkeyno) && (exitcode != QitKey)) {
  1478.                 getakey(tkeytab[keyno],filno,keyno);
  1479.                 if (strcmp(tkeytab[keyno],savkey[keyno]) == 0)
  1480.                     ok = True;
  1481.                 else {
  1482. ⁿIFDEF MUSERⁿ
  1483.                     must_secure_index(filno,keyno,Lock);
  1484.                     addkey(idxkey[filno][keyno],&recno[filno],tkeytab[keyno]);
  1485.                     must_secure_index(filno,keyno,UnLock);
  1486. ⁿELSEDEFⁿ
  1487.                     addkey(idxkey[filno][keyno],&recno[filno],tkeytab[keyno]);
  1488. ⁿENDDEFⁿ
  1489.                     if (!ok) {
  1490.                         remove_keys(keyno);
  1491.                         audible(Error);
  1492.                         dspmsge(LSC_BaseError,LSC_KeyExists,4.0);
  1493.                         edit_rec(keyfld[filno][keyno]);
  1494.                         keyno = 0;
  1495.                     }
  1496.                 }
  1497.                 keyno++;
  1498.             }
  1499.             if (exitcode != QitKey) {
  1500.                 for (keyno = 1; keyno <= maxkeyno; keyno++)
  1501.                     if (strcmp(tkeytab[keyno],savkey[keyno]) != 0) {
  1502.                         changedkey = True;
  1503.                         strcpy(tk,tkeytab[keyno]);
  1504.                         strcpy(tkeytab[keyno],savkey[keyno]);
  1505.                         strcpy(savkey[keyno],tk);
  1506.                     }
  1507.                 remove_keys(maxkeyno+1);
  1508.                 putarec(filno);
  1509. ⁿIFDEF LINKEDⁿ
  1510.                 for (fno = 1; fno <= maxfilno; fno++)
  1511.                     if ((linkback[fno].f == filno) &&
  1512.                             (linkback[fno].t == _Unique) &&
  1513.                             filinuse[fno] &&
  1514.                             (strcmp(savelnk[fno],getlink(tk,fno)) != 0)) putlink(fno);
  1515. ⁿENDDEFⁿ
  1516.             }
  1517.             else ok = True;
  1518.         }
  1519.         getarec(filno);
  1520. ⁿIFDEF ADJUSTⁿ
  1521.         adjust(filno,'A');
  1522.         afteradjdisp(filno);
  1523. ⁿENDDEFⁿ
  1524. ⁿIFDEF TABLESⁿ
  1525.         if ((tabsize[filno] > 1) && changedkey) {
  1526.             getakey(savkey[1],filno,1);
  1527.             findmulti(filno,&recno[filno],savkey[1]);
  1528.             align_tab(filno);
  1529.         }
  1530. ⁿENDDEFⁿ
  1531.         displayrec(filno,scrno);
  1532. ⁿIFDEF MUSERⁿ
  1533.         tv = lock_datf(datf[filno],recno[filno],UnLock);
  1534. ⁿENDDEFⁿ
  1535.  
  1536.    lastrecop = Nul;
  1537.  
  1538. ⁿIFDEF MEMOSⁿ
  1539.    editmode = False;
  1540. ⁿENDDEFⁿ
  1541.     }
  1542. }
  1543.  
  1544. ⁿIFDEF MEMOSⁿ
  1545. void deletememos(void *fb, void *buf, int fno)
  1546. {
  1547.     word w;
  1548.     long mrec,trec;
  1549.     genbuf sbuf;
  1550.     fldblk *fblk;
  1551.     fldtyp *fld;
  1552.     byteptr buffer;
  1553.  
  1554.     fblk = (fldblk *) fb;
  1555.     buffer = (byteptr) buf;
  1556.     memmove(&sbuf[1],buf,fblk->dsz);
  1557.     w = 0;
  1558.     do {
  1559.         fld = &(*fblk->farr)[w];
  1560.         if (fld->typ == _Memo) {
  1561.             memmove(&mrec,fld->faddr,4);
  1562.             while (mrec != 0) {
  1563.                 getrec(datf[fno],mrec,buf);
  1564.                 memmove(&trec,&buffer[(fblk->dsz-3)-1],4);
  1565.                 deleterec(datf[fno],mrec);
  1566.                 mrec = trec;
  1567.             }
  1568.             memmove(buf,&sbuf[1],fblk->dsz);
  1569.         }
  1570.         w++;
  1571.     } while (w < fblk->numf);
  1572. }
  1573. ⁿENDDEFⁿ
  1574.  
  1575. ⁿIFDEF MUSERⁿ
  1576. ⁿIFDEF LINKEDⁿ
  1577. bool lock_linked(int fno, int lck)
  1578. {
  1579.     bool savok, tb;
  1580.     int i, keyno;
  1581.     uchar ans[2];
  1582.     uchar tpic[2];
  1583.     keystr tkey, tkey2;
  1584.  
  1585.    strcpy(ans, " ");
  1586.    strcpy(tpic, " ");
  1587.     tb      = True;
  1588.    ans[0]  = _Retry;
  1589.    tpic[0] = Pic_U;
  1590.     if (fno != filno) {        /* "filno" Already Locked By Delete_Record */
  1591.         do {
  1592.             tv = lock_datf(datf[fno],recno[fno],lck);
  1593.             if (tv == -1)
  1594.                 dbgetstr(ans,_Ch,LSC_LinkedDelRecInUse,ans,tpic,"",chkabortretry,nohelp);
  1595.         } while ((tv != 0) && (ans[0] != _Abort));
  1596.     }
  1597.     tb = (ans[0] == _Retry);
  1598.     if (tb) {
  1599.         link = No_Link;
  1600.         getarec(fno);
  1601.         link = Up_N_Down;
  1602.         for (i = 1; i <= maxfilno; i++) {
  1603.             if ((linkback[i].t == _Unique) && (linkback[i].f == fno)) {
  1604.                 if (filinuse[i]) {
  1605.                     getlink(tkey,i);  strcpy(tkey2,tkey);
  1606.                     searchkey(idxkey[i][1],&recno[i],tkey2);
  1607.                     savok = (bool)(ok && (strsearch(tkey2,tkey) == tkey2));
  1608.                     while (savok && tb) {
  1609.                         tb = lock_linked(i,lck);
  1610.                         nextkey(idxkey[i][1],&recno[i],tkey2);
  1611.                         savok = (bool)(ok && (strsearch(tkey2,tkey) == tkey2));
  1612.                     }
  1613.                     ok = True;  /* Restore OK to True */
  1614.                 }
  1615.             }
  1616.         }
  1617.     }
  1618.     return(tb);
  1619. }
  1620. ⁿENDDEFⁿ
  1621. ⁿENDDEFⁿ
  1622.  
  1623. void delarec(int fno)
  1624. {
  1625.     string tkey,tkey2;
  1626.     bool savok;
  1627.     int i,keyno;
  1628.     long delrecno;
  1629.  
  1630. ⁿIFDEF MUSERⁿ
  1631.   lockByDel[fno] = True;
  1632. ⁿENDDEFⁿ
  1633. ⁿIFDEF LINKEDⁿ
  1634. ⁿIFDEF MUSERⁿ
  1635.     if (fno == filno) {
  1636.         savok = lock_linked(fno,Lock);
  1637.         if (!savok) {
  1638.             savok = lock_linked(fno,UnLock); nextrec = recno[fno]; return;
  1639.         }
  1640.     }
  1641. ⁿENDDEFⁿ
  1642.     getarec(fno);
  1643.     for (i = 1; i <= maxfilno; i++) {
  1644.         if ((linkback[i].t == _Unique) && (linkback[i].f == (byte)fno)) {
  1645.             if (filinuse[i]) {
  1646.                 getlink(tkey,i);
  1647.                 strcpy(tkey2,tkey);
  1648.                 do {
  1649.                     searchkey(idxkey[i][1],&recno[i],tkey2);
  1650.                     savok = (bool)(ok && (strsearch(tkey2,tkey) == tkey2));
  1651.                     if (savok) delarec(i);
  1652.                 } while (savok);
  1653.             }
  1654.         }
  1655.     }
  1656. ⁿELSEDEFⁿ
  1657.     getarec(fno);
  1658. ⁿENDDEFⁿ
  1659.     delrecno = recno[fno];
  1660. ⁿIFDEF MUSERⁿ
  1661.     if (fno != filno) must_secure_rec(fno,0L,2);
  1662. ⁿENDDEFⁿ
  1663. ⁿIFDEF MEMOSⁿ
  1664.     switch (fno) {
  1665.         ⁿDELMEMOSⁿ
  1666.     }
  1667. ⁿENDDEFⁿ
  1668.     deleterec(datf[fno], delrecno);
  1669.     for (keyno = 1; keyno <= maxkeyno; keyno++) {
  1670.         if (keylen[fno][keyno] > 0) {
  1671.             delrecno = recno[fno];
  1672.             getakey(tkey,fno,keyno);
  1673. ⁿIFDEF MUSERⁿ
  1674.             must_secure_index(fno,keyno,Lock);
  1675.             deletekey(idxkey[fno][keyno],&delrecno,tkey);
  1676.             must_secure_index(fno,keyno,UnLock);
  1677. ⁿELSEDEFⁿ
  1678.             deletekey(idxkey[fno][keyno],&delrecno,tkey);
  1679. ⁿENDDEFⁿ
  1680.         }
  1681.     }
  1682. ⁿIFDEF ADJUSTⁿ
  1683.     adjust(fno,'D');
  1684. ⁿENDDEFⁿ
  1685. ⁿIFDEF MUSERⁿ
  1686.     if (fno != filno) {
  1687.         tv = lock_datf(datf[fno],recno[fno],UnLock);
  1688.         tv = lock_datf(datf[fno],0L,UnLock);
  1689.     }
  1690. ⁿENDDEFⁿ
  1691. ⁿIFDEF MUSERⁿ
  1692.   lockByDel[fno] = False;
  1693. ⁿENDDEFⁿ
  1694. }
  1695.  
  1696. void delete_record(void)
  1697. {
  1698.     byte i,ch;
  1699.     long trecno;
  1700.     keystr nxtkey;
  1701.     bool tok,child;
  1702.     int tf;
  1703.     string msg;
  1704.  
  1705.    lastrecop = _Delete;
  1706. ⁿIFDEF MUSERⁿ
  1707.     ok = True;
  1708.     tf = filno;
  1709.     trecno = recno[filno];
  1710. ⁿIFDEF LINKEDⁿ
  1711.     if (linkback[filno].f > 0) traceback(filno); else {
  1712.         getakey(key,filno,1);
  1713.         findmulti(filno,&recno[filno],key);
  1714.     }
  1715. ⁿELSEDEFⁿ
  1716.     getakey(key,filno,1);
  1717.     findmulti(filno,&recno[filno],key);
  1718. ⁿENDDEFⁿ
  1719.     displayrec(filno,scrno);
  1720.     if ((filno != tf) || (recno[filno] != trecno) || !ok) {
  1721.         dspmsge(LSC_Warning,LSC_SomeoneDeleted,4.0);
  1722.         return;
  1723.     }
  1724.     if (lock_datf(datf[filno],0L,Lock) != 0) {
  1725.         audible(Error);
  1726.         dspmsge(LSC_Warning,LSC_StatusUnavail,4.0);
  1727.     }
  1728.     else if (lock_datf(datf[filno],recno[filno],Lock) != 0) {
  1729.         audible(Error);
  1730.         dspmsge(LSC_Warning,LSC_DelRecInUse,4.0);
  1731.         tv = lock_datf(datf[filno],0L,UnLock);
  1732.     }
  1733.     else if (status_ok(filno)) {
  1734. ⁿELSEDEFⁿ
  1735.     if (status_ok(filno)) {
  1736. ⁿENDDEFⁿ
  1737.         getarec(filno);
  1738.         displayrec(filno,scrno);
  1739. ⁿIFDEF LINKEDⁿ
  1740.         child = False;
  1741.         for (i = 1; i <= maxfilno; i++)
  1742.             child = (bool)(child || ((linkback[i].f == (byte)filno) && (filinuse[i])));
  1743.         strcpy(msg,(child) ? LSC_DelLinkedRec : LSC_ConfirmDelRec);
  1744. ⁿELSEDEFⁿ
  1745.         strcpy(msg, LSC_ConfirmDelRec);
  1746. ⁿENDDEFⁿ
  1747.         do {
  1748.             dspmsge(LSC_Warning,msg,0.0);
  1749.             ch = upperch(getkey());
  1750.         } while ((ch !=_YES) && (ch != QitKey));
  1751.         if (ch == _YES) {
  1752.             trecno = recno[filno];
  1753.             prevkey(idxkey[filno][1],&recno[filno],key);
  1754.             if (ok) {
  1755.                 strcpy(nxtkey,key);
  1756.                 nextrec = recno[filno];
  1757.             }
  1758.             tok = ok;
  1759.             nextkey(idxkey[filno][1],&recno[filno],key);
  1760.             if (recno[filno] != trecno) {
  1761.                 audible(Error);
  1762.                 dspmsge(LSC_BaseError,LSC_CorruptIndex,4.0);
  1763.                 getarec(filno);
  1764.                 displayrec(filno,scrno);
  1765.             }
  1766.             else {
  1767.                 ok = True;
  1768.         message(NULL, LSC_Deleting);
  1769.                 delarec(filno);
  1770.         message(NULL, "");
  1771. ⁿIFDEF ADJUSTⁿ
  1772.                 afteradjdisp(filno);
  1773. ⁿENDDEFⁿ
  1774.                 if (tok) {
  1775.                     recno[filno] = nextrec;
  1776.                     findmulti(filno,&recno[filno],nxtkey);
  1777.                     if (ok) {
  1778.                         getarec(filno);
  1779. ⁿIFDEF TABLESⁿ
  1780.                         if (tabsize[filno] != 1) align_tab(filno);
  1781. ⁿENDDEFⁿ
  1782.                         if (status_ok(filno)) displayrec(filno,scrno); else top_record();
  1783.                     }
  1784.                     else top_record();
  1785.                 }
  1786.                 else top_record();
  1787.             }
  1788.         }
  1789. ⁿIFDEF MUSERⁿ
  1790.         tv = lock_datf(datf[filno],trecno,UnLock);
  1791.         tv = lock_datf(datf[filno],0L,UnLock);
  1792. ⁿENDDEFⁿ
  1793.     }
  1794.     else audible(Warning);
  1795. }
  1796.  
  1797. strptr autoinc(keystr sout, int kno)
  1798. {
  1799.    float tl = 1;                                      /* SN 3.5 */
  1800.    char  tempString1[10],                             /* SN 3.5 */
  1801.     tempString2[10],                                   /* SN 3.5 */
  1802.     tempString3[10],                                   /* SN 3.5 */
  1803.     tempString4[10],                                   /* SN 3.5 */
  1804.     tempString5[10],                                   /* SN 3.5 */
  1805.     fileName[20];                                      /* SN 3.5 */
  1806.  
  1807.     clearkey(idxkey[filno][kno]);
  1808.     prevkey(idxkey[filno][kno],&recno[filno],key);
  1809.  
  1810.     if (!ok) strcpy(sout,"1");
  1811.     else     strip(sout,fstr(sout,valu(key)+1,11,0));
  1812.  
  1813. ⁿIFDEF MUSERⁿ
  1814.    if (multiuser) {                                         /* SN 3.5 */
  1815.       *fileName    = *tempString1 = *tempString2 = Nul;
  1816.       *tempString3 = *tempString4 = *tempString5 = Nul;
  1817.       istr(tempString4, filno, 2);
  1818.       istr(tempString5, kno,   2);
  1819.       strip(tempString2, tempString4);
  1820.       strip(tempString3, tempString5);
  1821.       strcopy(tempString1, "ⁿMODNAMEⁿ", 0, 5);
  1822.       strconcat(fileName, "~", tempString1, tempString2, tempString3, NULL);
  1823.       tl = txtinc(fileName, tl);
  1824.       fstr(sout, tl, 11, 0);
  1825.    }
  1826. ⁿENDDEFⁿ
  1827.     return (strip(tempString1, sout));
  1828. }
  1829.  
  1830. void addarec(void)
  1831. {
  1832.     switch (filno) {
  1833.         ⁿADDRECⁿ
  1834.     }
  1835. }
  1836.  
  1837. void add_record(char func)
  1838. {
  1839. ⁿIFDEF TABLESⁿ
  1840.     byte stabsiz,stabidx;
  1841. ⁿENDDEFⁿ
  1842.     int fno;
  1843.     long savr,recd;
  1844.     int tf,keyno;
  1845.     bool rav;
  1846.     string tts;
  1847.  
  1848.    lastrecop = func;
  1849.     rav              = True;
  1850. ⁿIFDEF LINKEDⁿ
  1851. ⁿIFDEF MUSERⁿ
  1852.     if (linkback[filno].f > 0) {
  1853.         tf = filno;
  1854.         traceback(filno);
  1855.         displayrec(filno,scrno);
  1856.         if (filno != tf) {
  1857.             dspmsge(LSC_Warning,LSC_SomeoneDeleted,4.0);
  1858.             return;
  1859.         }
  1860.     }
  1861. ⁿENDDEFⁿ
  1862.     if (linkback[filno].f > 0) rav = recavail[linkback[filno].f];
  1863. ⁿENDDEFⁿ
  1864.     if ((usedrecs(datf[filno]) >= maxrec[filno]) || !rav) {
  1865.         if (rav) dspmsge("",LSC_MaxRecsReached,4.0);
  1866.         else     dspmsge("",LSC_NoParentRec,4.0);
  1867.     }
  1868.     else {
  1869.         if (ok) savr = recno[filno]; else savr = 0;
  1870.         scrn_active = False;
  1871.         cleartop = (bool)(func == 'A');
  1872.         clear_rec(filno);
  1873.         scrn_active = True;
  1874. ⁿIFDEF MEMOSⁿ
  1875.         if (!cleartop)
  1876.             switch (filno) {
  1877.                 ⁿCLEARMEMOⁿ
  1878.             }
  1879. ⁿENDDEFⁿ
  1880.         cleartop = True;
  1881.         ⁿSETFIELDⁿ
  1882. ⁿIFDEF TABLESⁿ
  1883.         stabsiz = 1;
  1884.         if (tabsize[filno] > 1) {
  1885.             stabidx = tabidx[filno];
  1886.             if (tabidx[filno] == tabsize[filno])
  1887.                 tabidx[filno] = 1;
  1888.             else
  1889.                 tabidx[filno] = tabused[filno]+1;
  1890.             stabsiz = tabsize[filno];
  1891.             tabsize[filno] = 1;
  1892.         }
  1893.         leaveclear = True;
  1894. ⁿENDDEFⁿ
  1895.         displayrec(filno,scrno);
  1896.         edit_rec(0);
  1897.         if (exitcode != QitKey) {
  1898. ⁿIFDEF MUSERⁿ
  1899.             must_secure_rec(filno,0L,2);
  1900.             addarec();
  1901.             tv = lock_datf(datf[filno],recno[filno],Lock);
  1902.             tv = lock_datf(datf[filno],0L,UnLock);
  1903. ⁿELSEDEFⁿ
  1904.             addarec();
  1905. ⁿENDDEFⁿ
  1906.             for (keyno = 1; keyno <= maxkeyno; keyno++) savkey[keyno][0] = '\0';
  1907.             keyno = 1;
  1908.             ok      = True;
  1909.             while ((keyno <= maxkeyno) && (exitcode != QitKey)) {
  1910.                 if (keylen[filno][keyno] > 0) {
  1911.                     getakey(tkeytab[keyno],filno,keyno);
  1912. ⁿIFDEF MUSERⁿ
  1913.                     must_secure_index(filno,keyno,Lock);
  1914.                     addkey(idxkey[filno][keyno],&recno[filno],tkeytab[keyno]);
  1915.                     must_secure_index(filno,keyno,UnLock);
  1916. ⁿELSEDEFⁿ
  1917.                     addkey(idxkey[filno][keyno],&recno[filno],tkeytab[keyno]);
  1918. ⁿENDDEFⁿ
  1919.                     if (!ok) {
  1920.                         remove_keys(keyno);
  1921.                         audible(Error);
  1922.                         dspmsge(LSC_BaseError,LSC_KeyExists,4.0);
  1923.                         edit_rec(keyfld[filno][keyno]);
  1924.                         if (exitcode == QitKey) {
  1925.                             recd = recno[filno];
  1926. ⁿIFDEF MUSERⁿ
  1927.                             must_secure_rec(filno,0L,2);
  1928.                             deleterec(datf[filno],recd);
  1929.                             tv = lock_datf(datf[filno],0L,UnLock);
  1930. ⁿELSEDEFⁿ
  1931.                             deleterec(datf[filno],recd);
  1932. ⁿENDDEFⁿ
  1933.                             recno[filno] = savr;
  1934.                         }
  1935.                         else {
  1936.                             keyno = 0;
  1937.                             putarec(filno);
  1938.                         }
  1939.                     }
  1940.                 }
  1941.                 keyno++;
  1942.             }
  1943. ⁿIFDEF ADJUSTⁿ
  1944.             if (exitcode != QitKey) {
  1945.                 adjust(filno,'A');
  1946.                 afteradjdisp(filno);
  1947.             }
  1948. ⁿENDDEFⁿ
  1949. ⁿIFDEF MUSERⁿ
  1950.             tv = lock_datf(datf[filno],recno[filno],UnLock);
  1951. ⁿENDDEFⁿ
  1952.         }
  1953.         else recno[filno] = savr;
  1954.         if (exitcode == QitKey) {
  1955. ⁿIFDEF TABLESⁿ
  1956.             if (stabsiz > 1) tabidx[filno] = stabidx;
  1957. ⁿENDDEFⁿ
  1958. ⁿIFDEF MEMOSⁿ
  1959. ⁿIFDEF MUSERⁿ
  1960.             must_secure_rec(filno,0L,2);
  1961. ⁿENDDEFⁿ
  1962.             fno = filno;
  1963.             switch (fno) {
  1964.                 ⁿDELMEMOSⁿ
  1965.             }
  1966. ⁿIFDEF MUSERⁿ
  1967.             tv = lock_datf(datf[filno],0L,UnLock);
  1968. ⁿENDDEFⁿ
  1969. ⁿENDDEFⁿ
  1970.         }
  1971. ⁿIFDEF TABLESⁿ
  1972.         if (stabsiz > 1) tabsize[filno] = stabsiz;
  1973.         leaveclear = False;
  1974. ⁿENDDEFⁿ
  1975.         ok = (bool)(ok || (savr > 0));
  1976.         getarec(filno);
  1977. ⁿIFDEF TABLESⁿ
  1978.         if ((exitcode != QitKey) && (tabsize[filno] > 1)) {
  1979.             getakey(skey,filno,1);
  1980.             findmulti(filno,&recno[filno],skey);
  1981.             align_tab(filno);
  1982.         }
  1983. ⁿENDDEFⁿ
  1984.         displayrec(filno,scrno);
  1985.     }
  1986.    lastrecop = Nul;
  1987. }
  1988.  
  1989. void initialize(void)
  1990. {
  1991.    ⁿKEYFIELDⁿ
  1992.    command    = Cmd_No_Command;
  1993.    deltas     = def1.deltat;
  1994.     keynum     = 1;
  1995.     scrno      = 1;
  1996.     _trace     = 0;
  1997.     menuanchor = 0;
  1998.     link       = Up_N_Down;
  1999.     listing    = False;
  2000.    listAndAdd = False;
  2001. ⁿIFDEF TABLESⁿ
  2002.     leaveclear = False;
  2003.     switchtab = False;
  2004. ⁿENDDEFⁿ
  2005.     scrn_active = False;
  2006.     cleartop = True;
  2007.     for (filno = 1; filno <= maxfilno; filno++) {
  2008.         recno[filno] = 0;
  2009. ⁿIFDEF MUSERⁿ
  2010.     lockByDel[filno] = False;
  2011. ⁿENDDEFⁿ
  2012. ⁿIFDEF TABLESⁿ
  2013.         tabrecno[filno] = 0;
  2014. ⁿENDDEFⁿ
  2015. ⁿIFDEF LINKEDⁿ
  2016.         clear_rec(filno);
  2017. ⁿELSEDEFⁿ
  2018.         top_record();
  2019. ⁿENDDEFⁿ
  2020.         recavail[filno] = (bool)(usedrecs(datf[filno]) > 0);
  2021. ⁿIFDEF TABLESⁿ
  2022.         tabidx[filno] = 1; tabused[filno] = 0;
  2023. ⁿENDDEFⁿ
  2024.     }
  2025. ⁿIFDEF LINKEDⁿ
  2026.     for (filno = 1; filno <= maxfilno; filno++) if (linkback[filno].f == 0) top_record();
  2027. ⁿENDDEFⁿ
  2028.     scrn_active = True;
  2029.     filno = 1;
  2030. }
  2031.  
  2032. bool custom_key(int scr, int fno, int *fld, uchar *key)
  2033. {
  2034.     bool tb;
  2035.  
  2036.     ⁿcodedispⁿ
  2037.     return(False);
  2038. }
  2039.  
  2040. void on_error(void)
  2041. {
  2042.     closefiles();
  2043. }
  2044.  
  2045. void swapmenu(void)
  2046. {
  2047.     bool savdisp;
  2048.     byte ni,tl,tw,tlen;
  2049.     itmptr titm;
  2050.     mnuptr m;
  2051.  
  2052.     savdisp = (bool)((dm.curmnu->winp != NULL) && dm.curmnu->winp->disp);
  2053.     if (savdisp) zapmnu(&dm,dm.curmnu);
  2054.     m = dm.curmnu;
  2055.     m->mtyp = (byte)((m->mtyp == Vert) ? 2 : Vert);
  2056.     tw = 1; ni = 0; tl = 0;
  2057.     titm = m->fitm;
  2058.     do {
  2059.         ni++; tl += m->mtyp;
  2060.         if (m->mtyp == Vert) { titm->ix = 2; titm->iy = ni; }
  2061.         else { titm->ix = tl; titm->iy = 1; }
  2062.         tlen = (byte)strlen(titm->prompt); tl += tlen;
  2063.         if (tlen > tw) tw = tlen;
  2064.         titm = titm->nitm;
  2065.     } while (titm != m->fitm);
  2066.     if (m->mtyp == Vert) { m->widm = tw+2; m->hgtm = ni; }
  2067.     else { m->widm = tl+m->mtyp-2; m->hgtm = 1; }
  2068.     if (m->mtyp != Vert) {
  2069.         m->ym = (m->xm == 2) ? 1 : scrhgt;
  2070.         m->xm = 1; m->mbchrs[0] = '\0';
  2071.     }
  2072.     else {
  2073.         if (m->ym == 1) { m->ym = 2; m->xm = scrwid-m->widm; }
  2074.         else { m->ym = scrhgt-m->hgtm; m->xm = 2; }
  2075.         m->mbchrs[0] = '─';
  2076.     }
  2077.     if (savdisp) dspmnu(&dm,dm.curmnu);
  2078.     menuanchor = (menuanchor+1) % 4;
  2079. }
  2080.  
  2081. void changeto(pathstr newpath, int *res)
  2082. {
  2083.     *res = (changedir(newpath)) ? 0 : 1;
  2084.     if (*res == 0) {
  2085.         getcurrentdir(datapath,0);
  2086.         pathSwap = True;
  2087.     }
  2088. }
  2089.  
  2090. void newload(mnufrec *m, pathstr newmenu)
  2091. {
  2092.     int i;
  2093.     pathstr newnam;
  2094.  
  2095.     strcpy(newnam,newmenu);
  2096.     svm = smc;
  2097.     smc = db_malloc(sizeof(savmtyp));
  2098.     smc->savprv = svm;
  2099.     strcpy(smc->savnam,m->mnufnam);
  2100.     smc->savno = m->curmnu->mno;
  2101.     strcpy(smc->savprompt,m->curitm->prompt);
  2102.     if (dm.curitm->selpath[0] != '\0') {
  2103.         getcurrentdir(smc->savpath,0);
  2104.         changeto(dm.curitm->selpath,&i);
  2105.     }
  2106.     else {
  2107.         i = 0;
  2108.         smc->savpath[0] = '\0';
  2109.     }
  2110.     if (i == 0) {
  2111.         disposemnus(&dm);
  2112.         strcpy(dm.mnufnam,newnam);
  2113.         initmnu(&dm,0,0,OnDisk);
  2114.         dispallwin();
  2115.         if (dm.curmnu == NULL) {
  2116.             if (smc->savpath[0] != '\0')
  2117.                 changeto(smc->savpath,&i);
  2118.                 strcpy(dm.mnufnam,smc->savnam);
  2119.                 initmnu(&dm,0,0,OnDisk);
  2120.                 dispallwin();
  2121.                 jumptomnu(&dm,smc->savno);
  2122.                 do
  2123.                     dm.curitm = dm.curitm->nitm;
  2124.                 while ((strcmp(smc->savnam,dm.curitm->prompt) != 0) &&
  2125.                                 (dm.curitm != dm.curmnu->fitm));
  2126.                 db_free(smc);
  2127.                 smc = svm;
  2128.             }
  2129.             else {
  2130.                 dspmnu(&dm,dm.curmnu);
  2131.             }
  2132.         }
  2133.         else {
  2134.             db_free(smc);
  2135.             smc = svm;
  2136.             doserr(3,dm.curitm->selpath);
  2137.         }
  2138.     pathSwap = True;
  2139. }
  2140.  
  2141. void setcommand(byte c_num)
  2142. {
  2143.     switch(c_num) {
  2144.       case 1 :  command = Cmd_Next_Record;    break;
  2145.       case 2 :  command = Cmd_Prev_Record;    break;
  2146.       case 3 :  command = Cmd_Find_Record;    break;
  2147.       case 4 :  command = Cmd_Top_Record;     break;
  2148.       case 5 :  command = Cmd_Last_Record;    break;
  2149.       case 6 :  command = Cmd_Edit_Record;    break;
  2150.       case 7 :  command = Cmd_Add_Record;     break;
  2151.       case 8 :  command = Cmd_Copy_Record;    break;
  2152.       case 9 :  command = Cmd_Delete_Record;  break;
  2153.       case 10 : command = Cmd_Next_File;      break;
  2154.       case 11 : command = Cmd_Prev_File;      break;
  2155.       case 12 : command = Cmd_Swap_Menu;      break;
  2156.    }
  2157. }
  2158.  
  2159. void do_proc(int procno, mnufrec *m)
  2160. {
  2161.    setcommand(procno);
  2162.    hidewin(T_OFF,dm.curmnu->winp);
  2163.     switch (procno) {
  2164.         case 1 : next_record(_Next); break;
  2165.         case 2 : next_record(_Prev); break;
  2166.         case 3 : find_record(); break;
  2167.         case 4 : if (status_ok(filno)) top_record(); else audible(Warning); break;
  2168.         case 5 : last_record(); break;
  2169.         case 6 : if (status_ok(filno)) {
  2170.             edit_record();
  2171.             getakey(key,filno,1);
  2172.             findmulti(filno,&recno[filno],key);
  2173.             if (!ok) top_record();
  2174.         }
  2175.         else audible(Warning); break;
  2176.         case 7 :
  2177.             add_record('A');
  2178.             getakey(key,filno,1);
  2179.             findmulti(filno,&recno[filno],key);
  2180.             if (!ok) top_record();
  2181.         break;
  2182.         case 8 : if (status_ok(filno)) {
  2183.             add_record('C');
  2184.             getakey(key,filno,1);
  2185.             findmulti(filno,&recno[filno],key);
  2186.             if (!ok) top_record();
  2187.         }
  2188.         else audible(Warning); break;
  2189.         case 9 : delete_record(); break;
  2190.         case 10: switch_file('+'); break;
  2191.         case 11: switch_file('-'); break;
  2192.         case 12: setdeltas(); break;
  2193.         case 13: swapmenu(); break;
  2194. /***************************************************************************
  2195. * [DG] 09/11/92 -- Added cases 101-116, which will switch instantly to     *
  2196. *                  files 1-16, by subtracting 100 from the case number.    *
  2197. *                  If the file number is larger than the maximum defined   *
  2198. *                  file, we switch to the highest valid file.              *
  2199. ***************************************************************************/
  2200.       case 101:
  2201.       case 102:
  2202.       case 103:
  2203.       case 104:
  2204.       case 105:
  2205.       case 106:
  2206.       case 107:
  2207.       case 108:
  2208.       case 109:
  2209.       case 110:
  2210.       case 111:
  2211.       case 112:
  2212.       case 113:
  2213.       case 114:
  2214.       case 115:
  2215.       case 116: filno = (procno - 100);
  2216.                 if (filno > maxfilno)  filno = maxfilno;
  2217.                 switch_file(' ');
  2218.                 break;
  2219. /***********************/ /* [DG] End Modification */ /*******************/
  2220.     }
  2221.    hidewin(T_ON,dm.curmnu->winp);
  2222.    dispwindow(dm.curmnu->winp);
  2223. }
  2224.  
  2225. void do_ctl(mnufrec *m, itmptr itm)
  2226. {
  2227.     string ts;
  2228.     uchar yes[2],tpic[2];
  2229.  
  2230.     if ((m->curmnu != NULL) && (itm != NULL)) {
  2231.         switch (itm->seltyp) {
  2232.             case _Proc : do_proc((int) ival(itm->selact),m); break;
  2233.             case _Menu :
  2234.                 if ((ival(itm->selact) > 0) && (m->mat[(int) ival(itm->selact)-1] != NULL)) {
  2235.                     if (m->mat[(int) ival(itm->selact)-1]->winp != NULL)
  2236.                         jumptomnu(m,(byte) ival(itm->selact));
  2237.                     else {
  2238.                         m->mat[(int) ival(itm->selact)-1]->pmnu = m->curmnu->mno;
  2239.                         m->curmnu = m->mat[(int) ival(itm->selact)-1];
  2240.                         dspmnu(m,m->curmnu);
  2241.                         m->curitm = m->curmnu->litm;
  2242.                         m->level = 0;
  2243.                     }
  2244.                 }
  2245.             break;
  2246.             case _Quit :
  2247.                 dbgetstr(ts,_Ch,LSC_QuitDataBase,chstr(yes,_YES),chstr(tpic,Pic_U),"",chkyesno,nohelp);
  2248.                 quit = (bool)((ts[0] == _YES) && (exitcode != QitKey));
  2249.             break;
  2250.         }
  2251.     }
  2252. }
  2253.  
  2254. bool initdbm(void)
  2255. {
  2256.     strcpy(dm.mnufnam,localmenu);
  2257.     initmnu(&dm,0,0,OnDisk);
  2258.     return (bool)(dm.curmnu != NULL);
  2259. }
  2260.  
  2261. void datenpath(void)
  2262. {
  2263.     string ts;
  2264.  
  2265.     if (uw.bgw != NULL) {
  2266.         if (mdate.x != 0)
  2267.             if (mdate.m == 0)
  2268.                 writewxy(datum(ts,sysdate(ts)),0,mdate.x,mdate.y,uw.bgw);
  2269.             else
  2270.                 writewxy(slash(ts,sysdate(ts)),0,mdate.x,mdate.y,uw.bgw);
  2271.         if (mpath.x != 0) {
  2272.             strcpy(ts,datapath);
  2273.             if (strlen(ts) == 3) strcat(ts,applname);
  2274.             else { strcat(ts,"\\"); strcat(ts,applname); }
  2275.             writewxy(ts,0,mpath.x,mpath.y,uw.bgw);
  2276.         }
  2277.     }
  2278. }
  2279.  
  2280. void do_menu(void)
  2281. {
  2282.     byte b;
  2283.     uchar ctlkey;
  2284.     int err;
  2285.     string ts;
  2286.     uchar yes[2],tpic[2];
  2287.  
  2288.     set_addmember(ExitSet,AltX);
  2289.     if (initdbm()) {
  2290.         for (b = 0; b < def1.anchor; b++) swapmenu();
  2291.         strcat(strcpy(uw.wfnam,applname),".DBW");
  2292.         err = initwin(&uw);
  2293.         if (err == 0) {
  2294.             if ((dm.curmnu->ym == 25) && (scrhgt > 25)) dm.curmnu->ym = scrhgt;
  2295.             datenpath();
  2296.             if (uw.bgw != NULL) uw.bgw->disp = True;
  2297.             strcat(strcpy(hw.wfnam,applname),".DBH");
  2298.             initwin(&hw);
  2299.             dispallwin();
  2300.             hidewin(T_ON,uw.wa[1]);
  2301.             top_record();
  2302.             quit = False;
  2303.             dspmnu(&dm,dm.curmnu);
  2304.             do {
  2305.                 if (dm.curitm->sec > gvar->sec) {
  2306.                     if (dm.curmnu->mtyp == Vert) goud(&dm,Down);
  2307.            else                         gorl(&dm,Right);
  2308.                 }
  2309.                 hbar(&dm);
  2310.                 tandk(0,0,uw.wa[scrno]);
  2311.                 ctlkey = upperch(getkey());
  2312.                 if ((dm.curitm->sec > gvar->sec) &&
  2313.                         ((ctlkey != AltX) && (ctlkey != AltL) && (ctlkey != QitKey)))
  2314.                     dberrm(LSC_MustLogOn);
  2315. // [DG] 09/09/1992
  2316. // Restructured switch statement to allow (mostly) CUA-compliant hot-keys
  2317.                 switch (ctlkey) {
  2318.                   case Enter    : if (gvar->sec >= dm.curitm->sec)
  2319.                                           do_ctl(&dm,dm.curitm); break;
  2320.                   case HlpKey   : itemhelp(&dm); break;
  2321. /* Next */    case CtrlRArr : do_proc( 1,&dm); break;
  2322. /* Prev */    case CtrlLArr : do_proc( 2,&dm); break;
  2323. /* Find */    case AltS     : do_proc( 3,&dm); break;
  2324. /* Top  */    case Home     : do_proc( 4,&dm); break;
  2325. /* Last */    case EndKey   : do_proc( 5,&dm); break;
  2326. /* Edit */    case CtrlEnter: do_proc( 6,&dm); break;
  2327. /* Add  */    case Ins      : do_proc( 7,&dm); break;
  2328. /* Copy */    case CtrlC    : do_proc( 8,&dm); break;
  2329. /* Del  */    case Del      : do_proc( 9,&dm); break;
  2330. /* +Fil */    case PgDn     : do_proc(10,&dm); break;
  2331. /* -Fil */    case PgUp     : do_proc(11,&dm); break;
  2332. /* ScSv */      case AltV     : do_proc(12,&dm); break;
  2333.                   case UArr     : if (dm.curmnu->mtyp != Vert) do_proc(2,&dm);
  2334.                                          else goud(&dm,Up); break;
  2335.                   case DArr     : if (dm.curmnu->mtyp != Vert) do_proc(1,&dm);
  2336.                                          else goud(&dm,Down); break;
  2337.                   case LArr     : gorl(&dm,Left); break;
  2338.                   case RArr     : gorl(&dm,Right); break;
  2339. ⁿIFDEF TABLESⁿ
  2340.                   case CtrlPgUp : if (tabsize[filno] > 1)
  2341.                                          next_tab_page(_Prev); break;
  2342.                   case CtrlPgDn : if (tabsize[filno] > 1)
  2343.                                          next_tab_page(_Next); break;
  2344. ⁿENDDEFⁿ
  2345.                   case AltX     : dbgetstr(ts,_Ch,LSC_QuitDataBase,
  2346.                                          chstr(yes,_YES),chstr(tpic,Pic_U),"",
  2347.                                             chkyesno,nohelp);
  2348.                                          quit = (bool)((ts[0] == _YES) &&
  2349.                                                           (exitcode != QitKey));
  2350.                                    break;
  2351.                  case QitKey   : if ((dm.curmnu != NULL) &&
  2352.                                   (dm.curmnu->pmnu != 0))
  2353.                                 {
  2354.                                       zapmnu(&dm,dm.curmnu);
  2355.                                       dm.curmnu->litm = dm.curitm;
  2356.                                       dm.curmnu = dm.mat[dm.curmnu->pmnu-1];
  2357.                                       dm.curitm = dm.curmnu->litm;
  2358.                                       dm.level = 0;
  2359.                                       if (dm.curmnu->winp == NULL)
  2360.                                   dspmnu(&dm,dm.curmnu);
  2361.                                      }
  2362.                                    else
  2363.                                 {
  2364.                                 if (filno > 1)
  2365.                                   switch_file('-');
  2366.                                       else
  2367.                                   {
  2368.                                          dbgetstr(ts,_Ch,LSC_QuitDataBase,
  2369.                                            chstr(yes,_YES),
  2370.                                            chstr(tpic,Pic_U),"",
  2371.                                            chkyesno,nohelp);
  2372.                                          quit = (bool)((ts[0] == _YES) &&
  2373.                                                (exitcode != QitKey));
  2374.                                         }
  2375.                                      }
  2376.                                    break;
  2377.                     default      : if (selitm(ctlkey,&dm))
  2378.                                 {
  2379.                                        hbar(&dm);
  2380.                                        do_ctl(&dm,dm.curitm);
  2381.                                       }
  2382.                                    break;
  2383. // End of changes
  2384.                 }
  2385.             } while (!quit);
  2386.         }
  2387.  
  2388.  
  2389.         else dberrm(strconcat(ts,DOSErr8," [",uw.wfnam,"]",NULL));
  2390.         if ((menuanchor != def1.anchor) || (deltas != def1.deltat)) {
  2391.             def1.anchor = menuanchor;
  2392.      def1.deltat = deltas;
  2393.             updexe(def1.exeid,sizeof(def1));
  2394.         }
  2395.         disposemnus(&dm);
  2396.         closeallwin();
  2397.     }
  2398.     else dberrm(strconcat(ts,_NoFiles," [",localmenu,"]",NULL));
  2399. }
  2400.  
  2401. void main(void)
  2402. {
  2403.     extfhc_init();
  2404.     db_curs_init();
  2405.     db_date_init();
  2406.     db_funcs_init();
  2407.     db_heap_init();
  2408.     db_gvar_init();
  2409.     db_key_init();
  2410.     db_pswd_init();
  2411.     db_win_init();
  2412.     db_util_init();
  2413.     db_work_init();
  2414.     db_tree_init();
  2415.     db_list_init();
  2416. ⁿIFDEF MANUALⁿ
  2417.     db_man_init();
  2418. ⁿENDDEFⁿ
  2419. ⁿIFDEF MEMOSⁿ
  2420.     db_mnu_init();
  2421.     db_memo_init();
  2422. ⁿELSEDEFⁿ
  2423.     db_mnu_init();
  2424. ⁿENDDEFⁿ
  2425. ⁿIFDEF MUSERⁿ
  2426.     multiuser = True;
  2427. ⁿELSEDEFⁿ
  2428.     multiuser = False;
  2429. ⁿENDDEFⁿ
  2430.     initedit();
  2431.     initindex();
  2432.     _keyexpr = keyexpr;
  2433.     _getarec = getarec;
  2434.     _horizrec = horizrec;
  2435.     clrscr();
  2436.     if (menudriven && !dbcaller) {
  2437.         audible(Error);
  2438.         dspmsge(LSC_BaseError,LSC_MenuDriven,4.0);
  2439.     }
  2440.     else if (!validpath()) {
  2441.         audible(Error);
  2442.         dspmsge(LSC_BaseError,LSC_AbortBadPath,4.0);
  2443.     }
  2444.     else {
  2445.         if (openwin(0,(byte)(80-strlen(LSC_Initializing))/2,12,
  2446.                                 (byte)strlen(LSC_Initializing),1,31,31,8,"─┐│┘─└│┌",TopCnt,"")) {
  2447.             twinp = curwin;
  2448.             writewxy(LSC_Initializing,31,1,1,twinp);
  2449.             hidewin(T_ON,twinp);
  2450.             openfiles();
  2451.             closewin(&twinp);
  2452.         }
  2453.         if (fok) {
  2454.             shutdown = on_error;
  2455.             initialize();
  2456. ⁿIFDEF MANUALⁿ
  2457.             initmanual("ⁿMANUALⁿ");
  2458. ⁿENDDEFⁿ
  2459.             do_menu();
  2460.             if (openwin(0,(80-strlen(LSC_ClosingFile))/2,12,
  2461.                                     (byte)strlen(LSC_ClosingFile),1,31,31,8,"─┐│┘─└│┌",TopCnt,"")) {
  2462.                 twinp = curwin;
  2463.                 writewxy(LSC_ClosingFile,31,1,1,twinp);
  2464.                 hidewin(T_ON,twinp);
  2465.                 closefiles();
  2466.                 closewin(&twinp);
  2467.             }
  2468.         }
  2469.         else {
  2470.             audible(Error);
  2471.             dspmsge(LSC_ErrNeededFiles,LSC_ErrMissingFile,5.0);
  2472.         }
  2473.     }
  2474.     clrscr();
  2475. }
  2476.