#include #include #include #include #include #include "xbindex.h" #include "xbase.h" #include "xbcmds.h" #include "dottalk.h" extern select_rec * FAR s[max_area]; extern short far area; extern long memory; extern int DOSERROR; extern int XERROR; extern char *XMSG[]; char *dfile,*xfile; void main() { char command_line[max_params*param_size]; memory = 0; initcmds(); initbase(); memset((char *)command_line,' ',sizeof(command_line)); commands(command_line); } static char *help[] = { "QUIT", "USE FILENAME [INDEX ]", "INDEX ", "LIST ", "FIELD ", "TOP", "BOTTOM", "SKIP ", "DISPLAY", "GOTO ", "COPY TO FILENAME [FOR | WHILE FIELDNAME <|>|>=|<= ] [TYPE SDF] [TYPE DELIMITED] ", "RECNO", "DIR", "!", "ASCEND", "DESCEND", "NIDX", "PIDX", "RTREE", "FIND", "LOCATE ", "SAYGET", "EDIT ", "APPEND", "SAVE", "DELETE", "PACK", "COUNT", "SELECT ", "DEBUG [BUFFER] [FIELD ]", "HELP" }; void sayfield(int field_idx) { printf("%s ",SA->fd[field_idx]); } void display() { short i ; if (!SA->fok) { return; } printf("\n"); for (i = 1; i <= SA->num_of_fields; i++) { printf("%s\n",SA->fd[i]); }; printf("\n"); } void ascendtree() { int i; i = first_key(SI.pe,SI.pix); while (i != EOIX) { printf("%s %d\n",SI.pe->key,SI.pe->rptr); i = next_key(SI.pe,SI.pix); } } void descendtree() { int i; last_key(SI.pe,SI.pix); i = prev_key(SI.pe,SI.pix); while (i != EOIX) { printf("%s %d\n",SI.pe->key,SI.pe->rptr); i = prev_key(SI.pe,SI.pix); } } char * FAR PASCAL _export parsecom(char *comstr,char *cp[]) { /*num_of_params is a global variable in xbcmds.h */ num_of_params = (char)sscanf(comstr,"%s%s%s%s%s",cp[1],cp[2],cp[3],cp[4],cp[5]); return(cp[1]); } void commands(char *command_str) { int i,j,ret; int stat; short fieldno; char *cp[6]; char *dfile; SA->fok = FALSE; SI.idx = FALSE; for (i=1;i<=5;i++) { cp[i] = calloc(param_size,sizeof(char)); memchk(cp[i],"commands","cp[i]",(long)(param_size*sizeof(char))); } while (strnicmp(command_str,"QUIT",3)!=0) { printf("."); memset(command_str,' ',sizeof(command_str)); for (i=1;i<=5;i++) { /* cp[i] = "\0"; */ memset(cp[i],' ',sizeof(cp[i])); } gets(command_str); command_verb = parsecom(command_str,cp); if (strnicmp(command_verb,"LIST",3)==0) { if (!SA->fok) return; stat = 1; if (!SI.idx) { for (i=(int)SA->crn;i<=SA->hr->num_of_recs;i++) { if (num_of_params < 2) { display(); } else { for (j=2;j<=num_of_params;j++) { sayfield(match(cp[j])); } printf("\n"); } if (i != SA->hr->num_of_recs) stat = skip(1); } } else { while (stat != EOIX) { if (num_of_params <2) { display(); } else { for (j=2;j<=num_of_params;j++) { sayfield(match(cp[j])); } printf("\n"); } stat = skip(1); } } } if (strnicmp(command_verb,"FIELD",3)==0) { for (i=2;i<=num_of_params;i++) sayfield(match(cp[i])); printf("\n"); } if (strnicmp(command_verb,"LOCA",3)==0) locate(cp[2],cp[3]); if (strnicmp(command_verb,"GOTO",3)==0) { i = atoi(cp[2]); if ((i >= 0) && (i <= SA->hr->num_of_recs)) goto_rec(i); else printf("%d is not a valid number\n",i); } if (strnicmp(command_verb,"TOP ",3)==0) top(); if (strnicmp(command_verb,"BOTT",3)==0) bottom(); if (strnicmp(command_verb,"SKIP",3)==0) { i = atoi(cp[2]); if (abs(i) <= SA->hr->num_of_recs) skip(i); else if ((strnicmp(cp[2]," ",3)==0) || (num_of_params == 1)) skip(1); else printf("%d is not a valid record number\n",i); } if (strnicmp(command_verb,"COPY",3)==0) copyfile(cp); if (strnicmp(command_verb,"DISP",3)==0) display(); if (strnicmp(command_verb,"USE ",3)==0) { if (num_of_params == 1) { if (SI.idx) { close_index(SI.pix); free(SI.pix); free(SI.pe); } if (SA->fok) close_file(area); } else { if (strnicmp(cp[3],"INDEX",3)==0) stat=TRUE; else { stat=FALSE; if (SI.idx) { close_index(SI.pix); free(SI.pix); free(SI.pe); } } dfile = dbname(cp[2]); xfile = dxname(cp[4]); use(dfile,xfile,(char)stat); } } if (strnicmp(command_verb,"SAVE",3)==0) { save_rec(area); printf("record updated\n"); } if (strnicmp(command_verb,"EDIT",3)==0) { if (num_of_params == 3) { if (edit_field(cp[2],cp[3]) == 0) { printf("could not edit %s\n",cp[2]); } } } if (strnicmp(command_verb,"SELE",3)==0) { i = atoi(cp[2]); if (i==0) printf("current work area = %d\n",area); else { if ((i>-1) && (i<256)) area = (char)i; else printf("select %s failed\n",cp[2]); } } if (strnicmp(command_verb,"RECO",3)==0) printf("%d\n",SA->crn); if (strnicmp(command_verb,"DIR ",3)==0) { /* DOSERROR = system("C:\\COMMAND.COM /C DIR *.*"); */ if (DOSERROR != 0) printf("#%d DOS ERROR\n",DOSERROR); } if (strnicmp(command_verb,"! ",3)==0) { /* DOSERROR = system("C:\\COMMAND.COM"); */ if (DOSERROR != 0) printf("#%d DOS ERROR\n",DOSERROR); } /* if (strnicmp(command_verb,"BROW",3)==0) browse(W,H,X,Y); */ if (strnicmp(command_verb,"RELA",3)==0) relate((char)atoi(cp[2]),(char)atoi(cp[3]), (char)atoi(cp[4]),(char)atoi(cp[5])); if (strnicmp(command_verb,"ASCE",3)==0) ascendtree(); if (strnicmp(command_verb,"DESC",3)==0) descendtree(); if (strnicmp(command_verb,"NIDX",3)==0) { ret = next_key(SI.pe,SI.pix); if (ret==IX_OK) goto_rec(SI.pe->rptr); else printf("%d\n",ret); } if (strnicmp(command_verb,"PIDX",3)==0) { if (prev_key(SI.pe,SI.pix)==IX_OK) goto_rec(SI.pe->rptr); } if (strnicmp(command_verb,"INDE",3)==0) { fieldno = (short)atoi(cp[3]); if ((fieldno > 0) && (fieldno <= SA->num_of_fields)) { /* syntax - INDEX indexname fieldnumber */ SI.idx= FALSE; xfile = dxname(cp[2]); build_index(xfile,fieldno,SA->hr->num_of_recs); } else printf("invalid order\n"); } if (strnicmp(command_verb,"FIND",3)==0) { if (!SI.idx) printf("this area not indexed\n"); else { if (num_of_params == 1) cp[2] = " "; if (!find(cp[2])) printf("could not find %s\n",cp[2]); } } if (strnicmp(command_verb,"SAYGET",3)==0) { } if (strnicmp(command_verb,"APPE",3)==0) append_blank(area); if (strnicmp(command_verb,"DELE",3)==0) delete_rec(area); if (strnicmp(command_verb,"PACK",3)==0) { /* pack(area); */ } if (strnicmp(command_verb,"COUN",3)==0) printf("%d\n",SA->hr->num_of_recs); if (strnicmp(command_verb,"REIN",3)==0) reindex(cp[2]); if (strnicmp(command_verb,"HELP",3)==0) for (i=0;i<=25;i++) printf("%s\n",help[i]); #if MSDOS if (strnicmp(command_verb,"MEMO",3)==0) printf("memory available = %d free count = %d\n",_memavl(),_freect(1)); #endif if (strnicmp(command_verb,"ORDE",3)==0) { i = atoi(cp[2]); if (i==0) printf("current order in area %d = %d\n",area,SA->ord); else order((char)atoi(cp[2]),(char)atoi(cp[3])); } if (strnicmp(command_verb,"OPEN",3)==0) { if (strnicmp(cp[2],"INDEX",3)==0) { if (open_index(dxname(cp[3]),1)==0) printf("index open error\n"); } } if (strnicmp(command_verb,"SWAB",3)==0) swabdbf(cp[2]); if (strnicmp(command_verb,"FIXH",3)==0) { SA->hr->num_of_recs = atol(cp[2]); printf("num_of_recs = %d %x\n", SA->hr->num_of_recs, SA->hr->num_of_recs); } if (strnicmp(command_verb,"DEBU",3)==0) { printf(" Select Record Information\n"); printf("area = %d\n",SA->a); printf("file pointer = %d\n",*SA->fp); printf("file ok = %d\n",SA->fok); printf("curr rec no = %d\n",SA->crn); if (strnicmp(cp[2],"BUFF",3)==0) { for (i=0;ihr->cpr;i++) printf("%c",SA->rd[i]); } printf("indexed = %d\n",SI.idx); printf("index order = %d\n",SA->ord); printf("num_of_fields = %d\n",SA->num_of_fields); /* field_rec *fr[max_fields]; string fd[max_fields]; */ printf(" Header Information - %s\n",dbname); printf("version = %x\n",SA->hr->version); /* update last_updated */ printf("num of recs = %d\n",SA->hr->num_of_recs); printf("data start = %d\n",SA->hr->data_start); printf("chars per rec = %d\n",SA->hr->cpr); if (strnicmp(cp[2],"FIEL",3)==0) { i = atoi(cp[3]); printf("%d\n",i); if (i == 0) { for (i=1;i<=SA->num_of_fields;i++) { printf(" Field %d Information \n",i); printf("field name char = %c\n",SA->fr[i]->field_name[0]); printf("field_type = %c\n",SA->fr[i]->field_type); printf("field_data_address = %d\n",SA->fr[i]->field_data_address); printf("field_length = %d\n",SA->fr[i]->field_length); printf("decimal_places = %d\n",SA->fr[i]->decimal_places) ; } } else { printf(" Field %d Information \n",i); printf("field name char = %c\n",SA->fr[i]->field_name[0]); printf("field_type = %c\n",SA->fr[i]->field_type); printf("field_data_address = %d\n",SA->fr[i]->field_data_address); printf("field_length = %d\n",SA->fr[i]->field_length); printf("decimal_places = %d\n",SA->fr[i]->decimal_places) ; } } } } fcloseall(); }