From: Chris Baggett Based on code from Erwin S. Andreasen Subject: ACMD(ispell) conversion ok, I looked at Erwin's ispell.txt on his LETTERS site. And as a start, I decided that I would circle-fy it. After I figured out what certain variables were meant to do, I proceeded and here it is: The only thing you need to add if you want to use this ACMD() is : 1) ACMD(do_ispell); in the ACMD() list in interpreter.c 2) put "ispell" in the command_interpreter array as a new command is done 3) void ispell_init(void); void ispell_done(void); // put these lines at the top of comm.c 4) in comm.c's init_game() right before the game_loop(mother_desc); put this: ispell_init(); 5) in comm.c's init_game() right AFTER the game_loop(mother_desc); put this: ispell_done(); Ex. it should now look like this: ispell_init(); game_loop(mother_desc); ispell_done(); after that, change your Makefile (I use the makefile auto-dependencies thing so it helps me out a lot to just be able to type make depend) put ispell.o in the OBJFILES, and basically add the new file to the Makefile listing and don't forget ispell.c The syntax for it is basically 'ispell ' (which checks to see if it is spelled correctly and gives suggestions) or 'ispell +' (which adds it to your personal dictionary defined at the top of ispell.c) This should work, I worked out all the bugs and no problems now. Thanks go out to Erwin S. Andreasen for the help he gave, and the original idea. I'm not responsible for any damage done to anything on your system. This is mailer code that works! Here it is (ispell.c) WARNING: this only works on UNIX systems. ============================================================================== /* Interface to iSpell * Copyright (c) 1997 Erwin S. Andreasen * */ #include "conf.h" #include "sysdep.h" #include #include #include #include "structs.h" #include "utils.h" #include "comm.h" #include "interpreter.h" #include "db.h" #include #define Stringify(x) Str(x) #define Str(x) #x #define MSL MAX_STRING_LENGTH #define ISPELL_DICTIONARY "etc/mud.dictionary" static FILE *ispell_out; static ispell_pid=-1; static int to[2], from[2]; #define ISPELL_BUF_SIZE 1024 void ispell_init(void) { char ignore_buf[1024]; #if 0 if (IS_SET(sysdata.options, OPT_NO_ISPELL)) { ispell_pid=-1; return; } #endif pipe(to); pipe(from); ispell_pid = fork(); if (ispell_pid < 0) log("ispell_init: fork: %s", strerror(errno)); else if (ispell_pid == 0) /* child */ { int i; dup2 (to[0], 0); /* this is where we read commands from - make it stdin */ close (to[0]); close (to[1]); dup2 (from[1], 1); /* this is where we write stuff to */ close (from[0]); close (from[1]); /* Close all the other files */ for (i = 2; i < 255; i++) close (i); execlp ("ispell", "ispell", "-a", "-p" ISPELL_DICTIONARY, (char *) NULL); exit(1); } else /* ok !*/ { close (to[0]); close (from[1]); ispell_out = fdopen (to[1], "w"); setbuf (ispell_out, NULL); #if !defined( sun ) /* that ispell on sun gives no (c) msg */ read (from[0], ignore_buf, 1024); #endif } } void ispell_done(void) { if (ispell_pid != -1) { fprintf (ispell_out, "#\n"); fclose (ispell_out); close (from[0]); waitpid(ispell_pid, NULL, 0); ispell_pid = -1; } } char* get_ispell_line (char *word) { static char buf[ISPELL_BUF_SIZE]; char buf2[MSL*3]; int len; if (ispell_pid == -1) return NULL; if (word) { fprintf (ispell_out, "^%s\n", word); fflush (ispell_out); } len = read (from[0], buf2, ISPELL_BUF_SIZE); buf2[len] = '\0'; /* Read up to max 1024 characters here */ if (sscanf (buf2, "%" Stringify(ISPELL_BUF_SIZE) "[^\n]\n\n", buf) != 1 ) return NULL; return buf; } ACMD(do_ispell) { char *pc; if (ispell_pid <= 0) { send_to_char ("ispell is not running.\r\n",ch); return; } skip_spaces(&argument); if (!argument[0] || strchr (argument, ' ')) { send_to_char ("Invalid input.\r\n",ch); return; } if (argument[0] == '+') { for (pc = argument+1;*pc; pc++) if (!isalpha(*pc)) { send_to_charf (ch, "'%c' is not a letter.\r\n", *pc); return; } fprintf (ispell_out, "*%s\n", argument+1); fflush (ispell_out); return; /* we assume everything is OK.. better be so! */ } pc = get_ispell_line(argument); if (!pc) { send_to_char ("ispell: failed.\r\n",ch); return; } switch (pc[0]) { case '*': case '+': /* root */ case '-': /* compound */ send_to_char ("Correct.\r\n",ch); break; case '&': /* miss */ send_to_charf(ch, "Not found. Possible words: %s\r\n", strchr(pc, ':') +1); break; case '?': /* guess */ send_to_charf(ch, "Not found. Possible words: %s\r\n", strchr(pc, ' :')+1); break; case '#': /* none */ send_to_char ("Unable to find anything that matches.\r\n",ch ); break; default: send_to_charf (ch, "Weird output from ispell: %s\r\n", pc); } } ============================================================================