Pagini recente » Cod sursa (job #1081919) | Cod sursa (job #430591) | Cod sursa (job #2423088) | Cod sursa (job #612644) | Cod sursa (job #36605)
Cod sursa(job #36605)
#include <conio.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#define FOR(i,a,b) for( i = (a) ; i < (b) ; ++i )
#define PRINT_COMMAND { char tmp[128]={0}; trans(cmd.substr(6,cmd.length()-6),tmp); print_file(tmp); }
#define RUN_COMMAND { char tmp[128]={0}; trans(cmd.substr(4,cmd.length()-4),tmp); system(tmp); }
#define RHIDE system("c:/djgpp/bin/rhide.exe\n");
using namespace std;
string line, cmd;
void DO(string cmd);
void print_file(const char x[]);
void trans(string x,char A[]);
void get(string &x);
void fget(FILE *f,string &x);
void color(string x);
void init();
int main()
{
init();
while(cmd != "exit")
{
cout<<line;
get(cmd); //funtia mea smechera de citit stringuri :)) '
DO(cmd);
}
return 0;
}
void DO(string cmd)
{
if(cmd == "exit")
return ;
else
if(cmd.substr(0,3) == "run")
RUN_COMMAND
else
if(cmd == "rhide")
RHIDE
else
if(cmd == "help")
print_file("list.crawler");
else
if(cmd == "clrscr")
clrscr();
else
if(cmd.substr(0,5) == "print")
PRINT_COMMAND
else
if(cmd.substr(0,5) == "color")
color(cmd);
else
if(cmd.substr(0,4) == "line")
line = cmd.substr(5,cmd.length()-5);
else
cout<<"type 'help' for list of commands !\n";
}
void print_file(const char x[])
{
FILE *f = fopen(x,"r");
char c;
while((c=fgetc(f)) != EOF)
cout<<c;
fclose(f);
}
void trans(string x, char A[])
{
int i;
for(i=0;i<x.length();++i)
A[i] = x[i];
}
void get(string &x)
{
char buf[128];
fgets(buf,128,stdin);
buf[strlen(buf)-1] = 0;
x = buf;
}
void fget(FILE *f,string &x)
{
char buf[128];
fgets(buf,128,f);
buf[strlen(buf)-1] = 0;
x = buf;
}
void color(string x)
{
if(x == "color blue")
textcolor(9);
if(x == "color red")
textcolor(4);
if(x == "color green")
textcolor(2);
if(x == "color white")
textcolor(15);
clrscr();
// print_file("hello world.crawler");
}
void init()
{
FILE *f = fopen("default.crawler","r");
while(cmd != "exit")
{
fget(f,cmd); //funtia mea smechera de citit stringuri :)) '
DO(cmd);
}
cmd = "by Puni Andrei Paul";
}