mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.0 KiB

  1. /* ccat (counting cat)
  2. *
  3. * --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. *
  5. * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. * Please add additional copyright information _after_ the line containing
  7. * the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. * the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. *
  10. * ROCK Linux: rock-src/misc/archive/ccat.c
  11. * ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version. A copy of the GNU General Public
  17. * License can be found at Documentation/COPYING.
  18. *
  19. * Many people helped and are helping developing ROCK Linux. Please
  20. * have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. * file for details.
  22. *
  23. * --- ROCK-COPYRIGHT-NOTE-END ---
  24. */
  25. #define VERSION "2000-06-15"
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <errno.h>
  29. int main(int argc) {
  30. char s1[]="................................"
  31. "................................";
  32. char buf[10240];
  33. int c,rc1,rc2;
  34. if (argc != 1) {
  35. fprintf(stderr,
  36. "ccat (counting cat) Version " VERSION "\n"
  37. "Copyright (C) 2000 Clifford Wolf, Thomas Baumgartner\n"
  38. "\n"
  39. " This program is free software; you can redistribute it and/or modify\n"
  40. " it under the terms of the GNU General Public License as published by\n"
  41. " the Free Software Foundation; either version 2 of the License, or\n"
  42. " (at your option) any later version.\n"
  43. "\n"
  44. " This program is distributed in the hope that it will be useful,\n"
  45. " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  46. " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
  47. " GNU General Public License for more details.\n"
  48. "\n"
  49. " You should have received a copy of the GNU General Public License\n"
  50. " along with this program; if not, write to the Free Software\n"
  51. " Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"
  52. "\n"
  53. "Usage: `ccat' reads from its stdin and writes to stdout. No command line\n"
  54. " arguments ar allowed. A status bar is printed to stderr.\n\n"
  55. ); fflush(stderr);
  56. return 1;
  57. }
  58. c=1024; rc1=rc2=0;
  59. while (1) {
  60. if (c%1024 == 0) {
  61. fprintf(stderr,"\r%6d0 MB [%s]\r%6d0 MB [",
  62. c/1024,s1,c/1024); fflush(stderr);
  63. }
  64. if ( (rc1=read(0,buf,10240)) <= 0 ) { rc2=rc1; break; }
  65. if (c%16 == 0) {
  66. fprintf(stderr,"X"); fflush(stderr);
  67. }
  68. if ( (rc2=write(1,buf,rc1)) != rc1 ) break;
  69. c++;
  70. }
  71. if (rc1 == -1) {
  72. fprintf(stderr,"\nRead ERROR: %s\n",strerror(errno));
  73. } else if (rc2 == -1) {
  74. fprintf(stderr,"\nWrite ERROR: %s\n",strerror(errno));
  75. } else if (rc2 != rc1) {
  76. fprintf(stderr,"\nWrite ERROR: Only %d of %d bytes "
  77. "in the last block has been written.\n",rc2,rc1);
  78. } else
  79. fprintf(stderr,"\n");
  80. return 0;
  81. }