home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 01 Jun 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>DDevList.c<< 29 Jan 1997 13:56:25 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/Ex/DDevList p:pLib/StartCode.o p:/pOS_RKRM/pDos/DDevList.c p:pLib/StdIO.o -l pOSStub -l pOS -l CPPList
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
- /*\
- *** Example:
- *** struct pOS_RawDoFmtData
- *** struct pOS_MemPool
- *** struct pOS_MemHeader
- *** struct pOS_DosDevice
- *** struct pOS_DosMountDevice
- *** struct pOS_AssignNode
- *** struct pOS_DateTime
- ***
- *** pOS_AllocPoolMem
- *** pOS_RawDoFmt
- *** pOS_InitMemPool
- *** pOS_DateToStr
- *** pOS_NameFromObjectLock
- *** pOS_FreePoolAll
- \*/
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:pExec/Memory.h"
- #include "p:pExec/RawDoFmt.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DateTime.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:pDOS/DosDev.h"
- #include "p:pDOS/DosBase.h"
- #include "p:proto/pList.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_stdio.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
- extern struct pOS_ExecBase* gb_ExecBase;
- extern struct pOS_DosBase* gb_DosBase;
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "Dos-Device - Lister";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
-
-
-
-
- struct PrtData
- {
- struct pOS_RawDoFmtData Fmt;
- struct pOS_MemPool MP;
-
- UBYTE *Adr;
- ULONG Size;
- };
-
-
-
- /*----------------------------------
- Bei jedem Aufruf befindet sich das zu schreibende Byte in rdft_Data.
- Durch den pOS_AllocPoolMem() auf die volle Segmentgröße wird verhindert,
- daß die Alloc-Reihenfolge zufällig sein kann.
- -----------------------------------*/
- VOID DoFmt(_R_A0 struct pOS_RawDoFmtData* fmt)
- {
- PrtData* PD=(struct PrtData*)fmt->rdft_User[0];
- if(PD->Adr==NULL) {
- PD->Adr=(UBYTE*)pOS_AllocPoolMem(&PD->MP,PD->MP.mpl_SegmSize,MEMF_CLEAR);
-
- /* ein Byte weniger, damit das Nullbyte nicht überschrieben wird */
- PD->Size=PD->MP.mpl_SegmSize-1;
- }
- if(PD->Adr) {
- *PD->Adr++=fmt->rdft_Data;
- if(--PD->Size==0) PD->Adr=NULL;
- }
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID XPrintf(struct PrtData* pd,const CHAR* fmt,...)
- {
- pd->Fmt.rdft_Format=fmt;
- pd->Fmt.rdft_Argv=(ULONG*) ((&fmt)+1);
- pOS_RawDoFmt(&pd->Fmt);
- }
-
-
- /*----------------------------------
- Den gesamten Pufferinhalt nach pr_COS ausgeben.
- Damit ein zweiter Aufruf keine alten Daten ausgibt, wird jeder
- bearbeitete Puffer sofort gelöscht.
- Der oberste Node wird aus der Liste entfernt, ausgegeben und über die
- mpl_Free-Funktion freigegeben.
- -----------------------------------*/
- VOID XFlush(struct PrtData* pd)
- {
- pOS_MemHeader *MH;
-
- while(MH=(struct pOS_MemHeader*)pOS_ListRemHead((struct pOS_List*)&pd->MP.mpl_List)) {
- printf((CHAR*)MH->mh_Lower);
- pd->MP.mpl_Free((pOS_ExecBase*)gb_ExecBase,&pd->MP,MH);
- }
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Ops[1]={0};
-
- Args=pOS_ReadDosArgs("",Ops,sizeof(Ops)/sizeof(ULONG),
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- TAG_END);
-
- if(Args) {
- struct PrtData Data;
- struct pOS_DosDevice *DD;
- static const CHAR *NameType[]=
- {
- "-",
- "DDTYP_Handler",
- "DDTYP_Assign",
- "DDTYP_Volume",
- "DDTYP_LateAssign",
- "DDTYP_NonBindingAssign",
- "DDTYP_Foreign"
- };
-
- static const CHAR *NameMountType[]=
- {
- "-",
- "DMDTYP_Pico",
- "DMDTYP_BOD",
- "DMDTYP_Net"
- };
-
-
- /*\
- *** Pool auf eine Segemtgröße von 1024 Bytes initialisieren.
- \*/
- pOS_InitMemPool(&Data.MP,1024,MEMF_PUBLIC);
- Data.Fmt.rdft_InterFmt=NULL; /* Standard-Funktion verwenden */
- Data.Fmt.rdft_DoFmt=DoFmt; /* unsere Funktion */
- Data.Fmt.rdft_User[0]=(ULONG)&Data; /* unsere privaten Daten */
- Data.Adr=NULL; /* Grundzustand */
-
- pOS_LockDosDevList(); /* Dos-Device-Liste locken */
-
- for(DD=(struct pOS_DosDevice*)gb_DosBase->dos_Device.lh_Head;
- DD->ddv_Dev.lib_Node.ln_Succ;
- DD=(struct pOS_DosDevice*)DD->ddv_Dev.lib_Node.ln_Succ) {
-
- XPrintf(&Data,"\n\033[1m %s: \033[0m [%s]\n",DD->ddv_Dev.lib_Node.ln_Name,
- NameType[DD->ddv_Type]);
- switch(DD->ddv_Type) {
-
- case DDTYP_Handler:
- {
- const struct pOS_DosMountDevice *MD=DD->ddv_U.ddv_Handler.ddvh_Mount;
- XPrintf(&Data,
- " Mount-Type = %s\n"
- " Mount-Flags = 0x%4lx (enum pOS_DosMountDevFlags)\n",
- NameMountType[MD->dmd_Type],MD->dmd_Flags);
- }
- break;
-
- case DDTYP_Volume:
- {
- const struct pOS_DosDevice *HD=DD->ddv_U.ddv_Volume.ddvv_Handler;
- pOS_DateTime DT;
- CHAR DateStr[pOS_DATETIMESTR_MAX];
- CHAR TimeStr[pOS_DATETIMESTR_MAX];
- CHAR DayStr[pOS_DATETIMESTR_MAX];
-
- XPrintf(&Data,
- " Vol-Handler = '%s:'\n",
- HD->ddv_Dev.lib_Node.ln_Name);
-
- DT.dat_Format =DATETFRM_LOCAL;
- DT.dat_Flags =0;
- DT.dat_StrDay =NULL;
- DT.dat_StrDate=DateStr;
- DT.dat_StrTime=TimeStr;
- DT.dat_StrDay =DayStr;
- DT.dat_Stamp =DD->ddv_U.ddv_Volume.ddvv_Date;
- pOS_DateToStr(&DT);
- XPrintf(&Data," Vol-Date: %s %s %s\n",DayStr,DateStr,TimeStr);
- }
- break;
-
- case DDTYP_Assign:
- {
- CHAR Buffer[pOS_DosPathName_MAX];
- struct pOS_AssignNode *AN;
- pOS_NameFromObjectLock(DD->ddv_U.ddv_Assign.ddva_Lock,Buffer,sizeof(Buffer));
- XPrintf(&Data," Assign-Path %s\n",Buffer);
- for(AN=(struct pOS_AssignNode*)DD->ddv_Lst.lh_Head;
- AN->an_Node.ln_Succ;
- AN=(struct pOS_AssignNode*)AN->an_Node.ln_Succ)
- {
- pOS_NameFromObjectLock(AN->an_Lock,Buffer,sizeof(Buffer));
- XPrintf(&Data," +Path %s\n",Buffer);
- }
- }
- break;
-
- case DDTYP_LateAssign:
- case DDTYP_NonBindingAssign:
- XPrintf(&Data," Assign-Path %s\n",DD->ddv_U.ddv_Assign.ddva_Name);
- break;
- }
-
- }
- pOS_UnlockDosDevList();
-
- XFlush(&Data); /* alle Daten ausgeben */
-
- pOS_FreePoolAll(&Data.MP);
- pOS_DeleteDosArgs(Args); /* Args freigeben */
- }
- else Err=DOSFAIL_FAIL; /* vollkommen fehlgeschlagen */
- pOS_SetShellFail(Err);
- }
-
-
-