Няшная / Говнокод #27407 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
// https://github.com/sergev/bkunix/blob/master/src/bin/pwd.c
void
cat(name)
	char *name;
{
	register int i, j;

	i = -1;
	while (name[++i] != 0);
	if ((off+i+2) > 511) {
		write(2, "pwd: too long path\n", 19);
		exit(1);
	}
	for (j=off+1; j>=0; --j)
		path[j+i+1] = path[j];
	off=i+off+1;
	path[i] = '/';
	for (--i; i>=0; --i)
		path[i] = name[i];
}

char * ckroot(dev, ino)
int dev, ino;
{
	DIR * dir;
	struct stat st;
	register struct dirent * d;
	chdir("/");
	dir = opendir("/");
	do {
		d = readdir(dir);
		if (! d) {
			return "[mount point]";
		}
		stat(d->d_name, &st);
	} while (st.st_dev != dev || st.st_ino != ino);
	closedir(dir);
	return d->d_name;
}

int
main()
{
	int rdev, rino;
	DIR *dir;
	struct stat dot, dotdot;
	register struct dirent *d;

	stat("/", &dot);
	rdev = dot.st_dev;
	rino = dot.st_ino;
/*printf ("/ dev=%d ino=%d\n", rdev, (int) rino);*/
	for (;;) {
		stat(".", &dot);
/*printf (". dev=%d ino=%d\n", (int) dot.st_dev, (int) dot.st_ino);*/
		if (dot.st_ino == rino && dot.st_dev == rdev)
			break;
		dir = opendir("..");
		if (! dir) {
			write(2, "pwd: cannot open ..\n", 20);
			return 1;
		}
		stat("..", &dotdot);
/*printf (".. dev=%d ino=%d\n", (int) dotdot.st_dev, (int) dotdot.st_ino);*/
		chdir("..");
		if (dot.st_dev == dotdot.st_dev) {
			if (dot.st_ino == dotdot.st_ino) {
				cat(ckroot(dot.st_dev, dot.st_ino));
				break;
			}
			do {
				d = readdir(dir);
				if (! d) {
					write(2, "read error in ..\n", 17);
					return 1;
				}
			} while (d->d_ino != dot.st_ino);
		} else {
			do {
				d = readdir(dir);
				if (! d) {
					write(2, "read error in ..\n", 17);
					return 1;
				}
				stat(d->d_name, &dotdot);
/*printf ("%.14s dev=%d ino=%d\n", d->d_name, (int) dotdot.st_dev, (int) dotdot.st_ino);*/
			} while (dotdot.st_ino != dot.st_ino ||
				dotdot.st_dev != dot.st_dev);
		}
		closedir(dir);
		cat(d->d_name);
/*path[off] = 0; printf ("pwd %s\n", path);*/
	}
	write(1, "/", 1);
	if (off < 0)
		off = 0;
	path[off] = '\n';
	write(1, path, off + 1);
	return 0;
}

какой pwd )))

Запостил: j123123 j123123, (Updated )

Комментарии (15) RSS

  • Если нет getcwd, надо в цикле делать chdir("..") пока не дойдем до корня, а потом всю питушню состыковать
    Ответить
    • > Если нет getcwd

      А почему его нет? Какая-то необычная эмбеддед ось?
      Ответить
      • Да, эмбеддед ось для БК-0010
        https://ru.wikipedia.org/wiki/Операционные_системы_БК-0010/11#BKUNIX

        https://github.com/sergev/bkunix/

        .
        		BKUNIX - what could have been...
        
        Starting from the mid-1980s in the USSR a home microcomputer BK-0010
        was produced that used the instruction set of DEC LSI-11.
        Its first version, released in 1985, had 32 Kb of RAM, out of which
        up to 16 Kb had to be reserved for the video memory.
        A tape recorder was the external storage device. A great variety of games,
        educational and text processing software, as well as a few programming
        systems have been written for it.
        
        ...
        
        After learning about the existence of Mini-Unix and LSX - the minimalistic
        Unix kernels derived from Unix V6, and reviving the latter from an incomplete
        floppy image dump, I realized that it could have been possible to run a real
        Unix on BK-0010! Indeed, LSX in its minimal configuration required only 40 Kb
        of RAM, and a BK with a floppy controller could provide up to 44 Kb.
        
        As all the LSX and Mini-Unix sources were written in an ancient dialect of the
        C language (no unsigned, void, long; weird - by today's standards - syntax
        of assignment operators and initializations), the first step was to patch
        the source to conform to the newer style of C. An initial attempt to use
        GCC for cross-development failed: it produced a buggy and size-inefficient
        code. We have settled on using the Ritchie C compiler from a BSD distribution
        and the Johnson Portable C compiler (PCC). In the process, quite a few bugs
        in PCC got fixed.
        Ответить
        • >https://www.mailcom.com/lsx/index.html
          блядь, реально чтоли эмуль поставть и запидролица?
          >Most importantly, on Unix V6, it's not cd, it's chdir!
          хи

          А какой там редактор? ed?
          Ответить
            • ого, регистр букв это свойство подсистемы терминалов:)

              Не, в ed я должно не просижу. vi вроде изобрели примерно в том же году, но в BSD, а не в самом unix
              Ответить
  • иногда мне кажется если бы не придумали java - то люди бы сих пор не научились бы программировать
    Ответить
  • > //

    Ого, думал в Си так незя
    Ответить
    • В том древнеСи так действительно было нельзя. Это только в C99 появилось и пришло из крестов
      Ответить
      • Ты доволен, или хуйня ненужная?
        Ответить
        • Удобно. Но я и так бы обошелся. Это далеко не самая нужная фича
          Ответить

Добавить комментарий

Из-за тебя ушел bormand, guest!

    А не использовать ли нам bbcode?


    8