csh and tcsh work

Sources of csh/sh.print.c

csh と tcsh のソース

Bill Joy

First published: October, 1978.

Copyright © 1979 Regents of the University of California.

  1. 1
    /* Copyright (c) 1979 Regents of the University of California */
  2. 2
    #include "sh.h"
  3. 3
  4. 4
    /*
  5. 5
     * C Shell
  6. 6
     */
  7. 7
  8. 8
    p60ths(l)
  9. 9
    	long l;
  10. 10
    {
  11. 11
  12. 12
    	l += 3;
  13. 13
    	printf("%d.%d", (int) (l / 60), (int) ((l % 60) / 6));
  14. 14
    }
  15. 15
  16. 16
    psecs(l)
  17. 17
    	long l;
  18. 18
    {
  19. 19
    	register int i;
  20. 20
  21. 21
    	i = l / 3600;
  22. 22
    	if (i) {
  23. 23
    		printf("%d:", i);
  24. 24
    		i = l % 3600;
  25. 25
    		p2dig(i / 60);
  26. 26
    		goto minsec;
  27. 27
    	}
  28. 28
    	i = l;
  29. 29
    	printf("%d", i / 60);
  30. 30
    minsec:
  31. 31
    	i %= 60;
  32. 32
    	printf(":");
  33. 33
    	p2dig(i);
  34. 34
    }
  35. 35
  36. 36
    p2dig(i)
  37. 37
    	register int i;
  38. 38
    {
  39. 39
  40. 40
    	printf("%d%d", i / 10, i % 10);
  41. 41
    }
  42. 42
  43. 43
    char	linbuf[64];
  44. 44
    char	*linp = linbuf;
  45. 45
  46. 46
    putchar(c)
  47. 47
    	register int c;
  48. 48
    {
  49. 49
  50. 50
    	if ((c & QUOTE) == 0 && (c == 0177 || c < ' ' && c != '\t' && c != '\n')) {
  51. 51
    		putchar('^');
  52. 52
    		if (c == 0177)
  53. 53
    			c = '?';
  54. 54
    		else
  55. 55
    			c |= 'A' - 1;
  56. 56
    	}
  57. 57
    	c &= TRIM;
  58. 58
    	*linp++ = c;
  59. 59
    	if (c == '\n' || linp >= &linbuf[sizeof linbuf - 2])
  60. 60
    		flush();
  61. 61
    }
  62. 62
  63. 63
    draino()
  64. 64
    {
  65. 65
  66. 66
    	linp = linbuf;
  67. 67
    }
  68. 68
  69. 69
    flush()
  70. 70
    {
  71. 71
    	register int unit;
  72. 72
  73. 73
    	if (haderr)
  74. 74
    		unit = didfds ? 2 : SHDIAG;
  75. 75
    	else
  76. 76
    		unit = didfds ? 1 : SHOUT;
  77. 77
    	if (linp != linbuf) {
  78. 78
    		write(unit, linbuf, linp - linbuf);
  79. 79
    		linp = linbuf;
  80. 80
    	}
  81. 81
    }
  82. 82
  83. 83
    plist(vp)
  84. 84
    	register struct varent *vp;
  85. 85
    {
  86. 86
    	register int (*wasintr)();
  87. 87
  88. 88
    	if (setintr)
  89. 89
    		wasintr = signal(SIGINT, pintr);
  90. 90
    	for (vp = vp->link; vp != 0; vp = vp->link) {
  91. 91
    		int len = blklen(vp->vec);
  92. 92
  93. 93
    		printf(vp->name);
  94. 94
    		printf("\t");
  95. 95
    		if (len != 1)
  96. 96
    			putchar('(');
  97. 97
    		blkpr(vp->vec);
  98. 98
    		if (len != 1)
  99. 99
    			putchar(')');
  100. 100
    		printf("\n");
  101. 101
    	}
  102. 102
    	if (setintr)
  103. 103
    		signal(SIGINT, wasintr);
  104. 104
    }

To the top of this page