#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  ddli.c fpdio.c qst.c strdup.c
# Wrapped by fdnh@troi.cc.rochester.edu on Sat Dec 11 19:40:52 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'ddli.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ddli.c'\"
else
echo shar: Extracting \"'ddli.c'\" \(9375 characters\)
sed "s/^X//" >'ddli.c' <<'END_OF_FILE'
X/*
X *  ddli.c
X *  The Duniho and Duniho Life Pattern Indicator
X *  by Fergus Duniho
X *  Copyright (c) 1992, 1993 Fergus Duniho
X */
X
X#define VER "V3.00"
X#define EMAIL "fdnh@troi.cc.rochester.edu"
X
X#define AMIGA 1
X#define MSDOS 2
X#define OTHER 3
X
X#define OPSYS OTHER
X
X#if OPSYS == AMIGA
X    #define prtdev "PRT:"
X    #define FILE_NAME_MAX 32
X#elif OPSYS == MSDOS
X    #define prtdev "PRN"
X    #define FILE_NAME_MAX 8
X#elif OPSYS == OTHER
X    #define prtdev ""
X    #define FILE_NAME_MAX 16
X#else
X    #error OPERATING SYSTEM UNKNOWN
X#endif
X
X/*
X * If your compiler does not have the command "strdup",
X * which is common in C compilers but not part of ANSI
X * C, uncomment the next #include statement.
X */
X/* #include "strdup.c" */
X
X#include "fpdio.c"
X#include "qst.c"
X#include <time.h>
X
X#define XN E ? "Extraverted" : "Introverted"
X#define QFILE "DDLI.QST"
X
Xmain () {
X    int i, col, size, found, A, pr[14], x,
X        E, I, S, N, T, F, J, P, ES, EN, ET, EF, R;
X    char line[256], nline[512], *type, *name, *fname, *Version,
X         LP[5], LPE[5], LPI[5],
X         *PF[2] = {"Intuition", "Sensing"},
X         *JF[2] = {"Thinking", "Feeling"},
X         *text1 = "Your %s function is %s %s.";
X    FILE *fptr;
X    qst *Q;
X
X#if OPSYS == MSDOS
X    col = 75;
X#else
X    wrapwrite (stdout, 0, 0, 20, "How many columns does your screen have?", 0);
X    col = fgetp(stdin);
X#endif
X
X    wrapwrite (stdout, 0, 0, col,
X        "\n\"The Duniho and Duniho Life Pattern Indicator\"",
X        VER, "\nBy Fergus Duniho. Copyright (c) 1992, 1993",
X        "Fergus Duniho.\n\nMost of the questions are drawn from",
X        "and based on those in Terence Duniho's \"Preference",
X        "Patterns Questionaire\" and his book _Wholeness Lies",
X        "Within_. Fergus is responsible for the choice of questions.",
X        "\n\nThis product is freeware. Send comments, bug reports,",
X        "reports on accuracy, and suggestions for improvement to",
X        "Fergus Duniho at the following address:\n\n", EMAIL, 0);
X
X    size = Linefeeds(QFILE) / 3;
X    Q = new_qnode(0);
X    Q->pv = Q->nx = Q;
X    Version = Get_QList (QFILE, Q, size);
X
X    wrapwrite (stdout, 0, 0, col, "\nWhat is your name?", 0);
X    name = clone_line(stdin, 80);
X
X#ifdef DEBUG
X    wrapwrite (stdout, 0, 0, col,
X        "Enter an integer as a seed value for the random # generator", 0);
X    srand (fgetp(stdin));
X#else
X    srand (clock());
X#endif
X
X    Q = RND_QList (Q, size);
X    AskQuestions (Q, col);
X    for (i = 0; i < 14; i++) /* Initializes Preference Scores to Zero */
X        pr[i] = 0;
X    for (Q = Q->nx; Q->num > 0; Q = Q->nx) /* Calculates Scores */
X        pr[Q->ans] += Q->strength;
X
X#if OPSYS == OTHER
X    wrapwrite (stdout, 0, 0, col,
X        "Send output to (1) Screen or (2) File?", 0);
X#else
X    wrapwrite (stdout, 0, 0, col,
X        "Send output to (1) Screen, (2) File or (3) Printer?", 0);
X#endif
X    do {
X        A = fgetp(stdin);
X        if (A == 1)
X            fptr = stdout;
X        else if (A == 2) {
X            wrapwrite (stdout, 0, 0, col, "Please enter a file name.", 0);
X            fname = clone_line(stdin, FILE_NAME_MAX);
X            WrOpen (fptr, fname);
X        }
X#if OPSYS != OTHER
X        else if (A == 3) {
X            WrOpen (fptr, prtdev);
X            col = 75;
X        }
X#endif
X        else
X#if OPSYS == OTHER
X            wrapwrite (stdout, 0, 0, col, "Please enter a 1 or a 2.", 0);
X#else
X            wrapwrite (stdout, 0, 0, col,
X                "Please enter a 1, a 2, or a 3.", 0);
X#endif
X    } while (A < 1 || A > 3);
X
X    E = pr[1]; I = pr[2]; S = pr[3]; N = pr[4];
X    T = pr[5]; F = pr[6]; J = pr[7]; P = pr[8];
X    ES = pr[12]; EN = pr[13]; ET = pr[11]; EF = pr[10];
X    sprintf (nline, "%s's scores on the main set of questions:\n"
X                    "\nExtraversion (E): %2d    %2d :(I) Introversion"
X                    "\nSensing      (S): %2d    %2d :(N) iNtuition"
X                    "\nThinking     (T): %2d    %2d :(F) Feeling"
X                    "\nJudging      (J): %2d    %2d :(P) Preceiving\n",
X                    name, E, I, S, N, T, F, J, P);
X    wrapwrite (fptr, 0, 0, col, nline, 0);
X
X    /* Calculates possible life pattern based on primary scores. */
X    LP[0] = (E > I) ? 'E' : (E < I) ? 'I' : 'X';
X    LP[1] = (S > N) ? 'S' : (S < N) ? 'N' : 'X';
X    LP[2] = (T > F) ? 'T' : (T < F) ? 'F' : 'X';
X    LP[3] = (J > P) ? 'J' : (J < P) ? 'P' : 'X';
X    LP[4] = 0;
X
X    fprintf (fptr, "You scored as an %s.\n", LP);
X    x = 0;
X    for (i = 0; i < 4; i++)
X        if (LP[i] == 'X')
X            x++;
X    if (x) {
X        sprintf (line, "This is not a real type. You could be any of"
X        "%d different types. Read the type descriptions to determine "
X        "which you are.", pow(2,x));
X        wrapwrite (fptr, 0, 0, col, line, 0);
X    }
X    else {
X        E = (LP[0] == 'E'); R = ((LP[3] == 'J') == E);
X        sprintf (line, "\nAssuming that you are an %s,\n", LP);
X        wrapwrite (fptr, 0, 5, col, line, 0);
X        sprintf (line, text1, "DOMINANT", XN, R ? JF[LP[2] == 'F'] : PF[LP[1] == 'S']);
X        wrapwrite (fptr, 0, 5, col, line, 0);
X        sprintf (line, text1, "AUXILIARY", !XN, R ? PF[LP[1] == 'S'] : JF[LP[2] == 'F']);
X        wrapwrite (fptr, 0, 5, col, line, 0);
X        sprintf (line, text1, "TERTIARY", XN, R ? PF[LP[1] == 'N'] : JF[LP[2] == 'T']);
X        wrapwrite (fptr, 0, 5, col, line, 0);
X        sprintf (line, text1, "INFERIOR", !XN, R ? JF[LP[2] == 'T'] : PF[LP[1] == 'N']);
X        wrapwrite (fptr, 0, 5, col, line, 0);
X    }
X    if (A == 1) {
X        wrapwrite (stdout, 0, 0, col, "Hit <ENTER> or <RETURN> to see",
X            "your results on the supplementary questions.", 0);
X        while (fgetc(stdin) != '\n');
X    }
X    sprintf (nline, "\n%s's scores on the supplementary questions:\n\n"
X    "Extraverted Thinking / Introverted Feeling   : %d\n"
X    "Extraverted Feeling / Introverted Thinking   : %d\n\n"
X    "Extraverted Intuition / Introverted Sensing  : %d\n"
X    "Extraverted Sensing / Introverted Intuition  : %d\n\n"
X    "Rationality (Dominant Judging Function)      : %d\n"
X    "A-rationality (Dominant Perceiving Function) : %d\n\n",
X        name, ET, EF, EN, ES, pr[9], pr[0]);
X    wrapwrite (fptr, 0, 0, col, nline, 0);
X
X    /* Calculates possible life patterns based on supplemental scores. */
X    LPE[0] = 'E'; LPI[0] = 'I';
X    if (pr[9] > pr[0]) {
X        LPE[3] = 'J';
X        LPI[3] = 'P';
X    }
X    else if (pr[9] < pr[0]) {
X        LPE[3] = 'P';
X        LPI[3] = 'J';
X    }
X    else {
X        LPE[3] = 'X';
X        LPI[3] = 'X';
X    }
X    if (LPE[3] == 'P') {
X        if (EF > ET) {
X            LPE[2] = 'T';
X            LPI[2] = 'F';
X        }
X        else if (EF < ET) {
X            LPE[2] = 'F';
X            LPI[2] = 'T';
X        }
X        else {
X            LPE[2] = 'X';
X            LPI[2] = 'X';
X        }
X        if (ES < EN) {
X            LPE[1] = 'N';
X            LPI[1] = 'S';
X        }
X        else if (ES > EN) {
X            LPE[1] = 'S';
X            LPI[1] = 'N';
X        }
X        else {
X            LPE[1] = 'X';
X            LPI[1] = 'X';
X        }
X    }
X    else if (LPE[3] == 'J') {
X        if (EF < ET) {
X            LPE[2] = 'T';
X            LPI[2] = 'F';
X        }
X        else if (EF > ET) {
X            LPE[2] = 'F';
X            LPI[2] = 'T';
X        }
X        else {
X            LPE[2] = 'X';
X            LPI[2] = 'X';
X        }
X        if (ES > EN) {
X            LPE[1] = 'N';
X            LPI[1] = 'S';
X        }
X        else if (ES < EN) {
X            LPE[1] = 'S';
X            LPI[1] = 'N';
X        }
X        else {
X            LPE[1] = 'X';
X            LPI[1] = 'X';
X        }
X    }
X    else {
X        LPE[1] = 'X';
X        LPE[2] = 'X';
X        LPI[1] = 'X';
X        LPI[2] = 'X';
X    }
X    LPE[4] = LPI[4] = 0;
X
X    sprintf (line, "According to the supplementary scores, %s could be "
X    "an %s or an %s.", name, LPE, LPI);
X    if ((strcmp(LP, LPE) == 0) || (strcmp(LP, LPI) == 0))
X        sprintf (nline, "%s These results corroborate your score as an %s.", line, LP);
X    else
X        sprintf (nline, "%s These results conflict with the evaluation of %s as an %s.", line, name, LP);
X    wrapwrite (fptr, 5, 0, col, nline, "\n\n", 0);
X    if (fptr != stdout)
X        fclose (fptr);
X
X    wrapwrite (stdout, 5, 0, col, "With your permission, this program will",
X        "now record your raw scores in a file. To further the reliability",
X        "of this program, I would like you to save a copy of this record",
X        "and email it to me at", EMAIL, "through the Internet, or",
X        "through my personal email account on the FileWorks BBS in",
X        "Rochester, NY. Do you give this program your permission to",
X        "save this record? (y/n)", 0);
X
X    if (yesno() == 1) {
X        wrapwrite (stdout, 0, 0, col, "What will you name this file?\n", 0);
X        free (fname);
X        fname = clone_line(stdin, FILE_NAME_MAX);
X        wrapwrite (stdout, 0, 0, col,
X            "What is your psychological type?\n", 0);
X        type = clone_line(stdin, 4);
X        printf ("\nSending raw scores to \"%s\".\n", fname);
X        WrOpen (fptr, fname);
X        fprintf (fptr, "%s\n%s\n", Version, type);
X        for (Q = Q->nx; Q->num > 0; Q = Q->nx)
X            fprintf (fptr, "%d %d %d\n", Q->num, Q->ans, Q->strength);
X        fclose (fptr);
X    }
X}
X
Xint pow (x, y) {
X    if (y < 1)
X        return 1;
X    if (y = 1)
X        return x;
X    return x * pow(x, y-1);
X}
END_OF_FILE
if test 9375 -ne `wc -c <'ddli.c'`; then
    echo shar: \"'ddli.c'\" unpacked with wrong size!
fi
# end of 'ddli.c'
fi
if test -f 'fpdio.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fpdio.c'\"
else
echo shar: Extracting \"'fpdio.c'\" \(3275 characters\)
sed "s/^X//" >'fpdio.c' <<'END_OF_FILE'
X/* FPDIO.C Copyright (C) 1993 Fergus Patrick Duniho */
X
X#ifndef _FPDIO_C
X#define _FPDIO_C
X
X#include <ctype.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <stdarg.h>
X
X#define RdOpen(X,Y) X=FDOpen(Y, "r")
X#define WrOpen(X,Y) X=FDOpen(Y, "w")
X#define ApOpen(X,Y) X=FDOpen(Y, "a")
X
Xvoid wrapwrite (FILE *fptr, int ind, int lm, int rm, char *s, ...);
Xint wrdlen(char *s);
Xint fgetp (FILE *fptr);
XFILE *FDOpen (const char *fn, const char *mode);
Xint Linefeeds (char *fname);
Xchar *clone_line (FILE *fptr, int max);
Xint yesno ();
X
Xvoid wrapwrite (FILE *fptr, int ind, int lm, int rm, char *s, ...) {
X    va_list ap;
X    int i, j, l;
X
X    va_start(ap, s);
X    for (j = ind; ; j = lm) {
X        for (i = 0; i < j; i++)
X            fputc (' ', fptr);
X        for (i = j; i < rm; i++)
X            switch (*s) {
X                case 0:     /* End of string reached */
X                    if ((s = va_arg(ap, char *)) == 0) {
X                        fputc ('\n', fptr);
X                        va_end(ap);
X                        return;
X                    }
X                    if ((i + wrdlen(s)) >= rm)
X                        i = rm;
X                    else if (i > j)
X                        fputc (' ', fptr);
X                    break;
X                case ' ':     /* End of word reached */
X                    if ((i + wrdlen(++s)) >= rm)
X                        i = rm;
X                    else if (i > j)
X                        fputc (' ', fptr);
X                    break;
X                case '\n':    /* End of line reached */
X                    i = rm;
X                    s++;
X                    break;
X                default:
X                    fputc (*s++, fptr);
X            }
X        fputc ('\n', fptr);
X        if ((*s == '\0') && ((s = va_arg(ap, char *)) == 0)) {
X            va_end(ap);
X            return;
X        }
X    }
X}
X
Xint wrdlen(char *s) {
X    int r;
X
X    for (r = 0; *s != ' ' && *s != '\n' && *s != '\0'; r++, s++);
X    return r;
X}
X
Xint fgetp (FILE *fptr) {
X    int c, tot = 0;
X
X    while (!isdigit(c = getc(fptr)))
X        if (c == EOF)
X            return EOF;
X    do {
X        tot *= 10;
X        tot += (c - '0');
X    } while (isdigit(c = getc(fptr)));
X    if (c != '\n')
X        ungetc (c, fptr);
X    return tot;
X}
X
XFILE *FDOpen (const char *fn, const char *mode) {
X    FILE *fptr;
X
X    if ((fptr = fopen(fn, mode)) == NULL) {
X        fprintf (stderr, "Could not open %s.", fn);
X        exit (2);
X    }
X    return fptr;
X}
X
Xint Linefeeds (char *fname) {
X    FILE *fptr;
X    int c, cnt = 0;
X
X    RdOpen (fptr, fname);
X    while ((c = getc(fptr)) != EOF)
X        if (c == '\n')
X            cnt++;
X    fclose (fptr);
X    return cnt;
X}
X
Xchar *clone_line (FILE *fptr, int max) {
X    char *s, *r, *t;
X    int i;
X
X    s = (char *)malloc(max + 1);
X    t = s;
X    for (i = 0; (i < max) && ((*s = fgetc(fptr)) != '\n'); i++, s++);
X    if (*s != '\n')
X        ungetc(*s, fptr);
X    *s = '\0';
X    r = strdup(t);
X    free (t);
X    return r;
X}
X
Xint yesno () {
X    int c;
X
X    for (;;) {
X        c = fgetc(stdin);
X        while (fgetc(stdin) != '\n');
X        if (c == 'y' || c == 'Y')
X            return 1;
X        if (c == 'n' || c == 'N')
X            return 0;
X        puts ("Please answer y or n.");
X    }
X}
X
X#endif /* _FPDIO_C */
END_OF_FILE
if test 3275 -ne `wc -c <'fpdio.c'`; then
    echo shar: \"'fpdio.c'\" unpacked with wrong size!
fi
# end of 'fpdio.c'
fi
if test -f 'qst.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'qst.c'\"
else
echo shar: Extracting \"'qst.c'\" \(4478 characters\)
sed "s/^X//" >'qst.c' <<'END_OF_FILE'
X/* QST.C  Copyright (C) 1993 Fergus Patrick Duniho */
X
X#define MAXLINE 256
X
Xtypedef struct qnode {
X    int p[2]; /* Preference Array Numbers */
X    int num, ans, strength;
X    char *Qtext, *Atext[2];
X    struct qnode *pv, *nx;
X} qst;
X
Xqst *RND_QList (qst *Q, int size);
Xchar *Get_QList (char *fname, qst *Q, int size);
Xvoid AskQuestions (qst *Q, int col);
Xint AskQ (qst *Q, int col);
Xchar get_answer(int col);
Xqst *new_qnode (int num);
Xint get_strength (int col);
X
Xqst *new_qnode (int num) {
X    qst *node;
X
X    if ((node = (qst *)malloc(sizeof(qst))) == NULL) {
X      perror ("Malloc can't allocate enough memory for a new qnode.\n");
X      exit (2);
X   }
X   node->ans = -1;
X   node->num = num;
X   return node;
X}
X
X/* Get_QList: Reads questions from a file into a linked list.
X   Returns the version # string from the beginning of the
X   questions file. */
X
Xchar *Get_QList (char *fname, qst *Q, int size) {
X    FILE *fptr;
X    int i, j;
X    char *V;
X    qst *S;
X
X    S = Q;
X    RdOpen (fptr, fname);
X    V = clone_line(fptr, MAXLINE);
X    for (i = 1; i <= size; i++) {
X        Q->nx = new_qnode(i);
X        Q->nx->pv = Q;
X        Q = Q->nx;
X        Q->Qtext = clone_line(fptr, MAXLINE);
X        for (j = 0; j < 2; j++) {
X            Q->p[j] = fgetp(fptr);
X            Q->Atext[j] = clone_line(fptr, MAXLINE);
X        }
X    }
X    fclose (fptr);
X    Q->nx = S;
X    return V;
X}
X
X/* nth_qnode: Returns the nth member of a linked list of qst nodes. */
X
Xqst *nth_qnode (qst *Q, unsigned int n) {
X    while (n--)
X        Q = Q->nx;
X    return Q;
X}
X
X/* RND_QList: Randomizes a linked list of questions. */
X
Xqst *RND_QList (qst *Q, int size) {
X    qst *S, *L, *N, *SN;
X    unsigned int i, j;
X    char *temp;
X
X    SN = N = new_qnode(0);
X    S = Q;
X
X    /* Randomizes Answer Order */
X    for (i = 0; i < size; i++)
X        if (rand() % 2) {
X            L = nth_qnode(S, i);
X            j = L->p[1]; L->p[1] = L->p[0]; L->p[0] = j;
X            temp = L->Atext[1];
X            L->Atext[1] = L->Atext[0];
X            L->Atext[0] = temp;
X        }
X
X    /* Randomizes Question Order */
X    for (; size; size--) {
X        i = (rand() % size) + 1;
X        L = nth_qnode(S, i);
X        L->nx->pv = L->pv;
X        L->pv->nx = L->nx;
X        N->nx = L;
X        L->pv = N;
X        N = L;
X    }
X    free (S);
X    N->nx = SN;
X    SN->pv = N;
X    return SN;
X}
X
Xvoid AskQuestions (qst *Q, int col) {
X    int more = 1, flag = 1, num;
X
X    while (more) {
X        for (Q = Q->nx, num = 1; Q->num > 0; Q = Q->nx, num++) {
X            if ((Q->ans != -1) && flag)
X                continue;
X            flag = 1;
X            printf ("\nQuestion #%d\n", num);
X            if (AskQ(Q, col)) {
X                Q = Q->pv->pv;
X                flag = 0;
X                num -= 2;
X                if (num < 0) num = 0;
X            }
X        }
X        more = 0;
X        for (Q = Q->nx; Q->num > 0; Q = Q->nx)
X            if (Q->ans == -1) more = 1;
X    }
X}
X
X/* AskQ: Asks a single question. */
X
Xint AskQ (qst *Q, int col) {
X    char A;
X
X    wrapwrite (stdout, 0, 0, col, Q->Qtext, 0);
X    wrapwrite (stdout, 0, 4, col, "(A)", Q->Atext[0], 0);
X    puts (" ... Or");
X    wrapwrite (stdout, 0, 4, col, "(B)", Q->Atext[1], 0);
X    if ((A = get_answer(col)) < 2) {
X        Q->ans = Q->p[A];
X        Q->strength = get_strength(col);
X    }
X    else if (A == 4)
X        exit (2);
X    return A == 3;
X}
X
Xchar get_answer(int col) {
X    char c;
X
X    for (;;) {
X        c = fgetc(stdin);
X        while (fgetc(stdin) != '\n');
X        if (islower(c))
X            c = toupper(c);
X        if (c == 'A')
X            return 0;
X        if (c == 'B')
X            return 1;
X        if (c == 'S')
X            return 2;
X        if (c == 'P')
X            return 3;
X        if (c == 'Q')
X            return 4;
X        wrapwrite (stdout, 0, 0, col,
X            "Answer with an A or a B.\n",
X            "P = Go back to Previous question\n",
X            "Q = Quit\n",
X            "S = Skip until later.\n", 0);
X    }
X}
X
Xint get_strength (int col) {
X    int i;
X    wrapwrite (stdout, 0, 0, col, "Please rate the strength of this",
X        "preference on a scale of 1 to 7.\n",
X        "1 = Faint\n",
X        "2 = Weak\n",
X        "3 = Modest\n",
X        "4 = Moderate\n",
X        "5 = Strong\n",
X        "6 = Extreme\n",
X        "7 = Excessive\n", 0);
X    for (;;) {
X        i = fgetp(stdin);
X        if (i < 8)
X            break;
X        wrapwrite (stdout, 0, 0, col,
X            "Please select a number from 1 to 7.", 0);
X    }
X    return i;
X}
END_OF_FILE
if test 4478 -ne `wc -c <'qst.c'`; then
    echo shar: \"'qst.c'\" unpacked with wrong size!
fi
# end of 'qst.c'
fi
if test -f 'strdup.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'strdup.c'\"
else
echo shar: Extracting \"'strdup.c'\" \(409 characters\)
sed "s/^X//" >'strdup.c' <<'END_OF_FILE'
X/* STRDUP.C by Fergus Patrick Duniho. Public Domain */
X
X#ifndef _STRDUP_C
X#define _STRDUP_C
X
X#include <stdlib.h>
X#include <string.h>
X
Xchar *strdup (char *s);
X
Xchar *strdup (char *s) {
X    char *r;
X
X    if ((r = (char *)malloc(strlen(s) + 1)) == NULL) {
X      perror ("Malloc cannot allocate enough memory for a new string.\n");
X      exit (2);
X    }
X    strcpy (r, s);
X    return r;
X}
X
X#endif /* _STRDUP_C */
END_OF_FILE
if test 409 -ne `wc -c <'strdup.c'`; then
    echo shar: \"'strdup.c'\" unpacked with wrong size!
fi
# end of 'strdup.c'
fi
echo shar: End of shell archive.
exit 0
