ckuusr.c
资源名称:cku197.tar.Z [点击查看]
上传用户:dufan58
上传日期:2007-01-05
资源大小:3407k
文件大小:233k
源码类别:
通讯/手机编程
开发平台:
Windows_Unix
- printf("?Unexpected switch value - %dn",cmresult.nresult);
- x = -9;
- goto xconnx;
- }
- }
- debug(F101,"doxconn cmresult.fcode","",cmresult.fcode);
- if (cmresult.fcode != _CMCFM) {
- printf("?Unexpected function code: %dn",cmresult.fcode);
- x = -9;
- goto xconnx;
- }
- #ifdef OS2 /* Make results available globally */
- if (pv[CONN_IL].ival > -1) /* Idle limit */
- tt_idlelimit = pv[CONN_IL].ival;
- if (pv[CONN_II].ival > -1) /* Idle limit */
- tt_idlesnd_tmo = pv[CONN_II].ival;
- if (pv[CONN_IS].sval) /* Idle string */
- if (tt_idlesnd_str = (char *)malloc((int)strlen(pv[CONN_IS].sval)+1))
- strcpy(tt_idlesnd_str,pv[CONN_IS].sval);
- if (pv[CONN_TL].ival > -1) /* Session limit */
- tt_timelimit = pv[CONN_TL].ival;
- #endif /* OS2 */
- #ifdef CK_TRIGGER
- if (pv[CONN_TS].sval) /* Trigger strings */
- makelist(pv[CONN_TS].sval,tt_trigger,TRIGGERS);
- for (i = 0; i < TRIGGERS; i++) /* Trigger match pointers */
- tt_trmatch[i] = NULL;
- if (triggerval) { /* Reset trigger value */
- free(triggerval);
- triggerval = NULL;
- }
- #endif /* CK_TRIGGER */
- x = doconect((pv[CONN_NV].ival > 0) ? 1 : 0);
- #ifdef CKLOGDIAL
- {
- int xx;
- debug(F101,"doxconn doconect returns","",x);
- if ((xx = ttchk()) < 0) dologend();
- debug(F101,"doxconn ttchk returns","",xx);
- }
- #endif /* CKLOGDIAL */
- #ifdef CK_TRIGGER
- debug(F111,"doxconn doconect triggerval",triggerval,x);
- #endif /* CK_TRIGGER */
- /* Back from CONNECT -- Restore global settings */
- #ifdef OS2
- tt_idlelimit = g_tt_idlelimit;
- tt_idlesnd_tmo = g_tt_idlesnd_tmo;
- tt_timelimit = g_tt_timelimit;
- tt_idlesnd_str = g_tt_idlesnd_str;
- #endif /* OS2 */
- #ifdef CK_TRIGGER
- for (i = 0; i < TRIGGERS; i++)
- tt_trigger[i] = g_tt_trigger[i];
- #endif /* CK_TRIGGER */
- xconnx:
- for (i = 0; i <= CONN_MAX; i++) { /* Free malloc'd memory */
- if (pv[i].sval)
- free(pv[i].sval);
- }
- success = (x > 0) ? 1 : 0;
- return(x);
- }
- #endif /* NOLOCAL */
- #ifdef ADDCMD
- /* cx == XXADD or XXREMV */
- /* fc == ADD_BIN or ADD_TXT */
- static int
- doadd(cx,fc) int cx, fc; {
- #ifdef PATTERNS
- char * tmp[FTPATTERNS];
- char **p = NULL;
- int i, n = 0, x = 0, last;
- #endif /* PATTERNS */
- if (cx != XXADD && cx != XXREMV) {
- printf("?Unexpected function code: %dn",cx);
- return(-9);
- }
- #ifdef PATTERNS
- while (n < FTPATTERNS) { /* Collect new patterns */
- tmp[n] = NULL;
- if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
- break;
- strcpy(line,s);
- s = brstrip(line);
- makestr(&(tmp[n++]),s);
- }
- if (x == -3)
- x = cmcfm();
- if (x < 0)
- goto xdoadd;
- p = (fc == ADD_BIN) ? binpatterns : txtpatterns; /* Which list */
- last = 0;
- for (i = 0; i < FTPATTERNS; i++) { /* Find last one in list */
- if (!p[i]) {
- last = i;
- break;
- }
- }
- if (cx == XXADD) { /* Adding */
- if (last + n > FTPATTERNS) { /* Check if too many */
- printf("?Too many patterns - %d is the maximumn", FTPATTERNS);
- goto xdoadd;
- }
- for (i = 0; i < n; i++) /* Copy in the new ones. */
- makestr(&(p[i+last]),tmp[i]);
- makestr(&(p[i+last]),NULL); /* Null-terminate the list */
- x = 1;
- goto xdoadd; /* Done */
- } else if (cx == XXREMV) { /* Remove something(s) */
- int j, k;
- if (last == 0) /* List is empty */
- goto xdoadd; /* Nothing to remove */
- for (i = 0; i < n; i++) { /* i = Patterns they typed */
- for (j = 0; j < last; j++) { /* j = Patterns in list */
- /* Change this to ckstrcmp()... */
- if (filecase)
- x = !strcmp(tmp[i],p[j]); /* Case-sensitive match */
- else
- x = ckstrcmp(tmp[i],p[j],-1,0); /* Case-independent match */
- if (x) { /* This one matches */
- makestr(&(p[j]),NULL); /* Free it */
- for (k = j; k < last; k++) /* Move the rest up */
- p[k] = p[k+1];
- p[k] = NULL; /* Erase last one */
- if (!p[k])
- break;
- }
- }
- }
- }
- xdoadd: /* Common exit */
- for (i = 0; i < n; i++)
- if (tmp[i])
- free(tmp[i]);
- return(x);
- #endif /* PATTERNS */
- }
- /* ADD SEND-LIST */
- static int
- addsend(cx) int cx; {
- #ifndef NOMSEND
- extern struct keytab fttab[];
- extern int nfttyp;
- struct filelist * flp;
- char * fmode = "";
- int xmode = 0;
- int xbinary = 0;
- #endif /* NOMSEND */
- #ifdef NOMSEND
- printf("?Sorry, ADD/REMOVE SEND-LIST not available.n");
- return(-9);
- #endif /* NOMSEND */
- if (cx == XXREMV) {
- printf("?Sorry, REMOVE SEND-LIST not implemented yet.n");
- return(-9);
- }
- #ifndef NOMSEND
- #ifndef XYZ_INTERNAL
- if (protocol != PROTO_K) {
- printf("?Sorry, ADD SEND-LIST does not work with external protocolsn");
- return(-9);
- }
- #endif /* XYZ_INTERNAL */
- x = cmifi("File specification to add","", &s,&y,xxstring);
- if (x < 0) {
- if (x == -3) {
- printf("?A file specification is requiredn");
- return(-9);
- } else
- return(x);
- }
- strcpy(tmpbuf,s);
- s = tmpbuf;
- if (filesinlist == 0) /* Take care of v(filespec) */
- fspec[0] = NUL;
- zfnqfp(s,LINBUFSIZ,line);
- s = line;
- if (((int)strlen(fspec) + (int)strlen(s) + 1) < fspeclen) {
- strcat(fspec,s);
- strcat(fspec," ");
- } else
- printf("WARNING - \v(filespec) buffer overflown");
- xbinary = binary;
- #ifdef PATTERNS
- if (patterns /* PATTERNS are ON */
- #ifdef CK_LABELED
- && binary != XYFT_L /* And not if FILE TYPE LABELED */
- #endif /* CK_LABELED */
- #ifdef VMS
- && binary != XYFT_I /* or FILE TYPE IMAGE */
- #endif /* VMS */
- ) {
- if (binary != XYFT_T && txtpatterns[0]) {
- int i;
- for (i = 0; i < FTPATTERNS && txtpatterns[i]; i++) {
- if (ckmatch(txtpatterns[i],line,filecase,1)) {
- xbinary = XYFT_T;
- break;
- }
- }
- }
- if (binary != XYFT_B && binpatterns[0]) {
- int i;
- for (i = 0; i < FTPATTERNS && binpatterns[i]; i++) {
- if (ckmatch(binpatterns[i],line,filecase,1)) {
- xbinary = XYFT_B;
- break;
- }
- }
- }
- }
- #endif /* PATTERNS */
- fmode = gfmode(xbinary,0);
- if ((x = cmkey(fttab,nfttyp,
- "type of file transfer", fmode, xxstring)) < 0)
- return(x);
- xmode = x;
- cmarg2 = "";
- if ((x = cmfld(y ?
- "nAs-name template containing replacement variables such as \v(filename)" :
- "Name to send it with", "",&s,NULL)) < 0)
- if (x != -3)
- return(x);
- #ifndef NOSPL
- if (y && *s) {
- char * p = tmpbuf;
- x = TMPBUFSIZ;
- zzstring(s,&p,&x);
- if (!strcmp(tmpbuf,s)) {
- printf(
- "?As-name for file group must contain variables such as \v(filename)n"
- );
- return(-9);
- }
- }
- #endif /* NOSPL */
- strcpy(tmpbuf,s);
- cmarg2 = tmpbuf;
- if ((x = cmcfm()) < 0)
- return(x);
- flp = (struct filelist *) malloc(sizeof(struct filelist));
- if (flp) {
- if (filetail)
- filetail->fl_next = flp;
- filetail = flp;
- if (!filehead)
- filehead = flp;
- x = (int) strlen(line); /* Length of filename */
- s = (char *) malloc(x + 1);
- if (s) {
- strcpy(s,line);
- flp->fl_name = s;
- flp->fl_mode = xmode;
- x = (int) strlen(cmarg2); /* Length of as-name */
- if (x < 1) {
- flp->fl_alias = NULL;
- } else {
- s = (char *) malloc(x + 1);
- if (s) {
- strcpy(s,cmarg2);
- flp->fl_alias = s;
- } else {
- printf("Sorry, can't allocate space for as-name");
- return(-9);
- }
- }
- flp->fl_next = NULL;
- filesinlist++; /* Count this node */
- return(success = 1); /* Finished adding this node */
- } else {
- printf("Sorry, can't allocate space for name");
- return(-9);
- }
- } else {
- printf("Sorry, can't allocate file list node");
- return(-9);
- }
- #endif /* NOMSEND */
- }
- #endif /* ADDCMD */
- #ifndef NOHTTP /* HTTP ops... */
- #ifdef TCPSOCKET
- #define HTTP_GET 0 /* GET */
- #define HTTP_PUT 1 /* PUT */
- #define HTTP_POS 2 /* POST */
- #define HTTP_IDX 3 /* INDEX */
- #define HTTP_HED 4 /* HEAD */
- #define HTTP_DEL 5 /* DELETE */
- static struct keytab httptab[] = {
- "delete", HTTP_DEL, 0,
- "get", HTTP_GET, 0,
- "head", HTTP_HED, 0,
- "index", HTTP_IDX, 0,
- "put", HTTP_PUT, 0,
- "post", HTTP_POS, 0
- };
- static int nhttptab = sizeof(httptab)/sizeof(struct keytab);
- /* HTTP switches */
- #define HT_SW_AG 0 /* /AGENT */
- #define HT_SW_HD 1 /* /HEADER */
- #define HT_SW_US 2 /* /USER */
- #define HT_SW_PW 3 /* /PASSWORD */
- #define HT_SW_AR 4
- static struct keytab httpswtab[] = {
- "/agent", HT_SW_AG, CM_ARG,
- #ifndef NOSPL
- "/array", HT_SW_AR, CM_ARG,
- #endif /* NOSPL */
- "/header", HT_SW_HD, CM_ARG,
- "/password", HT_SW_PW, CM_ARG,
- "/user", HT_SW_US, CM_ARG,
- "", 0, 0
- };
- static int nhttpswtab = sizeof(httpswtab)/sizeof(struct keytab) - 1;
- /* HTTP PUT/POST switches */
- #define HT_PP_MT 0 /* /MIME-TYPE */
- static struct keytab httpptab[] = {
- "/mime-type", HT_PP_MT, CM_ARG,
- "", 0, 0
- };
- static int nhttpptab = sizeof(httpptab)/sizeof(struct keytab) - 1;
- #define HTTP_MAXHDR 8
- static int
- dohttp(action, lfile, rf, agent, hdr, user, pass, mime, array)
- int action; char *lfile, *rf, *agent, *hdr, *user, *pass, *mime, array;
- /* dohttp */ {
- int i, rc = 0;
- char * hdrlist[HTTP_MAXHDR];
- char rfile[CKMAXPATH+1];
- /* Check for a valid state to execute the command */
- if (inserver) {
- printf("?The HTTP command may not be used from the IKSrn");
- } else if (!local || ttchk() < 0) {
- printf("?No connectionn");
- } else if (!network) {
- printf("?The HTTP command is not for serial connectionsn");
- } else if (nettype != NET_TCPB && nettype != NET_TCPA) {
- printf("?The HTTP command only for TCP/IP connectionsn");
- } else {
- rc = 1;
- }
- /* If the command is not valid, exit with failure */
- if (rc == 0)
- return(success = 0);
- if (rf[0] != '/') {
- rfile[0] = '/';
- ckstrncpy(&rfile[1],rf,CKMAXPATH);
- } else {
- ckstrncpy(rfile,rf,CKMAXPATH);
- }
- for (i = 0; i < HTTP_MAXHDR; i++) /* Initialize header list */
- hdrlist[i] = NULL;
- makelist(hdr,hdrlist,HTTP_MAXHDR); /* Make header list */
- #ifdef BETATEST
- for (i = 0; i < nhttptab; i++) /* Find action keyword */
- if (httptab[i].kwval == action)
- break;
- if (i == nhttptab) { /* Shouldn't happen... */
- printf("?Invalid action - %dn",action);
- return(success = 0);
- }
- printf("HTTP action: %sn",httptab[i].kwd);
- printf(" Agent: %sn",agent ? agent : "(null)");
- if (hdrlist[1]) {
- printf(" Header list: 1. %sn",hdrlist[0]);
- for (i = 1; i < HTTP_MAXHDR && hdrlist[i]; i++)
- printf("%15d. %sn",i+1,hdrlist[i]);
- } else
- printf(" Header: %sn",hdrlist[0] ? hdrlist[0] : "(null)");
- printf(" User: %sn",user ? user : "(null)");
- printf(" Password: %sn",pass ? pass : "(null)");
- #ifndef NOSPL
- if (array)
- printf(" Array: \%%%c[]n", array);
- else
- printf(" Array: (none)n");
- #endif /* NOSPL */
- if (action == HTTP_PUT || action == HTTP_POS)
- printf(" Mime-type: %sn",mime ? mime : "(null)");
- printf(" Local file: %sn",lfile ? lfile : "(null)");
- printf(" Remote file: %sn",rfile ? rfile : "(null)");
- #endif /* BETATEST */
- switch (action) {
- case HTTP_DEL:
- rc = http_delete(agent,hdrlist,user,pass,array,rfile);
- break;
- case HTTP_GET:
- rc = http_get(agent,hdrlist,user,pass,array,lfile,rfile);
- break;
- case HTTP_HED:
- rc = http_head(agent,hdrlist,user,pass,array,lfile,rfile);
- break;
- case HTTP_PUT:
- rc = http_put(agent,hdrlist,mime,user,pass,array,lfile,rfile);
- break;
- case HTTP_POS:
- rc = http_post(agent,hdrlist,mime,user,pass,array,lfile,rfile);
- break;
- case HTTP_IDX:
- rc = http_index(agent,hdrlist,user,pass,array,lfile,rfile);
- break;
- }
- return(success = ((rc < 0) ? 0 : 1));
- }
- #endif /* TCPSOCKET */
- #endif /* NOHTTP */
- #ifndef NOSPL /* ARRAY ops... */
- static struct keytab arraytab[] = {
- "clear", ARR_CLR, 0,
- "copy", ARR_CPY, 0,
- "dcl", ARR_DCL, CM_INV,
- "declare", ARR_DCL, 0,
- "destroy", ARR_DST, 0,
- "resize", ARR_RSZ, 0,
- "set", ARR_SET, 0,
- #ifndef NOSHOW
- "show", ARR_SHO, 0,
- #endif /* NOSHOW */
- "sort", ARR_SRT, 0,
- "", 0, 0
- };
- static int narraytab = sizeof(arraytab)/sizeof(struct keytab) - 1;
- int
- arrayitoa(x) int x; { /* Array index to array letter */
- if (x == 1)
- return(64);
- else if (x < 0 || x > (122 - ARRAYBASE))
- return(-1);
- else
- return(x + ARRAYBASE);
- }
- int
- arrayatoi(c) int c; { /* Array letter to array index */
- if (c == 64)
- c = 96;
- if (c > 63 && c < 91)
- c += 32;
- if (c < ARRAYBASE || c > 122)
- return(-1);
- return(c - ARRAYBASE);
- }
- static int
- dodcl() {
- int i, n, v, lo, hi, rc = 0;
- int isdynamic = 0;
- char ** p = NULL;
- char tmp[64]; /* Local temporary string buffer */
- if ((y = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
- if (y == -3) {
- printf("?Array name requiredn");
- return(-9);
- } else return(y);
- }
- #ifdef COMMENT
- if ((y = arraynam(s,&x,&n)) < 0) { /* Check it */
- if (y == -2 && n == -17) { /* Secret code for emtpy brackets */
- isdynamic = 1;
- n = CMDBL / 5;
- } else {
- return(y);
- }
- }
- debug(F111,"DCL",s,n);
- #else
- ckstrncpy(line,s,LINBUFSIZ);
- s = line;
- x = arraybounds(s,&lo,&hi);
- if (lo < 0 && hi < 0) {
- isdynamic = 1;
- n = CMDBL / 5;
- } else if (hi > -1) {
- printf("?Segment notation not allowed in array declarationsn");
- return(-9);
- } else
- n = lo;
- x = arrayitoa(x);
- #endif /* COMMENT */
- p = (char **)malloc(sizeof(char **)*(n+1));
- if (!p) {
- printf("?Memory allocation errorn");
- return(-9);
- }
- v = 0; /* Highest initialized member */
- p[0] = NULL; /* Element 0 */
- while (n > 0 && v < n) { /* Parse initializers */
- p[v+1] = NULL;
- sprintf(tmp,"Initial value for \&%c[%d]",x,v+1); /* Help string */
- if ((rc = cmfld((char *)tmp,"",&s,xxstring)) < 0) { /* Get field */
- if (rc == -3) /* If answer is empty, we're done */
- break;
- else /* Parse error, free temp pointers */
- goto dclx;
- }
- rc = 1;
- if (v == 0 && !strcmp(s,"=")) /* Skip the = sign. */
- continue;
- s = brstrip(s); /* Strip any braces */
- makestr(&(p[++v]),s);
- }
- if ((y = cmtxt("Carriage return to confirm","",&s,NULL)) < 0)
- return(y);
- if (isdynamic)
- n = v;
- if (dclarray((char)x,n) < 0) { /* Declare the array */
- printf("?Declare failedn");
- goto dclx;
- }
- for (i = 1; i <= v; i++) { /* Add any initial values */
- sprintf(tmp,"&%c[%d]",(char)x,i);
- if (addmac(tmp,p[i]) < 0) {
- printf("Array initialization error: %s %sn",tmp,p[i]);
- rc = -9;
- goto dclx;
- }
- }
- dclx:
- if (p) {
- for (i = 1; i <= v; i++)
- if (p[i]) free(p[i]);
- free(p);
- }
- debug(F101,"DCL rc","",rc);
- return(success = rc);
- }
- static int
- rszarray() {
- int i, x, y, n, lo, hi;
- char c, * s, ** ap = NULL;
- if ((x = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
- if (x == -3) {
- printf("?Array name requiredn");
- return(-9);
- } else return(x);
- }
- ckstrncpy(line,s,LINBUFSIZ); /* Make safe copy of name */
- s = line;
- x = arraybounds(s,&lo,&hi);
- if (lo < 0 && hi < 0) {
- y = cmnum("New size","",10,&lo,xxstring);
- if (y < 0) {
- if (y == -3)
- printf("?New size requiredn");
- return(y);
- }
- }
- if ((y = cmcfm()) < 0)
- return(y);
- if (x < 0) { /* Parse the name, get index */
- printf("?Bad array reference - "%s"n", s);
- return(-9);
- }
- if (!a_ptr[x]) {
- printf("?Array not declared - "%s"n", s);
- return(-9);
- }
- if (lo < 0) {
- printf("?New size requiredn");
- return(-9);
- }
- if (hi > -1) {
- printf("?Array segments not allowed for this operationn");
- return(-9);
- }
- c = arrayitoa(x); /* Get array letter */
- if (c == '@') { /* Argument vector array off limits */
- printf("?Sorry, \&@[] is read-onlyn");
- return(-9);
- }
- if (lo == 0) { /* If new size is 0... */
- dclarray(c,0); /* Undeclare the array */
- return(success = 1);
- }
- n = a_dim[x]; /* Current size */
- ap = (char **) malloc((lo+1) * sizeof(char *)); /* New array */
- y = (n < lo) ? n : lo;
- for (i = 0; i <= y; i++) /* Copy the part that fits */
- ap[i] = a_ptr[x][i];
- if (n < lo) { /* If original array smaller */
- for (; i <= lo; i++) /* initialize extra elements in */
- ap[i] = NULL; /* new array to NULL. */
- } else if (n > lo) { /* If new array smaller */
- for (; i <= lo; i++) /* deallocate leftover elements */
- makestr(&(a_ptr[x][i]),NULL); /* from original array. */
- }
- free(a_ptr[x]); /* Free original array list */
- a_ptr[x] = ap; /* Replace with new one */
- a_dim[x] = lo; /* Record the new dimension */
- return(success = 1);
- }
- static int
- copyarray() {
- int i, j, x1, lo1, hi1, x2, lo2, hi2, whole = 0;
- char c1, c2, * a1, * a2;
- if ((y = cmfld("Name of source array","",&s,NULL)) < 0)
- return(y);
- ckstrncpy(line,s,LINBUFSIZ);
- a1 = line;
- if ((x1 = arraybounds(a1,&lo1,&hi1)) < 0) {
- printf("?Bad array reference - "%s"n", a1);
- return(-9);
- } else if (!a_ptr[x1]) {
- printf("?Array not declared - "%s"n", a1);
- return(-9);
- }
- c1 = arrayitoa(x1);
- if ((y = cmfld("Name of destination array","",&s,NULL)) < 0)
- return(y);
- ckstrncpy(tmpbuf,s,TMPBUFSIZ);
- a2 = tmpbuf;
- if ((x2 = arraybounds(a2,&lo2,&hi2)) < 0) {
- printf("?Bad array reference - "%s"n", a2);
- return(-9);
- }
- c2 = arrayitoa(x2);
- if ((x = cmcfm()) < 0)
- return(x);
- if (c2 == '@') { /* Argument vector array off limits */
- printf("?Sorry, \&@[] is read-onlyn");
- return(-9);
- }
- if (lo1 < 0 && lo2 < 0 && hi1 < 0 && hi2 < 0) /* Special case for */
- whole = 1; /* whole array... */
- if (lo1 < 0) lo1 = whole ? 0 : 1; /* Supply lower bound of source */
- if (hi1 < 0) hi1 = a_dim[x1]; /* Supply upper bound of source */
- if (lo2 < 0) lo2 = whole ? 0 : 1; /* Lower bound of target */
- if (hi2 < 0) hi2 = lo2 + hi1 - lo1; /* Upper bound of target */
- if (a_ptr[x2]) { /* Target array is already declared? */
- if (hi2 > a_dim[x2]) /* If upper bound out of range */
- hi2 = a_dim[x2]; /* shrink to fit */
- } else { /* Otherwise... */
- x2 = dclarray(c2, hi2); /* declare the target array */
- }
- for (i = lo1, j = lo2; i <= hi1 && j <= hi2; i++,j++) { /* Copy */
- makestr(&(a_ptr[x2][j]),a_ptr[x1][i]);
- }
- return(success = 1);
- }
- static int /* Undeclare an array */
- unarray() {
- int x, y, n, rc = 0;
- char c, * s;
- if ((y = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
- if (y == -3) {
- printf("?Array name requiredn");
- return(-9);
- } else return(y);
- }
- ckstrncpy(line,s,LINBUFSIZ); /* Make safe copy of name */
- s = line;
- if ((y = cmcfm()) < 0)
- return(y);
- if ((x = arraybounds(s,&y,&n)) < 0) { /* Parse the name, get index */
- printf("?Bad array reference - "%s"n", s);
- return(-9);
- }
- if (y > 0 || n > 0) {
- printf("?Partial arrays can not be destroyedn");
- return(-9);
- }
- c = arrayitoa(x); /* Get array letter */
- if (a_ptr[x]) { /* If array is declared */
- if (c == '@') { /* Argument vector array off limits */
- printf("?Sorry, \&@[] is read-onlyn");
- return(-9);
- }
- rc = dclarray(c,0); /* Undeclare the array */
- } else /* It wasn't declared */
- rc = 1;
- if (rc > -1) { /* Set return code and success */
- success = 1;
- rc = 1;
- } else {
- success = 0;
- printf("?Failed - destroy "\&%c[]"n", c);
- rc = -9;
- }
- return(rc);
- }
- static int
- clrarray(cx) int cx; {
- int i, x, lo, hi;
- char c, * s, * val = NULL;
- if ((x = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
- if (x == -3) {
- printf("?Array name requiredn");
- return(-9);
- } else return(x);
- }
- ckstrncpy(line,s,LINBUFSIZ); /* Make safe copy of name */
- s = line;
- if (cx == ARR_SET) { /* SET */
- if ((x = cmtxt("Value","",&val,xxstring)) < 0)
- return(x);
- ckstrncpy(tmpbuf,val,TMPBUFSIZ); /* Value to set */
- val = tmpbuf;
- if (!*val) val = NULL;
- } else if ((x = cmcfm()) < 0) /* CLEAR */
- return(x);
- if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Parse the name */
- printf("?Bad array reference - "%s"n", s);
- return(-9);
- }
- c = arrayitoa(x); /* Get array letter */
- if (!a_ptr[x]) { /* If array is declared */
- printf("?Array %s is not declaredn", s);
- return(-9);
- } else if (c == '@') { /* Argument vector array off limits */
- printf("?Sorry, \&@[] is read-onlyn");
- return(-9);
- }
- if (lo < 0) lo = 0;
- if (hi < 0) hi = a_dim[x];
- for (i = lo; i <= hi; i++) /* Clear/Set selected range */
- makestr(&(a_ptr[x][i]),val);
- return(success = 1);
- }
- #endif /* NOSPL */
- /* D O C M D -- Do a command */
- /*
- Returns:
- -2: user typed an illegal command
- -1: reparse needed
- 0: parse was successful (even tho command may have failed).
- */
- int
- docmd(cx) int cx; {
- debug(F101,"docmd entry, cx","",cx);
- activecmd = cx;
- doconx = ((activecmd == XXCON) || (activecmd == XXTEL) ||
- (activecmd == XXRLOG) || (activecmd == XXPIPE) ||
- (activecmd == XXIKSD) || (activecmd == XXPTY));
- /*
- Massive switch() broken up into many smaller ones, for the benefit of
- compilers that run out of space when trying to handle large switch
- statements.
- */
- switch (cx) {
- case -4: /* EOF */
- #ifdef OSK
- if (msgflg) printf("n");
- #else
- if (msgflg) printf("rn");
- #endif /* OSK */
- doexit(GOOD_EXIT,xitsta);
- case -3: /* Null command */
- return(0);
- case -9: /* Like -2, but errmsg already done */
- case -1: /* Reparse needed */
- return(cx);
- case -6: /* Special */
- case -2: /* Error, maybe */
- #ifndef NOSPL
- /*
- Maybe they typed a macro name. Let's look it up and see.
- */
- if (cx == -6) /* If they typed CR */
- strcat(cmdbuf,"