Visit Our UNIX and Linux User Community


pascal and C


 
Thread Tools Search this Thread
Top Forums Programming pascal and C
# 1  
Old 10-21-2007
pascal and C

Hi I don't understand syntax of pascal and I have some code in pascal. I will be very lucky, when someone could to rewrite into C.

procedure ListInit (var L:TList);
begin
L.Act:=nil;
L.Frst:=nil
end; (* ListInit *)

procedure InsertFirst(var L:Tlist,El:TEl);
var
UkPomEl:TUk;
begin
new(UkPomEl); (* Create a new element *)
UkPomEl^.Data:=El; (* Setting date folder *)
UkPomEl^.UkNasl:=L.Frst; (* Uk is pointer, where is beginning *)
L.Frst:=UkPomEl; (* Beginning pointig to new element *)
end; (* InsertFirst *)

procedureFirst(var L:TList);
begin
L.Active:=L.First(* First become active; in empty list without changes *)
end; (* First*)

functionActive(L:TList):Boolean;
begin
Active:=L.Act<>nil
end; (* Active*)

procedure PostInsert (var L:Tlist; El:TEl);
var PomUk:Tuk;
begin
if L.Act <> nil then begin (* Only for active list *)
new(PomUk);
PomUk^.Data:=El;
PomUk^.UkNasl:=L.Act^.UkNasl; (* New element pointing at the *)
(* same place, where active element poiniting too*)
L.Act^.UkNasl:= PomUk (* Active element pointing to the new element *)
end;

procedure Copy (L:Tlist; var El:TEl);
(* Operation suppose handling of activity of list in form: if Active(L) then begin
Copy(L,El); ... Copy in nonactive list evoke a mistake *)
begin
El:= L.Act^.Data
end;

procedure Actualize (var L:Tlist; El:TEl);
begin
if L.Act<> nil
then begin
L.Act^.Data:=El
end
end;

procedure PostDelete(var L:Tlist);
var
PomUk:Tuk;
begin
if (L.Act<>nil)
then
if L.Act^.UkNasl <> nil
then begin (* something can be canceled out *)
PomUk:=L.Act^UkNasl; (* Pointer to the canceled element *)
L.Act^.UkNasl:=PomUk^.UkNasl; (* Bypass of canceled element *)
Dispose(PomUk)
end (*if L.Act^.UkNasl<> *)
end (*if L.Act <> *)
end;


Thank for all for hepl
Milla
# 2  
Old 10-21-2007
Not exact as you have some undefined types, but something like..

Code:
void ListInit(TList *L)
{
	L->Act=NULL;
	L->Frst=NUL;
}

void InsertFirst(Tlist *L,TE1 *El)
{
	TUk *UkPomE1=malloc(sizeof(*UkPomEl));
	UkPomEl->Data=El;
	UkPomEl->UkNasl=L->Frst;
	L->Frst=UkPomEl;
}

void First(TList *L)
{
	L->Active=L->First;
}

int Active(TList *L)
{
	return (L->Act != NULL);
}

void PostInsert(Tlist *L,TE1 *El)
{
	if (L->Act)
	{
		Tuk *PomUk=malloc(sizeof(*PomUk));
		PomUk->Data=El;
		PomUk=UkNasl=L->Act->UkNasl;
		L->Act->UkNasl=PomUk;
	}
}

void Copy(Tlist *L,TE1 *El)
{
	(*El)=*(L->Act->Data)
}

void Actualize(Tlist *L, TE1 *El)
{
	if (L->Act)
	{
		*(L->Act->Data)=*El;
	}
}

void PostDelete(Tlist *L)
{
	if (L->Act)
	{
		if (L->Act->UkNas1)
		{
			Tuk *PomUk;
			PomUk=L->Act->UkNasl;
			L->Act->UkNasl=PomUk->UkNasl;
			free(PomUk);
		}
	}
}

there are free Pascal to C convertors available on the net.
# 3  
Old 10-28-2007
thank you porter
I try to use PtoC program, but I think, that it makes some mistakes or I don't understand of this program. Please I have some other codes, which i don't understand. Can someone to rewrite this pascal code to C code? Thank you very much


procedureDListInit(var L:TDList);
begin
L.Frst:=nil;
L.Lst:=nil;
L.Act:=nil;
(* PocPrv:=0; *)
end;

procedureDInsertFirst(var L:TDlist; El:TData);
var
PomUk:TUkPrv;
begin
new(PomUk);
PomUk^.Data:=El;
PomUk^.LUk:= nil; (* left pointer of new show to nil*)
PomUk^.PUk:= L.Frst; (* right of new show to actual first or nil*)
ifL.Frst<> nil
then
L.Frst^.LUk:=PomUk; (* actual first show to the left and to a new elementh*)
else(* add to empty list *)
L.Lst:=Pomuk;
L.Frst:=PomUk; (* corection of pointer of beginning *)
end;

procedureDDeleteFirst(var L:TDlist);
(* You have to check, if you canceled active element or only one element *)
var
PomUk:TUkPrv;
begin
ifL.Frst<>nil
thenbegin
PomUk:= L.Frst;
ifL.Act=L.Frst
thenL.Act:= nil; (* first was activeí, canceled of activity of list*)
ifL.Frst=L.Lst
thenbegin(* canceled first element - ceating empty list*)
L.Lst:=nil;
L.Frst:= nil
endelsebegin
L.Frst:= L.Frst^.PUk; (* actualize of beginning of the list*)
L.Frst^.LUk:= nil; (* if list isnot empty, first element to the left pointing nil*)
end;
Dispose(PomUk)
end; (* if*)
end; (* procedure*)


procedureDPostInsert(var L:TDList; El:TData);
(* Procedure must controll, if you add last element*)
var
PomUk:TUkPrv;
begin
ifL.Act<>nil
thenbegin
new(PomUk);
PomUk^.Data:= El;
PomUk^.PUk:= L.Act^.PUk; (* *)
PomUk^.LUk:= L.Act;
L.Act^.Puk:= PomUk; (*adding of left elementh to inserting elementh*)
ifL.Act=L.Lst
thenL.Lst:=PomUk(* correction of poiter at the end - new is the last*)
elsePomUk^.PUk^.LUk:=PomUk(* adding of right elementh inserting elementh *)
end; (* if*)
end; (* procedure*)


procedureDPostDelete(var LSmilieList);
(* you have to controll, if you cancell last element *)
var
PomUk: TUkPrv;
begin
if(L.Act<> nil)
thenbegin
ifL.Act^.PUk <> nil(* can you cancel something? *)
thenbegin(* canceled elementh donot exist *)
PomUk:= L.Act^.PUk; (* pointer to conceled*)
L.Act^.PUk:= PomUk^.PUk; (* bypass of conceled *)
ifPomUk= L.Lst
thenL.Lst:=L.Act(* if the last is canceled, Act will be Lst*)
else(* common element is canceled *)
PomUk^.PUk^.LUk:= L.Act; (* element behind canceled pointing to the left to Act*)
Dispose(PomIk);
end; (*ifL.Act^.Puk <> nil*)
end; (* ifL.Act<> nil*)
end; (* procedure*)


procedureDPreDelete(var LSmilieList);
(* you have to check if you canceled firts element*)
var
PomUk: TUkPrv;
begin
if(L.Act<> nil)
then begin
if L.Act^.LUk <> nil (* can you cancel something? *)
then begin(* canceled elementh exist *)
PomUk:= L.Act^.LUk; (* pointer to conceled*)
L.Act^.LUk:= PomUk^.LUk; (* bypass of canceled *)
ifPomUk= L.Frst
thenL.Frst:=L.Act(*if the fitst is canceled, Act will be first*)
else(*common element is canceled*)
PomUk^.LUk^.PUk:= L.Act; (* element before canceled poiting to the right to Act*)
Dispose(PomUk)
end; (*ifL.Act^.Luk <> nil*)
end; (* ifL.Act<> nil*)
end; (* procedure*)


procedure CopyDoubleList (DLOrig:TDList; var DLDupl:TDList);
var
El:TData;
begin
DInit(DLDupl);
DFirst(DLOrig);
while DActive(DLOrig) do begin
DCopy(DLOrig,El);
DSucc(DLOrig);
DInsertLast(DLDupl,El)(* inserting at the end is copying easy*)
end (* while *)
end; (* procedure *)


procedure DPreDelete(var LSmilieList);
(* you have to chech, if you canceled first elementh *)
var
PomUk: TUkPrv;
begin
if (L.Act <> nil)
then begin
if L.Act^.LUk <> nil (* can you cancel something? *)
then begin (* canceled exist *)
PomUk:= L.Act^.LUk; (* pointer to canceled*)
L.Act^.LUk:= PomUk^.LUk;(* bypass of canceled *)
if PomUk = L.Frst
then L.Frst:=L.Act (* if first is canceled, first become active *)
else (* common element is canceled *)
PomUk^.LUk^.PUk:= L.Act; (* elementh before canceled pointing to the right to active elementh *)
Dispose(PomUk)
end (*if L.Act^.Luk <> nil *)
end (* if L.Act<> nil *)
end; (* procedure *)


//////////////////////////////////////////////



procedure QInit(var Q:TQueue);
begin
with Q do begin
QZac:=1;
QKon:=1
end (* with *)
end;


procedure QueUp (var Q:TQeue; El:TElem);
begin
Q.QPole[Q.QKon] := El;
Q.QKon:=Q.QKon + 1;
if Q.QKon > QMax
then Q.QKon := 1; (* attention of round of list *)
end;

procedure Remove (var Q:TQueue);
begin
if Q.QZac<>Q.QKon
then begin
Q.QZac:=Q.Qzac + 1;
if Q.QZac > QMax
then Q.QZac:=1; (* attention of round of array*)
end (* if *)
end;

procedure Front (Q.TQueue; var El:TElem);
(* Procedure make error if you read empty queue *)
begin
El:= Q.QPole[Q.QZac]
end;


function QEmpty(Q:TQueue): Boolean;
begin
QEmpty:= Q.Zac=Q.Kon
end;


function QFull(Q: TQueue): Boolean;
begin
QFull:= (Q.Zac=1) and (Q.Kon=QMax) or ((Q.Zac - 1) =
Q.Kon)
end;
# 4  
Old 10-28-2007
It may be time for you to learn Pascal.

The fundamentals are the same as C, basic types, structs, pointers etc, just different syntax.
# 5  
Old 10-28-2007
please I need this only for this nothing else
# 6  
Old 10-28-2007
Try this mapping:

Code:
description                Pascal     C

assignment               :=           =
pointer reference       ^            ->
variable arg              var          *
procedure                procedure  void
start scope              begin        {
end scopt                end          }
comment                 (*  *)       /*     */


Previous Thread | Next Thread
Test Your Knowledge in Computers #498
Difficulty: Medium
Learning a computer programming language is harder than learning a new spoken language.
True or False?

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need help in writing shell script to generate pascal's triangle

Hi :) I am learning shell scripting, I need help, I would like to have a script that produces pascal's triangle as shown in the picture http://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Pascal%27s_triangle_5.svg/250px-Pascal%27s_triangle_5.svg.png plz, help it's urgent thanks in... (1 Reply)
Discussion started by: angel1
1 Replies

2. UNIX for Dummies Questions & Answers

Traversing Pascal/Delphi code using GVim

Hi, I am using GVim as editor... and i am viewing code of pascal/ delphi.. my problem is its difficult to use GVim as source code browser.... normally ctags helps to traverse in vim for c/c++.. is there anything like that for pascal/ delphi to minimise this complication of each... (0 Replies)
Discussion started by: SankarV
0 Replies

Featured Tech Videos