-/*
- * $Source$
- * $Header$
+/* $Id $
+ *
+ * Simple add-me-to/remove-me-from list client
+ *
+ * mailmaint.c - pjlevine - 20 August 1987
+ *
+ * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
*/
-/* (c) Copyright 1988 by the Massachusetts Institute of Technology. */
-/* For copying and distribution information, please see the file */
-/* <mit-copyright.h>. */
-
-#ifndef lint
-static char rcsid_mailmaint_c[] = "$Header$";
-#endif
+#include <mit-copyright.h>
+#include <moira.h>
+#include <moira_site.h>
-/***********************************************************************/
-/* mailmaint.c - pjlevine - 20 August 1987 */
-/***********************************************************************/
-#include <stdio.h>
-#include <pwd.h>
-#include <signal.h>
-#include <string.h>
+#include <ctype.h>
#include <curses.h>
-#include <sys/types.h>
-#include <stdarg.h>
+#include <pwd.h>
+#include <stdio.h>
#include <stdlib.h>
-#include <com_err.h>
-#include <ctype.h>
-#include <moira.h>
-#include <moira_site.h>
-#include <mit-copyright.h>
+#include <string.h>
+#include <unistd.h>
+RCSID("$Header$");
#define STARTCOL 0
#define STARTROW 3
char *whoami; /* should not be static, for logging package */
static int status;
-static int scream();
-void menu_err_hook(const char *who, long code, const char *fmt, va_list args);
typedef struct list_info {
int active;
} List_info;
static char *ascbuff = {"0123456789"};
-static int print_2(), print_1();
static List_info *current_li = (List_info *) NULL;
-static int get_list_info();
-static int fetch_list_info();
typedef struct _menu {
int num_items;
int moreflg, toggle, first_time;
char *username;
+void get_main_input(void);
+void show_list_info(void);
+void display_buff(char *buf);
+void start_display_buff(char *buff);
+void add_member(void);
+void delete_member(void);
+void list_by_member(void);
+void show_all(void);
+static int print_1(int argc, char *argv[], void *callback);
+static int print_all(int argc, char *argv[], void *callback);
+void list_all_groups(void);
+void list_members(void);
+static int print_2(int argc, char *argv[], void *callback);
+void start_display(char *buff);
+void end_display(void);
+void display_menu(MENU *menu);
+void pack_main_menu(void);
+void pack_help_menu(void);
+void highlight(MENU *menu);
+void title(char *buff);
+void center_text(int row, char *buff);
+void show_text(int row, int col, char *buff);
+void erase_line(int row, int col);
+void cls(void);
+void clrwin(int erase_row);
+static int fetch_list_info(char *list, List_info *li);
+static int get_list_info(int argc, char **argv, void *hint);
+int Prompt(char *prompt, char *buf, int buflen, int crok);
+void menu_err_hook(const char *who, long code, const char *fmt, va_list args);
+
/* This crock is because the original code was very broken and this makes
* it work. Someday, we should abandon the code or fix it right.
*/
current_li->modwith = NULL;
}
if (!(username = getlogin()))
- {
- struct passwd *getpwuid();
-
- username = getpwuid(getuid())->pw_name;
- }
- username = (username && strlen(username)) ? strsave(username) : "";
+ username = getpwuid(getuid())->pw_name;
+ username = username ? strdup(username) : "";
printf("Connecting to database for %s...please hold on.\n", username);
}
/****************************************************/
-int get_main_input(void)
+void get_main_input(void)
{
int c;
int retflg;
}
/****************************************************/
-int show_list_info(void)
+void show_list_info(void)
{
char *buf;
}
/****************************************************/
-int display_buff(char *buf)
+void display_buff(char *buf)
{
int i, cnt;
char *printbuf;
start_display_buff(printbuf);
free(printbuf);
}
- return 0;
+ return;
}
/****************************************************/
-int start_display_buff(char *buff)
+void start_display_buff(char *buff)
{
char buffer[5];
num_members++;
if (moreflg)
- return 0;
+ return;
if (currow >= LINES - 2)
{
page++;
erase_line(currow, STARTCOL);
show_text(currow, STARTCOL, "Flushing query...");
moreflg = 1;
- return 0;
+ return;
}
clrwin(DISPROW + 2);
currow = DISPROW + 2;
}
show_text(currow, STARTCOL, buff);
currow++;
- return 0;
+ return;
}
/****************************************************/
-int add_member(void)
+void add_member(void)
{
char *argv[3];
char *buf;
if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1)
{
display_buff("\n");
- argv[0] = strsave(buf);
- argv[1] = strsave("user");
- argv[2] = strsave(username);
- if ((status = mr_query("add_member_to_list", 3, argv, scream, NULL)))
+ argv[0] = strdup(buf);
+ argv[1] = strdup("user");
+ argv[2] = strdup(username);
+ if ((status = mr_query("add_member_to_list", 3, argv, NULL, NULL)))
{
display_buff("\n");
com_err(whoami, status, " found.\n");
}
/****************************************************/
-int delete_member(void)
+void delete_member(void)
{
char *argv[3];
char *buf;
if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1)
{
display_buff("\n");
- argv[0] = strsave(buf);
- argv[1] = strsave("user");
- argv[2] = strsave(username);
- if ((status = mr_query("delete_member_from_list", 3, argv, scream, NULL)))
+ argv[0] = strdup(buf);
+ argv[1] = strdup("user");
+ argv[2] = strdup(username);
+ if ((status = mr_query("delete_member_from_list", 3, argv, NULL, NULL)))
{
display_buff("\n");
com_err(whoami, status, " found.\n");
}
/****************************************************/
-int list_by_member(void)
+void list_by_member(void)
{
char *nargv[3];
char *buf;
- nargv[1] = strsave("ruser");
- nargv[2] = strsave(username);
+ nargv[1] = strdup("ruser");
+ nargv[2] = strdup(username);
buf = calloc(BUFSIZ, 1);
sprintf(buf, "%s is on the following lists:\n", username);
show_text(DISPROW, STARTCOL, buf);
show_text(currow, STARTCOL, "Press any Key to continue...");
getchar();
clrwin(DISPROW);
- return;
}
/****************************************************/
-int show_all(void)
+void show_all(void)
{
char c;
}
else
erase_line(DISPROW, STARTCOL);
- return;
}
/****************************************************/
-static int print_1(int argc, char *argv[], char *callback)
+static int print_1(int argc, char *argv[], void *callback)
{
char buf[BUFSIZ];
sprintf(buf, "%s\n", argv[0]);
start_display(buf);
- return 0;
+ return MR_CONT;
}
/****************************************************/
-static int print_all(int argc, char *argv[], char *callback)
+static int print_all(int argc, char *argv[], void *callback)
{
char buf[BUFSIZ];
sprintf(buf, "%s\n", argv[0]);
start_display(buf);
- return 0;
+ return MR_CONT;
}
/****************************************************/
-int list_all_groups(void)
+void list_all_groups(void)
{
char *argv[5];
argv[0] = argv[1] = argv[3] = "true";
com_err(whoami, status, " in list_all_groups\n");
}
end_display();
-
- return 0;
}
/****************************************************/
-int list_members(void)
+void list_members(void)
{
char *argv[1];
char *buf;
return;
}
end_display();
- return 0;
+ return;
}
clrwin(DISPROW);
- return 0;
}
/****************************************************/
-static int print_2(int argc, char *argv[], char *callback)
+static int print_2(int argc, char *argv[], void *callback)
{
char buf[BUFSIZ];
sprintf(buf, "%s %s", argv[0], argv[1]);
start_display(buf);
- return 0;
+ return MR_CONT;
}
/****************************************************/
-int start_display(char *buff)
+void start_display(char *buff)
{
char *buffer;
int secondcol; /* where to start the second column of text */
secondcol = (COLS / 2); /* 1/2 was accross the screen */
num_members++;
if (moreflg)
- return 0;
+ return;
buffer = calloc(50, 1);
if (currow >= LINES - 2)
{
erase_line(currow, STARTCOL);
show_text(currow, STARTCOL, "Flushing query...");
moreflg = 1;
- return 0;
+ return;
}
clrwin(DISPROW + 2);
currow = DISPROW + 2;
currow++;
}
toggle = !toggle;
- return 0;
}
/****************************************************/
-int end_display(void)
+void end_display(void)
{
char *buffer;
}
/****************************************************/
-int display_menu(MENU *menu)
+void display_menu(MENU *menu)
{
int i;
}
/****************************************************/
-int pack_main_menu(void)
+void pack_main_menu(void)
{
char *buf;
buf = calloc(50, 1);
sprintf(buf, "Mail List Program for %s", username);
- main_menu->title = strsave(buf);
- main_menu->items[0] = strsave("1. Show all public mailing lists.");
- main_menu->items[1] = strsave("2. Get all members of a mailing list.");
- main_menu->items[2] = strsave("3. Display lists of which you are a member.");
- main_menu->items[3] = strsave("4. Show description of list.");
- main_menu->items[4] = strsave("5. Add yourself to a mailing list.");
- main_menu->items[5] = strsave("6. Delete yourself from a mailing list.");
- main_menu->items[6] = strsave("q. Quit.");
+ main_menu->title = strdup(buf);
+ main_menu->items[0] = strdup("1. Show all public mailing lists.");
+ main_menu->items[1] = strdup("2. Get all members of a mailing list.");
+ main_menu->items[2] = strdup("3. Display lists of which you are a member.");
+ main_menu->items[3] = strdup("4. Show description of list.");
+ main_menu->items[4] = strdup("5. Add yourself to a mailing list.");
+ main_menu->items[5] = strdup("6. Delete yourself from a mailing list.");
+ main_menu->items[6] = strdup("q. Quit.");
}
/****************************************************/
-int pack_help_menu(void)
+void pack_help_menu(void)
{
help_menu = malloc(sizeof(MENU));
help_menu->num_items = 5;
help_menu->items = malloc(sizeof(char *) * help_menu->num_items);
- help_menu->title = strsave("mailmaint is designed as a basic mail list administration program.");
- help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like");
- help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the");
- help_menu->items[2] = strsave("program listmaint.");
- help_menu->items[3] = strsave(" ");
- help_menu->items[4] = strsave("Press any key to continue.");
+ help_menu->title = strdup("mailmaint is designed as a basic mail list administration program.");
+ help_menu->items[0] = strdup("if you need to perform more advanced list manipulation like");
+ help_menu->items[1] = strdup("adding lists, or changing list characteristics, refer to the");
+ help_menu->items[2] = strdup("program listmaint.");
+ help_menu->items[3] = strdup(" ");
+ help_menu->items[4] = strdup("Press any key to continue.");
}
/****************************************************/
-int highlight(MENU *menu)
+void highlight(MENU *menu)
{
if (oldpos[level] != position[level])
{
}
/****************************************************/
-int title(char *buff)
+void title(char *buff)
{
move(0, MAX(0, (COLS - strlen(buff)) >> 1));
standout();
}
/****************************************************/
-int center_text(int row, char *buff)
+void center_text(int row, char *buff)
{
move(row, MAX(0, (COLS - strlen(buff)) >> 1));
addstr(buff);
}
/****************************************************/
-int show_text(int row, int col, char *buff)
+void show_text(int row, int col, char *buff)
{
mvcur(0, 0, row, col);
addstr(buff);
}
/****************************************************/
-int erase_line(int row, int col)
+void erase_line(int row, int col)
{
char *buff;
int i;
}
/****************************************************/
-int cls(void)
+void cls(void)
{
clear();
refresh();
}
/****************************************************/
-int clrwin(int erase_row)
+void clrwin(int erase_row)
{
int i;
char *buff;
free(buff);
}
-/****************************************************/
-static int scream(void)
-{
- com_err(whoami, status,
- "\nA Moira update returned a value -- programmer botch\n");
- mr_disconnect();
- exit(1);
- return 0; /* to keep compiler happy */
-}
-
/****************************************************/
static int fetch_list_info(char *list, List_info *li)
{
return mr_query("get_list_info", 1, argv, get_list_info, NULL);
}
-static int get_list_info(int argc, char **argv)
+static int get_list_info(int argc, char **argv, void *hint)
{
if (current_li->acl_type)
free(current_li->acl_type);
- current_li->acl_type = strsave(argv[7]);
+ current_li->acl_type = strdup(argv[7]);
if (current_li->acl_name)
free(current_li->acl_name);
- current_li->acl_name = strsave(argv[8]);
+ current_li->acl_name = strdup(argv[8]);
if (current_li->desc)
free(current_li->desc);
- current_li->desc = strsave(argv[9]);
+ current_li->desc = strdup(argv[9]);
if (current_li->modtime)
free(current_li->modtime);
- current_li->modtime = strsave(argv[10]);
+ current_li->modtime = strdup(argv[10]);
if (current_li->modby)
free(current_li->modby);
- current_li->modby = strsave(argv[11]);
+ current_li->modby = strdup(argv[11]);
if (current_li->modwith)
free(current_li->modwith);
- current_li->modwith = strsave(argv[12]);
- return 0;
+ current_li->modwith = strdup(argv[12]);
+ return MR_CONT;
}