26 #include <sys/types.h> 27 #include <sys/select.h> 40 #include <lib$routines.h> 48 #include <sys\types.h> 71 if(ret < 0)
return ret;
72 return printf(
"%s",message);
77 struct timeval timout;
78 fd_set wset,rset,eset;
89 ret = ::select(maxfdp1,&rset,&wset,&eset,&timout);
90 if(ret == 0)
return 0;
103 if(ret < 0)
return ret;
106 printf(
"%s",message);
107 for(i=strlen(message); i<80; i++) printf(
" ");
119 buf =
new char [strlen(command)+1];
123 while(buf[i] !=
'\0')
128 arg[iarg++] = &buf[i];
129 while(buf[i] !=
'\"' && buf[i] !=
'\0') i++;
130 if(buf[i] ==
'\0')
break;
133 else if(buf[i] !=
' ' || i == 0)
135 arg[iarg++] = &buf[i];
136 while(buf[i] !=
' ' && buf[i] !=
'\0') i++;
137 if(buf[i] ==
'\0')
break;
144 ret = execvp(arg[0],arg);
153 static char ret[4*16+8];
158 for(i=0; p[i] !=
'\0' && i<=16; i++)
161 sprintf(buf,
"%04X",val);
175 if(source[i] ==
'\0')
break;
188 if(source[i] ==
'\0')
break;
189 if(source[i] ==
'\n')
break;
197 int rlvsnprintf(
char *text,
int len,
const char *format, va_list ap)
202 if(format == NULL || format[0] ==
'\0')
207 ret = _vsnprintf(text, len, format, ap);
211 if(format == NULL || format[0] ==
'\0')
216 ret = vsprintf(vms_is_deprecated, format, ap);
220 if(format == NULL || format[0] ==
'\0')
225 ret = vsnprintf(text, len, format, ap);
238 ret = _vsnprintf(text, len, format, ap);
242 ret = vsprintf(vms_is_deprecated, format, ap);
246 ret = vsnprintf(text, len, format, ap);
258 printf(
"entering rlSigtermHandler sig=%d\n",sig);
262 fsync(fileno(stdout));
277 static char freturn[512];
281 static struct dirent *dp;
283 if(*context == 0) dirp = opendir(
".");
286 while((dp = readdir(dirp)) != NULL)
288 if(dp->d_name[0] ==
'.') ;
289 else if(strstr(dp->d_name,pattern) != NULL)
291 strcpy(freturn,dp->d_name);
296 strcpy(freturn,dp->d_name);
306 static char file[512] =
"";
307 static char wildcard[80];
308 struct dsc$descriptor_s dwildcard;
309 struct dsc$descriptor_s dfreturn;
311 strcpy(wildcard,pattern);
313 dwildcard.dsc$w_length = strlen(wildcard);
314 dwildcard.dsc$a_pointer = wildcard;
315 dwildcard.dsc$b_dtype = DSC$K_DTYPE_T;
316 dwildcard.dsc$b_class = DSC$K_CLASS_S;
318 dfreturn.dsc$w_length =
sizeof(freturn);
319 dfreturn.dsc$a_pointer = &freturn[0];
320 dfreturn.dsc$b_dtype = DSC$K_DTYPE_T;
321 dfreturn.dsc$b_class = DSC$K_CLASS_S;
323 ret = LIB$FIND_FILE(&dwildcard,&dfreturn,context,0,0,0,0);
324 if (ret == RMS$_NMF)
return NULL;
325 else if(ret != RMS$_NORMAL)
return NULL;
326 else if(strcmp(freturn,file) == 0) { file[0] =
'\0';
return NULL; }
328 while(freturn[i] >
' ')i++;
334 static WIN32_FIND_DATAA wfd;
335 static HANDLE hFindFile;
340 hFindFile = FindFirstFileA(pattern,&wfd);
341 if(hFindFile == INVALID_HANDLE_VALUE)
return NULL;
342 else strcpy(freturn,(
const char *) &wfd.cFileName);
346 if(FindNextFileA(hFindFile,&wfd) == TRUE) strcpy(freturn,(
const char *) &wfd.cFileName);
347 else { FindClose(hFindFile);
return NULL; }
356 static char buf[1024];
359 strcpy(buf,getenv(
"HOME"));
363 strcpy(buf,
"sys$login:");
366 ExpandEnvironmentStringsA(
"%USERPROFILE%",buf,
sizeof(buf)-1);
367 if(strcmp(buf,
"%USERPROFILE%") == 0) strcpy(buf,
"C:");
377 return (val & 0x0ff)*256 + val/256;
385 sprintf(buf,
"buscommand -eib1 %d",command);
393 sprintf(buf,
"buscommand -eib2 %d",command);
401 sprintf(buf,
"buscommand -lon1 %d",command);
409 sprintf(buf,
"buscommand -lon2 %d",command);
417 sprintf(buf,
"buscommand -profibus1 %d",command);
425 sprintf(buf,
"buscommand -profibus2 %d",command);
433 sprintf(buf,
"buscommand -can1 %d",command);
441 sprintf(buf,
"buscommand -can2 %d",command);
448 HKEY applications,iexplore,shell,open,command;
450 unsigned long size,type;
460 if(ret != ERROR_SUCCESS)
470 if(ret != ERROR_SUCCESS)
472 RegCloseKey(applications);
481 if(ret != ERROR_SUCCESS)
483 RegCloseKey(applications);
484 RegCloseKey(iexplore);
493 if(ret != ERROR_SUCCESS)
495 RegCloseKey(applications);
496 RegCloseKey(iexplore);
506 if(ret != ERROR_SUCCESS)
508 RegCloseKey(applications);
509 RegCloseKey(iexplore);
515 ret = RegQueryValueExA(
520 (
unsigned char *) buf,
524 RegCloseKey(applications);
525 RegCloseKey(iexplore);
528 RegCloseKey(command);
530 if(ret != ERROR_SUCCESS)
return -1;
532 cptr = strstr(buf,
" %1");
533 if(cptr != NULL) *cptr =
'\0';
542 memset(&si, 0,
sizeof(si));
544 PROCESS_INFORMATION pi;
548 ExpandEnvironmentStringsA(command,cmd,
sizeof(cmd)-1);
549 ret = (int) CreateProcessA( NULL, cmd
551 , FALSE, CREATE_NO_WINDOW
563 return system(command);
567 int rlSubmitPvserver(
const char *env,
const char *path,
const char *pvs,
const char *options)
569 if(env == NULL || path == NULL || pvs == NULL)
return -1;
577 command =
"spawn/nowait ";
581 if(options != NULL) command += options;
586 if(cptr == NULL) { printf(
"rlSubmitPvserver:ERROR env=%s is not set\n", env);
return -2; }
598 if(options != NULL) command += options;
599 command +=
" \"-cd=";
619 sprintf(buf,
"konqueror %s &", htmlfile);
625 strcat(buf,htmlfile);
631 int rlOption(
const char *
string,
const char *option)
635 cptr = strstr(
string,option);
636 if(cptr == NULL)
return 0;
645 cptr = strstr(
string,option);
646 if(cptr == NULL)
return def;
648 cptr = strstr(cptr,
"=");
649 if(cptr == NULL)
return def;
651 sscanf(cptr,
"=%d",&ret);
660 cptr = strstr(
string,option);
661 if(cptr == NULL)
return def;
663 cptr = strstr(cptr,
"=");
664 if(cptr == NULL)
return def;
666 sscanf(cptr,
"=%f",&ret);
670 const char *
rlTextOption(
const char *
string,
const char *option,
const char *def)
677 cptr = strstr(
string,option);
678 if(cptr == NULL)
return def;
680 cptr = strstr(cptr,
"=");
681 if(cptr == NULL)
return def;
686 while(i < ((
int)
sizeof(ret)-1))
688 if(cptr[i] == quote || cptr[i] ==
'\0')
break;
700 if(source == NULL || destination == NULL)
return -1;
701 fin = fopen(source,
"r");
704 printf(
"rlCopyTextfile: could not read %s\n",source);
707 fout = fopen(destination,
"w");
711 printf(
"rlCopyTextfile: could not write %s\n",destination);
715 char *line =
new char[256*256];
716 while(fgets(line,
sizeof(line)-1,fin) != NULL)
718 fprintf(fout,
"%s",line);
729 if(str == NULL)
return -1;
732 *str = toupper(*str);
740 if(str == NULL)
return -1;
743 *str = tolower(*str);
752 if(str == NULL || startstr == NULL)
return 0;
753 ret = strncmp(str,startstr,strlen(startstr));
754 if(ret == 0)
return 1;
761 if(str == NULL || endstr == NULL)
return 0;
762 int index = strlen(str) - strlen(endstr);
763 if(index < 0)
return 0;
764 ret = strcmp(&str[index],endstr);
765 if(ret == 0)
return 1;
771 if(strstr(str,wild) != NULL)
return 1;
775 for(i=0; str[i] !=
'\0'; i++)
779 while(wild[w] ==
'*') w++;
780 if(wild[w] ==
'\0')
return 1;
782 if(wild[w] ==
'\0')
return 0;
783 while(str[i] != wild[w] && str[i] !=
'\0') i++;
784 if(str[i] ==
'\0')
return 0;
785 while(str[i] !=
'\0')
787 if(str[i] != wild[w])
goto try_next;
790 if(str[i] ==
'\0' && wild[w] ==
'\0')
return 1;
792 if(wild[w] !=
'\0')
return 0;
797 if(str[i] != wild[w])
return 0;
804 int rlStat(
const char *filepath,
struct stat *buf)
806 return stat(filepath, buf);
811 if(fin == NULL)
return -1;
812 return fread(data,1,len,fin);
817 if(fout == NULL)
return -1;
818 return fwrite(data,1,len,fout);
823 FILE *fout = fopen(filename,
"w");
826 printf(
"ERROR: rlWriteFile() could not write to %s\n", filename);
829 int ret = fwrite(data,1,len,fout);
837 int ret = CreateDirectoryA(dir,NULL);
842 return mkdir(dir, mode);
848 int bit = 1 << bitnumber;
849 *value = *value | bit;
855 int bit = 1 << bitnumber;
857 *value = *value & bit;
863 int bit = 1 << bitnumber;
864 *value = *value ^ bit;
870 int bit = 1 << bitnumber;
871 if(*value & bit)
return 1;
877 if(size <= 0)
return;
878 for(
int i=size; i>=2; i--) buffer[i-1] = buffer[i-2];
884 if(size <= 0)
return;
885 for(
int i=size; i>=2; i--) buffer[i-1] = buffer[i-2];
int rlDebugPrintf(const char *format,...)
int rlFRead(FILE *fin, void *data, int len)
static void(* rlUserSigtermHandler)(void *arg)
int rlProfibus1(int command)
void rlPushToFloatBuffer(float val, float *buffer, int size)
int rlSetDebugPrintf(int state)
int rlMkdir(const char *dir, int mode)
float rlFloatOption(const char *string, const char *option, float def)
const char * rlpass(const char *p)
int rlBrowser(const char *htmlfile)
char * rlstrlinecpy(char *dest, const char *source, int n)
static void * rlsigtermarg
int rlWriteFile(const char *filename, void *data, int len)
int rlCopyTextfile(const char *source, const char *destination)
void rlSetSigtermHandler(void(*handler)(void *arg), void *arg)
int rlFWrite(FILE *fout, void *data, int len)
void rlPushToDoubleBuffer(double val, double *buffer, int size)
int rlLastLinePrintf(const char *format,...)
int rlBitSet(int bitnumber, int *value)
int rlexec(const char *command)
int rlEndsWith(const char *str, const char *endstr)
static int get_iexplore(char *buf)
int rlStrMatch(const char *str, const char *wild)
int rlvsnprintf(char *text, int len, const char *format, va_list ap)
int rlBitClear(int bitnumber, int *value)
static int mysystem(const char *command)
char * rlstrncpy(char *dest, const char *source, int n)
const char * rlGetInifile(const char *name)
int rlSubmitPvserver(const char *env, const char *path, const char *pvs, const char *options)
const char * rlTextOption(const char *string, const char *option, const char *def)
int rlBitTest(int bitnumber, int *value)
const char * rlFindFile(const char *pattern, int *context)
int rlStat(const char *filepath, struct stat *buf)
int rlStartsWith(const char *str, const char *startstr)
int rlsnprintf(char *text, int len, const char *format,...)
static void rlSigtermHandler(int sig)
int rlBitChange(int bitnumber, int *value)
int rlsystem(const char *command)
int rlProfibus2(int command)
int rlIntOption(const char *string, const char *option, int def)
int rlOption(const char *string, const char *option)