toys: . vtk2-pld vtk2-pld/branches vtk2-pld/tags vtk2-pld/trunk vtk2-pld/trunk/Makefile vtk2-pld/tru...

sparky cvs at pld-linux.org
Sun Jul 30 18:58:23 CEST 2006


Author: sparky
Date: Sun Jul 30 18:58:20 2006
New Revision: 7561

Added:
   toys/
   toys/vtk2-pld/
   toys/vtk2-pld/branches/
   toys/vtk2-pld/tags/
   toys/vtk2-pld/trunk/
   toys/vtk2-pld/trunk/Makefile
   toys/vtk2-pld/trunk/README
   toys/vtk2-pld/trunk/vtk2.cpp
Log:
- playground for shadzik


Added: toys/vtk2-pld/trunk/Makefile
==============================================================================
--- (empty file)
+++ toys/vtk2-pld/trunk/Makefile	Sun Jul 30 18:58:20 2006
@@ -0,0 +1,23 @@
+PREFIX = /usr
+bindir = $(PREFIX)/bin
+DESTDIR =
+SOURCES = vtk2.cpp
+OBJECTS = vtk2.o
+TARGET = vtk2
+LINK = g++
+CXX	= i686-pld-linux-g++
+CFLAGS	= -pipe -Wall -W -O2
+CXXFLAGS = -pipe -Wall -W -O2
+DEL_FILE = rm -f
+INSTALL = /usr/bin/install -c
+
+all: Makefile $(TARGET)
+$(TARGET):  $(OBJECTS)
+	$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS)
+
+clean:
+	$(DEL_FILE) $(OBJECTS) $(TARGET)
+
+vtk2.o: vtk2.cpp
+
+install:

Added: toys/vtk2-pld/trunk/README
==============================================================================
--- (empty file)
+++ toys/vtk2-pld/trunk/README	Sun Jul 30 18:58:20 2006
@@ -0,0 +1,16 @@
+Virtual Tomasz Kłoczko
+by Bartosz Świątek (shadzik at pld-linux.org)
+License:
+Do what ya want to as long as you're an PLD Linux Deviloper.
+
+Simply converts pl_PL to pl_TK charset using a database.
+It can be also used for other purpose (ex. dictionary).
+
+Installation:
+Just type
+	make
+
+To see how to run the program type:
+	./vtk2 -h
+
+That's all folks.

Added: toys/vtk2-pld/trunk/vtk2.cpp
==============================================================================
--- (empty file)
+++ toys/vtk2-pld/trunk/vtk2.cpp	Sun Jul 30 18:58:20 2006
@@ -0,0 +1,213 @@
+/* VTK - Virtual Tomasz Kłoczki v. 0.2 (20060729)
+ * Author: Bartosz Świątek (shadzik at pld-linux.org)
+ * License: Do what you want with it as long as you are an PLD-devel.
+ *
+ * ChangeLog
+ * v. 0.2 - added functionality, works now
+ * v. 0.1 - init version
+*/
+
+#include <iostream>
+#include <vector>
+#include <string>
+#include <map>
+#include <fstream>
+
+#define book ".vtkdatabase"
+
+using namespace std;
+
+/*
+ * No comment :D
+*/
+void help()
+{
+        cout << "Usage:\tvtk <options>\n"
+                "-a word tk_word - add word and it's TK version to database\n"
+                "-r word         - remove word from database\n"
+                "-s string       - covert to pl_TK\n"
+                "-l              - print every entry\n"
+                "-h              - shows this help\n";
+}
+
+/*
+ * Adds entries to the file, nothing special at this moment.
+*/
+
+void add(string nick, string mail)
+{
+   ofstream file(book, ios::app);
+   if (file.is_open())
+   {
+      file << nick 
+           << endl 
+           << mail 
+           << endl;
+      file.close();
+   } else {
+      cout << "Write file error.\n";
+   }
+}
+
+/*
+ * Searches for an entry
+*/
+
+string search(string s_nick)
+{
+   ifstream file(book);
+   vector<map<string, string> > dane;
+
+   if (! file.is_open())
+   {
+      cout << "File read error.\n";
+      exit (1);
+   }
+
+   while (!file.eof())
+   {
+      string pobrana_linia;
+      map<string, string> mapa;
+
+      getline(file, pobrana_linia); //gets the whole line
+      mapa.insert(map<string, string>::value_type("nick", pobrana_linia)); //puts it into the map
+      dane.push_back(mapa); //inserts the map into the vector
+   }
+
+   for(int i=0;i < dane.size(); ++i) //start searching :)
+   {
+      if ((dane[i]["nick"] == s_nick) && (i+1 < dane.size()))
+      {
+         return dane[i+1]["nick"];
+      } else if ((dane[i]["nick"] != s_nick) && (i+1 >= dane.size())) {
+         return s_nick;
+      }
+   }
+}
+
+/*
+ * Shows the whole list using the same idea as in search(string arg);
+*/
+
+int list()
+{
+   ifstream file(book);
+   vector<map<string, string> > dane;
+
+   if (! file.is_open())
+   {
+      cout << "File read error.\n";
+      exit (1);
+   }
+
+   while (!file.eof())
+   {
+      string pobrana_linia;
+      map<string, string> mapa;
+
+      getline(file, pobrana_linia);
+      mapa.insert(map<string, string>::value_type("nick", pobrana_linia));
+      dane.push_back(mapa);
+   }
+
+   for(int i=0;i < dane.size(); ++i)
+   {
+      if (i+1 < dane.size()) //in order not to get an segfault in case that we were beyond our memory
+      {
+         cout << dane[i]["nick"] << " -> " << dane[i+1]["nick"] << endl;
+         i++;
+      }
+   }
+}
+
+/*
+ * Removes entries from the file if existent
+*/
+
+int rm(string r_nick)
+{
+   ifstream file(book);
+   vector<map<string, string> > dane;
+
+   if (! file.is_open())
+   {
+      cout << "File read error.\n";
+      exit (1);
+   }
+
+   while (!file.eof())
+   {
+      string pobrana_linia;
+      map<string, string> mapa;
+
+      getline(file, pobrana_linia); //gets the whole line
+      mapa.insert(map<string, string>::value_type("nick", pobrana_linia)); //puts it into the map
+      dane.push_back(mapa); //inserts the map into the vector
+   }
+   
+   ofstream file2(book, ios::trunc);
+   for(int i=0;i < dane.size(); ++i) //start searching :)
+   {
+      if ((dane[i]["nick"] == r_nick) && ((i+2) < dane.size()))
+      {
+         dane.erase(dane.begin()+i,dane.begin()+i+2);
+      }
+
+      if (file2.is_open())
+      {
+         if (dane[i]["nick"].size() != 0) //in case not to put empty data to the file
+         {
+            file2 << dane[i]["nick"]
+                  << endl;
+         }
+      } else {
+         cout << "Write file error.\n";
+      }
+   } //end for
+   file2.close();
+}
+
+/*
+ * The main method, nothing special.
+*/
+
+int main(int argc, char *argv[])
+{
+   int ch,i=1;
+   try {
+   while ((ch = getopt(argc, argv, "hls:a:r:")) != -1)
+   {
+       switch(ch)
+       {
+          case 'a':
+                    add(optarg, argv[optind]);
+                    exit(0);
+                    break;
+          case 's':
+                    while (argv[++i]!=0)
+                    	cout << search(argv[i]) << " ";
+                    cout << endl;
+                    exit(0);
+                    break;
+          case 'l':
+                    list();
+                    exit(0);
+                    break;
+          case 'r':
+                    rm(optarg);
+                    exit(0);
+                    break;
+          case 'h':
+                    help();
+                    exit(0);
+                    break;
+          default:
+                    help();
+                    exit(0);
+                    break;
+       }
+   }
+   } catch (...) {
+   cout << "Cought Exception.\n";
+   }
+}


More information about the pld-cvs-commit mailing list