summaryrefslogtreecommitdiff
path: root/src/runtime/c/teyjus/tables_gen/util
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2012-07-31 15:16:04 +0000
committerkr.angelov <kr.angelov@gmail.com>2012-07-31 15:16:04 +0000
commit83b321d862472f31c0c9f7feca8360ad5bfe8a75 (patch)
tree0f0ef20ad78e25b320013c7bb160211a8612d4e9 /src/runtime/c/teyjus/tables_gen/util
parent314662dd09d5d1480007faa79258b0e93cc2aa59 (diff)
An initial import of the teyjus source code in the C runtime for GF. The two runtime are still not connected but the source code compiles.
Diffstat (limited to 'src/runtime/c/teyjus/tables_gen/util')
-rw-r--r--src/runtime/c/teyjus/tables_gen/util/util.c135
-rw-r--r--src/runtime/c/teyjus/tables_gen/util/util.h71
2 files changed, 206 insertions, 0 deletions
diff --git a/src/runtime/c/teyjus/tables_gen/util/util.c b/src/runtime/c/teyjus/tables_gen/util/util.c
new file mode 100644
index 000000000..502bfa68f
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/util/util.c
@@ -0,0 +1,135 @@
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "util.h"
+
+
+/**************************************************************************/
+/* Space allocation */
+/**************************************************************************/
+/* allocate space of n bytes*/
+void* UTIL_malloc(size_t n)
+{
+ void* ptr = (void*)malloc(n);
+ if (ptr) return ptr;
+ printf("Error : cannot allocate space\n");
+ exit(1);
+
+}
+
+
+/* allocate space for a string of given size */
+char* UTIL_mallocStr(size_t size)
+{
+ char* ptr = (char*)malloc(sizeof(char)*(size + 1));
+ if (ptr) return ptr;
+
+ printf("Error : cannot allocate space\n");
+ exit(1);
+}
+
+
+/**************************************************************************/
+/* string operation */
+/**************************************************************************/
+/* Append two strings */
+char* UTIL_appendStr(char* str1, char* str2)
+{
+ size_t length = strlen(str1) + strlen(str2);
+ char* ptr = UTIL_mallocStr(length + 1);
+
+ strcpy(ptr, str1);
+ strcat(ptr, str2);
+
+ return ptr;
+}
+
+
+//convert lower case letters in a string to upper case ones
+char* UTIL_upperCase(char* str)
+{
+ char *newstr, *tmp;
+ newstr = strdup(str);
+ tmp = newstr;
+ while ((*tmp) != '\0'){
+ if ((97 <= (int)*tmp) && ((int)*tmp <= 122))
+ *tmp = (char)((int)*tmp - 32);
+ tmp++;
+ }
+ return newstr;
+}
+
+//convert to lower cases
+char* UTIL_lowerCase(char* str)
+{
+ char *newstr, *tmp;
+ newstr = strdup(str);
+ tmp = newstr;
+ while ((*tmp) != '\0'){
+ if ((65 <= (int)*tmp) && ((int)*tmp) <= 90)
+ *tmp = (char)((int)*tmp + 32);
+ tmp++;
+ }
+ return newstr;
+}
+
+//covert an non-negtive integer to string
+char* UTIL_itoa(int num)
+{
+ char *str = UTIL_mallocStr(33);
+ sprintf(str, "%d", num);
+ return str;
+}
+
+
+/**************************************************************************/
+/* file operation */
+/**************************************************************************/
+
+/* open file in read mode */
+FILE* UTIL_fopenR(char* filename)
+{
+ FILE* filePtr = fopen(filename, "r");
+ if (filePtr) return filePtr;
+
+ printf("Error : cannot open input file %s\n", filename);
+ exit(1);
+}
+
+
+/* open file in write mode */
+FILE* UTIL_fopenW(char* filename)
+{
+ FILE* filePtr = fopen(filename, "w");
+ if (filePtr) return filePtr;
+
+ printf("Error : cannot open output file %s\n", filename);
+ exit(1);
+}
+
+/* close file */
+void UTIL_fclose(FILE* file)
+{
+ fclose(file);
+}
+
diff --git a/src/runtime/c/teyjus/tables_gen/util/util.h b/src/runtime/c/teyjus/tables_gen/util/util.h
new file mode 100644
index 000000000..4cc6a8a11
--- /dev/null
+++ b/src/runtime/c/teyjus/tables_gen/util/util.h
@@ -0,0 +1,71 @@
+//////////////////////////////////////////////////////////////////////////////
+//Copyright 2008
+// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
+//////////////////////////////////////////////////////////////////////////////
+// This file is part of Teyjus. //
+// //
+// Teyjus is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation, either version 3 of the License, or //
+// (at your option) any later version. //
+// //
+// Teyjus is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
+//////////////////////////////////////////////////////////////////////////////
+
+/**************************************************************************/
+/* util.h{c}. */
+/* Auxiliary functions needed for generating source files. */
+/**************************************************************************/
+#ifndef UTIL_H
+#define UTIL_H
+#include <stdio.h>
+
+
+/**************************************************************************/
+/* Space allocation */
+/**************************************************************************/
+/* allocate space */
+void* UTIL_malloc(size_t size);
+
+/* allocate space for a string of given size */
+char* UTIL_mallocStr(size_t size);
+
+/**************************************************************************/
+/* string operation */
+/**************************************************************************/
+/* append two strings */
+char* UTIL_appendStr(char* str1, char* str2);
+/* capitalizing */
+char* UTIL_upperCase(char* str);
+/* to lower cases */
+char* UTIL_lowerCase(char* str);
+/* covert a non-negative integer to string */
+char* UTIL_itoa(int num);
+
+/**************************************************************************/
+/* file operation */
+/**************************************************************************/
+/* open file in read mode */
+FILE* UTIL_fopenR(char* filename);
+
+/* open file in write mode */
+FILE* UTIL_fopenW(char* filename);
+
+/* close file */
+void UTIL_fclose(FILE* file);
+
+
+/* bool type */
+typedef enum {
+ UTIL_FALSE, UTIL_TRUE
+} UTIL_Bool;
+
+#endif
+
+