/* CMD_C - command interpreter for QL-Kermit Based on ckucmd.c, (C) Columbia University */ /* Include files */ #include "flp1_ctype_h" /* Character types */ #include "ram1_ker_h" /* Kermit definitions */ #include "ram1_cmd_h" /* Command parser definitions */ /* External variables */ extern char cmdbuf[]; /* Command buffer */ /* Local variables */ #define PROML 60 /* Maximum prompt length */ char cmprom[PROML+2]; /* Prompt string */ int cc = 0; /* Character count */ int cmflgs; /* Command flags */ char *dfprom = "Kermit> "; /* Default prompt */ char atmbuf[ATMBL+4]; /* Atom buffer */ char filbuf[ATMBL+4]; /* File name buffer */ static bool psetf = FALSE; /* Prompt set flag */ static char *bp; /* Command buffer position */ static char *pp; /* Start of current field */ static char *np; /* Start of next field */ /* CMSETP - Set the program prompt */ cmsetp(s) char *s; { char *strncpy(); psetf = TRUE; /* Flag that prompt is set */ strncpy(cmprom,s,PROML-1); /* Copy the string */ cmprom[PROML] = NUL; /* Ensure null terminator */ } /* PROMPT - Issue the program prompt */ prompt() { if (!psetf) cmsetp(dfprom); /* If not set, use default */ printf("%s",cmprom); /* Print the prompt */ } /* CMRES - Reset pointers to beginning of command buffer */ cmres() { cc = 0; /* Reset character counter */ pp = np = bp = cmdbuf; /* Point to command buffer */ cmflgs = -5; /* Parse not yet started */ } /* CMINI - Clear the command and atom buffers, reset pointers */ cmini() { for (bp = cmdbuf; bp0) /* End of line */ { error("Not confirmed - %s",atmbuf); return(-2); } else return(0); case 2: continue; /* ESC */ case 3: if (xc>0) /* Question mark */ { error("Not confirmed - %s",atmbuf); return(-2); } help("Type ENTER to confirm",NULL); continue; } } } /* LOOKUP - Lookup the string in the given array of strings Call with: table = a 'struct keytab' table word = the target string to look up in the table n = the number of elements in the table *x = an integer for returning the table array index The keyword table must be arranged in ascending alphabetical order, and all letters must be lowercase. Returns the keyword's associated value (zero or greater) if found, with the variable x set to the array index, or: -3 if nothing to look up (target was null), -2 if ambiguous, -1 if not found. A match is successful if the target matches a keyword exactly, or if the target is a prefix of exactly one keyword. It is ambiguous if the target matches two or more keywords from the table. */ int lookup(table,cmd,n,x) struct keytab table[]; char *cmd; int n; int *x; { int i,v,cmdlen; /* Lowercase & get length of target, if it's null return code -3 */ if ((((cmdlen = lower(cmd)))==0) || (n<1)) return(-3); /* Not null, look it up */ for (i = 0; icmdbuf) /* If still in buffer, */ { delch(); /* erase character from screen, */ bp--; /* point behind it, */ if (*bp==SP) inword = FALSE; /* Flag if current field gone */ *bp = NUL; /* Erase character from buffer */ } else cmres(); /* If all gone, start again */ if (pp<=bp) continue; else return(cmflgs = -1); } if (c==LDEL || c==F3) /* Line delete */ { while ((bp--)>cmdbuf) { delch(); /* Run back to beginning */ *bp = NUL; } cmres(); /* Restart the command */ inword = FALSE; return(cmflgs = -1); } if (c==RDIS) /* Redisplay */ { *bp = NUL; printf("\n%s%s",cmprom,cmdbuf); continue; } if (echof) putch(c); /* If tty input, echo */ inword = TRUE; /* Flag we're in a word */ if (c!=LF) *bp++ = c; /* and deposit it */ } /* Get here if buffer full */ error("Buffer full"); return(cmflgs = -2); } /* ADDBUF - Add the string *cp to the command buffer */ int addbuf(cp) char *cp; { int len = 0; while ((*cp!=NUL) && (bp