P
P
pepl2132018-12-06 17:07:09
C++ / C#
pepl213, 2018-12-06 17:07:09

How to parse SimpleTerminal code?

I started to disassemble the SimpleTerminal code and a few misunderstandings arose.
1) Why is the file initially called config.def.h, and there are lines in the Makefile

config.h:
  cp config.def.h config.h

What for?
2) The arg.h file has a define that parses the arguments
/* use main(int argc, char *argv[]) */
#define ARGBEGIN	for (argv0 = *argv, argv++, argc--;\
          argv[0] && argv[0][0] == '-'\
          && argv[0][1];\
          argc--, argv++) {\
        char argc_;\
        char **argv_;\
        int brk_;\
        if (argv[0][1] == '-' && argv[0][2] == '\0') {\
          argv++;\
          argc--;\
          break;\
        }\
        int i_;\
        for (i_ = 1, brk_ = 0, argv_ = argv;\
            argv[0][i_] && !brk_;\
            i_++) {\
          if (argv_ != argv)\
            break;\
          argc_ = argv[0][i_];\
          switch (argc_)

#define ARGEND			}\
      }

// В x.c используется так 
int main(int argc, char *argv[])
{ ...
  ARGBEGIN {
  case 'a':
    allowaltscreen = 0;
    break;
  case 'c':
    opt_class = EARGF(usage());
    break;
  case 'e':
    if (argc > 0)
      --argc, ++argv;
    goto run;
  case 'f':
    opt_font = EARGF(usage());
    break;
  case 'g':
    xw.gm = XParseGeometry(EARGF(usage()),
        &xw.l, &xw.t, &cols, &rows);
    break;
  case 'i':
    xw.isfixed = 1;
    break;
  case 'o':
    opt_io = EARGF(usage());
    break;
  case 'l':
    opt_line = EARGF(usage());
    break;
  case 'n':
    opt_name = EARGF(usage());
    break;
  case 't':
  case 'T':
    opt_title = EARGF(usage());
    break;
  case 'w':
    opt_embed = EARGF(usage());
    break;
  case 'v':
    die("%s " VERSION "\n", argv0);
    break;
  default:
    usage();
  } ARGEND;
....
}
What? What for?
Why argv[0] && argv[0][0] == '-'&& argv[0][1];check the first character (of the file?) for '-'?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Melnikov, 2018-12-06
@BacCM

1) Perhaps this happens with some compilation options? Type a certain default file is taken, and in other cases some other one.
2) Because the first thing there is argv++

Q
q2zoff, 2018-12-07
@q27off

1) Obviously, if there is no config.h file (the goal is not achieved), a default config file is created.
2) It is not the first character of the file that is checked, but the correctness of the format of the passed arguments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question