>> >>> Vivek S <[email protected]> schrieb am 05.08.2011 um 20:19 in 
> Nachricht
<[email protected] 
> .com>:
I'd do the line wrapping in the code, not in the texts (terminal sizes 
> may
> vary anyway).
> 
> How do you do line wrapping in code ?

Hi!

Wow would you do line-wrapping in non-code? ;-)
What I was thinkingg of was some thing like "length = atoi(getenv("COLUMNS"))" 
to get the length of a line, and then maybe get the next word to be output and 
check if that would exceed the length. If so add a newline before outputting 
the next word.

Would you consider that to be a very obscure algorithm?

Regards,
Ulrich


> 
> On Wed, Aug 3, 2011 at 11:39 AM, Ulrich Windl <
> [email protected]> wrote:
> 
> > Hi!
> >
> > The idea is good, but I'd use a different implementation, trying to put
> > most text into one data structure, and then select the correct text. 
> Roughly
> > like
> >
> > struct help {
> >  const char *option;
> >  const char *explanation;
> > };
> >
> > struct help the_help[] = {
> >  {"p", "Portal in ip:port format. If only ip address is specified then the
> > value 3260 is assumed for the port."},
> >  {"n", "Name of the field to use in the update operation."},
> >  ...
> > };
> >
> > I'd do the line wrapping in the code, not in the texts (terminal sizes may
> > vary anyway). I guess you get thge idea how to pick the correct help text
> > from the array.
> >
> > Regards,
> > Ulrich
> >
> >
> >
> > >>> Vivek S <[email protected]> schrieb am 22.07.2011 um 19:09 in
> > Nachricht
> > <8069269.2450.1311354555863.JavaMail.geo-discussion-forums@prcn22>:
> > > Changed the way iscsiadm displays usage help about its commands. Rather
> > than
> > > simply displaying each possible mode along with its options on a single
> > > line,
> > > the user can now ask help for each mode separately which describes the
> > > various options and also provides some examples.
> > >
> > > Signed-off-by: Vivek Subbarao <[email protected]>
> > > --- open-iscsi/usr/iscsiadm.c    2011-07-09 23:27:17.963424339 +0530
> > > +++ open-iscsi-test/usr/iscsiadm.c    2011-07-22 22:19:16.452456354 +0530
> > > @@ -103,24 +103,201 @@ static struct option const long_options[
> > >  };
> > >  static char *short_options = "RlDVhm:p:P:T:H:I:U:k:L:d:r:n:v:o:sSt:u";
> > >
> > > -static void usage(int status)
> > > -{
> > > -    if (status != 0)
> > > -        fprintf(stderr, "Try `%s --help' for more information.\n",
> > > -            program_name);
> > > -    else {
> > > -        printf("\
> > > -iscsiadm -m discoverydb [ -hV ] [ -d debug_level ] [-P printlevel] [ -t
> > > type -p ip:port -I ifaceN ... [ -Dl ] ] | [ [ -p ip:port -t type] \
> > > -[ -o operation ] [ -n name ] [ -v value ] [ -lD ] ] \n\
> > > -iscsiadm -m discovery [ -hV ] [ -d debug_level ] [-P printlevel] [ -t
> > type
> > > -p ip:port -I ifaceN ... [ -l ] ] | [ [ -p ip:port ] [ -l | -D ] ] \n\
> > > -iiscsiadm -m node [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -L
> > > all,manual,automatic ] [ -U all,manual,automatic ] [ -S ] [ [ -T
> > targetname
> > > -p ip:port -I ifaceN ] [ -l | -u | -R | -s] ] \
> > > -[ [ -o  operation  ] [ -n name ] [ -v value ] ]\n\
> > > -iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P  printlevel] [ -r
> > > sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v
> > > value ] ]\n\
> > > -iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I
> > > ifacename ] [ [ -o  operation  ] [ -n name ] [ -v value ] ]\n\
> > > -iscsiadm -m fw [ -l ]\n\
> > > -iscsiadm -m host [ -P printlevel ] [ -H hostno ]\n\
> > > -iscsiadm -k priority\n");
> > > +/*
> > > + * Global defines for all iscsiadm command line options.
> > > + */
> > > +#define CMD_LINE_OPTION_MODE        (1<<0)
> > > +#define CMD_LINE_OPTION_PORTAL        (1<<1)
> > > +#define CMD_LINE_OPTION_TGTNAME        (1<<2)
> > > +#define CMD_LINE_OPTION_IFACE        (1<<3)
> > > +#define CMD_LINE_OPTION_OP        (1<<4)
> > > +#define CMD_LINE_OPTION_TYPE        (1<<5)
> > > +#define CMD_LINE_OPTION_NAME        (1<<6)
> > > +#define CMD_LINE_OPTION_VALUE        (1<<7)
> > > +#define CMD_LINE_OPTION_HOST        (1<<8)
> > > +#define CMD_LINE_OPTION_SID        (1<<9)
> > > +#define CMD_LINE_OPTION_RESCAN        (1<<10)
> > > +#define CMD_LINE_OPTION_PRINT        (1<<11)
> > > +#define CMD_LINE_OPTION_DSCVR        (1<<12)
> > > +#define CMD_LINE_OPTION_LOGIN        (1<<13)
> > > +#define CMD_LINE_OPTION_LOGINALL    (1<<14)
> > > +#define CMD_LINE_OPTION_LOGOUT        (1<<15)
> > > +#define CMD_LINE_OPTION_LOGOUTALL    (1<<16)
> > > +#define CMD_LINE_OPTION_STATS        (1<<17)
> > > +#define CMD_LINE_OPTION_KILLISCSID    (1<<18)
> > > +#define CMD_LINE_OPTION_DEBUG        (1<<19)
> > > +#define CMD_LINE_OPTION_SHOW        (1<<20)
> > > +#define CMD_LINE_OPTION_VERSION        (1<<21)
> > > +#define CMD_LINE_OPTION_HELP        (1<<22)
> > > +
> > > +static void print_option_help(unsigned int options)
> > > +{
> > > +    printf("Options\tDescription\n");
> > > +    printf("-------\t-----------\n");
> > > +
> > > +        if (options & CMD_LINE_OPTION_PORTAL)
> > > +        printf("-p\tPortal in ip:port format. If only ip address is
> > > specified\n\tthen the value 3260 is assumed for the port.\n");
> > > +        if (options & CMD_LINE_OPTION_TGTNAME)
> > > +        printf("-T\tIqn name of the target.\n");
> > > +        if (options & CMD_LINE_OPTION_IFACE)
> > > +        printf("-I\tInterface to use for the operation. This is the name
> > of
> > > file\n\tin /etc/iscsi/ifaces/ directory. Multiple interfaces can be
> > > specified.\n");
> > > +        if (options & CMD_LINE_OPTION_OP)
> > > +        printf("-o\tOne of the new, delete, update, show or
> > nonpersistent
> > > operations.\n");
> > > +        if (options & CMD_LINE_OPTION_TYPE)
> > > +            printf("-t\tType of discovery. Sendtargets, slp, isns or
> > > fw.\n");
> > > +    if (options & CMD_LINE_OPTION_NAME)
> > > +        printf("-n\tName of the field to use in the update
> > operation.\n");
> > > +        if (options & CMD_LINE_OPTION_VALUE)
> > > +        printf("-v\tValue to use for the specified field in the update
> > > operation.\n");
> > > +        if (options & CMD_LINE_OPTION_HOST)
> > > +        printf("-H\tSCSI host to use for the operation.\n");
> > > +        if (options & CMD_LINE_OPTION_SID)
> > > +        printf("-r\tSession ID to use. This is either a positive integer
> > or
> > > a sysfs\n\tpath like
> > /sys/devices/platform/hostH/sessionS/targetH:B:I\n");
> > > +        if (options & CMD_LINE_OPTION_RESCAN)
> > > +        printf("-R\tRescan all sessions if no SID is specified, else
> > scan
> > > only that session.\n");
> > > +        if (options & CMD_LINE_OPTION_PRINT)
> > > +            printf("-P\tLevel of information output. 0 to display a
> > single
> > > line\n\tand 1 to display detailed information in tree format.\n");
> > > +        if (options & CMD_LINE_OPTION_DSCVR)
> > > +        printf("-D\tDiscover targets.\n");
> > > +        if (options & CMD_LINE_OPTION_LOGIN)
> > > +        printf("-l\tLogin to the discovered or specified target.\n");
> > > +        if (options & CMD_LINE_OPTION_LOGINALL)
> > > +        printf("-L\tLogin to all sessions with the specified node or
> > > connection startup value\n\tor all session if all is passed.\n");
> > > +        if (options & CMD_LINE_OPTION_LOGOUT)
> > > +        printf("-u\tLogout of the specified node or session.\n");
> > > +        if (options & CMD_LINE_OPTION_LOGOUTALL)
> > > +        printf("-U\tLogout of all sessions with the specified node or
> > > connection startup value\n\tor all sessions if all is passed.\n");
> > > +        if (options & CMD_LINE_OPTION_STATS)
> > > +        printf("-s\tDisplay session statistics\n");
> > > +        if (options & CMD_LINE_OPTION_DEBUG)
> > > +        printf("-d\tPrint debugging information. Valid values are 0 to
> > > 8.\n");
> > > +        if (options & CMD_LINE_OPTION_KILLISCSID)
> > > +        printf("-k\tKill iscsid.\n");
> > > +        if (options & CMD_LINE_OPTION_SHOW)
> > > +        printf("-S\tShow masked values during information display.\n");
> > > +        if (options & CMD_LINE_OPTION_HELP)
> > > +        printf("-h\tDisplay this help.\n");
> > > +        if (options & CMD_LINE_OPTION_VERSION)
> > > +        printf("-v\tDisplay iscsiadm version.\n");
> > > +}
> > > +
> > > +
> > > +static void usage(int status, int mode)
> > > +{
> > > +    unsigned int options = 0;
> > > +
> > > +    if ((status != 0) || (mode == -1))
> > > +    {
> > > +        printf("\nIscsiadm supports the following modes. The user should
> > > enter atleast one of them.\nFor help about a particular mode, enter
> > > 'iscsiadm \
> > > +-m mode -h'.\n\n");
> > > +        printf("discoverydb\ndiscovery
> > > [DEPRECATED]\nnode\nsession\niface\nfw\nhost\n\n");
> > > +        printf("NOTE: To kill iscsid, use 'iscsiadm -k priority' with a
> > > priority of 0.\n\n");
> > > +    }
> > > +    else
> > > +    {
> > > +        printf("\n");
> > > +        switch (mode)
> > > +        {
> > > +            case MODE_DISCOVERYDB:
> > > +                printf("iscsiadm -m discoverydb [options...]\n\n");
> > > +                options = CMD_LINE_OPTION_PORTAL | CMD_LINE_OPTION_IFACE
> > |
> > > CMD_LINE_OPTION_OP \
> > > +                      | CMD_LINE_OPTION_TYPE | CMD_LINE_OPTION_NAME |
> > > CMD_LINE_OPTION_VALUE \
> > > +                      | CMD_LINE_OPTION_PRINT | CMD_LINE_OPTION_DSCVR |
> > > CMD_LINE_OPTION_LOGIN \
> > > +                      | CMD_LINE_OPTION_DEBUG | CMD_LINE_OPTION_HELP;
> > > +                print_option_help(options);
> > > +                printf("\nExample:\n\tTo discover a target\n");
> > > +                printf("\t\tiscsiadm -m discoverydb -t st -p
> > > 192.168.1.2:3260 -D\n");
> > > +                printf("\tTo discover and login\n");
> > > +                printf("\t\tiscsiadm -m discoverydb -t st -p
> > > 192.168.1.2:3260 -Dl\n");
> > > +                printf("\tTo specify an interface during discovery and
> > > login\n");
> > > +                printf("\t\tiscsiadm -m discoverydb -t st -p
> > > 192.168.1.2:3260 -I eth0 -Dl\n");
> > > +                printf("\tTo add or delete a record\n");
> > > +                printf("\t\tiscsiadm -m discoverydb -t st -p
> > > 192.168.1.2:3260 -o new/delete\n");
> > > +                printf("\tTo update a record\n");
> > > +                printf("\t\tiscsiadm -m discoverydb -t st -p
> > > 192.168.1.2:3260 -o update \n\t\t-n discovery.startup\
> > > +                        -v manual\n");
> > > +                printf("\tTo display records from discovery
> > database\n");
> > > +                printf("\t\tiscsiadm -m discoverydb\n\n");
> > > +                break;
> > > +
> > > +            case MODE_DISCOVERY:
> > > +                printf("iscsiadm -m discovery [options...]\n\n");
> > > +                options = CMD_LINE_OPTION_PORTAL | CMD_LINE_OPTION_IFACE
> > |
> > > CMD_LINE_OPTION_OP \
> > > +                      | CMD_LINE_OPTION_TYPE | CMD_LINE_OPTION_PRINT |
> > > CMD_LINE_OPTION_DSCVR \
> > > +                      | CMD_LINE_OPTION_LOGIN | CMD_LINE_OPTION_DEBUG |
> > > CMD_LINE_OPTION_HELP;
> > > +                print_option_help(options);
> > > +                printf("\nExample:\n\tTo discover a target\n");
> > > +                printf("\t\tiscsiadm -m discovery -t slp -p
> > > 192.168.1.1:3260 -D\n");
> > > +                printf("\tTo discover and login to a target\n");
> > > +                printf("\t\tiscsiadm -m discovery -t slp -p
> > > 192.168.1.1:3260 -Dl\n");
> > > +                printf("\tTo specify an interface\n");
> > > +                printf("\t\tiscsiadm -m discovery -t slp -p
> > > 192.168.1.1:3260 -I eth0\n\n");
> > > +                break;
> > > +
> > > +            case MODE_NODE:
> > > +                printf("iscsiadm -m node [options...]\n\n");
> > > +                options = CMD_LINE_OPTION_PORTAL | CMD_LINE_OPTION_DEBUG
> > |
> > > CMD_LINE_OPTION_PRINT \
> > > +                      | CMD_LINE_OPTION_LOGINALL |
> > > CMD_LINE_OPTION_LOGOUTALL | CMD_LINE_OPTION_SHOW \
> > > +                      | CMD_LINE_OPTION_TGTNAME | CMD_LINE_OPTION_IFACE
> > |
> > > CMD_LINE_OPTION_LOGIN \
> > > +                      | CMD_LINE_OPTION_RESCAN | CMD_LINE_OPTION_STATS |
> > > CMD_LINE_OPTION_HELP \
> > > +                      | CMD_LINE_OPTION_LOGOUT | CMD_LINE_OPTION_OP |
> > > CMD_LINE_OPTION_NAME \
> > > +                      | CMD_LINE_OPTION_VALUE;
> > > +                print_option_help(options);
> > > +                printf("\nExample:\n\tTo login to a target\n");
> > > +                printf("\t\tiscsiadm -m node -T
> > > iqn.2005-06.com.mydomain.openiscsi:test1 -p 192.168.1.2:3260 -l\n");
> > > +                printf("\tTo login to all targets with node or
> > connection
> > > startup type as manual\n");
> > > +                printf("\t\tiscsiadm -m node -L manual\n");
> > > +                printf("\tTo logout of all targets with node or
> > connection
> > > startup type as automatic\n");
> > > +                printf("\t\tiscsiadm -m node -U automatic\n");
> > > +                printf("\tTo rescan the session passing through a
> > > target\n");
> > > +                printf("\t\tiscsiadm -m node -T
> > > iqn.2005-06.com.mydomain.openiscsi.test1 -p 192.168.1.2:3260 -R\n");
> > > +                printf("\tTo display statistics about a session passing
> > > through a target\n");
> > > +                printf("\t\tiscsiadm -m node -T
> > > iqn.2005-06.com.mydomain.openiscsi:test1 -p 192.168.1.2:3260 -s\n");
> > > +                printf("\tTo add a new node record\n");
> > > +                printf("\t\tiscsiadm -m node -T
> > > iqn.2005-06.com.mydomain.openiscsi:test1 -p 192.168.1.2:3260 -o
> > new\n\n");
> > > +                break;
> > > +
> > > +            case MODE_SESSION:
> > > +                printf("iscsiadm -m session [options...]\n\n");
> > > +                options = CMD_LINE_OPTION_HELP | CMD_LINE_OPTION_DEBUG |
> > > CMD_LINE_OPTION_PRINT | CMD_LINE_OPTION_SID \
> > > +                      | CMD_LINE_OPTION_RESCAN | CMD_LINE_OPTION_LOGOUT
> > |
> > > CMD_LINE_OPTION_STATS \
> > > +                      | CMD_LINE_OPTION_OP | CMD_LINE_OPTION_NAME |
> > > CMD_LINE_OPTION_VALUE;
> > > +                print_option_help(options);
> > > +                printf("\nExample:\n\tTo logout of a session\n");
> > > +                printf("\t\tiscsiadm -m session -r 1 -u\n");
> > > +                printf("\tTo delete a session record\n");
> > > +                printf("\t\tiscsiadm -m session -r 2 -o delete\n\n");
> > > +                break;
> > > +
> > > +            case MODE_IFACE:
> > > +                printf("iscsiadm -m iface [options...]\n\n");
> > > +                options = CMD_LINE_OPTION_HELP | CMD_LINE_OPTION_DEBUG |
> > > CMD_LINE_OPTION_PRINT \
> > > +                      | CMD_LINE_OPTION_IFACE | CMD_LINE_OPTION_OP |
> > > CMD_LINE_OPTION_NAME | CMD_LINE_OPTION_VALUE;
> > > +                print_option_help(options);
> > > +                printf("\nExample:\n\tTo add a iface record\n");
> > > +                printf("\t\tiscsiadm -m iface -I eth1 -o new\n\n");
> > > +                break;
> > > +
> > > +            case MODE_FW:
> > > +                printf("iscsiadm -m fw [options...]\n\n");
> > > +                options = CMD_LINE_OPTION_LOGIN;
> > > +                print_option_help(options);
> > > +                printf("\n");
> > > +                break;
> > > +
> > > +            case MODE_HOST:
> > > +                printf("iscsiadm -m host [options...]\n\n");
> > > +                options = CMD_LINE_OPTION_PRINT | CMD_LINE_OPTION_HOST;
> > > +                print_option_help(options);
> > > +                printf("\n");
> > > +                break;
> > > +
> > > +            deafult:
> > > +                printf("Invalid mode\n\n");
> > > +        }
> > > +        printf("SEE MAN PAGE FOR MODE DETAILS\n\n");
> > >      }
> > > +
> > >      exit(status);
> > >  }
> > >
> > > @@ -370,7 +547,7 @@ logout_by_startup(char *mode)
> > >      if (!mode || !(!strcmp(mode, "automatic") || !strcmp(mode, "all") ||
> > >          !strcmp(mode,"manual"))) {
> > >          log_error("Invalid logoutall option %s.", mode);
> > > -        usage(ISCSI_ERR_INVAL);
> > > +        usage(ISCSI_ERR_INVAL, 0);
> > >          return ISCSI_ERR_INVAL;
> > >      }
> > >
> > > @@ -440,7 +617,7 @@ login_by_startup(char *mode)
> > >      if (!mode || !(!strcmp(mode, "automatic") || !strcmp(mode, "all") ||
> > >                 !strcmp(mode,"manual") || !strcmp(mode, "onboot"))) {
> > >          log_error("Invalid loginall option %s.", mode);
> > > -        usage(ISCSI_ERR_INVAL);
> > > +        usage(ISCSI_ERR_INVAL, 0);
> > >          return ISCSI_ERR_INVAL;
> > >      }
> > >
> > > @@ -2071,7 +2248,7 @@ main(int argc, char **argv)
> > >                  ISCSI_VERSION_STR);
> > >              return 0;
> > >          case 'h':
> > > -            usage(0);
> > > +            usage(0, mode);
> > >          }
> > >      }
> > >
> > > @@ -2087,7 +2264,7 @@ main(int argc, char **argv)
> > >      }
> > >
> > >      if (mode < 0)
> > > -        usage(ISCSI_ERR_INVAL);
> > > +        usage(ISCSI_ERR_INVAL, 0);
> > >
> > >      if (mode == MODE_FW) {
> > >          if ((rc = verify_mode_params(argc, argv, "ml", 0))) {
> >
> >
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "open-iscsi" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> > http://groups.google.com/group/open-iscsi?hl=en.
> >
> >



 

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.

Reply via email to