/*
 * help.c for tesh NT
 * $Id: help.c,v 1.14 2004/06/16 08:21:52 tesh Exp $
 * 010714 cb
 *
 * (C) 2001 Christian Jacobi
 * (C) 2001 Christoph Berg
 *
 * 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.
 */

#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#include "help.h"

void help() {
	printf("Hilfe zur Tante-Emma-Shell:\n");
	printf("\n");
	printf("  Einkaufen:             <name> <artikel> ...\n");
	printf("                    z.B. cb balisto orangina hochwald\n");
	printf("  Kontostand abfragen:   <name> info\n");
	printf("  Letzte Kontobewegunen: <name> buchungen\n");
	printf("  Passwort aendern:      <name> passwd\n");
	printf("  Ueberweisung:          <name> ueberweisung\n");
	printf("\n");
	printf("  Fuer Einzahlungen bitte im Raum 314 melden.\n");
	printf("  Bei Fragen: Mail an tante@wjpserver.cs.uni-sb.de oder vorbeikommen.\n");
	printf("  Tip: TAB-Completion spart Tipparbeit.\n");
}

char *tante_strftime(struct tm t) {
	static char time_buf[100];

	strftime(time_buf, 100, "%a, %e. %b %Y, %R", &t);
	return time_buf;
}

/*int eur2dm(int euro) {
  return (int)(((float)euro)*EUR2DM);
}*/


char *betrag2s(int b) {
  static char betrag_str[30];

  snprintf(betrag_str, 30, "%.2f", (float)b / 100.0);
  return betrag_str;
}

char *betrag2s_2(int b) { // zweite Kopie, da statische Daten
  static char betrag_str[30];

  snprintf(betrag_str, 30, "%.2f", (float)b / 100.0);
  return betrag_str;
}

/*char *betrag2dm(int b) {
  static char betrag_str[30];

  snprintf(betrag_str, 30, "%.2f", (float)b * EUR2DM / 100.0);
  return betrag_str;
}*/

char *cryptseed() {
	static char c[3];
	static char rand[16];
	int f, i, j;

	f = open("/dev/random", O_RDONLY);
	assert(f != -1);
	for(i = 0; i < 2; i++) {
		do {
			read(f, rand, 16);
			for(j = 0; j < 16; j++) {
				c[i] += rand[j];
			}
		} while (!isalnum(c[i]));
	}
	c[2] = '\0';
	close(f);

	return c;
}

char *komma(char *s) {
	char *p;
	for(p = s; *p; p++) {
		if(*p == ',')
			*p = '.';
	}
	return s;
}
