/* * Copyright (C) 2006-2019 S&S * Samuel Thibault * Sébastien Hinderer * * 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 the program ; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* vstp_main.c * files transferring with VisioBraille terminals */ #include #include #include #include #include #include "brlapi.h" #include "vstp.h" #define VSTPRC ".vstprc" #define LINELENGTH 255 char *socketport = NULL; char *keyname=NULL; void handleint(int signum) { fprintf(stderr,"aborting on signal %d\n",signum); transfer_abort(RET_INT); } /* every possible option */ #define OPTIONS "ifbnskd" static void printusage(char *name) { printf(VSTP_GET "/" VSTP_PUT " : get files from / put files to a VisioBraille terminal\n"); printf("Usage: %s [options] [files]\n",name); printf("[files] are Unix filenames\n"); printf(" -i ask for confirmation\n"); printf(" -f don't ask for confirmation (default)\n"); printf(" -b create backup (.vis~) file if file already exists\n"); printf(" -n do not create backup (.vis~) file (default)\n"); printf(" -s port use port as port number instead of default\n"); printf(" -k filename use filename as key path instead of default\n"); printf(" -d put files into current directory\n"); printf(" -o filename also use filename as options file\n"); exit(RET_EPARSE); } static void grr(char *name) { printusage(name); exit(RET_EPARSE); } static transferfun *CheckSendOrRecv(char *name){ if (strstr(name,VSTP_PUT) != NULL) return fileput; if (strstr(name,VSTP_GET) != NULL) return fileget; printf("Please call me as " VSTP_PUT " or as " VSTP_GET ".\n"); grr(name); exit(RET_EPARSE); } static void Parse(char *filename) { FILE *fd; char s[LINELENGTH+1]; char *c,*d; if (!(fd=fopen(filename,"r"))) return; while (fgets(s,LINELENGTH,fd)) { if ((c=strchr(s,'#'))) *c='\0'; if ((c=strchr(s,'\n'))) *c='\0'; if ((c=strchr(s,'='))) { /* '=' option : key name and value */ for (d=c-1; *d==' ' || *d=='\t'; d--); *(d+1)='\0'; for (c++; *c==' ' || *c=='\t'; c++); *(c-1)='\0'; if (!strcmp(s,"keyname")) { keyname = (char *) malloc(strlen(c)+1); strcpy(keyname,c); } else if (!strcmp(s,"socketport")) { socketport = (char *) malloc(strlen(c)+1); strcpy(socketport,c); } else if (!strcmp(s,"vbs_ext")) { visiobases_ext = (char *) malloc(5); strncpy(visiobases_ext,c,4); visiobases_ext[4]=0; } else if (!strcmp(s,"vbs_dir")) { visiobases_dir = (char *) malloc(strlen(c)+1); strcpy(visiobases_dir,c); } } else { if (!strcmp(s,"backup")) { backup=1; } else if (!strcmp(s,"nobackup")) { backup=0; } } } fclose(fd); } static void CheckOptions(int argc, char **argv) { int n,m; int i; for(n=1;n