Merge from vendor branch DIFFUTILS:
[dragonfly.git] / contrib / libio / PlotFile.cc
1 /* 
2 Copyright (C) 1993 Free Software Foundation
3
4 This file is part of the GNU IO Library.  This library is free
5 software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING.  If not, write to the Free
17 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does not cause
21 the resulting executable to be covered by the GNU General Public License.
22 This exception does not however invalidate any other reasons why
23 the executable file might be covered by the GNU General Public License. */
24
25 // This may look like C code, but it is really -*- C++ -*-
26 /* 
27 Copyright (C) 1988, 1992, 1993 Free Software Foundation
28     written by Doug Lea (dl@rocky.oswego.edu)
29     converted to use iostream library by Per Bothner (bothner@cygnus.com)
30
31 This file is part of the GNU IO Library.  This library is free
32 software; you can redistribute it and/or modify it under the
33 terms of the GNU General Public License as published by the
34 Free Software Foundation; either version 2, or (at your option)
35 any later version.
36
37 This library is distributed in the hope that it will be useful,
38 but WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40 GNU General Public License for more details.
41
42 You should have received a copy of the GNU General Public License
43 along with this library; see the file COPYING.  If not, write to the Free
44 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
45
46 As a special exception, if you link this library with files
47 compiled with GCC to produce an executable, this does not cause
48 the resulting executable to be covered by the GNU General Public License.
49 This exception does not however invalidate any other reasons why
50 the executable file might be covered by the GNU General Public License.  */
51
52 #ifdef __GNUG__
53 #pragma implementation
54 #endif
55 #include <PlotFile.h>
56
57 /*
58  PlotFile implementation module
59 */
60
61
62 PlotFile& PlotFile:: cmd(char c)
63
64   ofstream::put(c); 
65   return *this; 
66 }
67
68 PlotFile& PlotFile:: operator<<(const int x)
69
70 #if defined(convex)
71   ofstream::put((char)(x>>8)); 
72   ofstream::put((char)(x&0377)); 
73 #else
74   ofstream::put((char)(x&0377)); 
75   ofstream::put((char)(x>>8)); 
76 #endif
77   return *this; 
78 }
79
80 PlotFile& PlotFile:: operator<<(const char *s)
81
82   *(ofstream*)this << s;
83   return *this;
84 }
85
86
87 PlotFile& PlotFile:: arc(const int xi, const int yi,
88                          const int x0, const int y0,
89                          const int x1, const int y1)
90
91   return cmd('a') << xi << yi << x0 << y0 << x1 << y1; 
92 }
93
94
95 PlotFile& PlotFile:: box(const int x0, const int y0,
96                          const int x1, const int y1)
97
98   line(x0, y0, x0, y1);
99   line(x0, y1, x1, y1);
100   line(x1, y1, x1, y0);
101   return line(x1, y0, x0, y0);
102 }
103
104 PlotFile& PlotFile:: circle(const int x, const int y, const int r)
105
106   return cmd('c') << x << y << r; 
107 }
108
109 PlotFile& PlotFile:: cont(const int xi, const int yi)
110
111   return cmd('n') << xi << yi;
112 }
113
114 PlotFile& PlotFile:: dot(const int xi, const int yi, const int dx,
115                          int n, const int* pat)
116
117   cmd('d') << xi << yi << dx << n;
118   while (n-- > 0) *this << *pat++;
119   return *this; 
120 }
121
122 PlotFile& PlotFile:: erase()
123
124   return cmd('e'); 
125 }
126
127 PlotFile& PlotFile:: label(const char* s)
128
129   return cmd('t') << s << "\n"; 
130 }
131
132 PlotFile& PlotFile:: line(const int x0, const int y0,
133                           const int x1, const int y1)
134
135   return cmd('l') << x0 << y0 << x1 << y1; 
136 }
137
138 PlotFile& PlotFile:: linemod(const char* s)
139
140   return cmd('f') << s << "\n"; 
141 }
142
143 PlotFile& PlotFile:: move(const int xi, const int yi)
144
145   return cmd('m') << xi << yi;
146 }
147
148 PlotFile& PlotFile:: point(const int xi, const int yi)
149
150   return cmd('p') << xi << yi; 
151 }
152
153 PlotFile& PlotFile:: space(const int x0, const int y0,
154                            const int x1, const int y1)
155
156   return cmd('s') << x0 << y0 << x1 << y1; 
157 }