I have a program which I wish to modify. It used to be run from the command line, but now I wish to change this so it can be used as a function.
The program has complex argument processing so I want to pass my paramters to as if it were being called by the OS as a program.
I have tried to... (2 Replies)
I searched on the forums. No advises.
I am using a previous source code. I changed the main function main(int argc, char **argv) in a function misc(int argc, char **argv). How do you use the argc and argv parameters? This is how I am calling the function :
char param;
strcat(param,"wgrib ");... (4 Replies)
I have a script that asks a bunch of questions using the following method for input:
print "Name:";
while(<>){
chomp;
$name=$_;
}
So for example, if the questions asked for name, age, & color (in that order)... I want to be able to easily convert $ARGV into the input expected by... (2 Replies)
Hi C experts,
I have the following code for adding command line option for a program
int main (argc, argv)
int argc;
char *argv;
{
char *mem_type; //memory type
char *name; //name of the memory
int addr; //address bits
int data; ... (5 Replies)
this is in one of my scripts...
if ($#argv == 0) then
echo 'blah bla'
exit 0
endif
I want it to be something like this...
if ($#argv == 0 OR $argv >=3)
echo 'blah bla'
exit 0
endif
so when the arguments are none, or greater than three I want this "if then" to take over. how? I... (5 Replies)
Hello all,
Had a quick question:
In a typical csh script should inputting via stdin (i.e. set i = $< ) increase the value of $#argv ?
echo enter an value:
set val= "$<"
if($#argv == 0) then
echo No args
else
echo The arg is $argv
so if a value is inputted #argv... (1 Reply)
I'm working on my own pow function and I need to make a copy of *argv but
I think that I am having trouble with the size of *argv and the size of any array that I
make. The code below isn't working for me. and I want to accept any number no
matter the size with pow -f 2 2. I was working out... (16 Replies)
All of my machines (various open source derivatives on x86 and amd64) store argv above the stack (at a higher memory address). I am curious to learn if any systems store argv below the stack (at a lower memory address).
I am particularly interested in proprietary Unices, such as Solaris, HP-UX,... (9 Replies)
So i am trying to read in file
readFile <GivenFile> modFile
looking for a regular file under the directories in the GivenFile and print them out is my over all goal.
basically I am looking for anything that looks like a directory in the given file and printing it out.
Since I am trying to do... (2 Replies)
Discussion started by: squidGreen
2 Replies
LEARN ABOUT PLAN9
arg
ARG(2) System Calls Manual ARG(2)NAME
ARGBEGIN, ARGEND, ARGC, ARGF, arginit, argopt - process option letters from argv
SYNOPSIS
#include <u.h>
#include <libc.h>
ARGBEGIN {
char *ARGF();
Rune ARGC();
} ARGEND
extern char *argv0;
/* Alef only */
Arg *arginit(int argc, byte **argv);
Rune argopt(Arg *arg);
byte *argf(Arg *arg);
DESCRIPTION
These macros assume the names argc and argv are in scope; see exec(2). ARGBEGIN and ARGEND surround code for processing program options.
The code should be the cases of a C switch on option characters; it is executed once for each option character. Options end after an argu-
ment --, before an argument -, or before an argument that doesn't begin with -.
ARGC() returns the current option character.
ARGF() returns the current option argument: a pointer to the rest of the option string if not empty, or the next argument in argv if any,
or 0. ARGF must be called just once for each option that takes an argument.
After ARGBEGIN, argv0 is a copy of argv[0] (conventionally the name of the program).
After ARGEND, argv points at a zero-terminated list of the remaining argc arguments.
Alef
The Alef argument processing routines are unrelated. Instead, an aggr called Arg is initialized by a call to arginit. Successive calls to
argopt return successive option characters, or zero at the end of the options. After a call to argopt, argf will return any argument
string associated with the option.
EXAMPLES
This C program can take option b and option f, which requires an argument.
#include <u.h>
#include <libc.h>
void
main(int argc, char *argv[])
{
char *f;
print("%s", argv[0]);
ARGBEGIN {
case 'b':
print(" -b");
break;
case 'f':
print(" -f(%s)", (f=ARGF())? f: "no arg");
break;
default:
print(" badflag('%c')", ARGC());
} ARGEND
print(" %d args:", argc);
while(*argv)
print(" '%s'", *argv++);
print("
");
exits(0);
}
Here is the output for the run prog -bffile1 -r -f file2 arg1 arg2
prog -b -f(file1) badflag('r') -f(file2) 2 args: 'arg1' 'arg2'
This Alef program accepts options b and, with an attached file name, f.
#include <alef.h>
void
main(int argc, byte **argv)
{
int a, ac, bflag;
byte *file;
Arg *arg;
arg = arginit(argc, argv);
while(ac = argopt(arg)) switch(ac){
case 'b':
bflag = 1;
break;
case 'f':
file = argf(arg);
break;
}
for(a=0; a<arg->ac; a++)
print("argument %s
", arg->av[a]);
}
SOURCE
/sys/include/libc.h
ARG(2)