home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pDos / DDevList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  7.9 KB  |  297 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 01 Jun 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>DDevList.c<<   29 Jan 1997    13:56:25 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##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
  10.  
  11. /***********************************************************
  12.   pOS programing example - Copyright (C) 1995-97 proDAD
  13.  
  14.   This code was written as an easy to understand example,
  15.   how to program pOS features. It is provided 'as-is',
  16.   without any express or implied warranty.
  17.  
  18.   Permission is hereby granted to use, copy and modify
  19.   this source code for any purpose, without fee, subject
  20.   to the following conditions:
  21.  
  22.     (1) This notice may not be removed or altered from any
  23.         source distribution.
  24.  
  25.     (2) Altered source versions must be plainly marked as
  26.         such, and must not be misrepresented as being
  27.         the original source code.
  28.  
  29.     (3) If only executable code is distributed, then the
  30.         accompanying documentation have to state that
  31.         "this software is based in part on examples of
  32.         the pOS developer packet".
  33.  
  34.     (4) Permission for use of this code is granted only
  35.         if the user accepts full responsibility for any
  36.         undesirable consequences. proDAD accept NO LIABILITY
  37.         for damages of any kind.
  38.  
  39.   ©proDAD
  40. ***********************************************************/
  41.  
  42. /*\
  43. *** Example:
  44. *** struct pOS_RawDoFmtData
  45. *** struct pOS_MemPool
  46. *** struct pOS_MemHeader
  47. *** struct pOS_DosDevice
  48. *** struct pOS_DosMountDevice
  49. *** struct pOS_AssignNode
  50. *** struct pOS_DateTime
  51. ***
  52. *** pOS_AllocPoolMem
  53. *** pOS_RawDoFmt
  54. *** pOS_InitMemPool
  55. *** pOS_DateToStr
  56. *** pOS_NameFromObjectLock
  57. *** pOS_FreePoolAll
  58. \*/
  59.  
  60.  
  61. #define __COMPUTER_AMIGA 1
  62. #define NOMYDEBUG
  63.  
  64. #include "p:pExec/Types.h"
  65. #include "p:pExec/Memory.h"
  66. #include "p:pExec/RawDoFmt.h"
  67. #include "p:pDOS/ArgTags.h"
  68. #include "p:pDOS/DateTime.h"
  69. #include "p:pDOS/DosSig.h"
  70. #include "p:pDOS/DosErrors.h"
  71. #include "p:pDOS/DosDev.h"
  72. #include "p:pDOS/DosBase.h"
  73. #include "p:proto/pList.h"
  74. #include "p:proto/pLibExt.h"
  75. #include "p:proto/pExec2.h"
  76. #include "p:proto/pDOS2.h"
  77.  
  78. #ifdef _____ME_____
  79.   #include "grund/inc_string.h"
  80.   #include "grund/inc_stdio.h"
  81. #else
  82.  #ifdef __cplusplus
  83.  extern "C"  {
  84.  #endif
  85.   #include <string.h>
  86.   #include <stdio.h>
  87.  #ifdef __cplusplus
  88.  }
  89.  #endif
  90. #endif
  91.  
  92. extern struct pOS_ExecBase* gb_ExecBase;
  93. extern struct pOS_DosBase* gb_DosBase;
  94.  
  95.  
  96. const CHAR *HelpText=
  97. ""
  98. ;
  99.  
  100. const CHAR *PrgHeader=
  101. "Dos-Device - Lister";
  102.  
  103. const CHAR *PrgVerText=
  104. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  105.  
  106.  
  107.  
  108.  
  109. struct PrtData
  110. {
  111.   struct pOS_RawDoFmtData Fmt;
  112.   struct pOS_MemPool      MP;
  113.  
  114.   UBYTE *Adr;
  115.   ULONG Size;
  116. };
  117.  
  118.  
  119.  
  120. /*----------------------------------
  121. Bei jedem Aufruf befindet sich das zu schreibende Byte in rdft_Data.
  122. Durch den pOS_AllocPoolMem() auf die volle Segmentgröße wird verhindert,
  123. daß die Alloc-Reihenfolge zufällig sein kann.
  124. -----------------------------------*/
  125. VOID DoFmt(_R_A0 struct pOS_RawDoFmtData* fmt)
  126. {
  127.   PrtData* PD=(struct PrtData*)fmt->rdft_User[0];
  128.   if(PD->Adr==NULL) {
  129.     PD->Adr=(UBYTE*)pOS_AllocPoolMem(&PD->MP,PD->MP.mpl_SegmSize,MEMF_CLEAR);
  130.  
  131. /* ein Byte weniger, damit das Nullbyte nicht überschrieben wird */
  132.     PD->Size=PD->MP.mpl_SegmSize-1;
  133.   }
  134.   if(PD->Adr) {
  135.     *PD->Adr++=fmt->rdft_Data;
  136.     if(--PD->Size==0) PD->Adr=NULL;
  137.   }
  138. }
  139.  
  140.  
  141. /*----------------------------------
  142. -----------------------------------*/
  143. VOID XPrintf(struct PrtData* pd,const CHAR* fmt,...)
  144. {
  145.   pd->Fmt.rdft_Format=fmt;
  146.   pd->Fmt.rdft_Argv=(ULONG*) ((&fmt)+1);
  147.   pOS_RawDoFmt(&pd->Fmt);
  148. }
  149.  
  150.  
  151. /*----------------------------------
  152. Den gesamten Pufferinhalt nach pr_COS ausgeben.
  153. Damit ein zweiter Aufruf keine alten Daten ausgibt, wird jeder
  154. bearbeitete Puffer sofort gelöscht.
  155. Der oberste Node wird aus der Liste entfernt, ausgegeben und über die
  156. mpl_Free-Funktion freigegeben.
  157. -----------------------------------*/
  158. VOID XFlush(struct PrtData* pd)
  159. {
  160.   pOS_MemHeader *MH;
  161.  
  162.   while(MH=(struct pOS_MemHeader*)pOS_ListRemHead((struct pOS_List*)&pd->MP.mpl_List)) {
  163.     printf((CHAR*)MH->mh_Lower);
  164.     pd->MP.mpl_Free((pOS_ExecBase*)gb_ExecBase,&pd->MP,MH);
  165.   }
  166. }
  167.  
  168.  
  169. /*----------------------------------
  170. -----------------------------------*/
  171. #ifdef __cplusplus
  172. extern "C"
  173. #endif
  174. VOID main()
  175. {
  176.   struct pOS_DosArgs* Args;
  177.   UWORD Err=0;
  178.   ULONG Ops[1]={0};
  179.  
  180.   Args=pOS_ReadDosArgs("",Ops,sizeof(Ops)/sizeof(ULONG),
  181.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  182.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  183.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  184.     TAG_END);
  185.  
  186.   if(Args) {
  187.     struct PrtData Data;
  188.     struct pOS_DosDevice *DD;
  189.     static const CHAR *NameType[]=
  190.     {
  191.       "-",
  192.      "DDTYP_Handler",
  193.      "DDTYP_Assign",
  194.      "DDTYP_Volume",
  195.      "DDTYP_LateAssign",
  196.      "DDTYP_NonBindingAssign",
  197.      "DDTYP_Foreign"
  198.     };
  199.  
  200.     static const CHAR *NameMountType[]=
  201.     {
  202.       "-",
  203.       "DMDTYP_Pico",
  204.       "DMDTYP_BOD",
  205.       "DMDTYP_Net"
  206.     };
  207.  
  208.  
  209. /*\
  210. *** Pool auf eine Segemtgröße von 1024 Bytes initialisieren.
  211. \*/
  212.     pOS_InitMemPool(&Data.MP,1024,MEMF_PUBLIC);
  213.     Data.Fmt.rdft_InterFmt=NULL;  /* Standard-Funktion verwenden */
  214.     Data.Fmt.rdft_DoFmt=DoFmt;    /* unsere Funktion */
  215.     Data.Fmt.rdft_User[0]=(ULONG)&Data;  /* unsere privaten Daten */
  216.     Data.Adr=NULL;                /* Grundzustand */
  217.  
  218.     pOS_LockDosDevList(); /* Dos-Device-Liste locken */
  219.  
  220.     for(DD=(struct pOS_DosDevice*)gb_DosBase->dos_Device.lh_Head;
  221.         DD->ddv_Dev.lib_Node.ln_Succ;
  222.         DD=(struct pOS_DosDevice*)DD->ddv_Dev.lib_Node.ln_Succ) {
  223.  
  224.       XPrintf(&Data,"\n\033[1m %s: \033[0m  [%s]\n",DD->ddv_Dev.lib_Node.ln_Name,
  225.               NameType[DD->ddv_Type]);
  226.       switch(DD->ddv_Type) {
  227.  
  228.         case DDTYP_Handler:
  229.           {
  230.             const struct pOS_DosMountDevice *MD=DD->ddv_U.ddv_Handler.ddvh_Mount;
  231.             XPrintf(&Data,
  232.               "   Mount-Type  = %s\n"
  233.               "   Mount-Flags = 0x%4lx (enum pOS_DosMountDevFlags)\n",
  234.               NameMountType[MD->dmd_Type],MD->dmd_Flags);
  235.           }
  236.           break;
  237.  
  238.         case DDTYP_Volume:
  239.           {
  240.             const struct pOS_DosDevice *HD=DD->ddv_U.ddv_Volume.ddvv_Handler;
  241.             pOS_DateTime DT;
  242.             CHAR DateStr[pOS_DATETIMESTR_MAX];
  243.             CHAR TimeStr[pOS_DATETIMESTR_MAX];
  244.             CHAR DayStr[pOS_DATETIMESTR_MAX];
  245.  
  246.             XPrintf(&Data,
  247.               "   Vol-Handler = '%s:'\n",
  248.               HD->ddv_Dev.lib_Node.ln_Name);
  249.  
  250.             DT.dat_Format =DATETFRM_LOCAL;
  251.             DT.dat_Flags  =0;
  252.             DT.dat_StrDay =NULL;
  253.             DT.dat_StrDate=DateStr;
  254.             DT.dat_StrTime=TimeStr;
  255.             DT.dat_StrDay =DayStr;
  256.             DT.dat_Stamp  =DD->ddv_U.ddv_Volume.ddvv_Date;
  257.             pOS_DateToStr(&DT);
  258.             XPrintf(&Data,"   Vol-Date: %s %s %s\n",DayStr,DateStr,TimeStr);
  259.           }
  260.           break;
  261.  
  262.         case DDTYP_Assign:
  263.           {
  264.             CHAR Buffer[pOS_DosPathName_MAX];
  265.             struct pOS_AssignNode *AN;
  266.             pOS_NameFromObjectLock(DD->ddv_U.ddv_Assign.ddva_Lock,Buffer,sizeof(Buffer));
  267.             XPrintf(&Data,"   Assign-Path %s\n",Buffer);
  268.             for(AN=(struct pOS_AssignNode*)DD->ddv_Lst.lh_Head;
  269.                 AN->an_Node.ln_Succ;
  270.                 AN=(struct pOS_AssignNode*)AN->an_Node.ln_Succ)
  271.             {
  272.               pOS_NameFromObjectLock(AN->an_Lock,Buffer,sizeof(Buffer));
  273.               XPrintf(&Data,"         +Path %s\n",Buffer);
  274.             }
  275.           }
  276.           break;
  277.  
  278.         case DDTYP_LateAssign:
  279.         case DDTYP_NonBindingAssign:
  280.           XPrintf(&Data,"   Assign-Path %s\n",DD->ddv_U.ddv_Assign.ddva_Name);
  281.           break;
  282.       }
  283.  
  284.     }
  285.     pOS_UnlockDosDevList();
  286.  
  287.     XFlush(&Data); /* alle Daten ausgeben */
  288.  
  289.     pOS_FreePoolAll(&Data.MP);
  290.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  291.   }
  292.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  293.   pOS_SetShellFail(Err);
  294. }
  295.  
  296.  
  297.