This is commands.c in view mode; [Download] [Up]
/* -*- c -*- */ /* Webster Access, a program to use NeXT online Webster dictionary. Copyright (C) 1994 Benoit Grange, ben@fizz.fdn.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #import <libc.h> #import <syslog.h> #import "daemon.h" #import "utils.h" #import "commands.h" #import "search.h" #import "config.h" short mode = normalMode; void lowerString(char *c) { while (*c) { if ((*c >= 'A') && (*c <= 'Z')) *c += 'a' - 'A'; c++; } } void doQuit() { if (mode == enhancedMode) fprintf(clientW, "221 Nice to define with you\n"); report(); exit(0); } void doHelp() { fprintf(clientW, "%sWebster server for NS 3.x\n", (mode == enhancedMode)?"211-":""); fprintf(clientW, "%sSorry, no help available in this alpha version !\n", (mode == enhancedMode)?"211 ":""); } void processIndex(const char* name) { if (!strcmp(name, "dictionary")) { whichVolume = useDictionary; } else if (!strcmp(name, "thesaurus")) { whichVolume = useThesaurus; } else { fprintf(clientW, "ERROR FATAL\n"); return; } } void doTimeout() { report(); exit(0); } void commandLoop() { char buffer[256], *c; signal(SIGALRM, doTimeout); for (;;) { char* args; fflush(clientW); alarm(timeout); c = fgets(buffer, sizeof(buffer), clientR); alarm(0); if (!c) break; /* First word is command */ args = index(c, '\n'); if (args) *args = 0; args = index(c, '\r'); if (args) *args = 0; args = index(c, ' '); if (args) *args++ = 0; syslog(LOG_DEBUG, "COMMAND: '%s'\n", c); lowerString(c); if (!strcmp(c, "define")) processDefine(args); else if (!strcmp(c, "spell")) processSpell(args); else if (!strcmp(c, "complete")) processComplete(args); else if (!strcmp(c, "endings")) processEndings(args); else if (!strcmp(c, "quit")) doQuit(); else if (!strcmp(c, "help")) doHelp(); else if (!strcmp(c, "index")) processIndex(args); else if (mode == enhancedMode) { // if (!strcmp(c, "provide")) processProvide(args); // else if (!strcmp(c, "data")) processData(args); // else fprintf(clientW, "502 Unknown command %s, try HELP\n", c); } else { fprintf(clientW, "ERROR\n"); } syslog(LOG_DEBUG, "... done\n"); fflush(clientW); } }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.