|
1 /* |
|
2 * main.c - the main() function |
|
3 * |
|
4 * This file is part of zsh, the Z shell. |
|
5 * |
|
6 * Copyright (c) 1992-1997 Paul Falstad |
|
7 * All rights reserved. |
|
8 * |
|
9 * Permission is hereby granted, without written agreement and without |
|
10 * license or royalty fees, to use, copy, modify, and distribute this |
|
11 * software and to distribute modified versions of this software for any |
|
12 * purpose, provided that the above copyright notice and the following |
|
13 * two paragraphs appear in all copies of this software. |
|
14 * |
|
15 * In no event shall Paul Falstad or the Zsh Development Group be liable |
|
16 * to any party for direct, indirect, special, incidental, or consequential |
|
17 * damages arising out of the use of this software and its documentation, |
|
18 * even if Paul Falstad and the Zsh Development Group have been advised of |
|
19 * the possibility of such damage. |
|
20 * |
|
21 * Paul Falstad and the Zsh Development Group specifically disclaim any |
|
22 * warranties, including, but not limited to, the implied warranties of |
|
23 * merchantability and fitness for a particular purpose. The software |
|
24 * provided hereunder is on an "as is" basis, and Paul Falstad and the |
|
25 * Zsh Development Group have no obligation to provide maintenance, |
|
26 * support, updates, enhancements, or modifications. |
|
27 * |
|
28 */ |
|
29 |
|
30 #include "zsh.mdh" |
|
31 #include "main.pro" |
|
32 |
|
33 /* |
|
34 * Support for Cygwin binary/text mode filesystems. |
|
35 * Peter A. Castro <doctor@fruitbat.org> |
|
36 * |
|
37 * This deserves some explaination, because it uses Cygwin specific |
|
38 * runtime functions. |
|
39 * |
|
40 * Cygwin supports the notion of binary or text mode access to files |
|
41 * based on the mount attributes of the filesystem. If a file is on |
|
42 * a binary mounted filesystem, you get exactly what's in the file, CRLF's |
|
43 * and all. If it's on a text mounted filesystem, Cygwin will strip out |
|
44 * the CRs. This presents a problem because zsh code doesn't allow for |
|
45 * CRLF's as line terminators. So, we must force all open files to be |
|
46 * in text mode reguardless of the underlying filesystem attributes. |
|
47 * However, we only want to do this for reading, not writing as we still |
|
48 * want to write files in the mode of the filesystem. To do this, |
|
49 * we have two options: augment all {f}open() calls to have O_TEXT added to |
|
50 * the list of file mode options, or have the Cygwin runtime do it for us. |
|
51 * I choose the latter. :) |
|
52 * |
|
53 * Cygwin's runtime provides pre-execution hooks which allow you to set |
|
54 * various attributes for the process which effect how the process functions. |
|
55 * One of these attributes controls how files are opened. I've set |
|
56 * it up so that all files opened RDONLY will have the O_TEXT option set, |
|
57 * thus forcing line termination manipulation. This seems to solve the |
|
58 * problem (at least the Test suite runs clean :). |
|
59 * |
|
60 * Note: this may not work in later implementations. This will override |
|
61 * all mode options passed into open(). Cygwin (really Windows) doesn't |
|
62 * support all that much in options, so for now this is OK, but later on |
|
63 * it may not, in which case O_TEXT will have to be added to all opens calls |
|
64 * appropriately. |
|
65 * |
|
66 * This function is actually a hook in the Cygwin runtime which |
|
67 * is called before the main of a program. Because it's part of the program |
|
68 * pre-startup, it must be located in the program main and not in a DLL. |
|
69 * It must also be made an export so the linker resolves this function to |
|
70 * our code instead of the default Cygwin stub routine. |
|
71 */ |
|
72 |
|
73 /**/ |
|
74 #ifdef __CYGWIN__ |
|
75 /**/ |
|
76 mod_export void |
|
77 cygwin_premain0 (int argc, char **argv, void *myself) |
|
78 { |
|
79 static struct __cygwin_perfile pf[] = |
|
80 { |
|
81 {"", O_RDONLY | O_TEXT}, |
|
82 {NULL, 0} |
|
83 }; |
|
84 cygwin_internal (CW_PERFILE, pf); |
|
85 } |
|
86 /**/ |
|
87 #endif /* __CYGWIN__ */ |
|
88 |
|
89 /**/ |
|
90 int |
|
91 main(int argc, char **argv, char** env) |
|
92 { |
|
93 return (zsh_main(argc, argv, env)); |
|
94 } |