Home | History | Annotate | Download | only in MagickCore
      1 /*
      2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      3 %                                                                             %
      4 %                                                                             %
      5 %                                                                             %
      6 %                            V   V  M   M  SSSSS                              %
      7 %                            V   V  MM MM  SS                                 %
      8 %                            V   V  M M M   SSS                               %
      9 %                             V V   M   M     SS                              %
     10 %                              V    M   M  SSSSS                              %
     11 %                                                                             %
     12 %                                                                             %
     13 %                         MagickCore VMS Utility Methods                      %
     14 %                                                                             %
     15 %                               Software Design                               %
     16 %                                    Cristy                                   %
     17 %                                October 1994                                 %
     18 %                                                                             %
     19 %                                                                             %
     20 %  Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization      %
     21 %  dedicated to making software imaging solutions freely available.           %
     22 %                                                                             %
     23 %  You may not use this file except in compliance with the License.  You may  %
     24 %  obtain a copy of the License at                                            %
     25 %                                                                             %
     26 %    http://www.imagemagick.org/script/license.php                            %
     27 %                                                                             %
     28 %  Unless required by applicable law or agreed to in writing, software        %
     29 %  distributed under the License is distributed on an "AS IS" BASIS,          %
     30 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
     31 %  See the License for the specific language governing permissions and        %
     32 %  limitations under the License.                                             %
     33 %                                                                             %
     34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     35 %
     36 %  The directory methods are strongly based on similar methods written
     37 %  by Rich Salz.
     38 %
     39 */
     40 
     41 #if defined(vms)
     43 /*
     44   Include declarations.
     45 */
     46 #include "MagickCore/studio.h"
     47 #include "MagickCore/string_.h"
     48 #include "MagickCore/memory_.h"
     49 #include "MagickCore/vms.h"
     50 
     51 #if !defined(_AXP_) && (!defined(__VMS_VER) || (__VMS_VER < 70000000))
     53 /*
     54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     55 %                                                                             %
     56 %                                                                             %
     57 %                                                                             %
     58 %   c l o s e d i r                                                           %
     59 %                                                                             %
     60 %                                                                             %
     61 %                                                                             %
     62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     63 %
     64 %  closedir() closes the named directory stream and frees the DIR structure.
     65 %
     66 %  The format of the closedir method is:
     67 %
     68 %
     69 %  A description of each parameter follows:
     70 %
     71 %    o entry: Specifies a pointer to a DIR structure.
     72 %
     73 %
     74 */
     75 void closedir(DIR *directory)
     76 {
     77   if (image->debug != MagickFalse)
     78     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
     79   assert(directory != (DIR *) NULL);
     80   directory->pattern=DestroyString(directory->pattern);
     81   directory=DestroyString(directory);
     82 }
     83 
     84 /*
     86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     87 %                                                                             %
     88 %                                                                             %
     89 %                                                                             %
     90 %   o p e n d i r                                                             %
     91 %                                                                             %
     92 %                                                                             %
     93 %                                                                             %
     94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     95 %
     96 %  opendir() opens the directory named by filename and associates a directory
     97 %  stream with it.
     98 %
     99 %  The format of the opendir method is:
    100 %
    101 %      opendir(entry)
    102 %
    103 %  A description of each parameter follows:
    104 %
    105 %    o entry: Specifies a pointer to a DIR structure.
    106 %
    107 %
    108 */
    109 DIR *opendir(char *name)
    110 {
    111   DIR
    112     *directory;
    113 
    114   /*
    115     Allocate memory for handle and the pattern.
    116   */
    117   directory=(DIR *) AcquireMagickMemory(sizeof(DIR));
    118   if (directory == (DIR *) NULL)
    119     {
    120       errno=ENOMEM;
    121       return((DIR *) NULL);
    122     }
    123   if (strcmp(".",name) == 0)
    124     name="";
    125   directory->pattern=(char *) AcquireQuantumMemory(strlen(name)+sizeof("*.*")+
    126     1UL,sizeof(*directory->pattern));
    127   if (directory->pattern == (char *) NULL)
    128     {
    129       directory=DestroyString(directory);
    130       errno=ENOMEM;
    131       return(NULL);
    132     }
    133   /*
    134     Initialize descriptor.
    135   */
    136   (void) FormatLocaleString(directory->pattern,MagickPathExtent,"%s*.*",name);
    137   directory->context=0;
    138   directory->pat.dsc$a_pointer=directory->pattern;
    139   directory->pat.dsc$w_length=strlen(directory->pattern);
    140   directory->pat.dsc$b_dtype=DSC$K_DTYPE_T;
    141   directory->pat.dsc$b_class=DSC$K_CLASS_S;
    142   return(directory);
    143 }
    144 
    145 /*
    147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    148 %                                                                             %
    149 %                                                                             %
    150 %                                                                             %
    151 %   r e a d d i r                                                             %
    152 %                                                                             %
    153 %                                                                             %
    154 %                                                                             %
    155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    156 %
    157 %  readdir() returns a pointer to a structure representing the directory entry
    158 %  at the current position in the directory stream to which entry refers.
    159 %
    160 %  The format of the readdir
    161 %
    162 %      readdir(entry)
    163 %
    164 %  A description of each parameter follows:
    165 %
    166 %    o entry: Specifies a pointer to a DIR structure.
    167 %
    168 %
    169 */
    170 struct dirent *readdir(DIR *directory)
    171 {
    172   char
    173     buffer[sizeof(directory->entry.d_name)];
    174 
    175   int
    176     status;
    177 
    178   register char
    179     *p;
    180 
    181   register int
    182     i;
    183 
    184   struct dsc$descriptor_s
    185     result;
    186 
    187   /*
    188     Initialize the result descriptor.
    189   */
    190   result.dsc$a_pointer=buffer;
    191   result.dsc$w_length=sizeof(buffer)-2;
    192   result.dsc$b_dtype=DSC$K_DTYPE_T;
    193   result.dsc$b_class=DSC$K_CLASS_S;
    194   status=lib$find_file(&directory->pat,&result,&directory->context);
    195   if ((status == RMS$_NMF) || (directory->context == 0L))
    196     return((struct dirent *) NULL);
    197   /*
    198     Lowercase all filenames.
    199   */
    200   buffer[sizeof(buffer)-1]='\0';
    201   for (p=buffer; *p; p++)
    202     if (isupper((int) ((unsigned char) *p)))
    203       *p=tolower(*p);
    204   /*
    205     Skip any directory component and just copy the name.
    206   */
    207   p=buffer;
    208   while (isspace((int) ((unsigned char) *p)) == 0)
    209     p++;
    210   *p='\0';
    211   p=strchr(buffer,']');
    212   if (p)
    213     (void) CopyMagickString(directory->entry.d_name,p+1,MagickPathExtent);
    214   else
    215     (void) CopyMagickString(directory->entry.d_name,buffer,MagickPathExtent);
    216   directory->entry.d_namlen=strlen(directory->entry.d_name);
    217   return(&directory->entry);
    218 }
    219 #endif /* !defined(_AXP_) && (!defined(__VMS_VER) || (__VMS_VER < 70000000)) */
    220 
    221 /*
    223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    224 %                                                                             %
    225 %                                                                             %
    226 %                                                                             %
    227 %   I s M a g i c k C o n f l i c t                                           %
    228 %                                                                             %
    229 %                                                                             %
    230 %                                                                             %
    231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    232 %
    233 %  VMSIsMagickConflict() returns true if the image format conflicts with a
    234 %  logical drive (.e.g. SYS$SCRATCH:).
    235 %
    236 %  Contributed by Forrest Cahoon (forrest (at) wiredaemons.com)
    237 %
    238 %  The format of the VMSIsMagickConflict method is:
    239 %
    240 %      MagickBooleanType VMSIsMagickConflict(const char *magick)
    241 %
    242 %  A description of each parameter follows:
    243 %
    244 %    o magick: Specifies the image format.
    245 %
    246 %
    247 */
    248 MagickExport MagickBooleanType VMSIsMagickConflict(const char *magick)
    249 {
    250   ile3
    251     item_list[2];
    252 
    253   int
    254     device_class,
    255     status;
    256 
    257   struct dsc$descriptor_s
    258     device;
    259 
    260   assert(magick != (char *) NULL);
    261   device.dsc$w_length=strlen(magick);
    262   device.dsc$a_pointer=(char *) magick;
    263   device.dsc$b_class=DSC$K_CLASS_S;
    264   device.dsc$b_dtype=DSC$K_DTYPE_T;
    265   item_list[0].ile3$w_length=sizeof(device_class);
    266   item_list[0].ile3$w_code=DVI$_DEVCLASS;
    267   item_list[0].ile3$ps_bufaddr=&device_class;
    268   item_list[0].ile3$ps_retlen_addr=NULL;
    269   (void) ResetMagickMemory(&item_list[1],0,sizeof(item_list[1]));
    270   status=sys$getdviw(0,0,&device,&item_list,0,0,0,0);
    271   if ((status == SS$_NONLOCAL) ||
    272       ((status & 0x01) && (device_class & (DC$_DISK | DC$_TAPE))))
    273     return(MagickTrue);
    274   return(MagickFalse);
    275 }
    276 #endif /* defined(vms) */
    277