#ifndef _ctrconfig_c #define _ctrconfig_c void ctrcfgalert( char *txt, FILE *fp ) { fprintf(stdout,"\r\n%s\r\n",txt); if( fp != NULL ) { fclose( fp ); } } void ctrhelp( void ) { fprintf( stdout,"\n\n"); fprintf( stdout,"elctr (co.) E.Benninghaus, Rottweil, Germany\n"); fprintf( stdout,"usage: elctr -options\n"); fprintf( stdout,"\n"); } int ctrparsecommandline(int argc, char * argv[]) { int arg; char *p; for (arg = 1; arg < argc;) { if(strcmp(argv[arg],"-h")==0){ ctrhelp(); return(0); } /* if( ( strcmp(argv[arg],"-d")==0) && ( argv[arg + 1] != NULL) ) { if(strlen(argv[arg + 1]) > 82){ fprintf(stderr,"len of string for devicefile exceeds max. 82 chars\n"); return(0); } strcpy(cfg.devicefile,argv[arg + 1]); arg++;arg++; continue; } if( ( strcmp(argv[arg],"-i")==0) && ( argv[arg + 1] != NULL) ) { cfg.tcpport = atoi(argv[arg + 1]); arg++;arg++; continue; } */ arg++; } return(1); } int ctrcorrectvalues( void ) { if(elctr.hs_az360 > 0.0 ){ elctr.hs_az90 = elctr.hs_az360 / 4; elctr.hs_az180 = elctr.hs_az90 * 2; elctr.hs_az270 = elctr.hs_az90 * 3; } if(elctr.hs_alt90 > 0.0 ){ elctr.hs_alt180 = elctr.hs_alt90 * 2; } if(elctr.hs_fr360 > 0.0 ){ elctr.ms_perhsfr360 = 86400000.0 / elctr.hs_fr360; } return(1); } int ctrreadconfigfile( char *filename ) { size_t len; double d; long l; int i; unsigned short us; FILE *fp; char *s,*p; s = &il_tmptext[0]; sprintf(s,"./%s",filename); fp = fopen(s,"rt"); if(fp == NULL){ p = getenv("HOME"); if(p != NULL){ sprintf(s,"%s/.%s",p,filename); fp = fopen(s,"rt"); } } if(fp == NULL){ sprintf(s,"/etc/%s",filename); fp = fopen(s,"rt"); } if(fp == NULL){ ctrcfgalert("Cannot find, - or open configfile", fp); return( 0 ); } rewind(fp); while ( ! feof( fp ) ) { fgets( s , 252 , fp ); strCleanStr( s, 254 ); strEatBytes(0x20 , s ,254, 1); if( ( s[0] == ';' ) || ( s[0] == '#' ) ){ continue; } p = strchr(s, '=' ); if( p == NULL ){ continue; } p[0] = 0;p++; if(strcmp(s,"INTERFACE" ) == 0){ if(strcmp( p, "SERIAL") == 0 ){ elctr.iftype = IF_SERIAL; continue; } if(strcmp( p, "PARALLELSMC") == 0 ){ elctr.iftype = IF_PARALLEL; parsubtype = IF_PARALLELSUBSMC; continue; } if(strcmp( p, "PARALLELRAW") == 0 ){ elctr.iftype = IF_PARALLEL; parsubtype = IF_PARALLELSUBRAW; continue; } ctrcfgalert("No valid interface defined for INTERFACE", fp); return(0); } if(strcmp(s,"SERIALPORT" ) == 0){ len = strlen(p); if( len < 3 ){ ctrcfgalert("No valid portstring for SERIALPORT", fp); return(0); } if( len >= 128 ){ ctrcfgalert("portstring for SERIALPORT is too long", fp); return(0); } strcpy( &serialport[0], p ); continue; } if(strcmp(s,"JOYSTICKPORT" ) == 0){ if( strTestPtrHex( p ) == 1 ){ sscanf(p, "%x", &i ); } else { i = atoi( p ); } us = ( unsigned short ) i; if( us <= 0 ){ ctrcfgalert("Invalid value for JOYSTICKPORT",fp); return(0); } setJoystickPort( us ); continue; } if(strcmp(s,"PARALLELPORT" ) == 0){ if( strTestPtrHex( p ) == 1 ){ sscanf(p, "%x", &i ); } else { i = atoi( p ); } us = ( unsigned short ) i; if( us <= 0 ){ ctrcfgalert("Invalid value for PARALLELPORT",fp); return(0); } setParallelPort( us ); continue; } if(strcmp(s,"INPUTTYPE" ) == 0){ if(strcmp( p, "SERIAL") == 0 ){ elctr.inputiftype = IF_INPUTSERIAL; continue; } if(strcmp( p, "PARALLEL") == 0 ){ elctr.inputiftype = IF_INPUTPARALLEL; continue; } if(strcmp( p, "JOYSTICK") == 0 ){ elctr.inputiftype = IF_INPUTJOYSTICK; continue; } ctrcfgalert("No valid interface defined for INPUTTYPE", fp); return(0); } if(strcmp(s,"INPUTPORT" ) == 0){ if( strTestPtrHex( p ) == 1 ){ sscanf(p, "%x", &i ); } else { i = atoi( p ); } us = ( unsigned short ) i; if( us <= 0 ){ ctrcfgalert("Invalid value for INPUTPORT",fp); return(0); } if(elctr.inputiftype == IF_INPUTPARALLEL){ setParallelPort2( us ); continue; } if(elctr.inputiftype == IF_INPUTJOYSTICK){ setJoystickPort2( us ); continue; } if(elctr.inputiftype == IF_INPUTSERIAL){ continue; } ctrcfgalert("No valid INPUTTYPE for setting of port", fp); return(0); } if(strcmp(s,"JOYSTICKKEYPAD" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.keypad = KEYPADTYPE_JOYSTICK; } continue; } if(strcmp(s,"PARALLELKEYPAD" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.keypad = KEYPADTYPE_PARALLEL; } continue; } if(strcmp(s,"TIMERINTCTGOTO" ) == 0){ d = strtod((const char *)p,NULL); if( d < 0.0 ){ ctrcfgalert("No valid value defined for TIMERINTCTGOTO", fp); return(0); } elctr.timerintct_goto = d; continue; } if(strcmp(s,"TIMERINTCTCORRECTION" ) == 0){ d = strtod((const char *)p,NULL); if( d < 0.0 ){ ctrcfgalert("No valid value defined for TIMERINTCTCORRECTION", fp); return(0); } elctr.timerintct_correction = d; continue; } if(strcmp(s,"AZGOTOSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for AZGOTOSPEED", fp); return(0); } elctr.az_gotospeed = d; continue; } if(strcmp(s,"ALTGOTOSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for ALTGOTOSPEED", fp); return(0); } elctr.alt_gotospeed = d; continue; } if(strcmp(s,"FRGOTOSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for FRGOTOSPEED", fp); return(0); } elctr.fr_gotospeed = d; continue; } if(strcmp(s,"AZCORRECTIONSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for AZCORRECTIONSPEED", fp); return(0); } elctr.az_correctionspeed = d; continue; } if(strcmp(s,"ALTCORRECTIONSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for ALTCORRECTIONSPEED", fp); return(0); } elctr.alt_correctionspeed = d; continue; } if(strcmp(s,"FRCORRECTIONSPEED" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for FRCORRECTIONSPEED", fp); return(0); } elctr.fr_correctionspeed = d; continue; } if(strcmp(s,"AZHS360" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for AZHS360", fp); return(0); } elctr.hs_az360 = d; continue; } if(strcmp(s,"ALTHS90" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for ALTHS90", fp); return(0); } elctr.hs_alt90 = d; continue; } if(strcmp(s,"FRHS360" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for FRHS360", fp); return(0); } elctr.hs_fr360 = d; continue; } if(strcmp(s,"ALTHSHORIZONTLIMIT" ) == 0){ d = strtod((const char *)p,NULL); if( d < 0.0 ){ ctrcfgalert("No valid value defined for ALTHSHORIZONTLIMIT", fp); return(0); } elctr.hs_altlb = d; continue; } if(strcmp(s,"ALTHSZENITLIMIT" ) == 0){ d = strtod((const char *)p,NULL); if( d <= 0.0 ){ ctrcfgalert("No valid value defined for ALTHSZENITLIMIT", fp); return(0); } elctr.hs_altub = d; continue; } if(strcmp(s,"FRUSE" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.fruse = 1; } continue; } if(strcmp(s,"FRLEFT" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.frleft = 1; } continue; } if(strcmp(s,"DEBUG" ) == 0){ if( ( strcmp( p, "ON" ) == 0) || ( strcmp(p, "1") == 0 ) ) { elctr.debug = 1; } continue; } } fclose( fp ); return( ctrcorrectvalues() ); } #endif /*_ctrconfig_c*/