delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/07/28/08:43:05

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Date: Fri, 28 Jul 1995 11:41:19 BST
Subject: Reading a directory as if it was a file; calling interrupts

  A.Appleyard wrote:-
> Is there any way in (interrupts usable under Gnu C) to read a directory as
> if it was a file? I want to write my own program to explore directories. ...

  mat AT ardi DOT com (Mat Hostetter) replied:-
> Can't you use the `struct dirent' stuff in dirent.h?  Or are you trying to
> do something strange? -Mat

  (1) I <do> know the usual interrupts to read a directory one entry at a time
(as in the program below). I was just wondering if <also> there was a way to
read a directory all at once.

  (2) If I call a djgpp program `main(int N,char*Arg[])', where in the run
time store are the body of array Arg, and the strings that its elements point
to? How safe it it to leave the args there instead of copying them into the
program's local space as soon as possible?

  (3) I wrote a program to print a directory and its subdirectories. If in it
I use my often-criticized home-grown method of calling interrupts, it works OK
every time. But if I use the djgpp recommended interrupt calling method,
(trying to access a directory e.g. `D:*.*' with no `\' after the  drive code)
causes an `Unsupported INT 0x0d' in `GetFirst()' (for which see below).

variorum listfile on Fri Jul 28 11:12:37 1995 of these files:-
file 1 = dir.cc, 9313 chars, 182 lines  /* calling interrupts my way */
file 2 = dir2.cc, 9098 chars, 177 lines /* calling interrupts the usual way */
F1 F2 /* Line numbers. For brevity I have omitted irrelevant lines */
 1  1 #include<stdio.h>
  ...
15    /*-----*//* interrupts */
16    long _ax,_bx,_cx,_dx,_si,_di,_bp,_es; short _flags;
17    #define _carry (_flags&1)
18    #define _zeroflag (_flags&0x40)
19    #define __SR() /* save the registers */         ({asm("xchgl %eax,__ax"); \
20        asm("xchgl %ebx,__bx"); asm("xchgl %ecx,__cx"); asm("xchgl %edx,__dx"); \
21        asm("xchgl %esi,__si"); asm("xchgl %edi,__di"); asm("xchgl %ebp,__bp"); })
22    #define __RR() /* restore the registers */      ({ \
23        asm("pushf"); asm("popw __flags"); __SR();})
24    void int16() {__SR(); asm("int $0x16"); __RR();}
25    void int21() {__SR(); asm("int $0x21"); __RR();}
26    /*-----*/
  ...
40 28 class direntry{public:direntry*b,*e;
41 29   byte Reservebuf[13],Attribute __attribute__((packed));
42 30   FCBtime time; FCBdate date; uns long size; char name[13];
43 31   /* first 3 fields must add up to 21 bytes long */
  ...
   41 void segread(struct SREGS*s){} /* dummy in Gnu C */
   42 union REGS Reg;
  ...
70 60 /*----- read a key */
71    byte getch(){_ax=0; int16(); return _ax&255;}
   61 byte getch(){Reg.h.ah=0; int86(0x16,&Reg,&Reg); return(Reg.h.al);}
72 62 /*----- current disk drive */
73    byte drive(){_ax=0x1900; int21(); return (_ax&255)+'A';}
   63 byte drive(){Reg.h.ah=0x19; int86(0x21,&Reg,&Reg); return(Reg.h.al+'A');}
74 64 /*----- read next directory entry */
75    byte GetNext(){_ax=0x4F00; int21(); return !_carry;}
   65 byte GetNext(){Reg.h.ah=0x4F; intdos(&Reg,&Reg); /* Call DOS-Intr. 21(h) */
   66 return(!Reg.x.cflag); /* 1 if file found, else 0 */}
76 67 /*----- read first directory entry into DTA */
77 68 byte GetFirst(char*filename, uns int Attribute){
78 69 /****/printf("GetFirst(\"%s\",%1d);\n",filename,Attribute);
79    _ax=0x4E00; _cx=Attribute; _dx=(uns int)filename; int21(); return !_carry;}
   70 struct SREGS Segmente; segread(&Segmente);
   71 Reg.h.ah=0x4E; Reg.x.cx=Attribute; Reg.x.dx=(uns int)filename;
   72 intdosx(&Reg,&Reg,&Segmente);
   73 return(!Reg.x.cflag); /* 1 if file found, else 0 */}
80 74 /*----- SETDTA: sets the DTA to a user variable */
81    void direntry::setDTA(){_ax=0x1A00; _dx=(uns int)this; int21();}
   75 void direntry::setDTA(){struct SREGS Segment; segread(&Segment);
   76 Reg.h.ah=0x1A; Reg.x.dx=(uns int)this; intdosx(&Reg,&Reg,&Segment);}
  ...

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019