Программа зависает без вывода

Я долго изучал эту программу и понятия не имею, почему она не работает. Я достаточно уверен, что он все делает правильно, но вместо того, чтобы на самом деле работать , он просто зависает на неопределенный срок после печати первого приглашения, и я просто могу ' Я понимаю почему. Я уже почти на грани своего остроумия, поэтому, если кто-нибудь может предположить, что я делаю не так, я был бы очень признателен ...

Это C99, и вам понадобится библиотека mhash для его компиляции ( использует для вычисления CRC32). Он довольно портативен, но я разработал его для Linux. Не запускать в виртуальной машине!

#define _BSD_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <mhash.h>

/* WARNING: Do not debug this program. Halting on breakpoints at the wrong
 * time can be extremely hazardous. YOU HAVE BEEN WARNED. */

/* Structures used to define our layout. Note the careful use of volatile;
 * we don't want the compiler optimising away part of the invocation. */

typedef struct
{
    const char name[7];       /* sigil at focus */
    volatile int target;      /* summoning point */
    volatile char invocation; /* current char of invocation */
} focus_t;

typedef struct node
{
    const char name[4];   /* name of node */
    focus_t* center;      /* points to the evocation focus */
    struct node* cw;      /* clockwise binding ring */
    struct node* ccw;     /* counterclockwise binding ring */
    struct node* star;    /* next node of star */
    const char* linkname; /* name of star linkage */
    volatile uint32_t angel; /* protective angel for this node */
} node_t;

/* The pentacle nodes are circularly linked in both directions to form
 * a binding perimeter. In addition, they are singly linked to form a
 * classic 'daemon trap' five-pointed star. Each node points towards the
 * evocation focus (but not the other way around!) to enforce the geometry
 * we want. The design is based heavily on the Pentagram of Solomon. */

struct
{
    focus_t focus;
    node_t node[5];
}
S =
{
    /* None of the symbols for the pentacle are in Unicode. So we have to make
     * do with Latin transcriptions. */
    .focus = { "SOLUZEN", 0 },
    .node = {
        [0] = { "TE",   &S.focus, &S.node[1], &S.node[4], &S.node[2], "BELLONY" },
        [1] = { "TRA",  &S.focus, &S.node[2], &S.node[0], &S.node[3], "HALLIY" },
        [2] = { "GRAM", &S.focus, &S.node[3], &S.node[1], &S.node[4], "HALLIZA" },
        [3] = { "MA",   &S.focus, &S.node[4], &S.node[2], &S.node[0], "ABDIA" },
        [4] = { "TON",  &S.focus, &S.node[0], &S.node[3], &S.node[1], "BALLATON" }
    }
};

/* Name of spirit to summon --- rot13'd for safety.
 * (#65 from Crowley's translation of SHEMHAMPHORASH.)
 * This is Andrealphus, he that has dominion over menusuration, astronomy and
 * geometry. He seems fairly non-threatening. */

const char spiritname[] = "NAQERNYCUHF";
int rot13(int c) { return 'A' + (((c - 'A') + 13) % 26); }

/* We invoke the following names around the circle as a protective measure.
 * Strictly these should be in Hebrew script, but as the computer is a dumb
 * instrument we're relying on the symbolism rather than the actual literal
 * meaning themselves. Plus, working in RTL is a pain. */

const char* angels[] = {
        "Kether", "Eheieh", "Metatron", "Chaioth ha-Qadesh",
        "Rashith ha-Gilgalim", "Chokmah", "Jah", "Ratziel", "Auphanim",
        "Masloth", "Binah", "Jehovah Elohim", "Tzaphkiel", "Aralim",
        "Shabbathai", "Chesed", "El", "Tzadkiel", "Chasmalim", "Tzadekh",
        "Geburah", "Elohim Gibor", "Khamael", "Seraphim", "Madim",
        "Tiphareth", "Eloah Va-Daath", "Raphael", "Malachim", "Shemesh",
        "Netzach", "Jehovah Sabaoth", "Haniel", "Elohim", "Nogah", "Hod",
        "Elohim Sabaoth", "Michael", "Beni Elohim", "Kokab", "Yesod",
        "Shaddai El Chai", "Gabriel", "Cherubim", "Levanah"
};
const int angelcount = sizeof(angels)/sizeof(*angels);

/* Place the next angel on the pentacle. */

static void updatepentacle()
{
    static int angelnode = 0;
    static int angelindex = 0;

    const char* angel = angels[angelindex++];
    angelindex %= angelcount;

    /* Hash the angel's name to reduce its essence to 32 bits (which lets us
     * copy the angel bodily into the pentacle node. */

    uint32_t angelhash;
    MHASH td = mhash_init(MHASH_CRC32);
    mhash(td, angel, strlen(angel));
    mhash_deinit(td, &angelhash);

    S.node[angelnode].angel = angelhash;
    angelnode = (angelnode + 1) % 5;
}

int main(int argc, const char* argv[])
{
    /* Lock the evocation into memory, to prevent it from being paged out
     * while the spirit has manifested --- which would be bad. */

    int e = mlock(&S, sizeof(S));
    if (e != 0)
    {
        fprintf(stderr, "Unable to lock evocation, refusing to run\n");
        exit(1);
    }

    /* Actually perform the invocation: continually cycle the spirit's
     * name into the evocation focus (while maintaining our pentacle
     * integrity!) until something shows up in the target of the
     * evocation focus. */

    printf("Summoning...\n");
    do
    {
        for (int i = 0; i < sizeof(spiritname)-1; i++)
        {
            S.focus.invocation = rot13(spiritname[i]);
            updatepentacle();
            usleep(100); /* don't CPU-starve our spirit */
        }
    }
    while (S.focus.target == 0);
    printf("Summoning successful! %d\n", S.focus.target);

    /* Our spirit's arrived! Dismiss it immediately by using a null
     * invocation. Keep going until the evocation focus remains empty.
     * FIXME: a particularly mean spirit might find a way to hide. Until
     * we can sort this out, only summon relatively benign ones. This is
     * probably safe anyway, as when the process terminates the spirit's
     * address space will be nuked, taking the spirit with it. */

    printf("Dismissing...\n");
    do
    {
        S.focus.target = 0;
        for (int i = 0; i < 1000; i++)
        {
            S.focus.invocation = 0;
            updatepentacle();
        }
    }
    while (S.focus.target != 0);

    printf("Done.\n");
    return 0;
}

Кстати, не должен ли быть тег goetic ?

Изменить: Извините, я не вернулся раньше --- после Вчера вечером я опубликовал свой запрос, я провел еще несколько тестов, а затем мой компьютер начал издавать забавный запах гари, который не исчезал, когда я его выключал, поэтому я провел остаток ночи, срывая его, пытаясь найти, какая часть неисправна . (Ничего не нашел.) Я собираюсь немного поспать и вернусь к тебе. Спасибо за ответы!

Edit: I ' м размещая это из веб-кафе. Мой дом сгорел. У меня нет времени писать больше, но я должен вас предупредить: не запускайте эту программу ни по какой причине! В самом деле! Без шуток! Надо идти, надо где-нибудь найти убежище ---

Изменить:

13
задан Yu Hao 26 November 2014 в 02:36
поделиться