cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | % John Cristy % |
| 17 | % October 1994 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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) |
| 42 | /* |
| 43 | Include declarations. |
| 44 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame^] | 45 | #include "MagickCore/studio.h" |
| 46 | #include "MagickCore/string_.h" |
| 47 | #include "MagickCore/memory_.h" |
| 48 | #include "MagickCore/vms.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 49 | |
| 50 | #if !defined(_AXP_) && (!defined(__VMS_VER) || (__VMS_VER < 70000000)) |
| 51 | /* |
| 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 53 | % % |
| 54 | % % |
| 55 | % % |
| 56 | % c l o s e d i r % |
| 57 | % % |
| 58 | % % |
| 59 | % % |
| 60 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 61 | % |
| 62 | % closedir() closes the named directory stream and frees the DIR structure. |
| 63 | % |
| 64 | % The format of the closedir method is: |
| 65 | % |
| 66 | % |
| 67 | % A description of each parameter follows: |
| 68 | % |
| 69 | % o entry: Specifies a pointer to a DIR structure. |
| 70 | % |
| 71 | % |
| 72 | */ |
| 73 | void closedir(DIR *directory) |
| 74 | { |
| 75 | if (image->debug != MagickFalse) |
| 76 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 77 | assert(directory != (DIR *) NULL); |
| 78 | directory->pattern=DestroyString(directory->pattern); |
| 79 | directory=DestroyString(directory); |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 84 | % % |
| 85 | % % |
| 86 | % % |
| 87 | % o p e n d i r % |
| 88 | % % |
| 89 | % % |
| 90 | % % |
| 91 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 92 | % |
| 93 | % opendir() opens the directory named by filename and associates a directory |
| 94 | % stream with it. |
| 95 | % |
| 96 | % The format of the opendir method is: |
| 97 | % |
| 98 | % opendir(entry) |
| 99 | % |
| 100 | % A description of each parameter follows: |
| 101 | % |
| 102 | % o entry: Specifies a pointer to a DIR structure. |
| 103 | % |
| 104 | % |
| 105 | */ |
| 106 | DIR *opendir(char *name) |
| 107 | { |
| 108 | DIR |
| 109 | *directory; |
| 110 | |
| 111 | /* |
| 112 | Allocate memory for handle and the pattern. |
| 113 | */ |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 114 | directory=(DIR *) AcquireMagickMemory(sizeof(DIR)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 115 | if (directory == (DIR *) NULL) |
| 116 | { |
| 117 | errno=ENOMEM; |
| 118 | return((DIR *) NULL); |
| 119 | } |
| 120 | if (strcmp(".",name) == 0) |
| 121 | name=""; |
| 122 | directory->pattern=(char *) AcquireQuantumMemory(strlen(name)+sizeof("*.*")+ |
| 123 | 1UL,sizeof(*directory->pattern)); |
| 124 | if (directory->pattern == (char *) NULL) |
| 125 | { |
| 126 | directory=DestroyString(directory); |
| 127 | errno=ENOMEM; |
| 128 | return(NULL); |
| 129 | } |
| 130 | /* |
| 131 | Initialize descriptor. |
| 132 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 133 | (void) FormatLocaleString(directory->pattern,MaxTextExtent,"%s*.*",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 134 | directory->context=0; |
| 135 | directory->pat.dsc$a_pointer=directory->pattern; |
| 136 | directory->pat.dsc$w_length=strlen(directory->pattern); |
| 137 | directory->pat.dsc$b_dtype=DSC$K_DTYPE_T; |
| 138 | directory->pat.dsc$b_class=DSC$K_CLASS_S; |
| 139 | return(directory); |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 144 | % % |
| 145 | % % |
| 146 | % % |
| 147 | % r e a d d i r % |
| 148 | % % |
| 149 | % % |
| 150 | % % |
| 151 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 152 | % |
| 153 | % readdir() returns a pointer to a structure representing the directory entry |
| 154 | % at the current position in the directory stream to which entry refers. |
| 155 | % |
| 156 | % The format of the readdir |
| 157 | % |
| 158 | % readdir(entry) |
| 159 | % |
| 160 | % A description of each parameter follows: |
| 161 | % |
| 162 | % o entry: Specifies a pointer to a DIR structure. |
| 163 | % |
| 164 | % |
| 165 | */ |
| 166 | struct dirent *readdir(DIR *directory) |
| 167 | { |
| 168 | char |
| 169 | buffer[sizeof(directory->entry.d_name)]; |
| 170 | |
| 171 | int |
| 172 | status; |
| 173 | |
| 174 | register char |
| 175 | *p; |
| 176 | |
| 177 | register int |
| 178 | i; |
| 179 | |
| 180 | struct dsc$descriptor_s |
| 181 | result; |
| 182 | |
| 183 | /* |
| 184 | Initialize the result descriptor. |
| 185 | */ |
| 186 | result.dsc$a_pointer=buffer; |
| 187 | result.dsc$w_length=sizeof(buffer)-2; |
| 188 | result.dsc$b_dtype=DSC$K_DTYPE_T; |
| 189 | result.dsc$b_class=DSC$K_CLASS_S; |
| 190 | status=lib$find_file(&directory->pat,&result,&directory->context); |
| 191 | if ((status == RMS$_NMF) || (directory->context == 0L)) |
| 192 | return((struct dirent *) NULL); |
| 193 | /* |
| 194 | Lowercase all filenames. |
| 195 | */ |
| 196 | buffer[sizeof(buffer)-1]='\0'; |
| 197 | for (p=buffer; *p; p++) |
| 198 | if (isupper((unsigned char) *p)) |
| 199 | *p=tolower(*p); |
| 200 | /* |
| 201 | Skip any directory component and just copy the name. |
| 202 | */ |
| 203 | p=buffer; |
| 204 | while (isspace((unsigned char) *p) == 0) |
| 205 | p++; |
| 206 | *p='\0'; |
| 207 | p=strchr(buffer,']'); |
| 208 | if (p) |
| 209 | (void) CopyMagickString(directory->entry.d_name,p+1,MaxTextExtent); |
| 210 | else |
| 211 | (void) CopyMagickString(directory->entry.d_name,buffer,MaxTextExtent); |
| 212 | directory->entry.d_namlen=strlen(directory->entry.d_name); |
| 213 | return(&directory->entry); |
| 214 | } |
| 215 | #endif /* !defined(_AXP_) && (!defined(__VMS_VER) || (__VMS_VER < 70000000)) */ |
| 216 | |
| 217 | /* |
| 218 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 219 | % % |
| 220 | % % |
| 221 | % % |
| 222 | % I s M a g i c k C o n f l i c t % |
| 223 | % % |
| 224 | % % |
| 225 | % % |
| 226 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 227 | % |
| 228 | % VMSIsMagickConflict() returns true if the image format conflicts with a |
| 229 | % logical drive (.e.g. SYS$SCRATCH:). |
| 230 | % |
| 231 | % Contributed by Forrest Cahoon (forrest@wiredaemons.com) |
| 232 | % |
| 233 | % The format of the VMSIsMagickConflict method is: |
| 234 | % |
| 235 | % MagickBooleanType VMSIsMagickConflict(const char *magick) |
| 236 | % |
| 237 | % A description of each parameter follows: |
| 238 | % |
| 239 | % o magick: Specifies the image format. |
| 240 | % |
| 241 | % |
| 242 | */ |
| 243 | MagickExport MagickBooleanType VMSIsMagickConflict(const char *magick) |
| 244 | { |
| 245 | ile3 |
| 246 | item_list[2]; |
| 247 | |
| 248 | int |
| 249 | device_class, |
| 250 | status; |
| 251 | |
| 252 | struct dsc$descriptor_s |
| 253 | device; |
| 254 | |
| 255 | assert(magick != (char *) NULL); |
| 256 | device.dsc$w_length=strlen(magick); |
| 257 | device.dsc$a_pointer=(char *) magick; |
| 258 | device.dsc$b_class=DSC$K_CLASS_S; |
| 259 | device.dsc$b_dtype=DSC$K_DTYPE_T; |
| 260 | item_list[0].ile3$w_length=sizeof(device_class); |
| 261 | item_list[0].ile3$w_code=DVI$_DEVCLASS; |
| 262 | item_list[0].ile3$ps_bufaddr=&device_class; |
| 263 | item_list[0].ile3$ps_retlen_addr=NULL; |
| 264 | (void) ResetMagickMemory(&item_list[1],0,sizeof(item_list[1])); |
| 265 | status=sys$getdviw(0,0,&device,&item_list,0,0,0,0); |
| 266 | if ((status == SS$_NONLOCAL) || |
| 267 | ((status & 0x01) && (device_class & (DC$_DISK | DC$_TAPE)))) |
| 268 | return(MagickTrue); |
| 269 | return(MagickFalse); |
| 270 | } |
| 271 | #endif /* defined(vms) */ |