VB icon

Arab_Renamer

Email
Submitted on: 1/6/2015 3:56:00 PM
By: Kurtubba (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: C, Microsoft Visual C++
Views: 1844
 
     This commandline prog renames Arabic files to the same names but using English characters like the word 'Quran', so that files could be used on non-Arabic systems like Linux or on mp3players, also the program gives you the opportunity of limiting the files names during renaming. The program uses characters like 3, ', 6 and 7 which are popular characters used to replace specific Arabic letters. Copy the exe file inside the directory you want the files inside to be renamed and press 'a', you can get the old Arabic names back by pressing 'u' on your keyboard which undo all last changes. Another important possibility Arab Renamer presents is renaming files by reading the new names from a file called 'nnames.txt' in the same dir. This way you can edit names using regular expressions with a program like Jedit, editplus or Textpad. 1st press 'd' to make 'onames.txt' which have the old names, or create it manually then press 'r' to start renaming. You can also undo this action as mentioned b4.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Arab_Renamer
// Description:This commandline prog renames Arabic files to the same names but using English characters like the word 'Quran', so that files could be used on non-Arabic systems like Linux or on mp3players,
also the program gives you the opportunity of limiting the files names during renaming.
The program uses characters like 3, ', 6 and 7 which are popular characters used to replace specific Arabic letters.
Copy the exe file inside the directory you want the files inside to be renamed and press 'a', you can get the old Arabic names back by pressing 'u' on your keyboard which undo all last changes.
Another important possibility Arab Renamer presents is renaming files by reading the new names from a file called 'nnames.txt' in the same dir.
This way you can edit names using regular expressions with a program like Jedit, editplus or Textpad.
1st press 'd' to make 'onames.txt' which have the old names, or create it manually then press 'r' to start renaming. You can also undo this action
as mentioned b4.
// By: Kurtubba (from psc cd)
//**************************************

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <io.h>
#include <errno.h>
#include <time.h>
void Intro(char*);
void ara_renamer(char*, int);
void renamer(char*);
char* convrtit(char ara_name[]);
char *Specialwords(char* ara_name);
char *_replace (char *source_str, char *search_str, char *replace_str);
void mkundo(char*,char*);
void undo();
int main(int argc, char* argv[])
{
	char pth[260]="";
	_splitpath(argv[0], NULL, NULL, pth, NULL);
	strcat(pth,".exe");
	Intro(pth);
}
void Intro(char* pth)
{
	char in;
	int prnt=0, mkfile=0, x;
	char ttl[]=" ###########################################################################\n"
		"## AAAAAARRRRR##\n"
		"## AA AAAAA AAAAA AAAAARR RRRR RRRRR RRRRR RRRRRRR RRRR RRRRR ##\n"
		"## AAAAAA AA AA AARRRRRR RRR RR R R R RRR ##\n"
		"## AAA AAAAAA AAAAA AAAAAARRR RRRR RR R RRRRR RR R R RRRR RRRRRR ##\n"
		"## AAA AAA AA A AAARRR RRRR R RR R RR R R RRRRR ##\n"
		"## AAA AAA AA A AAAAAARRR RRRR RR R RR R RR R R RRRR RRR ##\n"
		"## -----------By Kurtubba@gawab.com------------##\n";
	HANDLE hnd;
	hnd = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTitle("Arab Renamer V 1 - By Kurtubba Software");
	SetConsoleTextAttribute(hnd, FOREGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
	printf(ttl);
	printf("##To Rename files from nnames.txt press.... r##\n");
	printf("##To Make directory listing press.... d ##\n");
	printf("##To Rename arabic files press.... a ##\n");
	printf("##To undo last changes press.... u##\n");
	printf("##for help press ....h##\n");
	printf("##To exit press ...x ##\n");
	printf(" ###########################################################################\n");
	SetConsoleTextAttribute(hnd, COMMON_LVB_REVERSE_VIDEO | FOREGROUND_RED | FOREGROUND_GREEN |FOREGROUND_BLUE);
	do{
		if(prnt){
			SetConsoleTextAttribute(hnd, FOREGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			printf(" ###########################################################################\n");
			printf("##To Rename files from nnames.txt press.... r##\n");
			printf("##To Make directory listing press.... d ##\n");
			printf("##To Rename arabic files press.... a ##\n");
			printf("##To undo last changes press.... u##\n");
			printf("##for help press ....h##\n");
			printf("##To exit press ...x ##\n");
			printf(" ###########################################################################\n");
			SetConsoleTextAttribute(hnd, COMMON_LVB_REVERSE_VIDEO | FOREGROUND_RED | FOREGROUND_GREEN |FOREGROUND_BLUE);
		}
		in=getch();
		in=toupper(in);
		fflush(stdin);
		switch (in)
		{
		case 'D':
			mkfile=1;
			ara_renamer(pth,mkfile);
			prnt=1;
			break;
		case 'R':
			printf("Renaming...\n\n");
			renamer(pth);
			prnt=1;
			break;
		case 'A':
			mkfile=0;
			printf("Renaming...\n\n");
			ara_renamer(pth,mkfile);
			prnt=1;
			break;
		case 'U':
			printf("Undoing last changes\n\n");
			undo();
			prnt=1;
			break;
		case 'H':
			printf("Diplaying help\n");
			system("cls");
			printf("\n");
			SetConsoleTextAttribute(hnd, FOREGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			for(x=0;ttl[x]!='\0';x++){
				printf("%c",ttl[x]);
				_sleep((clock_t).1 * CLOCKS_PER_SEC);
			}
			printf(" ###########################################################################\n\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			SetConsoleTextAttribute(hnd, COMMON_LVB_REVERSE_VIDEO | FOREGROUND_RED | FOREGROUND_GREEN |FOREGROUND_BLUE);
			printf("Arab Renamer renames Arabic files to the same names but\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("using English characters like the word 'Quran', so that files\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("could be used on non-Arabic systems like Linux or on mp3players,\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("also the program gives you the opportunity of limiting the\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("files names during renaming.\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("The program uses characters like 3, ', 6 and 7 which are popular\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("characters used to replace specific Arabic letters.\n\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("Copy the exe file inside the directory you want the files inside\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("to be renamed and press 'a', you can get the old Arabic names \n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("back by pressing 'u' on your keyboard which undo all last changes.\n\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("Another important possibility Arab Renamer presents is renaming files\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("by reading the new names from a file called 'nnames.txt' in the same dir.\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("This way you can edit names using regular expressions with a program like\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("Jedit, editplus or Textpad.\n");
			printf("1st press 'd' to make 'onames.txt' which have the old names, or create it\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("manually then press 'r' to start renaming. You can also undo this action \n");
			printf("as mentioned b4.\n");
			_sleep((clock_t)1 * CLOCKS_PER_SEC);
			printf("\n");
			printf("ENJOY!!\n");
			_sleep((clock_t).1 * CLOCKS_PER_SEC);
			printf("\n");
			printf("Email me for help or to request s.code <kurtubba@gawab.com>\n");
			_sleep((clock_t).1 * CLOCKS_PER_SEC);
			printf("\n");
			printf("\n");
			system("pause");
			prnt=1;
			break;
		case 'X':
			printf("Ending...\n\n");
			exit(0);
		default:
			prnt=0;
		}
	}while(in);
}
void undo()
{
	FILE* list;
	char buf[260]="",buf2[260]="", *nname,*oname;
	if(!(list=fopen("undo","r")))
	{
		printf("Can't find undo record file\n\n");
		return;
	}
	while(!feof(list))
	{
		oname=strtok(fgets(buf,260,list), "\n");
		nname=strtok(fgets(buf2,260,list), "\n");
		if(oname && nname)
		{
			if(rename(oname, nname)){
				if (errno==EEXIST)
					printf ("Permission denied: file %s already exists.\n", nname);
				if (errno==ENOENT)
					printf("%s doesn't exist\n", oname);
				if (errno==EACCES)
					printf("Access Denied: file %s in use\n", oname);
			}else
				printf("%s renamed to %s\n", oname, nname);
		}
	}
	//remove("undo");
	fclose(list);
	return;
}
void renamer(char* pth)
{
	FILE* fp, *fp2, *list;
	char buf[128]="",buf2[128]="";
	char *nname, *oname, in;
	fp2 = fopen("onames.txt", "r");
	if(!fp2){
		printf("onames.txt not found create one by pressing 'd'\n\n");
		return;
	}
	fp = fopen("nnames.txt", "r");
	if(!fp){
		fclose(fp2);
		printf("nnames.txt not found\n\n");
		return;
	}
	if((list=fopen("undo","r"))){
		fclose(list);
		printf("This will remove the last undo...Continue?\n");
		in=getch();
		in=toupper(in);
		if(in!='Y' && in!=' ' && in!='\r'){
			printf("NO\n\n");
			return;
		}else if(remove("undo")){
			if (errno==EACCES)
				printf("Access Denied: file undo in use\n\n");
			return;
		}else
			printf("YES\n\n");
	}
	while(!feof(fp2)){
		nname=strtok(fgets(buf, 127, fp), "\n");
		oname=strtok(fgets(buf2, 127, fp2), "\n");
		if (oname != NULL && nname != NULL && strcmp(nname,oname) ){
			if(rename(oname, nname)){
				if (errno==EEXIST)
					printf ("Permission denied: file %s already exists.\n", nname);
				if (errno==ENOENT)
					printf("%s doesn't exist\n", oname);
				if (errno==EACCES)
					printf("Access Denied: file %s in use\n", oname);
			}else{
				mkundo(oname,nname);
				printf ("%s renamed to %s\n", oname, nname);
			}
		}else if(oname != NULL){
			if (nname == NULL || !strcmp(nname,oname))
				printf("file %s No Change\n", oname);
		}
	}
	fclose(fp);
	fclose(fp2);
}
void ara_renamer(char* pth, int mkfile)
{
	struct _finddata_t x;
	char* oldname=x.name, ext[10]="", tmpname[260]="", newname[260]="", in=0;
	int done=0, lens=0;
	intptr_t handle;
	FILE* list;
	int s=0;
	handle = _findfirst( "*.*", & x);
	if(!mkfile)
	{
		if((list=fopen("undo","r"))){
			fclose(list);
			printf("This will remove the last undo...Continue?\n");
			in=getch();
			in=toupper(in);
			if(in!='Y' && in!=' ' && in!='\r'){
				printf("NO\n\n");
				return;
			}else if(remove("undo")){
				if (errno==EACCES)
					printf("Access Denied: file undo in use\n\n");
				return;
			}else
				printf("YES\n\n");
		}
		printf("do you want to limit the number of characters in the new names?\n");
		in=getch();
		in=toupper(in);
		if(in=='Y' || in==' ' || in=='\r'){
			printf("YES\n");
			while(!s){
				printf("Enter a number between 5 and 200\n");
				scanf("%d",&s);
				fflush( stdin );
				if(s<5 || s>200)
				{
					s=0;
					printf("Wrong Value. try again!..\n\n");
				}
			}
		}else
			printf("NO\n\n");
	}else if(mkfile){
		if((list=fopen("onames.txt","r"))){
			fclose(list);
			printf("File onames.txt aready exists...are you sure you want to overwrite?\n");
			in=getch();
			in=toupper(in);
			if(in!='Y' && in!=' ' && in!='\r'){
				printf("File not changed\n\n");
				return;
			}
		}
		list=fopen("onames.txt", "w+");
		if (!list){
			printf("Can't create file\n");
			return;
		}
		printf("Writing file...\n");
	}
	while ( !done )
	{
		if (strcmp(oldname,".") && strcmp(oldname,"..") && strcmp(oldname,pth) && !(x.attrib & _A_SUBDIR) && strcmp(x.name,"onames.txt") && strcmp(x.name,"nnames.txt") && strcmp(x.name,"undo"))
		{
			if(!mkfile)
			{
				ext[0]='\0';
				if(strrchr(oldname,'.'))
				{
					if((strlen(strrchr(oldname,'.')))<6)
						strcpy(ext, strrchr(oldname,'.'));
				}
				strncpy(tmpname,oldname,strlen(oldname)-strlen(ext));
				tmpname[strlen(oldname)-strlen(ext)]='\0';
				strcpy(newname, convrtit(tmpname));
				if (stricmp(tmpname, newname)){
					if (s){
						newname[s]='\0';
						tmpname[s]='\0';
					}
					if(ext)
						strcat(newname, ext);
					if(rename (oldname, newname)){
						if (errno==EEXIST)
							printf ("Permission denied: file %s already exists.\n", newname);
						if (errno==ENOENT)
							printf("%s doesn't exist\n", oldname);
						if (errno==EACCES)
							printf("Access Denied: file %s in use\n", oldname);
					}else{
						mkundo(oldname,newname);
						printf("%s renamed to %s\n", oldname, newname);
					}
				}else
					printf("File %s No Changes\n", oldname);
			}else if(mkfile){
				fprintf(list,"%s\n",oldname);
				printf("%s\n",oldname);
			}
		}
		done = _findnext( handle, & x );
	}
	_findclose(handle);
	if(mkfile)
	{
		fclose(list);
		CopyFileA("onames.txt","nnames.txt", 1);
		printf("\nfile onames.txt created successfully.\nEdit file nnames.txt to create new names\n\n");
	}
	return;
}
void mkundo(char* oldname,char *newname)
{
	FILE* list;
	if(list=fopen("undo","a"))
	{
		fprintf(list, "%s\n%s\n", newname, oldname);			
		fclose(list);
	}else
		printf("Can't create undo file\n");
}
char* convrtit(char ara_name[260])
{
	int n=0, v;
	char cnvr[3]="", eng_name[260]="";
	ara_name = Specialwords(ara_name);
	while (ara_name[n]){
		v=1;
		switch (ara_name[n])
		{
		case 'أ':
		case 'ا':
		case 'آ':
			cnvr[0]='a';
			break;
		case 'إ':
			cnvr[0]='e';
			break;
		case 'ب':
			cnvr[0]='b';
			break;
		case 'ت':
			cnvr[0]='t';
			break;
		case 'ث':
			strcpy(cnvr, "th");
			v=2;
			break;
		case 'ج':
			cnvr[0]='g';
			break;
		case 'ح':
			cnvr[0]='7';
			break;
		case 'خ':
			strcpy(cnvr, "kh");
			v=2;
			break;
		case 'د':
		case 'ض':
			cnvr[0]='d';
			break;
		case 'ذ':
		case 'ز':
		case 'ظ':
			cnvr[0]='z';
			break;
		case 'ر':
			cnvr[0]='r';
			break;
		case 'س':
		case 'ص':
			cnvr[0]='s';
			break;
		case 'ش':
			strcpy(cnvr, "sh");
			v=2;
			break;
		case 'ط':
			cnvr[0]='6';
			break;
		case 'ع':
			cnvr[0]='3';
			break;
		case 'غ':
			strcpy(cnvr, "gh");
			v=2;
			break;
		case 'ف':
			cnvr[0]='f';
			break;
		case 'ق':
			cnvr[0]='q';
			break;
		case 'ك':
			cnvr[0]='k';
			break;
		case 'ل':
			cnvr[0]='l';
			break;
		case 'م':
			cnvr[0]='m';
			break;
		case 'ن':
			cnvr[0]='n';
			break;
		case 'ه':
		case 'ة':
			cnvr[0]='h';
			break;
		case 'ؤ':
			strcpy(cnvr, "u'");
			v=2;
			break;
		case 'و':
			cnvr[0]='w';
			break;
		case 'ي':
		case 'ى':
			cnvr[0]='y';
			break;
		case 'ء':
		case 'ئ':
			cnvr[0]='\'';
			break;
		case 'ٍ':
		case 'ـ':
			cnvr[0]='\0';
			break;
		default:
			cnvr[0]=ara_name[n];
			break;
		}
		if (v==1)
			cnvr[1]='\0';
		else
			cnvr[2]='\0';
		strcat(eng_name, cnvr);
		n++;
	}
	return eng_name;
}
char *Specialwords(char* ara_name)
{
	ara_name = _replace( ara_name, "الناس", "An-Nas");
	ara_name = _replace( ara_name, "الفلق", "Al-Falaq");
	ara_name = _replace( ara_name, "الإخلاص", "Al-Ikhlas");
	ara_name = _replace( ara_name, "المسد", "Al-Masadd");
	ara_name = _replace( ara_name, "النصر", "An-Nasr");
	ara_name = _replace( ara_name, "الكافرون", "Al-Kafiroon");
	ara_name = _replace( ara_name, "الكوثر", "Al-Kauther");
	ara_name = _replace( ara_name, "الماعون", "Al-Ma3un");
	ara_name = _replace( ara_name, "قريش", "Quraish");
	ara_name = _replace( ara_name, "الفيل", "Al-Fil");
	ara_name = _replace( ara_name, "الهمزة", "Al-Humaza");
	ara_name = _replace( ara_name, "العصر", "Al-3asr");
	ara_name = _replace( ara_name, "التكاثر", "At-Takathur");
	ara_name = _replace( ara_name, "القارعة", "Al-Qari3a");
	ara_name = _replace( ara_name, "العاديات", "Al-3adiyat");
	ara_name = _replace( ara_name, "الزلزلة", "Az-Zalzala");
	ara_name = _replace( ara_name, "البينة", "Al-Bayyina");
	ara_name = _replace( ara_name, "القدر", "Al-Qadr");
	ara_name = _replace( ara_name, "العلق", "Al-3alaq");
	ara_name = _replace( ara_name, "التين", "At-Tin");
	ara_name = _replace( ara_name, "الشرح", "As-Sharh");
	ara_name = _replace( ara_name, "الضحى", "Ad-Dhu7a");
	ara_name = _replace( ara_name, "الليل", "Al-Layl");
	ara_name = _replace( ara_name, "الشمس", "Ash-Shams");
	ara_name = _replace( ara_name, "البلد", "Al-Balad");
	ara_name = _replace( ara_name, "الفجر", "Al-Fajr");
	ara_name = _replace( ara_name, "الغاشية", "Al-Ghashiya");
	ara_name = _replace( ara_name, "الأعلى", "Al-A3la");
	ara_name = _replace( ara_name, "الطارق", "At-6ariq");
	ara_name = _replace( ara_name, "البروج", "Al-Burooj");
	ara_name = _replace( ara_name, "الانشقاق", "Al-Inshiqaq");
	ara_name = _replace( ara_name, "المطففين", "Al-Mutaffifin");
	ara_name = _replace( ara_name, "الانفطار", "Al-Infi6ar");
	ara_name = _replace( ara_name, "التكوير", "At-Takwir");
	ara_name = _replace( ara_name, "عبس", "3basa");
	ara_name = _replace( ara_name, "النازعات", "An-Nazi3at");
	ara_name = _replace( ara_name, "النبأ", "An-Nab'");
	ara_name = _replace( ara_name, "المرسلات.rm", "Al-Mursalat");
	ara_name = _replace( ara_name, "الإنسان.rm", "Al-Insan");
	ara_name = _replace( ara_name, "القيامة.rm", "Al-Qiyama");
	ara_name = _replace( ara_name, "المدثر", "Al-Muddather");
	ara_name = _replace( ara_name, "المزمل", "Al-Muzzammil");
	ara_name = _replace( ara_name, "الجن", "Al-Jinn");
	ara_name = _replace( ara_name, "نوح", "Noo7");
	ara_name = _replace( ara_name, "المعارج", "Al-Ma3arij");
	ara_name = _replace( ara_name, "الحاقة", "Al-7aaqqa");
	ara_name = _replace( ara_name, "القلم", "Al-Qalam");
	ara_name = _replace( ara_name, "الملك", "Al-Mulk");
	ara_name = _replace( ara_name, "التحريم", "At-Ta7rim");
	ara_name = _replace( ara_name, "الطلاق", "At-Talaq");
	ara_name = _replace( ara_name, "التغابن", "At-Taghabun");
	ara_name = _replace( ara_name, "المنافقون", "Al-Munafiqoon");
	ara_name = _replace( ara_name, "الجمعة", "Al-Jumu3a");
	ara_name = _replace( ara_name, "الصف", "As-Saff");
	ara_name = _replace( ara_name, "الممتحنة", "Al-Mumta7ana");
	ara_name = _replace( ara_name, "الحشر", "Al-7ashr");
	ara_name = _replace( ara_name, "المجادلة", "Al-Mujadala");
	ara_name = _replace( ara_name, "الحديد", "Al-7adid");
	ara_name = _replace( ara_name, "الواقعة", "Al-Waqi3a");
	ara_name = _replace( ara_name, "الرحمن", "Ar-Ra7man");
	ara_name = _replace( ara_name, "القمر", "Al-Qamar");
	ara_name = _replace( ara_name, "النجم", "An-Najm");
	ara_name = _replace( ara_name, "الطور", "At-6ur");
	ara_name = _replace( ara_name, "الذاريات", "Az-Zariyat");
	ara_name = _replace( ara_name, "الحجرات", "Al-7ujraat");
	ara_name = _replace( ara_name, "الفتح", "Al-Fat7");
	ara_name = _replace( ara_name, "محمد", "Muhammad");
	ara_name = _replace( ara_name, "الأحقاف", "Al-A7qaf");
	ara_name = _replace( ara_name, "الجاثية", "Al-Jathiya");
	ara_name = _replace( ara_name, "الدخان", "Ad-Dukhan");
	ara_name = _replace( ara_name, "الزخرف", "Az-Zukhruf");
	ara_name = _replace( ara_name, "الشورى", "Ash-Shura");
	ara_name = _replace( ara_name, "فصلت", "Fussilat");
	ara_name = _replace( ara_name, "غافر", "Ghafir");
	ara_name = _replace( ara_name, "الزمر", "Az-Zumar");
	ara_name = _replace( ara_name, "الصافات", "As-Saaffat");
	ara_name = _replace( ara_name, "فاطر", "Fa6er");
	ara_name = _replace( ara_name, "سبأ", "Saba'");
	ara_name = _replace( ara_name, "الأحزاب", "Al-A7zab");
	ara_name = _replace( ara_name, "السجدة", "As-Sajda");
	ara_name = _replace( ara_name, "لقمان", "Luqman");
	ara_name = _replace( ara_name, "الروم", "Ar-Room");
	ara_name = _replace( ara_name, "العنكبوت", "Al-3ankaboot");
	ara_name = _replace( ara_name, "القصص", "Al-Qasas");
	ara_name = _replace( ara_name, "النمل", "An-Naml");
	ara_name = _replace( ara_name, "الشعراء", "Ash-Shu3ara'");
	ara_name = _replace( ara_name, "الفرقان", "Al-Furqan");
	ara_name = _replace( ara_name, "النور", "An-Noor");
	ara_name = _replace( ara_name, "المؤمنون", "Al-Mu'menoon");
	ara_name = _replace( ara_name, "الحج", "Al-7ajj");
	ara_name = _replace( ara_name, "الأنبياء", "Al-Anbiya'");
	ara_name = _replace( ara_name, "مريم", "Maryam");
	ara_name = _replace( ara_name, "الكهف", "Al-Kahf");
	ara_name = _replace( ara_name, "الإسراء", "Al-Isra'");
	ara_name = _replace( ara_name, "النحل", "An-Na7l");
	ara_name = _replace( ara_name, "الحجر", "Al-7ijr");
	ara_name = _replace( ara_name, "إبراهيم", "Ibrahim");
	ara_name = _replace( ara_name, "الرعد", "Ar-Ra3d");
	ara_name = _replace( ara_name, "يوسف", "Yusuf");
	ara_name = _replace( ara_name, "هود", "Hud");
	ara_name = _replace( ara_name, "يونس", "Yunus");
	ara_name = _replace( ara_name, "التوبة", "At-Tawba");
	ara_name = _replace( ara_name, "الأنفال", "Al-Anfal");
	ara_name = _replace( ara_name, "الأعراف", "Al-A3raf");
	ara_name = _replace( ara_name, "الأنعام", "Al-An3aam");
	ara_name = _replace( ara_name, "المائدة", "Al-Ma'eda");
	ara_name = _replace( ara_name, "النساء", "An-Nisa");
	ara_name = _replace( ara_name, "آل عمران", "Aal-e-3imran");
	ara_name = _replace( ara_name, "البقرة", "Al-Baqara");
	ara_name = _replace( ara_name, "الفاتحة", "Al-Fatiha");
	ara_name = _replace( ara_name, "الله", "Allah");
	ara_name = _replace( ara_name, "لله", "lelah");
	ara_name = _replace( ara_name, "القرآن", "Al-Quran");
	ara_name = _replace( ara_name, "قرآن", "Quran");
	ara_name = _replace( ara_name, " ال", " al-");
	/*buggy piece*/
	if(!strcmp(ara_name, "ق"))
		ara_name = _replace( ara_name, "ق", "Qaf");
	if(strstr(ara_name, " ق"))
		if(!strcmp(strstr(ara_name, " ق")+2, "") || !strcmp(strstr(ara_name, " ق")+2, " "))
			ara_name = _replace( ara_name, " ق", " Qaf");
	if(!strcmp(ara_name, "ص"))
		ara_name = _replace( ara_name, "ص", "Sad");
	if(strstr(ara_name, " ص"))
		if(!strcmp(strstr(ara_name, " ص")+2, "") || !strcmp(strstr(ara_name, " ص")+2, " ") )
			ara_name = _replace( ara_name, " ص", " Sad");
	if(!strcmp(ara_name, "يس") )
		ara_name = _replace( ara_name, "يس", "Ya-seen");
	if(strstr(ara_name, " يس"))
		if(!strcmp(strstr(ara_name, " يس")+3, "") || !strcmp(strstr(ara_name, " يس")+3, " ") )
			ara_name = _replace( ara_name, " يس", " Ya-seen");
	if(!strcmp(ara_name, "طه") )
		ara_name = _replace( ara_name, "طه", " 6aha");
	if(strstr(ara_name, " طه"))
		if(!strcmp(strstr(ara_name, " طه")+3, "") || !strcmp(strstr(ara_name, " طه")+3, " ") )
			ara_name = _replace( ara_name, " طه", " 6aha");
	/*buggy end*/
	return ara_name;
}
char *_replace (char *source_str, char *search_str, char *replace_str)
{
	char *p, *q, *s, *t, *newbuf = NULL;
	int count,newlen;
	int search_strlen = strlen (search_str);
	int replace_strlen = strlen (replace_str);
	int remainlen = 0;
	if(!source_str || !search_str || !replace_str) 
		return "Not enough arguments";
	if(!strstr( source_str, search_str )) 
		return source_str;
	for (count = 0, p = source_str; (q = strstr (p, search_str)) != NULL; p = q + search_strlen, count++) 
		;
	remainlen = strlen (p);
	if (count > 0) {
		newlen = strlen (source_str) + (count * strlen (replace_str) - count * search_strlen)+1;
		if ((newbuf = malloc (newlen)) != NULL)
		{
			memset (newbuf, '\0', newlen);
			for (s = p = source_str, t = newbuf; (q = strstr (p, search_str)) != NULL; ) 
			{
				memcpy (t, s, q - s);
				t += (q - s);
				memcpy (t, replace_str, replace_strlen);
				t += replace_strlen;
				s = p = q + search_strlen;
			}
			memcpy (t, s, remainlen);
			return newbuf;
		}
	}
	else
		return source_str;
} 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.