Source code of Windows XP (NT5)
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.

68 lines
1.5 KiB

  1. /* readline.c */
  2. #define MAXLINESIZE 256
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7. #include <conio.h>
  8. #define LF 0x0a
  9. #define CR 0x0d
  10. __cdecl main (argc, argv)
  11. int argc;
  12. char *argv[];
  13. {
  14. char line[MAXLINESIZE];
  15. char *prompt = "";
  16. char *formats = "%s\n";
  17. char *formatc = "%c\n";
  18. char inputchar;
  19. FILE *file = stdout;
  20. int argcount = 0;
  21. int getline = 1;
  22. while (++argcount < argc) {
  23. if (!(_stricmp(argv[argcount], "-p"))) {
  24. if (++argcount != argc) {
  25. prompt = argv[argcount];
  26. }
  27. } else if (!(_stricmp(argv[argcount], "-f"))) {
  28. if (++argcount != argc) {
  29. if ((file = fopen(argv[argcount], "a")) == NULL) {
  30. printf("Could not open %s\n", argv[argcount]);
  31. exit(1);
  32. }
  33. }
  34. } else if (!(_stricmp(argv[argcount], "-t"))) {
  35. if (++argcount != argc) {
  36. formats = argv[argcount];
  37. }
  38. } else if (!(_stricmp(argv[argcount], "-c"))) {
  39. getline = 0;
  40. } else {
  41. printf("usage: readline [-c] [-p prompt] [-f file] [-t formats]\n");
  42. exit(2);
  43. }
  44. }
  45. printf("%s", prompt);
  46. if (getline == 1)
  47. gets(line);
  48. else {
  49. inputchar = (char)_getch();
  50. _putch(inputchar);
  51. _putch(LF);
  52. _putch(CR);
  53. }
  54. if (getline == 1)
  55. fprintf(file, formats, line);
  56. else
  57. fprintf(file, formatc, inputchar);
  58. return 0;
  59. }