rllib  1
rlcutil.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  rlcutil.cpp - description
3  -------------------
4  begin : Wed Dec 11 2002
5  copyright : (C) 2002 by R. Lehrig
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13  * published by the Free Software Foundation *
14  * *
15  ***************************************************************************/
16 #include "rlcutil.h"
17 #include "rlstring.h"
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <stdarg.h>
22 #include <signal.h>
23 
24 #ifdef RLUNIX
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <sys/select.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <dirent.h>
31 #endif
32 
33 #ifdef __VMS
34 #include <descrip.h>
35 #include <rmsdef.h>
36 #include <ssdef.h>
37 #include <iodef.h>
38 #include <unixio.h>
39 #include <file.h>
40 #include <lib$routines.h>
41 #endif
42 
43 #ifdef RLWIN32
44 #include <windows.h>
45 #include <winreg.h>
46 #include <fcntl.h>
47 #include <io.h>
48 #include <sys\types.h>
49 #include <sys\stat.h>
50 #endif
51 
53 
54 int rlSetDebugPrintf(int state)
55 {
56  if(state == 0) rlDebugPrintfState = 0;
57  else rlDebugPrintfState = 1;
58  return 0;
59 }
60 
61 int rlDebugPrintf(const char *format, ...)
62 {
63  int ret;
64  char message[rl_PRINTF_LENGTH]; // should be big enough
65 
66  if(rlDebugPrintfState == 0) return 0;
67  va_list ap;
68  va_start(ap,format);
69  ret = rlvsnprintf(message, rl_PRINTF_LENGTH - 1, format, ap);
70  va_end(ap);
71  if(ret < 0) return ret;
72  return printf("%s",message);
73 }
74 
76 {
77  struct timeval timout;
78  fd_set wset,rset,eset;
79  int ret,maxfdp1;
80  int s = 0;
81  /* setup sockets to read */
82  maxfdp1 = s+1;
83  FD_ZERO(&rset);
84  FD_SET (s,&rset);
85  FD_ZERO(&wset);
86  FD_ZERO(&eset);
87  timout.tv_sec = 0;
88  timout.tv_usec = 0;
89  ret = ::select(maxfdp1,&rset,&wset,&eset,&timout);
90  if(ret == 0) return 0; /* timeout */
91  return 1;
92 }
93 
94 int rlLastLinePrintf(const char *format, ...)
95 {
96  int ret,i;
97  char message[rl_PRINTF_LENGTH]; // should be big enough
98 
99  va_list ap;
100  va_start(ap,format);
101  ret = rlvsnprintf(message, rl_PRINTF_LENGTH - 1, format, ap);
102  va_end(ap);
103  if(ret < 0) return ret;
104  message[79] = '\0';
105  printf("%c[80D",27); // move 80 columns left
106  printf("%s",message);
107  for(i=strlen(message); i<80; i++) printf(" ");
108  return 80;
109 }
110 
111 #ifdef RLUNIX
112 //------------------------------------------------------------------------
113 int rlexec(const char *command)
114 {
115  char *buf;
116  char *arg[512];
117  int i,iarg,ret;
118 
119  buf = new char [strlen(command)+1];
120  strcpy(buf,command);
121  iarg = 0;
122  i = 0;
123  while(buf[i] != '\0')
124  {
125  if(buf[i] == '\"')
126  {
127  i++;
128  arg[iarg++] = &buf[i];
129  while(buf[i] != '\"' && buf[i] != '\0') i++;
130  if(buf[i] == '\0') break;
131  buf[i] = '\0';
132  }
133  else if(buf[i] != ' ' || i == 0)
134  {
135  arg[iarg++] = &buf[i];
136  while(buf[i] != ' ' && buf[i] != '\0') i++;
137  if(buf[i] == '\0') break;
138  buf[i] = '\0';
139  }
140  i++;
141  }
142  arg[iarg] = NULL;
143 
144  ret = execvp(arg[0],arg);
145  delete [] buf;
146  return ret;
147 }
148 #endif
149 
150 //------------------------------------------------------------------------
151 const char *rlpass(const char *p)
152 {
153  static char ret[4*16+8];
154  char buf[80];
155  int i,val;
156 
157  ret[0] = '\0';
158  for(i=0; p[i] != '\0' && i<=16; i++)
159  {
160  val = p[i] * 16;
161  sprintf(buf,"%04X",val);
162  strcat(ret,buf);
163  }
164 
165  return ret;
166 }
167 
168 //------------------------------------------------------------------------
169 char *rlstrncpy(char *dest, const char *source, int n)
170 {
171  int i;
172 
173  for(i=0; i<n; i++)
174  {
175  if(source[i] == '\0') break;
176  dest[i] = source[i];
177  }
178  dest[i] = '\0';
179  return dest;
180 }
181 
182 char *rlstrlinecpy(char *dest, const char *source, int n)
183 {
184  int i;
185 
186  for(i=0; i<n; i++)
187  {
188  if(source[i] == '\0') break;
189  if(source[i] == '\n') break;
190  dest[i] = source[i];
191  }
192  dest[i] = '\0';
193  return dest;
194 }
195 
196 //------------------------------------------------------------------------
197 int rlvsnprintf(char *text, int len, const char *format, va_list ap)
198 {
199  int ret;
200 
201 #ifdef RLWIN32
202  if(format == NULL || format[0] == '\0')
203  {
204  text[0] = '\0';
205  return 1;
206  }
207  ret = _vsnprintf(text, len, format, ap);
208 #endif
209 #ifdef __VMS
210  static char vms_is_deprecated[rl_PRINTF_LENGTH];
211  if(format == NULL || format[0] == '\0')
212  {
213  text[0] = '\0';
214  return 1;
215  }
216  ret = vsprintf(vms_is_deprecated, format, ap);
217  rlstrncpy(text,vms_is_deprecated,len);
218 #endif
219 #ifdef RLUNIX
220  if(format == NULL || format[0] == '\0')
221  {
222  text[0] = '\0';
223  return 1;
224  }
225  ret = vsnprintf(text, len, format, ap);
226 #endif
227  return ret;
228 }
229 
230 //------------------------------------------------------------------------
231 int rlsnprintf(char *text, int len, const char *format, ...)
232 {
233  int ret;
234 
235  va_list ap;
236  va_start(ap,format);
237 #ifdef RLWIN32
238  ret = _vsnprintf(text, len, format, ap);
239 #endif
240 #ifdef __VMS
241  static char vms_is_deprecated[rl_PRINTF_LENGTH];
242  ret = vsprintf(vms_is_deprecated, format, ap);
243  rlstrncpy(text,vms_is_deprecated,len);
244 #endif
245 #ifdef RLUNIX
246  ret = vsnprintf(text, len, format, ap);
247 #endif
248  va_end(ap);
249  return ret;
250 }
251 
252 //------------------------------------------------------------------------
253 static void *rlsigtermarg = NULL;
254 static void (*rlUserSigtermHandler)(void *arg) = NULL;
255 
256 static void rlSigtermHandler(int sig)
257 {
258  printf("entering rlSigtermHandler sig=%d\n",sig);
259  if(sig == SIGTERM && rlUserSigtermHandler != NULL) rlUserSigtermHandler(rlsigtermarg);
260 #ifdef RLUNIX
261  fflush(stdout);
262  fsync(fileno(stdout));
263 #endif
264  exit(0);
265 }
266 
267 void rlSetSigtermHandler(void (*handler)(void *arg), void *arg)
268 {
269  rlsigtermarg = arg;
270  rlUserSigtermHandler = handler;
271  signal(SIGTERM,rlSigtermHandler);
272 }
273 
274 //------------------------------------------------------------------------
275 const char *rlFindFile(const char *pattern, int *context)
276 {
277  static char freturn[512];
278 
279 #ifdef RLUNIX
280  static DIR *dirp;
281  static struct dirent *dp;
282 
283  if(*context == 0) dirp = opendir(".");
284  *context = 1;
285 
286  while((dp = readdir(dirp)) != NULL)
287  {
288  if(dp->d_name[0] == '.') ;
289  else if(strstr(dp->d_name,pattern) != NULL)
290  {
291  strcpy(freturn,dp->d_name);
292  return freturn;
293  }
294  else if(rlStrMatch(dp->d_name, pattern))
295  {
296  strcpy(freturn,dp->d_name);
297  return freturn;
298  }
299  }
300  closedir(dirp);
301  return NULL;
302 #endif
303 
304 #ifdef __VMS
305  int i,ret;
306  static char file[512] = "";
307  static char wildcard[80];
308  struct dsc$descriptor_s dwildcard;
309  struct dsc$descriptor_s dfreturn;
310 
311  strcpy(wildcard,pattern);
312 
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;
317 
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;
322 
323  ret = LIB$FIND_FILE(&dwildcard,&dfreturn,context,0,0,0,0);
324  if (ret == RMS$_NMF) return NULL; // no more files found
325  else if(ret != RMS$_NORMAL) return NULL;
326  else if(strcmp(freturn,file) == 0) { file[0] = '\0'; return NULL; }
327  i=0;
328  while(freturn[i] > ' ')i++;
329  freturn[i] = '\0';
330  return freturn;
331 #endif
332 
333 #ifdef RLWIN32
334  static WIN32_FIND_DATAA wfd;
335  static HANDLE hFindFile;
336 
337  if(*context == 0) // find first
338  {
339  *context = 1;
340  hFindFile = FindFirstFileA(pattern,&wfd);
341  if(hFindFile == INVALID_HANDLE_VALUE) return NULL;
342  else strcpy(freturn,(const char *) &wfd.cFileName);
343  }
344  else // subsequent find
345  {
346  if(FindNextFileA(hFindFile,&wfd) == TRUE) strcpy(freturn,(const char *) &wfd.cFileName);
347  else { FindClose(hFindFile); return NULL; }
348  }
349  return freturn;
350 #endif
351 }
352 
353 //------------------------------------------------------------------------
354 const char *rlGetInifile(const char *name)
355 {
356  static char buf[1024];
357 
358 #ifdef RLUNIX
359  strcpy(buf,getenv("HOME"));
360  strcat(buf,"/.");
361 #endif
362 #ifdef __VMS
363  strcpy(buf,"sys$login:");
364 #endif
365 #ifdef RLWIN32
366  ExpandEnvironmentStringsA("%USERPROFILE%",buf,sizeof(buf)-1);
367  if(strcmp(buf,"%USERPROFILE%") == 0) strcpy(buf,"C:");
368  strcat(buf,"\\");;
369 #endif
370 
371  strcat(buf,name);
372  return buf;
373 }
374 
375 int rlSwapShort(int val)
376 {
377  return (val & 0x0ff)*256 + val/256;
378 }
379 
380 //------------------------------------------------------------------------
381 int rlEib1(int command)
382 {
383  char buf[80];
384 
385  sprintf(buf,"buscommand -eib1 %d",command);
386  return system(buf);
387 }
388 
389 int rlEib2(int command)
390 {
391  char buf[80];
392 
393  sprintf(buf,"buscommand -eib2 %d",command);
394  return system(buf);
395 }
396 
397 int rlLon1(int command)
398 {
399  char buf[80];
400 
401  sprintf(buf,"buscommand -lon1 %d",command);
402  return system(buf);
403 }
404 
405 int rlLon2(int command)
406 {
407  char buf[80];
408 
409  sprintf(buf,"buscommand -lon2 %d",command);
410  return system(buf);
411 }
412 
413 int rlProfibus1(int command)
414 {
415  char buf[80];
416 
417  sprintf(buf,"buscommand -profibus1 %d",command);
418  return system(buf);
419 }
420 
421 int rlProfibus2(int command)
422 {
423  char buf[80];
424 
425  sprintf(buf,"buscommand -profibus2 %d",command);
426  return system(buf);
427 }
428 
429 int rlCan1(int command)
430 {
431  char buf[80];
432 
433  sprintf(buf,"buscommand -can1 %d",command);
434  return system(buf);
435 }
436 
437 int rlCan2(int command)
438 {
439  char buf[80];
440 
441  sprintf(buf,"buscommand -can2 %d",command);
442  return system(buf);
443 }
444 
445 #ifdef RLWIN32
446 static int get_iexplore(char *buf)
447 {
448  HKEY applications,iexplore,shell,open,command;
449  long ret;
450  unsigned long size,type;
451  char *cptr;
452 
453  buf[0] = '\0';
454 
455  ret = RegOpenKeyA(
456  HKEY_CLASSES_ROOT, // handle to open key
457  "Applications", // address of name of subkey to open
458  &applications // address of handle to open key
459  );
460  if(ret != ERROR_SUCCESS)
461  {
462  return -1;
463  }
464 
465  ret = RegOpenKeyA(
466  applications, // handle to open key
467  "iexplore.exe", // address of name of subkey to open
468  &iexplore // address of handle to open key
469  );
470  if(ret != ERROR_SUCCESS)
471  {
472  RegCloseKey(applications);
473  return -1;
474  }
475 
476  ret = RegOpenKeyA(
477  iexplore, // handle to open key
478  "shell", // address of name of subkey to open
479  &shell // address of handle to open key
480  );
481  if(ret != ERROR_SUCCESS)
482  {
483  RegCloseKey(applications);
484  RegCloseKey(iexplore);
485  return -1;
486  }
487 
488  ret = RegOpenKeyA(
489  shell, // handle to open key
490  "open", // address of name of subkey to open
491  &open // address of handle to open key
492  );
493  if(ret != ERROR_SUCCESS)
494  {
495  RegCloseKey(applications);
496  RegCloseKey(iexplore);
497  RegCloseKey(shell);
498  return -1;
499  }
500 
501  ret = RegOpenKeyA(
502  open, // handle to open key
503  "command", // address of name of subkey to open
504  &command // address of handle to open key
505  );
506  if(ret != ERROR_SUCCESS)
507  {
508  RegCloseKey(applications);
509  RegCloseKey(iexplore);
510  RegCloseKey(shell);
511  RegCloseKey(open);
512  return -1;
513  }
514 
515  ret = RegQueryValueExA(
516  command, // handle to key to query
517  "", // address of name of value to query
518  NULL, // reserved
519  &type, // address of buffer for value type
520  (unsigned char *) buf, // address of data buffer
521  &size // address of data buffer size
522  );
523 
524  RegCloseKey(applications);
525  RegCloseKey(iexplore);
526  RegCloseKey(shell);
527  RegCloseKey(open);
528  RegCloseKey(command);
529 
530  if(ret != ERROR_SUCCESS) return -1;
531 
532  cptr = strstr(buf," %1");
533  if(cptr != NULL) *cptr = '\0';
534 
535  return 0;
536 }
537 
538 static int mysystem(const char *command)
539 {
540  int ret;
541  STARTUPINFOA si; // = { sizeof(si)};
542  memset(&si, 0, sizeof(si));
543  si.cb = sizeof(si);
544  PROCESS_INFORMATION pi;
545  char cmd[4096];
546 
547  //strcpy(cmd,command);
548  ExpandEnvironmentStringsA(command,cmd,sizeof(cmd)-1);
549  ret = (int) CreateProcessA( NULL, cmd
550  , NULL, NULL
551  , FALSE, CREATE_NO_WINDOW
552  , NULL, NULL
553  , &si, &pi);
554  return ret;
555 }
556 #endif
557 
558 int rlsystem(const char *command)
559 {
560 #ifdef RLWIN32
561  return mysystem(command);
562 #else
563  return system(command);
564 #endif
565 }
566 
567 int rlSubmitPvserver(const char *env, const char *path, const char *pvs, const char *options)
568 {
569  if(env == NULL || path == NULL || pvs == NULL) return -1;
570  rlString command,cd;
571  const char *cptr;
572 
573 #ifdef __VMS
574  cptr = env;
575  cd = cptr;
576  cd += path;
577  command = "spawn/nowait ";
578  command += cd;
579  command += pvs;
580  command += " ";
581  if(options != NULL) command += options;
582  command += " -cd=";
583  command += cd;
584 #else
585  cptr = getenv(env);
586  if(cptr == NULL) { printf("rlSubmitPvserver:ERROR env=%s is not set\n", env); return -2; }
587  cd += cptr;
588  cd += path;
589  command = "\"";
590  command += cd;
591 #ifdef RLWIN32
592  command += "\\";
593 #else
594  command += "/";
595 #endif
596  command += pvs;
597  command += "\" ";
598  if(options != NULL) command += options;
599  command += " \"-cd=";
600  command += cd;
601  command += "\"";
602 #endif
603 
604 #ifdef RLUNIX
605  command += " &";
606 #endif
607 
608  //printf("command=%s\n", command.text());
609  return rlsystem(command.text());
610  //example: rlSubmitPvserver("HOME","/temp/murx","pvs","-exit_on_bind_error -exit_after_last_client_terminates");
611 }
612 
613 int rlBrowser(const char *htmlfile)
614 {
615  char buf[4096];
616  int ret = 0;
617 
618 #ifdef RLUNIX
619  sprintf(buf,"konqueror %s &", htmlfile);
620  ret = system(buf);
621 #endif
622 #ifdef RLWIN32
623  if(get_iexplore(buf) < 0) return -1;
624  strcat(buf," ");
625  strcat(buf,htmlfile);
626  ret = mysystem(buf);
627 #endif
628  return ret;
629 }//------------------------------------------------------------------------
630 
631 int rlOption(const char *string, const char *option)
632 {
633  const char *cptr;
634 
635  cptr = strstr(string,option);
636  if(cptr == NULL) return 0;
637  return 1;
638 }
639 
640 int rlIntOption(const char *string, const char *option, int def)
641 {
642  const char *cptr;
643  int ret;
644 
645  cptr = strstr(string,option);
646  if(cptr == NULL) return def;
647 
648  cptr = strstr(cptr,"=");
649  if(cptr == NULL) return def;
650 
651  sscanf(cptr,"=%d",&ret);
652  return ret;
653 }
654 
655 float rlFloatOption(const char *string, const char *option, float def)
656 {
657  const char *cptr;
658  float ret;
659 
660  cptr = strstr(string,option);
661  if(cptr == NULL) return def;
662 
663  cptr = strstr(cptr,"=");
664  if(cptr == NULL) return def;
665 
666  sscanf(cptr,"=%f",&ret);
667  return ret;
668 }
669 
670 const char *rlTextOption(const char *string, const char *option, const char *def)
671 {
672  int i = 0;
673  const char *cptr;
674  char quote;
675  static char ret[rl_PRINTF_LENGTH];
676 
677  cptr = strstr(string,option);
678  if(cptr == NULL) return def;
679 
680  cptr = strstr(cptr,"=");
681  if(cptr == NULL) return def;
682 
683  cptr++;
684  quote = *cptr;
685  cptr++;
686  while(i < ((int) sizeof(ret)-1))
687  {
688  if(cptr[i] == quote || cptr[i] == '\0') break;
689  ret[i] = cptr[i];
690  i++;
691  }
692  ret[i] = '\0';
693  return ret;
694 }
695 
696 int rlCopyTextfile(const char *source, const char *destination)
697 {
698  FILE *fin, *fout;
699 
700  if(source == NULL || destination == NULL) return -1;
701  fin = fopen(source,"r");
702  if(fin == NULL)
703  {
704  printf("rlCopyTextfile: could not read %s\n",source);
705  return -1;
706  }
707  fout = fopen(destination,"w");
708  if(fout == NULL)
709  {
710  fclose(fin);
711  printf("rlCopyTextfile: could not write %s\n",destination);
712  return -1;
713  }
714 
715  char *line = new char[256*256];
716  while(fgets(line,sizeof(line)-1,fin) != NULL)
717  {
718  fprintf(fout,"%s",line);
719  }
720  delete [] line;
721 
722  fclose(fin);
723  fclose(fout);
724  return 0;
725 }
726 
727 int rlupper(char *str)
728 {
729  if(str == NULL) return -1;
730  while(*str != '\0')
731  {
732  *str = toupper(*str);
733  str++;
734  }
735  return 0;
736 }
737 
738 int rllower(char *str)
739 {
740  if(str == NULL) return -1;
741  while(*str != '\0')
742  {
743  *str = tolower(*str);
744  str++;
745  }
746  return 0;
747 }
748 
749 int rlStartsWith(const char *str, const char *startstr)
750 {
751  int ret;
752  if(str == NULL || startstr == NULL) return 0;
753  ret = strncmp(str,startstr,strlen(startstr));
754  if(ret == 0) return 1;
755  return 0;
756 }
757 
758 int rlEndsWith(const char *str, const char *endstr)
759 {
760  int ret;
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;
766  return 0;
767 }
768 
769 int rlStrMatch(const char *str, const char *wild)
770 {
771  if(strstr(str,wild) != NULL) return 1;
772  int i,w;
773 
774  w = 0;
775  for(i=0; str[i] != '\0'; i++)
776  {
777  if(wild[w] == '*')
778  {
779  while(wild[w] == '*') w++;
780  if(wild[w] == '\0') return 1;
781 try_next:
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')
786  {
787  if(str[i] != wild[w]) goto try_next;
788  i++;
789  w++;
790  if(str[i] == '\0' && wild[w] == '\0') return 1;
791  }
792  if(wild[w] != '\0') return 0;
793  return 1;
794  }
795  else
796  {
797  if(str[i] != wild[w]) return 0;
798  }
799  w++;
800  }
801  return 1;
802 }
803 
804 int rlStat(const char *filepath, struct stat *buf)
805 {
806  return stat(filepath, buf);
807 }
808 
809 int rlFRead(FILE *fin, void *data, int len)
810 {
811  if(fin == NULL) return -1;
812  return fread(data,1,len,fin);
813 }
814 
815 int rlFWrite(FILE *fout, void *data, int len)
816 {
817  if(fout == NULL) return -1;
818  return fwrite(data,1,len,fout);
819 }
820 
821 int rlWriteFile(const char *filename, void *data, int len)
822 {
823  FILE *fout = fopen(filename,"w");
824  if(fout == NULL)
825  {
826  printf("ERROR: rlWriteFile() could not write to %s\n", filename);
827  return -1;
828  }
829  int ret = fwrite(data,1,len,fout);
830  fclose(fout);
831  return ret;
832 }
833 
834 int rlMkdir(const char *dir, int mode)
835 {
836 #ifdef RLWIN32
837  int ret = CreateDirectoryA(dir,NULL);
838  if(ret) return 0;
839  if(mode) return -1;
840  return -1;
841 #else
842  return mkdir(dir, mode);
843 #endif
844 }
845 
846 int rlBitSet(int bitnumber, int *value)
847 {
848  int bit = 1 << bitnumber;
849  *value = *value | bit;
850  return *value;
851 }
852 
853 int rlBitClear(int bitnumber, int *value)
854 {
855  int bit = 1 << bitnumber;
856  bit = ~bit;
857  *value = *value & bit;
858  return *value;
859 }
860 
861 int rlBitChange(int bitnumber, int *value)
862 {
863  int bit = 1 << bitnumber;
864  *value = *value ^ bit;
865  return *value;
866 }
867 
868 int rlBitTest(int bitnumber, int *value)
869 {
870  int bit = 1 << bitnumber;
871  if(*value & bit) return 1;
872  return 0;
873 }
874 
875 void rlPushToDoubleBuffer(double val, double *buffer, int size)
876 {
877  if(size <= 0) return;
878  for(int i=size; i>=2; i--) buffer[i-1] = buffer[i-2];
879  buffer[0] = val;
880 }
881 
882 void rlPushToFloatBuffer(float val, float *buffer, int size)
883 {
884  if(size <= 0) return;
885  for(int i=size; i>=2; i--) buffer[i-1] = buffer[i-2];
886  buffer[0] = val;
887 }
888 
int rlDebugPrintf(const char *format,...)
Definition: rlcutil.cpp:61
int rlFRead(FILE *fin, void *data, int len)
Definition: rlcutil.cpp:809
static void(* rlUserSigtermHandler)(void *arg)
Definition: rlcutil.cpp:254
int rlEib1(int command)
Definition: rlcutil.cpp:381
int rlProfibus1(int command)
Definition: rlcutil.cpp:413
void rlPushToFloatBuffer(float val, float *buffer, int size)
Definition: rlcutil.cpp:882
int rlSetDebugPrintf(int state)
Definition: rlcutil.cpp:54
int rlMkdir(const char *dir, int mode)
Definition: rlcutil.cpp:834
float rlFloatOption(const char *string, const char *option, float def)
Definition: rlcutil.cpp:655
const char * rlpass(const char *p)
Definition: rlcutil.cpp:151
int rlBrowser(const char *htmlfile)
Definition: rlcutil.cpp:613
char * rlstrlinecpy(char *dest, const char *source, int n)
Definition: rlcutil.cpp:182
static void * rlsigtermarg
Definition: rlcutil.cpp:253
int rlSwapShort(int val)
Definition: rlcutil.cpp:375
int rllower(char *str)
Definition: rlcutil.cpp:738
int rlEib2(int command)
Definition: rlcutil.cpp:389
int rlWriteFile(const char *filename, void *data, int len)
Definition: rlcutil.cpp:821
int rlCopyTextfile(const char *source, const char *destination)
Definition: rlcutil.cpp:696
void rlSetSigtermHandler(void(*handler)(void *arg), void *arg)
Definition: rlcutil.cpp:267
#define rl_PRINTF_LENGTH
Definition: rldefine.h:71
int rlFWrite(FILE *fout, void *data, int len)
Definition: rlcutil.cpp:815
void rlPushToDoubleBuffer(double val, double *buffer, int size)
Definition: rlcutil.cpp:875
int rlDebugPrintfState
Definition: rlcutil.cpp:52
int rlLastLinePrintf(const char *format,...)
Definition: rlcutil.cpp:94
char * text()
Definition: rlstring.cpp:126
int rlBitSet(int bitnumber, int *value)
Definition: rlcutil.cpp:846
int rlexec(const char *command)
Definition: rlcutil.cpp:113
int rlEndsWith(const char *str, const char *endstr)
Definition: rlcutil.cpp:758
static int get_iexplore(char *buf)
Definition: rlcutil.cpp:446
int rlStrMatch(const char *str, const char *wild)
Definition: rlcutil.cpp:769
int rlInputAvailable()
Definition: rlcutil.cpp:75
int rlvsnprintf(char *text, int len, const char *format, va_list ap)
Definition: rlcutil.cpp:197
int rlBitClear(int bitnumber, int *value)
Definition: rlcutil.cpp:853
static int mysystem(const char *command)
Definition: rlcutil.cpp:538
char * rlstrncpy(char *dest, const char *source, int n)
Definition: rlcutil.cpp:169
int rlCan1(int command)
Definition: rlcutil.cpp:429
const char * rlGetInifile(const char *name)
Definition: rlcutil.cpp:354
int rlLon1(int command)
Definition: rlcutil.cpp:397
int rlSubmitPvserver(const char *env, const char *path, const char *pvs, const char *options)
Definition: rlcutil.cpp:567
int rlCan2(int command)
Definition: rlcutil.cpp:437
int rlLon2(int command)
Definition: rlcutil.cpp:405
const char * rlTextOption(const char *string, const char *option, const char *def)
Definition: rlcutil.cpp:670
int rlBitTest(int bitnumber, int *value)
Definition: rlcutil.cpp:868
const char * rlFindFile(const char *pattern, int *context)
Definition: rlcutil.cpp:275
int rlStat(const char *filepath, struct stat *buf)
Definition: rlcutil.cpp:804
int rlStartsWith(const char *str, const char *startstr)
Definition: rlcutil.cpp:749
int rlsnprintf(char *text, int len, const char *format,...)
Definition: rlcutil.cpp:231
static void rlSigtermHandler(int sig)
Definition: rlcutil.cpp:256
int rlBitChange(int bitnumber, int *value)
Definition: rlcutil.cpp:861
int rlsystem(const char *command)
Definition: rlcutil.cpp:558
int rlupper(char *str)
Definition: rlcutil.cpp:727
int rlProfibus2(int command)
Definition: rlcutil.cpp:421
int rlIntOption(const char *string, const char *option, int def)
Definition: rlcutil.cpp:640
int rlOption(const char *string, const char *option)
Definition: rlcutil.cpp:631