int getinfo(char *s, char *d) { int sdir, ddir; int ret; srclen = strlen(s) + 5; /* 1 byte for null and 4 byte for \*.* */ dstlen = strlen(d) + 17; /* 1 for null, 4 for \*.* and 13 for folder */ srcbuf = 500; /* initialize the buffer */ dstbuf = 500; while (srclen > srcbuf) srcbuf *= 2; while (dstlen > dstbuf) dstbuf *= 2; fixsrc = (char *)malloc( (long)srcbuf ); fixdst = (char *)malloc( (long)dstbuf ); sdir = mystrcp(s, fixsrc); if ( opcode == OP_DELETE ) /* do directories or files rm */ return( (sdir)? DTOD:OK ); else /* do directories or files cp or mv */ { getlastpath(filestr,fixsrc); if (((ddir = mystrcp(d, fixdst))) && (sdir)) { /* dir to dir */ if (*filestr) { /* folder cp */ chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ addfile(fixdst, filestr); /* add the folder to dst */ ret = created( filestr ); /* create the 1st folder */ if ( ( !ret ) || ( ret == SKIP ) ) { free( fixsrc ); free( fixdst ); return( ret ); } strcat(bckslsh, fixdst); } return (DTOD); } if (ddir) { /* one file to dir */ chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ strcat(filestr, fixdst); } return OK; } }
/************************************************************************ ** get_definition : accumulate the macro definition, stops when it finds ** a newline (it uses it). returns a ptr to the end of the string it builds. ** builds the string in Macro_buffer. (given the start in P_defn_start) ************************************************************************/ int get_definition(void) { REG ptext_t p; UCHAR c; int stringize = FALSE; int charize = FALSE; p = P_defn_start; c = skip_cwhite(); for(;;) { chkbuf(p); switch(CHARMAP(c)) { case LX_EOS: if(handle_eos() == BACKSLASH_EOS) { /* got backslash EOS */ /* \<anything else> goes out as is. The <anything else> * character must be emitted now, so that * #define FOO(name) \name * . . . * FOO(bar) * * does NOT see occurence of name in the definition as an * occurence of the formal param and emit \bar when it is * expanded later,but if the definition is \nname it will * find name as a formal paramater and emit \nbar */ *p++ = c; /* put in backslash, break'll add new char */ c = get_non_eof(); } else { c = GETCH(); continue; } break; case LX_NL: /* only way out */ UNGETCH(); if(p == P_defn_start) { return(0); } chkbuf(p); *p++ = EOS_CHAR; *p++ = EOS_DEFINITION; /* tells handle_eos defn finished */ return(p - P_defn_start);/* p's last incr counts the 0*/ break; case LX_DQUOTE: case LX_SQUOTE: p = gather_chars(p, c); c = GETCH(); continue; break; case LX_POUND: split_op: switch(CHARMAP(GETCH())) { case LX_POUND: /* ** handle ## processing. cant be the first or the last. */ if(p == P_defn_start) { Msg_Temp = GET_MSG (2160); SET_MSG (Msg_Text, Msg_Temp); error(2160); /* ## not allowed as first entry */ continue; } if(*(p - 1) == ' ') { /* hose the last blank */ p--; } if(CHARMAP(c = skip_cwhite()) == LX_NL) { UNGETCH(); Msg_Temp = GET_MSG (2161); SET_MSG (Msg_Text, Msg_Temp); error(2161); continue; } /* this case does *not* fall through to LX_ID */ continue; break; case LX_EACH: charize = TRUE; break; case LX_EOS: if( handle_eos() != BACKSLASH_EOS ) { goto split_op; } /* ** FALLTHROUGH */ default: UNGETCH(); stringize = TRUE; break; } if(CHARMAP(c = skip_cwhite()) != LX_ID) { Msg_Temp = GET_MSG (2162); SET_MSG (Msg_Text, Msg_Temp); error(2162); /* must have id following */ continue; } /* ** FALLTHROUGH */ case LX_ID: { /* we have the start of an identifier - check it to see if * its an occurence of a formal parameter name. * we gather the id ourselves (instead of getid()) since this * wil save us from having to copy it to our string if it's * not a formal parameter. */ int n; ptext_t p_macformal; p_macformal = p; do { chkbuf(p); *p++ = c; get_more_id: c = GETCH(); } while(LXC_IS_IDENT(c)); if(CHARMAP(c) == LX_EOS) { if(handle_eos() != BACKSLASH_EOS) { goto get_more_id; } } *p = '\0'; /* term. string, but do not advance ptr */ if((n = is_macro_arg(p_macformal)) >= 1) { /* ** this is an occurance of formal 'n', replace the id with ** the special MAC character. */ p = p_macformal; if(stringize) { *p++ = LX_FORMALSTR; } else { if(charize) { *p++ = LX_FORMALCHAR; } else { *p++ = LX_FORMALMARK; } } *p++ = (UCHAR) n; } else if(charize || stringize) { Msg_Temp = GET_MSG (2162); SET_MSG (Msg_Text, Msg_Temp); error(2162); } stringize = FALSE; charize = FALSE; continue; /* we broke out of the loop with a new char */ } case LX_SLASH: if( ! skip_comment() ) { /* really is a slash */ break; } /* ** FALLTHROUGH */ case LX_CR: case LX_WHITE: /* ** this is white space, all contiguous whitespace is transformed ** to 1 blank. (hence the skip_cwhite() and the continue). */ if(CHARMAP(c = skip_cwhite()) != LX_NL) { *p++ = ' '; } continue; /* restart loop */ case LX_ILL: Msg_Temp = GET_MSG (2018); SET_MSG (Msg_Text, Msg_Temp, c); error(2018); c = GETCH(); continue; } *p++ = c; c = GETCH(); } }
int doact( VOID ) { /* char *saved; */ DMABUFFER *dumb, * saved; REG int ret, retmsg; int error; if ( f_level >= ( COPYMAXDEPTH + 1 ) ) { act_1: do1_alert( STFO8DEE ); return( FALSE ); } /* changed CHAR * to DMABUFFER * in expression below - JTT */ if ( !( dumb = (DMABUFFER *)malloc( (LONG)sizeof( DMABUFFER ) ) ) ) goto act_1; f_level++; retmsg = TRUE; saved = (DMABUFFER *)Fgetdta(); Fsetdta( dumb ); strcat(getall, fixsrc); if ( !( error = Fsfirst(fixsrc, 0x37) ) ) { do { if ( !ch_undo( ) || f_cancel ) /* user want to abort */ { f_abort = 1; retmsg = FALSE; goto mvend; } if (dumb->d_fname[0] != HOME) { if (SUBDIR & dumb->d_fattr) { chkbuf(srclen, srcbuf, &fixsrc); /* check buf size */ addfile(fixsrc, dumb->d_fname); /* add a dir into the path */ strcat(bckslsh, fixsrc); if (opcode != OP_DELETE) { chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ strcat(dumb->d_fname, fixdst); } else goto dorec; updatbox(dumb->d_fname); rechkd1: /* update check the dir existing or not */ switch( chkdf( dumb->d_fname, CPDIR ) ) { case QUIT: f_abort = 1; retmsg = FALSE; goto mvend; case SKIP: backdir(fixsrc); backdir(fixdst); updatnum(NUMDIR, --numdirs); srclen -= FILE_LEN; /* subtract the add lenth */ dstlen -= FILE_LEN; /* subtract the add lenth */ retmsg = TRUE; continue; case FALSE: goto mvend; case CHECK: goto rechkd1; case OK: recrtd: if (Dcreate(fixdst)) { if ( write_save ) goto kk_1; switch( fill_string( fixdst, CNTCRTDR ) ) { case 1: /* skip */ backdir(fixsrc); backdir(fixdst); updatnum(NUMDIR, --numdirs); srclen -= FILE_LEN; /* subtract the add lenth */ dstlen -= FILE_LEN; /* subtract the add lenth */ continue; case 2: /* retry */ goto recrtd; default: /* quit */ f_abort = 1; retmsg = FALSE; goto mvend; }/* switch */ }/* if recrtd */ break; } kk_1: updatnum(NUMDIR, --numdirs); strcat(bckslsh, fixdst); dorec: if (!doact()) /* do the recursion */ { retmsg = FALSE; goto mvend; } if (opcode == OP_COPY) goto clndir; rmstarb(fixsrc); /* after call, -> c:\d1\ */ if (opcode == OP_DELETE) { getlastpath(filestr, fixsrc); updatbox(filestr); } remvd: if (Ddelete(fixsrc)) { /* delete a dir */ if ( ( ret = fill_string( fixsrc, CNTDELD ) ) == 2 ) goto remvd; /* retry */ else if (ret == 3) { /* abort */ f_abort = 1; retmsg = FALSE; goto mvend; } } else /* No error */ upfdesk( fixsrc, (BYTE*)0 ); clndir: backdir(fixsrc); /* back one dir */ srclen -= FILE_LEN; /* subtract the add lenth */ if (opcode == OP_DELETE) updatnum(NUMDIR, --numdirs); else { backdir(fixdst); /* back one dir */ dstlen -= FILE_LEN; /* subtract the add lenth */ } } else { getlastpath(filestr, fixdst); updatname(CPDIR, filestr); /* update the dir */ updatname( CPFILE, dumb->d_fname ); /* update the file */ chkbuf(srclen, srcbuf, &fixsrc); /* check buf size */ addfile(fixsrc, dumb->d_fname); if (opcode != OP_DELETE) { chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ addfile(fixdst, dumb->d_fname); rename = 0; if (!(retmsg = wrfile(dumb->d_fname))) goto mvend; if ((rename) || (retmsg == SKIP)) goto clnfile; } if (opcode == OP_COPY) goto clnfile; remvf: if (ret = (WORD)(Fdelete(fixsrc))) /* rm the file from source */ { /* seek error or drive not ready */ /* if ((ret == E_SEEK) || (ret == EDRVNR)) { retmsg = FALSE; goto mvend; } */ /* retry */ if ( ( ret = fill_string( fixsrc, CNTDELF ) ) == 2 ) goto remvf; else if ( ret == 3 ) { /* abort */ f_abort = 1; retmsg = FALSE; goto mvend; } } else upfdesk( fixsrc, (BYTE*)0 ); clnfile: backdir(fixsrc); /* back one dir */ srclen -= FILE_LEN; /* subtract the add lenth */ if (opcode == OP_DELETE) updatnum(NUMFILE, --numfiles); else { backdir(fixdst); /* back one dir */ dstlen -= FILE_LEN; /* subtract the add lenth */ } } } } while (!Fsnext()); } else { if ( error != EFILNF ) /* if not file not found */ retmsg = FALSE; /* then return error */ } mvend: Fsetdta( saved ); f_level--; free( dumb ); return( retmsg ); }
int main (int ac, char *av[]) { char iobuf[BLKSIZE]; struct wrap_ccb _wccb, *wccb = &_wccb; int fd, i, rc; NDMOS_MACRO_ZEROFILL (wccb); wccb->iobuf = iobuf; wccb->n_iobuf = sizeof iobuf; fd = creat ("wt1.data", 0666); if (fd < 0) { perror ("create wt1.data"); return 1; } for (i = 0; i < NBLOCK; i++) { fillbuf (iobuf, sizeof iobuf, i); write (fd, iobuf, sizeof iobuf); } fillbuf (iobuf, sizeof iobuf, 0xFFF); close (fd); fd = open ("wt1.data", 0666); if (fd < 0) { perror ("re-open wt1.data"); return 2; } wccb->data_conn_fd = fd; for (i = 0; i < NBLOCK; i++) { /* get the first 100 of each block */ rc = wrap_reco_seek (wccb, i*sizeof iobuf, 256, 100); if (rc) { printf ("err=%d '%s'\n", rc, wccb->errmsg); break; } /* then get 512 */ rc = wrap_reco_must_have (wccb, 512); if (rc) { printf ("err=%d '%s'\n", rc, wccb->errmsg); break; } /* then get 512 more */ rc = wrap_reco_must_have (wccb, 1024); if (rc) { printf ("err=%d '%s'\n", rc, wccb->errmsg); break; } if (chkbuf (wccb->have, 1024, i) != 0) { printf ("BOING %d\n", i); } } close (fd); remove ("wt1.data"); return 0; }