]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
Functions to transform strings to fixed length and maybe ansi-conform characters.
authorhades <hades>
Thu, 18 May 2000 21:31:01 +0000 (21:31 +0000)
committerhades <hades>
Thu, 18 May 2000 21:31:01 +0000 (21:31 +0000)
hadaq/hwtapechar.c [new file with mode: 0644]
hadaq/hwtapechar.h [new file with mode: 0644]

diff --git a/hadaq/hwtapechar.c b/hadaq/hwtapechar.c
new file mode 100644 (file)
index 0000000..8beecf5
--- /dev/null
@@ -0,0 +1,185 @@
+#include "hwtapechar.h"
+
+const char *ansichar(const char *s, int length) {
+       char *r;
+       int i, end;
+       end = 0;
+       *r = *s;
+       for(i=0 ; i<length ; i++) {
+               if (end == 0) {
+                       switch (s[i]) {
+                               case ('A'):
+                               case ('B'):
+                               case ('C'):
+                               case ('D'):
+                               case ('E'):
+                               case ('F'):
+                               case ('G'):
+                               case ('H'):
+                               case ('I'):
+                               case ('J'):
+                               case ('K'):
+                               case ('L'):
+                               case ('M'):
+                               case ('N'):
+                               case ('O'):
+                               case ('P'):
+                               case ('Q'):
+                               case ('R'):
+                               case ('S'):
+                               case ('T'):
+                               case ('U'):
+                               case ('V'):
+                               case ('W'):
+                               case ('X'):
+                               case ('Y'):
+                               case ('Z'):
+       
+                               case ('0'):
+                               case ('1'):
+                               case ('2'):
+                               case ('3'):
+                               case ('4'):
+                               case ('5'):
+                               case ('6'):
+                               case ('7'):
+                               case ('8'):
+                               case ('9'):
+       
+                               case (' '):
+                               case ('!'):
+                               case ('"'):
+                               case ('%'):
+                               case ('&'):
+                               case ('\''):
+                               case ('('):
+                               case (')'):
+                               case ('*'):
+                               case ('+'):
+                               case (','):
+                               case ('-'):
+                               case ('_'):
+                               case ('.'):
+                               case ('/'):
+                               case (':'):
+                               case (';'):
+                               case ('<'):
+                               case ('='):
+                               case ('>'):
+                               case ('?'):
+                                       break;
+                               case ('a'):
+                                       r[i] = 'A';
+                                       break;
+                               case ('b'):
+                                       r[i] = 'B';
+                                       break;
+                               case ('c'):
+                                       r[i] = 'C';
+                                       break;
+                               case ('d'):
+                                       r[i] = 'D';
+                                       break;
+                               case ('e'):
+                                       r[i] = 'E';
+                                       break;
+                               case ('f'):
+                                       r[i] = 'F';
+                                       break;
+                               case ('g'):
+                                       r[i] = 'G';
+                                       break;
+                               case ('h'):
+                                       r[i] = 'H';
+                                       break;
+                               case ('i'):
+                                       r[i] = 'I';
+                                       break;
+                               case ('j'):
+                                       r[i] = 'J';
+                                       break;
+                               case ('k'):
+                                       r[i] = 'K';
+                                       break;
+                               case ('l'):
+                                       r[i] = 'L';
+                                       break;
+                               case ('m'):
+                                       r[i] = 'M';
+                                       break;
+                               case ('n'):
+                                       r[i] = 'N';
+                                       break;
+                               case ('o'):
+                                       r[i] = 'O';
+                                       break;
+                               case ('p'):
+                                       r[i] = 'P';
+                                       break;
+                               case ('q'):
+                                       r[i] = 'Q';
+                                       break;
+                               case ('r'):
+                                       r[i] = 'R';
+                                       break;
+                               case ('s'):
+                                       r[i] = 'S';
+                                       break;
+                               case ('t'):
+                                       r[i] = 'T';
+                                       break;
+                               case ('u'):
+                                       r[i] = 'U';
+                                       break;
+                               case ('v'):
+                                       r[i] = 'V';
+                                       break;
+                               case ('w'):
+                                       r[i] = 'W';
+                                       break;
+                               case ('x'):
+                                       r[i] = 'X';
+                                       break;
+                               case ('y'):
+                                       r[i] = 'Y';
+                                       break;
+                               case ('z'):
+                                       r[i] = 'Z';
+                                       break;
+                               case ('\0'):
+                                       r[i] = ' ';
+                                       end = 1;
+                                       break;
+                               default:
+                                       r[i] = 'Z';
+                                       break;
+                       }
+               } else {
+                       r[i] = ' ';
+               }
+       }
+       r[length] = '\0';
+
+       return r;
+}
+
+const char *unixchar(const char *s, int length) {
+       char *r;
+       int i, end;
+       *r = *s;
+       end = 0;
+       for(i=0 ; i<length ; i++) {
+               if (end == 0) {
+                       if(s[i] == '\0') {
+                               r[i] = ' ';
+                               end = 1;
+                       }
+               } else {
+                       r[i] = ' ';
+               }
+       }
+       r[length] = '\0';
+
+       return r;
+}
+
diff --git a/hadaq/hwtapechar.h b/hadaq/hwtapechar.h
new file mode 100644 (file)
index 0000000..0f0ba2e
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef HWTAPECHAR_H
+#define HWTAPECHAR_H
+
+const char *ansichar(const char *, int);
+const char *unixchar(const char *, int);
+
+#endif
+