From derhartmut at euirc.eu Wed Jul 1 18:31:27 2009 From: derhartmut at euirc.eu (Alexander Hartmut Kluth) Date: Wed, 1 Jul 2009 18:31:27 +0200 Subject: [tyndur-devel] Erste help-Pages Message-ID: <1f8653f40907010931s2e7ff8c0s62079bfa713ae788@mail.gmail.com> Hier ein paar Help-Pages. Mfg, DerHartmut -------------- nächster Teil -------------- Ein Dateianhang mit HTML-Daten wurde abgetrennt... URL: -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : cd.xml Dateityp : text/xml Dateigröße : 800 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : ls.xml Dateityp : text/xml Dateigröße : 1171 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : stat.xml Dateityp : text/xml Dateigröße : 965 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : pwd.xml Dateityp : text/xml Dateigröße : 632 bytes Beschreibung: nicht verfügbar URL : From derhartmut at euirc.eu Wed Jul 1 21:26:20 2009 From: derhartmut at euirc.eu (Alexander Hartmut Kluth) Date: Wed, 1 Jul 2009 21:26:20 +0200 Subject: [tyndur-devel] Weitere helppages Message-ID: <1f8653f40907011226s2023bd1bm90d6f877f06f9779@mail.gmail.com> Und weiter im Kontext, hier weitere helppages. Mfg, DerHartmut -------------- nächster Teil -------------- Ein Dateianhang mit HTML-Daten wurde abgetrennt... URL: -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : cat.xml Dateityp : text/xml Dateigröße : 969 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : date.xml Dateityp : text/xml Dateigröße : 838 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : bincat.xml Dateityp : text/xml Dateigröße : 1116 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : echo.xml Dateityp : text/xml Dateigröße : 773 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : exit.xml Dateityp : text/xml Dateigröße : 603 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : set.xml Dateityp : text/xml Dateigröße : 1281 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : sleep.xml Dateityp : text/xml Dateigröße : 870 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : source.xml Dateityp : text/xml Dateigröße : 877 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : start.xml Dateityp : text/xml Dateigröße : 963 bytes Beschreibung: nicht verfügbar URL : From derhartmut at euirc.eu Wed Jul 1 21:50:59 2009 From: derhartmut at euirc.eu (Alexander Hartmut Kluth) Date: Wed, 1 Jul 2009 21:50:59 +0200 Subject: [tyndur-devel] Helppages Message-ID: <1f8653f40907011250l78863031r5167e538aa33026e@mail.gmail.com> Version 2 der unglaublichen Helppages. Mfg, DerHartmut -------------- nächster Teil -------------- Ein Dateianhang mit HTML-Daten wurde abgetrennt... URL: -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : helppages_part1_v2.tar.gz Dateityp : application/x-gzip Dateigröße : 2266 bytes Beschreibung: nicht verfügbar URL : From mail at kevin-wolf.de Wed Jul 1 22:23:04 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Wed, 1 Jul 2009 22:23:04 +0200 Subject: [tyndur-devel] Erste help-Pages In-Reply-To: <1f8653f40907010931s2e7ff8c0s62079bfa713ae788@mail.gmail.com> References: <1f8653f40907010931s2e7ff8c0s62079bfa713ae788@mail.gmail.com> Message-ID: <200907012223.04959@kevin-wolf.de> Am Mittwoch, 1. Juli 2009 18:31 schrieb Alexander Hartmut Kluth: > [tyndur-devel] Erste help-Pages > Von: > Alexander Hartmut Kluth > An: > tyndur-devel at tyndur.org > Datum: > Heute 18:31:27 >   > Hier ein paar Help-Pages. > > Mfg, > > DerHartmut > cd.xml > Wie du selbst festgestellt hast, die IDs müssen überall nochmal korrigiert werden. > >     cd >     >         Wechseln in ein neues Verzeichnis >     > > > >     >         cd >         Verzeichnis >     > > > >     Beschreibung >     >         Mit cd kann man in ein neues Verzeichnis wechseln. >         >             >                 Mit Parameter wird in das aktuelle Verzeichnis gewechselt, > sofern es eins ist. Wieso will ich ins aktuelle Verzeichnis wechseln? Da bin ich doch schon? Und wieso eine Liste mit nur einem Punkt? >         >     > > > >     Siehe auch >     pwd > > > > ls.xml > > > >     ls >     >         Anzeigen des Verzeichnisinhalts >     > > > >     >         ls >     >     >         ls >         Verzeichnis Das Argument ist hier eigentlich optional. >     > > > >     Beschreibung >     >         Per ls kann man sich den Inhalt eines Verzeichnisses auf dem > Bildschirm ausgeben lassen. >         >             >                 Ohne Parameter wird der Inhalt des aktuellen Verzeichnisses > angezeigt. >             >                 Falls ein Parameter angegeben wird und es sich um ein > Verzeichnis handelt, wird der Inhalt dieses Verzeichnisses ausgegeben, >             >         >     > > > >     Siehe auch >     pwd >     cd > > > > stat.xml > > > >     stat >     >         Informationen zu einer Datei ermitteln >     > > > >     >         stat >         Datei >     > > > >     Beschreibung >     >         Per stat kann man sich Informationen zu einer Datei auf dem > Bildschirm ausgeben lassen. Das mit "auf dem Bildschirm" würde ich streichen. vielleicht implementieren wir ja tatsächlich mal sowas wie Ausgabeumleitung. >         >             >                 Die Datei wird als Parameter angegeben. Nun werden > Informationen zum Dateinamen, der Groesse und des Typs angegeben. s/Groesse/Größe/ und zwar in UTF-8. Auf Umlaute zu verzichten ist im Code gut, aber was der Benutzer sieht, sollte schon ordentlich sein. >             >         >     > > > >     Siehe auch >     pwd >     cd > > > > pwd.xml > > > >     pwd >     >         Anzeigen des aktuellen Verzeichnispfades >     > > > >     >         ls *hust* >     > > > >     Beschreibung >     >         Per pwd wird der aktuelle Verzeichnispfad auf dem Bildschirm > ausgegeben. Wieder der Bildschirm > > > >     Siehe auch >     ls Hm, du hast es irgendwie mit dem ls, oder? ;-) >     cd > > > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel From toni at tyndur.org Wed Jul 1 22:33:08 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Wed, 1 Jul 2009 22:33:08 +0200 Subject: [tyndur-devel] [PATCH] tcpip: Unterstuetzung fuer TCP-Server In-Reply-To: <1246182508-6569-1-git-send-email-kevin@tyndur.org> References: <1246182508-6569-1-git-send-email-kevin@tyndur.org> Message-ID: <20090701203308.GA9809@einstein.produktiv.lan> On Sun, Jun 28 11:48, Kevin Wolf wrote: > + tcpip: Unterstuetzung fuer TCP-Server. Um Verbindungen > entgegenzunehmen, muss sich ein Server zunaechst fuer einen Port > registrieren, indem er tcpip:/tcp-listen/: oeffnet. Sobald ein > Client eine Verbindung oeffnen will, wird in dieser Datei der Name > einer zweiten Datei in tcpip:/tcp-conn ausgegeben, die geoeffnet > werden muss, um die Verbindung anzunehmen (pro Client eine Zeile). > > Signed-off-by: Kevin Wolf > --- > src/modules/tcpip/include/lostio_if.h | 18 ++ > src/modules/tcpip/include/tcp.h | 21 ++ > src/modules/tcpip/lostio_if.c | 13 +- > src/modules/tcpip/tcp.c | 25 +++ > src/modules/tcpip/tcp_server.c | 343 +++++++++++++++++++++++++++++++++ > 5 files changed, 414 insertions(+), 6 deletions(-) > create mode 100644 src/modules/tcpip/tcp_server.c > > diff --git a/src/modules/tcpip/include/lostio_if.h b/src/modules/tcpip/include/lostio_if.h > index 894ea80..1d34799 100644 > --- a/src/modules/tcpip/include/lostio_if.h > +++ b/src/modules/tcpip/include/lostio_if.h > @@ -38,8 +38,26 @@ > > #include "main.h" > > + > +#define LOSTIO_TYPES_TCPPORT 255 > +#define LOSTIO_TYPES_NETCONFIG 254 > +#define LOSTIO_TYPES_DNS 253 > +#define LOSTIO_TYPES_ROUTE 252 > +#define LOSTIO_TYPES_SERVER 251 > +#define LOSTIO_TYPES_SERVER_DIR 250 > +#define LOSTIO_TYPES_SERVER_CONN 249 > + > + > void init_lostio_interface(void); > void lostio_add_driver(struct driver *driver); > void lostio_add_device(struct device *device); > > +size_t lostio_tcp_read(lostio_filehandle_t* fh, void* buf, > + size_t blocksize, size_t count); > +size_t lostio_tcp_write > + (lostio_filehandle_t* fh, size_t blocksize, size_t count, void* data); > +int lostio_tcp_close(lostio_filehandle_t* filehandle); > + > + > + > #endif > diff --git a/src/modules/tcpip/include/tcp.h b/src/modules/tcpip/include/tcp.h > index 42b5699..d192226 100644 > --- a/src/modules/tcpip/include/tcp.h > +++ b/src/modules/tcpip/include/tcp.h > @@ -43,6 +43,7 @@ > #define TCPS_WAIT_FOR_LAST_ACK 3 > #define TCPS_CONNECTED_FIN 4 > #define TCPS_CLOSED 5 > +#define TCPS_WAIT_FOR_ACCEPT 6 > > #define TCPF_FIN (1 << 0) > #define TCPF_SYN (1 << 1) > @@ -107,9 +108,15 @@ struct tcp_out_buffer { > void* data; > }; > > +struct tcp_server { > + uint16_t port; > + list_t* requests; > +}; > + > > void init_tcp(void); > struct tcp_connection* tcp_open_connection(dword ip, word port); > +void tcp_accept_connection(struct tcp_connection* conn); > > word tcp_checksum > (struct tcp_header* header, struct tcp_pseudo_header* pseudo_header, > @@ -128,4 +135,18 @@ void tcp_send_ack(struct tcp_connection* conn); // TODO Ersetzen > */ > size_t tcp_get_mss(struct tcp_connection* conn); > > +/** > + * Registriert die LostIO-Typehandles, die fuer TCP-Server benoetigt werden > + */ > +void tcp_server_register_lostio(void); > + > +/** > + * Wird aufgerufen, um ein SYN-Paket zu behandeln. Erstellt eine Verbindung, > + * ohne jedoch SYN ACK zu senden. Stattdessen wird der Server benachrichtigt > + * und eine LostIO-Ressource angelegt, ueber die die Verbindung tatsaechlich > + * auf TCP-Ebene geoeffnet wird. > + */ > +struct tcp_connection* tcp_incoming_connection(uint32_t ip, > + struct tcp_header* header); > + > #endif > diff --git a/src/modules/tcpip/lostio_if.c b/src/modules/tcpip/lostio_if.c > index 3bb7f10..a3b0f1c 100644 > --- a/src/modules/tcpip/lostio_if.c > +++ b/src/modules/tcpip/lostio_if.c > @@ -45,6 +45,7 @@ > #include "network.h" > #include "ip.h" > #include "tcp.h" > +#include "lostio_if.h" > #include "dns.h" > > //Hier koennen die Debug-Nachrichten aktiviert werden > @@ -67,11 +68,6 @@ > #endif > > > -#define LOSTIO_TYPES_TCPPORT 255 > -#define LOSTIO_TYPES_NETCONFIG 254 > -#define LOSTIO_TYPES_DNS 253 > -#define LOSTIO_TYPES_ROUTE 252 > - > typehandle_t typehandle; > typehandle_t typehandle2; > typehandle_t typehandle3; > @@ -124,10 +120,15 @@ void init_lostio_interface(void) > > lostio_register_typehandle(&typehandle3); > > + // Typ fuer das DNS-Verzeichnis > lostio_type_directory_use_as(LOSTIO_TYPES_DNS); > get_typehandle(LOSTIO_TYPES_DNS)->not_found = lostio_tcp_not_found; > vfstree_get_node_by_path("/")->type = LOSTIO_TYPES_DNS; > - > + > + // Weitere Typen > + tcp_server_register_lostio(); > + > + // Dateien/Verzeichnisse anlegen > vfstree_create_node("/dns", LOSTIO_TYPES_DNS, 0, NULL, > LOSTIO_FLAG_BROWSABLE); > vfstree_create_node("/route", LOSTIO_TYPES_ROUTE, 1, NULL, 0); > diff --git a/src/modules/tcpip/tcp.c b/src/modules/tcpip/tcp.c > index 7eac8b2..721a690 100644 > --- a/src/modules/tcpip/tcp.c > +++ b/src/modules/tcpip/tcp.c > @@ -66,12 +66,14 @@ > extern bool debug_checksum; > > list_t* tcp_connections; > +list_t* tcp_servers; > > void tcp_send_ack(struct tcp_connection* conn); > > void init_tcp() > { > tcp_connections = list_create(); > + tcp_servers = list_create(); > } > > static word tcp_get_free_port(void) > @@ -129,6 +131,8 @@ static void tcp_send_packet(struct tcp_connection* conn, void* data, > > tcp_update_checksum(buffer, &pseudo_header, buffer + sizeof(header), data_size + options_size); > > + DEBUG_MSG2("Sending packet to %x, ack = %d", conn->dest_ip, > + conn->ack); > ip_send(conn->dest_ip, IP_PROTO_TCP, buffer, buffer_size); > } > > @@ -153,6 +157,15 @@ void tcp_send_ack(struct tcp_connection* conn) > } > } > > +static void tcp_send_syn_ack(struct tcp_connection* conn) > +{ > + conn->status = TCPS_CONNECTED; > + conn->seq = 0; //TODO (dword) get_tick_count(); Warum doen wir denn das nicht? ;-) > + > + tcp_send_packet(conn, NULL, 0, TCPF_SYN | TCPF_ACK); > + conn->seq++; > +} > + > static void tcp_send_reset(struct tcp_connection* conn) > { > tcp_send_packet(conn, NULL, 0, TCPF_RST); > @@ -214,6 +227,12 @@ struct tcp_connection* tcp_open_connection(dword ip, word port) > return conn; > } > > +void tcp_accept_connection(struct tcp_connection* conn) > +{ > + DEBUG_MSG("tcp_send_syn_ack"); > + tcp_send_syn_ack(conn); > +} > + > > struct tcp_connection* tcp_get_connection > (dword remote_ip, word remote_port, word local_port) > @@ -312,6 +331,12 @@ void tcp_receive(dword source_ip, void* data, dword data_size) > big_endian_word(header->dest_port)); > > DEBUG_MSG("--"); > + > + // Neue Verbindung fuer einen TCP-Server? > + if ((conn == NULL) && (header->flags == TCPF_SYN)) { > + conn = tcp_incoming_connection(source_ip, header); > + } > + > if (conn == NULL) { > DEBUG_MSG1("Verbindung nicht gefunden. IP = %08x", source_ip); > return; > diff --git a/src/modules/tcpip/tcp_server.c b/src/modules/tcpip/tcp_server.c > new file mode 100644 > index 0000000..da48ad6 > --- /dev/null > +++ b/src/modules/tcpip/tcp_server.c > @@ -0,0 +1,343 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "ip.h" > +#include "tcp.h" > +#include "lostio_if.h" > + > +extern list_t* tcp_connections; > +extern list_t* tcp_servers; > + > +static void do_nothing(void) {} > + > +/** > + * Legt Knoten im Verzeichnisbaum an, die noch nicht existieren, wenn auf sie > + * zugegriffen werden soll > + */ > +static bool lio_server_dir_not_found(char** path, byte flags, pid_t pid, > + io_resource_t* ps) > +{ > + return vfstree_create_node(*path, LOSTIO_TYPES_SERVER, 0, NULL, 0); Eiglentlich wäre es noch nett, hier schon mal zu prüfen, ob der Pfad einigermassen sinnvoll aussieht, damit nicht irgendwas erstellt wird. > +} > + > +/** > + * Das Oeffnen einer Datei in tcpip:/tcp-listen registriert einen TCP-Server. > + * Wenn ein Client verbindet, wird in der geoeffneten Datei der Dateiname zum > + * Oeffnen der Verbindung ausgegeben > + */ > +static bool lio_server_pre_open(char** path, byte flags, pid_t pid, > + io_resource_t* ps) > +{ > + char* s; > + char* port; > + int portnr; > + int i; > + struct tcp_server* server; > + vfstree_node_t* node; > + > + // Knoten raussuchen > + node = vfstree_get_node_by_path(*path); > + if (node == NULL) { > + return FALSE; > + } > + > + // Pfad auseinandernehmen > + if (strncmp(*path, "/tcp-listen/", strlen("/tcp-listen/"))) { > + return FALSE; > + } > + > + s = *path + strlen("/tcp-listen/"); > + port = strchr(s, ':'); > + if (port == NULL) { > + return FALSE; > + } > + > + port++; > + portnr = atoi(port); > + if (port == 0) { > + return FALSE; > + } > + > + // Pruefen, ob der Port nicht schon belegt ist > + p(); > + for (i = 0; (server = list_get_element_at(tcp_servers, i)); i++) { > + if (server->port == portnr) { Ich würde hier noch Folgendes vorschlagen: v(); > + return FALSE; > + } > + } > + v(); Ich würde sagen das gibt eine race-condition. Das v() muss doch noch warten, bis der neue Server in die Liste eingetragen wurde. > + // Neuen Server anlegen und der Ressource zuordnen > + server = calloc(1, sizeof(*server)); > + server->port = portnr; > + server->requests = list_create(); > + node->data = server; > + > + p(); > + list_push(tcp_servers, server); > + v(); > + > + return TRUE; > +} > + > +/** > + * Liest eine Verbindung, die geoeffnet werden kann, aus > + */ > +size_t lio_server_read(lostio_filehandle_t* fh, void* buf, > + size_t blocksize, size_t count) > +{ > + struct tcp_server* server = fh->node->data; > + char* s; > + size_t len; > + > + s = list_pop(server->requests); > + if (s == NULL) { > + return 0; > + } > + > + len = strlen(s); > + if (blocksize * count < len) { > + len = blocksize * count; > + } > + > + > + strncpy(buf, s, len); > + free(s); > + > + return len; > +} > + > +/** > + * Beendet einen Server > + */ > +int lio_server_close(lostio_filehandle_t* fh) > +{ > + struct tcp_server* server = fh->node->data; > + struct tcp_server* cur; > + char* s; > + int i; > + > + // Aus der Liste der Server entfernen > + p(); > + for (i = 0; (cur = list_get_element_at(tcp_servers, i)); i++) { > + if (server == cur) { > + list_remove(tcp_servers, i); > + break; > + } > + } > + v(); > + > + // VFS-Knoten entfernen > + fh->node->data = NULL; > + while ((s = list_pop(server->requests))) { > + free(s); > + } > + list_destroy(server->requests); > + free(server); > + vfstree_delete_child(fh->node->parent, fh->node->name); > + > + return 0; > +} > + > +/** > + * Wird aufgerufen, um ein SYN-Paket zu behandeln. Erstellt eine Verbindung, > + * ohne jedoch SYN ACK zu senden. Stattdessen wird der Server benachrichtigt > + * und eine LostIO-Ressource angelegt, ueber die die Verbindung tatsaechlich > + * auf TCP-Ebene geoeffnet wird. > + */ > +struct tcp_connection* tcp_incoming_connection(uint32_t remote_ip, > + struct tcp_header* header) > +{ > + struct tcp_server* server; > + struct tcp_connection* conn; > + struct routing_entry* route; > + uint64_t timeout; > + int i; > + > + uint16_t remote_port = big_endian_word(header->source_port); > + uint16_t local_port = header->dest_port; Hm ist der LE, oder warum funktioniert das? > + > + // Server an header->dest_port suchen > + server = NULL; > + for (i = 0; (server = list_get_element_at(tcp_servers, i)); i++) { > + if (server->port == header->dest_port) { Wenn du hier ein local_port nimmst, musst du weniger tippen. :-P > + break; > + } > + } > + > + if (server == NULL) { > + return NULL; > + } > + Hier müsste wohl noch ein p() hin, sonst schleichen sich doch plötzlich doch Duplikate ein... > + // Duplikate suchen > + // Wenn wir sowieso schon darauf warten, dass jemand die Verbindung > + // annimmt, hilft uns ein zweites SYN-Paket auch nicht weiter. > + conn = NULL; > + for (i = 0; (conn = list_get_element_at(tcp_connections, i)); i++) { > + if ((conn->source_port == local_port) && > + (conn->dest_port == remote_port) && > + (conn->dest_ip == remote_ip)) > + { > + return NULL; > + } > + } > + > + // Verbindung erstellen > + conn = calloc(1, sizeof(struct tcp_connection)); > + route = get_routing_entry(remote_ip); > + > + if (route == NULL) { > + return NULL; > + } > + > + conn->dest_ip = remote_ip; > + conn->dest_port = remote_port; > + conn->source_ip = route->device->dev.ip; > + conn->source_port = local_port; > + conn->window = 0x1000; > + conn->ack = big_endian_dword(header->seq) + 1; > + conn->out_buffer = list_create(); > + conn->in_buffer = list_create(); > + conn->to_lostio = list_create(); > + conn->status = TCPS_WAIT_FOR_ACCEPT; > + > + p(); > + list_push(tcp_connections, conn); > + v(); > + > + // Neuen VFS-Knoten anlegen > + char* ip_str = ip_to_string(remote_ip); > + char* buf; > + asprintf(&buf, "/tcp-conn/local:%d_%s:%d", > + header->dest_port, ip_str, header->source_port); Wenn du hier local_port und remote_port nimmst, passt das sogar von der Endianness her. > + vfstree_create_node(buf, LOSTIO_TYPES_SERVER_CONN, 0, conn, > + LOSTIO_FLAG_NOAUTOEOF); > + free(buf); > + > + // Den Server informieren > + asprintf(&buf, "tcpip:/tcp-conn/local:%d_%s:%d\n", > + header->dest_port, ip_str, header->source_port); Dito. > + free(ip_str); > + p(); > + list_push(server->requests, buf); > + v(); > + > + // Warten, bis der Server die Verbindung annimmt > + timeout = get_tick_count() + 9 * 1000000; > + timer_register(do_nothing, 10 * 1000000); > + while ((conn->status == TCPS_WAIT_FOR_ACCEPT) > + && (get_tick_count() < timeout)) > + { > + wait_for_rpc(); > + } > + > + if (conn->status == TCPS_WAIT_FOR_ACCEPT) { > + // TODO Verbindung abbrechen und wieder freigeben > + return NULL; > + } > + > + return conn; > +} > + > +/** > + * Oeffnet eine eingehende Verbindung > + */ > +void lio_server_conn_post_open(lostio_filehandle_t* fh) > +{ > + struct tcp_connection* conn = fh->node->data; > + > + tcp_accept_connection(conn); > + fh->node->size++; Wozu das denn? ;-) > +} > + > +/** > + * Schliesst eine eingehende Verbindung und entfernt sie aus dem > + * Verzeichnisbaum. > + */ > +int lio_server_conn_close(lostio_filehandle_t* fh) > +{ > + int ret = lostio_tcp_close(fh); > + > + // VFS-Knoten entfernen > + vfstree_delete_child(fh->node->parent, fh->node->name); Ich frage mich gerade ob das eine gute Idee ist, aber du wirst es ja wohl getestet haben... Ich hätte da nämlich rot vermutet, aber kann sein, dass LIO das richtig macht...;-) > + > + return ret; > +} > + > +/// Typ fuer einen TCP-Server > +static typehandle_t lio_type_server = { > + .id = LOSTIO_TYPES_SERVER, > + .pre_open = &lio_server_pre_open, > + .read = &lio_server_read, > + .close = &lio_server_close, > +}; > + > +/// Typ fuer eine Verbindung fuer TCP-Server > +static typehandle_t lio_type_server_conn = { > + .id = LOSTIO_TYPES_SERVER_CONN, > + .post_open = &lio_server_conn_post_open, > + .read = &lostio_tcp_read, > + .write = &lostio_tcp_write, > + .close = &lio_server_conn_close, > +}; > + > +/** > + * Registriert die LostIO-Typehandles, die fuer TCP-Server benoetigt werden > + */ > +void tcp_server_register_lostio(void) > +{ > + // Typ fuer das Verzeichnis tcp-listen > + lostio_type_directory_use_as(LOSTIO_TYPES_SERVER_DIR); > + get_typehandle(LOSTIO_TYPES_SERVER_DIR)->not_found = > + &lio_server_dir_not_found; > + > + // Typen fuer einen TCP-Server und seine Verbindungen > + lostio_register_typehandle(&lio_type_server); > + lostio_register_typehandle(&lio_type_server_conn); > + > + // Knoten erstellen > + vfstree_create_node("/tcp-listen", LOSTIO_TYPES_SERVER_DIR, 0, NULL, > + LOSTIO_FLAG_BROWSABLE); > + vfstree_create_node("/tcp-conn", LOSTIO_TYPES_DIRECTORY, 0, NULL, > + LOSTIO_FLAG_BROWSABLE); > +} Mehr sehe ich im Moment leider nicht. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From alexanderkluth at gmx.de Thu Jul 2 15:41:44 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Thu, 2 Jul 2009 15:41:44 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_Neue_Befehle_hinzugef=C3=BCg?= =?utf-8?q?t=3A_bincat=2C_cat=2C_cd=2C_date=2C_echo=2C_exit=2C_help?= =?utf-8?q?=2C_ls=2C_pwd=2C_set=2C_sleep=2C_source=2C_start=2C_stat?= In-Reply-To: <1> References: <1> Message-ID: <1246542104-9957-1-git-send-email-alexanderkluth@gmx.de> From: Alexander Hartmut Kluth --- help.xml | 31 ------------------------------- 1 files changed, 0 insertions(+), 31 deletions(-) delete mode 100644 help.xml diff --git a/help.xml b/help.xml deleted file mode 100644 index a1266cd..0000000 --- a/help.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - help - - Zeigt Hilfeseiten an und ermöglicht die Navigation zwischen diesen - - - - - - help - filename - - - - - Beschreibung - help zeigt die als Argument übergebene Hilfeseite an. Ist die Seite -zu lang für das Display, kann mit Pfeil Hoch/Runter gescrollt werden. - Desweiteren lassen sich (falls vorhanden) Links via Pfeil Links/Rechts - auswählen, welchen mit Return gefolgt werden kann. - - - Parameter - - filename - Der Dateiname des zu betrachtenden Hilfedokumentes. - - - \ No newline at end of file -- 1.6.0.4 From alexanderkluth at gmx.de Thu Jul 2 15:49:55 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Thu, 2 Jul 2009 15:49:55 +0200 Subject: [tyndur-devel] [PATCH] bincat, cat, cd, date, exit, pwd, set, sleep, source, start und stat In-Reply-To: <1> References: <1> Message-ID: <1246542595-10190-1-git-send-email-alexanderkluth@gmx.de> From: Alexander Hartmut Kluth --- bincat.xml | 38 ++++++++++++++++++++++++++++++++++++++ cat.xml | 36 ++++++++++++++++++++++++++++++++++++ cd.xml | 34 ++++++++++++++++++++++++++++++++++ date.xml | 34 ++++++++++++++++++++++++++++++++++ exit.xml | 29 +++++++++++++++++++++++++++++ pwd.xml | 29 +++++++++++++++++++++++++++++ set.xml | 44 ++++++++++++++++++++++++++++++++++++++++++++ sleep.xml | 36 ++++++++++++++++++++++++++++++++++++ source.xml | 35 +++++++++++++++++++++++++++++++++++ start.xml | 37 +++++++++++++++++++++++++++++++++++++ stat.xml | 37 +++++++++++++++++++++++++++++++++++++ 11 files changed, 389 insertions(+), 0 deletions(-) create mode 100644 bincat.xml create mode 100644 cat.xml create mode 100644 cd.xml create mode 100644 date.xml create mode 100644 exit.xml create mode 100644 pwd.xml create mode 100644 set.xml create mode 100644 sleep.xml create mode 100644 source.xml create mode 100644 start.xml create mode 100644 stat.xml diff --git a/bincat.xml b/bincat.xml new file mode 100644 index 0000000..4bf9d8c --- /dev/null +++ b/bincat.xml @@ -0,0 +1,38 @@ + + + + bincat + + Zeige den Inhalt einer Datei als einzelne Bytes an + + + + + + bincat + Datei + + + + + Beschreibung + + Per bincat kann man sich den Inhalt einer Datei in Form von Bytes (hexadazimal) + auf dem Bildschirm anzeigen lassen. + + + Die Datei wird als Parameter angegeben. Wenn selbige exisitiert und kein + Verzeichnis ist, wird der Inhalt in Form von Bytes auf dem Bildschirm + ausgegeben. Zum Scrollen bitte Shift+BildAuf/BildAb benutzen. + + + + + + + Siehe auch + cat + pipe + + + diff --git a/cat.xml b/cat.xml new file mode 100644 index 0000000..1d87b8a --- /dev/null +++ b/cat.xml @@ -0,0 +1,36 @@ + + + + cat + + Zeige den Inhalt einer Datei an + + + + + + cat + Datei + + + + + Beschreibung + + Per cat kann man sich den Inhalt einer Datei auf dem Bildschirm anzeigen lassen. + + + Die Datei wird als Parameter angegeben. Wenn selbige exisitiert und kein + Verzeichnis ist, wird der Inhalt auf dem Bildschirm ausgegeben. + + + + + + + Siehe auch + bincat + pipe + + + diff --git a/cd.xml b/cd.xml new file mode 100644 index 0000000..d4ed4a8 --- /dev/null +++ b/cd.xml @@ -0,0 +1,34 @@ + + + + cd + + Wechseln in ein neues Verzeichnis + + + + + + cd + Verzeichnis + + + + + Beschreibung + + Mit cd kann man in ein neues Verzeichnis wechseln. + + + Mit Parameter wird in das aktuelle Verzeichnis gewechselt, sofern es eins ist. + + + + + + + Siehe auch + pwd + + + diff --git a/date.xml b/date.xml new file mode 100644 index 0000000..d25f37e --- /dev/null +++ b/date.xml @@ -0,0 +1,34 @@ + + + + date + + Zeigt das aktuelle Datum und die aktuelle Uhrzeit an + + + + + + date + + + + + Beschreibung + + date zeigt das aktuelle Datum und die aktuelle Uhrzeit an. + + + Die Datei wird als Parameter angegeben. Wenn selbige exisitiert und kein + Verzeichnis ist, wird der Inhalt auf dem Bildschirm ausgegeben. + + + + + + + Siehe auch + sleep + + + diff --git a/exit.xml b/exit.xml new file mode 100644 index 0000000..0213389 --- /dev/null +++ b/exit.xml @@ -0,0 +1,29 @@ + + + + exit + + Beendet die Shell + + + + + + exit + + + + + Beschreibung + + exit beendet die aktuelle Shell. Läuft keine Shell mehr im Hintergrund, lässt sich + per ENTER eine neue starten. + + + + + Siehe auch + start + + + diff --git a/pwd.xml b/pwd.xml new file mode 100644 index 0000000..efd5cdf --- /dev/null +++ b/pwd.xml @@ -0,0 +1,29 @@ + + + + pwd + + Anzeigen des aktuellen Verzeichnispfades + + + + + + ls + + + + + Beschreibung + + Per pwd wird der aktuelle Verzeichnispfad auf dem Bildschirm ausgegeben. + + + + + Siehe auch + ls + cd + + + diff --git a/set.xml b/set.xml new file mode 100644 index 0000000..5be6bcc --- /dev/null +++ b/set.xml @@ -0,0 +1,44 @@ + + + + set + + Setzt Umgebungsvariablen oder zeigt diese an + + + + + + set + + + set + Umgebungsvariable + + + + + Beschreibung + + Per set kann man sich die aktuellen Umgebungsvariablen ansehen, deren Werte neu + setzen oder neue Umgebungsvariablen mit neuen Werten setzen. + + + Ohne Parameter werden die aktuellen Umgebungsvariablen samt Werte angezeigt. + + + Ist der erste Parameter eine existierende Variable, so wird mit dem zweite Parameter + der neue Wert gesetzt. + + + Ist der erste Parameter eine neue Variable, so wird diese angelegt, allerdings nur, + wenn ein zweiter Parameter vorhanden ist. + + + + + + Siehe auch + + + diff --git a/sleep.xml b/sleep.xml new file mode 100644 index 0000000..916465f --- /dev/null +++ b/sleep.xml @@ -0,0 +1,36 @@ + + + + sleep + + Aktuelle Unterbrechung des Betriebes + + + + + + sleep + Sekunden + + + + + Beschreibung + + Per sleep unterbricht bzw. hält man z.B. ein Script für eine definierte + Zeit an. + + + Die zu pausierende Zeit wird als Sekunde in Form einer Zahl als + Parameter angegeben. + + + + + + + Siehe auch + date + + + diff --git a/source.xml b/source.xml new file mode 100644 index 0000000..8b62409 --- /dev/null +++ b/source.xml @@ -0,0 +1,35 @@ + + + + source + + Fürt ein Script aus + + + + + + source + Auszuführendes Script + + + + + Beschreibung + + Per source führt man ein Script aus. + + + Das Script muss als Parameter übergeben werden. Befindet es sich nicht + im aktuellen Verzeichnis, so muss man den Pfad zum SCript mit angeben. + + + + + + + Siehe auch + start + + + diff --git a/start.xml b/start.xml new file mode 100644 index 0000000..036f14b --- /dev/null +++ b/start.xml @@ -0,0 +1,37 @@ + + + + start + + Startet ein Programm im Hintergrund + + + + + + start + Pfad zum Programm + + + + + Beschreibung + + Per start wird ein Programm im Hintergrund gestartet, die Shell kann + weiterbenutzt werden. + + + Das Programm wird als Parameter übergeben. Sofern es sich nicht + im aktuellen Verzeichnis befindet, muss noch der Pfad vorangestellt + werden. + + + + + + + Siehe auch + source + + + diff --git a/stat.xml b/stat.xml new file mode 100644 index 0000000..7cc74e9 --- /dev/null +++ b/stat.xml @@ -0,0 +1,37 @@ + + + + stat + + Informationen zu einer Datei ermitteln + + + + + + stat + Datei + + + + + Beschreibung + + Per stat kann man sich Informationen zu einer Datei auf dem Bildschirm + ausgeben lassen. + + + Die Datei wird als Parameter angegeben. Nun werden Informationen zum + Dateinamen, der Groesse und des Typs angegeben. + + + + + + + Siehe auch + pwd + cd + + + -- 1.6.0.4 From alexanderkluth at gmx.de Sat Jul 4 00:35:50 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Sat, 4 Jul 2009 00:35:50 +0200 Subject: [tyndur-devel] [PATCH] free, ps, kill, dbg_st, ln, symlink, readlink In-Reply-To: <1> References: <1> Message-ID: <1246660550-14612-1-git-send-email-alexanderkluth@gmx.de> --- dbg_st.xml | 41 +++++++++++++++++++++++++++++++++++++++++ free.xml | 35 +++++++++++++++++++++++++++++++++++ kill.xml | 44 ++++++++++++++++++++++++++++++++++++++++++++ ln.xml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ ps.xml | 33 +++++++++++++++++++++++++++++++++ pstree.xml | 40 ++++++++++++++++++++++++++++++++++++++++ readlink.xml | 43 +++++++++++++++++++++++++++++++++++++++++++ symlink.xml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 331 insertions(+), 0 deletions(-) create mode 100644 dbg_st.xml create mode 100644 free.xml create mode 100644 kill.xml create mode 100644 ln.xml create mode 100644 ps.xml create mode 100644 pstree.xml create mode 100644 readlink.xml create mode 100644 symlink.xml diff --git a/dbg_st.xml b/dbg_st.xml new file mode 100644 index 0000000..ab6fdce --- /dev/null +++ b/dbg_st.xml @@ -0,0 +1,41 @@ + + + + dbg_st + + Zeige den Stack-Backtrace eines Prozesses an + + + + + + dbg_st + PID (Prozess-ID) + + + + + Beschreibung + + Per dbg_st kann man sich den Stack-Backtrace eines Prozesses anzeigen lassen. + + + Der PID (Prozess-ID) wird als Parameter übergeben. + + + + + + + Siehe auch + + + pstree + + + ps + + + + + diff --git a/free.xml b/free.xml new file mode 100644 index 0000000..11f20d8 --- /dev/null +++ b/free.xml @@ -0,0 +1,35 @@ + + + + free + + Zeige den aktuellen Speicherverbrauch des Systems an + + + + + + free + + + + + Beschreibung + + Per free kann man sich den aktuellen Speicherverbrauch auf dem System ansehen. + + + + + Siehe auch + + + ps + + + pstree + + + + + diff --git a/kill.xml b/kill.xml new file mode 100644 index 0000000..5a6c29a --- /dev/null +++ b/kill.xml @@ -0,0 +1,44 @@ + + + + kill + + Beendet einen Prozess + + + + + + cat + Datei + + + + + Beschreibung + + Per kill kann man einen Prozess direkt beenden. + + + Die PID (Prozess-ID) wird dem Programm als Argument übergeben. + + + + + + + Siehe auch + + + ps + + + pstree + + + dbg_st + + + + + diff --git a/ln.xml b/ln.xml new file mode 100644 index 0000000..4507549 --- /dev/null +++ b/ln.xml @@ -0,0 +1,48 @@ + + + + ln + + Legt einen Link auf eine Datei an + + + + + + ln + Zu verlinkende Datei + Name und Ort des Links + + + + + Beschreibung + + Per ln kann man einen Link auf eine Datei erstellen. Beim Aufruf des Links + wird dann automatisch auf die Datei verwiesen. + + + Die Quelldatei wird als Parameter (samt Pfad, falls nicht aktuelles + Verzeichnis) angegeben. + + + Der Name des Links wird als zweiter Parameter (ebenfalls samt Pfad, + falls nicht aktuelles Verzeichnis) angegeben. + + + + + + + Siehe auch + + + symlink + + + readlink + + + + + diff --git a/ps.xml b/ps.xml new file mode 100644 index 0000000..b3379d4 --- /dev/null +++ b/ps.xml @@ -0,0 +1,33 @@ + + + + ps + + Zeigt eine Liste aller Prozesse an + + + + + + ps + + + + + Beschreibung + + Per ps kann man sich eine Liste aller auf dem System laufender Prozesse ansehen. + Zum Scrollen einfach Shirt+BildAuf/BildAb drücken. + + + + + Siehe auch + + + pstree + + + + + diff --git a/pstree.xml b/pstree.xml new file mode 100644 index 0000000..81dd70e --- /dev/null +++ b/pstree.xml @@ -0,0 +1,40 @@ + + + + pstree + + Zeige alle Prozesse in einer Baumstruktur an + + + + + + cat + Datei + + + + + Beschreibung + + Per pstree kann man sich alle aktuell auf dem System laufenden Prozesse + in einer Baumstruktur anzeigen lassen. + + + Die Datei wird als Parameter angegeben. Wenn selbige exisitiert und kein + Verzeichnis ist, wird der Inhalt auf dem Bildschirm ausgegeben. + + + + + + + Siehe auch + + + ps + + + + + diff --git a/readlink.xml b/readlink.xml new file mode 100644 index 0000000..ab0c0e3 --- /dev/null +++ b/readlink.xml @@ -0,0 +1,43 @@ + + + + readlink + + Liest das Ziel eines symbolischen Links aus + + + + + + readlink + Symbolischer Link + + + + + Beschreibung + + Per readlink kann das Ziel eines symbolischen Links ausgelesen und auf dem + Bildschirm ausgegeben werden. + + + Der symbolische Link wird (falls nicht im aktuellen Verzeichnis mitsamt + dem Pfad) als Parameter angegeben. + + + + + + + Siehe auch + + + symlink + + + ln + + + + + diff --git a/symlink.xml b/symlink.xml new file mode 100644 index 0000000..0b94ea3 --- /dev/null +++ b/symlink.xml @@ -0,0 +1,47 @@ + + + + symlink + + Legt einen symbolischen Link auf eine Datei an + + + + + + ln + Zu verlinkende Datei + Name und Ort des symbolischen Links + + + + + Beschreibung + + Per symlink kann ein symbolischer Link auf eine Datei erstellt werden. + + + Die Quelldatei wird als Parameter (samt Pfad, falls nicht aktuelles + Verzeichnis) angegeben. + + + Der Name des Links wird als zweiter Parameter (ebenfalls samt Pfad, + falls nicht aktuelles Verzeichnis) angegeben. + + + + + + + Siehe auch + + + readlink + + + ln + + + + + -- 1.6.0.4 From alexanderkluth at gmx.de Sat Jul 4 01:29:30 2009 From: alexanderkluth at gmx.de (Alexander Hartmut Kluth) Date: Sat, 4 Jul 2009 01:29:30 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_touch=2Ec_in_c/shell/cmds_pl?= =?utf-8?q?us_=C3=84nderungen_an_shell=2Ec_und_shell=2Eh_damit_touc?= =?utf-8?q?h_von_der_Shell_auf_aufgerufen_werden_kann?= In-Reply-To: <1> References: <1> Message-ID: <1246663770-23595-1-git-send-email-alexanderkluth@gmx.de> --- src/modules/c/shell/cmds/touch.c | 113 ++++++++++++++++++++++++++++++++++++++ src/modules/c/shell/shell.c | 1 + src/modules/c/shell/shell.h | 1 + 3 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/shell/cmds/touch.c diff --git a/src/modules/c/shell/cmds/touch.c b/src/modules/c/shell/cmds/touch.c new file mode 100644 index 0000000..a4462f3 --- /dev/null +++ b/src/modules/c/shell/cmds/touch.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Hartmut Kluth. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include "types.h" +#include "stdlib.h" +#include "stdio.h" +#include "unistd.h" +#include + + +void touch_display_usage(void); + +#ifdef CONFIG_SHELL_BUILTIN_ONLY + int shell_command_touch(int argc, char* argv[], const char* args) +#else + int main(int argc, char* argv[]) +#endif +{ + if (argc < 2) { + touch_display_usage(); + return -1; + } + + int ignore_existing_file = FALSE; + FILE* new_filehandle; + char* new_file; + + if (argc == 3) { + if ((strcmp(argv[1], "-i")) == 0 || (strcmp(argv[1], "--ignore") == 0)) { + ignore_existing_file = TRUE; + new_file = argv[2]; + } else { + touch_display_usage(); + return -1; + } + } else { + new_file = argv[1]; + } + + // Versuchen, die Datei zum Lesen zu öffnen... + new_filehandle = fopen(new_file, "r"); + + if (new_filehandle != NULL) { + // ...wenn die Datei existiert, prüfen, ob sie überschrieben werden soll + if (ignore_existing_file) { + fclose(new_filehandle); + + int result = io_remove_link(new_file); + + if (result != 0) { + fprintf(stderr, "Fehler beim Löschen der existierenden Datei!\n"); + return EXIT_FAILURE; + } + + new_filehandle = fopen(new_file, "w"); + fclose(new_filehandle); + } else { + fprintf(stderr, "Fehler: Datei %s existiert bereits!\n", new_file); + return EXIT_FAILURE; + } + } else { + fclose(new_filehandle); + + new_filehandle = fopen(new_file, "w"); + fclose(new_filehandle); + } + + return EXIT_SUCCESS; +} + + +void touch_display_usage() +{ + puts("\nAufruf: touch[-i|--ignore] Datei\n"); +} + diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c index cb5de50..7c3b6be 100644 --- a/src/modules/c/shell/shell.c +++ b/src/modules/c/shell/shell.c @@ -99,6 +99,7 @@ shell_command_t shell_commands[] = { {"stat", &shell_command_stat}, {"sleep", &shell_command_sleep}, {"bench", &shell_command_bench}, + {"touch", &shell_command_touch}, #endif {NULL, NULL} }; diff --git a/src/modules/c/shell/shell.h b/src/modules/c/shell/shell.h index 4a45786..6185590 100644 --- a/src/modules/c/shell/shell.h +++ b/src/modules/c/shell/shell.h @@ -83,6 +83,7 @@ int shell_command_clear(int argc, char* argv[], const char* args); int shell_command_stat(int argc, char* argv[], const char* args); int shell_command_sleep(int argc, char* argv[], const char* args); int shell_command_bench(int argc, char* argv[], const char* args); + int shell_command_touch(int argc, char* argv[], const char* args); #endif #endif -- 1.6.0.4 From kevin at tyndur.org Sat Jul 4 14:11:09 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 4 Jul 2009 14:11:09 +0200 Subject: [tyndur-devel] [PATCH 3/3] libc: POSIX: Fixes fuer select In-Reply-To: <1246709469-6707-1-git-send-email-kevin@tyndur.org> References: <1246709469-6707-1-git-send-email-kevin@tyndur.org> Message-ID: <1246709469-6707-4-git-send-email-kevin@tyndur.org> ! libc: POSIX: select(): Sekunden sind das, was lang dauert, und Mikrosekunden das kurze. Nicht umgekehrt. ! libc: POSIX: select(): Ein Nullbyte ist eigentlich eine perfekte Eingabe, kein Fehler. Signed-off-by: Kevin Wolf --- src/modules/lib/posix/select.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/lib/posix/select.c b/src/modules/lib/posix/select.c index 539f555..9ae365c 100644 --- a/src/modules/lib/posix/select.c +++ b/src/modules/lib/posix/select.c @@ -67,8 +67,9 @@ int select(int number_fds, fd_set* readfds, fd_set* writefds, uint64_t timeout_tick; if (timeout != NULL) { - timeout_tick = get_tick_count() + timeout->tv_sec + - 1000ULL * 1000ULL * timeout->tv_usec; + timeout_tick = get_tick_count() + + 1000ULL * 1000ULL * timeout->tv_sec + + timeout->tv_usec; } else { timeout_tick = (uint64_t) -1; } @@ -101,7 +102,7 @@ int select(int number_fds, fd_set* readfds, fd_set* writefds, if (f != NULL) { c = fgetc(f); - if (c == 0 || c == EOF) { + if (c == EOF) { *rd &= ~(1 << i); } else { ungetc(c, f); -- 1.6.0.2 From kevin at tyndur.org Sat Jul 4 14:11:06 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 4 Jul 2009 14:11:06 +0200 Subject: [tyndur-devel] [PATCH 0/3] Patches fuer SVN Message-ID: <1246709469-6707-1-git-send-email-kevin@tyndur.org> Mit den folgenden Patches tut SVN beim Auschecken schonmal was halbwegs sinnvolles. Kevin Wolf (3): libc: Etwas besser gefaktes rename libc: POSIX: Rueckgabewert von read libc: POSIX: Fixes fuer select src/modules/lib/posix/posix_files.c | 8 +++++ src/modules/lib/posix/select.c | 7 ++-- src/modules/lib/stdlibc/file.c | 55 +++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 5 deletions(-) From kevin at tyndur.org Sat Jul 4 14:11:07 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 4 Jul 2009 14:11:07 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: Etwas besser gefaktes rename In-Reply-To: <1246709469-6707-1-git-send-email-kevin@tyndur.org> References: <1246709469-6707-1-git-send-email-kevin@tyndur.org> Message-ID: <1246709469-6707-2-git-send-email-kevin@tyndur.org> + libc: rename() kann jetzt Dateien verschieben (durch kopieren und loeschen). Verzeichnisse gehen nach wie vor nicht. Signed-off-by: Kevin Wolf --- src/modules/lib/stdlibc/file.c | 55 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/modules/lib/stdlibc/file.c b/src/modules/lib/stdlibc/file.c index 5bb60cd..7ec650e 100644 --- a/src/modules/lib/stdlibc/file.c +++ b/src/modules/lib/stdlibc/file.c @@ -857,14 +857,65 @@ int remove(const char* filename) } #ifndef CONFIG_LIBC_NO_STUBS +#include +#include +#define BUFFER_SIZE 4096 /** * Datei verschieben */ int rename(const char* oldpath, const char* newpath) { - printf("[file.c] FIXME: rename aufgerufen, aber nicht implementiert\n"); - return -1; + const char* src_path = oldpath; + const char* dst_path = newpath; + + printf("[file.c] rename %s => %s\n", oldpath, newpath); + + FILE* src = fopen(src_path, "r"); + if (src == NULL) { + fprintf(stderr, "Konnte die Quelldatei nicht oeffnen\n"); + errno = ENOENT; + return -1; + } + + FILE* dst; + if (is_directory(dst_path)) { + fprintf(stderr, "Ziel ist ein Verzeichnis\n"); + errno = EEXIST; + return -1; + } else { + dst = fopen(dst_path, "w"); + } + + if (dst == NULL) { + fprintf(stderr, "Konnte die Zieldatei nicht oeffnen\n"); + fclose(src); + errno = EACCES; + return -1; + } + + uint8_t buffer[BUFFER_SIZE]; + + while (!feof(src)) { + size_t length = fread(buffer, BUFFER_SIZE, 1, src); + if (length == 0) { + fprintf(stderr, "Fehler beim Kopieren: %d\n", length); + fclose(src); + fclose(dst); + errno = EIO; + return -1; + } + + fwrite(buffer, length, 1, dst); + } + + fclose(src); + fclose(dst); + + unlink(src_path); + + return 0; } +#undef BUFFER_SIZE #endif /** -- 1.6.0.2 From kevin at tyndur.org Sat Jul 4 14:11:08 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 4 Jul 2009 14:11:08 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: POSIX: Rueckgabewert von read In-Reply-To: <1246709469-6707-1-git-send-email-kevin@tyndur.org> References: <1246709469-6707-1-git-send-email-kevin@tyndur.org> Message-ID: <1246709469-6707-3-git-send-email-kevin@tyndur.org> ! libc: POSIX: Wenn read 0 zurueckgibt, heisst das EOF. Wenn nur im Moment nichts da ist, ist -1/EAGAIN der richtige Wert. Signed-off-by: Kevin Wolf --- src/modules/lib/posix/posix_files.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/src/modules/lib/posix/posix_files.c b/src/modules/lib/posix/posix_files.c index 34cc4ee..bbf4413 100644 --- a/src/modules/lib/posix/posix_files.c +++ b/src/modules/lib/posix/posix_files.c @@ -254,6 +254,14 @@ ssize_t read(int fd, void* buffer, size_t size) size_t bytes = fread(buffer, 1, size, file); // FIXME: Fehlerbehandlung + + if (bytes == 0) { + if (!feof(file)) { + errno = EAGAIN; + return -1; + } + } + return bytes; } -- 1.6.0.2 From m.nemo at gmx.net Sat Jul 4 15:28:40 2009 From: m.nemo at gmx.net (Andreas Freimuth) Date: Sat, 04 Jul 2009 15:28:40 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: Etwas besser gefaktes rename In-Reply-To: <1246709469-6707-2-git-send-email-kevin@tyndur.org> References: <1246709469-6707-1-git-send-email-kevin@tyndur.org> <1246709469-6707-2-git-send-email-kevin@tyndur.org> Message-ID: <4A4F5908.8070002@gmx.net> statt die ganzen Daten zu kopieren müsste es doch auch mit io_create_link(newpath, oldpath, true); io_remove_link(oldpath); gehen oder nicht? Zumindest wenn newpath und oldpath auf dem gleichen Laufwerk sind. -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : signature.asc Dateityp : application/pgp-signature Dateigröße : 898 bytes Beschreibung: OpenPGP digital signature URL : From mail at kevin-wolf.de Sat Jul 4 17:01:03 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 4 Jul 2009 17:01:03 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: Etwas besser gefaktes rename In-Reply-To: <4A4F5908.8070002@gmx.net> References: <1246709469-6707-1-git-send-email-kevin@tyndur.org> <1246709469-6707-2-git-send-email-kevin@tyndur.org> <4A4F5908.8070002@gmx.net> Message-ID: <200907041701.03664@kevin-wolf.de> Am Samstag, 4. Juli 2009 15:28 schrieb Andreas Freimuth: > statt die ganzen Daten zu kopieren müsste es doch auch mit > io_create_link(newpath, oldpath, true); > io_remove_link(oldpath); > gehen oder nicht? Zumindest wenn newpath und oldpath auf dem gleichen > Laufwerk sind. Im Prinzip ein guter Einwand und du hattest mich auch schon so weit, einen Editor zu öffnen, um das umzuändern. Aber dann ist mir aufgefallen, dass wir momentan gar kein Dateisystem haben, das mit Hardlinks umgehen kann... Die scheinen nichtmal in cdi/fs vorgesehen zu sein. Also, wenn du Lust hast... ;-) From toni at tyndur.org Sat Jul 4 22:34:28 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 4 Jul 2009 22:34:28 +0200 Subject: [tyndur-devel] [PATCH 2/3] libc: POSIX: Rueckgabewert von read In-Reply-To: <1246709469-6707-3-git-send-email-kevin@tyndur.org> References: <1246709469-6707-1-git-send-email-kevin@tyndur.org> <1246709469-6707-3-git-send-email-kevin@tyndur.org> Message-ID: <20090704203427.GA27683@einstein.produktiv.lan> On Sat, Jul 04 14:11, Kevin Wolf wrote: > ! libc: POSIX: Wenn read 0 zurueckgibt, heisst das EOF. Wenn nur im > Moment nichts da ist, ist -1/EAGAIN der richtige Wert. > > Signed-off-by: Kevin Wolf > --- > src/modules/lib/posix/posix_files.c | 8 ++++++++ > 1 files changed, 8 insertions(+), 0 deletions(-) > > diff --git a/src/modules/lib/posix/posix_files.c b/src/modules/lib/posix/posix_files.c > index 34cc4ee..bbf4413 100644 > --- a/src/modules/lib/posix/posix_files.c > +++ b/src/modules/lib/posix/posix_files.c > @@ -254,6 +254,14 @@ ssize_t read(int fd, void* buffer, size_t size) > > size_t bytes = fread(buffer, 1, size, file); > // FIXME: Fehlerbehandlung > + > + if (bytes == 0) { > + if (!feof(file)) { Wie wärs mit if (!bytes && !feof(file)), oder meinetwegen auch (bytes == 0) && !feof(file) > + errno = EAGAIN; > + return -1; > + } > + } > + > return bytes; > } Aber jo, ich glaube dass du das alleine hinbekommst, danach also rein damit ;-) Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Jul 4 22:37:45 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 4 Jul 2009 22:37:45 +0200 Subject: [tyndur-devel] [PATCH 3/3] libc: POSIX: Fixes fuer select In-Reply-To: <1246709469-6707-4-git-send-email-kevin@tyndur.org> References: <1246709469-6707-1-git-send-email-kevin@tyndur.org> <1246709469-6707-4-git-send-email-kevin@tyndur.org> Message-ID: <20090704203745.GB27683@einstein.produktiv.lan> On Sat, Jul 04 14:11, Kevin Wolf wrote: > ! libc: POSIX: select(): Sekunden sind das, was lang dauert, und > Mikrosekunden das kurze. Nicht umgekehrt. > ! libc: POSIX: select(): Ein Nullbyte ist eigentlich eine perfekte > Eingabe, kein Fehler. > > Signed-off-by: Kevin Wolf > --- > src/modules/lib/posix/select.c | 7 ++++--- > 1 files changed, 4 insertions(+), 3 deletions(-) > > diff --git a/src/modules/lib/posix/select.c b/src/modules/lib/posix/select.c > index 539f555..9ae365c 100644 > --- a/src/modules/lib/posix/select.c > +++ b/src/modules/lib/posix/select.c > @@ -67,8 +67,9 @@ int select(int number_fds, fd_set* readfds, fd_set* writefds, > > uint64_t timeout_tick; > if (timeout != NULL) { > - timeout_tick = get_tick_count() + timeout->tv_sec + > - 1000ULL * 1000ULL * timeout->tv_usec; > + timeout_tick = get_tick_count() + > + 1000ULL * 1000ULL * timeout->tv_sec + > + timeout->tv_usec; > } else { > timeout_tick = (uint64_t) -1; > } > @@ -101,7 +102,7 @@ int select(int number_fds, fd_set* readfds, fd_set* writefds, > > if (f != NULL) { > c = fgetc(f); > - if (c == 0 || c == EOF) { > + if (c == EOF) { Hm ich glaube das ist so auch doof... Gibt unser fgetc wirklich EOF zurück, wenns grad nichts zu lesen gibt? > *rd &= ~(1 << i); > } else { > ungetc(c, f); -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sun Jul 5 19:27:58 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 5 Jul 2009 19:27:58 +0200 Subject: [tyndur-devel] [PATCH] root-common: tmp-Verzeichnis Message-ID: <1246814878-26394-1-git-send-email-kevin@tyndur.org> + root-common: Mit einem /tmp laufen manche Programme besser Signed-off-by: Kevin Wolf --- 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 build/root-common/tmp/dummy.txt diff --git a/build/root-common/tmp/dummy.txt b/build/root-common/tmp/dummy.txt new file mode 100644 index 0000000..e69de29 -- 1.6.0.2 From kevin at tyndur.org Sun Jul 5 19:28:04 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 5 Jul 2009 19:28:04 +0200 Subject: [tyndur-devel] [PATCH] tcpip: Fix fuer Erkennung von SYN ACK Message-ID: <1246814884-26442-1-git-send-email-kevin@tyndur.org> ! tcpip: Fuer ein SYN ACK muessen beide Flags gesetzt sein, nicht nur eins. Signed-off-by: Kevin Wolf --- src/modules/tcpip/tcp.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/modules/tcpip/tcp.c b/src/modules/tcpip/tcp.c index 721a690..0327c6e 100644 --- a/src/modules/tcpip/tcp.c +++ b/src/modules/tcpip/tcp.c @@ -415,7 +415,7 @@ void tcp_receive(dword source_ip, void* data, dword data_size) // den Daten ankommen und daf�r sorgen, da� diese verworfen werden switch (conn->status) { case TCPS_WAIT_FOR_SYN_ACK: - if (header->flags & (TCPF_SYN | TCPF_ACK)) { + if ((header->flags & TCPF_SYN) && (header->flags & TCPF_ACK)) { DEBUG_MSG("SYN ACK erhalten"); conn->ack = big_endian_dword(header->seq) + 1;//data_size; conn->window = 0x1000; -- 1.6.0.2 From toni at tyndur.org Sun Jul 5 19:30:31 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 5 Jul 2009 19:30:31 +0200 Subject: [tyndur-devel] [PATCH] tcpip: Fix fuer Erkennung von SYN ACK In-Reply-To: <1246814884-26442-1-git-send-email-kevin@tyndur.org> References: <1246814884-26442-1-git-send-email-kevin@tyndur.org> Message-ID: <20090705173031.GA1906@einstein.produktiv.lan> On Sun, Jul 05 19:28, Kevin Wolf wrote: > ! tcpip: Fuer ein SYN ACK muessen beide Flags gesetzt sein, nicht nur > eins. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jul 5 19:30:57 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 5 Jul 2009 19:30:57 +0200 Subject: [tyndur-devel] [PATCH] root-common: tmp-Verzeichnis In-Reply-To: <1246814878-26394-1-git-send-email-kevin@tyndur.org> References: <1246814878-26394-1-git-send-email-kevin@tyndur.org> Message-ID: <20090705173057.GB1906@einstein.produktiv.lan> On Sun, Jul 05 19:27, Kevin Wolf wrote: > + root-common: Mit einem /tmp laufen manche Programme besser > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jul 5 19:48:03 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 5 Jul 2009 19:48:03 +0200 Subject: [tyndur-devel] [PATCH 1/3] libc: Etwas besser gefaktes rename In-Reply-To: <1246709469-6707-2-git-send-email-kevin@tyndur.org> References: <1246709469-6707-1-git-send-email-kevin@tyndur.org> <1246709469-6707-2-git-send-email-kevin@tyndur.org> Message-ID: <20090705174803.GA6144@einstein.produktiv.lan> On Sat, Jul 04 14:11, Kevin Wolf wrote: > + libc: rename() kann jetzt Dateien verschieben (durch kopieren und > loeschen). Verzeichnisse gehen nach wie vor nicht. > > Signed-off-by: Kevin Wolf > --- > src/modules/lib/stdlibc/file.c | 55 ++++++++++++++++++++++++++++++++++++++- > 1 files changed, 53 insertions(+), 2 deletions(-) > > diff --git a/src/modules/lib/stdlibc/file.c b/src/modules/lib/stdlibc/file.c > index 5bb60cd..7ec650e 100644 > --- a/src/modules/lib/stdlibc/file.c > +++ b/src/modules/lib/stdlibc/file.c > @@ -857,14 +857,65 @@ int remove(const char* filename) > } > > #ifndef CONFIG_LIBC_NO_STUBS > +#include > +#include > +#define BUFFER_SIZE 4096 > /** > * Datei verschieben > */ > int rename(const char* oldpath, const char* newpath) > { > - printf("[file.c] FIXME: rename aufgerufen, aber nicht implementiert\n"); > - return -1; > + const char* src_path = oldpath; > + const char* dst_path = newpath; > + > + printf("[file.c] rename %s => %s\n", oldpath, newpath); > + > + FILE* src = fopen(src_path, "r"); > + if (src == NULL) { > + fprintf(stderr, "Konnte die Quelldatei nicht oeffnen\n"); > + errno = ENOENT; > + return -1; > + } > + > + FILE* dst; > + if (is_directory(dst_path)) { > + fprintf(stderr, "Ziel ist ein Verzeichnis\n"); > + errno = EEXIST; > + return -1; > + } else { > + dst = fopen(dst_path, "w"); > + } > + > + if (dst == NULL) { > + fprintf(stderr, "Konnte die Zieldatei nicht oeffnen\n"); > + fclose(src); > + errno = EACCES; > + return -1; > + } > + > + uint8_t buffer[BUFFER_SIZE]; Den hätte ich lieber ein paar Zeilen weiter oben. > + > + while (!feof(src)) { > + size_t length = fread(buffer, BUFFER_SIZE, 1, src); > + if (length == 0) { > + fprintf(stderr, "Fehler beim Kopieren: %d\n", length); > + fclose(src); > + fclose(dst); > + errno = EIO; > + return -1; > + } > + > + fwrite(buffer, length, 1, dst); Wenn du schon brav auf IO-Probleme prüfst, dann doch hier auch gleich. ;-) > + } > + > + fclose(src); > + fclose(dst); > + > + unlink(src_path); > + > + return 0; > } > +#undef BUFFER_SIZE > #endif > > /** Hm, die Fehlermeldungen finde ich irgendwie etwas seltsam... ;-) Aber sonst sieht das vernünftig aus. Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From xanclic at googlemail.com Tue Jul 7 16:52:55 2009 From: xanclic at googlemail.com (Max Reitz) Date: Tue, 7 Jul 2009 16:52:55 +0200 Subject: [tyndur-devel] [PATCH] tcpip: SYN-ACK-Timeout-TODO + Clientportoverflow Message-ID: <1246978375-23235-1-git-send-email-xanclic@googlemail.com> + tcpip: Verbindung wird bei SYN-ACK-Timeout getrennt. + tcpip: Die if-Abfrage in tcp_get_free_port() soll ein Overflow der Clientports verhindern (damit Ports wie 80 oder 21 nicht aus Versehen belegt werden). --- src/modules/tcpip/tcp.c | 22 +++++++++++++++++++--- 1 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/modules/tcpip/tcp.c b/src/modules/tcpip/tcp.c index 84d272a..061ceb9 100644 --- a/src/modules/tcpip/tcp.c +++ b/src/modules/tcpip/tcp.c @@ -81,6 +81,9 @@ static word tcp_get_free_port(void) { // FIXME static word source_port = 32768; + if (source_port > 65500) { //Bisschen Platz lassen + source_port = 32768; + } return source_port++; } @@ -183,6 +186,7 @@ struct tcp_connection* tcp_open_connection(dword ip, word port) { struct routing_entry* route = get_routing_entry(ip); uint64_t timeout; + int tcp_list_size, i; if (route == NULL) { return NULL; @@ -218,7 +222,19 @@ struct tcp_connection* tcp_open_connection(dword ip, word port) } if (conn->status == TCPS_WAIT_FOR_SYN_ACK) { - // TODO Verbindung abbrechen und wieder freigeben + tcp_send_reset(conn); + tcp_list_size = list_size(tcp_connections); + for (i = 0; i < tcp_list_size; i++) //Geht alle Elemente durch, es könnte ja sein, dass conn jetzt nicht mehr das erste Element ist + { + if (list_get_element_at(tcp_connections, i) == conn) { + list_remove(tcp_connections, i); //Hoffen wir mal, dass in der Zwischenzeit (von list_get_element_at() bis hier) nichts gepusht wurde + break; + } + } + list_destroy(conn->out_buffer); + list_destroy(conn->in_buffer); + list_destroy(conn->to_lostio); + free(conn); DEBUG_MSG("Timeout beim Verbindungsaufbau"); return NULL; } @@ -290,7 +306,7 @@ dword tcp_check_in_data_order(struct tcp_connection* conn) } v(); - DEBUG_MSG1("Verbleibende Segemnte im in-Buffer: %d", + DEBUG_MSG1("Verbleibende Segmente im in-Buffer: %d", list_size(conn->in_buffer)); @@ -378,7 +394,7 @@ void tcp_receive(dword source_ip, void* data, dword data_size) printf("\033[1;31mTCP-Checksumme ungueltig\n\033[0;37m\n\n"); - printf("\033[1;31mTCP-Checksumme ungueltig\n\033[0;37m\n\n"); + //printf("\033[1;31mTCP-Checksumme ungueltig\n\033[0;37m\n\n"); #if 0 debug_checksum = TRUE; -- 1.6.0.2 From xanclic at googlemail.com Tue Jul 7 17:47:40 2009 From: xanclic at googlemail.com (Max Reitz) Date: Tue, 7 Jul 2009 17:47:40 +0200 Subject: [tyndur-devel] [PATCH] tcpip: tcp_free_connection() Message-ID: <1246981660-6626-1-git-send-email-xanclic@googlemail.com> ! tcpip: Das Löschen einer Verbindung nach tcp_free_connection() ausgelagert (und gelockt) - tcpip: Kommentar des doppelten printf() --- src/modules/tcpip/include/tcp.h | 1 + src/modules/tcpip/tcp.c | 46 ++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/modules/tcpip/include/tcp.h b/src/modules/tcpip/include/tcp.h index 4f33957..b0b5917 100644 --- a/src/modules/tcpip/include/tcp.h +++ b/src/modules/tcpip/include/tcp.h @@ -116,6 +116,7 @@ struct tcp_server { void init_tcp(void); struct tcp_connection* tcp_open_connection(dword ip, word port); +void tcp_free_connection(struct tcp_connection* conn); void tcp_accept_connection(struct tcp_connection* conn); word tcp_checksum diff --git a/src/modules/tcpip/tcp.c b/src/modules/tcpip/tcp.c index 061ceb9..1501316 100644 --- a/src/modules/tcpip/tcp.c +++ b/src/modules/tcpip/tcp.c @@ -186,7 +186,6 @@ struct tcp_connection* tcp_open_connection(dword ip, word port) { struct routing_entry* route = get_routing_entry(ip); uint64_t timeout; - int tcp_list_size, i; if (route == NULL) { return NULL; @@ -223,18 +222,7 @@ struct tcp_connection* tcp_open_connection(dword ip, word port) if (conn->status == TCPS_WAIT_FOR_SYN_ACK) { tcp_send_reset(conn); - tcp_list_size = list_size(tcp_connections); - for (i = 0; i < tcp_list_size; i++) //Geht alle Elemente durch, es könnte ja sein, dass conn jetzt nicht mehr das erste Element ist - { - if (list_get_element_at(tcp_connections, i) == conn) { - list_remove(tcp_connections, i); //Hoffen wir mal, dass in der Zwischenzeit (von list_get_element_at() bis hier) nichts gepusht wurde - break; - } - } - list_destroy(conn->out_buffer); - list_destroy(conn->in_buffer); - list_destroy(conn->to_lostio); - free(conn); + tcp_free_connection(conn); DEBUG_MSG("Timeout beim Verbindungsaufbau"); return NULL; } @@ -244,6 +232,36 @@ struct tcp_connection* tcp_open_connection(dword ip, word port) return conn; } +void tcp_free_connection(struct tcp_connection* conn) +{ + int tcp_list_size, i; + + tcp_list_size = list_size(tcp_connections); + for (i = 0; i < tcp_list_size; i++) //Geht alle Elemente durch, es koennte + //ja sein, dass conn jetzt nicht mehr + //das erste Element ist + { + if (list_get_element_at(tcp_connections, i) == conn) { + p(); + //Falls inzwischen was geaendert wurde, dauert das erneute Durchlaufen + //der ganze Liste relativ lang. Aber es passiert vermutlich selten und + //anstatt die ganze Schleife zu locken, ist das bestimmt besser. + if (list_get_element_at(tcp_connections, i) != conn) { + v(); + i = -1; //Wird nach dem continue auf 0 inkrementiert + continue; + } + list_remove(tcp_connections, i); + v(); + break; + } + } + list_destroy(conn->out_buffer); + list_destroy(conn->in_buffer); + list_destroy(conn->to_lostio); + free(conn); +} + void tcp_accept_connection(struct tcp_connection* conn) { DEBUG_MSG("tcp_send_syn_ack"); @@ -394,8 +412,6 @@ void tcp_receive(dword source_ip, void* data, dword data_size) printf("\033[1;31mTCP-Checksumme ungueltig\n\033[0;37m\n\n"); - //printf("\033[1;31mTCP-Checksumme ungueltig\n\033[0;37m\n\n"); - #if 0 debug_checksum = TRUE; p(); -- 1.6.0.2 From alex at tyndur.org Tue Jul 7 22:01:51 2009 From: alex at tyndur.org (Alexander Siol) Date: Tue, 7 Jul 2009 22:01:51 +0200 Subject: [PATCH] +cp: -r, -v und -t hinzugefügt Message-ID: <1246996911-30080-1-git-send-email-alex@tyndur.org> --- trunk/src/modules/c/shell/cmds/cp.c | 178 ++++++++++++++++++++++++++++++----- 1 files changed, 155 insertions(+), 23 deletions(-) diff --git a/trunk/src/modules/c/shell/cmds/cp.c b/trunk/src/modules/c/shell/cmds/cp.c index 2c1ada5..df733ab 100644 --- a/trunk/src/modules/c/shell/cmds/cp.c +++ b/trunk/src/modules/c/shell/cmds/cp.c @@ -41,11 +41,17 @@ #include "stdlib.h" #include "stdio.h" #include "unistd.h" +#include "getopt.h" +#include "collections.h" #include #define BUFFER_SIZE 4096 +int verbosity = 0; + void cp_display_usage(void); +int cp_file(char* src_path, char* dst_path); +int cp_recursive(char* src_path, char* dst_path); #ifdef CONFIG_SHELL_BUILTIN_ONLY int shell_command_cp(int argc, char* argv[], const char* args) @@ -53,21 +59,155 @@ void cp_display_usage(void); int main(int argc, char* argv[]) #endif { - if (argc != 3) { + static const struct option long_options[] = + { + { "target", required_argument, 0, 't' }, + { "recursive", no_argument, 0, 'r' }, + { "verbose", no_argument, 0, 'v' }, + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + optind = 0; + + char* targetpath = NULL; + list_t* sources = list_create(); + + int index = -1; + int result; + + int recursive = 0; + + while (optind < argc) { + result = getopt_long(argc, argv, "vrt:", long_options, &index); + if (result == -1) { + break; + } + switch (result) { + case 't': + targetpath = optarg; + break; + case 'r': + recursive = 1; + break; + case 'v': + verbosity++; + break; + case 'h': + cp_display_usage(); + return EXIT_SUCCESS; + default: + break; + } + } + + while (optind < argc) { + list_push(sources, (void*)argv[optind++]); + } + + // Falls kein Target-Parameter gegeben ist, letztes Element des Listings. + if (targetpath == NULL) { + targetpath = (char*)list_pop(sources); + } + + if (targetpath == NULL || list_size(sources) == 0) { cp_display_usage(); + goto bad_exit; + } + + if ( (list_size(sources) > 1) && (!is_directory(targetpath)) ) { + fprintf(stderr, + "Fehler: Mehrere Quellen, aber Ziel ist kein Verzeichnis!\n"); + goto bad_exit; + } + + char* src_path = NULL; + while ( (src_path = (char*)list_pop(sources)) ) { + if (is_directory(src_path)) { + if (recursive) { + cp_recursive(src_path, targetpath); + } + else { + fprintf(stderr, "%s übersprungen (suchen sie 'cp -r' ?)\n"); + goto bad_exit; + } + } else { + result = cp_file(src_path, targetpath); + if (result == -1) { + fprintf(stderr, "Konnte die Quelldatei nicht öffnen\n"); + goto bad_exit; + } + else if (result == -2) { + fprintf(stderr, "Konnte die Zieldatei nicht öffnen\n"); + goto bad_exit; + } + } + } + + list_destroy(sources); + return EXIT_SUCCESS; + + bad_exit: + list_destroy(sources); + return EXIT_FAILURE; +} + +void cp_display_usage() +{ + printf("Aufruf: cp [OPTIONEN] \n" + " oder: cp [OPTIONEN] ... \n" + " oder: cp [OPTIONEN] -t ...\n" + "\n" + "Optionen:\n" + " -v --verbose durchgeführte Tätigkeiten erklären\n" + " -r --recursive Verzeichnisse rekursiv kopieren\n" + " -h --help diese Hilfe anzeigen\n"); +} + +int cp_recursive(char* src_path, char* dst_path) +{ + if (is_directory(dst_path)) { + dst_path = strcat(dst_path, io_split_filename(src_path)); + } + if (!directory_create(dst_path)) { + fprintf(stderr, "Fehler: Pfad %s konnte nicht angelegt werden!\n", dst_path); + fprintf(stderr, " %s übersprungen.\n", src_path); + return -1; + } + printf("'%s' -> '%s'\n", src_path, dst_path); + + io_resource_t* dir_res = directory_open(src_path); + char *full_src_path = NULL; + char *full_dst_path = NULL; + if (dir_res != NULL) { + io_direntry_t* direntry; + while ((direntry = directory_read(dir_res))) { + asprintf(&full_src_path, "%s/%s", src_path, direntry->name); + asprintf(&full_dst_path, "%s/%s", dst_path, direntry->name); + if (direntry->type == IO_DIRENTRY_FILE) { + cp_file(full_src_path, full_dst_path); + } else { + cp_recursive(full_src_path, full_dst_path); + } + free(full_src_path); + free(full_dst_path); + free(direntry); + } + directory_close(dir_res); + return 1; + } + else { return -1; } - - char* src_path = argv[1]; - char* dst_path = argv[2]; +} +int cp_file(char* src_path, char* dst_path) { FILE* src = fopen(src_path, "r"); if (src == NULL) { - fprintf(stderr, "Konnte die Quelldatei nicht oeffnen\n"); - return EXIT_FAILURE; + return -1; } - FILE* dst; + FILE* dst = NULL; if (is_directory(dst_path)) { char* filename = io_split_filename(src_path); size_t length = strlen(filename) + strlen(dst_path) + 1; @@ -78,20 +218,18 @@ void cp_display_usage(void); dst_file_path[strlen(dst_file_path)] = '/'; strcat(dst_file_path, filename); dst_file_path[length] = '\0'; - - dst = fopen(dst_file_path, "w"); - } else { - dst = fopen(dst_path, "w"); + dst_path = dst_file_path; } + dst = fopen(dst_path, "w"); if (dst == NULL) { - fprintf(stderr, "Konnte die Zieldatei nicht oeffnen\n"); - fclose(src); - return EXIT_FAILURE; + return -2; } uint8_t buffer[BUFFER_SIZE]; - + + printf("'%s' -> '%s'\n", src_path, dst_path); + while (!feof(src)) { size_t length = fread(buffer, BUFFER_SIZE, 1, src); if (length == 0) { @@ -100,18 +238,12 @@ void cp_display_usage(void); fclose(dst); return EXIT_FAILURE; } - + fwrite(buffer, length, 1, dst); } fclose(src); fclose(dst); - return EXIT_SUCCESS; -} - -void cp_display_usage() -{ - puts("\nAufruf: cp "); + return 1; } - -- 1.6.0.4 From alex at tyndur.org Wed Jul 8 15:31:27 2009 From: alex at tyndur.org (Alexander Siol) Date: Wed, 8 Jul 2009 15:31:27 +0200 Subject: [PATCH] Re: +cp: -r, -v und -t hinzugefügt In-Reply-To: <1246996911-30080-1-git-send-email-alex@tyndur.org> References: <1246996911-30080-1-git-send-email-alex@tyndur.org> Message-ID: <1247059887-29488-1-git-send-email-alex@tyndur.org> --- trunk/src/modules/c/shell/cmds/cp.c | 181 ++++++++++++++++++++++++++++++---- 1 files changed, 159 insertions(+), 22 deletions(-) diff --git a/trunk/src/modules/c/shell/cmds/cp.c b/trunk/src/modules/c/shell/cmds/cp.c index 2c1ada5..30b8f53 100644 --- a/trunk/src/modules/c/shell/cmds/cp.c +++ b/trunk/src/modules/c/shell/cmds/cp.c @@ -41,11 +41,17 @@ #include "stdlib.h" #include "stdio.h" #include "unistd.h" +#include "getopt.h" +#include "collections.h" #include #define BUFFER_SIZE 4096 +int verbosity = 0; + void cp_display_usage(void); +int cp_file(char* src_path, char* dst_path); +int cp_recursive(char* src_path, char* dst_path); #ifdef CONFIG_SHELL_BUILTIN_ONLY int shell_command_cp(int argc, char* argv[], const char* args) @@ -53,21 +59,158 @@ void cp_display_usage(void); int main(int argc, char* argv[]) #endif { - if (argc != 3) { + static const struct option long_options[] = + { + { "target", required_argument, 0, 't' }, + { "recursive", no_argument, 0, 'r' }, + { "verbose", no_argument, 0, 'v' }, + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + optind = 0; + verbosity = 0; + + char* targetpath = NULL; + list_t* sources = list_create(); + + int index = -1; + int result; + + int recursive = 0; + + while (optind < argc) { + result = getopt_long(argc, argv, "vrt:", long_options, &index); + if (result == -1) { + break; + } + switch (result) { + case 't': + targetpath = optarg; + break; + case 'r': + recursive = 1; + break; + case 'v': + verbosity++; + break; + case 'h': + cp_display_usage(); + return EXIT_SUCCESS; + default: + break; + } + } + + while (optind < argc) { + list_push(sources, (void*)argv[optind++]); + } + + // Falls kein Target-Parameter gegeben ist, letztes Element des Listings. + if (targetpath == NULL) { + targetpath = (char*)list_pop(sources); + } + + if (targetpath == NULL || list_size(sources) == 0) { cp_display_usage(); + goto bad_exit; + } + + if ( (list_size(sources) > 1) && (!is_directory(targetpath)) ) { + fprintf(stderr, + "Fehler: Mehrere Quellen, aber Ziel ist kein Verzeichnis!\n"); + goto bad_exit; + } + + char* src_path = NULL; + while ( (src_path = (char*)list_pop(sources)) ) { + if (is_directory(src_path)) { + if (recursive) { + cp_recursive(src_path, targetpath); + } + else { + fprintf(stderr, "%s übersprungen (suchen sie 'cp -r' ?)\n", src_path); + goto bad_exit; + } + } else { + result = cp_file(src_path, targetpath); + if (result == -1) { + fprintf(stderr, "Konnte die Quelldatei nicht öffnen\n"); + goto bad_exit; + } + else if (result == -2) { + fprintf(stderr, "Konnte die Zieldatei nicht öffnen\n"); + goto bad_exit; + } + } + } + + list_destroy(sources); + return EXIT_SUCCESS; + + bad_exit: + list_destroy(sources); + return EXIT_FAILURE; +} + +void cp_display_usage() +{ + printf("Aufruf: cp [OPTIONEN] \n" + " oder: cp [OPTIONEN] ... \n" + " oder: cp [OPTIONEN] -t ...\n" + "\n" + "Optionen:\n" + " -v --verbose durchgeführte Tätigkeiten erklären\n" + " -r --recursive Verzeichnisse rekursiv kopieren\n" + " -h --help diese Hilfe anzeigen\n"); +} + +int cp_recursive(char* src_path, char* dst_path) +{ + if (is_directory(dst_path)) { + dst_path = strcat(dst_path, io_split_filename(src_path)); + } + if (!directory_create(dst_path)) { + fprintf(stderr, "Fehler: Pfad %s konnte nicht angelegt werden!\n", dst_path); + fprintf(stderr, " %s übersprungen.\n", src_path); return -1; } + if (verbosity > 0) { + printf("'%s' -> '%s'\n", src_path, dst_path); + } - char* src_path = argv[1]; - char* dst_path = argv[2]; + io_resource_t* dir_res = directory_open(src_path); + char *full_src_path = NULL; + char *full_dst_path = NULL; + if (dir_res != NULL) { + io_direntry_t* direntry; + while ((direntry = directory_read(dir_res))) { + asprintf(&full_src_path, "%s/%s", src_path, direntry->name); + asprintf(&full_dst_path, "%s/%s", dst_path, direntry->name); + if (direntry->type == IO_DIRENTRY_FILE) { + cp_file(full_src_path, full_dst_path); + } else { + cp_recursive(full_src_path, full_dst_path); + } + free(full_src_path); + free(full_dst_path); + free(direntry); + } + directory_close(dir_res); + return 1; + } + else { + return -1; + } +} +int cp_file(char* src_path, char* dst_path) { FILE* src = fopen(src_path, "r"); if (src == NULL) { - fprintf(stderr, "Konnte die Quelldatei nicht oeffnen\n"); - return EXIT_FAILURE; + return -1; } - FILE* dst; + FILE* dst = NULL; if (is_directory(dst_path)) { char* filename = io_split_filename(src_path); size_t length = strlen(filename) + strlen(dst_path) + 1; @@ -78,20 +221,20 @@ void cp_display_usage(void); dst_file_path[strlen(dst_file_path)] = '/'; strcat(dst_file_path, filename); dst_file_path[length] = '\0'; - - dst = fopen(dst_file_path, "w"); - } else { - dst = fopen(dst_path, "w"); + dst_path = dst_file_path; } + dst = fopen(dst_path, "w"); if (dst == NULL) { - fprintf(stderr, "Konnte die Zieldatei nicht oeffnen\n"); - fclose(src); - return EXIT_FAILURE; + return -2; } uint8_t buffer[BUFFER_SIZE]; - + + if (verbosity > 0) { + printf("'%s' -> '%s'\n", src_path, dst_path); + } + while (!feof(src)) { size_t length = fread(buffer, BUFFER_SIZE, 1, src); if (length == 0) { @@ -100,18 +243,12 @@ void cp_display_usage(void); fclose(dst); return EXIT_FAILURE; } - + fwrite(buffer, length, 1, dst); } fclose(src); fclose(dst); - return EXIT_SUCCESS; -} - -void cp_display_usage() -{ - puts("\nAufruf: cp "); + return 1; } - -- 1.6.0.4 From xanclic at googlemail.com Fri Jul 10 22:46:34 2009 From: xanclic at googlemail.com (Max Reitz) Date: Fri, 10 Jul 2009 22:46:34 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH=5D_Mau-Mau_hinzugef=C3=BCgt?= Message-ID: <1247258794-963-1-git-send-email-xanclic@googlemail.com> + Mau-Mau spielen - leider geht Backspace nicht, aber was kann ich dafür, wenn fgets() nicht blockiert... --- src/modules/c/maumau/Makefile.all | 8 + src/modules/c/maumau/libmaumau.c | 119 +++++ src/modules/c/maumau/libmaumau.h | 122 ++++++ src/modules/c/maumau/maumau.c | 861 +++++++++++++++++++++++++++++++++++++ 4 files changed, 1110 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/maumau/Makefile.all create mode 100644 src/modules/c/maumau/libmaumau.c create mode 100644 src/modules/c/maumau/libmaumau.h create mode 100644 src/modules/c/maumau/maumau.c diff --git a/src/modules/c/maumau/Makefile.all b/src/modules/c/maumau/Makefile.all new file mode 100644 index 0000000..d38bbd3 --- /dev/null +++ b/src/modules/c/maumau/Makefile.all @@ -0,0 +1,8 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/apps/maumau" +$LOST_TOOLS_LD -omaumau -Ttext=0x40000000 *.o --start-group $2 --end-group + + +$LOST_TOOLS_STRIP -s maumau -o $1/apps/maumau diff --git a/src/modules/c/maumau/libmaumau.c b/src/modules/c/maumau/libmaumau.c new file mode 100644 index 0000000..f07b0dd --- /dev/null +++ b/src/modules/c/maumau/libmaumau.c @@ -0,0 +1,119 @@ +/*************************************************************************** + * Copyright (C) 2009 by Max Reitz * + * xanclic at googlemail.com * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#define ISLIB + +#include "libmaumau.h" +#include +#include +#include + +#ifdef MYXOMYCOTA +#include +#else +#include +#endif + +maumau_t *newGame(player_count_t playerc, int correct_call) +{ + maumau_t *game; + + if ((playerc < 2) || (playerc > 5) || !correct_call) + return 0; + game = malloc(sizeof(maumau_t)); + game->_players = playerc; + game->_stackSize = 0; + return game; +} + +void startGame(maumau_t *game) +{ + int i, j, k; + + for (i = 0; i < 5; i++) + game->_player[i]._cards = 0; + k = 0; + for (i = MAUMAU_COLOUR_HEARTS; i <= MAUMAU_COLOUR_SPADES; i++) + { + for (j = MAUMAU_VALUE_7; j <= MAUMAU_VALUE_10; j++) + { + game->_stack[k]._single._colour = i; + game->_stack[k++]._single._value = j; + game->_stackSize++; + } + for (j = MAUMAU_VALUE_JACK; j <= MAUMAU_VALUE_ACE; j++) + { + game->_stack[k]._single._colour = i; + game->_stack[k++]._single._value = j; + game->_stackSize++; + } + } +} + +void shuffle(card_t *stack) +{ + card_t tmpstack[NUM_ELEMENTS]; + int i, j; + + #ifdef MYXOMYCOTA + srand(elapsedMilliseconds()); + #else + srand(time(NULL)); + #endif + memcpy(tmpstack, stack, sizeof(card_t)*NUM_ELEMENTS); + for (i = 0; i < NUM_ELEMENTS; i++) + { + while (!tmpstack[(j = rand()%NUM_ELEMENTS)]._single._value); + stack[i]._value = tmpstack[j]._value; + tmpstack[j]._single._value = 0; + } +} + +void action(maumau_t *game, int number, ...) +{ + va_list pars; + int which_player, cardstodo; + + va_start(pars, number); + switch (number) + { + case (MAUMAU_ACTION_PLAYER): + which_player = va_arg(pars, int)-1; + switch (va_arg(pars, int)) + { + case (MAUMAU_PLAYER_TAKE_CARDS): + for (cardstodo = va_arg(pars, int); (cardstodo > 0) && (game->_player[which_player]._cards < 16) && (game->_stackSize > 0); cardstodo--) + { + game->_player[which_player]._hand[(int)game->_player[which_player]._cards++]._value = game->_stack[(int)--game->_stackSize]._value; + game->_stack[(int)game->_stackSize]._value = 0; + } + break; + } + break; + } + va_end(pars); +} + +void putCurrentCardUnderStack(maumau_t *game) +{ + memmove(&game->_stack[1], &game->_stack[0], sizeof(card_t)*(NUM_ELEMENTS-1)); + game->_stack[0]._value = game->_currentCard._value; + game->_stackSize++; +} diff --git a/src/modules/c/maumau/libmaumau.h b/src/modules/c/maumau/libmaumau.h new file mode 100644 index 0000000..7c30e4c --- /dev/null +++ b/src/modules/c/maumau/libmaumau.h @@ -0,0 +1,122 @@ +/*************************************************************************** + * Copyright (C) 2009 by Max Reitz * + * xanclic at googlemail.com * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef __LIBMAUMAU_H +#define __LIBMAUMAU_H + +#define NUM_ELEMENTS 32 + +#ifndef ISLIB + +const char *colour_name[4] = { + "Herz", + "Karo", + "Kreuz", + "Pik" +}; + +const char *value_name[11] = { + "", + "Bube", + "Dame", + "König", + "As", + "", + "", + "7", + "8", + "9", + "10" +}; + +const char value_char[11] = { + '?', + 'B', + 'D', + 'K', + 'A', + '?', + '?', + '7', + '8', + '9', + 'X' +}; + +#endif + +#define MAUMAU_COLOUR_HEARTS 0 /* Herz */ +#define MAUMAU_COLOUR_DIAMONDS 1 /* Karo */ +#define MAUMAU_COLOUR_CLUBS 2 /* Kreuz */ +#define MAUMAU_COLOUR_SPADES 3 /* Pik */ + +#define MAUMAU_VALUE_7 7 +#define MAUMAU_VALUE_8 8 +#define MAUMAU_VALUE_9 9 +#define MAUMAU_VALUE_10 10 +#define MAUMAU_VALUE_JACK 1 /* Bube */ +#define MAUMAU_VALUE_QUEEN 2 /* Dame */ +#define MAUMAU_VALUE_KING 3 /* König */ +#define MAUMAU_VALUE_ACE 4 /* As */ + +#define MAUMAU_ACTION_PLAYER 0 +#define MAUMAU_PLAYER_TAKE_CARDS 0 + +#define players ,1 +#define with (player_count_t) +#define player MAUMAU_ACTION_PLAYER, +#define takes ,MAUMAU_PLAYER_TAKE_CARDS, +#define cards +#define card + +typedef int player_count_t; + +typedef union +{ + struct + { + char _colour; + char _value; + } _single; + short _value; +} card_t; + +typedef struct +{ + char _cards; + card_t _hand[32]; +} player_t; + +typedef struct +{ + int _players; + int _stackSize; + player_t _player[5]; + card_t _stack[NUM_ELEMENTS]; + card_t _currentCard; +} maumau_t; + +void action(maumau_t *game, int number, ...); +maumau_t* newGame(player_count_t playerc, int correct_call); +void putCurrentCardUnderStack(maumau_t *game); +void shuffle(card_t *stack); +void startGame(maumau_t *game); + +#endif diff --git a/src/modules/c/maumau/maumau.c b/src/modules/c/maumau/maumau.c new file mode 100644 index 0000000..1885720 --- /dev/null +++ b/src/modules/c/maumau/maumau.c @@ -0,0 +1,861 @@ +/*************************************************************************** + * Copyright (C) 2009 by Max Reitz * + * xanclic at googlemail.com * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +//define this if you are using Linux or another OS with full Unicode support +//#define FULL_UNICODE + +//define this if you are using the (very strange) týndur standard C library +#define TYNDUR + +#include "libmaumau.h" +#include +#include +#include +#include + +#define SYMBOL_HEARTS 3 +#define SYMBOL_DIAMONDS 4 +#define SYMBOL_CLUBS 5 +#define SYMBOL_SPADES 6 + +#define MUST_NOTHING 0x00 +#define MUST_TAKE 0x01 +#define MUST_WAIT 0x02 + + +int main(int argc, char *argv[]) +{ + maumau_t *game; + FILE *graphic; + int i, _card = 0, playerMust[2] = {0, 0}, curcol, colcount[4], greatest, greatest_i, maybe, mau = 0, _take = 0, found, ignorePlayer1 = 0, c; + char inp[32], pafterclear[128]; + #ifdef TYNDUR + int inpi, tinp; + #endif + + if (argc > 2) + { + fprintf(stderr, "Unbekannte Parameter.\n"); + return EXIT_FAILURE; + } + if (argc == 2) + { + if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-?") || !strcmp(argv[1], "--help")) + { + printf("Ein einfaches Textbasiertes Mau-Mau.\n"); + printf("REGELN:\n"); + printf(" Zunächst gelten die Standardregeln von Mau-Mau. Achtung: Wer eine Karte\n"); + printf(" ziehen muss, weil er keine legen kann/will, der muss für diese Runde aus-\n"); + printf(" setzen.\n"); + printf("SONDERREGELN:\n"); + printf(" Ein Bube darf auf jede andere Karte gelegt werden (auch auf andere Buben).\n"); + printf(" Der ihn ausspielende Spieler darf nach dem Legen die nächste auszuspielende\n"); + printf(" Farbe wählen.\n"); + printf(" Wird eine 7 gelegt, so muss der andere Spieler zwei Karten ziehen, bevor er\n"); + printf(" seinen Zug ausführt, es sei denn, er kann mit einer 7 oder 10 antworten.\n"); + printf(" Wird eine 10 gelegt, so muss der andere Spieler eine Karte ziehen, bevor er\n"); + printf(" seinen Zug ausführt, es sei denn, er kann mit einer 7 oder 10 antworten.\n"); + printf(" \"Antworten\" heißt, auf eine \"Ziehkarte\" (7 oder 10) sofort eine andere\n"); + printf(" (beliebige) Ziehkarte zu legen und so die Anzahl der zu ziehenden Karten zu\n"); + printf(" erhöhen und die Bürde des Ziehens wieder dem anderen Spieler zu übertragen.\n"); + printf(" Ein As lässt den gegnerischen Spieler eine Runde aussetzen.\n"); + printf("\n"); + printf("Die genauen Regeln sollten Sie unter /mnt/fda/home/Mau-Mau-Regeln.txt finden.\n"); + return EXIT_SUCCESS; + } + else if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) + { + printf("MyxMauMau (MyX games) 0.5\nWritten by Max Reitz\n\n"); + printf("Using libmaumau 0.3\nWritten by Max Reitz with support from irc.euirc.net#tyndur\n"); + return EXIT_SUCCESS; + } + else + { + fprintf(stderr, "Unbekannter Parameter.\n"); + return EXIT_FAILURE; + } + } + + if ((graphic = fopen("/dev/c437console", "r"))) + freopen("/dev/c437console", "a", graphic); + + game = newGame(with 2 players); + startGame(game); + shuffle(game->_stack); + action(game, player 1 takes 6 cards); + action(game, player 2 takes 6 cards); + game->_currentCard._value = game->_stack[--game->_stackSize]._value; + curcol = game->_currentCard._single._colour; + + pafterclear[0] = 0; + + for (;;) + { + printf("\33[2J"); + + if (mau) + { + if (mau == 0x01) + printf("Sie: \""); + else if (mau == 0x02) + printf("Gegner: \""); + else + printf("Sie und Ihr Gegner: \""); + + printf("Mau!\"\n\n"); + mau = 0; + } + + printf("Aktuelle Farbe: "); + switch (curcol) + { + case (MAUMAU_COLOUR_HEARTS): printf("\33[31m"); + if (graphic) fputc(SYMBOL_HEARTS, graphic); + else + #ifndef FULL_UNICODE + putchar('H'); + #else + printf("\u2665"); + #endif + break; + case (MAUMAU_COLOUR_DIAMONDS): printf("\33[31m"); + if (graphic) fputc(SYMBOL_DIAMONDS, graphic); + else + #ifndef FULL_UNICODE + putchar('C'); + #else + printf("\u2666"); + #endif + break; + case (MAUMAU_COLOUR_CLUBS): printf("\33[30;1m"); + if (graphic) fputc(SYMBOL_CLUBS, graphic); + else + #ifndef FULL_UNICODE + putchar('K'); + #else + printf("\u2663"); + #endif + break; + case (MAUMAU_COLOUR_SPADES): printf("\33[30;1m"); + if (graphic) fputc(SYMBOL_SPADES, graphic); + else + #ifndef FULL_UNICODE + putchar('P'); + #else + printf("\u2660"); + #endif + break; + } + printf("\33[0m\n\n"); + + //BEGINN "KARTEN DES GEGNERS" + for (i = 0; i < game->_player[1]._cards; i++) + { + if (graphic) + { + if (!i) + fprintf(graphic, "\xDA\xC4\xC4\xC4"); + else + fprintf(graphic, "\xC2\xC4\xC4\xC4"); + } + else + printf("+---"); + } + if (graphic) + fprintf(graphic, "\xBF\n"); + else + printf("+\n"); + + for (i = 0; i < game->_player[1]._cards; i++) + { + if (graphic) + fprintf(graphic, "\xB3\33[34m\xB0\xB0\xB0\33[0m"); + else + printf("|\33[34m###\33[0m"); + } + if (graphic) + fputc('\xB3', graphic); + else + putchar('|'); + putchar('\n'); + for (i = 0; i < game->_player[1]._cards; i++) + { + if (graphic) + fprintf(graphic, "\xB3\33[34m\xB0\xB0\xB0\33[0m"); + else + printf("|\33[34m###\33[0m"); + } + if (graphic) + fprintf(graphic, "\xB3\n"); + else + printf("|\n"); + + for (i = 0; i < game->_player[1]._cards; i++) + { + if (graphic) + { + if (!i) + fprintf(graphic, "\xC0\xC4\xC4\xC4"); + else + fprintf(graphic, "\xC1\xC4\xC4\xC4"); + } + else + { + printf("+---"); + } + } + if (graphic) + fprintf(graphic, "\xD9\n"); + else + printf("+\n"); + //ENDE "KARTEN DES GEGNERS" + + //BEGINN "STAPEL" + if (graphic) + fprintf(graphic, "\xC9\xCD\xCD\xCD\xBB \xC9\xCD\xCD\xCD\xBB\n\xBA "); + else + printf("+===+ +===+\n| "); + switch (game->_currentCard._single._colour) + { + case (MAUMAU_COLOUR_HEARTS): printf("\33[31m"); + if (graphic) fputc(SYMBOL_HEARTS, graphic); + else + #ifndef FULL_UNICODE + putchar('H'); + #else + printf("\u2665"); + #endif + break; + case (MAUMAU_COLOUR_DIAMONDS): printf("\33[31m"); + if (graphic) fputc(SYMBOL_DIAMONDS, graphic); + else + #ifndef FULL_UNICODE + putchar('C'); + #else + printf("\u2666"); + #endif + break; + case (MAUMAU_COLOUR_CLUBS): printf("\33[30;1m"); + if (graphic) fputc(SYMBOL_CLUBS, graphic); + else + #ifndef FULL_UNICODE + putchar('K'); + #else + printf("\u2663"); + #endif + break; + case (MAUMAU_COLOUR_SPADES): printf("\33[30;1m"); + if (graphic) fputc(SYMBOL_SPADES, graphic); + else + #ifndef FULL_UNICODE + putchar('P'); + #else + printf("\u2660"); + #endif + break; + } + printf("\33[0m "); + if (graphic) + fprintf(graphic, "\xBA \xBA\33[34m\xB0\xB0\xB0\33[0m\xBA\n\xBA"); + else + printf("| |\33[34m###\33[0m|\n|"); + printf(" %c ", value_char[(int)game->_currentCard._single._value]); + if (graphic) + { + fprintf(graphic, "\xBA \xBA\33[34m\xB0\xB0\xB0\33[0m\xBA\n"); + fprintf(graphic, "\xC8\xCD\xCD\xCD\xBC \xC8\xCD\xCD\xCD\xBC\n"); + } + else + { + printf("| |\33[34m###\33[0m|\n"); + printf("+===+ +===+\n"); + } + //ENDE "STAPEL" + + //BEGINN "EIGENE KARTEN" + for (i = 0; i < game->_player[0]._cards; i++) + { + if (graphic) + { + if (!i) + fprintf(graphic, "\xDA\xC4\xC4\xC4"); + else + fprintf(graphic, "\xC2\xC4\xC4\xC4"); + } + else + printf("+---"); + } + if (graphic) + fprintf(graphic, "\xBF\n"); + else + printf("+\n"); + + for (i = 0; i < game->_player[0]._cards; i++) + { + if (graphic) + fprintf(graphic, "\xB3 "); + else + printf("| "); + switch (game->_player[0]._hand[i]._single._colour) + { + case (MAUMAU_COLOUR_HEARTS): + printf("\33[31m"); + if (graphic) + fputc(SYMBOL_HEARTS, graphic); + else + #ifndef FULL_UNICODE + putchar('H'); + #else + printf("\u2665"); + #endif + break; + case (MAUMAU_COLOUR_DIAMONDS): + printf("\33[31m"); + if (graphic) + fputc(SYMBOL_DIAMONDS, graphic); + else + #ifndef FULL_UNICODE + putchar('C'); + #else + printf("\u2666"); + #endif + break; + case (MAUMAU_COLOUR_CLUBS): + printf("\33[30;1m"); + if (graphic) + fputc(SYMBOL_CLUBS, graphic); + else + #ifndef FULL_UNICODE + putchar('K'); + #else + printf("\u2663"); + #endif + break; + case (MAUMAU_COLOUR_SPADES): + printf("\33[30;1m"); + if (graphic) + fputc(SYMBOL_SPADES, graphic); + else + #ifndef FULL_UNICODE + putchar('P'); + #else + printf("\u2660"); + #endif + break; + } + printf("\33[0m "); + } + if (graphic) + fputc('\xB3', graphic); + else + putchar('|'); + putchar('\n'); + for (i = 0; i < game->_player[0]._cards; i++) + { + if (graphic) + fprintf(graphic, "\xB3 "); + else + printf("| "); + printf("%c ", value_char[(int)game->_player[0]._hand[i]._single._value]); + } + if (graphic) + fprintf(graphic, "\xB3\n"); + else + printf("|\n"); + + for (i = 0; i < game->_player[0]._cards; i++) + { + if (graphic) + { + if (!i) + fprintf(graphic, "\xC0\xC4\xC4\xC4"); + else + fprintf(graphic, "\xC1\xC4\xC4\xC4"); + } + else + { + printf("+---"); + } + } + if (graphic) + fprintf(graphic, "\xD9\n"); + else + printf("+\n"); + //ENDE "EIGENE KARTEN" + + //BEGINN "EIGENE KARTENNUMMERN" + i = 0; + while (i < game->_player[0]._cards) + printf("%3i ", ++i); + putchar('\n'); + //ENDE "EIGENE KARTENNUMMERN" + + //BEGINN "SPIELER LEGT" + if (ignorePlayer1) + { + ignorePlayer1 = 0; + goto Player2sTurn; + } + if (playerMust[0] & MUST_TAKE) + { + playerMust[0] &= ~MUST_TAKE; + for (i = 0, found = 0; i < game->_player[0]._cards; i++) + { + if ((game->_player[0]._hand[i]._single._value == MAUMAU_VALUE_7) || (game->_player[0]._hand[i]._single._value == MAUMAU_VALUE_10)) + { + found = 1; + break; + } + } + if (found) + { + printf("\nSie müssten jetzt %i %s ziehen, können dies aber auch abwehren.\n", _take, (_take == 1) ? "Karte" : "Karten"); + printf("Möchten Sie eine 7 oder 10 legen? "); + #ifdef MYXOMYCOTA + printf("[j/n] "); + fflush(stdout); + c = 0; + while ((c != 'j') && (c != 'n')) + c = tolower(getchar()); + printf("\n"); + #else + do + { + printf("[j/n] "); + fflush(stdout); + clearerr(stdin); + #ifdef TYNDUR + *inp = 0; + while ((tinp = getchar()) == EOF); + if (feof(stdin) || ferror(stdin) || (tinp == '\n')) + { + putchar('\n'); + clearerr(stdin); + } + else + { + putchar(tinp); + fflush(stdout); + *inp = tolower(tinp); + } + if (!*inp) + continue; + #else + fgets(inp, 31, stdin); + if (!*inp) + continue; + inp[strlen(inp)-1] = 0; + #endif + } while ((strlen(inp) != 1) || ((tolower(*inp) != 'j') && (tolower(*inp) != 'n'))); + c = tolower(*inp); + #endif + if (c == 'n') + found = 0; + else + { + printf("\nWelche Karte möchten Sie legen?\n"); + for (;;) + { + printf("> "); + fflush(stdout); + clearerr(stdin); + #ifdef TYNDUR + memset(inp, 0, 32); + for (inpi = 0; inpi < 32; inpi++) + { + while ((tinp = getchar()) == EOF); + if (feof(stdin) || ferror(stdin) || (tinp == '\n')) + { + putchar('\n'); + clearerr(stdin); + break; + } + putchar(tinp); + fflush(stdout); + inp[inpi] = tolower(tinp); + } + if (!*inp) + continue; + #else + fgets(inp, 31, stdin); + if (!*inp) + continue; + inp[strlen(inp)-1] = 0; + for (i = 0; i < strlen(inp); i++) + inp[i] = tolower(inp[i]); + #endif + if (!strcmp(inp, "keine")) + { + _card = 0; + break; + } + _card = atoi(inp); + if ((_card < 1) || (_card > game->_player[0]._cards)) + { + printf("Diese Karte haben Sie leider nicht.\n"); + continue; + } + else if ((game->_player[0]._hand[_card-1]._single._value != MAUMAU_VALUE_7 ) && + (game->_player[0]._hand[_card-1]._single._value != MAUMAU_VALUE_10)) + { + printf("Diese Karte können Sie leider nicht ablegen (nur 7 oder 10).\n"); + continue; + } + break; + } + if (!_card) + found = 0; + else + { + putCurrentCardUnderStack(game); + game->_currentCard._value = game->_player[0]._hand[_card-1]._value; + if (_card < game->_player[0]._cards) + memmove(&game->_player[0]._hand[_card-1], &game->_player[0]._hand[_card], sizeof(card_t)*(game->_player[0]._cards-_card)); + game->_player[0]._cards--; + + curcol = game->_currentCard._single._colour; + switch (game->_currentCard._single._value) + { + case (MAUMAU_VALUE_7): + playerMust[1] |= MUST_TAKE; + _take += 2; + break; + case (MAUMAU_VALUE_10): + playerMust[1] |= MUST_TAKE; + _take++; + break; + } + if (game->_player[0]._cards == 1) + mau |= 0x01; + else if (!game->_player[0]._cards) + { + printf("\33[32;1mMAU MAU!\33[0m\n\nHerzlichen Glückwunsch! Sie haben das Spiel gewonnen!\n"); + break; + } + } + } + ignorePlayer1 = 1; + } + if (!found) + { + sprintf(pafterclear, "\nSie müssen %i %s ziehen.\n", _take, (_take == 1) ? "Karte" : "Karten"); + action(game, player 1 takes _take cards); + _take = 0; + ignorePlayer1 = 0; + } + continue; //Alles neu zeichnen + } + if (*pafterclear) + { + printf(pafterclear); + *pafterclear = 0; + } + if (playerMust[0] & MUST_WAIT) + { + playerMust[0] &= ~MUST_WAIT; + printf("\nSie müssen aussetzen. Drücken Sie die Eingabetaste.\n"); + while (getchar() != '\n'); + } + else + { + printf("\nWelche Karte möchten Sie legen?\n"); + for (;;) + { + printf("> "); + fflush(stdout); + clearerr(stdin); + #ifdef TYNDUR + memset(inp, 0, 32); + for (inpi = 0; inpi < 32; inpi++) + { + while ((tinp = getchar()) == EOF); + if (feof(stdin) || ferror(stdin) || (tinp == '\n')) + { + putchar('\n'); + clearerr(stdin); + break; + } + putchar(tinp); + fflush(stdout); + inp[inpi] = tolower(tinp); + } + if (!*inp) + continue; + #else + fgets(inp, 31, stdin); + if (!*inp) + continue; + inp[strlen(inp)-1] = 0; + for (i = 0; i < strlen(inp); i++) + inp[i] = tolower(inp[i]); + #endif + if (!strcmp(inp, "keine")) + { + _card = 0; + break; + } + else if (!strcmp(inp, "quit")) + { + _card = -1; + break; + } + _card = atoi(inp); + if ((_card < 1) || (_card > game->_player[0]._cards)) + { + printf("Diese Karte haben Sie nicht.\n"); + continue; + } + else if (game->_player[0]._hand[_card-1]._single._value == MAUMAU_VALUE_JACK) + break; + else if ((game->_player[0]._hand[_card-1]._single._value != game->_currentCard._single._value) && + (game->_player[0]._hand[_card-1]._single._colour != curcol )) + { + printf("Diese Karte können Sie leider nicht ablegen.\n"); + continue; + } + break; + } + + if (_card == -1) + break; + + if (!_card) + action(game, player 1 takes 1 card); + else + { + putCurrentCardUnderStack(game); + game->_currentCard._value = game->_player[0]._hand[_card-1]._value; + if (_card < game->_player[0]._cards) + memmove(&game->_player[0]._hand[_card-1], &game->_player[0]._hand[_card], sizeof(card_t)*(game->_player[0]._cards-_card)); + game->_player[0]._cards--; + + if (game->_currentCard._single._value != MAUMAU_VALUE_JACK) + { + curcol = game->_currentCard._single._colour; + switch (game->_currentCard._single._value) + { + case (MAUMAU_VALUE_ACE): + playerMust[1] |= MUST_WAIT; + break; + case (MAUMAU_VALUE_7): + playerMust[1] |= MUST_TAKE; + _take += 2; + break; + case (MAUMAU_VALUE_10): + playerMust[1] |= MUST_TAKE; + _take++; + break; + } + } + else if (game->_player[0]._cards) + { + printf("Da Sie einen Buben gelegt haben, dürfen Sie jetzt eine Farbe wählen.\n"); + for (;;) + { + printf("Möchten Sie Kreuz (K), Pik (P), Herz (H) oder Karo (C)? "); + fflush(stdout); + clearerr(stdin); + #ifdef TYNDUR + *inp = 0; + while ((tinp = getchar()) == EOF); + if (feof(stdin) || ferror(stdin) || (tinp == '\n')) + { + putchar('\n'); + clearerr(stdin); + } + else + { + putchar(tinp); + fflush(stdout); + *inp = toupper(tinp); + putchar('\n'); + } + if (!*inp) + continue; + #else + fgets(inp, 31, stdin); + if (!*inp) + continue; + inp[strlen(inp)-1] = 0; + if (strlen(inp) != 1) + continue; + *inp = toupper(*inp); + #endif + if ((*inp == 'K') || (*inp == 'P') || (*inp == 'H') || (*inp == 'C')) + break; + } + switch (*inp) + { + case ('K'): + curcol = MAUMAU_COLOUR_CLUBS; + break; + case ('P'): + curcol = MAUMAU_COLOUR_SPADES; + break; + case ('H'): + curcol = MAUMAU_COLOUR_HEARTS; + break; + case ('C'): + curcol = MAUMAU_COLOUR_DIAMONDS; + break; + } + } + } + + if (game->_player[0]._cards == 1) + mau |= 0x01; + else if (!game->_player[0]._cards) + { + printf("\33[32;1mMAU MAU!\33[0m\n\nHerzlichen Glückwunsch! Sie haben das Spiel gewonnen!\n"); + break; + } + } + //ENDE "SPIELER LEGT" + + Player2sTurn: + + //BEGINN "GEGNER LEGT" + if (playerMust[1] & MUST_TAKE) + { + playerMust[1] &= ~MUST_TAKE; + for (i = 0, found = 0; i < game->_player[0]._cards; i++) + { + if ((game->_player[1]._hand[i]._single._value == MAUMAU_VALUE_7) || (game->_player[1]._hand[i]._single._value == MAUMAU_VALUE_10)) + { + found = i+1; + break; + } + } + if (found) + { + putCurrentCardUnderStack(game); + game->_currentCard._value = game->_player[1]._hand[found-1]._value; + if (_card < game->_player[1]._cards) + memmove(&game->_player[1]._hand[found-1], &game->_player[1]._hand[found], sizeof(card_t)*(game->_player[1]._cards-found)); + game->_player[1]._cards--; + + curcol = game->_currentCard._single._colour; + switch (game->_currentCard._single._value) + { + case (MAUMAU_VALUE_7): + playerMust[0] |= MUST_TAKE; + _take += 2; + break; + case (MAUMAU_VALUE_10): + playerMust[0] |= MUST_TAKE; + _take++; + break; + } + if (game->_player[1]._cards == 1) + mau |= 0x02; + else if (!game->_player[1]._cards) + { + printf("\33[31;1mMAU MAU!\33[0m\n\nLeider haben Sie verloren!\n"); + break; + } + continue; + } + else + { + action(game, player 2 takes _take cards); + _take = 0; + ignorePlayer1 = 1; + continue; + } + } + if (playerMust[1] & MUST_WAIT) + playerMust[1] &= ~MUST_WAIT; + else + { + for (i = 0, _card = 0, maybe = 0; i < game->_player[1]._cards; i++) + { + if (game->_player[1]._hand[i]._single._value == MAUMAU_VALUE_JACK) + maybe = i+1; + else if ((game->_player[1]._hand[i]._single._value == game->_currentCard._single._value) || + (game->_player[1]._hand[i]._single._colour == curcol )) + { + _card = i+1; + break; + } + } + + if (!_card && maybe) + _card = maybe; + + if (!_card) + action(game, player 2 takes 1 card); + else + { + putCurrentCardUnderStack(game); + game->_currentCard._value = game->_player[1]._hand[_card-1]._value; + if (_card < game->_player[1]._cards) + memmove(&game->_player[1]._hand[_card-1], &game->_player[1]._hand[_card], sizeof(card_t)*(game->_player[1]._cards-_card)); + game->_player[1]._cards--; + + if (game->_currentCard._single._value != MAUMAU_VALUE_JACK) + { + curcol = game->_currentCard._single._colour; + switch (game->_currentCard._single._value) + { + case (MAUMAU_VALUE_ACE): + playerMust[0] |= MUST_WAIT; + break; + case (MAUMAU_VALUE_7): + playerMust[0] |= MUST_TAKE; + _take += 2; + break; + case (MAUMAU_VALUE_10): + playerMust[0] |= MUST_TAKE; + _take++; + break; + } + } + else if (game->_player[1]._cards) + { + memset(colcount, 0, 4*sizeof(int)); + for (i = 0; i < game->_player[1]._cards; i++) + colcount[(int)game->_player[1]._hand[i]._single._colour]++; + greatest = 0; + for (i = 0, greatest_i = 0; i < 4; i++) + { + if (colcount[i] > greatest) + { + greatest = colcount[i]; + greatest_i = i; + } + } + curcol = greatest_i; + } + } + + if (game->_player[1]._cards == 1) + mau |= 0x02; + else if (!game->_player[1]._cards) + { + printf("\33[31;1mMAU MAU!\33[0m\n\nLeider haben Sie verloren!\n"); + break; + } + } + //ENDE "GEGNER LEGT" + } + + free(game); + return EXIT_SUCCESS; +} -- 1.6.0.2 From kevin at tyndur.org Sun Jul 12 12:09:21 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 12 Jul 2009 12:09:21 +0200 Subject: [tyndur-devel] [PATCH] libc: Segfault in tree_prev/next() bei leerem Baum gefixt Message-ID: <1247393361-26971-1-git-send-email-kevin@tyndur.org> ! libc: Wenn der Baum keine Wurzel hat, muss gleich NULL zurueckgegeben werden, sonst gibt es einen Nullpointerzugriff. Signed-off-by: Kevin Wolf --- src/lib/collections/tree.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/lib/collections/tree.c b/src/lib/collections/tree.c index 87dbcea..d565fa8 100644 --- a/src/lib/collections/tree.c +++ b/src/lib/collections/tree.c @@ -473,6 +473,9 @@ void* tree_prev(tree_t* tree, void* node) if (node == NULL) { current = tree->root; + if (current == NULL) { + return NULL; + } } else { // Irgendwo mitten im Baum ist es einfach, den Vorgaenger zu finden: @@ -517,6 +520,9 @@ void* tree_next(tree_t* tree, void* node) if (node == NULL) { current = tree->root; + if (current == NULL) { + return NULL; + } } else { // Das ist im Prinzip ein tree_prev mit links und rechts vertauscht -- 1.6.0.2 From kevin at tyndur.org Sun Jul 12 20:10:19 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 12 Jul 2009 20:10:19 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: select und EOF Message-ID: <1247422219-6589-1-git-send-email-kevin@tyndur.org> ! libc: POSIX: Fuer select() gilt eine Datei auch dann als lesbar, wenn der Dateizeiger am Ende ist und read nichts mehr zurueckgibt. Signed-off-by: Kevin Wolf --- src/modules/lib/posix/select.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/modules/lib/posix/select.c b/src/modules/lib/posix/select.c index 9ae365c..0508577 100644 --- a/src/modules/lib/posix/select.c +++ b/src/modules/lib/posix/select.c @@ -101,6 +101,12 @@ int select(int number_fds, fd_set* readfds, fd_set* writefds, f = fdopen(i, NULL); if (f != NULL) { + // Eine Datei, die zu Ende ist, gilt als lesbar + if (feof(f)) { + ret++; + continue; + } + c = fgetc(f); if (c == EOF) { *rd &= ~(1 << i); -- 1.6.0.2 From kevin at tyndur.org Sun Jul 12 20:17:27 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 12 Jul 2009 20:17:27 +0200 Subject: [tyndur-devel] [PATCH 0/4] POSIX: Mehr Sockets Message-ID: <1247422651-7199-1-git-send-email-kevin@tyndur.org> Und die naechste POSIX-Runde ist an der Reihe, dieses Mal mit allen Fixes, um wget halbwegs ans Laufen zu bringen. Kevin Wolf (4): libc: POSIX: Server-Sockets libc: POSIX: Prototyp von connect() gefixt libc: POSIX: getsockname() libc: POSIX: h_error src/modules/include/netdb.h | 11 +++ src/modules/include/sys/socket.h | 32 ++++++++- src/modules/lib/posix/net.c | 2 + src/modules/lib/posix/socket.c | 147 +++++++++++++++++++++++++++++++++++++- 4 files changed, 188 insertions(+), 4 deletions(-) From kevin at tyndur.org Sun Jul 12 20:17:29 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 12 Jul 2009 20:17:29 +0200 Subject: [tyndur-devel] [PATCH 2/4] libc: POSIX: Prototyp von connect() gefixt In-Reply-To: <1247422651-7199-1-git-send-email-kevin@tyndur.org> References: <1247422651-7199-1-git-send-email-kevin@tyndur.org> Message-ID: <1247422651-7199-3-git-send-email-kevin@tyndur.org> ! libc: POSIX: Fehlendes const im Prototyp von connect() ergaenzt Signed-off-by: Kevin Wolf --- src/modules/include/sys/socket.h | 2 +- src/modules/lib/posix/socket.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h index 1d19b5a..bc75e0b 100644 --- a/src/modules/include/sys/socket.h +++ b/src/modules/include/sys/socket.h @@ -91,7 +91,7 @@ int socket(int domain, int type, int protocol); * * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. */ -int connect(int socket, struct sockaddr* address, socklen_t address_len); +int connect(int socket, const struct sockaddr* address, socklen_t address_len); /** * Liest eine Anzahl Bytes aus einem Socket diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c index 65194de..fa505b0 100644 --- a/src/modules/lib/posix/socket.c +++ b/src/modules/lib/posix/socket.c @@ -121,7 +121,7 @@ int socket(int domain, int type, int protocol) * * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. */ -int connect(int sock, struct sockaddr* address, socklen_t address_len) +int connect(int sock, const struct sockaddr* address, socklen_t address_len) { struct socket* socket = get_socket(sock); struct sockaddr_in* inet_addr = (struct sockaddr_in*) address; -- 1.6.0.2 From kevin at tyndur.org Sun Jul 12 20:17:30 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 12 Jul 2009 20:17:30 +0200 Subject: [tyndur-devel] [PATCH 3/4] libc: POSIX: getsockname() In-Reply-To: <1247422651-7199-1-git-send-email-kevin@tyndur.org> References: <1247422651-7199-1-git-send-email-kevin@tyndur.org> Message-ID: <1247422651-7199-4-git-send-email-kevin@tyndur.org> + libc: POSIX: getsockname() Signed-off-by: Kevin Wolf --- src/modules/include/sys/socket.h | 5 +++++ src/modules/lib/posix/socket.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-) diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h index bc75e0b..bf5ca98 100644 --- a/src/modules/include/sys/socket.h +++ b/src/modules/include/sys/socket.h @@ -94,6 +94,11 @@ int socket(int domain, int type, int protocol); int connect(int socket, const struct sockaddr* address, socklen_t address_len); /** + * Gibt die lokale Adresse des Sockets zurueck + */ +int getsockname(int sock, struct sockaddr* address, socklen_t* address_len); + +/** * Liest eine Anzahl Bytes aus einem Socket */ ssize_t recv(int socket, const void *buffer, size_t length, int flags); diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c index fa505b0..2e7ab77 100644 --- a/src/modules/lib/posix/socket.c +++ b/src/modules/lib/posix/socket.c @@ -44,6 +44,7 @@ struct socket { sa_family_t sa_family; struct lostio_internal_file conn; + size_t local_address_len; struct sockaddr* local_address; FILE* listen_file; }; @@ -191,6 +192,7 @@ int bind(int sock, const struct sockaddr* address, socklen_t address_len) // FIXME Das wird beim Schliessen geleakt socket->local_address = malloc(address_len); + socket->local_address_len = address_len; memcpy(socket->local_address, address, address_len); return 0; @@ -281,6 +283,33 @@ int accept(int sock, struct sockaddr* address, socklen_t* address_len) } /** + * Gibt die lokale Adresse des Sockets zurueck + */ +int getsockname(int sock, struct sockaddr* address, socklen_t* address_len) +{ + struct socket* socket = get_socket(sock); + size_t len; + + if (socket == NULL) { + errno = EBADF; + return -1; + } + + if (socket->local_address == NULL) { + errno = EINVAL; + return -1; + } + + len = *address_len < socket->local_address_len + ? *address_len : socket->local_address_len; + memcpy(address, socket->local_address, len); + + *address_len = len; + + return 0; +} + +/** * Liest eine Anzahl Bytes aus einem Socket * * TODO Mit den Flags was sinnvolles machen -- 1.6.0.2 From kevin at tyndur.org Sun Jul 12 20:17:31 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 12 Jul 2009 20:17:31 +0200 Subject: [tyndur-devel] [PATCH 4/4] libc: POSIX: h_error In-Reply-To: <1247422651-7199-1-git-send-email-kevin@tyndur.org> References: <1247422651-7199-1-git-send-email-kevin@tyndur.org> Message-ID: <1247422651-7199-5-git-send-email-kevin@tyndur.org> + libc: POSIX: h_error und zugehoerige Statuscodes definieren Signed-off-by: Kevin Wolf --- src/modules/include/netdb.h | 11 +++++++++++ src/modules/lib/posix/net.c | 2 ++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/src/modules/include/netdb.h b/src/modules/include/netdb.h index 5fb2747..88cd98c 100644 --- a/src/modules/include/netdb.h +++ b/src/modules/include/netdb.h @@ -75,5 +75,16 @@ struct servent* getservbyname(const char* name, const char* protocol); */ struct protoent* getprotobyname(const char* name); +/** Fehlerstatus fuer gethostbyaddr() und gethostbyname() */ +extern int h_errno; + +/** Werte fuer h_error */ +enum { + HOST_NOT_FOUND, + NO_DATA, + NO_RECOVERY, + TRY_AGAIN, +}; + #endif diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index 4832d29..44b45b5 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -34,6 +34,8 @@ #include #include +int h_errno; + unsigned long int htonl(unsigned long int hostlong) { return big_endian_dword(hostlong); -- 1.6.0.2 From kevin at tyndur.org Sun Jul 12 20:17:28 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 12 Jul 2009 20:17:28 +0200 Subject: [tyndur-devel] [PATCH 1/4] libc: POSIX: Server-Sockets In-Reply-To: <1247422651-7199-1-git-send-email-kevin@tyndur.org> References: <1247422651-7199-1-git-send-email-kevin@tyndur.org> Message-ID: <1247422651-7199-2-git-send-email-kevin@tyndur.org> + libc: POSIX: TCP-Server-Sockets Signed-off-by: Kevin Wolf --- src/modules/include/sys/socket.h | 25 ++++++++ src/modules/lib/posix/socket.c | 116 +++++++++++++++++++++++++++++++++++++- 2 files changed, 139 insertions(+), 2 deletions(-) diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h index b58c58c..1d19b5a 100644 --- a/src/modules/include/sys/socket.h +++ b/src/modules/include/sys/socket.h @@ -119,4 +119,29 @@ ssize_t recvfrom(int socket, const void *buffer, size_t length, int flags, ssize_t sendto(int socket, const void *buffer, size_t length, int flags, const struct sockaddr* to, socklen_t to_len); +/** + * Bindet einen Socket an einen bestimmten TCP-Port (bzw. allgemein an eine + * Adresse) + * + * @param sock Socket, dem die Adresse zugewiesen werden soll + * @param address Adresse fuer den Socket (Fuer IP: struct sockaddr_in) + * @param address_len Groesse der Adressstruktur + * + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. + */ +int bind(int sock, const struct sockaddr* address, socklen_t address_len); + +/** + * Benutzt einen Socket, um auf eingehende Verbindungen zu warten + * + * @param sock Socket, der auf Verbindungen warten soll + * @param backlog Wird unter tyndur ignoriert + */ +int listen(int sock, int backlog); + +/** + * Nimmt eine eingehende Verbindung an + */ +int accept(int sock, struct sockaddr* address, socklen_t* address_len); + #endif diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c index 9a4d0e4..65194de 100644 --- a/src/modules/lib/posix/socket.c +++ b/src/modules/lib/posix/socket.c @@ -42,8 +42,10 @@ struct socket { uint64_t id; struct tree_item tinfo; - sa_family_t sa_family; - struct lostio_internal_file conn; + sa_family_t sa_family; + struct lostio_internal_file conn; + struct sockaddr* local_address; + FILE* listen_file; }; static tree_t* sockets = NULL; @@ -169,6 +171,116 @@ out_ip_string: } /** + * Bindet einen Socket an einen bestimmten TCP-Port (bzw. allgemein an eine + * Adresse) + * + * @param sock Socket, dem die Adresse zugewiesen werden soll + * @param address Adresse fuer den Socket (Fuer IP: struct sockaddr_in) + * @param address_len Groesse der Adressstruktur + * + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. + */ +int bind(int sock, const struct sockaddr* address, socklen_t address_len) +{ + struct socket* socket = get_socket(sock); + + if (socket == NULL) { + errno = EBADF; + return -1; + } + + // FIXME Das wird beim Schliessen geleakt + socket->local_address = malloc(address_len); + memcpy(socket->local_address, address, address_len); + + return 0; +} + +/** + * Benutzt einen Socket, um auf eingehende Verbindungen zu warten + * + * @param sock Socket, der auf Verbindungen warten soll + * @param backlog Wird unter tyndur ignoriert + */ +int listen(int sock, int backlog) +{ + char* path; + uint16_t port; + struct socket* socket = get_socket(sock); + struct sockaddr_in* inet_addr; + + if (socket == NULL) { + errno = EBADF; + return -1; + } + + inet_addr = (struct sockaddr_in*) socket->local_address; + port = big_endian_word(inet_addr->sin_port); + if (asprintf(&path, "tcpip:/tcp-listen/:%d", port) < 1) { + errno = ENOMEM; + return -1; + } + + socket->listen_file = fopen(path, "r"); + free(path); + if (socket->listen_file == NULL) { + errno = EACCES; + return -1; + } + + return 0; +} + +/** + * Nimmt eine eingehende Verbindung an + */ +int accept(int sock, struct sockaddr* address, socklen_t* address_len) +{ + char buf[64]; + int clientsock; + struct socket* clientsocket; + struct lostio_internal_file* conn; + + struct socket* socket = get_socket(sock); + + if (socket == NULL) { + errno = EBADF; + return -1; + } + + if (socket->listen_file == NULL) { + errno = EINVAL; + return -1; + } + + if (fgets(buf, sizeof(buf), socket->listen_file) == NULL) { + errno = EAGAIN; + return -1; + } + + clientsocket = calloc(1, sizeof(*clientsocket)); + clientsocket->sa_family = AF_INET; + clientsock = create_socket(socket); + + conn = (struct lostio_internal_file*) fopen(buf, "r+"); + if (conn == NULL) { + free(socket); + errno = EAGAIN; + return -1; + } + setvbuf((FILE*)conn, NULL, _IONBF, 0); + + // FIXME Boeser Hack + memcpy(&socket->conn, conn, sizeof(*conn)); + free(conn); + + // TODO Adresse aus buf rausfummeln + *address_len = 0; + + return clientsock; +} + +/** * Liest eine Anzahl Bytes aus einem Socket * * TODO Mit den Flags was sinnvolles machen -- 1.6.0.2 From toni at tyndur.org Thu Jul 16 21:01:01 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 16 Jul 2009 21:01:01 +0200 Subject: [tyndur-devel] [PATCH] libc: Segfault in tree_prev/next() bei leerem Baum gefixt In-Reply-To: <1247393361-26971-1-git-send-email-kevin@tyndur.org> References: <1247393361-26971-1-git-send-email-kevin@tyndur.org> Message-ID: <20090716190101.GA31068@einstein.produktiv.lan> On Sun, Jul 12 12:09, Kevin Wolf wrote: > ! libc: Wenn der Baum keine Wurzel hat, muss gleich NULL zurueckgegeben > werden, sonst gibt es einen Nullpointerzugriff. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Jul 16 21:06:41 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 16 Jul 2009 21:06:41 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: select und EOF In-Reply-To: <1247422219-6589-1-git-send-email-kevin@tyndur.org> References: <1247422219-6589-1-git-send-email-kevin@tyndur.org> Message-ID: <20090716190641.GB31068@einstein.produktiv.lan> On Sun, Jul 12 20:10, Kevin Wolf wrote: > ! libc: POSIX: Fuer select() gilt eine Datei auch dann als lesbar, wenn > der Dateizeiger am Ende ist und read nichts mehr zurueckgibt. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Jul 16 21:16:31 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 16 Jul 2009 21:16:31 +0200 Subject: [tyndur-devel] [PATCH 2/4] libc: POSIX: Prototyp von connect() gefixt In-Reply-To: <1247422651-7199-3-git-send-email-kevin@tyndur.org> References: <1247422651-7199-1-git-send-email-kevin@tyndur.org> <1247422651-7199-3-git-send-email-kevin@tyndur.org> Message-ID: <20090716191631.GC31068@einstein.produktiv.lan> On Sun, Jul 12 20:17, Kevin Wolf wrote: > ! libc: POSIX: Fehlendes const im Prototyp von connect() ergaenzt > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Jul 16 21:33:31 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 16 Jul 2009 21:33:31 +0200 Subject: [tyndur-devel] [PATCH 4/4] libc: POSIX: h_error In-Reply-To: <1247422651-7199-5-git-send-email-kevin@tyndur.org> References: <1247422651-7199-1-git-send-email-kevin@tyndur.org> <1247422651-7199-5-git-send-email-kevin@tyndur.org> Message-ID: <20090716193331.GD31068@einstein.produktiv.lan> On Sun, Jul 12 20:17, Kevin Wolf wrote: > + libc: POSIX: h_error und zugehoerige Statuscodes definieren > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Jul 16 21:50:55 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 16 Jul 2009 21:50:55 +0200 Subject: [tyndur-devel] [PATCH 3/4] libc: POSIX: getsockname() In-Reply-To: <1247422651-7199-4-git-send-email-kevin@tyndur.org> References: <1247422651-7199-1-git-send-email-kevin@tyndur.org> <1247422651-7199-4-git-send-email-kevin@tyndur.org> Message-ID: <20090716195055.GE31068@einstein.produktiv.lan> On Sun, Jul 12 20:17, Kevin Wolf wrote: > + libc: POSIX: getsockname() > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Jul 16 22:04:33 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 16 Jul 2009 22:04:33 +0200 Subject: [tyndur-devel] [PATCH 1/4] libc: POSIX: Server-Sockets In-Reply-To: <1247422651-7199-2-git-send-email-kevin@tyndur.org> References: <1247422651-7199-1-git-send-email-kevin@tyndur.org> <1247422651-7199-2-git-send-email-kevin@tyndur.org> Message-ID: <20090716200433.GF31068@einstein.produktiv.lan> On Sun, Jul 12 20:17, Kevin Wolf wrote: > + libc: POSIX: TCP-Server-Sockets > > Signed-off-by: Kevin Wolf > --- > src/modules/include/sys/socket.h | 25 ++++++++ > src/modules/lib/posix/socket.c | 116 +++++++++++++++++++++++++++++++++++++- > 2 files changed, 139 insertions(+), 2 deletions(-) > > diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h > index b58c58c..1d19b5a 100644 > --- a/src/modules/include/sys/socket.h > +++ b/src/modules/include/sys/socket.h > @@ -119,4 +119,29 @@ ssize_t recvfrom(int socket, const void *buffer, size_t length, int flags, > ssize_t sendto(int socket, const void *buffer, size_t length, int flags, > const struct sockaddr* to, socklen_t to_len); > > +/** > + * Bindet einen Socket an einen bestimmten TCP-Port (bzw. allgemein an eine > + * Adresse) > + * > + * @param sock Socket, dem die Adresse zugewiesen werden soll > + * @param address Adresse fuer den Socket (Fuer IP: struct sockaddr_in) > + * @param address_len Groesse der Adressstruktur > + * > + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. > + */ > +int bind(int sock, const struct sockaddr* address, socklen_t address_len); > + > +/** > + * Benutzt einen Socket, um auf eingehende Verbindungen zu warten > + * > + * @param sock Socket, der auf Verbindungen warten soll > + * @param backlog Wird unter tyndur ignoriert > + */ > +int listen(int sock, int backlog); Hier wäre ein Kommentar zum Rückgabewert ganz nett. > + > +/** > + * Nimmt eine eingehende Verbindung an > + */ > +int accept(int sock, struct sockaddr* address, socklen_t* address_len); Dito > + > #endif > diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c > index 9a4d0e4..65194de 100644 > --- a/src/modules/lib/posix/socket.c > +++ b/src/modules/lib/posix/socket.c > @@ -42,8 +42,10 @@ struct socket { > uint64_t id; > struct tree_item tinfo; > > - sa_family_t sa_family; > - struct lostio_internal_file conn; > + sa_family_t sa_family; > + struct lostio_internal_file conn; > + struct sockaddr* local_address; Hm ist da noch ein trailing space, oder habe ich den aus versehen reingemacht? ;-) > + FILE* listen_file; > }; > > static tree_t* sockets = NULL; > @@ -169,6 +171,116 @@ out_ip_string: > } > > /** > + * Bindet einen Socket an einen bestimmten TCP-Port (bzw. allgemein an eine > + * Adresse) > + * > + * @param sock Socket, dem die Adresse zugewiesen werden soll > + * @param address Adresse fuer den Socket (Fuer IP: struct sockaddr_in) > + * @param address_len Groesse der Adressstruktur > + * > + * @return 0 bei Erfolg. Im Fehlerfall -1 und errno wird gesetzt. > + */ > +int bind(int sock, const struct sockaddr* address, socklen_t address_len) > +{ > + struct socket* socket = get_socket(sock); > + > + if (socket == NULL) { > + errno = EBADF; > + return -1; > + } > + > + // FIXME Das wird beim Schliessen geleakt > + socket->local_address = malloc(address_len); > + memcpy(socket->local_address, address, address_len); > + > + return 0; > +} > + > +/** > + * Benutzt einen Socket, um auf eingehende Verbindungen zu warten > + * > + * @param sock Socket, der auf Verbindungen warten soll > + * @param backlog Wird unter tyndur ignoriert > + */ > +int listen(int sock, int backlog) > +{ > + char* path; > + uint16_t port; > + struct socket* socket = get_socket(sock); > + struct sockaddr_in* inet_addr; > + > + if (socket == NULL) { > + errno = EBADF; > + return -1; > + } Hier müsste man doch prüfen, ob es wirklich tcpip ist in der sockaddr, oder wenigstens address_len prüfen (Das ja hier noch garnicht existiert, wie ich grad feststelle, bäh, alles d00f *g*). > + > + inet_addr = (struct sockaddr_in*) socket->local_address; > + port = big_endian_word(inet_addr->sin_port); > + if (asprintf(&path, "tcpip:/tcp-listen/:%d", port) < 1) { > + errno = ENOMEM; > + return -1; > + } > + > + socket->listen_file = fopen(path, "r"); Wäre da ein w+ nicht einleuchtender? r sollte doch keine Datei erstellen... > + free(path); > + if (socket->listen_file == NULL) { > + errno = EACCES; > + return -1; > + } > + > + return 0; > +} > + > +/** > + * Nimmt eine eingehende Verbindung an > + */ > +int accept(int sock, struct sockaddr* address, socklen_t* address_len) > +{ > + char buf[64]; > + int clientsock; > + struct socket* clientsocket; > + struct lostio_internal_file* conn; > + > + struct socket* socket = get_socket(sock); > + > + if (socket == NULL) { > + errno = EBADF; > + return -1; > + } > + > + if (socket->listen_file == NULL) { > + errno = EINVAL; > + return -1; > + } > + > + if (fgets(buf, sizeof(buf), socket->listen_file) == NULL) { > + errno = EAGAIN; > + return -1; > + } > + > + clientsocket = calloc(1, sizeof(*clientsocket)); > + clientsocket->sa_family = AF_INET; > + clientsock = create_socket(socket); > + > + conn = (struct lostio_internal_file*) fopen(buf, "r+"); > + if (conn == NULL) { > + free(socket); > + errno = EAGAIN; > + return -1; > + } > + setvbuf((FILE*)conn, NULL, _IONBF, 0); > + > + // FIXME Boeser Hack > + memcpy(&socket->conn, conn, sizeof(*conn)); > + free(conn); > + > + // TODO Adresse aus buf rausfummeln > + *address_len = 0; > + > + return clientsock; > +} > + > +/** > * Liest eine Anzahl Bytes aus einem Socket > * > * TODO Mit den Flags was sinnvolles machen -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sat Jul 18 22:07:49 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 18 Jul 2009 22:07:49 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: Etwas vernuenftigeres stat Message-ID: <1247947669-9266-1-git-send-email-kevin@tyndur.org> ! libc: POSIX: Manche Programme pruefen auf Dateirechte und laufen mit 777 besser. Die Konstanten sollten auch nicht alle gleich sein. Signed-off-by: Kevin Wolf --- src/modules/include/sys/stat.h | 42 ++++++++++++++++++++-------------------- src/modules/lib/posix/stat.c | 2 + 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/modules/include/sys/stat.h b/src/modules/include/sys/stat.h index 25290f7..5e7cfcb 100644 --- a/src/modules/include/sys/stat.h +++ b/src/modules/include/sys/stat.h @@ -33,47 +33,47 @@ // Modus Format: 3 Bits fuer Dateityp /// Zurgriffsberechtigungen -#define S_IRUSR 0 -#define S_IWUSR 0 -#define S_IXUSR 0 -#define S_IRGRP 0 -#define S_IWGRP 0 -#define S_IXGRP 0 -#define S_IROTH 0 -#define S_IWOTH 0 -#define S_IXOTH 0 -#define S_IRWXU 0 -#define S_IRWXG 0 -#define S_IRWXO 0 - -/* Sowas haben wir momentan eh nicht */ +#define S_IRUSR 0400 +#define S_IWUSR 0200 +#define S_IXUSR 0100 +#define S_IRGRP 0040 +#define S_IWGRP 0020 +#define S_IXGRP 0010 +#define S_IROTH 0004 +#define S_IWOTH 0002 +#define S_IXOTH 0001 +#define S_IRWXU 0700 +#define S_IRWXG 0070 +#define S_IRWXO 0007 + +/* FIXME Sowas haben wir momentan eh nicht */ #define S_ISUID (1 << 5) #define S_ISGID (1 << 5) #define S_ISVTX (1 << 5) /// Modus: Maske fuer Dateityp -#define S_IFMT 0x7 +#define S_IFMT (0x7 << 12) /// Modus: Blockdatei -#define S_IFBLK 0x0 +#define S_IFBLK (0x0 << 12) /// Modus: Character Datei -#define S_IFCHR 0x1 +#define S_IFCHR (0x1 << 12) /// Modus: Regulaere Datei -#define S_IFREG 0x2 +#define S_IFREG (0x2 << 12) /// Modus: FIFO -#define S_IFIFO 0x3 +#define S_IFIFO (0x3 << 12) /// Modus: Verzeichnis -#define S_IFDIR 0x4 +#define S_IFDIR (0x4 << 12) /// Modus: Symlink -#define S_IFLNK 0x5 +#define S_IFLNK (0x5 << 12) /// Modus: Socket -#define S_IFSOCK 0x6 +#define S_IFSOCK (0x6 << 12) /// Ueberprueft ob es sich bei einem st_mode-Feld um eine Regulaere Datei diff --git a/src/modules/lib/posix/stat.c b/src/modules/lib/posix/stat.c index 56f6104..9033c76 100644 --- a/src/modules/lib/posix/stat.c +++ b/src/modules/lib/posix/stat.c @@ -84,6 +84,7 @@ static int lost_stat(FILE* f, struct stat* stat_buf) // Zuerst die ganze Struktur auf 0 Setzen memset(stat_buf, 0, sizeof(struct stat)); + stat_buf->st_mode = 0777; stat_buf->st_mode |= S_IFREG; pos = ftell(f); @@ -133,6 +134,7 @@ int stat(const char* filename, struct stat* stat_buf) // Zuerst die ganze Struktur auf 0 Setzen memset(stat_buf, 0, sizeof(struct stat)); + stat_buf->st_mode = 0777; stat_buf->st_mode |= S_IFDIR; stat_buf->st_uid = 0; stat_buf->st_gid = 0; -- 1.6.0.2 From kevin at tyndur.org Sat Jul 18 23:11:53 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 18 Jul 2009 23:11:53 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: Prototypen von recvfrom/sendto gefixt Message-ID: <1247951513-10199-1-git-send-email-kevin@tyndur.org> ! libc: POSIX: Prototypen von recvfrom/sendto gefixt Signed-off-by: Kevin Wolf --- src/modules/include/sys/socket.h | 2 +- src/modules/lib/posix/socket.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/include/sys/socket.h b/src/modules/include/sys/socket.h index bf3e6aa..a8446f6 100644 --- a/src/modules/include/sys/socket.h +++ b/src/modules/include/sys/socket.h @@ -114,7 +114,7 @@ ssize_t send(int socket, const void *buffer, size_t length, int flags); * Fuer TCP werden die zusaetzlichen Parameter ignoriert */ ssize_t recvfrom(int socket, const void *buffer, size_t length, int flags, - const struct sockaddr* from, socklen_t from_len); + const struct sockaddr* from, socklen_t* from_len); /** * Sendet eine Anzahl Bytes ueber einen Socket diff --git a/src/modules/lib/posix/socket.c b/src/modules/lib/posix/socket.c index ec382c1..f0b97e1 100644 --- a/src/modules/lib/posix/socket.c +++ b/src/modules/lib/posix/socket.c @@ -352,7 +352,7 @@ ssize_t send(int socket, const void *buffer, size_t length, int flags) * Fuer TCP werden die zusaetzlichen Parameter ignoriert */ ssize_t recvfrom(int socket, const void *buffer, size_t length, int flags, - const struct sockaddr* from, socklen_t from_len) + const struct sockaddr* from, socklen_t* from_len) { return recv(socket, buffer, length, flags); } @@ -363,7 +363,7 @@ ssize_t recvfrom(int socket, const void *buffer, size_t length, int flags, * Fuer TCP werden die zusaetzlichen Parameter ignoriert */ ssize_t sendto(int socket, const void *buffer, size_t length, int flags, - const struct sockaddr* to, socklen_t from_len) + const struct sockaddr* to, socklen_t to_len) { return send(socket, buffer, length, flags); } -- 1.6.0.2 From kevin at tyndur.org Sun Jul 19 00:28:38 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 19 Jul 2009 00:28:38 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Generalueberholung fuer kprintf Message-ID: <1247956118-21026-1-git-send-email-kevin@tyndur.org> ! kernel2: kprintf hat 64-Bit-Zahlen kaputtgemacht + kernel2: Ausgabe von long ints * kernel2: Klarere Trennung von signed/unsigned in kprintf Signed-off-by: Kevin Wolf --- src/kernel2/src/kprintf.c | 50 ++++++++++++++++++++++++++++++++++---------- 1 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/kernel2/src/kprintf.c b/src/kernel2/src/kprintf.c index d9d4594..29d8e5a 100644 --- a/src/kernel2/src/kprintf.c +++ b/src/kernel2/src/kprintf.c @@ -109,7 +109,7 @@ void kaprintf(char* format, va_list args) { int pad; char padfill; - signed long long value = 0; + unsigned long long value = 0; while(*format) { @@ -133,28 +133,54 @@ void kaprintf(char* format, va_list args) pad = pad * 10 + *format++ - '0'; } - if(format[0] == 'l' && format[1] == 'l' && (format[2] == 'd' || format[2] == 'i' || format[2] == 'o' || format[2] == 'u' || format[2] == 'x')) + if(format[0] == 'l' && format[1] == 'l' && (format[2] == 'd' || format[2] == 'i')) { - //value = *(unsigned long long*)(*args); - //*args += 2; - value = va_arg(args, unsigned int); - + signed long long tmp = va_arg(args, long long int); + if (tmp < 0) { + con_putc_ansi('-'); + pad--; + value = -tmp; + } else { + value = tmp; + } format += 2; } + else if(format[0] == 'l' && format[1] == 'l' && (format[2] == 'o' || format[2] == 'u' || format[2] == 'x')) + { + value = va_arg(args, unsigned long long int); + format += 2; + } + else if(format[0] == 'l' && (format[1] == 'd' || format[1] == 'i')) + { + signed long int tmp = va_arg(args, long int); + if(tmp < 0) { + con_putc_ansi('-'); + pad--; + value = -tmp; + } else { + value = tmp; + } + format++; + } + else if(format[0] == 'l' && (format[1] == 'o' || format[1] == 'u' || format[1] == 'x')) + { + value = va_arg(args, unsigned long int); + format++; + } else if(format[0] == 'd' || format[0] == 'i') { - value = va_arg(args, unsigned int);//*(*args)++; - if(value < 0) - { + int tmp = va_arg(args, int); + if(tmp < 0) { con_putc_ansi('-'); pad--; - value = -value; + value = -tmp; + } else { + value = tmp; } } else if(format[0] == 'u' || format[0] == 'o' || format[0] == 'p' || format[0] == 'x') { - value = va_arg(args, unsigned int);//*(*args)++; - //value = value & 0xffffffff; + value = va_arg(args, unsigned int); } switch(*format) -- 1.6.0.2 From kevin at tyndur.org Sun Jul 19 14:25:01 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 19 Jul 2009 14:25:01 +0200 Subject: [tyndur-devel] [PATCH] libc: Doubles in printf Message-ID: <1248006301-20798-1-git-send-email-kevin@tyndur.org> + libc: printf: Unterstuetzung fuer Ausgabe von (long) doubles Signed-off-by: Kevin Wolf --- src/modules/lib/stdlibc/jprintf.c | 62 +++++++++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-) diff --git a/src/modules/lib/stdlibc/jprintf.c b/src/modules/lib/stdlibc/jprintf.c index 067d1bd..0219c73 100644 --- a/src/modules/lib/stdlibc/jprintf.c +++ b/src/modules/lib/stdlibc/jprintf.c @@ -111,6 +111,43 @@ char * ulltoa(unsigned long long value, char * buf, unsigned int radix, unsigned return buf; } + +/** + * Konvertiert eine Gleitkommazahl in einen String + * + * @param value Die Zahl + * @param buf Der Puffer + * @param precision Anzahl der Nachkommastellen + * + * @return buf + */ +static void ldtoa(long double value, char* buf, unsigned int precision) +{ + // Negative Zahlen gleich rausfiltern + if (value < 0) { + *buf++ = '-'; + value = -value; + } + + // Integeranteil ausgeben + ulltoa((unsigned long long) value, buf, 10, 0); + value -= (unsigned long long) value; + buf += strlen(buf); + + // Nachkommastellen + if (value && precision) { + *buf++ = '.'; + } + + while (value && precision--) { + value *= 10.0; + *buf++ = '0' + (int) value; + value -= (int) value; + } + + *buf = '\0'; +} + /** * Ruft die dem Kontext entsprechende putc Funktion auf. @@ -212,6 +249,7 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) unsigned int width; unsigned int precision; unsigned int length; + unsigned int long_double; bytes_written = 0; @@ -244,6 +282,7 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) width = 0; precision = -1; length = 32; + long_double = 0; // flags switch(*format) @@ -312,6 +351,7 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) break; case 'L': // long double + long_double = 1; format++; break; } @@ -458,6 +498,28 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) } format++; break; + case 'f': + case 'g': + // FIXME Bei g duerfen keine abschliessenden Nullen vorkommen + { + char buf[67]; + long double value; + + if (precision == -1) { + precision = 6; + } + + if (long_double) { + value = va_arg(ap, long double); + } else { + value = va_arg(ap, double); + } + + ldtoa(value, buf, precision); + WRITE_STRING(buf, -1); + } + format++; + break; case 'c': { char c = (char)va_arg(ap, int); -- 1.6.0.2 From toni at tyndur.org Sun Jul 19 22:02:23 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 19 Jul 2009 22:02:23 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: Etwas vernuenftigeres stat In-Reply-To: <1247947669-9266-1-git-send-email-kevin@tyndur.org> References: <1247947669-9266-1-git-send-email-kevin@tyndur.org> Message-ID: <20090719200222.GA13484@einstein.kaufmann.lan> On Sat, Jul 18 22:07, Kevin Wolf wrote: > ! libc: POSIX: Manche Programme pruefen auf Dateirechte und laufen mit > 777 besser. Die Konstanten sollten auch nicht alle gleich sein. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Jul 25 10:32:00 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Jul 2009 10:32:00 +0200 Subject: [tyndur-devel] [PATCH] libc: POSIX: Prototypen von recvfrom/sendto gefixt In-Reply-To: <1247951513-10199-1-git-send-email-kevin@tyndur.org> References: <1247951513-10199-1-git-send-email-kevin@tyndur.org> Message-ID: <20090725083200.GA22931@einstein.kaufmann.lan> On Sat, Jul 18 23:11, Kevin Wolf wrote: > ! libc: POSIX: Prototypen von recvfrom/sendto gefixt > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Jul 25 10:40:14 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Jul 2009 10:40:14 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Generalueberholung fuer kprintf In-Reply-To: <1247956118-21026-1-git-send-email-kevin@tyndur.org> References: <1247956118-21026-1-git-send-email-kevin@tyndur.org> Message-ID: <20090725084014.GB22931@einstein.kaufmann.lan> On Sun, Jul 19 00:28, Kevin Wolf wrote: > ! kernel2: kprintf hat 64-Bit-Zahlen kaputtgemacht > + kernel2: Ausgabe von long ints > * kernel2: Klarere Trennung von signed/unsigned in kprintf > > Signed-off-by: Kevin Wolf Ich glaube das könnte so funktionieren... ;-) Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Jul 25 12:15:54 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 25 Jul 2009 12:15:54 +0200 Subject: [tyndur-devel] [PATCH] libc: Doubles in printf In-Reply-To: <1248006301-20798-1-git-send-email-kevin@tyndur.org> References: <1248006301-20798-1-git-send-email-kevin@tyndur.org> Message-ID: <20090725101554.GA23338@einstein.kaufmann.lan> On Sun, Jul 19 14:25, Kevin Wolf wrote: > + libc: printf: Unterstuetzung fuer Ausgabe von (long) doubles > > Signed-off-by: Kevin Wolf > --- > src/modules/lib/stdlibc/jprintf.c | 62 +++++++++++++++++++++++++++++++++++++ > 1 files changed, 62 insertions(+), 0 deletions(-) > > diff --git a/src/modules/lib/stdlibc/jprintf.c b/src/modules/lib/stdlibc/jprintf.c > index 067d1bd..0219c73 100644 > --- a/src/modules/lib/stdlibc/jprintf.c > +++ b/src/modules/lib/stdlibc/jprintf.c > @@ -111,6 +111,43 @@ char * ulltoa(unsigned long long value, char * buf, unsigned int radix, unsigned > > return buf; > } > + > +/** > + * Konvertiert eine Gleitkommazahl in einen String > + * > + * @param value Die Zahl > + * @param buf Der Puffer > + * @param precision Anzahl der Nachkommastellen > + * > + * @return buf > + */ > +static void ldtoa(long double value, char* buf, unsigned int precision) > +{ > + // Negative Zahlen gleich rausfiltern > + if (value < 0) { > + *buf++ = '-'; > + value = -value; > + } > + > + // Integeranteil ausgeben > + ulltoa((unsigned long long) value, buf, 10, 0); > + value -= (unsigned long long) value; > + buf += strlen(buf); > + > + // Nachkommastellen > + if (value && precision) { > + *buf++ = '.'; > + } > + > + while (value && precision--) { > + value *= 10.0; > + *buf++ = '0' + (int) value; > + value -= (int) value; > + } > + > + *buf = '\0'; > +} > + > > /** > * Ruft die dem Kontext entsprechende putc Funktion auf. > @@ -212,6 +249,7 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) > unsigned int width; > unsigned int precision; > unsigned int length; > + unsigned int long_double; > > bytes_written = 0; > > @@ -244,6 +282,7 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) > width = 0; > precision = -1; > length = 32; > + long_double = 0; > > // flags > switch(*format) > @@ -312,6 +351,7 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) > break; > case 'L': > // long double > + long_double = 1; > format++; > break; > } > @@ -458,6 +498,28 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) > } > format++; > break; > + case 'f': > + case 'g': > + // FIXME Bei g duerfen keine abschliessenden Nullen vorkommen > + { > + char buf[67]; Wie kommst du denn hier auf diese 67, und sollte ldtoa die nicht auch kennen, um einen Pufferüberlauf zu verhindern? > + long double value; > + > + if (precision == -1) { > + precision = 6; > + } > + > + if (long_double) { > + value = va_arg(ap, long double); > + } else { > + value = va_arg(ap, double); > + } > + > + ldtoa(value, buf, precision); > + WRITE_STRING(buf, -1); > + } > + format++; > + break; > case 'c': > { > char c = (char)va_arg(ap, int); -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Thu Jul 30 09:46:57 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 30 Jul 2009 09:46:57 +0200 Subject: [tyndur-devel] [PATCH] GRUB-Konfiguration fuer kernel2 aktualisiert Message-ID: <1248940017-11221-1-git-send-email-kevin@tyndur.org> ! servmgr bekommt mittlerweile einen Parameter mehr. Bei dieser Gelegenheit gleich die komplette kernel1-Konfiguration uebernommen. Signed-off-by: Kevin Wolf --- build/config/grub_hd_kernel2.cfg | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build/config/grub_hd_kernel2.cfg b/build/config/grub_hd_kernel2.cfg index 9b296d6..38d2b4b 100644 --- a/build/config/grub_hd_kernel2.cfg +++ b/build/config/grub_hd_kernel2.cfg @@ -1,8 +1,9 @@ title tyndur2 kernel /boot/tyndur2 debug=s module /modules/init boot=file:/ +module /modules/pci module /modules/ata module /modules/ext2 -module /modules/servmgr ata:/ata00_p0|ext2:/ ata ext2 +module /modules/console servmgr:/term servmgr:/term +module /modules/servmgr ata:/ata00_p0|ext2:/ vterm:/vterm8/out ata ext2 console boot - -- 1.6.0.2 From kevin at tyndur.org Thu Jul 30 11:14:50 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 30 Jul 2009 11:14:50 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Rueckgabewerte des RPC-Syscall aktualisiert Message-ID: <1248945290-31082-1-git-send-email-kevin@tyndur.org> ! kernel2: Vor einer Weile wurde kernel1 und der Userspace in Hinsicht auf die Rueckgabewerte des RPC-Syscall geaendert (-errno statt -1). Da hat dazu gefuerhrt, dass unter kernel2 blockierte RPCs nicht wiederholt wurden. Mit -EAGAIN geht das wieder und alles ist gut. Signed-off-by: Kevin Wolf --- src/kernel2/src/syscalls/rpc.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/kernel2/src/syscalls/rpc.c b/src/kernel2/src/syscalls/rpc.c index 688c4ea..da4cbd1 100644 --- a/src/kernel2/src/syscalls/rpc.c +++ b/src/kernel2/src/syscalls/rpc.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "kernel.h" #include "syscall.h" @@ -135,7 +136,7 @@ int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata, if (!process) { // FIXME // abort_task("RPC zu nicht vorhandenem Prozess"); - return -1; + return -ESRCH; } callee = list_get_element_at(process->threads, 0); @@ -146,11 +147,11 @@ int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata, if (metadata_size + data_size > 8 * PAGE_SIZE) { // FIXME // abort_task("RPC-Datenblock zu gross: %d Bytes", data_size); - return -1; + return -EINVAL; } if (callee->process->rpc_handler == NULL) { - return -1; + return -EINVAL; } /* @@ -196,7 +197,7 @@ int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata, ((callee->process->blocked_by_pid) || !pm_block_rpc(callee->process, syscall_pm_get_pid()))) { - return -1; + return -EAGAIN; } // Interrupt Stack Frame des aufgerufenen Tasks mappen -- 1.6.0.2 From toni at tyndur.org Thu Jul 30 21:47:20 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 30 Jul 2009 21:47:20 +0200 Subject: [tyndur-devel] [PATCH] GRUB-Konfiguration fuer kernel2 aktualisiert In-Reply-To: <1248940017-11221-1-git-send-email-kevin@tyndur.org> References: <1248940017-11221-1-git-send-email-kevin@tyndur.org> Message-ID: <20090730194720.GA26634@einstein.kaufmann.lan> On Thu, Jul 30 09:46, Kevin Wolf wrote: > ! servmgr bekommt mittlerweile einen Parameter mehr. Bei dieser > Gelegenheit gleich die komplette kernel1-Konfiguration uebernommen. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Thu Jul 30 21:50:20 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Thu, 30 Jul 2009 21:50:20 +0200 Subject: [tyndur-devel] [PATCH] kernel2: Rueckgabewerte des RPC-Syscall aktualisiert In-Reply-To: <1248945290-31082-1-git-send-email-kevin@tyndur.org> References: <1248945290-31082-1-git-send-email-kevin@tyndur.org> Message-ID: <20090730195019.GB26634@einstein.kaufmann.lan> On Thu, Jul 30 11:14, Kevin Wolf wrote: > ! kernel2: Vor einer Weile wurde kernel1 und der Userspace in Hinsicht > auf die Rueckgabewerte des RPC-Syscall geaendert (-errno statt -1). Da > hat dazu gefuerhrt, dass unter kernel2 blockierte RPCs nicht KRITIKEL ^ > wiederholt wurden. Mit -EAGAIN geht das wieder und alles ist gut. > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Fri Jul 31 10:33:01 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 31 Jul 2009 10:33:01 +0200 Subject: [tyndur-devel] [PATCH v2] libc: Doubles in printf Message-ID: <1249029181-7358-1-git-send-email-kevin@tyndur.org> + libc: printf: Unterstuetzung fuer Ausgabe von (long) doubles Signed-off-by: Kevin Wolf --- src/modules/lib/stdlibc/jprintf.c | 63 +++++++++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-) diff --git a/src/modules/lib/stdlibc/jprintf.c b/src/modules/lib/stdlibc/jprintf.c index 067d1bd..b451227 100644 --- a/src/modules/lib/stdlibc/jprintf.c +++ b/src/modules/lib/stdlibc/jprintf.c @@ -111,6 +111,43 @@ char * ulltoa(unsigned long long value, char * buf, unsigned int radix, unsigned return buf; } + +/** + * Konvertiert eine Gleitkommazahl in einen String + * + * @param value Die Zahl + * @param buf Der Puffer + * @param precision Anzahl der Nachkommastellen + * + * @return buf + */ +static void ldtoa(long double value, char* buf, unsigned int precision) +{ + // Negative Zahlen gleich rausfiltern + if (value < 0) { + *buf++ = '-'; + value = -value; + } + + // Integeranteil ausgeben + ulltoa((unsigned long long) value, buf, 10, 0); + value -= (unsigned long long) value; + buf += strlen(buf); + + // Nachkommastellen + if (value && precision) { + *buf++ = '.'; + } + + while (value && precision--) { + value *= 10.0; + *buf++ = '0' + (int) value; + value -= (int) value; + } + + *buf = '\0'; +} + /** * Ruft die dem Kontext entsprechende putc Funktion auf. @@ -212,6 +249,7 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) unsigned int width; unsigned int precision; unsigned int length; + unsigned int long_double; bytes_written = 0; @@ -244,6 +282,7 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) width = 0; precision = -1; length = 32; + long_double = 0; // flags switch(*format) @@ -312,6 +351,7 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) break; case 'L': // long double + long_double = 1; format++; break; } @@ -458,6 +498,29 @@ int jvprintf(struct jprintf_args * args, const char * format, va_list ap) } format++; break; + case 'f': + case 'g': + // FIXME Bei g duerfen keine abschliessenden Nullen vorkommen + if (precision == -1) { + precision = 6; + } + { + // 64-Bit-Integer gehen dezimal in maximal 21 Zeichen, dazu + // Vorzeichen, Komma und abschliessendes Nulbyte + char buf[precision + 21 + 3]; + long double value; + + if (long_double) { + value = va_arg(ap, long double); + } else { + value = va_arg(ap, double); + } + + ldtoa(value, buf, precision); + WRITE_STRING(buf, -1); + } + format++; + break; case 'c': { char c = (char)va_arg(ap, int); -- 1.6.0.2 From kevin at tyndur.org Fri Jul 31 13:10:47 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 31 Jul 2009 13:10:47 +0200 Subject: [tyndur-devel] [PATCH 3/4] kedit: Automatisch erzeugte Einrueckung bei Leerzeilen loeschen In-Reply-To: <1249038648-326-1-git-send-email-kevin@tyndur.org> References: <1249038648-326-1-git-send-email-kevin@tyndur.org> Message-ID: <1249038648-326-4-git-send-email-kevin@tyndur.org> + kedit: Wenn zweimal direkt Enter gedrueckt wird, wird zuneachst die richtige Einrueckung beibehalten. Beim zweiten Enter wird die Einrueckung der ersten Zeile wieder geloescht, damit eine saubere Leerzeile entsteht. Signed-off-by: Kevin Wolf --- src/modules/pas/kedit/kedit.pas | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas index 420cc9e..3542b07 100644 --- a/src/modules/pas/kedit/kedit.pas +++ b/src/modules/pas/kedit/kedit.pas @@ -85,10 +85,19 @@ end; procedure Edit; + var + autoindent: boolean; + old_autoindent: boolean; + procedure DoInput; var key: UnicodeChar; begin + // old_autoindent ist nur gesetzt, wenn schon der letzte Tastendruck + // ein Enter war. + old_autoindent := autoindent; + autoindent := false; + with state do begin key := ReadUnicodeChar; case key of @@ -149,10 +158,18 @@ procedure Edit; cursX := 1; if length(text^[cursY-1]) > 0 then begin + autoindent := true; while (cursX <= MaxColumns) and (text^[cursY-1, cursX] = ' ') do begin text^[cursY] := ' ' + text^[cursY]; inc(cursX); end; + + if old_autoindent then begin + if text^[cursY-1] = Space(length(text^[cursY-1])) then begin + text^[cursY-1] := ''; + end; + end; + end; changed:=true; @@ -194,6 +211,7 @@ procedure Edit; begin exitEditor := false; redrawEditor := true; + autoindent := false; repeat if redrawEditor then begin DrawEditor(@state); -- 1.6.0.2 From kevin at tyndur.org Fri Jul 31 13:10:44 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 31 Jul 2009 13:10:44 +0200 Subject: [tyndur-devel] [PATCH 0/4] Ein paar kedit-Verbesserungen Message-ID: <1249038648-326-1-git-send-email-kevin@tyndur.org> Diese Serie geht ein paar nervige Kleinigkeiten an, die mir aufgefallen sind, nachdem ich den kedit in letzter Zeit ab und zu für Code verwendet habe. Kevin Wolf (4): kedit: Syntaxhighlighting: const kedit: Syntaxhighlighting: Unsigned-Literale kedit: Automatisch erzeugte Einrueckung bei Leerzeilen loeschen kedit: Erweitertes Pos1/Ende src/modules/pas/kedit/kedit.pas | 18 ++++++++++++++++++ src/modules/pas/kedit/kedit_input.pas | 28 ++++++++++++++++++++++++++-- src/modules/pas/kedit/syntax.pas | 17 +++++++++++++++-- 3 files changed, 59 insertions(+), 4 deletions(-) From kevin at tyndur.org Fri Jul 31 13:10:45 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 31 Jul 2009 13:10:45 +0200 Subject: [tyndur-devel] [PATCH 1/4] kedit: Syntaxhighlighting: const In-Reply-To: <1249038648-326-1-git-send-email-kevin@tyndur.org> References: <1249038648-326-1-git-send-email-kevin@tyndur.org> Message-ID: <1249038648-326-2-git-send-email-kevin@tyndur.org> + kedit: const gehoert auch zu einem Typen dazu Signed-off-by: Kevin Wolf --- src/modules/pas/kedit/syntax.pas | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/pas/kedit/syntax.pas b/src/modules/pas/kedit/syntax.pas index a8043e5..bef4df3 100644 --- a/src/modules/pas/kedit/syntax.pas +++ b/src/modules/pas/kedit/syntax.pas @@ -47,9 +47,9 @@ const 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' ); - Types_C: Array [1..16] of String = ( + Types_C: Array [1..17] of String = ( 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', - 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile' + 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' ); -- 1.6.0.2 From kevin at tyndur.org Fri Jul 31 13:10:46 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 31 Jul 2009 13:10:46 +0200 Subject: [tyndur-devel] [PATCH 2/4] kedit: Syntaxhighlighting: Unsigned-Literale In-Reply-To: <1249038648-326-1-git-send-email-kevin@tyndur.org> References: <1249038648-326-1-git-send-email-kevin@tyndur.org> Message-ID: <1249038648-326-3-git-send-email-kevin@tyndur.org> + kedit: Integerkonstanten duerfen auch ein U fuer unsigned enthalten Signed-off-by: Kevin Wolf --- src/modules/pas/kedit/syntax.pas | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/src/modules/pas/kedit/syntax.pas b/src/modules/pas/kedit/syntax.pas index bef4df3..b382265 100644 --- a/src/modules/pas/kedit/syntax.pas +++ b/src/modules/pas/kedit/syntax.pas @@ -88,6 +88,7 @@ function MatchesNumber(s: String; pos: integer): integer; var i: integer; long: integer; + unsigned: boolean; needfig: boolean; hex: boolean; prefix: boolean; @@ -97,6 +98,7 @@ begin end; long := 0; + unsigned := false; needfig := false; hex := false; prefix := false; @@ -118,6 +120,17 @@ begin MatchesNumber := i - pos; end; exit; + end else if (s[i] in ['u', 'U']) then begin + if unsigned then begin + MatchesNumber := 0; + exit; + end; + unsigned := true; + + if long > 0 then begin + // LUL is nicht erlaubt + long := 2; + end; end else if (s[i] in ['l', 'L']) then begin Inc(long); if long > 2 then begin -- 1.6.0.2 From kevin at tyndur.org Fri Jul 31 13:10:48 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 31 Jul 2009 13:10:48 +0200 Subject: [tyndur-devel] [PATCH 4/4] kedit: Erweitertes Pos1/Ende In-Reply-To: <1249038648-326-1-git-send-email-kevin@tyndur.org> References: <1249038648-326-1-git-send-email-kevin@tyndur.org> Message-ID: <1249038648-326-5-git-send-email-kevin@tyndur.org> + kedit: Pos1 springt erst an den Anfang der Zeile, beim zweiten Tastendruck zum ersten Nicht-Leerzeichen. Ende geht analog. Signed-off-by: Kevin Wolf --- src/modules/pas/kedit/kedit_input.pas | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/modules/pas/kedit/kedit_input.pas b/src/modules/pas/kedit/kedit_input.pas index 030ba95..aaf5683 100644 --- a/src/modules/pas/kedit/kedit_input.pas +++ b/src/modules/pas/kedit/kedit_input.pas @@ -172,13 +172,37 @@ end; procedure uih_cursor_to_start_of_line(state: pkedit_state); begin - state^.cursX := 1; + with state^ do begin + if cursX = 1 then begin + // Wenn der Cursor schon auf der ersten Spalte ist, zum ersten + // Nichtleerzeichen auf der Zeile springen + while (length(text^[cursY]) > cursX) + and (text^[cursY][cursX] = ' ') + do begin + // Ansonsten Cursor in die erste Spalte setzen + Inc(cursX) + end; + end else begin + cursX := 1; + end; + end; end; procedure uih_cursor_to_end_of_line(state: pkedit_state); +var + text_end: integer; begin with state^ do begin - cursX := Length(RTrim(text^[cursY])); + text_end := Length(RTrim(text^[cursY])); + if cursX = text_end + 1 then begin + // Wenn der Cursor schon hinter dem letzten Zeichen des Texts (ohne + // abschliessende Leerzeichen) steht, ganz ans Ende der Zeile + // springen + cursX := Length(text^[cursY]); + end else begin + // Ansonsten Cursor ans Ende des Texts setzen + cursX := text_end; + end; if cursX < 255 then Inc(cursX); end; end; -- 1.6.0.2 From alex at tyndur.org Fri Jul 31 21:38:57 2009 From: alex at tyndur.org (Alexander Siol) Date: Fri, 31 Jul 2009 21:38:57 +0200 Subject: [tyndur-devel] [PATCH 1/4] kedit: Syntaxhighlighting: const In-Reply-To: <1249038648-326-2-git-send-email-kevin@tyndur.org> References: <1249038648-326-1-git-send-email-kevin@tyndur.org> <1249038648-326-2-git-send-email-kevin@tyndur.org> Message-ID: <20090731193826.GA19111@alex> On Fri, Jul 31, 2009 at 01:10:45PM +0200, Kevin Wolf wrote: > + kedit: const gehoert auch zu einem Typen dazu > > Signed-off-by: Kevin Wolf > --- > src/modules/pas/kedit/syntax.pas | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/src/modules/pas/kedit/syntax.pas b/src/modules/pas/kedit/syntax.pas > index a8043e5..bef4df3 100644 > --- a/src/modules/pas/kedit/syntax.pas > +++ b/src/modules/pas/kedit/syntax.pas > @@ -47,9 +47,9 @@ const > 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', > 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' > ); > - Types_C: Array [1..16] of String = ( > + Types_C: Array [1..17] of String = ( > 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', > - 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile' > + 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' > ); > Acked-by: Alexander Siol > > -- > 1.6.0.2 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: Digital signature URL : From alex at tyndur.org Fri Jul 31 21:45:28 2009 From: alex at tyndur.org (Alexander Siol) Date: Fri, 31 Jul 2009 21:45:28 +0200 Subject: [tyndur-devel] [PATCH 3/4] kedit: Automatisch erzeugte Einrueckung bei Leerzeilen loeschen In-Reply-To: <1249038648-326-4-git-send-email-kevin@tyndur.org> References: <1249038648-326-1-git-send-email-kevin@tyndur.org> <1249038648-326-4-git-send-email-kevin@tyndur.org> Message-ID: <20090731194528.GB19111@alex> On Fri, Jul 31, 2009 at 01:10:47PM +0200, Kevin Wolf wrote: > + kedit: Wenn zweimal direkt Enter gedrueckt wird, wird zuneachst die > richtige Einrueckung beibehalten. Beim zweiten Enter wird die > Einrueckung der ersten Zeile wieder geloescht, damit eine saubere > Leerzeile entsteht. > > Signed-off-by: Kevin Wolf > --- > src/modules/pas/kedit/kedit.pas | 18 ++++++++++++++++++ > 1 files changed, 18 insertions(+), 0 deletions(-) > > diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas > index 420cc9e..3542b07 100644 > --- a/src/modules/pas/kedit/kedit.pas > +++ b/src/modules/pas/kedit/kedit.pas > @@ -85,10 +85,19 @@ end; > > procedure Edit; > > + var > + autoindent: boolean; > + old_autoindent: boolean; > + > procedure DoInput; > var > key: UnicodeChar; > begin > + // old_autoindent ist nur gesetzt, wenn schon der letzte Tastendruck > + // ein Enter war. > + old_autoindent := autoindent; > + autoindent := false; > + > with state do begin > key := ReadUnicodeChar; > case key of > @@ -149,10 +158,18 @@ procedure Edit; > cursX := 1; > > if length(text^[cursY-1]) > 0 then begin > + autoindent := true; > while (cursX <= MaxColumns) and (text^[cursY-1, cursX] = ' ') do begin > text^[cursY] := ' ' + text^[cursY]; > inc(cursX); > end; > + > + if old_autoindent then begin > + if text^[cursY-1] = Space(length(text^[cursY-1])) then begin > + text^[cursY-1] := ''; > + end; > + end; > + > end; > > changed:=true; > @@ -194,6 +211,7 @@ procedure Edit; > begin > exitEditor := false; > redrawEditor := true; > + autoindent := false; > repeat > if redrawEditor then begin > DrawEditor(@state); Acked-by: Alexander Siol > -- > 1.6.0.2 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: Digital signature URL : From alex at tyndur.org Fri Jul 31 21:56:14 2009 From: alex at tyndur.org (Alexander Siol) Date: Fri, 31 Jul 2009 21:56:14 +0200 Subject: [tyndur-devel] [PATCH 4/4] kedit: Erweitertes Pos1/Ende In-Reply-To: <1249038648-326-5-git-send-email-kevin@tyndur.org> References: <1249038648-326-1-git-send-email-kevin@tyndur.org> <1249038648-326-5-git-send-email-kevin@tyndur.org> Message-ID: <20090731195614.GC19111@alex> On Fri, Jul 31, 2009 at 01:10:48PM +0200, Kevin Wolf wrote: > + kedit: Pos1 springt erst an den Anfang der Zeile, beim zweiten > Tastendruck zum ersten Nicht-Leerzeichen. Ende geht analog. > > Signed-off-by: Kevin Wolf > --- > src/modules/pas/kedit/kedit_input.pas | 28 ++++++++++++++++++++++++++-- > 1 files changed, 26 insertions(+), 2 deletions(-) > > diff --git a/src/modules/pas/kedit/kedit_input.pas b/src/modules/pas/kedit/kedit_input.pas > index 030ba95..aaf5683 100644 > --- a/src/modules/pas/kedit/kedit_input.pas > +++ b/src/modules/pas/kedit/kedit_input.pas > @@ -172,13 +172,37 @@ end; > > procedure uih_cursor_to_start_of_line(state: pkedit_state); > begin > - state^.cursX := 1; > + with state^ do begin > + if cursX = 1 then begin > + // Wenn der Cursor schon auf der ersten Spalte ist, zum ersten > + // Nichtleerzeichen auf der Zeile springen > + while (length(text^[cursY]) > cursX) > + and (text^[cursY][cursX] = ' ') > + do begin > + // Ansonsten Cursor in die erste Spalte setzen > + Inc(cursX) > + end; > + end else begin > + cursX := 1; > + end; > + end; > end; > > procedure uih_cursor_to_end_of_line(state: pkedit_state); > +var > + text_end: integer; > begin > with state^ do begin > - cursX := Length(RTrim(text^[cursY])); > + text_end := Length(RTrim(text^[cursY])); > + if cursX = text_end + 1 then begin > + // Wenn der Cursor schon hinter dem letzten Zeichen des Texts (ohne > + // abschliessende Leerzeichen) steht, ganz ans Ende der Zeile > + // springen > + cursX := Length(text^[cursY]); > + end else begin > + // Ansonsten Cursor ans Ende des Texts setzen > + cursX := text_end; > + end; > if cursX < 255 then Inc(cursX); > end; > end; Acked-by: Alexander Siol > -- > 1.6.0.2 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: Digital signature URL : From alex at tyndur.org Fri Jul 31 22:04:19 2009 From: alex at tyndur.org (Alexander Siol) Date: Fri, 31 Jul 2009 22:04:19 +0200 Subject: [tyndur-devel] [PATCH 2/4] kedit: Syntaxhighlighting: Unsigned-Literale In-Reply-To: <1249038648-326-3-git-send-email-kevin@tyndur.org> References: <1249038648-326-1-git-send-email-kevin@tyndur.org> <1249038648-326-3-git-send-email-kevin@tyndur.org> Message-ID: <20090731200419.GD19111@alex> On Fri, Jul 31, 2009 at 01:10:46PM +0200, Kevin Wolf wrote: > + kedit: Integerkonstanten duerfen auch ein U fuer unsigned enthalten > > Signed-off-by: Kevin Wolf > --- > src/modules/pas/kedit/syntax.pas | 13 +++++++++++++ > 1 files changed, 13 insertions(+), 0 deletions(-) > > diff --git a/src/modules/pas/kedit/syntax.pas b/src/modules/pas/kedit/syntax.pas > index bef4df3..b382265 100644 > --- a/src/modules/pas/kedit/syntax.pas > +++ b/src/modules/pas/kedit/syntax.pas > @@ -88,6 +88,7 @@ function MatchesNumber(s: String; pos: integer): integer; > var > i: integer; > long: integer; > + unsigned: boolean; > needfig: boolean; > hex: boolean; > prefix: boolean; > @@ -97,6 +98,7 @@ begin > end; > > long := 0; > + unsigned := false; > needfig := false; > hex := false; > prefix := false; > @@ -118,6 +120,17 @@ begin > MatchesNumber := i - pos; > end; > exit; > + end else if (s[i] in ['u', 'U']) then begin > + if unsigned then begin > + MatchesNumber := 0; > + exit; > + end; > + unsigned := true; > + > + if long > 0 then begin > + // LUL is nicht erlaubt > + long := 2; > + end; > end else if (s[i] in ['l', 'L']) then begin > Inc(long); > if long > 2 then begin Acked-by: Alexander Siol > -- > 1.6.0.2 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: Digital signature URL : From mail at kevin-wolf.de Fri Jul 31 22:20:44 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Fri, 31 Jul 2009 22:20:44 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH=5D_Re=3A_+cp=3A_-r=2C_-v_u?= =?iso-8859-1?q?nd_-t_hinzugef=FCgt?= In-Reply-To: <1247059887-29488-1-git-send-email-alex@tyndur.org> References: <1246996911-30080-1-git-send-email-alex@tyndur.org> <1247059887-29488-1-git-send-email-alex@tyndur.org> Message-ID: <200907312220.44415@kevin-wolf.de> Am Mittwoch, 8. Juli 2009 15:31 schrieb Alexander Siol: > --- > trunk/src/modules/c/shell/cmds/cp.c | 181 > ++++++++++++++++++++++++++++++---- 1 files changed, 159 insertions(+), 22 > deletions(-) > > diff --git a/trunk/src/modules/c/shell/cmds/cp.c > b/trunk/src/modules/c/shell/cmds/cp.c index 2c1ada5..30b8f53 100644 > --- a/trunk/src/modules/c/shell/cmds/cp.c > +++ b/trunk/src/modules/c/shell/cmds/cp.c > @@ -41,11 +41,17 @@ > #include "stdlib.h" > #include "stdio.h" > #include "unistd.h" > +#include "getopt.h" > +#include "collections.h" und Die anderen kannst du gleich mitändern, die sind nur aus historischen Gründen so. ;-) > #include > > #define BUFFER_SIZE 4096 > > +int verbosity = 0; static > + > void cp_display_usage(void); > +int cp_file(char* src_path, char* dst_path); > +int cp_recursive(char* src_path, char* dst_path); Hier tut es wegen dem cp_ zwar nicht weh, könnten aber auch static sein. > > #ifdef CONFIG_SHELL_BUILTIN_ONLY > int shell_command_cp(int argc, char* argv[], const char* args) > @@ -53,21 +59,158 @@ void cp_display_usage(void); > int main(int argc, char* argv[]) > #endif > { > - if (argc != 3) { > + static const struct option long_options[] = > + { > + { "target", required_argument, 0, 't' }, > + { "recursive", no_argument, 0, 'r' }, > + { "verbose", no_argument, 0, 'v' }, > + { "help", no_argument, 0, 'h' }, > + { 0, 0, 0, 0 } > + }; > + > + optind = 0; > + verbosity = 0; > + > + char* targetpath = NULL; > + list_t* sources = list_create(); > + > + int index = -1; > + int result; > + > + int recursive = 0; > + > + while (optind < argc) { > + result = getopt_long(argc, argv, "vrt:", long_options, &index); Fehlt da nicht -h? > + if (result == -1) { > + break; > + } > + switch (result) { > + case 't': > + targetpath = optarg; > + break; > + case 'r': > + recursive = 1; > + break; > + case 'v': > + verbosity++; > + break; > + case 'h': > + cp_display_usage(); > + return EXIT_SUCCESS; > + default: > + break; > + } > + } > + > + while (optind < argc) { > + list_push(sources, (void*)argv[optind++]); Der Cast ist unnötig, von und nach void* geht automatisch. > + } > + > + // Falls kein Target-Parameter gegeben ist, letztes Element des > Listings. + if (targetpath == NULL) { > + targetpath = (char*)list_pop(sources); > + } > + > + if (targetpath == NULL || list_size(sources) == 0) { > cp_display_usage(); > + goto bad_exit; > + } > + > + if ( (list_size(sources) > 1) && (!is_directory(targetpath)) ) { > + fprintf(stderr, > + "Fehler: Mehrere Quellen, aber Ziel ist kein Verzeichnis!\n"); > + goto bad_exit; > + } > + > + char* src_path = NULL; > + while ( (src_path = (char*)list_pop(sources)) ) { > + if (is_directory(src_path)) { > + if (recursive) { > + cp_recursive(src_path, targetpath); > + } > + else { > + fprintf(stderr, "%s übersprungen (suchen sie 'cp -r' > ?)\n", src_path); + goto bad_exit; s/sie/Sie/ ;-) > + } > + } else { > + result = cp_file(src_path, targetpath); > + if (result == -1) { > + fprintf(stderr, "Konnte die Quelldatei nicht öffnen\n"); > + goto bad_exit; > + } > + else if (result == -2) { Das else gehört auf die Zeile vom } > + fprintf(stderr, "Konnte die Zieldatei nicht öffnen\n"); > + goto bad_exit; Bei den Fehlermeldungen wäre es evtl. noch sinnvoll zu sagen, bei welcher Datei er jetzt eigentlich grad war. > + } > + } > + } > + > + list_destroy(sources); > + return EXIT_SUCCESS; > + > + bad_exit: > + list_destroy(sources); > + return EXIT_FAILURE; > +} > + > +void cp_display_usage() > +{ > + printf("Aufruf: cp [OPTIONEN] \n" > + " oder: cp [OPTIONEN] ... \n" > + " oder: cp [OPTIONEN] -t ...\n" > + "\n" > + "Optionen:\n" > + " -v --verbose durchgeführte Tätigkeiten erklären\n" > + " -r --recursive Verzeichnisse rekursiv kopieren\n" > + " -h --help diese Hilfe anzeigen\n"); > +} > + > +int cp_recursive(char* src_path, char* dst_path) > +{ > + if (is_directory(dst_path)) { > + dst_path = strcat(dst_path, io_split_filename(src_path)); > + } Das riecht nach Buffer Overflow und zwar einem garantierten (strcat alloziert nicht, sondern hängt an dst_path an). Du suchst asprintf. > + if (!directory_create(dst_path)) { > + fprintf(stderr, "Fehler: Pfad %s konnte nicht angelegt werden!\n", > dst_path); + fprintf(stderr, " %s übersprungen.\n", > src_path); > return -1; > } > + if (verbosity > 0) { > + printf("'%s' -> '%s'\n", src_path, dst_path); > + } > > - char* src_path = argv[1]; > - char* dst_path = argv[2]; > + io_resource_t* dir_res = directory_open(src_path); > + char *full_src_path = NULL; > + char *full_dst_path = NULL; char* x, nicht char *x > + if (dir_res != NULL) { > + io_direntry_t* direntry; > + while ((direntry = directory_read(dir_res))) { > + asprintf(&full_src_path, "%s/%s", src_path, direntry->name); > + asprintf(&full_dst_path, "%s/%s", dst_path, direntry->name); > + if (direntry->type == IO_DIRENTRY_FILE) { > + cp_file(full_src_path, full_dst_path); > + } else { > + cp_recursive(full_src_path, full_dst_path); > + } > + free(full_src_path); > + free(full_dst_path); > + free(direntry); > + } > + directory_close(dir_res); > + return 1; 0 für Erfolg wäre üblicher, wenn -1 Fehler ist. > + } > + else { > + return -1; > + } > +} > > +int cp_file(char* src_path, char* dst_path) { > FILE* src = fopen(src_path, "r"); > if (src == NULL) { > - fprintf(stderr, "Konnte die Quelldatei nicht oeffnen\n"); > - return EXIT_FAILURE; > + return -1; > } > > - FILE* dst; > + FILE* dst = NULL; > if (is_directory(dst_path)) { > char* filename = io_split_filename(src_path); > size_t length = strlen(filename) + strlen(dst_path) + 1; > @@ -78,20 +221,20 @@ void cp_display_usage(void); > dst_file_path[strlen(dst_file_path)] = '/'; > strcat(dst_file_path, filename); > dst_file_path[length] = '\0'; > - > - dst = fopen(dst_file_path, "w"); > - } else { > - dst = fopen(dst_path, "w"); > + dst_path = dst_file_path; > } > + dst = fopen(dst_path, "w"); > > if (dst == NULL) { > - fprintf(stderr, "Konnte die Zieldatei nicht oeffnen\n"); > - fclose(src); > - return EXIT_FAILURE; > + return -2; > } > > uint8_t buffer[BUFFER_SIZE]; > - > + > + if (verbosity > 0) { > + printf("'%s' -> '%s'\n", src_path, dst_path); > + } > + > while (!feof(src)) { > size_t length = fread(buffer, BUFFER_SIZE, 1, src); > if (length == 0) { > @@ -100,18 +243,12 @@ void cp_display_usage(void); > fclose(dst); > return EXIT_FAILURE; > } > - > + > fwrite(buffer, length, 1, dst); > } > > fclose(src); > fclose(dst); > > - return EXIT_SUCCESS; > -} > - > -void cp_display_usage() > -{ > - puts("\nAufruf: cp "); > + return 1; > } > - From alex at tyndur.org Fri Jul 31 23:05:00 2009 From: alex at tyndur.org (Alexander Siol) Date: Fri, 31 Jul 2009 23:05:00 +0200 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH=5D_Re=3A_+cp=3A_-r=2C_-v_u?= =?iso-8859-1?q?nd_-t_hinzugef=FCgt?= In-Reply-To: <200907312220.44415@kevin-wolf.de> References: <1246996911-30080-1-git-send-email-alex@tyndur.org> <1247059887-29488-1-git-send-email-alex@tyndur.org> <200907312220.44415@kevin-wolf.de> Message-ID: <20090731210500.GE19111@alex> So, hier die neue Variante -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : 0001--cp-r-v-und-t-hinzugef-gt.patch Dateityp : text/x-diff Dateigröße : 7872 bytes Beschreibung: nicht verfügbar URL : -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: Digital signature URL : From toni at tyndur.org Fri Jul 31 23:15:21 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 31 Jul 2009 23:15:21 +0200 Subject: [tyndur-devel] [PATCH v2] libc: Doubles in printf In-Reply-To: <1249029181-7358-1-git-send-email-kevin@tyndur.org> References: <1249029181-7358-1-git-send-email-kevin@tyndur.org> Message-ID: <20090731211521.GA11415@einstein.kaufmann.lan> On Fri, Jul 31 10:33, Kevin Wolf wrote: > + libc: printf: Unterstuetzung fuer Ausgabe von (long) doubles > > Signed-off-by: Kevin Wolf Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL :