csh and tcsh work

Sources of csh/sh.hist.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
    savehist(sp)
  9. 9
    	struct wordent *sp;
  10. 10
    {
  11. 11
    	register struct Hist *hp, *np;
  12. 12
    	int histlen;
  13. 13
    	register char *cp;
  14. 14
  15. 15
    	cp = value("history");
  16. 16
    	if (*cp == 0)
  17. 17
    		histlen = 0;
  18. 18
    	else {
  19. 19
    		while (*cp && digit(*cp))
  20. 20
    			cp++;
  21. 21
    		/* avoid a looping snafu */
  22. 22
    		if (*cp)
  23. 23
    			set("history", "10");
  24. 24
    		histlen = getn(value("history"));
  25. 25
    	}
  26. 26
    	/* throw away null lines */
  27. 27
    	if (sp->next->word[0] == '\n')
  28. 28
    		return;
  29. 29
    	for (hp = &Histlist; np = hp->Hnext;)
  30. 30
    		if (eventno - np->Href >= histlen || histlen == 0)
  31. 31
    			hp->Hnext = np->Hnext, hfree(np);
  32. 32
    		else
  33. 33
    			hp = np;
  34. 34
    	enthist(++eventno, sp, 1);
  35. 35
    }
  36. 36
  37. 37
    struct Hist *
  38. 38
    enthist(event, lp, docopy)
  39. 39
    	int event;
  40. 40
    	register struct wordent *lp;
  41. 41
    	bool docopy;
  42. 42
    {
  43. 43
    	register struct Hist *np;
  44. 44
  45. 45
    	np = (struct Hist *) calloc(1, sizeof *np);
  46. 46
    	np->Hnum = np->Href = event;
  47. 47
    	if (docopy)
  48. 48
    		copylex(&np->Hlex, lp);
  49. 49
    	else {
  50. 50
    		np->Hlex.next = lp->next;
  51. 51
    		lp->next->prev = &np->Hlex;
  52. 52
    		np->Hlex.prev = lp->prev;
  53. 53
    		lp->prev->next = &np->Hlex;
  54. 54
    	}
  55. 55
    	np->Hnext = Histlist.Hnext;
  56. 56
    	Histlist.Hnext = np;
  57. 57
    	return (np);
  58. 58
    }
  59. 59
  60. 60
    hfree(hp)
  61. 61
    	register struct Hist *hp;
  62. 62
    {
  63. 63
  64. 64
    	freelex(&hp->Hlex);
  65. 65
    	xfree(hp);
  66. 66
    }
  67. 67
  68. 68
    dohist()
  69. 69
    {
  70. 70
  71. 71
    	if (getn(value("history")) == 0)
  72. 72
    		return;
  73. 73
    	dohist1(Histlist.Hnext);
  74. 74
    }
  75. 75
  76. 76
    dohist1(hp)
  77. 77
    	register struct Hist *hp;
  78. 78
    {
  79. 79
  80. 80
    	if (hp == 0)
  81. 81
    		return;
  82. 82
    	hp->Href++;
  83. 83
    	dohist1(hp->Hnext);
  84. 84
    	phist(hp);
  85. 85
    }
  86. 86
  87. 87
    phist(hp)
  88. 88
    	register struct Hist *hp;
  89. 89
    {
  90. 90
  91. 91
    	printf("%6d\t", hp->Hnum);
  92. 92
    	prlex(&hp->Hlex);
  93. 93
    }

To the top of this page