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

  1. ; /** execute p:/pOS/pLib/pLibExt.c
  2. cc:c/storm/StormC_2_0_8 -o ram:pOS1.o -d _M1_ -c p:pLib/pLibExt.c -g20 -O9 -pc -i cc:include -i ci: -wEPRTcV -d NOMYDEBUG=1 -L
  3. cc:c/storm/StormC_2_0_8 -o ram:pOS2.o -d _M2_ -c p:pLib/pLibExt.c -g20 -O9 -pc -i cc:include -i ci: -wEPRTcV -d NOMYDEBUG=1 -L
  4. cc:c/storm/StormC_2_0_8 -o ram:pOS3.o -d _M3_ -c p:pLib/pLibExt.c -g20 -O9 -pc -i cc:include -i ci: -wEPRTcV -d NOMYDEBUG=1 -L
  5.  
  6. quit
  7. ; **/
  8.  
  9. #ifndef __INC_POS_PLIB_PLIBEXT_C
  10. #define __INC_POS_PLIB_PLIBEXT_C
  11. /*******************************************************************
  12.  $CRT 16 Mar 1996 : hb
  13.  
  14.  $AUT Holger Burkarth
  15.  $DAT >>pLibExt.c<<   01 Feb 1997    10:01:36 - (C) ProDAD
  16. *******************************************************************/
  17.  
  18. /*******************************************************************
  19. pOS_FWritef                    pOS_GetDosObjectType
  20. pOS_GetDosLockType             pOS_CheckBreakSignal
  21. pOS_GetNextString              pOS_GetDosObjectSize
  22. pOS_GetDosFailFromStr          pOS_VSPrintf
  23. pOS_SPrintf                    pOS_DosErrPrintf
  24. pOS_GetObjectData              pOS_SetObjectData
  25. pOS_GetAbsObjectData           pOS_SetAbsObjectData
  26. pOS_Debugf                     pOS_TimeDelay
  27. kprintf                        pOS_KPrintf
  28. *******************************************************************/
  29.  
  30. #include "p:pExec/Types.h"
  31.  
  32. #include "p:pDOS/DosErrors.h"
  33. #include "p:pDOS/FIB.h"
  34. #include "p:pDOS/Files.h"
  35. #include "p:pDOS/Lock.h"
  36. #include "p:pDOS/Process.h"
  37. #include "p:pDOS/Segment.h"
  38. #include "p:pDOS/DosSig.h"
  39. #include "p:pDOS/InfoData.h"
  40. #include "p:pDos/DosBase.h"
  41. #include "p:pExec/RawDoFmt.h"
  42. #include "p:pIntui/IClass.h"
  43. #include "p:proto/pExec2.h"
  44. #include "p:proto/pDOS2.h"
  45. #include "p:proto/pLibExt.h"
  46. #include "p:proto/pIntui2.h"
  47. #include "p:proto/pGfx2.h"
  48. #include "p:proto/pUtil2.h"
  49. #include "p:proto/pGadget2.h"
  50.  
  51.  
  52. #ifdef __cpluplus
  53. extern "C" {
  54. #endif
  55.  #include <string.h>
  56.  #include <ctype.h>
  57. #ifdef __cpluplus
  58. }
  59. #endif
  60.  
  61.  
  62. /** Dos **/
  63. #ifdef _M1_
  64.  
  65. /*----------------------------------
  66. -----------------------------------*/
  67. dossize_t pOS_FWritef(struct pOS_FileHandle* fh,const CHAR* format,...)
  68. {
  69.   return( pOS_VFWritef(fh,format,((ULONG*)&format)+1) );
  70. }
  71.  
  72. /*----------------------------------
  73. -----------------------------------*/
  74. SLONG pOS_GetDosObjectType(const struct pOS_FileLock* currDir,
  75.                            const dosname_t* name)
  76. {
  77.   SLONG Type=-1;
  78.   struct pOS_FileInfoBlock* FIB;
  79.  
  80.   FIB=(struct pOS_FileInfoBlock*)pOS_AllocDosObject(DOSOBJ_FIB,NULL);
  81.   if(FIB) {
  82.     struct pOS_FileLock *Lock;
  83.  
  84.     Lock=pOS_LockObject(currDir,name,FILELKACC_Shared);
  85.     if(Lock) {
  86.       if(pOS_ExamineObject(Lock,FIB))  Type=FIB->fib_DirEntryType;
  87.       else if(!pOS_IsFileSystem(Lock)) Type=FINFENTYP_Dir;
  88.       pOS_UnlockObject(Lock);
  89.     }
  90.     else Type=0;
  91.     pOS_FreeDosObject(DOSOBJ_FIB,FIB);
  92.   }
  93.   return(Type);
  94. }
  95.  
  96.  
  97. /*----------------------------------
  98. -----------------------------------*/
  99. SLONG pOS_GetDosLockType(const struct pOS_FileLock* lock)
  100. {
  101.   SLONG Type=-1;
  102.   struct pOS_FileInfoBlock* FIB;
  103.  
  104.   FIB=(struct pOS_FileInfoBlock*)pOS_AllocDosObject(DOSOBJ_FIB,NULL);
  105.   if(FIB) {
  106.     if(pOS_ExamineObject(lock,FIB))  Type=FIB->fib_DirEntryType;
  107.     else if(!pOS_IsFileSystem(lock)) Type=FINFENTYP_Dir;
  108.     pOS_FreeDosObject(DOSOBJ_FIB,FIB);
  109.   }
  110.   return(Type);
  111. }
  112.  
  113.  
  114. /*----------------------------------
  115. -----------------------------------*/
  116. dossize_t pOS_GetDosObjectSize(const struct pOS_FileLock* currDir,const dosname_t* name)
  117. {
  118.   dossize_t Size=0;
  119.   struct pOS_FileInfoBlock* FIB;
  120.  
  121.   FIB=(struct pOS_FileInfoBlock*)pOS_AllocDosObject(DOSOBJ_FIB,NULL);
  122.   if(FIB) {
  123.     struct pOS_FileLock *Lock;
  124.  
  125.     Lock=pOS_LockObject(currDir,name,FILELKACC_Shared);
  126.     if(Lock) {
  127.       if(pOS_ExamineObject(Lock,FIB)) Size=FIB->fib_Size;
  128.       pOS_UnlockObject(Lock);
  129.     }
  130.     pOS_FreeDosObject(DOSOBJ_FIB,FIB);
  131.   }
  132.   return(Size);
  133. }
  134.  
  135.  
  136.  
  137.  
  138. /*----------------------------------
  139. -----------------------------------*/
  140. BOOL pOS_CheckBreakSignal()
  141. {
  142.   if(pOS_SetSignal(0L,DOSSIGF_CTRL_C) & DOSSIGF_CTRL_C) {
  143.     struct pOS_Process *Proc=(struct pOS_Process*)pOS_FindTask(NULL);
  144.     if(Proc->pr_CES) pOS_WriteFile(Proc->pr_CES,"^C\n",3);
  145.     return(TRUE);
  146.   }
  147.   return(FALSE);
  148. }
  149.  
  150.  
  151. /*----------------------------------
  152. -----------------------------------*/
  153. #ifdef __cplusplus
  154. extern "C"
  155. #endif
  156.  
  157. static VOID pOSp_VSPrintf(struct pOS_RawDoFmtData *data)
  158. {
  159.   *((UBYTE*)data->rdft_User[0])=data->rdft_Data;
  160.   data->rdft_User[0]++;
  161.   data->rdft_ResSize++;
  162. }
  163.  
  164.  
  165. /*----------------------------------
  166. -----------------------------------*/
  167. CHAR* pOS_VSPrintf(CHAR* string,const CHAR* format,const ULONG* argv)
  168. {
  169.   struct pOS_RawDoFmtData Data;
  170.  
  171. //  ww_w("pOS_VSPrintf");
  172. //  ww_rp(string);
  173. //  ww_rp(format);
  174. //  ww_endN(0);
  175.  
  176.   Data.rdft_Format=format;
  177.   Data.rdft_InterFmt=NULL;
  178.   Data.rdft_DoFmt=pOSp_VSPrintf;
  179.   Data.rdft_Argv=argv;
  180.   Data.rdft_User[0]=(ULONG)string;
  181.  
  182.   pOS_RawDoFmt(&Data);
  183.   *((UBYTE*)Data.rdft_User[0])='\0';
  184.   return((CHAR*)Data.rdft_User[0]);
  185. }
  186.  
  187.  
  188. /*----------------------------------
  189. -----------------------------------*/
  190. CHAR* pOS_SPrintf(CHAR* string,const CHAR* format,...)
  191. {
  192.   return( pOS_VSPrintf(string,format,(ULONG*) ((&format)+1) ) );
  193. }
  194.  
  195.  
  196. /*----------------------------------
  197. -----------------------------------*/
  198. BOOL pOS_DosInfoDataName(const struct pOS_FileLock* currDir,
  199.                          const dosname_t* name,struct pOS_DosInfoData* data)
  200. {
  201.   BOOL Flg=FALSE;
  202.  
  203.   struct pOS_FileLock *Lock;
  204.  
  205.   Lock=pOS_LockObject(currDir,name,FILELKACC_Shared);
  206.   if(Lock) {
  207.     Flg=pOS_GetDosInfoData(Lock,data);
  208.     pOS_UnlockObject(Lock);
  209.   }
  210.  
  211.   return(Flg);
  212. }
  213.  
  214.  
  215. /*----------------------------------
  216. -----------------------------------*/
  217. BOOL pOS_DosErrPrintf(struct pOS_FileHandle* cerr,const CHAR* format,...)
  218. {
  219.   struct pOS_Process *const Proc=(struct pOS_Process*)pOS_FindTask(NULL);
  220.  
  221. //  ww_w("pOS_DosErrPrintf");
  222. //  ww_rp(format);
  223. //  ww_endN(FALSE);
  224.  
  225.   if(Proc->pr_Error2) {
  226.     if(!cerr) cerr=Proc->pr_CES;
  227.     if(!cerr) cerr=Proc->pr_COS;
  228.     if(cerr) {
  229.       const CHAR *Name=pOS_GetDosErrText((enum pOS_DosErrors)Proc->pr_Error2);
  230.       pOS_VFWritef(cerr,format,((ULONG*)&format)+1);
  231.       pOS_FWritef(cerr,"%s\n",Name);
  232.     }
  233.   }
  234.   return(Proc->pr_Error2!=0);
  235. }
  236.  
  237.  
  238.  
  239. #endif /** _M1_ **/
  240.  
  241.  
  242.  
  243. /** Exec **/
  244. #ifdef _M2_
  245.  
  246. /*----------------------------------
  247. -----------------------------------*/
  248. ULONG pOS_GetObjectData(APTR obj,ULONG tag)
  249. {
  250.   struct pOS_IntuiMethod Mth;
  251.   ULONG Dt;
  252.  
  253.   Mth.imth_Method=ICLMTH_Get;
  254.   Mth.imth_U.imth_Get.imgt_ID=tag;
  255.   Mth.imth_U.imth_Get.imgt_Variable=&Dt;
  256.   pOS_DoIMethodA(obj,(struct pOS_Method*)&Mth);
  257.   return(Dt);
  258. }
  259.  
  260. /*----------------------------------
  261. -----------------------------------*/
  262. ULONG pOS_SetObjectData(APTR obj,ULONG tag,...)
  263. {
  264.   struct pOS_IntuiMethod Mth;
  265.  
  266.   Mth.imth_Method=ICLMTH_Set;
  267.   Mth.imth_U.imth_Set.imst_Info=NULL;
  268.   Mth.imth_U.imth_Set.imst_Tags=(struct pOS_TagItem*)&tag;
  269.   return( pOS_DoIMethodA(obj,(struct pOS_Method*)&Mth) );
  270. }
  271.  
  272.  
  273. /*----------------------------------
  274. -----------------------------------*/
  275. ULONG pOS_GetAbsObjectData(const struct pOS_Class* cl,APTR obj,ULONG tag)
  276. {
  277.   struct pOS_IntuiMethod Mth;
  278.   ULONG Dt;
  279.  
  280.   Mth.imth_Method=ICLMTH_Get;
  281.   Mth.imth_U.imth_Get.imgt_ID=tag;
  282.   Mth.imth_U.imth_Get.imgt_Variable=&Dt;
  283.   pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)&Mth);
  284.   return(Dt);
  285. }
  286.  
  287. /*----------------------------------
  288. -----------------------------------*/
  289. ULONG pOS_SetAbsObjectData(const struct pOS_Class* cl,APTR obj,ULONG tag,...)
  290. {
  291.   struct pOS_IntuiMethod Mth;
  292.  
  293.   Mth.imth_Method=ICLMTH_Set;
  294.   Mth.imth_U.imth_Set.imst_Info=NULL;
  295.   Mth.imth_U.imth_Set.imst_Tags=(struct pOS_TagItem*)&tag;
  296.   return( pOS_DoAbsMethodA(cl,obj,(struct pOS_Method*)&Mth) );
  297. }
  298.  
  299. /*----------------------------------
  300. -----------------------------------*/
  301. VOID pOS_TimeDelay(ULONG sec,ULONG mics)
  302. {
  303.   pOS_WaitTimeSignal(0,mics + (sec?sec*1000000:0));
  304. }
  305.  
  306.  
  307. /*----------------------------------
  308. -----------------------------------*/
  309. VOID kprintf(const CHAR* format,...)
  310. {
  311.   pOS_VKPrintf(format,(ULONG*) ((&format)+1) );
  312. }
  313.  
  314. /*----------------------------------
  315. -----------------------------------*/
  316. VOID pOS_KPrintf(const CHAR* format,...)
  317. {
  318.   pOS_VKPrintf(format,(ULONG*) ((&format)+1) );
  319. }
  320.  
  321.  
  322.  
  323. #endif /** _M2_ **/
  324.  
  325.  
  326.  
  327. /** Other **/
  328. #ifdef _M3_
  329.  
  330. /*----------------------------------
  331. -----------------------------------*/
  332. ULONG pOS_GetDosFailFromStr(const CHAR* str)
  333. {
  334.   ULONG Err;
  335.  
  336. //  ww_w("pOS_GetDosFailFromStr");
  337. //  ww_rp(str);
  338. //  ww_endN(-1);
  339.  
  340.   if     (stricmp(str,"OK")==0)    Err=DOSFAIL_OK;
  341.   else if(stricmp(str,"WARN")==0)  Err=DOSFAIL_WARN;
  342.   else if(stricmp(str,"ABORT")==0) Err=DOSFAIL_ABORT;
  343.   else if(stricmp(str,"ERROR")==0) Err=DOSFAIL_ERROR;
  344.   else if(stricmp(str,"FAIL")==0)  Err=DOSFAIL_FAIL;
  345.   else Err=-1;
  346.  
  347.   return(Err);
  348. }
  349.  
  350.  
  351. /*----------------------------------
  352. -----------------------------------*/
  353. const CHAR* pOS_GetNextString(const CHAR* name,CHAR* puffer,size_t pufSize)
  354. {
  355.   while(*name==' ' || *name=='\t') name++;
  356.  
  357.   if(*name=='\"') {
  358.     for(++name; !(*name=='\"' || *name=='\0' || pufSize==0);
  359.             *puffer++=*name++,--pufSize) ;
  360.     if(*name) ++name;
  361.   }
  362.   else {
  363.     for(; !(*name==' ' || *name=='\t' || *name=='\0' || *name=='\n' || pufSize==0);
  364.             *puffer++=*name++,--pufSize) ;
  365.   }
  366.  
  367.   while(*name==' ' || *name=='\t') name++;
  368.  
  369.   puffer[0]='\0';
  370.   return(name);
  371. }
  372.  
  373.  
  374. #endif /** _M3_ **/
  375.  
  376.  
  377.  
  378. #endif
  379.