APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

IBCOPY.C Tony Lawrence:

We no longer offer ftp downloads. If there is a file you need referenced here, please contact me by email and I will get it to you.


/* Copyright 1994 Anthony Lawrence

Archives files to a date, sequence  number format.

For example, IBCOPY DT *.DAT produces (assuming today is 12/31/94)

941231DT.001
941231DT.002
941231DT.003  and so on.  You can add a directory argument also:

IBCOPY MF *.GIF \MYSTUFF produces

\MYSTUFF\941231MF.001
\MYSTUFF\941231MF.002

Note that this is not written to support more than 999 files
being copied with the same tag and directory.  You could
easily modify this to use .aaa, etc. if you want.

*/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <direct.h>
#include <dos.h>
#include <time.h>

#define Dir_Mask        16
#define Any_Mask        22
#define Showit          1
#define DontShow        0
#define WIDTH           78
struct dta {
char dos_reserved[21];
char flag;
short time;
short date;
long size;
char name[13];
} ;
struct  dta *pd;

void    s_print(struct dta *this);
int     compare(char *this,char *that);
int     makename(char *t,char *u);
int     Wild_control=0;
char S_wild[10][128];
int     savewild(),getwild();
char    *basename(char *string);
char    *qualify(char *p);

char Fname_buf[128];
char CommandBuf[128];
char *Cbuf=CommandBuf;
char Safe[128];
char *Wild=Fname_buf;
int Counter=1;
char *Newname="941006ED.001";
char Dirbuf[128];
char *Archdir=Dirbuf;
char Archbuf[128];
char *Archname=Archbuf;
char *Ext="ED";

main(argc,argv)
int argc;
char **argv;

{
int x;

if (argc < 3)
{
printf("Usage %s TYpe Wildcard [Directory]\n",basename(argv[0]));
printf("Renames as YYMMDDTY.001, etc.)\n");
printf("Example: %s QS BOB.*\n",basename(argv[0]));
printf("produces 941017QS.001, 941017QS.002, etc\n");
printf("Example: %s DQ BOB.*\n",basename(argv[0]));
printf("produces 941017DQ.001, 941017DQ.002, etc\n");
exit(0);
}
strncpy(Ext,argv[1],2);
strcpy(Archdir,".");
strcpy(Wild,argv[2]);
if (argc > 3) strcpy(Archdir,argv[3]);
Wild=qualify(Wild);          /* get args & flags */

do_dir(Any_Mask,Showit);                /* gather data */

}

do_dir(int val,int show)
{
pd=(struct dta *) malloc(sizeof(struct dta));

_asm {
        pusha
        call    setdta
        mov     ah,0x4e
        mov     dx,Wild
        mov     cx,val
        int     0x21
        jb      no_more
d_loop: mov     si,pd
        mov     ax,[si+30]
        cmp     al,'.'
        jz      jfnext
        cmp     show,1
        jz      doshow
        mov     si,pd
        mov     ax,[si+21]
        and     ax,Dir_Mask
        jz      noshow
        add     si,30
        push    si
        mov     ax,Wild
        push    ax
        call    savewild
        call    makename
        pop     ax
        pop     ax
        push    0
        push    Any_Mask
        push    pd
        call    do_dir
        pop     pd
        pop     ax
        pop     ax
        call    setdta
        call    getwild
        jmp     noshow
no_more:jmp     outahere
jfnext: jmp     fnext
doshow: push    pd
        call    showit
        pop     pd
        call    setdta
        jmp     fnext
noshow: mov     si,pd
fnext:  mov     ah,0x4f
        int     0x21
        jb      no_more
        jmp     d_loop
setdta: mov     dx,pd
        mov     ah,0x1a
        int     0x21
        ret
showit: push    pd
        call    s_print
        pop     pd
        ret
outahere:
        popa

     }
}


savewild()
{
if (Wild_control > 9) Wild_control=9;
strcpy(S_wild[Wild_control++],Wild);
}
getwild()
{
strcpy(Wild,S_wild[--Wild_control]);
}
makename(char *string,char *name)
{

char *tt;

tt=strstr(string,"*.*");
if (tt)
 sprintf(tt,"%s\\*.*",name);
}

compare(char *this, char *that)
{
int first=0,second=0;
if (*this == '*' || strchr(this,'\\'))
    first=1;
if (*that == '*' || strchr(that,'\\'))
    second=1;

if (first && !second)
        return(-1);
if (second && !first)
        return(1);

return(strcmp(this,that));

}



char *basename(char *string)
{

_asm  {
      push      si
      push      di
      cld
      mov        si,string
      mov        di,si
f1:   lodsb
      cmp       al, '\\'
      jnz       f2
      mov       di,si
f2:   or         al,al
      jnz        f1
      cld
      mov       string,di
      pop       di
      pop       si
      }

return(string);
}

char *qualify(char *p)
{
unsigned drive=0,drivenow=0,junk=0;
char *dirnow,*drivedir;
int ok=0;

_dos_getdrive(&drivenow);
dirnow=getcwd(NULL,64);

if (*(p+1) == ':')
  drive=(toupper(*p)-64);
else
  drive=drivenow;


if (*p == 0)
  return(strlwr("*.*"));
if (strcmp(p+1,":")==0)
   {
   strcat(p,"*.*");
   return(p);
   }

_dos_setdrive(drive,&junk);
drivedir=getcwd(NULL,64);
ok=chdir(p);

chdir(drivedir);

_dos_setdrive(drivenow,&junk);
chdir(dirnow);
if (!ok)
{
if (strcmp(strrchr(p,'\\'),"\\") !=0)
    {
    strcat(p,"\\*.*");
    }
else
    {
    strcat(p,"*.*");
    }
}
else
  {
  if (!strstr(p,".*") && strstr(p,"*") && !strstr(p,"*."))
     strcat(p,".*");

  }

return(p);


}


void s_print(struct dta *dtp)
{
struct tm *tptr;
time_t now;

if (dtp->flag & Dir_Mask)
   return;
time(&now);
tptr=localtime(&now);

sprintf(Newname,"%.2d%.2d%.2d%s\.001",tptr->tm_year,tptr->tm_mon+1,tptr->tm_mday,Ext);
sprintf(Archname, "%s\\%s",Archdir,Newname);
while (access(Archname,0) == 0)
{
Counter++;
sprintf(Newname,"%.2d%.2d%.2d%s\.%.3d",tptr->tm_year,tptr->tm_mon+1,tptr->tm_mday,Ext,Counter);
sprintf(Archname, "%s\\%s",Archdir,Newname);
}
sprintf(Cbuf,"COPY %s %s",dtp->name,Archname);
system(Cbuf);

}
 

Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Dos Programs - archiver ibcopy




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





As an experimental psychologist, I have been trained not to believe anything unless it can be demonstrated in the laboratory on rats or sophomores. (Steven Pinker)

Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. ((Edsger W. Dijkstra)












This post tagged: