Commit ac2313fa ac2313faf9050f41f6788ae3904aa59e6b40a42a by Sergey Poznyakoff

(ins): New option 'before' allows to insert an item before another one.

1 parent 6338a74f
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc. 2 Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
3 3
4 GNU Mailutils is free software; you can redistribute it and/or modify 4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -127,6 +127,42 @@ prep (list_t list, int argc, char **argv) ...@@ -127,6 +127,42 @@ prep (list_t list, int argc, char **argv)
127 } 127 }
128 128
129 void 129 void
130 ins (list_t list, int argc, char **argv)
131 {
132 int rc;
133 char *item;
134 char *new_item;
135
136 if (argc < 3 || argc > 4)
137 {
138 fprintf (stderr, "ins [before] item new_item?\n");
139 return;
140 }
141
142 if (argc == 4)
143 {
144 if (strcmp (argv[1], "before"))
145 {
146 fprintf (stderr, "ins before item new_item?\n");
147 return;
148 }
149
150 item = argv[2];
151 new_item = argv[3];
152 }
153 else
154 {
155 item = argv[1];
156 new_item = argv[2];
157 }
158
159 rc = list_insert (list, item, strdup (new_item), argc == 4);
160 if (rc)
161 fprintf (stderr, "list_insert: %s\n", mu_strerror (rc));
162 }
163
164
165 void
130 repl (list_t list, int argc, char **argv) 166 repl (list_t list, int argc, char **argv)
131 { 167 {
132 int rc; 168 int rc;
...@@ -207,6 +243,7 @@ help () ...@@ -207,6 +243,7 @@ help ()
207 printf ("add item [item...]\n"); 243 printf ("add item [item...]\n");
208 printf ("prep item [item...]\n"); 244 printf ("prep item [item...]\n");
209 printf ("repl old_item new_item\n"); 245 printf ("repl old_item new_item\n");
246 printf ("ins [before] item new_item\n");
210 printf ("print\n"); 247 printf ("print\n");
211 printf ("quit\n"); 248 printf ("quit\n");
212 printf ("iter num\n"); 249 printf ("iter num\n");
...@@ -261,6 +298,8 @@ shell (list_t list) ...@@ -261,6 +298,8 @@ shell (list_t list)
261 add (list, argc, argv); 298 add (list, argc, argv);
262 else if (strcmp (argv[0], "prep") == 0) 299 else if (strcmp (argv[0], "prep") == 0)
263 prep (list, argc, argv); 300 prep (list, argc, argv);
301 else if (strcmp (argv[0], "ins") == 0)
302 ins (list, argc, argv);
264 else if (strcmp (argv[0], "repl") == 0) 303 else if (strcmp (argv[0], "repl") == 0)
265 repl (list, argc, argv); 304 repl (list, argc, argv);
266 else if (strcmp (argv[0], "print") == 0) 305 else if (strcmp (argv[0], "print") == 0)
......