#include /* string functions */ #include #include #include #include /* form header file */ #include #include #include #include /* key functions */ #include /* string fields */ #include /* scrollable regions */ #include /* help header file */ #include /* btrieve functions */ #include /* function prototypes */ #include #include #include typedef struct { char desc[20]; char price[6]; char nl; } SUPCL; typedef struct { char service[16]; char nl; } SVCCL; #define TICMSG 1 #define ORDMSG 2 #define TICHDR 3 #define ESTMSG 4 #define ERRLOG 5 editicm(fmp) /* edit ticket message */ DFORMPTR fmp; { char fn[] = "editicm"; /* for debugging system */ int end; int status; DFORMPTR ticfm; MEMOPTR msgp; FILE *ticfile; INIT_MODULE(fn); message = mem_get(10 * 79); /* 10 rows x 78 cols (+\n) */ strcpy(&fullpath[pathl],"ECTICKET.TXT"); /* add file name to path */ ticfile = _fsopen(fullpath,"rt",SH_DENYNO); /* check for text file */ ticfm = fm_def(6,0,17,80,LNORMAL,BDR_DLNP); /* define form */ sw_shad(TRANSPARENT,LSHADOW,OFF,ticfm->wnp); sw_title(" Ticket Message ",LMNACT,TOPCENTER,ticfm->wnp); sfm_help("*TICFM",ticfm); /* help keyword */ sfm_name("message",ticfm); if (ticfile == NULLP) /* no file found */ bg_txtdef(0,CENTER_TEXT,"Enter up to 10 lines of a ticket message", LNORMAL,ticfm); else bg_txtdef(0,CENTER_TEXT,"This is the current ticket message", LNORMAL,ticfm); bg_linedef(1,0,78,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,ticfm); msgp = memo_def(2,0,NULLP,FADJACENT,10,78,message,ticfm,10,78); sf_opt(TRAILBLANKS,ON,msgp); sf_opt(KEEPNEWLINES,ON,msgp); sf_att(LHIGHLITE,LHIGHLITE,LHIGHLITE,(FIELDPTR) msgp); bg_linedef(12,0,78,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,ticfm); bg_txtdef(13,4,"Use cursor keys to move about the text, toggle Insert mode on/off with", LNORMAL,ticfm); bg_txtdef(14,4,"the Ins key. Enter starts a new line. Include margins if desired.", LNORMAL,ticfm); if (ticfile != NULLP) /*ticket text file found */ { end = fread(message,1,10 * 79,ticfile); /* read message */ message[end] = '\0'; /* add terminating null */ fclose(ticfile); /* close ticket text file */ et_rplevnt(KEY_F9,(EVENTFP) cleartm,MEMOETP); sf_msg(msgline4,msgp); } else { sf_msg(msgline,msgp); } erasemsg = 0; /* clear switch */ fm_up(ticfm); status = fm_rd(0,ticfm); et_rplevnt(KEY_F9,NULLFP,MEMOETP); if (status != AC_EXIT) /* Esc or error */ { if (fm_isup(ticfm)) fm_dn(ticfm); fm_free(ticfm); mem_free(message); EXIT_MODULE(fn); return(SAMELEVEL); } ticfile = _fsopen(fullpath,"wt",SH_DENYRW); /* open ticket text file */ if (ticfile) /* file opened or created */ { if (! st_isblank(message) && ! erasemsg) { fputs(message,ticfile); /* write message to file */ fclose(ticfile); /* close ticket message file */ test_prt(TICMSG,ticprt); /* print the message */ } else { fclose(ticfile); /* close ticket message file */ remove(fullpath); /* delete file */ } } else { wn_up(&ec_err); v_stpl(1,1,"Error opening ticket text file:",&ec_err); v_stpl(2,1,fullpath,&ec_err); v_stpl(4,1," - PRESS ANY KEY",&ec_err); bell_err(); ki(); wn_dn(&ec_err); } if (wn_isup(&msg)) wn_dn(&msg); if (fm_isup(ticfm)) fm_dn(ticfm); fm_free(ticfm); mem_free(message); EXIT_MODULE(fn); return(SAMELEVEL); } editestm(fmp) /* edit estimate message */ DFORMPTR fmp; { char fn[] = "editestm"; /* for debugging system */ int end; int status; DFORMPTR ticfm; MEMOPTR msgp; FILE *ticfile; INIT_MODULE(fn); message = mem_get(10 * 79); /* 10 rows x 78 cols (+\n) */ strcpy(&fullpath[pathl],"ECEST.TXT"); /* add file name to path */ ticfile = _fsopen(fullpath,"rt",SH_DENYNO); /* check for est text file */ ticfm = fm_def(6,0,17,80,LNORMAL,BDR_DLNP); /* define form */ sw_shad(TRANSPARENT,LSHADOW,OFF,ticfm->wnp); sw_title(" Estimate Message ",LMNACT,TOPCENTER,ticfm->wnp); sfm_help("*ESTFM",ticfm); /* help keyword */ sfm_name("estimate",ticfm); if (ticfile == NULLP) /* no file found */ bg_txtdef(0,CENTER_TEXT,"Enter up to 10 lines of an estimate message", LNORMAL,ticfm); else bg_txtdef(0,CENTER_TEXT,"This is the current estimate message", LNORMAL,ticfm); bg_linedef(1,0,78,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,ticfm); msgp = memo_def(2,0,NULLP,FADJACENT,10,78,message,ticfm,10,78); sf_opt(TRAILBLANKS,ON,msgp); sf_opt(KEEPNEWLINES,ON,msgp); sf_att(LHIGHLITE,LHIGHLITE,LHIGHLITE,(FIELDPTR) msgp); bg_linedef(12,0,78,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,ticfm); bg_txtdef(13,4,"Use cursor keys to move about the text, toggle Insert mode on/off with", LNORMAL,ticfm); bg_txtdef(14,4,"the Ins key. Enter starts a new line. Include margins if desired.", LNORMAL,ticfm); if (ticfile != NULLP) /* ticket text file found */ { end = fread(message,1,10 * 79,ticfile); /* read message */ message[end] = '\0'; /* add terminating null */ fclose(ticfile); /* close ticket text file */ et_rplevnt(KEY_F9,(EVENTFP) cleartm,MEMOETP); sf_msg(msgline4,msgp); } else { sf_msg(msgline,msgp); } erasemsg = 0; /* clear switch */ fm_up(ticfm); status = fm_rd(0,ticfm); et_rplevnt(KEY_F9,NULLFP,MEMOETP); if (status != AC_EXIT) /* Esc or error */ { if (fm_isup(ticfm)) fm_dn(ticfm); fm_free(ticfm); mem_free(message); EXIT_MODULE(fn); return(SAMELEVEL); } ticfile = _fsopen(fullpath,"wt",SH_DENYRW); /* open ticket text file */ if (ticfile) /* file opened or created */ { if (! st_isblank(message) && ! erasemsg) { fputs(message,ticfile); /* write message to file */ fclose(ticfile); /* close ticket message file */ test_prt(ESTMSG,ticprt); /* print the message */ } else { fclose(ticfile); /* close ticket message file */ remove(fullpath); /* delete file */ } } else { wn_up(&ec_err); v_stpl(1,1,"Error opening estimate text file:",&ec_err); v_stpl(2,1,fullpath,&ec_err); v_stpl(4,1," - PRESS ANY KEY",&ec_err); bell_err(); ki(); wn_dn(&ec_err); } if (wn_isup(&msg)) wn_dn(&msg); if (fm_isup(ticfm)) fm_dn(ticfm); fm_free(ticfm); mem_free(message); EXIT_MODULE(fn); return(SAMELEVEL); } cleartm(fmp,eventptr) /* clear ticket message func */ DFORMPTR fmp; EVENTPTR eventptr; { char fn[] = "cleartm"; char resp; /* field for askfm */ DFORMPTR askfm; DFIELDPTR afldp; /* ptr to field structure */ int status; INIT_MODULE(fn); askfm = fm_def(10,17,8,46,(UCHAR) LMNINACT,BDR_DLNP); sfm_opt(AUTOEXIT,ON,askfm); /* don't need to press F10 */ sfm_help("*ASKFM",askfm); /* install help keyword */ resp = 'N'; /* initialize response */ bg_txtdef(1,1,"Are you sure you want to clear the",LMNINACT,askfm); if (strcmp(fm_ptrnam(fmp),"message") == 0) bg_txtdef(2,1,"ticket message text?",LMNINACT,askfm); if (strcmp(fm_ptrnam(fmp),"estimate") == 0) bg_txtdef(2,1,"estimate message text?",LMNINACT,askfm); if (strcmp(fm_ptrnam(fmp),"order") == 0) bg_txtdef(2,1,"order message text?",LMNINACT,askfm); if (strcmp(fm_ptrnam(fmp),"header") == 0) bg_txtdef(2,1,"ticket header text?",LMNINACT,askfm); afldp = fld_def(4,1,"Enter 'Y' to clear the text, 'N' to quit ",FADJACENT, "!",F_BOOL,(PTR) &resp,askfm); sf_msg(msgline,afldp); bell_vv(); status = fm_proc(0,askfm); fm_free(askfm); if (status != AC_EXIT || resp == 'N') /* Esc pressed, error or 'N' */ { EXIT_MODULE(fn); return(1); } erasemsg = 1; /* set switch */ sfm_nextitem(AC_EXIT,fmp); /* done with form */ EXIT_MODULE(fn); return(1); } editordm(fmp) /* edit order text message */ DFORMPTR fmp; { char fn[] = "editordm"; /* for debugging system */ DFORMPTR ordfm; MEMOPTR msgp; FILE *ordfile; int end; int status; INIT_MODULE(fn); message = mem_get(30 * 79); /* 30 rows x 78 cols (+\n) */ strcpy(&fullpath[pathl],"ECORDER.TXT"); /* add file name to path */ ordfile = _fsopen(fullpath,"rt",SH_DENYNO); /* check for order file */ ordfm = fm_def(2,0,21,80,LNORMAL,BDR_DLNP); /* define form */ sw_shad(TRANSPARENT,LSHADOW,OFF,ordfm->wnp); sw_title(" Customer Order Message ",LMNACT,TOPCENTER,ordfm->wnp); sfm_help("*ORDFM",ordfm); /* help keyword */ sfm_name("order",ordfm); if (ordfile == NULLP) /* no file found */ bg_txtdef(0,CENTER_TEXT,"Enter up to 30 lines of an order message", LNORMAL,ordfm); else bg_txtdef(0,CENTER_TEXT,"This is the current order message", LNORMAL,ordfm); bg_linedef(1,0,78,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,ordfm); msgp = memo_def(2,0,NULLP,FADJACENT,14,78,message,ordfm,30,78); sf_opt(TRAILBLANKS,ON,msgp); sf_opt(KEEPNEWLINES,ON,msgp); sf_att(LHIGHLITE,LHIGHLITE,LHIGHLITE,(FIELDPTR) msgp); bg_linedef(16,0,78,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,ordfm); bg_txtdef(17,4,"Use cursor keys to move about the text, toggle Insert mode on/off with", LNORMAL,ordfm); bg_txtdef(18,4,"the Ins key. Enter starts a new line. Include margins if desired.", LNORMAL,ordfm); if (ordfile != NULLP) /* order text file found */ { end = fread(message,1,30 * 79,ordfile); /* read message */ message[end] = '\0'; /* add terminating null */ fclose(ordfile); /* close order text file */ et_rplevnt(KEY_F9,(EVENTFP) cleartm,MEMOETP); sf_msg(msgline4,msgp); } else { sf_msg(msgline,msgp); } erasemsg = 0; /* clear switch */ fm_up(ordfm); status = fm_rd(0,ordfm); et_rplevnt(KEY_F9,NULLFP,MEMOETP); if (status != AC_EXIT) /* Esc or error */ { if (fm_isup(ordfm)) fm_dn(ordfm); fm_free(ordfm); mem_free(message); EXIT_MODULE(fn); return(SAMELEVEL); } ordfile = _fsopen(fullpath,"wt",SH_DENYRW); /* open order text file */ if (ordfile) /* file opened or created */ { if (! st_isblank(message) && ! erasemsg) { fputs(message,ordfile); /* write message to file */ fclose(ordfile); /* close ticket message file */ test_prt(ORDMSG,ordprt); /* print the message */ } else { fclose(ordfile); /* close ticket message file */ remove(fullpath); /* delete file */ } } else { wn_up(&ec_err); v_stpl(1,1,"Error opening order text file:",&ec_err); v_stpl(2,1,fullpath,&ec_err); v_stpl(4,1," - PRESS ANY KEY",&ec_err); bell_err(); ki(); wn_dn(&ec_err); } if (wn_isup(&msg)) wn_dn(&msg); if (fm_isup(ordfm)) fm_dn(ordfm); fm_free(ordfm); mem_free(message); EXIT_MODULE(fn); return(SAMELEVEL); } test_prt(type,prtfile) int type; char *prtfile; { char fn[] = "test_prt"; FILE *tstfile; DFORMPTR askfm; DFIELDPTR fp; char resp; int status; char *textline; int hdrlines = 0; INIT_MODULE(fn); askfm = fm_def(11,22,5,35,(UCHAR) LMNINACT,BDR_DLNP); /* define form */ sfm_opt(AUTOEXIT,ON,askfm); /* don't need to press F10 */ sfm_help("*ASKFM",askfm); /* install help keyword */ resp = 'N'; fp = fld_def(1,1,"Want to print this (Y/N)? ",FADJACENT,"!", F_BOOL,&resp,askfm); sf_opt(TRAILBLANKS,ON,fp); sf_msg(msgline,fp); bell_vv(); status = fm_proc(0,askfm); /* process form */ fm_free(askfm); if (status != AC_EXIT || resp != 'Y') { EXIT_MODULE(fn); return(0); } status = open_prt(prtfile); /* open ticket printer */ if (status) /* open failed */ { wn_up(&ec_err); v_stpl(1,1,"Error opening printer ",&ec_err); v_st(prtfile,&ec_err); v_stpl(3,1," - PRESS ANY KEY",&ec_err); csr_hide(); bell_err(); ki(); wn_dn(&ec_err); EXIT_MODULE(fn); return(0); } if (type == TICHDR) strcpy(&fullpath[pathl],"ECTICHDR.TXT"); /* add file name to path */ if (type == ORDMSG) strcpy(&fullpath[pathl],"ECORDER.TXT"); /* add file name to path */ if (type == TICMSG) strcpy(&fullpath[pathl],"ECTICKET.TXT"); /* add file name to path */ if (type == ESTMSG) strcpy(&fullpath[pathl],"ECEST.TXT"); /* add file name to path */ if (type == ERRLOG) strcpy(&fullpath[pathl],"ECERROR.LOG"); /* add file name to path */ tstfile = _fsopen(fullpath,"rt",SH_DENYNO); /* check for ticket msg file*/ if (tstfile == NULLP) /* error on open */ { wn_up(&ec_err); v_stpl(1,1,"Error opening file:",&ec_err); v_stpl(2,1,fullpath,&ec_err); v_stpl(3,1," - PRESS ANY KEY",&ec_err); csr_hide(); bell_err(); ki(); wn_dn(&ec_err); fclose(prtfil); EXIT_MODULE(fn); return(0); } if (! wn_isup(&msg)) wn_up(&msg); else wn_clr(&msg); if (type == TICHDR) v_stattpl(1,CENTER_TEXT,"Printing the ticket header ...", LURGENT,STATT,&msg); if (type == TICMSG) v_stattpl(1,CENTER_TEXT,"Printing the ticket message ...", LURGENT,STATT,&msg); if (type == ESTMSG) v_stattpl(1,CENTER_TEXT,"Printing the estimate message ...", LURGENT,STATT,&msg); if (type == ORDMSG) v_stattpl(1,CENTER_TEXT,"Printing the order message ...", LURGENT,STATT,&msg); if (type == ERRLOG) v_stattpl(1,CENTER_TEXT,"Printing the error log ...", LURGENT,STATT,&msg); fputs("\n",prtfil); /* skip one line */ textline = mem_stblank(241); /* get enough to avoid error */ while (fgets(textline,241,tstfile)) /* not EOF or error */ { if (textline[0] == '\\' && type != ERRLOG) /* this line is print cmd*/ { prtcmd(textline); /* send command to printer */ continue; } fputs(textline,prtfil); /* write text to printer */ } fclose(tstfile); /* close file */ mem_free(textline); /* free memory for line */ fputs("\r\n\x0C",prtfil); /* send form feed */ fputs("\x1B\x12",prtfil); /* clear compressed */ fputs("\x1B\x48",prtfil); /* clear double strike */ fputs("\x1B\x14",prtfil); /* clear double width */ fputs("\x1B\x46",prtfil); /* clear emphasized */ fclose(prtfil); EXIT_MODULE(fn); return(0); } editsupl(fmp) /* edit supplies list */ DFORMPTR fmp; { char fn[] = "editsupl"; /* for debugging system */ int status; /* returned by fm_proc() */ DFORMPTR supl; DFIELDPTR fp; SRPTR srp; FILE *supfile; /* supply file */ char *fbuf; /* buffer for file */ SUPCL *p; /* pointer to file struct */ int i; /* counter */ INIT_MODULE(fn); strcpy(&fullpath[pathl],"ECSUPPLY.TXT"); /* add file name to path */ supfile = _fsopen(fullpath,"rt",SH_DENYNO); /* check for supply list */ if (supfile != NULLP) /* file opened */ { fbuf = mem_stblank(30); /* get memory for file line */ for (i = 0; i < 100; i++) /* fill arrays */ { fgets(fbuf,30,supfile); /* get line */ if (feof(supfile) || ferror(supfile)) /* end-of-file or error */ break; p = (SUPCL *) fbuf; /* point to buffer as struct */ strncpy((char *) sups[i].desc,p->desc,20); /* copy description */ strncpy((char *) sups[i].price,p->price,6); /* copy price */ } fclose(supfile); /* close file for now */ mem_free(fbuf); /* free memory for file line */ } supl = fm_def(6,24,15,33,LNORMAL,BDR_DLNP); /* supplies list form */ sfm_help("*SUPLFM",supl); /* install help keyword */ sw_title(" Supplies List ",LMNACT,TOPCENTER,supl->wnp); sfm_opt(CURSORCROSS,OFF,supl); /* turn off left-right arrow */ bg_txtdef(0,1,"Description",LNORMAL,supl); bg_linedef(1,0,31,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,supl); bg_linedef(0,22,13,DOWN | X_LINEBDR,LNORMAL,LINE_SLNP,supl); bg_txtdef(0,25,"Price",LNORMAL,supl); srp = sr_def(2,0,11,31,LNORMAL,BDR_NULLP,100,(PTR) &sups, sizeof(SUPPL),supl); fp = srf_def(1,NULLP,1,pic_def('!',20),F_STRING,sups[0].desc,srp); sf_msg(msgline7,fp); sf_opt(TRAILBLANKS,ON,fp); /* retain trailing blanks */ sf_opt(FORCECONVERT,ON,fp); fp = srf_def(24,NULLP,24,"###@##",F_STRING,sups[0].price,srp); sf_msg(msgline7,fp); sf_opt(TRAILBLANKS,ON,fp); /* retain trailing blanks */ sf_opt(CLEARONKEY,ON,fp); /* clear on first entry */ sf_opt(RTADJUST,ON,fp); /* right-adjust on exit */ sf_opt(FORCECONVERT,ON,fp); sf_endfp(endsupp,fp); /* install end field func */ et_rplevnt(KEY_F9,(EVENTFP) list_del,SRETP); et_rplevnt(KEY_F6,(EVENTFP) list_ins,SRETP); status = fm_proc(0,supl); /* process form */ et_rplevnt(KEY_F9,NULLFP,SRETP); et_rplevnt(KEY_F6,NULLFP,SRETP); fm_free(supl); /* free memory for form */ if (status != AC_EXIT) /* Esc or error */ { EXIT_MODULE(fn); return(SAMELEVEL); } supfile = _fsopen(fullpath,"wt",SH_DENYRW); /* reopen supply list file */ if (supfile == NULLP) /* error on re-open */ { wn_up(&ec_err); v_stpl(1,1,"Error re-opening ECSUPPLY.TXT",&ec_err); v_stpl(3,1," - PRESS ANY KEY",&ec_err); bell_err(); ki(); wn_dn(&ec_err); EXIT_MODULE(fn); return(SAMELEVEL); } for (i = 0; i < 100; i++) { if (st_isblank((char *) sups[i].desc)) /* skip blank lines */ continue; fputs((char *) sups[i].desc,supfile); /* copy description to file */ fputs((char *) sups[i].price,supfile); /* copy price to file */ fputs("\n",supfile); /* terminate with newline */ } fclose(supfile); /* close supply list file */ EXIT_MODULE(fn); return(SAMELEVEL); } endsupp(fmp) DFORMPTR(fmp); { char fn[] = "endsupp"; char sprice[7]; int row; SRPTR srp; double newprice; INIT_MODULE(fn); srp = cursrp(fmp); /* point to scrollable region*/ row = sr_currow(srp); /* get row in form */ srf_get(sprice,row,1,srp); /* get new price */ if (st_isblank(sprice)) /* blank not allowed */ { ssr_nextpos(AC_SAMEROW,AC_SAMECOL,srp); /* stay in this field */ EXIT_MODULE(fn); return(1); } if (! sr_rowisaltered(srp)) { ssr_nextpos(AC_NEXTROW,AC_FIRSTCOL,srp); /* skip to next row */ EXIT_MODULE(fn); return(1); } newprice = atof(sprice); /* convert to float */ if (newprice >= 1000.00) /* too large for field */ { if (! wn_isup(&ec_err)) wn_up(&ec_err); v_stpl(1,1,"Amount of $1000 or more is",&ec_err); v_stpl(2,1,"invalid - PRESS ANY KEY",&ec_err); bell_err(); ki(); wn_dn(&ec_err); ssr_nextpos(AC_SAMEROW,AC_SAMECOL,srp); /* stay in price field */ EXIT_MODULE(fn); return(1); } sprintf(sprice,"%6.2f",newprice); /* convert to dollars */ srf_upd(sprice,row,1,srp); /* redisplay */ EXIT_MODULE(fn); return(1); } list_del(fmp,eventptr) /* delete list line func */ DFORMPTR fmp; EVENTPTR eventptr; { char fn[] = "list_del"; int row; /* row in scrollable form */ SRPTR srp; INIT_MODULE(fn); srp = cursrp(fmp); /* get ptr to scroll region */ row = sr_currow(srp); /* get row in form */ if (! sr_rowdel(row,srp)) /* delete row */ bell_err(); EXIT_MODULE(fn); return(1); } list_ins(fmp,eventptr) /* insert list line func */ DFORMPTR fmp; EVENTPTR eventptr; { char fn[] = "supl_ins"; int row; /* row in scrollable form */ SRPTR srp; INIT_MODULE(fn); srp = cursrp(fmp); /* get ptr to scroll region */ row = sr_currow(srp); /* get row in form */ if (! sr_rowins(row,srp)) /* insert row */ bell_err(); EXIT_MODULE(fn); return(TRUE); } editsvcl(fmp) /* edit services list */ DFORMPTR fmp; { char fn[] = "editsvcl"; /* for debugging system */ int status; /* returned by fm_proc() */ DFORMPTR svc; DFIELDPTR fp; SRPTR srp; FILE *svcfile; /* service file */ char *fbuf; /* buffer for file */ SVCCL *p; /* pointer to file struct */ int i; /* counter */ INIT_MODULE(fn); strcpy(&fullpath[pathl],"ECSERVIC.TXT"); /* add file name to path */ svcfile = _fsopen(fullpath,"rt",SH_DENYNO); /* check for service list */ if (svcfile != NULLP) /* file opened */ { fbuf = mem_stblank(20); /* get memory for file line */ for (i = 0; i < 50; i++) /* fill arrays */ { fgets(fbuf,20,svcfile); /* get line */ if (feof(svcfile) || ferror(svcfile)) /* end-of-file or error */ break; p = (SVCCL *) fbuf; /* point to buffer as struct */ strncpy((char *) svcs[i].service,p->service,16); /* copy service */ } fclose(svcfile); /* close file for now */ mem_free(fbuf); /* free memory for file line */ } svc = fm_def(6,30,15,20,LNORMAL,BDR_DLNP); /* supplies list form */ sfm_help("*SVCLFM",svc); /* install help keyword */ sw_title(" Service List ",LMNACT,TOPCENTER,svc->wnp); sfm_opt(CURSORCROSS,OFF,svc); /* turn off left-right arrow */ bg_txtdef(0,5,"Services",LNORMAL,svc); bg_linedef(1,0,18,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,svc); srp = sr_def(2,0,11,18,LNORMAL,BDR_NULLP,50,(PTR) &svcs, sizeof(SVCL),svc); fp = srf_def(1,NULLP,1,pic_def('!',16),F_STRING,svcs[0].service,srp); sf_msg(msgline7,fp); sf_opt(TRAILBLANKS,ON,fp); /* retain trailing blanks */ sf_opt(FORCECONVERT,ON,fp); et_rplevnt(KEY_F9,(EVENTFP) list_del,SRETP); et_rplevnt(KEY_F6,(EVENTFP) list_ins,SRETP); status = fm_proc(0,svc); /* process form */ et_rplevnt(KEY_F9,NULLFP,SRETP); et_rplevnt(KEY_F6,NULLFP,SRETP); fm_free(svc); /* free memory for form */ if (status != AC_EXIT) /* Esc or error */ { EXIT_MODULE(fn); return(SAMELEVEL); } svcfile = _fsopen(fullpath,"wt",SH_DENYRW); /* reopen supply list file */ if (svcfile == NULLP) /* error on re-open */ { wn_up(&ec_err); v_stpl(1,1,"Error re-opening ECSERVIC.TXT",&ec_err); v_stpl(3,1," - PRESS ANY KEY",&ec_err); bell_err(); ki(); wn_dn(&ec_err); EXIT_MODULE(fn); return(SAMELEVEL); } for (i = 0; i < 50; i++) { if (st_isblank((char *) svcs[i].service)) /* skip blank lines */ continue; fputs((char *) svcs[i].service,svcfile); /* copy description to file*/ fputs("\n",svcfile); /* terminate with newline */ } fclose(svcfile); /* close supply list file */ EXIT_MODULE(fn); return(SAMELEVEL); } editlog(fmp) DFORMPTR fmp; { char fn[] = "editlog"; WINDOWPTR wnp; DFORMPTR askfm; DFIELDPTR fp; FILE *log; char *stdate; char *thisdate; char *line; int count,c,status; char resp; INIT_MODULE(fn); strcpy(&fullpath[pathl],"ECERROR.LOG"); /* add file name to path */ if ((log = _fsopen(fullpath,"rt",SH_DENYNO)) == NULLP) /* check for log */ { wn_up(&ec_err); v_stpl(1,1,"Log file NOT FOUND:",&ec_err); v_stpl(2,1,fullpath,&ec_err); v_stpl(4,1," - PRESS ANY KEY",&ec_err); bell_err(); ki(); wn_dn(&ec_err); EXIT_MODULE(fn); return(SAMELEVEL); } wnp = wn_def(8,7,14,64,LNORMAL,BDR_SLNP); /* define window */ sw_title(" Error Log ",LMNACT,TOPCENTER,wnp); /* add title to window */ sw_shad(TRANSPARENT,LSHADOW,BOTTOMRIGHT,wnp); /* add shadow to window */ wn_up(wnp); stdate = mem_stblank(8); /* get memory for field */ askfm = fm_def(10,24,8,33,(UCHAR) LMNINACT,BDR_DLNP); /* define form */ sfm_opt(AUTOEXIT,ON,askfm); /* don't need to press F10 */ sfm_help("*ASKFM",askfm); /* install help keyword */ bg_txtdef(1,1,"Enter starting date, or leave",LMNINACT,askfm); bg_txtdef(2,1,"blank for all entries",LMNINACT,askfm); fp = fld_def(4,1,"Starting Date ",FADJACENT,"99/99/99", F_DATE,stdate,askfm); sf_opt(TRAILBLANKS,ON,fp); sf_msg(msgline,fp); bell_vv(); status = fm_proc(0,askfm); fm_free(askfm); line = mem_stblank(80); /* get memory for line */ if (status == AC_EXIT) /* Esc not pressed */ { if (! st_isblank(stdate)) /* starting date entered */ { thisdate = mem_stblank(8); /* get memory for variable */ while (! feof(log)) { fgets(line,80,log); /* get line from file */ if (strncmp(line,"Date",4) != 0) /* not date line */ continue; strncpy(thisdate,&line[6],8); /* copy date to variable */ if (date_diff(stdate,thisdate,SYSDATEFMT) >= 0L) /* comp dates */ break; } } } mem_free(stdate); /* free memory for variables */ mem_free(thisdate); if (feof(log)) /* no matching entries */ { wn_up(&ec_err); v_stpl(1,1,"No entries on or later than",&ec_err); v_stpl(2,1,stdate,&ec_err); v_stpl(4,1," - PRESS ANY KEY",&ec_err); bell_err(); ki(); wn_dn(&ec_err); mem_free(line); EXIT_MODULE(fn); return(SAMELEVEL); } count = 0; /* init line count */ c = 0; while (! feof(log)) { v_statt(line,(UCHAR) LHIGHLITE,wnp); /* write string to window */ count++; /* increment count */ if (count > 11) /* window is full */ { wi_sav(MSG_WNP); /* save current message */ wn_clr(MSG_WNP); /* clear message window */ v_stpl(0,0,"Press any key to continue, or Esc to quit",MSG_WNP); c = ki(); wi_unsav(MSG_WNP); /* restore message window */ count = 0; /* reset counter */ if (c == KEY_ESC) /* Esc pressed */ break; } fgets(line,80,log); /* get next line */ } fclose(log); /* done with file */ test_prt(ERRLOG,rptprt); /* print the log file */ if (wn_isup(&msg)) wn_dn(&msg); if (c != KEY_ESC) { wi_sav(MSG_WNP); wn_clr(MSG_WNP); v_stpl(0,0,"Press any key to continue",MSG_WNP); bell_vv(); ki(); wi_unsav(MSG_WNP); } askfm = fm_def(11,22,5,35,(UCHAR) LMNINACT,BDR_DLNP); /* define form */ sfm_opt(AUTOEXIT,ON,askfm); /* don't need to press F10 */ sfm_help("*ASKFM",askfm); /* install help keyword */ resp = 'N'; fp = fld_def(1,1," Want to clear the log (Y/N)? ",FADJACENT,"!", F_BOOL,&resp,askfm); sf_opt(TRAILBLANKS,ON,fp); sf_msg(msgline,fp); bell_vv(); status = fm_proc(0,askfm); /* process form */ fm_free(askfm); if (status == AC_EXIT && resp == 'Y') remove(fullpath); /* delete log file */ wn_dn(wnp); wn_free(wnp); mem_free(line); EXIT_MODULE(fn); return(SAMELEVEL); } editich(fmp) /* edit ticket header */ DFORMPTR fmp; { char fn[] = "editich"; /* for debugging system */ int end; int status; DFORMPTR ticfm; MEMOPTR msgp; FILE *ticfile; INIT_MODULE(fn); message = mem_get(6 * 79); /* 6 rows x 79 cols (+\n) */ strcpy(&fullpath[pathl],"ECTICHDR.TXT"); /* add file name to path */ ticfile = _fsopen(fullpath,"rt",SH_DENYNO); /* check for ticket text */ ticfm = fm_def(8,0,13,80,LNORMAL,BDR_DLNP); /* define form */ sw_shad(TRANSPARENT,LSHADOW,OFF,ticfm->wnp); sw_title(" Ticket Header ",LMNACT,TOPCENTER,ticfm->wnp); sfm_help("*TICHFM",ticfm); /* help keyword */ sfm_name("header",ticfm); if (ticfile == NULLP) /* no file found */ bg_txtdef(0,CENTER_TEXT,"Enter up to 6 lines of a ticket header", LNORMAL,ticfm); else bg_txtdef(0,CENTER_TEXT,"This is the current ticket header", LNORMAL,ticfm); bg_linedef(1,0,78,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,ticfm); msgp = memo_def(2,0,NULLP,FADJACENT,6,78,message,ticfm,6,78); sf_opt(TRAILBLANKS,ON,msgp); sf_opt(KEEPNEWLINES,ON,msgp); sf_att(LHIGHLITE,LHIGHLITE,LHIGHLITE,(FIELDPTR) msgp); bg_linedef(8,0,78,RIGHT | X_LINEBDR,LNORMAL,LINE_SLNP,ticfm); bg_txtdef(9,4,"Use cursor keys to move about the text, toggle Insert mode on/off with", LNORMAL,ticfm); bg_txtdef(10,4,"the Ins key. Enter starts a new line. Include margins if desired.", LNORMAL,ticfm); if (ticfile != NULLP) /* ticket text file found */ { end = fread(message,1,6 * 55,ticfile); /* read message */ message[end] = '\0'; /* add terminating null */ fclose(ticfile); /* close ticket text file */ et_rplevnt(KEY_F9,(EVENTFP) cleartm,MEMOETP); sf_msg(msgline4,msgp); } else { sf_msg(msgline,msgp); } erasemsg = 0; /* clear switch */ fm_up(ticfm); status = fm_rd(0,ticfm); et_rplevnt(KEY_F9,NULLFP,MEMOETP); if (status != AC_EXIT) /* Esc or error */ { if (fm_isup(ticfm)) fm_dn(ticfm); fm_free(ticfm); mem_free(message); EXIT_MODULE(fn); return(SAMELEVEL); } ticfile = _fsopen(fullpath,"wt",SH_DENYRW); /* open ticket text file */ if (ticfile) /* file opened or created */ { if (! st_isblank(message) && ! erasemsg) { fputs(message,ticfile); /* write message to file */ fclose(ticfile); /* close ticket message file */ test_prt(TICHDR,ticprt); /* print the message */ } else { fclose(ticfile); /* close ticket message file */ remove(fullpath); /* delete file */ } } else { wn_up(&ec_err); v_stpl(1,1,"Error opening ticket header file:",&ec_err); v_stpl(2,1,fullpath,&ec_err); v_stpl(4,1," - PRESS ANY KEY",&ec_err); bell_err(); ki(); wn_dn(&ec_err); } if (wn_isup(&msg)) wn_dn(&msg); if (fm_isup(ticfm)) fm_dn(ticfm); fm_free(ticfm); mem_free(message); EXIT_MODULE(fn); return(SAMELEVEL); }