26 #include <sys/types.h>
39 #include <lib$routines.h>
47 #include <sys\types.h>
70 if(ret < 0)
return ret;
71 return printf(
"%s",message);
83 if(ret < 0)
return ret;
87 for(i=strlen(message); i<80; i++) printf(
" ");
99 buf =
new char [strlen(command)+1];
103 while(buf[i] !=
'\0')
108 arg[iarg++] = &buf[i];
109 while(buf[i] !=
'\"' && buf[i] !=
'\0') i++;
110 if(buf[i] ==
'\0')
break;
113 else if(buf[i] !=
' ' || i == 0)
115 arg[iarg++] = &buf[i];
116 while(buf[i] !=
' ' && buf[i] !=
'\0') i++;
117 if(buf[i] ==
'\0')
break;
124 ret = execvp(arg[0],arg);
133 static char ret[4*16+8];
138 for(i=0; p[i] !=
'\0' && i<=16; i++)
141 sprintf(buf,
"%04X",val);
155 if(source[i] ==
'\0')
break;
163 int rlvsnprintf(
char *text,
int len,
const char *format, va_list ap)
168 if(format == NULL || format[0] ==
'\0')
173 ret = _vsnprintf(text, len, format, ap);
177 if(format == NULL || format[0] ==
'\0')
182 ret = vsprintf(vms_is_deprecated, format, ap);
186 if(format == NULL || format[0] ==
'\0')
191 ret = vsnprintf(text, len, format, ap);
204 ret = _vsnprintf(text, len, format, ap);
208 ret = vsprintf(vms_is_deprecated, format, ap);
212 ret = vsnprintf(text, len, format, ap);
224 printf(
"entering rlSigtermHandler sig=%d\n",sig);
228 fsync(fileno(stdout));
243 static char freturn[512];
247 static struct dirent *dp;
249 if(*context == 0) dirp = opendir(
".");
252 while((dp = readdir(dirp)) != NULL)
254 if(dp->d_name[0] ==
'.') ;
255 else if(strstr(dp->d_name,pattern) != NULL)
257 strcpy(freturn,dp->d_name);
262 strcpy(freturn,dp->d_name);
272 static char file[512] =
"";
273 static char wildcard[80];
274 struct dsc$descriptor_s dwildcard;
275 struct dsc$descriptor_s dfreturn;
277 strcpy(wildcard,pattern);
279 dwildcard.dsc$w_length = strlen(wildcard);
280 dwildcard.dsc$a_pointer = wildcard;
281 dwildcard.dsc$b_dtype = DSC$K_DTYPE_T;
282 dwildcard.dsc$b_class = DSC$K_CLASS_S;
284 dfreturn.dsc$w_length =
sizeof(freturn);
285 dfreturn.dsc$a_pointer = &freturn[0];
286 dfreturn.dsc$b_dtype = DSC$K_DTYPE_T;
287 dfreturn.dsc$b_class = DSC$K_CLASS_S;
289 ret = LIB$FIND_FILE(&dwildcard,&dfreturn,context,0,0,0,0);
290 if (ret == RMS$_NMF)
return NULL;
291 else if(ret != RMS$_NORMAL)
return NULL;
292 else if(strcmp(freturn,file) == 0) { file[0] =
'\0';
return NULL; }
294 while(freturn[i] >
' ')i++;
300 static WIN32_FIND_DATAA wfd;
301 static HANDLE hFindFile;
306 hFindFile = FindFirstFileA(pattern,&wfd);
307 if(hFindFile == INVALID_HANDLE_VALUE)
return NULL;
308 else strcpy(freturn,(
const char *) &wfd.cFileName);
312 if(FindNextFileA(hFindFile,&wfd) == TRUE) strcpy(freturn,(
const char *) &wfd.cFileName);
313 else { FindClose(hFindFile);
return NULL; }
322 static char buf[1024];
325 strcpy(buf,getenv(
"HOME"));
329 strcpy(buf,
"sys$login:");
332 ExpandEnvironmentStringsA(
"%USERPROFILE%",buf,
sizeof(buf)-1);
333 if(strcmp(buf,
"%USERPROFILE%") == 0) strcpy(buf,
"C:");
343 return (val & 0x0ff)*256 + val/256;
351 sprintf(buf,
"buscommand -eib1 %d",command);
359 sprintf(buf,
"buscommand -eib2 %d",command);
367 sprintf(buf,
"buscommand -lon1 %d",command);
375 sprintf(buf,
"buscommand -lon2 %d",command);
383 sprintf(buf,
"buscommand -profibus1 %d",command);
391 sprintf(buf,
"buscommand -profibus2 %d",command);
399 sprintf(buf,
"buscommand -can1 %d",command);
407 sprintf(buf,
"buscommand -can2 %d",command);
414 HKEY applications,iexplore,shell,open,command;
416 unsigned long size,type;
426 if(ret != ERROR_SUCCESS)
436 if(ret != ERROR_SUCCESS)
438 RegCloseKey(applications);
447 if(ret != ERROR_SUCCESS)
449 RegCloseKey(applications);
450 RegCloseKey(iexplore);
459 if(ret != ERROR_SUCCESS)
461 RegCloseKey(applications);
462 RegCloseKey(iexplore);
472 if(ret != ERROR_SUCCESS)
474 RegCloseKey(applications);
475 RegCloseKey(iexplore);
481 ret = RegQueryValueExA(
486 (
unsigned char *) buf,
490 RegCloseKey(applications);
491 RegCloseKey(iexplore);
494 RegCloseKey(command);
496 if(ret != ERROR_SUCCESS)
return -1;
498 cptr = strstr(buf,
" %1");
499 if(cptr != NULL) *cptr =
'\0';
507 STARTUPINFOA si = {
sizeof(si)};
508 PROCESS_INFORMATION pi;
512 ExpandEnvironmentStringsA(command,cmd,
sizeof(cmd)-1);
513 ret = (int) CreateProcessA( NULL, cmd
515 , FALSE, CREATE_NO_WINDOW
527 return system(command);
531 int rlSubmitPvserver(
const char *env,
const char *path,
const char *pvs,
const char *options)
533 if(env == NULL || path == NULL || pvs == NULL)
return -1;
541 command =
"spawn/nowait ";
545 if(options != NULL) command += options;
550 if(cptr == NULL) { printf(
"rlSubmitPvserver:ERROR env=%s is not set\n", env);
return -2; }
562 if(options != NULL) command += options;
563 command +=
" \"-cd=";
583 sprintf(buf,
"konqueror %s &", htmlfile);
589 strcat(buf,htmlfile);
595 int rlOption(
const char *
string,
const char *option)
599 cptr = strstr(
string,option);
600 if(cptr == NULL)
return 0;
609 cptr = strstr(
string,option);
610 if(cptr == NULL)
return def;
612 cptr = strstr(cptr,
"=");
613 if(cptr == NULL)
return def;
615 sscanf(cptr,
"=%d",&ret);
624 cptr = strstr(
string,option);
625 if(cptr == NULL)
return def;
627 cptr = strstr(cptr,
"=");
628 if(cptr == NULL)
return def;
630 sscanf(cptr,
"=%f",&ret);
634 const char *
rlTextOption(
const char *
string,
const char *option,
const char *def)
641 cptr = strstr(
string,option);
642 if(cptr == NULL)
return def;
644 cptr = strstr(cptr,
"=");
645 if(cptr == NULL)
return def;
650 while(i < ((
int)
sizeof(ret)-1))
652 if(cptr[i] == quote || cptr[i] ==
'\0')
break;
664 if(source == NULL || destination == NULL)
return -1;
665 fin = fopen(source,
"r");
668 printf(
"rlCopyTextfile: could not read %s\n",source);
671 fout = fopen(destination,
"w");
675 printf(
"rlCopyTextfile: could not write %s\n",destination);
679 char *line =
new char[256*256];
680 while(fgets(line,
sizeof(line)-1,fin) != NULL)
682 fprintf(fout,
"%s",line);
693 if(str == NULL)
return -1;
696 *str = toupper(*str);
704 if(str == NULL)
return -1;
707 *str = tolower(*str);
716 if(str == NULL || startstr == NULL)
return 0;
717 ret = strncmp(str,startstr,strlen(startstr));
718 if(ret == 0)
return 1;
724 if(strstr(str,wild) != NULL)
return 1;
728 for(i=0; str[i] !=
'\0'; i++)
732 while(wild[w] ==
'*') w++;
733 if(wild[w] ==
'\0')
return 1;
735 if(wild[w] ==
'\0')
return 0;
736 while(str[i] != wild[w] && str[i] !=
'\0') i++;
737 if(str[i] ==
'\0')
return 0;
738 while(str[i] !=
'\0')
740 if(str[i] != wild[w])
goto try_next;
743 if(str[i] ==
'\0' && wild[w] ==
'\0')
return 1;
745 if(wild[w] !=
'\0')
return 0;
750 if(str[i] != wild[w])
return 0;
757 int rlStat(
const char *filepath,
struct stat *buf)
759 return stat(filepath, buf);
765 int ret = CreateDirectoryA(dir,NULL);
769 return mkdir(dir, mode);
775 int bit = 1 << bitnumber;
776 *value = *value | bit;
782 int bit = 1 << bitnumber;
784 *value = *value & bit;
790 int bit = 1 << bitnumber;
791 *value = *value ^ bit;
797 int bit = 1 << bitnumber;
798 if(*value & bit)
return 1;