1b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley/* vi.c - You can't spell "evil" without "vi".
2b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley *
3b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley * Copyright 2015 Rob Landley <rob@landley.net>
4b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley *
5b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html
6b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley
7b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob LandleyUSE_VI(NEWTOY(vi, "<1>1", TOYFLAG_USR|TOYFLAG_BIN))
8b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley
9b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landleyconfig VI
10b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley  bool "vi"
11b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley  default n
12b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley  help
13b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley    usage: vi FILE
14b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley
15b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley    Visual text editor. Predates the existence of standardized cursor keys,
16b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley    so the controls are weird and historical.
17b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley*/
18b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley
19b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley#define FOR_vi
20b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley#include "toys.h"
21b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley
22b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob LandleyGLOBALS(
23b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley  struct linestack *ls;
24b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley  char *statline;
25b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley)
26b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley
27e32e802240c5b3803b9769948dc7a18b3fc1630cRob Landleystruct linestack_show {
28e32e802240c5b3803b9769948dc7a18b3fc1630cRob Landley  struct linestack_show *next;
29e32e802240c5b3803b9769948dc7a18b3fc1630cRob Landley  long top, left;
30e32e802240c5b3803b9769948dc7a18b3fc1630cRob Landley  int x, width, y, height;
31b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley};
32b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley
33e32e802240c5b3803b9769948dc7a18b3fc1630cRob Landley// linestack, what to show, where to show it
34e32e802240c5b3803b9769948dc7a18b3fc1630cRob Landleyvoid linestack_show(struct linestack *ls, struct linestack_show *lss)
35b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley{
36e32e802240c5b3803b9769948dc7a18b3fc1630cRob Landley  return;
37146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landley}
38146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landley
39146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landleyvoid vi_main(void)
40146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landley{
41146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landley  int i;
42b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley
43146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landley  if (!(TT.ls = linestack_load(*toys.optargs)))
44146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landley    TT.ls = xzalloc(sizeof(struct linestack));
45146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landley
46146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landley  for (i=0; i<TT.ls->len; i++)
47146d219e117b56cc6f7e77c1083e91a961b906b5Rob Landley    printf("%.*s\n", (int)TT.ls->idx[i].len, (char *)TT.ls->idx[i].ptr);
48b64abbc1c637f8b79a4a5f1382ae7d6f4bcc0d4dRob Landley}
49