OpenSDE Framework (without history before r20070)
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.

82 lines
2.7 KiB

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