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

  1.  
  2. /*******************************************************************
  3.  $CRT 27 Dec 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>Relabel.c<<   29 Dec 1996    15:38:18 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/c/Relabel p:pLib/StartCode.o p:/pOS_RKRM/pDos/Relabel.c p:pLib/StdIO.o -l pOSStub -l pOS
  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. ***
  45. \*/
  46.  
  47.  
  48. #define __COMPUTER_AMIGA 1
  49. #define NOMYDEBUG
  50.  
  51. #include "p:pExec/Types.h"
  52. #include "p:pDOS/ArgTags.h"
  53. #include "p:pDos/DosBase.h"
  54. #include "p:pDOS/DosSig.h"
  55. #include "p:pDOS/DosErrors.h"
  56. #include "p:pDOS/Process.h"
  57. #include "p:pDos/Lock.h"
  58. #include "p:pDos/FIB.h"
  59. #include "p:pDOS/DosDev.h"
  60. #include "p:proto/pLibExt.h"
  61. #include "p:proto/pExec2.h"
  62. #include "p:proto/pDOS2.h"
  63.  
  64. #ifdef _____ME_____
  65.   #include "grund/inc_string.h"
  66.   #include "grund/inc_stdio.h"
  67. #else
  68.  #ifdef __cplusplus
  69.  extern "C" {
  70.  #endif
  71.   #include <string.h>
  72.   #include <stdio.h>
  73.  #ifdef __cplusplus
  74.  }
  75.  #endif
  76. #endif
  77.  
  78.  
  79. const CHAR *HelpText=
  80. ""
  81. ;
  82.  
  83. const CHAR *PrgHeader=
  84. "Change Volume-Name";
  85.  
  86. const CHAR *PrgVerText=
  87. "$VER: 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Burkarth)";
  88.  
  89.  
  90.  
  91. /*----------------------------------
  92. -----------------------------------*/
  93. #ifdef __cplusplus
  94. extern "C"
  95. #endif
  96.  
  97. VOID main()
  98. {
  99.   struct pOS_DosArgs* Args;
  100.   ULONG Ops[2]={0,0};
  101.   UWORD Err=0;
  102.  
  103.   Args=pOS_ReadDosArgs(
  104. // 0        1
  105. "DEVICE/A, NAME",
  106. Ops,sizeof(Ops)/sizeof(ULONG),
  107.  
  108.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  109.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  110.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  111.     TAG_END);
  112.  
  113.   if(Args) {
  114.     pOS_FileLock* Lock;
  115.     pOS_DosDevice* DD;
  116.  
  117.     if(Lock=pOS_LockObject(NULL,(dosname_t*)Ops[0],
  118.                     FILELKACC_Shared | FILELKACC_NoReq))
  119.     {
  120.       DD=Lock->fl_DosDev;
  121.       if(DD->ddv_Type==DDTYP_Volume) DD=DD->ddv_U.ddv_Volume.ddvv_Handler;
  122.       else if(DD->ddv_Type!=DDTYP_Handler) {
  123.         printf("Device isn't handler <%s>\n",DD->ddv_Dev.lib_Node.ln_Name);
  124.         DD=NULL;
  125.       }
  126.  
  127.       if(DD) {
  128.         if(Ops[1]) {
  129.           if(strpbrk((CHAR*)Ops[1],"/:")) {
  130.             printf("Illegal Name <%s>, no ':' and no '/'!\n",Ops[1]);
  131.             Err=DOSFAIL_FAIL;
  132.           }
  133.           else {
  134.             if(!pOS_RelabelDosDevice(DD,(CHAR*)Ops[1])) {
  135.               pOS_PrintDosErr(NULL,DD->ddv_Dev.lib_Node.ln_Name,0);
  136.               Err=DOSFAIL_FAIL;
  137.             }
  138.           }
  139.         }
  140.         else {
  141.           pOS_FileInfoBlock* FIB;
  142.  
  143.           FIB=(pOS_FileInfoBlock*)pOS_AllocDosObject(DOSOBJ_FIB,NULL);
  144.           if(FIB) {
  145.             if(pOS_ExamineObject(Lock,FIB))  {
  146.               printf("%s\n",FIB->fib_FileName);
  147.             }
  148.             else {
  149.               pOS_PrintDosErr(NULL,DD->ddv_Dev.lib_Node.ln_Name,0);
  150.             }
  151.             pOS_FreeDosObject(DOSOBJ_FIB,FIB);
  152.           }
  153.         }
  154.       }
  155.       pOS_UnlockObject(Lock);
  156.     }
  157.     else {
  158.       pOS_PrintDosErr(NULL,(CHAR*)Ops[0],0);
  159.       Err=DOSFAIL_FAIL;
  160.     }
  161.     pOS_DeleteDosArgs(Args);
  162.   }
  163.   pOS_SetShellFail(Err);
  164. }
  165.  
  166.  
  167.