Welcome, Guest. Please login or register.

Author Topic: Executing c command in c  (Read 2801 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show only replies by foleyjo
Executing c command in c
« on: May 07, 2017, 07:19:44 PM »
Hi
Can anybody explain how in Amiga C I can use Execute() but change the directory first. I thought it would be simply Execute("cd path",bptr,bptr); but that is ignored
 

Offline D00kie

  • Jr. Member
  • **
  • Join Date: Apr 2003
  • Posts: 68
    • Show only replies by D00kie
    • http://www.tigger1.demon.co.uk
Re: Executing c command in c
« Reply #1 on: May 07, 2017, 08:58:30 PM »
I think you want Dos.library/SetCliCurrentDirName. http://wiki.amigaos.net/amiga/autodocs/dos.doc.txt
Provided the program is run through the shell, that should set the CLI environment to use the directory you want and the new process should pick it up. It would with System() rather than Execute(), anyway.
Haiku is a joke
What a waste of freaking time
I have eggs to suck
 

guest11527

  • Guest
Re: Executing c command in c
« Reply #2 on: May 07, 2017, 09:06:41 PM »
Quote from: foleyjo;825470
Can anybody explain how in Amiga C I can use Execute() but change the directory first.
In general, I would recommend System() or rather SystemTagList() to execute a command as it is considerably more flexible than Execute().

Anyhow, in general, the current directory of the process is inherited to the shell launched through Execute(), so you could simply newlock=Lock(...) the desired target directory, then call oldlock=CurrentDir(newlock), then Execute(), then UnLock(CurrentDir(oldlock));

Alternatively, you can also set the current directory through the NP_CurrentDir tag of the System() call, which is a bit more convenient.
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show only replies by foleyjo
Re: Executing c command in c
« Reply #3 on: May 07, 2017, 11:31:58 PM »
Thanks.

I've looked for information on the SystemTagList() but can't find much that I understand.
I've tried to use it but I'm just getting a crash.
Heres what I've got with an explanation of why I think it's supposed to be like this. Though probably doing it completely wrong.
Code: [Select]

   struct TagItem * tags;            /*Setup a pointer to the tags that will be used */
   tags = AllocateTagItems(1);    /*Create empty tag*/
   tags[0].ti_Tag = NP_CurrentDir;  /*Set Tag as NP_CurrentDir */
   tags[0].ti_Data = (ULONG)"work:/docs/";  /*Set the directory path prefixed with (ULONG) because ti_Data only accepts ULONG %/
   SystemTagList("dir",tags);  /*Runs the command dir in tags[0] (not the command I'm actually running but used in this instance to shorten code */
   FreeTagItems(tags);   /*Clear tags from memory*/


Sorry if this is all actually simple stuff. A lot of the sites I'm finding for tutorials are either dead sites, not in depth enough to explain things properly or not in English and when I translate the text using google translate the code gets messed up and no longer works.
 

guest11527

  • Guest
Re: Executing c command in c
« Reply #4 on: May 08, 2017, 08:52:40 AM »
Quote from: foleyjo;825483
Thanks.

I've looked for information on the SystemTagList() but can't find much that I understand.
I've tried to use it but I'm just getting a crash.
Tags can be placed on the stack, or even in the arguments of the "tag-based" function System(), there is no need to allocate them manually. Tag-lists also need to be terminated by TAG_DONE, or you crash. Last but not least, NP_CurrentDir takes a Lock as argument, not a string.

Code: [Select]
LONG result = -1;
BPTR lock = Lock("my directory",SHARED_ACCESS);

if (lock) {
result = System("my command",NP_CurrentDir,lock,TAG_DONE);
UnLock(lock);
}
Approximately, minus typos.
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show only replies by foleyjo
Re: Executing c command in c
« Reply #5 on: May 08, 2017, 09:42:35 AM »
Thanks again Thomas.
Didn't find anything like that when I was trying to see how to use it. You have been a big help.
 

Offline kolla

Re: Executing c command in c
« Reply #6 on: May 08, 2017, 12:42:04 PM »
When was the last time someone wrote a book on C programming for Amiga? :)
B5D6A1D019D5D45BCC56F4782AC220D8B3E2A6CC
---
A3000/060CSPPC+CVPPC/128MB + 256MB BigRAM/Deneb USB
A4000/CS060/Mediator4000Di/Voodoo5/128MB
A1200/Blz1260/IndyAGA/192MB
A1200/Blz1260/64MB
A1200/Blz1230III/32MB
A1200/ACA1221
A600/V600v2/Subway USB
A600/Apollo630/32MB
A600/A6095
CD32/SX32/32MB/Plipbox
CD32/TF328
A500/V500v2
A500/MTec520
CDTV
MiSTer, MiST, FleaFPGAs and original Minimig
Peg1, SAM440 and Mac minis with MorphOS
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show only replies by foleyjo
Re: Executing c command in c
« Reply #7 on: May 08, 2017, 08:45:24 PM »
Thomas I tried using the method you posted but it didn't work.
It gave me an error on the lock bit of system()
So I mixed what I already had by using a lock and not a string and it worked.
Thank you for pointing me in the right direction.
 

guest11527

  • Guest
Re: Executing c command in c
« Reply #8 on: May 08, 2017, 09:49:53 PM »
Quote from: foleyjo;825521
Thomas I tried using the method you posted but it didn't work.

This type of thing happens if you don't have the system in front of you. That's why I said "minus typos".
Code: [Select]
#include <dos/dos.h>
#include <dos/dostags.h>
#include <proto/dos.h>

int main(int argc,char **argv)
{
  BPTR lock = Lock(&quot;foo&quot;,SHARED_LOCK);

  if (lock) {
    LONG res = SystemTags(&quot;foo&quot;,NP_CurrentDir,lock,TAG_DONE);
    UnLock(lock);
  }

  return 0;
}
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show only replies by foleyjo
Re: Executing c command in c
« Reply #9 on: May 09, 2017, 01:54:01 PM »
Yeah that's how I had it except I didn't use SHARED_LOCK . My documentation only talked about read_access and write_access so I used read_access.

I'm not sure I tried SystemTags(). I tried System() and SystemTagList() .

I notice your code uses (int argc,char **argv) . Is this important as I haven't included them?
 

guest11527

  • Guest
Re: Executing c command in c
« Reply #10 on: May 09, 2017, 06:02:09 PM »
Quote from: foleyjo;825557
I notice your code uses (int argc,char **argv) . Is this important as I haven't included them?
ANSI-C knows two signatures for main:"int main(void)" and "int main(int argc,char **argv)", where the latter is equivalent to "int main(int argc,char *argv[])" due to the way how C handles arrays.

If your compiler supports any other signature, then that's an extension. "int main()" for example does not declare parameters, which was acceptable form in K&R C which your C compiler may still support. It is not ANSI-C.
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show only replies by foleyjo
Re: Executing c command in c
« Reply #11 on: May 10, 2017, 09:22:41 AM »
Good to know thanks.

I'm starting to think I might give up or change language as I'm just not finding anything that I is useful to help me understand what to do. Except for the help here which was great.

For example I'm now trying to open a jpg picture in mui.
I found how to play a sound in mui but nothing about pictures.
I found one tutorial that says how to create a datatype object but nothing on how to set that object as a picture or how to display said picture in a window.
I looked at mui_image. I think I have to use the OLD_Image attribute because I didn't see anywhere else to set the image.

I've managed to create a listview with a list that is loaded from a file and when I double click an item in the list it runs an event (Currently shows me the contents of the directory of where the file is stored in the console). I tried to find information on how to do something for a single click .
The only thing I can find that seems to make sense is select_change (https://muidev.de/wiki/Documentation/API/MUI_Listview#MUIA_Listview_SelectChange)
but this only works if I hold the mouse button down and drag it up and down the list.

So I'm thinking it's either keep asking lots of questions here or just give up and as I don't want to annoy people with my questions I'm leaning towards the give up. :(
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show only replies by foleyjo
Re: Executing c command in c
« Reply #12 on: May 10, 2017, 04:38:19 PM »
With regards to the image I'm trying to load
Do I create an area as a child of the window and then DTpic as a child of the area with MUIA_Dtpic_Name holding the filename (pointer to the string) for the image I want to open?

Will the datatypes library then work out what type of picture it is (iff,png,jpg,etc) or does that need to be specified somewhere else?


Will the list selection on a single click be something like
Code: [Select]
DoMethod(List_Name, MUIM_List_Select, MUIV_List_Select_Active, MUIV_List_Select_Ask, TRUE, Action_Name);  (Where list_name is the name of the list and Action_Name is the name of the called function)
« Last Edit: May 10, 2017, 04:53:00 PM by foleyjo »
 

Offline nicholas

Re: Executing c command in c
« Reply #13 on: May 10, 2017, 06:04:56 PM »
Quote from: foleyjo;825604
Good to know thanks.

I'm starting to think I might give up or change language as I'm just not finding anything that I is useful to help me understand what to do. Except for the help here which was great.

For example I'm now trying to open a jpg picture in mui.
I found how to play a sound in mui but nothing about pictures.
I found one tutorial that says how to create a datatype object but nothing on how to set that object as a picture or how to display said picture in a window.
I looked at mui_image. I think I have to use the OLD_Image attribute because I didn't see anywhere else to set the image.

I've managed to create a listview with a list that is loaded from a file and when I double click an item in the list it runs an event (Currently shows me the contents of the directory of where the file is stored in the console). I tried to find information on how to do something for a single click .
The only thing I can find that seems to make sense is select_change (https://muidev.de/wiki/Documentation/API/MUI_Listview#MUIA_Listview_SelectChange)
but this only works if I hold the mouse button down and drag it up and down the list.

So I'm thinking it's either keep asking lots of questions here or just give up and as I don't want to annoy people with my questions I'm leaning towards the give up. :(


This is an old but useful guide to developing in C for the Amiga.

http://library.morph.zone/Magic_User_Interface_Programming

A nice MUI tutorial

http://library.morph.zone/Magic_User_Interface_Programming

If you use IRC the #mui channel on Freenode is a good place to ask questions.
“Een rezhim-i eshghalgar-i Quds bayad az sahneh-i ruzgar mahv shaved.” - Imam Ayatollah Sayyed  Ruhollah Khomeini
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show only replies by foleyjo
Re: Executing c command in c
« Reply #14 on: May 10, 2017, 09:45:26 PM »
Thanks for the advice nicholas though were the 2 links supposed to be to the same site.
I did find that site but I was looking through an example I downloaded from it but the comments were not in English.

I managed to get an image loaded using Dtpic.
It wasn't working earlier but I think I was using an old version of mui as I downloaded the latest from muidev.de and Dtpic worked.

There's also some demos in this version that I didn't have which seem to do things that I need so I can try and learn the code.