I'm having problem with Edward Almasy's snippet for saving players' aliases.
It worked in Linux, but not in Win95. I have tried to mail Edward, but his
e-mail address doesn't work, so I'm hoping to get some help here.
When I first compiled my mud in Win95 with the new alias.c file I got this
error:
cl -c /nologo /I. /IC:\PROGRAM\DEVSTUDIO\VC\INCLUDE alias.c
alias.c
alias.c(17) : fatal error C1083: Cannot open include file: 'unistd.h': No such f
ile or directory
NMAKE : fatal error U1077: 'C:\PROGRAM\DEVSTUDIO\VC\BIN\cl.exe' : ret
urn code '0x2'
Stop.
Ok, I removed the line #include <unistd.h> and then it compiled succesfully.
But the mud crashed when I typed SAVE to save my aliases. (surprise! :-)
The <unistd.h> don't seem to work under Win95. What shall I include
instead? Or is it some other way to fix this error?
Hope you can help me. Below are my alias.c file and my ACMD(do_save)-
function.
/********************* alias.c *******************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "interpreter.h"
void write_aliases(struct char_data *ch)
{
FILE *ptFHndl;
char pcFileName[127];
struct alias *pstAliasRec;
char *pcRepStart;
/* get name of alias file */
get_filename(GET_NAME(ch), pcFileName, ALIAS_FILE);
/* remove old alias file */
unlink(pcFileName);
/* if no aliases */
if (!GET_ALIASES(ch))
/* abort */
return;
/* open new alias file */
ptFHndl = fopen(pcFileName,"wt");
/* while there are alias records left */
pstAliasRec = GET_ALIASES(ch);
while (pstAliasRec)
{
/* write out command */
fprintf(ptFHndl, "%d\n", strlen(pstAliasRec->alias));
fprintf(ptFHndl, "%s\n", pstAliasRec->alias);
/* remove leading spaces on replacement */
pcRepStart = pstAliasRec->replacement;
while (*pcRepStart == ' ') pcRepStart++;
/* write out replacement */
fprintf(ptFHndl, "%d\n", strlen(pcRepStart));
fprintf(ptFHndl, "%s\n", pcRepStart);
fprintf(ptFHndl, "%d\n", pstAliasRec->type);
/* move to next alias record */
pstAliasRec = pstAliasRec->next;
}
/* close new alias file */
fclose(ptFHndl);
}
void read_aliases(struct char_data *ch)
{
char pcFileName[127];
FILE *ptFHndl;
struct alias *pstAliasRec;
int iLen;
/* get alias file name */
get_filename(GET_NAME(ch), pcFileName, ALIAS_FILE);
/* open alias file */
ptFHndl = fopen(pcFileName, "r");
/* if file open failed */
if (ptFHndl == NULL)
/* abort */
return;
/* create initial alias record */
CREATE(pstAliasRec, struct alias, 1);
GET_ALIASES(ch) = pstAliasRec;
/* while not end of alias file */
while (!feof(ptFHndl))
{
/* read in length of command */
fscanf(ptFHndl, "%d\n", &iLen);
/* allocate command string */
CREATE(pstAliasRec->alias, char, (iLen + 2));
/* read in command */
fgets(pstAliasRec->alias, (iLen+1), ptFHndl);
/* read in length of replacement */
fscanf(ptFHndl, "%d\n", &iLen);
/* allocate replacement string */
CREATE(pstAliasRec->replacement, char, (iLen + 3));
*pstAliasRec->replacement = ' ';;
/* read in replacement */
fgets((pstAliasRec->replacement + 1), (iLen+1), ptFHndl);
/* read in type */
fscanf(ptFHndl, "%d\n", &pstAliasRec->type);
/* if there are aliases left to read */
if (!feof(ptFHndl))
{
/* create new alias record and link into chain */
CREATE(pstAliasRec->next, struct alias, 1);
pstAliasRec = pstAliasRec->next;
pstAliasRec->next = NULL;
}
}
/* close alias file */
fclose(ptFHndl);
}
/****************** act.other.c ********************/
ACMD(do_save)
{
void write_aliases(struct char_data *ch);
if (IS_NPC(ch) || !ch->desc)
return;
if (cmd) {
sprintf(buf, "Saving %s (including aliases).\r\n", GET_NAME(ch));
send_to_char(buf, ch);
}
write_aliases(ch);
save_char(ch, NOWHERE);
Crash_crashsave(ch);
if (ROOM_FLAGGED(ch->in_room, ROOM_HOUSE_CRASH))
House_crashsave(world[ch->in_room].number);
}
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST