Code: Alles auswählen
#include "sbimgnfo.h"
#include <string>
#define PACKAGE "sbimgnfo"
#define VERSION "1.0"
#define char_delay_usec 500
int main(int argc, char *argv[])
{
switch (fork()) {
case -1:
return -1;
case 0:
break;
default:
return 0;
}
if (setsid() < 0) {
perror("[sbimgnfo] error setsid");
return 1;
}
printf("%s - shows image information on virtual console, v%s\n", argv[0], VERSION);
printf("\t\tby Wahnfried, fernsehass, ctx, limette, scp\n\n");
char buf[200] = "";
char rel[10] = "";
char imageversion[4] = "";
char imagesubver[4] = "";
char jahr[5] = "2005";
char monat[3] = "01";
char tag[3] = "31";
char stunde[3] = "16";
char minute[3] = "00";
char ersteller[20] = "keine Angabe";
char adresse[20] = "127.0.0.1";
char broadcast[20] = "127.0.0.1";
char gateway[20] = "127.0.0.1";
char netmask[20] = "127.0.0.1";
char nameserver[20] = "127.0.0.1";
char gui[20] = "Neutrino";
int ch;
int m = 0;
FILE *out;
FILE *fb;
FILE *conf;
FILE* fv = fopen(".version", "r");
if(fv)
{
while(fgets(buf, 120, fv)!=NULL)
{
sscanf(buf, "version=%1s%1s%2s%4s%2s%2s%2s%2s", (char *) &rel,&imageversion,&imagesubver,&jahr,&monat,&tag,&stunde,&minute);
sscanf(buf, "comment=Erstellt von %s" , (char *) &ersteller);
}
fclose(fv);
}
FILE* fn = fopen("/var/etc/network/interfaces", "r");
if(fn)
{
while(fgets(buf, 120, fn)!=NULL)
{
sscanf(buf, "address %s" , (char *) &adresse);
sscanf(buf, "broadcast %s" , (char *) &broadcast);
sscanf(buf, "gateway %s" , (char *) &gateway);
sscanf(buf, "netmask %s" , (char *) &netmask);
}
fclose(fn);
}
FILE* fr = fopen("/var/etc/resolv.conf", "r");
if(fr)
{
while(fgets(buf, 120, fr)!=NULL)
{
sscanf(buf, "nameserver %s" , (char *) &nameserver);
}
fclose(fr);
}
if (strcmp(rel, "0") == 0)
{
sprintf(rel,"Release");
}
if (strcmp(rel, "1") == 0)
{
sprintf(rel,"Intern");
}
if (strcmp(rel, "2") == 0)
{
sprintf(rel,"Test");
}
out = fopen("/var/tmp/test.info", "w");
fprintf(out, "\n\n\n\n\n\n\n\t\t\t-------- Image Infos --------\n\n");
fprintf(out, "\t\t\t Image Version : %s.%s\n", imageversion,imagesubver);
fprintf(out, "\t\t\t Image Typ : %s\n", rel);
fprintf(out, "\t\t\t Erstelldatum : %s.%s.%s\n", tag,monat,jahr);
fprintf(out, "\t\t\t Erstelluhrzeit : %s:%s\n", stunde,minute);
fprintf(out, "\t\t\t Erstellt von : %s\n", ersteller);
fprintf(out, "\n\t\t\t Die Netzwerkeinstellungen sind:\n");
fprintf(out, "\t\t\t IP Adresse : %s\n", adresse);
fprintf(out, "\t\t\t Netzmaske : %s\n", netmask);
fprintf(out, "\t\t\t Broadcast : %s\n", broadcast);
fprintf(out, "\t\t\t Gateway : %s\n", gateway);
fprintf(out, "\t\t\t Nameserver : %s\n", nameserver);
fprintf(out, "\n\n\t\t\t\tLade %s......", gui);
fclose (out);
if((fb = fopen( "/dev/vc/1", "w" )) != NULL )
{
if((conf = fopen( "/var/tmp/test.info", "r" )) == NULL )
{ // dann
fprintf(fb, "\n\n\n\n\n\n\n\t\t\tKeine Image Info gefunden!\n"); //gebe aus
}
else //ansonsten
{
ch = fgetc(conf); //hole zeichen aus der config
while(!feof(conf)) //frage ob dateiende da ist ??
{
while (m<8)
{
fputc(ch, fb); //schreibe zeichen in /dev/vc/1
ch = fgetc(conf); //hole zeichen aus der config
fflush(fb); //speichere in datei /dev/vc/1
m = m + 1;
}
m = 0;
usleep(char_delay_usec * 8); //pause 4000 millionstel sek.
}
fclose(conf);
}
fclose(fb); //schliesse /dev/vc/1
system("rm /var/tmp/test.info");
}
return 0;
}
Jedoch unterscheidet sich der Aufbau dieser Ur-Version doch erheblich vom Aufbau der im cvs vorhanden cdkvcinfo.