* libcurses++, libc++ and liblightOS++ are installed into the crosscompiler directory
[lightOS.git] / apps / cat.cpp
blob9013f7561fcdbfca85b0c944de8296bcf21bc2b3
1 /*
2 lightOS application
3 Copyright (C) 2006-2008 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program 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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <iostream>
20 #include <utility>
21 #include <lightOS/lightOS.hpp>
22 using namespace std;
23 using namespace lightOS;
25 #include <stdio.h>
27 void show_stdin()
29 while (true)
31 char buf;
32 if (fread(&buf, 1, 1, stdin) != 1)
33 return;
34 cout << buf;
37 int main(int argc, char **argv)
39 if (argc == 1)show_stdin();
40 else
42 for (int i=1;i < argc;i++)
44 if (strcmp(argv[i], "-") == 0)
45 show_stdin();
46 else
48 file File(argv[i], access::read);
49 if (File)
51 if (File.filetype() == file::block)
53 if (File.blockcount() != 0)
55 size_t size = File.blocksize() * File.blockcount();
56 auto_array<char> data(new char[size+1]);
57 if (File.read(data.get(), 0, size) != size)return -1;
58 data.get()[size] = '\0';
59 cout << data.get();
62 else cerr << "cat: \"" << argv[i] << "\" is not a block file" << endl;
64 else cerr << "cat: could not open the file \"" << argv[i] << "\"" << endl;
68 return 0;