1 /* Copyright (C) 2001-2012 Artifex Software, Inc.
2 All Rights Reserved.
3
4 This software is provided AS-IS with no warranty, either express or
5 implied.
6
7 This software is distributed under license and may not be copied,
8 modified or distributed except as expressly authorized under the terms
9 of the license contained in the file LICENSE in this distribution.
10
11 Refer to licensing information at http://www.artifex.com or contact
12 Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael,
13 CA 94903, U.S.A., +1(415)492-9861, for further information.
14 */
15
16
17 /* Common routines for MS-DOS (any compiler) and DesqView/X, */
18 /* which has a MS-DOS-like file system. */
19 #include "dos_.h"
20 #include "gx.h"
21 #include "gp.h"
22 #include "gpmisc.h"
23
24 /* ------ Printer accessing ------ */
25
26 /* Put a printer file (which might be stdout) into binary or text mode. */
27 /* This is not a standard gp procedure, */
28 /* but all MS-DOS configurations need it. */
29 void
gp_set_file_binary(int prnfno,bool binary)30 gp_set_file_binary(int prnfno, bool binary)
31 {
32 union REGS regs;
33
34 regs.h.ah = 0x44; /* ioctl */
35 regs.h.al = 0; /* get device info */
36 regs.rshort.bx = prnfno;
37 intdos(®s, ®s);
38 if (regs.rshort.cflag != 0 || !(regs.h.dl & 0x80))
39 return; /* error, or not a device */
40 if (binary)
41 regs.h.dl |= 0x20; /* binary (no ^Z intervention) */
42 else
43 regs.h.dl &= ~0x20; /* text */
44 regs.h.dh = 0;
45 regs.h.ah = 0x44; /* ioctl */
46 regs.h.al = 1; /* set device info */
47 intdos(®s, ®s);
48 }
49
50 /* ------ File accessing ------ */
51
52 /* Set a file into binary or text mode. */
53 int
gp_setmode_binary(FILE * pfile,bool binary)54 gp_setmode_binary(FILE * pfile, bool binary)
55 {
56 gp_set_file_binary(fileno(pfile), binary);
57 return 0; /* Fake out dos return status */
58 }
59
60 /* ------ File names ------ */
61
62 /* Define the character used for separating file names in a list. */
63 const char gp_file_name_list_separator = ';';
64
65 /* Define the string to be concatenated with the file mode */
66 /* for opening files without end-of-line conversion. */
67 const char gp_fmode_binary_suffix[] = "b";
68
69 /* Define the file modes for binary reading or writing. */
70 const char gp_fmode_rb[] = "rb";
71 const char gp_fmode_wb[] = "wb";
72
73 /* -------------- Helpers for gp_file_name_combine_generic ------------- */
74
gp_file_name_root(const char * fname,uint len)75 uint gp_file_name_root(const char *fname, uint len)
76 { int i = 0;
77
78 if (len == 0)
79 return 0;
80 if (len > 1 && fname[0] == '\\' && fname[1] == '\\') {
81 /* A network path: "\\server\share\" */
82 int k = 0;
83
84 for (i = 2; i < len; i++)
85 if (fname[i] == '\\' || fname[i] == '/')
86 if (k++) {
87 i++;
88 break;
89 }
90 } else if (fname[0] == '/' || fname[0] == '\\') {
91 /* Absolute with no drive. */
92 i = 1;
93 } else if (len > 1 && fname[1] == ':') {
94 /* Absolute with a drive. */
95 i = (len > 2 && (fname[2] == '/' || fname[2] == '\\') ? 3 : 2);
96 }
97 return i;
98 }
99
gs_file_name_check_separator(const char * fname,int len,const char * item)100 uint gs_file_name_check_separator(const char *fname, int len, const char *item)
101 { if (len > 0) {
102 if (fname[0] == '/' || fname[0] == '\\')
103 return 1;
104 } else if (len < 0) {
105 if (fname[-1] == '/' || fname[-1] == '\\')
106 return 1;
107 }
108 return 0;
109 }
110
gp_file_name_is_parent(const char * fname,uint len)111 bool gp_file_name_is_parent(const char *fname, uint len)
112 { return len == 2 && fname[0] == '.' && fname[1] == '.';
113 }
114
gp_file_name_is_current(const char * fname,uint len)115 bool gp_file_name_is_current(const char *fname, uint len)
116 { return len == 1 && fname[0] == '.';
117 }
118
gp_file_name_separator(void)119 const char *gp_file_name_separator(void)
120 { return "/";
121 }
122
gp_file_name_directory_separator(void)123 const char *gp_file_name_directory_separator(void)
124 { return "/";
125 }
126
gp_file_name_parent(void)127 const char *gp_file_name_parent(void)
128 { return "..";
129 }
130
gp_file_name_current(void)131 const char *gp_file_name_current(void)
132 { return ".";
133 }
134
gp_file_name_is_partent_allowed(void)135 bool gp_file_name_is_partent_allowed(void)
136 { return true;
137 }
138
gp_file_name_is_empty_item_meanful(void)139 bool gp_file_name_is_empty_item_meanful(void)
140 { return false;
141 }
142
143 gp_file_name_combine_result
gp_file_name_combine(const char * prefix,uint plen,const char * fname,uint flen,bool no_sibling,char * buffer,uint * blen)144 gp_file_name_combine(const char *prefix, uint plen, const char *fname, uint flen,
145 bool no_sibling, char *buffer, uint *blen)
146 {
147 return gp_file_name_combine_generic(prefix, plen,
148 fname, flen, no_sibling, buffer, blen);
149 }
150