gp_dosfs.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright (C) 1992, 1993, 1996, 1998 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gp_dosfs.c,v 1.2.6.1 2002/01/25 06:33:09 rayjj Exp $ */
  16. /* Common routines for MS-DOS (any compiler) and DesqView/X, */
  17. /* which has a MS-DOS-like file system. */
  18. #include "dos_.h"
  19. #include "gx.h"
  20. #include "gp.h"
  21. /* ------ Printer accessing ------ */
  22. /* Put a printer file (which might be stdout) into binary or text mode. */
  23. /* This is not a standard gp procedure, */
  24. /* but all MS-DOS configurations need it. */
  25. void
  26. gp_set_file_binary(int prnfno, bool binary)
  27. {
  28. union REGS regs;
  29. regs.h.ah = 0x44; /* ioctl */
  30. regs.h.al = 0; /* get device info */
  31. regs.rshort.bx = prnfno;
  32. intdos(&regs, &regs);
  33. if (regs.rshort.cflag != 0 || !(regs.h.dl & 0x80))
  34. return; /* error, or not a device */
  35. if (binary)
  36. regs.h.dl |= 0x20; /* binary (no ^Z intervention) */
  37. else
  38. regs.h.dl &= ~0x20; /* text */
  39. regs.h.dh = 0;
  40. regs.h.ah = 0x44; /* ioctl */
  41. regs.h.al = 1; /* set device info */
  42. intdos(&regs, &regs);
  43. }
  44. /* ------ File accessing ------ */
  45. /* Set a file into binary or text mode. */
  46. int
  47. gp_setmode_binary(FILE * pfile, bool binary)
  48. {
  49. gp_set_file_binary(fileno(pfile), binary);
  50. return 0; /* Fake out dos return status */
  51. }
  52. /* ------ File names ------ */
  53. /* Define the character used for separating file names in a list. */
  54. const char gp_file_name_list_separator = ';';
  55. /* Define the string to be concatenated with the file mode */
  56. /* for opening files without end-of-line conversion. */
  57. const char gp_fmode_binary_suffix[] = "b";
  58. /* Define the file modes for binary reading or writing. */
  59. const char gp_fmode_rb[] = "rb";
  60. const char gp_fmode_wb[] = "wb";
  61. /* Answer whether a file name contains a directory/device specification, */
  62. /* i.e. is absolute (not directory- or device-relative). */
  63. bool
  64. gp_file_name_is_absolute(const char *fname, unsigned len)
  65. {
  66. /* A file name is absolute if it contains a drive specification */
  67. /* (second character is a :) or if it start with 0 or more .s */
  68. /* followed by a / or \. */
  69. if (len >= 2 && fname[1] == ':')
  70. return true;
  71. while (len && *fname == '.')
  72. ++fname, --len;
  73. return (len && (*fname == '/' || *fname == '\\'));
  74. }
  75. /* Answer whether the file_name references the directory */
  76. /* containing the specified path (parent). */
  77. bool
  78. gp_file_name_references_parent(const char *fname, unsigned len)
  79. {
  80. int i = 0, last_sep_pos = -1;
  81. /* A file name references its parent directory if it starts */
  82. /* with ../ or ..\ or if one of these strings follows / or \ */
  83. while (i < len) {
  84. if (fname[i] == '/' || fname[i] == '\\') {
  85. last_sep_pos = i++;
  86. continue;
  87. }
  88. if (fname[i++] != '.')
  89. continue;
  90. if (i > last_sep_pos + 2 || (i < len && fname[i] != '.'))
  91. continue;
  92. i++;
  93. /* have separator followed by .. */
  94. if (i < len && (fname[i] == '/' || fname[i++] == '\\'))
  95. return true;
  96. }
  97. return false;
  98. }
  99. /* Answer the string to be used for combining a directory/device prefix */
  100. /* with a base file name. The prefix directory/device is examined to */
  101. /* determine if a separator is needed and may return an empty string */
  102. const char *
  103. gp_file_name_concat_string(const char *prefix, unsigned plen)
  104. {
  105. if (plen > 0)
  106. switch (prefix[plen - 1]) {
  107. case ':':
  108. case '/':
  109. case '\\':
  110. return "";
  111. };
  112. return "/";
  113. }