echo.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %
  4. % File: PXK:ECHO.C
  5. % Description: Handle raw/cooked terminal I/O, get homedir info
  6. % Author: Russ Fish
  7. % Created: 2 March 1982
  8. % Modified:
  9. % Mode: Text
  10. % Package:
  11. % Status: Open Source: BSD License
  12. % Copyright 1983, Hewlett-Packard Company, see the file
  13. % HP_disclaimer at the root of the PSL file tree
  14. %
  15. % Redistribution and use in source and binary forms, with or without
  16. % modification, are permitted provided that the following conditions are met:
  17. %
  18. % * Redistributions of source code must retain the relevant copyright
  19. % notice, this list of conditions and the following disclaimer.
  20. % * Redistributions in binary form must reproduce the above copyright
  21. % notice, this list of conditions and the following disclaimer in the
  22. % documentation and/or other materials provided with the distribution.
  23. %
  24. % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26. % THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27. % PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNERS OR
  28. % CONTRIBUTORS
  29. % BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. % POSSIBILITY OF SUCH DAMAGE.
  36. %
  37. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  38. */
  39. /*
  40. * There used to be a collection of comments here describing revisions
  41. * made from about 1982 to 1989. I think those are by now of interest
  42. * to archaeologists! So anybody who wants to see them can consult older
  43. * copies of this file in the repositories. It is neverthless proper to
  44. * record the names of those who (in addition to the original author)
  45. * have contributed:
  46. * Leight Stoller
  47. */
  48. #include <stdio.h>
  49. #ifndef __WIN64__
  50. #include <sys/ioctl.h>
  51. #include <pwd.h>
  52. #endif
  53. #include "psl.h"
  54. /*
  55. * The functions here are (just) called from compiled code. In the
  56. * assembly code for the kernel the code is written with the names
  57. * having a leading underscore. For Linux that underscore remains
  58. * visible here in the C code that is linked to, while under Cygwin
  59. * or on a Macintosh it is not. So here I define functions whose names
  60. * have leading underscores if I am on Linux but not otherwise. This is
  61. * a bit messy and ugly but is still about the neatest I can think of
  62. * at present if I want one body of code to apply everywhere.
  63. */
  64. #if defined __linux__ || defined __CYGWIN__
  65. #define _(x) _ ## x
  66. #else
  67. #define _(x) x
  68. #endif
  69. /* TAG( EchoOff )
  70. * Enter character-at-a-time mode.
  71. */
  72. void _(echooff)() /* (Note names lowercased by PSL compiler... */
  73. {
  74. }
  75. /* TAG( EchoOn )
  76. * Re-enter line I/O mode.
  77. */
  78. void _(echoon)()
  79. {
  80. }
  81. /* TAG( External_CharsInInputBuffer )
  82. * Return number of characters in input buffer.
  83. */
  84. void _(external_charsininputbuffer)(FILE *fp)
  85. {
  86. }
  87. /* TAG( FlushStdOutputBuffer )
  88. * Clear out buffer, when in EchoOff mode.
  89. */
  90. void _(flushstdoutputbuffer)()
  91. { fflush( stdout );
  92. }
  93. int getuid();
  94. struct passwd *getpwuid(), *getpwnam();
  95. char *_(external_user_homedir_string)()
  96. { struct passwd *ptr;
  97. if ((ptr = getpwuid(getuid())) != NULL)
  98. return(ptr->pw_dir);
  99. else
  100. { fprintf(stderr, "Error in external_user_homedir_string()\n");
  101. return ("");
  102. }
  103. }
  104. char *_(external_anyuser_homedir_string)(const char *username)
  105. { struct passwd *ptr;
  106. if ((ptr = getpwnam(username)) != NULL) return(ptr -> pw_dir);
  107. else return "";
  108. }
  109. void _(pppprofil)(int u)
  110. {}
  111. /* end of echo.c */