ecu - SCO XENIX V/{2,3}86 Extended CU part 13/47
Warren Tucker
wht at tridom.uucp
Mon Oct 9 07:52:57 AEST 1989
---- Cut Here and unpack ----
#!/bin/sh
# this is part 13 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file ecuxfer.c continued
#
CurArch=13
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
exit 1; fi
( read Scheck
if test "$Scheck" != $CurArch
then echo "Please unpack part $Scheck next!"
exit 1;
else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file ecuxfer.c"
sed 's/^X//' << 'SHAR_EOF' >> ecuxfer.c
X stand_end();
X ff(se,"\r\n");
X }
X
X ff(se,"\r\n");
X
X file_xfer_done_bell();
X start_rcvr_process(1);
X} /* end of send_files_to_remote */
X
X/*+-------------------------------------------------------------------------
X receive_files_from_remote(argc,argv)
X--------------------------------------------------------------------------*/
Xvoid
Xreceive_files_from_remote(argc,argv)
Xint argc;
Xchar **argv;
X{
Xregister itmp;
Xchar execcmd[256];
Xint xfertype;
Xchar bottom_label[64];
X
X sprintf(bottom_label,"-C 'Connected to %s' ",
X (Llogical[0]) ? Llogical : "?");
X
X switch(to_lower(*(argv[0] + 1)))
X {
X case 'k': xfertype = CKERMIT; break;
X case 's': xfertype = ECUSEA; break;
X case 'x': xfertype = ECURZ_X; break;
X case 'y': xfertype = ECURZ_Y; break;
X case 'z': xfertype = ECURZ_Z; break;
X default: ff(se,"receive command invalid\n");
X return;
X }
X
X if(xfertype == ECURZ_X)
X {
X char p[128];
X kill_rcvr_process(SIGUSR1);
X sprintf(execcmd,"ecurz -X -. %d -c ",Liofd);
X strcat(execcmd,bottom_label);
X if(protocol_log_packets)
X strcpy(&execcmd[strlen(execcmd) ],"-, ");
X
X /* get xmodem ascii or binary */
X ff(se," Translate CR/LF to NL (ASCII)? ");
X switch(itmp = to_lower(ttygetc(0)))
X {
X case 'y': strcat(execcmd,"-a "); break;
X case 'n': strcat(execcmd,"-b "); break;
X default:
X ff(se,"transfer abandoned\r\n");
X start_rcvr_process(1);
X return;
X }
X ff(se,"%s\r\n",(itmp == 'y') ? "yes" : "no");
X ff(se,"File name to receive via XMODEM/CRC: ");
X ttygets(p,sizeof(p),1);
X if( (p[0] != ESC) && strlen(p) )
X {
X strcat(execcmd,p);
X file_xfer_start();
X exec_cmd(execcmd);
X file_xfer_done_bell();
X }
X else
X ff(se,"transfer abandoned\r\n");
X }
X else if(xfertype == ECURZ_Y)
X {
X ff(se,"\r\n");
X kill_rcvr_process(SIGUSR1);
X sprintf(execcmd,"ecurz -Y -. %d -y ",Liofd);
X strcat(execcmd,bottom_label);
X if(protocol_log_packets)
X strcpy(&execcmd[strlen(execcmd) ],"-, ");
X file_xfer_start();
X exec_cmd(execcmd);
X file_xfer_done_bell();
X }
X else if(xfertype == ECURZ_Z)
X {
X ff(se,"\r\n");
X kill_rcvr_process(SIGUSR1);
X sprintf(execcmd,"ecurz -Z -. %d ",Liofd);
X strcat(execcmd,bottom_label);
X if(protocol_log_packets)
X sprintf(&execcmd[strlen(execcmd) ],"-, ");
X file_xfer_start();
X exec_cmd(execcmd);
X file_xfer_done_bell();
X }
X else if(xfertype == CKERMIT)
X {
X kill_rcvr_process(SIGUSR1);
X sprintf(execcmd,"ckermit -r -e 512 -l %d -b %d -p %c",
X Liofd,Lbaud,(Lparity) ? Lparity : 'n');
X ff(se," Translate CR/LF to NL (ASCII)? ");
X switch(itmp = to_lower(ttygetc(0)))
X {
X case 'y': strcat(execcmd," -i"); break;
X case 'n': break;
X default:
X ff(se,"transfer abandoned\r\n");
X start_rcvr_process(1);
X return;
X }
X ff(se,"%s\r\n",(itmp == 'a') ? "yes" : "no");
X file_xfer_start();
X exec_cmd(execcmd);
X file_xfer_done_bell();
X }
X else if(xfertype == ECUSEA)
X {
X kill_rcvr_process(SIGUSR1);
X sprintf(execcmd,"ecusea -r -. %d -/ %s",Liofd,curr_dir);
X if(protocol_log_packets)
X strcat(execcmd," -,");
X file_xfer_start();
X exec_cmd(execcmd);
X file_xfer_done_bell();
X }
X lreset_ksr();
X start_rcvr_process(1);
X} /* end of receive_files_from_remote */
X/* end of ecuxfer.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo "File ecuxfer.c is complete"
chmod 0644 ecuxfer.c || echo "restore of ecuxfer.c fails"
echo "x - extracting esdutil.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > esdutil.c &&
X/* CHK=0x7C00 */
X/*+----------------------------------------------------------------
X esdutil.c - ecu extended string descriptor manipulation
X Copyright 1989 Warren H. Tucker, III. All Rights Reserved
X
X Defined functions:
X append_zstr_to_esd(param,zstr)
X end_of_cmd(param)
X esdstrindex(esd1,esd2,index1_flag,index2_flag)
X fgetesd(param,fileptr)
X fputesd(param,fileptr,index_flag,nl_flag)
X free_esd(tesd)
X get_alpha_zstr(param,strbuf,strbuf_maxcb)
X get_alphanum_zstr(param,strbuf,strbuf_maxcb)
X get_cmd_char(param,pchar)
X get_numeric_value(param,value)
X get_numeric_zstr(param,strbuf,strbuf_maxcb)
X get_switches(param,switches,switches_max)
X get_word_zstr(param,strbuf,strbuf_maxcb)
X init_esd(tesd,cptr,maxcb)
X keyword_lookup(ktable,param)
X make_esd(maxcb)
X null_terminate_esd(tesd)
X show_esd(tesd,title)
X skip_cmd_break(param)
X skip_cmd_char(param,skipchar)
X skip_colon(param)
X skip_comma(param)
X skip_paren(param,fLeft)
X strindex(str1,str2)
X strip_trailing_spaces_esd(ztext)
X zero_esd(tesd)
X
X-----------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-03-1989-22:57-wht------------- ecu 2.00 ---------------- */
X/*:06-24-1989-16:53-wht-flush edits --- ecu 1.95 */
X
X#include <ctype.h>
X#include "ecu.h"
X#include "ecuerror.h"
X#include "esd.h"
X
Xchar *malloc();
X
X/*+-------------------------------------------------------------------------
X null_terminate_esd(&esd)
X puts null at 'cb' position of string (standard esd always
X has one more byte in buffer than maxcb says)
X--------------------------------------------------------------------------*/
Xvoid
Xnull_terminate_esd(tesd)
Xregister ESD *tesd;
X{
X tesd->pb[tesd->cb] = 0;
X} /* end of null_terminate_esd */
X
X/*+-----------------------------------------------------------------------
X zero_esd(tesd) zero an esd
X------------------------------------------------------------------------*/
Xvoid
Xzero_esd(tesd)
Xregister ESD *tesd;
X{
X tesd->cb = 0; /* current count == 0 */
X tesd->index = 0; /* parse index to first position */
X tesd->old_index = 0; /* parse index to first position */
X *tesd->pb = 0; /* start with null terminated string */
X
X} /* end of zero_esd */
X
X/*+-----------------------------------------------------------------------
X init_esd(tesd,cptr,maxcb) init an esd
X------------------------------------------------------------------------*/
Xvoid
Xinit_esd(tesd,cptr,maxcb)
Xregister ESD *tesd;
Xchar *cptr;
Xregister maxcb;
X{
X tesd->pb = cptr; /* pointer to string */
X tesd->maxcb = maxcb; /* max characters in buffer */
X zero_esd(tesd);
X
X} /* end of init_esd */
X
X/*+-----------------------------------------------------------------------
X esdptr = make_esd(maxcb) allocate an esd and buffer
X------------------------------------------------------------------------*/
XESD *
Xmake_esd(maxcb)
Xregister maxcb; /* desired maxcb */
X{
Xregister ESD *tesd;
Xregister actual_cb;
X
X /* we get an extra character to ensure room for null past maxcb */
X actual_cb = maxcb + sizeof(ESD) + 1;
X if(actual_cb & 1) /* even allocation */
X ++actual_cb;
X if((tesd = (ESD *)malloc( (unsigned)actual_cb )) == NULL)
X return((ESD *)0); /* return NULL if failure */
X
X init_esd(tesd,(char *)(tesd + 1),maxcb);
X return(tesd);
X
X} /* end of make_esd */
X
X/*+-----------------------------------------------------------------------
X free_esd(esdptr)
X------------------------------------------------------------------------*/
Xvoid
Xfree_esd(tesd)
Xregister ESD *tesd;
X{
X tesd->maxcb = 0;
X tesd->cb = 0;
X free((char *)tesd);
X}
X
X/*+-------------------------------------------------------------------------
X show_esd(tesd,title)
X--------------------------------------------------------------------------*/
Xvoid
Xshow_esd(tesd,title)
XESD *tesd;
Xchar *title;
X{
Xregister itmp;
X
X if(title && *title)
X {
X pputs(title);
X pputs("\n");
X }
X null_terminate_esd(tesd);
X pputs(tesd->pb);
X pputs("\n");
X for(itmp = 0; itmp <= tesd->cb; itmp++)
X {
X if(itmp == tesd->old_index)
X pputc('^');
X else if(itmp == tesd->index)
X pputc('^');
X else
X pputc(' ');
X if((itmp > tesd->old_index) && (itmp > tesd->index))
X break;
X }
X pprintf(" o%d i%d c%d\n",tesd->old_index,tesd->index,tesd->cb);
X
X} /* end of show_esd */
X
X/*+----------------------------------------------------------------
X strindex: string index function
X
X Returns position of 'str2' in 'str1' if found
X If 'str2' is null, then 0 is returned (null matches anything)
X Returns -1 if not found
X-----------------------------------------------------------------*/
Xint
Xstrindex(str1,str2)
Xchar *str1; /* the (target) string to search */
Xchar *str2; /* the (comparand) string to search for */
X{
Xregister istr1 = 0;
Xregister lstr2 = strlen(str2);
Xregister char *mstr = str1; /* the (target) string to search */
X
X if(*str2 == 0) /* null string matches anything */
X return(0);
X
X while(*mstr)
X {
X if(*mstr == *str2)
X { /* we have a first char match... does rest of string match? */
X if(!strncmp(mstr,str2,lstr2))
X return(istr1); /* if so, return match position */
X }
X mstr++;
X istr1++;
X }
X
X return(-1); /* if we exhaust target string, flunk */
X
X} /* end of strindex */
X
X/*+-------------------------------------------------------------------------
X esdstrindex(esd1,esd2,index1_flag,index2_flag)
X
X Call strindex with esd1->pb and esd2->pb.
X If index1_flag != 0, esd1->pb + esd1->index passed
X If index2_flag != 0, esd2->pb + esd2->index passed
X--------------------------------------------------------------------------*/
Xesdstrindex(esd1,esd2,index1_flag,index2_flag)
Xregister ESD *esd1;
Xregister ESD *esd2;
Xregister index1_flag;
Xregister index2_flag;
X{
X return(strindex((index1_flag) ? esd1->pb : esd1->pb + esd1->index,
X (index2_flag) ? esd2->pb : esd2->pb + esd2->index));
X
X} /* end of esdstrindex */
X
X/*+----------------------------------------------------------------
X keyword_lookup(ktable,param)
X
X Lookup string in keyword_table struct array
X Returns table->key_token if 'param' found in
X 'table', else -1
X
X Beware substrings. "type","typedef" will both match "type"
X-----------------------------------------------------------------*/
Xkeyword_lookup(ktable,param)
Xregister KEYTAB *ktable;
Xregister char *param;
X{
Xregister plen = strlen(param);
X
X while(ktable->key_word)
X {
X if(!strncmp(ktable->key_word,param,plen))
X return(ktable->key_token);
X ++ktable;
X } /* end of while */
X
X return(-1); /* search failed */
X
X} /* end of keyword_lookup */
X
X/*+----------------------------------------------------------------
X skip_cmd_break(param)
X
X Finds next non-break
X
X 'param' is an esd with valid 'index' field
X Returns 0 index field points to non-break character
X eNoParameter end of command found
X-----------------------------------------------------------------*/
Xint
Xskip_cmd_break(param)
Xregister ESD *param;
X{
Xregister cb = param->cb;
Xregister index = param->index;
Xregister char *pb = param->pb;
X
X while(index < cb)
X {
X if(!isspace(*(pb + index)))
X break;
X index++;
X }
X param->old_index = param->index = index;
X if(index >= cb)
X return(eNoParameter);
X return(0);
X
X} /* end of skip_cmd_break */
X
X/*+-------------------------------------------------------------------------
X end_of_cmd(param) - return 1 if at end of command
X--------------------------------------------------------------------------*/
Xint
Xend_of_cmd(param)
Xregister ESD *param;
X{
X if(skip_cmd_break(param) || (*(param->pb + param->index) == ';') ||
X (*(param->pb + param->index) == '#'))
X return(1);
X return(0);
X} /* end of end_of_cmd */
X
X/*+-------------------------------------------------------------------------
X erc = skip_cmd_char(param,skipchar)
X--------------------------------------------------------------------------*/
Xint
Xskip_cmd_char(param,skipchar)
Xregister ESD *param;
Xregister char skipchar;
X{
Xint erc;
X
X if(erc = skip_cmd_break(param))
X return(erc);
X
X if(param->pb[param->index] == skipchar)
X {
X ++param->index;
X return(0);
X }
X
X return(eSyntaxError);
X
X} /* end of skip_cmd_char */
X
X/*+-------------------------------------------------------------------------
X erc = skip_colon(param)
X--------------------------------------------------------------------------*/
Xint
Xskip_colon(param)
Xregister ESD *param;
X{
X register erc;
X
X if(erc = skip_cmd_break(param))
X return(erc);
X
X if(param->pb[param->index] == ':')
X {
X ++param->index;
X return(0);
X }
X
X return(eCommaExpected);
X
X} /* end of skip_colon */
X
X/*+-------------------------------------------------------------------------
X erc = skip_comma(param)
X--------------------------------------------------------------------------*/
Xint
Xskip_comma(param)
Xregister ESD *param;
X{
X register erc;
X
X if(erc = skip_cmd_break(param))
X return(erc);
X
X if(param->pb[param->index] == ',')
X {
X ++param->index;
X return(0);
X }
X
X return(eCommaExpected);
X
X} /* end of skip_comma */
X
X/*+-------------------------------------------------------------------------
X erc = skip_paren(fparam,LEFT or RIGHT)
X--------------------------------------------------------------------------*/
Xint
Xskip_paren(param,fLeft)
Xregister ESD *param;
Xint fLeft;
X{
Xregister erc = (fLeft) ? eMissingLeftParen : eMissingRightParen;
Xregister char search = (fLeft) ? '(' : ')';
X
X if(erc = skip_cmd_break(param))
X return(erc);
X
X if(param->pb[param->index] == search)
X {
X param->index++;
X return(0);
X }
X return(erc);
X
X} /* end of skip_paren */
X
X/*+-------------------------------------------------------------------------
X get_cmd_char(param,pchar)
X--------------------------------------------------------------------------*/
Xint
Xget_cmd_char(param,pchar)
Xregister ESD *param;
Xchar *pchar;
X{
Xint erc;
X
X if(erc = skip_cmd_break(param))
X return(erc);
X *pchar = param->pb[param->index++];
X return(0);
X
X} /* end of get_cmd_char */
X
X/*+----------------------------------------------------------------
X get_alpha_zstr(&esd,&strbuf,strbuf_maxcb)
X
X places next alphabetic string token [A_Za_z_] into
X the null-terminated 'strbuf' string. returns 0 or -1
X or skip_cmd_break error codes
X-----------------------------------------------------------------*/
Xint
Xget_alpha_zstr(param,strbuf,strbuf_maxcb)
XESD *param;
Xregister char *strbuf;
Xint strbuf_maxcb;
X{
Xregister izstr;
Xregister schar;
Xregister char *pb = param->pb;
X
X if(izstr = skip_cmd_break(param))
X return(izstr);
X izstr = 0;
X while( (izstr < strbuf_maxcb-1) && (param->index < param->cb) )
X {
X schar = pb[param->index];
X if((!isalpha(schar)) && (schar != '_'))
X break;
X strbuf[izstr++] = schar;
X param->index++;
X }
X
X strbuf[izstr] = 0;
X return(izstr ? 0 : eBadParameter);
X
X} /* end of get_alpha_zstr */
X
X/*+----------------------------------------------------------------
X get_alphanum_zstr(&esd,&strbuf,strbuf_maxcb)
X
X places next alphanumeric string token [A-Za-z0-9_]
X into the null-terminated 'strbuf' string. returns 0
X or -1 or skip_cmd_break error codes
X-----------------------------------------------------------------*/
Xint
Xget_alphanum_zstr(param,strbuf,strbuf_maxcb)
Xregister ESD *param;
Xregister char *strbuf;
Xint strbuf_maxcb;
X{
Xint izstr = 0;
Xint schar;
Xregister cb = param->cb;
Xregister index;
X
X if(izstr = skip_cmd_break(param))
X return(izstr);
X
X index = param->index;
X while( (izstr < strbuf_maxcb-1) && (index < cb))
X {
X schar = param->pb[index++];
X if(isalnum(schar) || (schar == '_'))
X strbuf[izstr++] = schar;
X else
X {
X --index;
X break;
X }
X }
X
X param->index = index;
X strbuf[izstr]=0;
X return(izstr ? 0 : eBadParameter);
X
X} /* end of get_alphanum_zstr */
X
X/*+----------------------------------------------------------------
X get_numeric_zstr(&esd,&strbuf,strbuf_maxcb)
X gets next numeric string token places it
X into the null-terminated 'strbuf' string. returns 0 or -1
X or skip_cmd_break error codes
X-----------------------------------------------------------------*/
Xint
Xget_numeric_zstr(param,strbuf,strbuf_maxcb)
Xregister ESD *param;
Xregister char *strbuf;
Xregister strbuf_maxcb;
X{
X register izstr;
X register schar;
X
X if(izstr = skip_cmd_break(param))
X return(izstr);
X
X while( (izstr < strbuf_maxcb-1) && (param->index < param->cb) )
X {
X schar = param->pb[param->index++];
X if( isdigit(schar) )
X strbuf[izstr++]=schar;
X else
X {
X --param->index;
X break;
X }
X }
X
X strbuf[izstr]=0;
X return(izstr ? 0 : eBadParameter);
X
X} /* end of get_numeric_zstr */
X
X/*+-----------------------------------------------------------------------
X get_numeric_value(param,&long_var)
X------------------------------------------------------------------------*/
Xget_numeric_value(param,value)
Xregister ESD *param;
Xregister long *value;
X{
Xregister erc;
Xchar buf[32];
X
X if(erc = get_numeric_zstr(param,buf,sizeof(buf)))
X return(erc);
X sscanf(buf,"%ld",value);
X return(0);
X
X} /* end of get_numeric_value */
X
X/*+----------------------------------------------------------------
X get_word_zstr(&esd,&strbuf,strbuf_maxcb)
X
X gets next word (continuous string of characters without spaces
X or tabs) returns 0 or -1 or skip_cmd_break error codes
X-----------------------------------------------------------------*/
Xint
Xget_word_zstr(param,strbuf,strbuf_maxcb)
Xregister ESD *param;
Xregister char *strbuf;
Xregister strbuf_maxcb;
X{
X register izstr;
X register schar;
X
X if(izstr = skip_cmd_break(param))
X return(izstr);
X
X while( (izstr < strbuf_maxcb-1) && (param->index < param->cb) )
X {
X schar = param->pb[param->index++];
X if( (schar > 0x20) && (schar <= 0x7e))
X strbuf[izstr++]=schar;
X else
X {
X --param->index;
X break;
X }
X }
X
X strbuf[izstr]=0;
X return(izstr ? 0 : eBadParameter);
X
X} /* end of get_word_zstr */
X
X/*+-------------------------------------------------------------------------
X strip_trailing_spaces_esd(param)
X--------------------------------------------------------------------------*/
Xvoid
Xstrip_trailing_spaces_esd(ztext)
Xregister ESD *ztext;
X{
X while(ztext->cb && (ztext->pb[ztext->cb-1] == 0x20))
X ztext->cb--;
X} /* end of strip_trailing_spaces_esd */
X
X/*+-------------------------------------------------------------------------
X fgetesd(&esd,fileptr)
X
X stdio read from FILE *fileptr into esd
X returns param->cb set up not including trailing nl, param->index == 0
X--------------------------------------------------------------------------*/
Xint
Xfgetesd(param,fileptr)
Xregister ESD *param;
Xregister FILE *fileptr;
X{
Xregister char *cptr;
X
X if(fgets(param->pb,param->maxcb,fileptr) == NULL)
X return(eEOF);
X if((cptr = strchr(param->pb,0x0A)) == NULL)
X return(eBufferTooSmall);
X param->cb = (int)(cptr - param->pb);
X null_terminate_esd(param);
X param->index = 0;
X param->old_index = 0;
X return(0);
X
X} /* end of fgetesd */
X
X/*+-------------------------------------------------------------------------
X fputesd(&esd,fileptr,index_flag,nl_flag)
X
X write esd contents to stdio FILE *fileptr
X if index_flag is true, write from param->index thru end of esd
X otherwise, from start of esd
X if nl_flag is true, append nl to write, else just esd contents
X--------------------------------------------------------------------------*/
Xint
Xfputesd(param,fileptr,index_flag,nl_flag)
Xregister ESD *param;
XFILE *fileptr;
Xint index_flag;
Xint nl_flag;
X{
Xregister char *cptr;
Xregister write_length;
X
X if(index_flag)
X {
X cptr = ¶m->pb[param->index];
X write_length = param->cb - param->index;
X }
X else
X {
X cptr = param->pb;
X write_length = param->cb;
X }
X
X if(write_length)
X fwrite(cptr,write_length,1,fileptr);
X
X if(nl_flag)
X fputc(0x0A,fileptr);
X
X return(0);
X} /* end of fputesd */
X
X/*+-----------------------------------------------------------------
X append_zstr_to_esd(param,zstr)
X------------------------------------------------------------------*/
Xappend_zstr_to_esd(param,zstr)
XESD *param;
Xchar *zstr;
X{
Xregister zstrlen = strlen(zstr);
Xregister erc = 0;
X
X if(zstrlen > (param->maxcb - param->cb))
X {
X zstrlen = param->maxcb - param->cb;
X erc = eBufferTooSmall;
X }
X
X if(zstrlen)
X {
X strncpy(param->pb + param->cb,zstr,zstrlen);
X param->cb += zstrlen;
X }
X return(erc);
X}
X
X/*+-------------------------------------------------------------------------
X get_switches(param,switches,switches_max)
X--------------------------------------------------------------------------*/
Xint
Xget_switches(param,switches,switches_max)
XESD *param;
Xchar *switches;
Xint switches_max;
X{
Xregister itmp;
Xregister index;
Xregister char *pb = param->pb;
Xint cb = param->cb;
Xchar schar;
X
X *switches = 0;
X
X if(itmp = skip_cmd_break(param))
X return(itmp);
X
X index = param->index;
X if(*(param->pb + index) != '-')
X return(eNoSwitches);
X
X switches_max--;
X *switches++ = '-';
X index++;
X while((itmp < switches_max) && (index < cb))
X {
X schar = *(pb + index++);
X if(isspace(schar))
X break;
X *switches++ = schar;
X }
X
X param->index = index;
X *switches = 0;
X return(0);
X
X} /* end of get_switches() */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of esdutil.c */
SHAR_EOF
chmod 0644 esdutil.c || echo "restore of esdutil.c fails"
echo "x - extracting fcrc.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > fcrc.c &&
X/* CHK=0x5634 */
Xchar *rev="2.16";
X/*+------------------------------------------------------------------------
X fcrc.c - calculate, check &/or store CRC for file
X
X CCITT CRC-16 x^16 + x^12 + x^5 + 1
X
X Since carriage returns and line feeds present a problem between
X MS-DOS and UNIX/XENIX, these two characters are not
X included in a CRC calculation. Refer to the main procedure
X for usage information.
X
X For MSDOS versions, take note that this source does NOT work
X with MSC 3.0 because under that system rename(newfile,oldfile)
X is the rule rather than MSC 4.0 rename(oldfile,newfile). If you
X want to compile under MSC 3.0, swap rename() arguments.
X
X Compilation:
Xpyr BSD4.2 cc -O fcrc.c -o fcrc; strip fcrc
XXENIX/286 cc -O -M2 -K fcrc.c -o fcrc; strip fcrc
Xsys V cc -O -DATT fcrc.c -o fcrc; strip fcrc
XMSDOS(MSC4) msc fcrc.c; link fcrc+ssetargv/stack:2048; exepack fcrc...
X
X Defined functions:
X build_temp_names(base_fname)
X crc_clear()
X crc_finish(crc)
X filecrc(filename,crc_returned,crc_found,source_type)
X main(argc,argv,envp)
X str_index(str1,str2)
X to_upper(ch)
X trigger_type(source_type,trigger_str)
X usage()
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:06-21-1989-16:23-wht-add .68k support */
X/*:06-14-1989-17:05-wht-add .ep support */
X/*:06-13-1989-11:39-wht-add .sa as motorola asm */
X/*:05-06-1989-15:14-wht-allow .l files (same as .c) */
X/*:04-17-1989-13:41-wht-adapt to pyr 4.4 chgs need sys/types.h */
X/*:04-15-1989-13:18-wht-do not allow -u operation if access(fn,2) fails */
X/*:12-01-1988-13:23-wht-skip non-regular files */
X/*:09-08-1988-21:22-wht-allow .y files (same as .c) */
X/*:06-06-1988-20:27-wht-add -r, get rid of ulcmpb/ulindex */
X/*:05-29-1988-14:53-wht-major overhaul -- use read/write not stdio for .NEW */
X/*:05-29-1988-13:50-wht-assign version number */
X/*:05-28-1988-16:58-wht-crc_update table driven: speed up order of magnitude! */
X/*:02-21-1987-18:03-wht-use prototyping under XENIX and MSDOS */
X/*:02-04-1987-16:20-wht-fix what happened if file matched *make*.c */
X/*:01-30-1987-00:40-wht-unlink MSDOS savef before rename to it */
X/*:01-29-1987-14:10-wht-better answer for MSDOS/Intermetrics asm diffs */
X/*:12-18-1986-16:30-wht-use ':' in tempname rather than '$' */
X/*:12-05-1986-15:00-wht-bug in BSD4.2 version did not unlink(savef) */
X/*:12-04-1986-18:30-wht-make skip of 0x0D/0x0A optional */
X/*:12-04-1986-15:30-wht-fflush stdout when write performed */
X/*:11-18-1986-09:30-wht-move new program to Pyramid for BSD4.2 test */
X/*:10-18-1986-14:00-wht-make perror calls more helpful */
X/*:08-14-1986-17:30-WHT-add make source support */
X/*:08-14-1986-15:30-WHT-add assembler source support */
X/*:08-10-1986-15:20-WHT-add correct report code for no update_flag */
X/*:07-30-1986-17:00-WHT-add code for creating CRC record in file */
X/*:07-29-1986-15:30-WHT-Creation */
X
X#include <stdio.h>
X
X#define STYPE_c 0
X#define STYPE_asm 1 /* Intermetrics C68k */
X#define STYPE_make 2
X#define STYPE_bat 3
X
X#define ff fprintf
X#define se stderr
X
X#if defined(M_XENIX)
X#define SYSV 1
X#endif
X#if defined(ATT)
X#define SYSV 1
X#endif
X
X#include <sys/types.h>
X
X#if defined(M_XENIX)
X#include <fcntl.h>
X#endif
X
X#if defined(ATT)
X#include <fcntl.h>
X#endif
X
X#if MSDOS /* MSC 4.00 */
X#include <fcntl.h>
X#include <process.h>
X#include <io.h>
X#include <string.h>
X#endif
X
X#include <sys/stat.h>
X
X#ifndef MSDOS
X#define strcmpi strcmp /* only case-sensitive comparison under UNIX */
X#define strncmpi strncmp /* only case-sensitive comparison under UNIX */
X#endif
X
X#if defined(pyr) /* Pyr OSx */
X#include <sys/file.h>
X#define strchr index
X#define strrchr rindex
Xextern char *index();
Xextern char *rindex();
X#endif
X
X#if SYSV
Xextern char *strchr();
Xextern char *strrchr();
X#endif
X
X#if MSDOS | XENIX
X#if LINT_ARGS
Xchar to_upper(char );
Xint filecrc(char *,unsigned int *,char *,int );
Xint str_index(char *,char *);
Xunsigned short crc_clear(void);
Xunsigned short crc_finish(unsigned short );
Xvoid build_temp_names(char *);
Xvoid trigger_type(int ,char *);
Xvoid usage(void);
X#endif
X#endif
X
Xextern int errno;
X
Xchar rdbuf[32768-1024];
Xchar errmsg[80];
Xchar savef[128]; /* see build_temp_names */
Xchar tempf[128]; /* see build_temp_names */
Xchar trigger[32];
Xint buflen;
Xint skip_cr_nl = 1; /* if we should ignore CR and LF chars */
X
X#if MSDOS
Xint msdos = 1;
X#else
Xint msdos = 0;
X#endif
Xint msdos_switch = 0; /* -m switch */
X
X/* crc_table calculated by Mark G. Mendel, Network Systems Corporation */
Xunsigned short crc_table[256] =
X{
X 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
X 0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
X 0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
X 0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
X 0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
X 0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
X 0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
X 0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
X 0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
X 0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
X 0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
X 0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
X 0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
X 0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
X 0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
X 0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
X 0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
X 0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
X 0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
X 0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
X 0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
X 0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
X 0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
X 0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
X 0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
X 0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
X 0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
X 0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
X 0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
X 0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
X 0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
X 0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
X};
X
X/*+-------------------------------------------------------------------------
X crc_update(crc,cp)
X from article Copyright (C) 1986 Stephen Satchell.
X NOTE:
X First argument is referenced twice.
X Second argument must be in range 0 to 255.
X
X Programmers may incorporate any or all code into their programs,
X giving proper credit within the source. Publication of the
X source routines is permitted so long as proper credit is given
X to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
X Omen Technology.
X--------------------------------------------------------------------------*/
X#define crc_update(crc,data) \
X (crc_table[((crc >> 8) & 255)] ^ (crc << 8) ^ data)
X
X/*+------------------------------------------------------------------------
X crc = crc_clear();
X
X This function clears the CRC to zero. It should be called prior to
X the start of the processing of a block for both received messages,
X and messages to be transmitted.
X--------------------------------------------------------------------------*/
Xunsigned short crc_clear()
X{
X return(0);
X}
X
X/*+------------------------------------------------------------------------
X crc = crc_finish(crc);
X
X This function must be called once after all the characters in a block
X have been processed for a message which is to be TRANSMITTED. It
X returns the calculated CRC bytes, which should be transmitted as the
SHAR_EOF
echo "End of part 13"
echo "File fcrc.c is continued in part 14"
echo "14" > s2_seq_.tmp
exit 0
--
-------------------------------------------------------------------
Warren Tucker, Tridom Corporation ...!gatech!emory!tridom!wht
Ker-au'-lo-phon. An 8-foot partial flue-stop, having metal pipes
surmounted by adjustable rings, and with a hole bored near the top
of each pipe, producing a soft and "reedy" tone.
More information about the Alt.sources
mailing list