Mercurial > ~dholland > hg > ag > index.cgi
comparison examples/dsl/redirect.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children | 607e3be6bad8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /***** | |
2 | |
3 AnaGram Programming Examples | |
4 | |
5 A Dos Script Language | |
6 Redirection Class Definition | |
7 | |
8 Copyright 1993 Parsifal Software. All Rights Reserved. | |
9 | |
10 This software is provided 'as-is', without any express or implied | |
11 warranty. In no event will the authors be held liable for any damages | |
12 arising from the use of this software. | |
13 | |
14 Permission is granted to anyone to use this software for any purpose, | |
15 including commercial applications, and to alter it and redistribute it | |
16 freely, subject to the following restrictions: | |
17 | |
18 1. The origin of this software must not be misrepresented; you must not | |
19 claim that you wrote the original software. If you use this software | |
20 in a product, an acknowledgment in the product documentation would be | |
21 appreciated but is not required. | |
22 2. Altered source versions must be plainly marked as such, and must not be | |
23 misrepresented as being the original software. | |
24 3. This notice may not be removed or altered from any source distribution. | |
25 | |
26 *****/ | |
27 | |
28 #ifndef REDIRECT_H | |
29 #define REDIRECT_H | |
30 #include <sys/types.h> | |
31 #include <sys/stat.h> | |
32 #include <stdio.h> | |
33 #include <string.h> | |
34 #include <fcntl.h> | |
35 | |
36 #if defined(__MSDOS__) || defined(__WINDOWS__) | |
37 #include <io.h> | |
38 #else | |
39 #include <unistd.h> | |
40 #include <stdlib.h> | |
41 #define O_TEXT 0 | |
42 #define O_BINARY 0 | |
43 #define tell(fd) lseek(fd, 0, SEEK_CUR) | |
44 /* This is only meant to compile, not run. (Unix) */ | |
45 #define filelength(fd) ((void)(fd), 0) | |
46 #endif | |
47 | |
48 #define STDIN 0 | |
49 #define STDOUT 1 | |
50 #define STDERR 2 | |
51 | |
52 class redirect { | |
53 int handle; // actual handle | |
54 int old_handle; // old handle | |
55 char name[L_tmpnam]; // temporary name, if any | |
56 int copy_flag; // is it live or is it memorex? | |
57 public: | |
58 | |
59 // Constructors | |
60 redirect(int h); | |
61 redirect(int h, char *file_name, int append_flag = 0); | |
62 redirect(redirect &); | |
63 | |
64 // Reset | |
65 friend redirect &reset(redirect &e) { | |
66 lseek(e.handle,0,0); | |
67 return e; | |
68 } | |
69 | |
70 // Destructor | |
71 ~redirect(); | |
72 | |
73 // Save resultant file | |
74 friend char *save_file(redirect &s); | |
75 | |
76 // Extract contents | |
77 friend char *content(redirect &s); | |
78 }; | |
79 | |
80 #endif |