/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * COPYING NOTES * * replyfunc.c -- replay function bodies * * Copyright (C) 2002 Roberto A. Foglietta <robang@libero.it> * Copyright (C) 2002 GEA-Automotive <fogliettar@gea-automotive.com> * * 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. * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * REVISION NOTES: * released 21-10-2002 by Roberto A. Foglietta */ #include <stdlib.h> #include <unistd.h> #include <string.h> #include <stdio.h> #ifdef USING_IO_FILE #include "iofile.h" #endif #ifdef USING_SHARED_MEMORY #include "shmtool.h" #endif #define ACQ_FUNCTION #include "replyfunc.h" char *acq_hello(void) { static char name[256]={"\0"}; gethostname(&name[128], 128); sprintf(name, "Hello from %s\n", &name[128]); return name; } char *acq_getall(void) { static char *str = NULL; //{"That is all\n\0"}; #ifdef USING_SHARED_MEMORY static int shmid = -1; //long lun; if(shmid == -1) { shmid = initshm(); if(shmid == -1) return NULL; } if(str != NULL) free(str); str = readshm(shmid); #endif #ifdef USING_IO_FILE str = read_file_to_buffer ("README", "rt", &lun); #endif str = malloc(128); sprintf(str,"That is all\n"); return str; } char *acq_bye(void) { return strdup(_STOP); } #define MAXLEN 256 char *acq_help(void) { int i, j = MAXLEN; static char str[MAXLEN]; sprintf(str, "Admitted command list:\n"); for (i = 0; i < N_ACQUIRE_STEPS && j; i++) { strcat(str, ACQ_TEXT[i]); j -= strlen(ACQ_TEXT[i]); strcat(str, "\n"); j --; } return str; } #undef MAXLEN char * reply_func (char const *data) { //static char str[256] = { "\0" }; //char host[128]; int i; for (i = 0; i < N_ACQUIRE_STEPS; i++) if (!strncasecmp (data, ACQ_TEXT[i], strlen (ACQ_TEXT[i]))) return ACQ_FUNC[i](); /* Default */ return ACQ_FUNC[HELP](); }