MAX_LENGTH replaced by stdio.h's BUFSIZ

This commit is contained in:
Frederic Culot 2007-04-04 19:38:18 +00:00
parent be46b49384
commit 2496888682
8 changed files with 63 additions and 56 deletions

View File

@ -1,4 +1,4 @@
/* $calcurse: custom.c,v 1.6 2007/03/24 23:18:52 culot Exp $ */ /* $calcurse: custom.c,v 1.7 2007/04/04 19:38:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,6 +27,7 @@
#include <ncurses.h> #include <ncurses.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include "i18n.h" #include "i18n.h"
#include "io.h" #include "io.h"
@ -273,7 +274,7 @@ custom_color_config(int notify_bar)
NBPOS NBPOS
}; };
WINDOW *conf_win; WINDOW *conf_win;
char label[MAX_LENGTH]; char label[BUFSIZ];
char *choose_color_1 = char *choose_color_1 =
_("Use 'X' or SPACE to select a color, " _("Use 'X' or SPACE to select a color, "
"'H/L' 'J/K' or arrow keys to move"); "'H/L' 'J/K' or arrow keys to move");
@ -312,7 +313,7 @@ custom_color_config(int notify_bar)
clear(); clear();
win_row = (notify_bar) ? row - 3 : row - 2; win_row = (notify_bar) ? row - 3 : row - 2;
conf_win = newwin(win_row, col, 0, 0); conf_win = newwin(win_row, col, 0, 0);
snprintf(label, MAX_LENGTH, _("CalCurse %s | color theme"), VERSION); snprintf(label, BUFSIZ, _("CalCurse %s | color theme"), VERSION);
win_show(conf_win, label); win_show(conf_win, label);
status_mesg(choose_color_1, choose_color_2); status_mesg(choose_color_1, choose_color_2);
@ -451,7 +452,7 @@ custom_load_color(char *color, int background)
#define AWAITED_COLORS 2 #define AWAITED_COLORS 2
int i, len, color_num; int i, len, color_num;
char c[AWAITED_COLORS][MAX_LENGTH]; char c[AWAITED_COLORS][BUFSIZ];
int colr[AWAITED_COLORS]; int colr[AWAITED_COLORS];
const char *wrong_color_number = const char *wrong_color_number =
_("FATAL ERROR in custom_load_color: wrong color number.\n"); _("FATAL ERROR in custom_load_color: wrong color number.\n");
@ -588,6 +589,6 @@ custom_color_theme_name(char *theme_name)
} }
} }
snprintf(theme_name, MAX_LENGTH, "%s on %s", color_name[0], snprintf(theme_name, BUFSIZ, "%s on %s", color_name[0],
color_name[1]); color_name[1]);
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: day.c,v 1.20 2007/03/10 15:55:25 culot Exp $ */ /* $calcurse: day.c,v 1.21 2007/04/04 19:38:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -404,6 +404,7 @@ day_edit_item(int year, int month, int day, int item_num)
#define END '2' #define END '2'
#define DESC '3' #define DESC '3'
#define REPT '4' #define REPT '4'
struct day_item_s *p; struct day_item_s *p;
struct recur_event_s *re; struct recur_event_s *re;
struct rpt_s *rpt; struct rpt_s *rpt;
@ -520,7 +521,7 @@ day_edit_item(int year, int month, int day, int item_num)
while ( (ch != 'D') && (ch != 'W') && (ch != 'M') while ( (ch != 'D') && (ch != 'W') && (ch != 'M')
&& (ch != 'Y') ) { && (ch != 'Y') ) {
status_mesg(mesg_type_1, mesg_type_2); status_mesg(mesg_type_1, mesg_type_2);
typestr = (char *) malloc(sizeof(char)); typestr = (char *)malloc(sizeof(char) * 2);
*typestr = recur_def2char(rpt->type); *typestr = recur_def2char(rpt->type);
cancel = updatestring(swin, &typestr, 0, 1); cancel = updatestring(swin, &typestr, 0, 1);
ch = toupper(*typestr); ch = toupper(*typestr);
@ -530,8 +531,8 @@ day_edit_item(int year, int month, int day, int item_num)
} }
while (newfreq == 0) { while (newfreq == 0) {
status_mesg(mesg_freq_1, ""); status_mesg(mesg_freq_1, "");
freqstr = (char *) malloc(MAX_LENGTH); freqstr = (char *) malloc(BUFSIZ);
snprintf(freqstr, MAX_LENGTH, "%d", rpt->freq); snprintf(freqstr, BUFSIZ, "%d", rpt->freq);
cancel = updatestring(swin, &freqstr, 0, 1); cancel = updatestring(swin, &freqstr, 0, 1);
newfreq = atoi(freqstr); newfreq = atoi(freqstr);
free(freqstr); free(freqstr);

View File

@ -1,4 +1,4 @@
/* $calcurse: day.h,v 1.10 2007/03/10 15:55:25 culot Exp $ */ /* $calcurse: day.h,v 1.11 2007/04/04 19:41:27 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,6 +27,8 @@
#ifndef CALCURSE_DAY_H #ifndef CALCURSE_DAY_H
#define CALCURSE_DAY_H #define CALCURSE_DAY_H
#include <stdio.h>
#include "vars.h" #include "vars.h"
#include "apoint.h" #include "apoint.h"
@ -49,8 +51,8 @@ struct day_item_s {
}; };
struct day_saved_item_s { struct day_saved_item_s {
char start[MAX_LENGTH]; char start[BUFSIZ];
char end[MAX_LENGTH]; char end[BUFSIZ];
char state; char state;
char type ; char type ;
char *mesg; char *mesg;

View File

@ -1,4 +1,4 @@
/* $calcurse: help.c,v 1.15 2007/03/24 23:19:48 culot Exp $ */ /* $calcurse: help.c,v 1.16 2007/04/04 19:38:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -26,6 +26,7 @@
#include <ncurses.h> #include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <ctype.h> #include <ctype.h>
@ -51,7 +52,7 @@ write_help_pad(WINDOW *win, char *title, char *text, int pad_width)
nl_text = get_help_lines(text); nl_text = get_help_lines(text);
nl_title = get_help_lines(title); nl_title = get_help_lines(title);
erase_window_part(win, 0, 0, MAX_LENGTH, pad_width); erase_window_part(win, 0, 0, BUFSIZ, pad_width);
custom_apply_attr(win, ATTR_HIGHEST); custom_apply_attr(win, ATTR_HIGHEST);
mvwprintw(win, 0, 0, "%s", title); mvwprintw(win, 0, 0, "%s", title);
custom_remove_attr(win, ATTR_HIGHEST); custom_remove_attr(win, ATTR_HIGHEST);
@ -77,7 +78,7 @@ help_screen(int which_pan)
{ {
WINDOW *help_win = NULL; WINDOW *help_win = NULL;
WINDOW *help_pad = NULL; WINDOW *help_pad = NULL;
char label[MAX_LENGTH]; char label[BUFSIZ];
int ch = '?'; int ch = '?';
int help_row, text_lines; int help_row, text_lines;
int help_col = col; int help_col = col;
@ -364,9 +365,9 @@ help_screen(int which_pan)
help_row = (notify_bar()) ? row - 3 : row - 2; help_row = (notify_bar()) ? row - 3 : row - 2;
text_lines = help_row - (pad_offset + 1); text_lines = help_row - (pad_offset + 1);
help_win = newwin(help_row, help_col, 0, 0); help_win = newwin(help_row, help_col, 0, 0);
help_pad = newpad(MAX_LENGTH, pad_width); help_pad = newpad(BUFSIZ, pad_width);
box(help_win, 0, 0); box(help_win, 0, 0);
snprintf(label, MAX_LENGTH, _("CalCurse %s | help"), VERSION); snprintf(label, BUFSIZ, _("CalCurse %s | help"), VERSION);
win_show(help_win, label); win_show(help_win, label);
/* Display the help screen related to user input. */ /* Display the help screen related to user input. */

View File

@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.13 2007/03/24 23:20:49 culot Exp $ */ /* $calcurse: io.c,v 1.14 2007/04/04 19:38:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -143,11 +143,11 @@ io_get_export_stream(void)
_("Press [ENTER] to continue."); _("Press [ENTER] to continue.");
stream = NULL; stream = NULL;
stream_name = (char *)malloc(MAX_LENGTH); stream_name = (char *)malloc(BUFSIZ);
home = getenv("HOME"); home = getenv("HOME");
if (home == NULL) if (home == NULL)
home = "."; home = ".";
snprintf(stream_name, MAX_LENGTH, "%s/calcurse.ics", home); snprintf(stream_name, BUFSIZ, "%s/calcurse.ics", home);
while (stream == NULL) { while (stream == NULL) {
status_mesg(question, ""); status_mesg(question, "");
@ -198,7 +198,7 @@ io_export_recur_events(FILE *stream)
{ {
struct recur_event_s *i; struct recur_event_s *i;
struct days_s *day; struct days_s *day;
char ical_date[MAX_LENGTH]; char ical_date[BUFSIZ];
for (i = recur_elist; i != 0; i = i->next) { for (i = recur_elist; i != 0; i = i->next) {
date_sec2ical_date(i->day, ical_date); date_sec2ical_date(i->day, ical_date);
@ -233,7 +233,7 @@ void
io_export_events(FILE *stream) io_export_events(FILE *stream)
{ {
struct event_s *i; struct event_s *i;
char ical_date[MAX_LENGTH]; char ical_date[BUFSIZ];
for (i = eventlist; i != 0; i = i->next) { for (i = eventlist; i != 0; i = i->next) {
date_sec2ical_date(i->day, ical_date); date_sec2ical_date(i->day, ical_date);
@ -250,8 +250,8 @@ io_export_recur_apoints(FILE *stream)
{ {
recur_apoint_llist_node_t *i; recur_apoint_llist_node_t *i;
struct days_s *day; struct days_s *day;
char ical_datetime[MAX_LENGTH]; char ical_datetime[BUFSIZ];
char ical_date[MAX_LENGTH]; char ical_date[BUFSIZ];
pthread_mutex_lock(&(recur_alist_p->mutex)); pthread_mutex_lock(&(recur_alist_p->mutex));
for (i = recur_alist_p->root; i != 0; i = i->next) { for (i = recur_alist_p->root; i != 0; i = i->next) {
@ -292,7 +292,7 @@ void
io_export_apoints(FILE *stream) io_export_apoints(FILE *stream)
{ {
apoint_llist_node_t *i; apoint_llist_node_t *i;
char ical_datetime[MAX_LENGTH]; char ical_datetime[BUFSIZ];
pthread_mutex_lock(&(alist_p->mutex)); pthread_mutex_lock(&(alist_p->mutex));
for (i = alist_p->root; i != 0; i = i->next) { for (i = alist_p->root; i != 0; i = i->next) {
@ -333,21 +333,21 @@ io_init(char *cfile)
{ {
FILE *data_file; FILE *data_file;
char *home; char *home;
char apts_file[MAX_LENGTH] = ""; char apts_file[BUFSIZ] = "";
int ch; int ch;
home = getenv("HOME"); home = getenv("HOME");
if (home == NULL) { if (home == NULL) {
home = "."; home = ".";
} }
snprintf(path_dir, MAX_LENGTH, "%s/" DIR_NAME, home); snprintf(path_dir, BUFSIZ, "%s/" DIR_NAME, home);
snprintf(path_todo, MAX_LENGTH, "%s/" TODO_PATH, home); snprintf(path_todo, BUFSIZ, "%s/" TODO_PATH, home);
snprintf(path_conf, MAX_LENGTH, "%s/" CONF_PATH, home); snprintf(path_conf, BUFSIZ, "%s/" CONF_PATH, home);
if (cfile == NULL) { if (cfile == NULL) {
snprintf(path_apts, MAX_LENGTH, "%s/" APTS_PATH, home); snprintf(path_apts, BUFSIZ, "%s/" APTS_PATH, home);
} else { } else {
snprintf(apts_file, MAX_LENGTH, "%s", cfile); snprintf(apts_file, BUFSIZ, "%s", cfile);
strncpy(path_apts, apts_file, MAX_LENGTH); strncpy(path_apts, apts_file, BUFSIZ);
/* check if the file exists, otherwise create it */ /* check if the file exists, otherwise create it */
data_file = fopen(path_apts, "r"); data_file = fopen(path_apts, "r");
if (data_file == NULL) { if (data_file == NULL) {
@ -402,7 +402,7 @@ io_save_cal(conf_t *conf, int layout)
struct event_s *k; struct event_s *k;
apoint_llist_node_t *j; apoint_llist_node_t *j;
struct todo_s *i; struct todo_s *i;
char theme_name[MAX_LENGTH]; char theme_name[BUFSIZ];
char *access_pb = _("Problems accessing data file ..."); char *access_pb = _("Problems accessing data file ...");
char *config_txt = char *config_txt =
"#\n# Calcurse configuration file\n#\n# This file sets the configuration options used by Calcurse. These\n# options are usually set from within Calcurse. A line beginning with \n# a space or tab is considered to be a continuation of the previous line.\n# For a variable to be unset its value must be blank.\n# To set a variable to the empty string its value should be \"\".\n# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n"; "#\n# Calcurse configuration file\n#\n# This file sets the configuration options used by Calcurse. These\n# options are usually set from within Calcurse. A line beginning with \n# a space or tab is considered to be a continuation of the previous line.\n# For a variable to be unset its value must be blank.\n# To set a variable to the empty string its value should be \"\".\n# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n";
@ -695,7 +695,7 @@ load_todo(void)
char *nl; char *nl;
int nb_tod = 0; int nb_tod = 0;
int c, id; int c, id;
char buf[MAX_LENGTH], e_todo[MAX_LENGTH]; char buf[BUFSIZ], e_todo[BUFSIZ];
data_file = fopen(path_todo, "r"); data_file = fopen(path_todo, "r");
if (data_file == NULL) { if (data_file == NULL) {
@ -712,7 +712,7 @@ load_todo(void)
id = 9; id = 9;
ungetc(c, data_file); ungetc(c, data_file);
} }
fgets(buf, MAX_LENGTH, data_file); fgets(buf, BUFSIZ, data_file);
nl = strchr(buf, '\n'); nl = strchr(buf, '\n');
if (nl) { if (nl) {
*nl = '\0'; *nl = '\0';

View File

@ -1,4 +1,4 @@
/* $calcurse: recur.c,v 1.23 2007/03/10 16:48:19 culot Exp $ */ /* $calcurse: recur.c,v 1.24 2007/04/04 19:38:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -26,6 +26,7 @@
#include <ncurses.h> #include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
@ -121,7 +122,9 @@ struct recur_event_s *recur_event_new(char *mesg, long day, int id,
* Correspondance between the defines on recursive type, * Correspondance between the defines on recursive type,
* and the letter to be written in file. * and the letter to be written in file.
*/ */
char recur_def2char(int define){ char
recur_def2char(int define)
{
char recur_char; char recur_char;
switch (define) { switch (define) {
@ -138,7 +141,8 @@ char recur_def2char(int define){
recur_char = 'Y'; recur_char = 'Y';
break; break;
} }
return recur_char;
return (recur_char);
} }
/* /*
@ -572,7 +576,7 @@ recur_repeat_item(int sel_year, int sel_month, int sel_day,
int ch = 0; int ch = 0;
int valid_date = 0, date_entered = 0; int valid_date = 0, date_entered = 0;
int year = 0, month = 0, day = 0; int year = 0, month = 0, day = 0;
char user_input[MAX_LENGTH] = ""; char user_input[BUFSIZ] = "";
char *mesg_type_1 = char *mesg_type_1 =
_("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early"); _("Enter the repetition type: (D)aily, (W)eekly, (M)onthly, (Y)early");
char *mesg_type_2 = _("[D/W/M/Y] "); char *mesg_type_2 = _("[D/W/M/Y] ");
@ -617,7 +621,7 @@ recur_repeat_item(int sel_year, int sel_month, int sel_day,
while (freq == 0) { while (freq == 0) {
status_mesg(mesg_freq_1, ""); status_mesg(mesg_freq_1, "");
if (getstring(swin, user_input, MAX_LENGTH, 0, 1) == if (getstring(swin, user_input, BUFSIZ, 0, 1) ==
GETSTRING_VALID) { GETSTRING_VALID) {
freq = atoi(user_input); freq = atoi(user_input);
if (freq == 0) { if (freq == 0) {

View File

@ -1,4 +1,4 @@
/* $calcurse: todo.c,v 1.10 2007/03/10 15:54:59 culot Exp $ */ /* $calcurse: todo.c,v 1.11 2007/04/04 19:38:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -43,10 +43,10 @@ todo_new_item(int total)
char *mesg = _("Enter the new ToDo item : "); char *mesg = _("Enter the new ToDo item : ");
char *mesg_id = char *mesg_id =
_("Enter the ToDo priority [1 (highest) - 9 (lowest)] :"); _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
char todo_input[MAX_LENGTH] = ""; char todo_input[BUFSIZ] = "";
status_mesg(mesg, ""); status_mesg(mesg, "");
if (getstring(swin, todo_input, MAX_LENGTH, 0, 1) == if (getstring(swin, todo_input, BUFSIZ, 0, 1) ==
GETSTRING_VALID) { GETSTRING_VALID) {
while ( (ch < '1') || (ch > '9') ) { while ( (ch < '1') || (ch > '9') ) {
status_mesg(mesg_id, ""); status_mesg(mesg_id, "");
@ -149,7 +149,7 @@ int
todo_chg_priority(int action, int item_num) todo_chg_priority(int action, int item_num)
{ {
struct todo_s *backup; struct todo_s *backup;
char backup_mesg[MAX_LENGTH]; char backup_mesg[BUFSIZ];
int backup_id; int backup_id;
int do_chg = 1, new_position; int do_chg = 1, new_position;

View File

@ -1,4 +1,4 @@
/* $calcurse: vars.h,v 1.8 2007/03/24 23:22:16 culot Exp $ */ /* $calcurse: vars.h,v 1.9 2007/04/04 19:38:18 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -30,17 +30,15 @@
#include <ncurses.h> #include <ncurses.h>
#include <pthread.h> #include <pthread.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#define DIR_NAME ".calcurse" #define DIR_NAME ".calcurse"
#define TODO_PATH ".calcurse/todo" #define TODO_PATH ".calcurse/todo"
#define APTS_PATH ".calcurse/apts" #define APTS_PATH ".calcurse/apts"
#define CONF_PATH ".calcurse/conf" #define CONF_PATH ".calcurse/conf"
#define MAX_LENGTH 512
#define CTRL(x) ((x) & 0x1f) #define CTRL(x) ((x) & 0x1f)
#define ESCAPE 27 #define ESCAPE 27
#define ATTR_FALSE 0 #define ATTR_FALSE 0
#define ATTR_TRUE 1 #define ATTR_TRUE 1
#define ATTR_LOWEST 2 #define ATTR_LOWEST 2
@ -64,9 +62,9 @@ struct nbar_s {
int show; /* display or hide the notify-bar */ int show; /* display or hide the notify-bar */
int cntdwn; /* warn when time left before next app int cntdwn; /* warn when time left before next app
* becomes lesser than cntdwn */ * becomes lesser than cntdwn */
char datefmt[MAX_LENGTH]; /* format for displaying date */ char datefmt[BUFSIZ]; /* format for displaying date */
char timefmt[MAX_LENGTH]; /* format for displaying time */ char timefmt[BUFSIZ]; /* format for displaying time */
char cmd[MAX_LENGTH]; /* notification command */ char cmd[BUFSIZ]; /* notification command */
char *shell; /* user shell to launch notif. cmd */ char *shell; /* user shell to launch notif. cmd */
pthread_mutex_t mutex; pthread_mutex_t mutex;
}; };
@ -86,10 +84,10 @@ extern bool colorize;
extern int days[12]; extern int days[12];
extern char *monthnames[12]; extern char *monthnames[12];
extern char *daynames[8]; extern char *daynames[8];
extern char path_dir[MAX_LENGTH]; extern char path_dir[BUFSIZ];
extern char path_todo[MAX_LENGTH]; extern char path_todo[BUFSIZ];
extern char path_apts[MAX_LENGTH]; extern char path_apts[BUFSIZ];
extern char path_conf[MAX_LENGTH]; extern char path_conf[BUFSIZ];
extern WINDOW *awin, *cwin, *twin, *swin; extern WINDOW *awin, *cwin, *twin, *swin;
extern struct pad_s *apad; extern struct pad_s *apad;
extern struct nbar_s *nbar; extern struct nbar_s *nbar;