-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathiprconfig.c
19615 lines (16660 loc) · 460 KB
/
iprconfig.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* IBM IPR adapter configuration utility
*
* (C) Copyright 2000, 2004
* International Business Machines Corporation and others.
* All Rights Reserved. This program and the accompanying
* materials are made available under the terms of the
* Common Public License v1.0 which accompanies this distribution.
**/
#ifndef iprlib_h
#include "iprlib.h"
#endif
#include <nl_types.h>
#include <locale.h>
#include <term.h>
#include <ncurses.h>
#include <form.h>
#include <panel.h>
#include <menu.h>
#include <string.h>
#include "iprconfig.h"
#include <sys/ioctl.h>
#include <scsi/sg.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <libgen.h>
#include <math.h>
char *tool_name = "iprconfig";
#define MAX_CMD_LENGTH 1000
struct devs_to_init_t {
struct ipr_dev *dev;
struct ipr_ioa *ioa;
u64 device_id;
int new_block_size;
int cmplt;
int do_init;
int done;
int dev_type;
#define IPR_AF_DASD_DEVICE 1
#define IPR_JBOD_DASD_DEVICE 2
struct devs_to_init_t *next;
};
#define for_each_dev_to_init(dev) for (dev = dev_init_head; dev; dev = dev->next)
struct prot_level {
struct ipr_array_cap_entry *array_cap_entry;
u8 is_valid:1;
u8 reserved:7;
};
struct array_cmd_data {
u8 array_id;
u8 prot_level;
u16 stripe_size;
int qdepth;
u32 do_cmd;
int vset_cache;
struct ipr_ioa *ioa;
struct ipr_dev *dev;
struct ipr_array_query_data *qac;
struct array_cmd_data *next;
};
/* not needed once menus incorporated into screen_driver */
struct window_l {
WINDOW *win;
struct window_l *next;
};
struct panel_l {
PANEL *panel;
struct panel_l *next;
};
static struct devs_to_init_t *dev_init_head = NULL;
static struct devs_to_init_t *dev_init_tail = NULL;
static struct array_cmd_data *raid_cmd_head = NULL;
static struct array_cmd_data *raid_cmd_tail = NULL;
static i_container *i_con_head = NULL; /* FIXME requires multiple heads */
static char log_root_dir[200];
static char editor[200];
FILE *errpath;
static int toggle_field;
nl_catd catd;
static char **add_args;
static int num_add_args;
static int use_curses;
#define for_each_raid_cmd(cmd) for (cmd = raid_cmd_head; cmd; cmd = cmd->next)
#define DEFAULT_LOG_DIR "/var/log"
#define DEFAULT_EDITOR "less"
#define IS_CANCEL_KEY(c) ((c == KEY_F(12)) || (c == 'q') || (c == 'Q'))
#define CANCEL_KEY_LABEL "q=Cancel "
#define IS_EXIT_KEY(c) ((c == KEY_F(3)) || (c == 'e') || (c == 'E'))
#define EXIT_KEY_LABEL "e=Exit "
#define CONFIRM_KEY_LABEL "c=Confirm "
#define CONFIRM_REC_KEY_LABEL "s=Confirm Reclaim "
#define ENTER_KEY '\n'
#define IS_ENTER_KEY(c) ((c == KEY_ENTER) || (c == ENTER_KEY))
#define IS_REFRESH_KEY(c) ((c == 'r') || (c == 'R'))
#define REFRESH_KEY_LABEL "r=Refresh "
#define IS_TOGGLE_KEY(c) ((c == 't') || (c == 'T'))
#define TOGGLE_KEY_LABEL "t=Toggle "
#define IS_PGDN_KEY(c) ((c == KEY_NPAGE) || (c == 'f') || (c == 'F'))
#define PAGE_DOWN_KEY_LABEL "f=PageDn "
#define IS_PGUP_KEY(c) ((c == KEY_PPAGE) || (c == 'b') || (c == 'B'))
#define PAGE_UP_KEY_LABEL "b=PageUp "
#define IS_5250_CHAR(c) (c == 0xa)
#define is_digit(ch) (((ch)>=(unsigned)'0'&&(ch)<=(unsigned)'9')?1:0)
struct special_status {
int index;
int num;
char *str;
} s_status;
char *print_device(struct ipr_dev *, char *, char *, int);
int display_menu(ITEM **, int, int, int **);
char *__print_device(struct ipr_dev *, char *, char *, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int);
static char *print_path_details(struct ipr_dev *, char *);
static int get_drive_phy_loc(struct ipr_ioa *ioa);
static char *print_ssd_report(struct ipr_dev *dev, char *body);
static char *af_dasd_perf (char *body, struct ipr_dev *dev);
#define print_dev(i, dev, buf, fmt, type) \
for (i = 0; i < 2; i++) \
(buf)[i] = print_device(dev, (buf)[i], fmt, type);
#define print_dev_conc(i, dev, buf, fmt, type) \
for (i = 0; i < 3; i++) \
(buf)[i] = print_device(dev, (buf)[i], fmt, (type + 5));
#define print_dev_enclosure(i, dev, buf, fmt, type) \
for (i = 0; i < 2; i++) { \
if ( i == 0 ) \
(buf)[i] = print_device(dev, (buf)[i], fmt, (type + 8)); \
if (i == 1) \
(buf)[i] = print_device(dev, (buf)[i], fmt, (type + 8)); \
}
static struct sysfs_dev *head_sdev;
static struct sysfs_dev *tail_sdev;
/**
* is_format_allowed -
* @dev: ipr dev struct
*
* Returns:
* 1 if format is allowed / 0 otherwise
**/
static int is_format_allowed(struct ipr_dev *dev)
{
int rc;
struct ipr_cmd_status cmd_status;
struct ipr_cmd_status_record *status_record;
struct sense_data_t sense_data;
if (ipr_is_af_dasd_device(dev)) {
rc = ipr_query_command_status(dev, &cmd_status);
if (rc == 0 && cmd_status.num_records != 0) {
status_record = cmd_status.record;
if ((status_record->status != IPR_CMD_STATUS_SUCCESSFUL)
&& (status_record->status != IPR_CMD_STATUS_FAILED))
return 0;
}
} else {
rc = ipr_test_unit_ready(dev, &sense_data);
if (rc == CHECK_CONDITION && (sense_data.error_code & 0x7F) == 0x70) {
if (sense_data.add_sense_code == 0x31 &&
sense_data.add_sense_code_qual == 0x00)
return 1;
else if ((sense_data.sense_key & 0x0F) == 0x02)
return 0;
}
}
return 1;
}
/**
* can_format_for_raid -
* @dev: ipr dev struct
*
* Returns:
* 1 if format for raid is allowed / 0 otherwise
**/
static int can_format_for_raid(struct ipr_dev *dev)
{
if (dev->ioa->is_secondary)
return 0;
if (!ipr_is_gscsi(dev) && !ipr_is_af_dasd_device(dev))
return 0;
if (ipr_is_hot_spare(dev) || !device_supported(dev))
return 0;
if (ipr_is_array_member(dev) && !dev->dev_rcd->no_cfgte_vol)
return 0;
if (ipr_is_af_dasd_device(dev) && ipr_device_is_zeroed(dev))
return 0;
if (!ipr_is_af_dasd_device(dev)) {
/* If on a JBOD adapter */
if (!dev->ioa->qac_data->num_records)
return 0;
if (is_af_blocked(dev, 0))
return 0;
}
if (!is_format_allowed(dev))
return 0;
return 1;
}
static int wait_for_formatted_af_dasd(int timeout_in_secs)
{
struct devs_to_init_t *dev = dev_init_head;
struct scsi_dev_data *scsi_devs;
struct scsi_dev_data *scsi_dev_data;
int num_devs, j, af_found, jbod2af_formats, num_secs;
u64 device_id;
for (num_secs = 0; num_secs < timeout_in_secs; num_secs++) {
af_found = 0;
jbod2af_formats = 0;
scsi_devs = NULL;
num_devs = get_scsi_dev_data(&scsi_devs);
for_each_dev_to_init(dev) {
if (!dev->dev || !dev->ioa)
continue;
if (!dev->dev->scsi_dev_data)
continue;
if (dev->dev_type != IPR_JBOD_DASD_DEVICE)
continue;
if (!ipr_is_af_blk_size(dev->ioa, dev->new_block_size))
continue;
if (!dev->do_init)
continue;
jbod2af_formats++;
device_id = dev->dev->scsi_dev_data->device_id;
for (j = 0, scsi_dev_data = scsi_devs;
j < num_devs; j++, scsi_dev_data++) {
if (scsi_dev_data->host != dev->ioa->host_num)
continue;
if (get_sg_name(scsi_dev_data))
continue;
if (scsi_dev_data->type != IPR_TYPE_AF_DISK)
continue;
if (dev->device_id != scsi_dev_data->device_id)
continue;
scsi_dbg(dev->dev, "Format complete. AF DASD found. New Device ID=%lx, Old Device ID=%lx\n",
scsi_dev_data->device_id, dev->device_id);
af_found++;
break;
}
}
free(scsi_devs);
if (af_found == jbod2af_formats)
break;
sleep(1);
}
return ((af_found == jbod2af_formats) ? 0 : -ETIMEDOUT);
}
/**
* flush_stdscr -
*
* Returns:
* nothing
**/
/* not needed after screen_driver can do menus */
static void flush_stdscr()
{
if (!use_curses) {
fprintf(stdout, "\r");
fflush(stdout);
return;
}
nodelay(stdscr, TRUE);
while(getch() != ERR) {}
nodelay(stdscr, FALSE);
}
/**
* free_i_con - free memory from an i_container list
* @i_con: i_container struct
*
* Returns:
* NULL
**/
static i_container *free_i_con(i_container *i_con)
{
i_container *temp_i_con;
i_con = i_con_head;
if (i_con == NULL)
return NULL;
do {
temp_i_con = i_con->next_item;
free(i_con);
i_con = temp_i_con;
} while (i_con);
i_con_head = NULL;
return NULL;
}
/**
* add_i_con - create a new i_con list or add an i_container to a list
* @i_con: i_container struct
* @f: field data
* @d: data buffer
*
* Returns:
* i_container pointen
**/
static i_container *add_i_con(i_container *i_con, char *f, void *d)
{
i_container *new_i_con;
new_i_con = malloc(sizeof(i_container));
new_i_con->next_item = NULL;
/* used to hold data entered into user-entry fields */
strncpy(new_i_con->field_data, f, MAX_FIELD_SIZE+1);
new_i_con->field_data[strlen(f)+1] = '\0';
/* a pointen to the device information represented by the i_con */
new_i_con->data = d;
if (i_con)
i_con->next_item = new_i_con;
else
i_con_head = new_i_con;
return new_i_con;
}
/**
* exit_confirmed -
* @i_con: i_container struct
*
* Returns:
* 0
**/
int exit_confirmed(i_container *i_con)
{
exit_func();
exit(0);
return 0;
}
/**
* free_screen -
* @panel:
* @win:
* @fields:
*
* Returns:
* nothing
**/
/*not needed after screen_driver can do menus */
static void free_screen(struct panel_l *panel, struct window_l *win,
FIELD **fields)
{
struct panel_l *cur_panel;
struct window_l *cur_win;
int i;
cur_panel = panel;
while(cur_panel) {
panel = panel->next;
del_panel(cur_panel->panel);
free(cur_panel);
cur_panel = panel;
}
cur_win = win;
while(cur_win) {
win = win->next;
delwin(cur_win->win);
free(cur_win);
cur_win = win;
}
if (fields) {
for (i = 0; fields[i] != NULL; i++)
free_field(fields[i]);
}
}
/**
* add_raid_cmd_tail -
* @ioa: ipr ioa struct
* @dev: ipr dev struct
* @array_id: array ID
*
* Returns:
* nothing
**/
static void add_raid_cmd_tail(struct ipr_ioa *ioa, struct ipr_dev *dev, u8 array_id)
{
if (raid_cmd_head) {
raid_cmd_tail->next = malloc(sizeof(struct array_cmd_data));
raid_cmd_tail = raid_cmd_tail->next;
} else {
raid_cmd_head = raid_cmd_tail = malloc(sizeof(struct array_cmd_data));
}
memset(raid_cmd_tail, 0, sizeof(struct array_cmd_data));
raid_cmd_tail->array_id = array_id;
raid_cmd_tail->ioa = ioa;
raid_cmd_tail->dev = dev;
}
/**
* free_raid_cmds - free the raid_cmd_head list
*
* Returns:
* nothing
**/
static void free_raid_cmds()
{
struct array_cmd_data *cur = raid_cmd_head;
while(cur) {
free(cur->qac);
cur = cur->next;
free(raid_cmd_head);
raid_cmd_head = cur;
}
}
/**
* free_devs_to_init - free the dev_init_head list
*
* Returns:
* nothing
**/
static void free_devs_to_init()
{
struct devs_to_init_t *dev = dev_init_head;
while (dev) {
dev = dev->next;
free(dev_init_head);
dev_init_head = dev;
}
}
/**
* strip_trailing_whitespace - remove trailing white space from a string
* @p_str: string
*
* Returns:
* 0 if success / non-zero on failure
**/
static char *strip_trailing_whitespace(char *p_str)
{
int len;
char *p_tmp;
len = strlen(p_str);
if (len == 0)
return p_str;
p_tmp = p_str + len - 1;
while(*p_tmp == ' ' || *p_tmp == '\n')
p_tmp--;
p_tmp++;
*p_tmp = '\0';
return p_str;
}
/**
* tool_exit_func - clean up curses stuff on exit if needed
*
* Returns:
* nothing
**/
static void tool_exit_func()
{
if (use_curses) {
clearenv();
clear();
refresh();
endwin();
}
}
/**
* cmdline_exit_func -
*
* Returns:
* nothing
**/
static void cmdline_exit_func()
{
}
/**
* ipr_list_opts -
* @body:
* @key:
* @list_str:
*
* Returns:
* pointen to body string
**/
static char *ipr_list_opts(char *body, char *key, char *list_str)
{
int start_len = 0;
char *string_buf = _("Select one of the following");
if (!body) {
body = realloc(body, strlen(string_buf) + 8);
sprintf(body, "\n%s:\n\n", string_buf);
}
start_len = strlen(body);
body = realloc(body, start_len + strlen(key) + strlen(_(list_str)) + 16);
sprintf(body + start_len, " %s. %s\n", key, _(list_str));
return body;
}
/**
* ipr_end_list -
* @body:
*
* Returns:
* pointen to body string
**/
static char *ipr_end_list(char *body)
{
int start_len = 0;
char *string_buf = _("Selection");
start_len = strlen(body);
body = realloc(body, start_len + strlen(string_buf) + 16);
sprintf(body + start_len, "\n\n%s: %%1", string_buf);
return body;
}
/**
* screen_driver - Main driver for curses based display
* @screen: s_node
* @header_lines: number of header lines
* @i_con: i_container struct
*
* Returns:
* screen_output struct
**/
static struct screen_output *screen_driver(s_node *screen, int header_lines, i_container *i_con)
{
WINDOW *w_pad = NULL,*w_page_header = NULL; /* windows to hold text */
FIELD **fields = NULL; /* field list for forms */
FORM *form = NULL; /* form for input fields */
int rc = 0; /* the status of the screen */
char *status; /* displays screen operations */
char buffer[100]; /* needed for special status strings */
bool invalid = false; /* invalid status display */
bool ground_cursor=false;
int stdscr_max_y,stdscr_max_x;
int w_pad_max_y=0,w_pad_max_x=0; /* limits of the windows */
int pad_l=0,pad_scr_r,pad_t=0,viewable_body_lines;
int title_lines=2,footer_lines=2; /* position of the pad */
int center,len=0,ch;
int i=0,j,k,row=0,col=0,bt_len=0; /* text positioning */
int field_width,num_fields=0; /* form positioning */
int h,w,t,l,o,b; /* form querying */
int active_field = 0; /* return to same active field after a quit */
bool pages = false,is_bottom = false; /* control page up/down in multi-page screens */
bool form_adjust = false; /* correct cursor position in multi-page screens */
bool refresh_stdscr = true;
bool x_offscr,y_offscr; /* scrolling windows */
bool pagedn, fakepagedn;
char *input = NULL;
struct screen_output *s_out;
struct screen_opts *temp; /* reference to another screen */
char *title,*body,*body_text; /* screen text */
i_container *temp_i_con;
int num_i_cons = 0;
int x, y;
int f_flags;
s_out = malloc(sizeof(struct screen_output)); /* passes an i_con and an rc value back to the function */
/* create text strings */
title = _(screen->title);
body = screen->body;
f_flags = screen->f_flags;
if (f_flags & ENTER_FLAG)
footer_lines += 3;
else if (f_flags & FWD_FLAG)
footer_lines++;
if (f_flags & TOGGLE_FLAG)
active_field = toggle_field;
bt_len = strlen(body);
body_text = calloc(bt_len + 1, sizeof(char));
/* determine max size needed and find where to put form fields and device
* input in the text and add them
* '%' marks a field. The number after '%' represents the field's width
*/
i=0;
temp_i_con = i_con_head;
while(body[i] != '\0') {
if (body[i] == '\n') {
row++;
col = -1;
body_text[len] = body[i];
len++;
} else if ((body[i] == '%') && is_digit(body[i+1])) {
fields = realloc(fields,sizeof(FIELD **) * (num_fields + 1));
i++;
field_width = 0;
sscanf(&(body[i]),"%d",&field_width);
fields[num_fields] = new_field(1,field_width,row,col,0,0);
if (field_width >= 30)
field_opts_off(fields[num_fields],O_AUTOSKIP);
if (field_width > 9)
/* skip second digit of field index */
i++;
if ((temp_i_con) && (temp_i_con->field_data[0]) && (f_flags & MENU_FLAG)) {
set_field_buffer(fields[num_fields], 0, temp_i_con->field_data);
input = field_buffer(fields[num_fields],0);
temp_i_con = temp_i_con->next_item;
num_i_cons++;
}
set_field_userptr(fields[num_fields],NULL);
num_fields++;
col += field_width-1;
bt_len += field_width;
body_text = realloc(body_text,bt_len);
for(k = 0; k < field_width; k++)
body_text[len+k] = ' ';
len += field_width;
} else {
body_text[len] = body[i];
len++;
}
col++;
i++;
if (col > w_pad_max_x)
w_pad_max_x = col;
}
body_text[len] = '\0';
w_pad_max_y = row;
w_pad_max_y++; /* some forms may not display correctly if this is not included */
w_pad_max_x++; /* adds a column for return char \n : else, a blank line will appear in the pad */
w_pad = newpad(w_pad_max_y,w_pad_max_x);
keypad(w_pad,TRUE);
if (num_fields) {
fields = realloc(fields,sizeof(FIELD **) * (num_fields + 1));
fields[num_fields] = NULL;
form = new_form(fields);
}
/* make the form appear in the pad; not stdscr */
set_form_win(form,w_pad);
set_form_sub(form,w_pad);
while(1) {
getmaxyx(stdscr,stdscr_max_y,stdscr_max_x);
/* clear all windows before writing new text to them */
clear();
wclear(w_pad);
if(pages)
wclear(w_page_header);
center = stdscr_max_x/2;
len = strlen(title);
/* add the title at the center of stdscr */
mvaddstr(0,(center-len/2)>0?center-len/2:0,title);
/* set the boundaries of the pad based on the size of the screen
and determine whether or not the user is able to scroll */
if ((stdscr_max_y - title_lines - footer_lines + 1) >= w_pad_max_y) {
viewable_body_lines = w_pad_max_y;
pad_t = 0;
y_offscr = false; /*not scrollable*/
pages = false;
for (i = 0; i < num_fields; i++)
field_opts_on(fields[i],O_ACTIVE);
} else {
viewable_body_lines = stdscr_max_y - title_lines - footer_lines - 1;
y_offscr = true; /*scrollable*/
if (f_flags & FWD_FLAG) {
pages = true;
w_page_header = subpad(w_pad,header_lines,w_pad_max_x,0,0);
}
}
if (stdscr_max_x > w_pad_max_x) {
pad_scr_r = w_pad_max_x;
pad_l = 0;
x_offscr = false;
} else {
pad_scr_r = stdscr_max_x;
x_offscr = true;
}
move(stdscr_max_y - footer_lines,0);
if (f_flags & ENTER_FLAG) {
if (num_fields == 0) {
addstr(_("\nPress Enter to Continue\n\n"));
ground_cursor = true;
} else
addstr(_("\nOr leave blank and press Enter to cancel\n\n"));
}
if ((f_flags & FWD_FLAG) && !(f_flags & ENTER_FLAG))
addstr("\n");
if (f_flags & CONFIRM_FLAG)
addstr(CONFIRM_KEY_LABEL);
if (f_flags & EXIT_FLAG)
addstr(EXIT_KEY_LABEL);
if (f_flags & CANCEL_FLAG)
addstr(CANCEL_KEY_LABEL);
if (f_flags & CONFIRM_REC_FLAG)
addstr(CONFIRM_REC_KEY_LABEL);
if (f_flags & REFRESH_FLAG)
addstr(REFRESH_KEY_LABEL);
if (f_flags & TOGGLE_FLAG)
addstr(TOGGLE_KEY_LABEL);
if ((f_flags & FWD_FLAG) && y_offscr) {
addstr(PAGE_DOWN_KEY_LABEL);
addstr(PAGE_UP_KEY_LABEL);
}
post_form(form);
/* add the body of the text to the screen */
if (pages) {
wmove(w_page_header,0,0);
waddstr(w_page_header,body_text);
}
wmove(w_pad,0,0);
waddstr(w_pad,body_text);
if (num_fields) {
set_current_field(form,fields[active_field]);
if (active_field == 0)
form_driver(form,REQ_NEXT_FIELD);
form_driver(form,REQ_PREV_FIELD);
}
refresh_stdscr = true;
for(;;) {
/* add global status if defined */
if (s_status.index) {
rc = s_status.index;
s_status.index = 0;
}
if (invalid) {
status = (char *)screen_status[INVALID_OPTION_STATUS];
invalid = false;
} else if (rc != 0) {
if ((status = strchr(screen_status[rc],'%')) == NULL) {
status = (char *)screen_status[rc];
} else if (status[1] == 'd') {
sprintf(buffer,screen_status[rc],s_status.num);
status = buffer;
} else if (status[1] == 's') {
sprintf(buffer,screen_status[rc],s_status.str);
status = buffer;
}
rc = 0;
} else
status = NULL;
move(stdscr_max_y-1,0);
clrtoeol(); /* clear last line */
mvaddstr(stdscr_max_y-1,0,status);
status = NULL;
pagedn = false;
if ((f_flags & FWD_FLAG) && y_offscr) {
if (!is_bottom)
mvaddstr(stdscr_max_y-footer_lines,stdscr_max_x-8,_("More..."));
else
mvaddstr(stdscr_max_y-footer_lines,stdscr_max_x-8," ");
for (i = 0; i < num_fields; i++) {
if (!fields[i])
continue;
/* height, width, top, left, offscreen rows, buffer */
field_info(fields[i],&h,&w,&t,&l,&o,&b);
/* turn all offscreen fields off */
if ((t >= (header_lines + pad_t)) &&
(t <= (viewable_body_lines + pad_t))) {
field_opts_on(fields[i],O_ACTIVE);
if (!form_adjust)
continue;
if (!(f_flags & TOGGLE_FLAG) || !toggle_field)
set_current_field(form,fields[i]);
form_adjust = false;
} else if (field_opts_off(fields[i],O_ACTIVE) == E_CURRENT &&
toggle_field && i == (toggle_field - 1)) {
pagedn = true;
}
}
}
if (f_flags & MENU_FLAG) {
for (i = 0; i < num_fields; i++) {
field_opts_off(fields[i],O_VISIBLE);
field_opts_on(fields[i],O_VISIBLE);
set_field_fore(fields[i],A_BOLD);
}
}
if ((f_flags & TOGGLE_FLAG) && toggle_field &&
(((field_opts(fields[toggle_field-1]) & O_ACTIVE) != O_ACTIVE) ||
pagedn)) {
pagedn = false;
fakepagedn = true;
ch = KEY_NPAGE;
} else {
fakepagedn = false;
toggle_field = 0;
if (refresh_stdscr) {
touchwin(stdscr);
refresh_stdscr = FALSE;
} else
touchline(stdscr,stdscr_max_y - 1,1);
refresh();
if (pages) {
touchwin(w_page_header);
prefresh(w_page_header, 0, pad_l,
title_lines, 0,
title_lines + header_lines - 1, pad_scr_r - 1);
touchwin(w_pad);
prefresh(w_pad, pad_t + header_lines, pad_l,
title_lines + header_lines, 0,
title_lines + viewable_body_lines, pad_scr_r - 1);
} else {
touchwin(w_pad);
prefresh(w_pad, pad_t, pad_l,
title_lines, 0,
title_lines + viewable_body_lines, pad_scr_r - 1);
}
if (ground_cursor) {
move(stdscr_max_y - 1, stdscr_max_x - 1);
refresh();
}
ch = wgetch(w_pad); /* pause for user input */
}
if (ch == KEY_RESIZE)
break;
if (IS_ENTER_KEY(ch)) {
if (num_fields > 0)
active_field = field_index(current_field(form));
if ((f_flags & ENTER_FLAG) && num_fields == 0) {
rc = (CANCEL_FLAG | rc);
goto leave;
} else if (f_flags & ENTER_FLAG) {
/* cancel if all fields are empty */
form_driver(form,REQ_VALIDATION);
for (i = 0; i < num_fields; i++) {
if (strlen(field_buffer(fields[i],0)) != 0)
/* fields are not empty -> continue */
break;
if (i == (num_fields - 1)) {
/* all fields are empty */
rc = (CANCEL_FLAG | rc);
goto leave;
}
}
}
if (num_fields > 0)
input = field_buffer(fields[active_field],0);
invalid = true;
for (i = 0; i < screen->num_opts; i++) {
temp = &(screen->options[i]);
if ((temp->key[0] == '\n') ||
((num_fields > 0)?(strcasecmp(input,temp->key) == 0):0)) {
invalid = false;
if ((temp->key[0] == '\n') && (num_fields > 0)) {
/* store field data to existing i_con (which should already
contain pointens) */
i_container *temp_i_con = i_con_head;
form_driver(form,REQ_VALIDATION);
for (i = 0; i < num_fields; i++) {
strncpy(temp_i_con->field_data,field_buffer(fields[i],0),MAX_FIELD_SIZE);
temp_i_con = temp_i_con->next_item;
}
}
if (temp->screen_function == NULL)
/* continue with function */
goto leave;
toggle_field = 0;
do
rc = temp->screen_function(i_con_head);
while (rc == REFRESH_SCREEN || rc & REFRESH_FLAG);
/* if screen flags exist on rc and they don't match
the screen's flags, return */
if ((rc & 0xF000) && !(screen->rc_flags & (rc & 0xF000)))
goto leave;
/* strip screen flags from rc */
rc &= ~(EXIT_FLAG | CANCEL_FLAG | REFRESH_FLAG);
if (screen->rc_flags & REFRESH_FLAG) {
s_status.index = rc;
rc = (REFRESH_FLAG | rc);
goto leave;
}
break;
}
}
if (!invalid) {
/*clear fields*/
form_driver(form,REQ_LAST_FIELD);
for (i = 0; i < num_fields; i++) {
form_driver(form,REQ_CLR_FIELD);
form_driver(form,REQ_NEXT_FIELD);
}