Poster | Thread |
AmiDARK
| |
Dos.library SystemTags & FileInfoBlock Posted on 16-Jul-2012 16:30:33
| | [ #1 ] |
|
|
|
Regular Member |
Joined: 28-Mar-2007 Posts: 469
From: South France | | |
|
| Hello.
do someone have any sample showing how I can use SystemTags function to execute a cli program from my C application ? Same for FileInfoBlock. I need to use it to get a file creation date & last changes date.
Can someone help please ?
Thank you.
Regards, |
|
Status: Offline |
|
|
Ami603
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 16-Jul-2012 17:32:29
| | [ #2 ] |
|
|
|
Cult Member |
Joined: 7-Mar-2003 Posts: 580
From: Valencia,Spain 8-) | | |
|
| @AmiDARK
/* ** RunCmd V1.0 ** Launches Asyncronously a shell command, while retaining ** all the console output in a listbrowser. ** ** Dependencies: ** Exec,DOS,Utility,Intuition,ListBrowser,(Layout?) ** ** Should be Fully Reentrant,(I HOPE) no global data is used. ** ** Inputs: ** Name: Name of the command to launch ** Out: ListBrowser nodes list ** Gad: ListBrowser gadget pointer ** Win: ListBrowser Window pointer ** Retuns: ** Nothing. ** TODO: ** Maybe returning some error codes ** Modify error output */
#include "includes.h"
void RunCmd(CONST_STRPTR Name,struct List *Out,struct Gadget *Gad,struct Window *Win) { BOOL done = FALSE; BPTR InPipe, OutPipe; LONG num; STRPTR Buffer; struct Node *node; struct FReadLineData *frld;
if((OutPipe = IDOS->Open("PIPE:CmdOut", MODE_NEWFILE))) { if (IDOS->SystemTags(Name, SYS_Input, NULL, SYS_Output, OutPipe, SYS_Error, OutPipe, SYS_Asynch, TRUE, TAG_END)!=-1) { if ((InPipe = IDOS->Open("PIPE:CmdOut", MODE_OLDFILE))) {
while ((done == FALSE)) { if((frld = IDOS->AllocDosObject(DOS_FREADLINEDATA,TAG_DONE))) { num = IDOS->FReadLine(InPipe,frld); if((num > 0)) { if((Buffer = IExec->AllocVec(frld->frld_LineLength,MEMF_ANY))) { IUtility->Strlcpy(Buffer,frld->frld_Line,frld->frld_LineLength); node = IListBrowser->AllocListBrowserNode(1, LBNCA_CopyText, TRUE, LBNCA_Text,Buffer, TAG_DONE); if(node) { IIntuition->SetGadgetAttrs(Gad,Win,NULL, LISTBROWSER_Labels, ~0, TAG_DONE); IExec->AddTail(Out,node); IIntuition->SetGadgetAttrs(Gad,Win,NULL, LISTBROWSER_Labels, Out, LISTBROWSER_MakeVisible,node, TAG_DONE); } IExec->FreeVec(Buffer); } } IDOS->FreeDosObject(DOS_FREADLINEDATA,frld); if((num Close(InPipe); } else IDOS->Printf("RunCmd::Failed to open input\n"); } else IDOS->Printf("RunCmd::Failed to load command\n"); } else IDOS->Printf("RunCmd::Failed to open output\n"); }
Last edited by Ami603 on 16-Jul-2012 at 08:28 PM.
_________________ Cuida tus piedras gordas.
A1200/030 32Mb A4000D A1-X1000. |
|
Status: Offline |
|
|
NutsAboutAmiga
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 16-Jul-2012 18:52:32
| | [ #3 ] |
|
|
|
Elite Member |
Joined: 9-Jun-2004 Posts: 12931
From: Norway | | |
|
| |
Status: Offline |
|
|
Ami603
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 16-Jul-2012 19:27:28
| | [ #4 ] |
|
|
|
Cult Member |
Joined: 7-Mar-2003 Posts: 580
From: Valencia,Spain 8-) | | |
|
| @NutsAboutAmiga
Care to show the syntax? thank you. _________________ Cuida tus piedras gordas.
A1200/030 32Mb A4000D A1-X1000. |
|
Status: Offline |
|
|
broadblues
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 16-Jul-2012 20:07:55
| | [ #5 ] |
|
|
|
Amiga Developer Team |
Joined: 20-Jul-2004 Posts: 4447
From: Portsmouth England | | |
|
| |
Status: Offline |
|
|
Ami603
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 16-Jul-2012 20:28:39
| | [ #6 ] |
|
|
|
Cult Member |
Joined: 7-Mar-2003 Posts: 580
From: Valencia,Spain 8-) | | |
|
| @broadblues
Thank you very much. _________________ Cuida tus piedras gordas.
A1200/030 32Mb A4000D A1-X1000. |
|
Status: Offline |
|
|
AmiDARK
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 16-Jul-2012 20:40:13
| | [ #7 ] |
|
|
|
Regular Member |
Joined: 28-Mar-2007 Posts: 469
From: South France | | |
|
| Thank you for the answer(s) :)
I will check all this.
Regards, AmiDARK |
|
Status: Offline |
|
|
Ami603
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 16-Jul-2012 21:45:56
| | [ #8 ] |
|
|
|
Cult Member |
Joined: 7-Mar-2003 Posts: 580
From: Valencia,Spain 8-) | | |
|
| @AmiDARK
As for FileInfoBlock, have a look at IDOS->ExamineObjectTags()
i think it will be more future-proof than FIB stuff.
_________________ Cuida tus piedras gordas.
A1200/030 32Mb A4000D A1-X1000. |
|
Status: Offline |
|
|
itix
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 7:23:38
| | [ #9 ] |
|
|
|
Elite Member |
Joined: 22-Dec-2004 Posts: 3398
From: Freedom world | | |
|
| @AmiDARK
It is easy:
struct FileInfoBlock fib; BPTR lock = Lock(filename, ACCESS_READ);
if (lock) { Examine(lock, &fib); UnLock(lock); }
That is it. On PowerPC stack is always long word aligned and you are not forced to use AllocDosObject() or AllocMem().
If coding for AmigaOS/68k you must allocate long word aligned FIB.
Last edited by itix on 17-Jul-2012 at 07:24 AM.
_________________ Amiga Developer Amiga 500, Efika, Mac Mini and PowerBook |
|
Status: Offline |
|
|
OldFart
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 7:51:21
| | [ #10 ] |
|
|
|
Elite Member |
Joined: 12-Sep-2004 Posts: 3066
From: Stad; en d'r is moar ain stad en da's Stad. Makkelk zat! | | |
|
| @AmiDARK
In OS4Depot you might find a tutorial (from me) about some DOS functions, called DosTutorials.lha. Example 2 and 3 make use of the ExamineObjectTags() function. Maybe it is of interest to you.
OldFart _________________ Life is a waste of time. Time is a waste of life. Get wasted all the time and you'll have the time of your life! |
|
Status: Offline |
|
|
OldFart
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 7:53:24
| | [ #11 ] |
|
|
|
Elite Member |
Joined: 12-Sep-2004 Posts: 3066
From: Stad; en d'r is moar ain stad en da's Stad. Makkelk zat! | | |
|
| @itix
In OS4 the use of Examine() is deprecated in favour of ExamineDosObject(). Quote:
Examine -- Examine a directory or file associated with a lock ( DEPRECATED - use ExamineObject() from V52+ ) |
OldFart
EDIT: Corrected sloppy spelling as 'deprecated' has an 'e' and not a 'i' in 5th position...Last edited by OldFart on 17-Jul-2012 at 07:54 AM.
_________________ Life is a waste of time. Time is a waste of life. Get wasted all the time and you'll have the time of your life! |
|
Status: Offline |
|
|
itix
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 9:03:36
| | [ #12 ] |
|
|
|
Elite Member |
Joined: 22-Dec-2004 Posts: 3398
From: Freedom world | | |
|
| @OldFart
In MorphOS Examine() is still valid and there is even Examine64() variant to get more information from a lock. _________________ Amiga Developer Amiga 500, Efika, Mac Mini and PowerBook |
|
Status: Offline |
|
|
Xenic
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 14:52:25
| | [ #13 ] |
|
|
|
Super Member |
Joined: 2-Feb-2004 Posts: 1246
From: Pennsylvania, USA | | |
|
| @Ami603 Quote:
if((OutPipe = IDOS->Open("PIPE:CmdOut", MODE_NEWFILE))) |
Maybe it's there but I don't see "OutPipe" being closed anywhere in your code before it exits.
_________________ X1000 with 2GB memory & OS4.1FE |
|
Status: Offline |
|
|
Xenic
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 15:06:06
| | [ #14 ] |
|
|
|
Super Member |
Joined: 2-Feb-2004 Posts: 1246
From: Pennsylvania, USA | | |
|
| @AmiDARK Ami603's IDOS->SystemTags() example looks O.K. except I would use something like:
SYS_Input, Open("nil:", MODE_NEWFILE),
for the Input filehandle. In async mode the i/o filehandles will be closed when the process ends and I don't know if defining SYS_Input as NULL will prevent AmigaDOS from closing the parent process input filehandle. I've never found any specific mention of supplying NULL as a filehandle in the documentation so I play it safe and supply a filehandle to NIL: for async processes.
_________________ X1000 with 2GB memory & OS4.1FE |
|
Status: Offline |
|
|
Hypex
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 15:11:07
| | [ #15 ] |
|
|
|
Elite Member |
Joined: 6-May-2007 Posts: 11329
From: Greensborough, Australia | | |
|
| @itix
The stack may be aligned but using it for system structures is not the proper way of doing it. AllocDosObject() is. Which also avoids relying on the hardware for any such features. |
|
Status: Offline |
|
|
Hypex
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 15:15:40
| | [ #16 ] |
|
|
|
Elite Member |
Joined: 6-May-2007 Posts: 11329
From: Greensborough, Australia | | |
|
| @OldFart
They don't want us using using functions like CreateMsgPort() wither. But I don't see why, it is a clean function. After all, I've seen it approved to use input.device still when commodiies.library should do the job but somehow can't. Using input.device goes back to the real Amiga 1.3 days. So I see no problem using an "old" function that does the job and is future proof. |
|
Status: Offline |
|
|
itix
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 15:27:48
| | [ #17 ] |
|
|
|
Elite Member |
Joined: 22-Dec-2004 Posts: 3398
From: Freedom world | | |
|
| @Hypex
AmigaOS has no restrictions on using stack space to store data (like neither have MorphOS or AROS).
Consider following example:
TEXT buf[500]; struct FileInfoBlock *fib = (APTR)&buf;
stccpy(buf, "PROGDIR:", sizeof(buf)); AddPart(buf, "Image.png", sizeof(buf)); // Buf is passed to dos.library fh = Open(buf, MODE_OLDFILE); // Again buf is passed to dos.library ExamineFH(fh, &fib); // Yet again same buf is passed to dos.library Close(fh);
FileInfoBlock is not a system structure. It is just pointer to a buffer used to retrieve data.
If you still insist FIB must be allocated using AllocDosObject() (why?) you should also use system routines to allocate space for names passed to Lock(), Open() etc.
As you see this idea to use AllocDosObject() to allocate FIB is insane idea. For other structures like ExAllControl it is needed because structure must be initialized properly before passed to dos.library.
Only real reason to use AllocDosObject() is long word alignment requirement in AmigaOS (but not in MorphOS or AROS). In old days it was source of many bugs because developers didnt know about long word alignment restrictions resulting in random behaviour/memory trashing.
CreateMsgPort
Btw following code is sometimes used:
void CreateQPort(struct MsgPort *port) { port->mp_Node.ln_Type = NT_MSGPORT; port->mp_Flags = PA_SIGNAL; if ((BYTE) (port->mp_SigBit = AllocSignal(-1)) == -1) { port->mp_SigBit = SIGB_SINGLE; SetSignal(0, SIGF_SINGLE); } port->mp_SigTask = FindTask(NULL); // SysBase->ThisTask would be faster here NEWLIST(&port->mp_MsgList); }
void DeleteQPort(struct MsgPort *port) { if (port->mp_SigBit == SIGB_SINGLE) { SetSignal(0, SIGF_SINGLE); } else { FreeSignal(port->mp_SigBit); } }
In AmigaOS it is neat because it saves from memory fragmentation and you dont have to test if memory allocation failed.
Last edited by itix on 17-Jul-2012 at 03:35 PM. Last edited by itix on 17-Jul-2012 at 03:32 PM. Last edited by itix on 17-Jul-2012 at 03:30 PM.
_________________ Amiga Developer Amiga 500, Efika, Mac Mini and PowerBook |
|
Status: Offline |
|
|
NutsAboutAmiga
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 15:32:08
| | [ #18 ] |
|
|
|
Elite Member |
Joined: 9-Jun-2004 Posts: 12931
From: Norway | | |
|
| |
Status: Offline |
|
|
NutsAboutAmiga
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 15:36:58
| | [ #19 ] |
|
|
|
Elite Member |
Joined: 9-Jun-2004 Posts: 12931
From: Norway | | |
|
| |
Status: Offline |
|
|
itix
| |
Re: Dos.library SystemTags & FileInfoBlock Posted on 17-Jul-2012 15:54:52
| | [ #20 ] |
|
|
|
Elite Member |
Joined: 22-Dec-2004 Posts: 3398
From: Freedom world | | |
|
| @NutsAboutAmiga
Examine64() will report correct size. But he was not asking about file size but file date.
And really, this DOS64 support on Amiga is most of time unused. There are only few applications requiring large file support.
Last edited by itix on 17-Jul-2012 at 03:57 PM.
_________________ Amiga Developer Amiga 500, Efika, Mac Mini and PowerBook |
|
Status: Offline |
|
|