PageRenderTime 31ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

/MagickCore/vms.c

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