Get rid of string structures
These were only used to construct constant strings with additional length fields. However, we can just use standard constant character arrays instead and let the compiler calculate the string length. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
2c9499bf27
commit
0f4b45e624
@ -210,7 +210,6 @@
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define STRING_BUILD(str) {str, sizeof (str) - 1}
|
|
||||||
#define STRINGIFY(x) #x
|
#define STRINGIFY(x) #x
|
||||||
#define TOSTRING(x) STRINGIFY(x)
|
#define TOSTRING(x) STRINGIFY(x)
|
||||||
#define __FILE_POS__ __FILE__ ":" TOSTRING(__LINE__)
|
#define __FILE_POS__ __FILE__ ":" TOSTRING(__LINE__)
|
||||||
@ -248,11 +247,6 @@ struct dmon_conf {
|
|||||||
unsigned log; /* log daemon activity */
|
unsigned log; /* log daemon activity */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct string {
|
|
||||||
const char *str;
|
|
||||||
const int len;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum datefmt {
|
enum datefmt {
|
||||||
DATEFMT_MMDDYYYY = 1,
|
DATEFMT_MMDDYYYY = 1,
|
||||||
DATEFMT_DDMMYYYY,
|
DATEFMT_DDMMYYYY,
|
||||||
|
100
src/ical.c
100
src/ical.c
@ -465,14 +465,14 @@ static float
|
|||||||
ical_chk_header (FILE *fd, char *buf, char *lstore, unsigned *lineno)
|
ical_chk_header (FILE *fd, char *buf, char *lstore, unsigned *lineno)
|
||||||
{
|
{
|
||||||
const int HEADER_MALFORMED = -1;
|
const int HEADER_MALFORMED = -1;
|
||||||
const struct string icalheader = STRING_BUILD ("BEGIN:VCALENDAR");
|
const char icalheader[] = "BEGIN:VCALENDAR";
|
||||||
float version;
|
float version;
|
||||||
|
|
||||||
if (!ical_readline (fd, buf, lstore, lineno))
|
if (!ical_readline (fd, buf, lstore, lineno))
|
||||||
return HEADER_MALFORMED;
|
return HEADER_MALFORMED;
|
||||||
|
|
||||||
str_toupper (buf);
|
str_toupper (buf);
|
||||||
if (strcmp (buf, icalheader.str) != 0)
|
if (strcmp (buf, icalheader) != 0)
|
||||||
return HEADER_MALFORMED;
|
return HEADER_MALFORMED;
|
||||||
|
|
||||||
while (!sscanf (buf, "VERSION:%f", &version))
|
while (!sscanf (buf, "VERSION:%f", &version))
|
||||||
@ -702,12 +702,12 @@ static ical_rpt_t *
|
|||||||
ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
|
ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
|
||||||
const int itemline)
|
const int itemline)
|
||||||
{
|
{
|
||||||
const struct string daily = STRING_BUILD ("DAILY");
|
const char daily[] = "DAILY";
|
||||||
const struct string weekly = STRING_BUILD ("WEEKLY");
|
const char weekly[] = "WEEKLY";
|
||||||
const struct string monthly = STRING_BUILD ("MONTHLY");
|
const char monthly[] = "MONTHLY";
|
||||||
const struct string yearly = STRING_BUILD ("YEARLY");
|
const char yearly[] = "YEARLY";
|
||||||
const struct string count = STRING_BUILD ("COUNT=");
|
const char count[] = "COUNT=";
|
||||||
const struct string interv = STRING_BUILD ("INTERVAL=");
|
const char interv[] = "INTERVAL=";
|
||||||
unsigned interval;
|
unsigned interval;
|
||||||
ical_rpt_t *rpt;
|
ical_rpt_t *rpt;
|
||||||
char *p;
|
char *p;
|
||||||
@ -730,13 +730,13 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (strcmp (freqstr, daily.str) == 0)
|
if (strcmp (freqstr, daily) == 0)
|
||||||
rpt->type = RECUR_DAILY;
|
rpt->type = RECUR_DAILY;
|
||||||
else if (strcmp (freqstr, weekly.str) == 0)
|
else if (strcmp (freqstr, weekly) == 0)
|
||||||
rpt->type = RECUR_WEEKLY;
|
rpt->type = RECUR_WEEKLY;
|
||||||
else if (strcmp (freqstr, monthly.str) == 0)
|
else if (strcmp (freqstr, monthly) == 0)
|
||||||
rpt->type = RECUR_MONTHLY;
|
rpt->type = RECUR_MONTHLY;
|
||||||
else if (strcmp (freqstr, yearly.str) == 0)
|
else if (strcmp (freqstr, yearly) == 0)
|
||||||
rpt->type = RECUR_YEARLY;
|
rpt->type = RECUR_YEARLY;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -769,9 +769,9 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
|
|||||||
unsigned cnt;
|
unsigned cnt;
|
||||||
char *countstr;
|
char *countstr;
|
||||||
|
|
||||||
if ((countstr = strstr (rrulestr, count.str)) != NULL)
|
if ((countstr = strstr (rrulestr, count)) != NULL)
|
||||||
{
|
{
|
||||||
countstr += count.len;
|
countstr += sizeof (count) - 1;
|
||||||
if (sscanf (countstr, "%u", &cnt) != 1)
|
if (sscanf (countstr, "%u", &cnt) != 1)
|
||||||
{
|
{
|
||||||
rpt->until = 0;
|
rpt->until = 0;
|
||||||
@ -786,9 +786,9 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
|
|||||||
rpt->until = 0;
|
rpt->until = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p = strstr (rrulestr, interv.str)) != NULL)
|
if ((p = strstr (rrulestr, interv)) != NULL)
|
||||||
{
|
{
|
||||||
p += interv.len;
|
p += sizeof (interv) - 1;
|
||||||
if (sscanf (p, "%u", &interval) != 1)
|
if (sscanf (p, "%u", &interval) != 1)
|
||||||
{
|
{
|
||||||
rpt->freq = 1;
|
rpt->freq = 1;
|
||||||
@ -921,16 +921,16 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
unsigned *lineno)
|
unsigned *lineno)
|
||||||
{
|
{
|
||||||
const int ITEMLINE = *lineno;
|
const int ITEMLINE = *lineno;
|
||||||
const struct string endevent = STRING_BUILD ("END:VEVENT");
|
const char endevent[] = "END:VEVENT";
|
||||||
const struct string summary = STRING_BUILD ("SUMMARY");
|
const char summary[] = "SUMMARY";
|
||||||
const struct string dtstart = STRING_BUILD ("DTSTART");
|
const char dtstart[] = "DTSTART";
|
||||||
const struct string dtend = STRING_BUILD ("DTEND");
|
const char dtend[] = "DTEND";
|
||||||
const struct string duration = STRING_BUILD ("DURATION");
|
const char duration[] = "DURATION";
|
||||||
const struct string rrule = STRING_BUILD ("RRULE");
|
const char rrule[] = "RRULE";
|
||||||
const struct string exdate = STRING_BUILD ("EXDATE");
|
const char exdate[] = "EXDATE";
|
||||||
const struct string alarm = STRING_BUILD ("BEGIN:VALARM");
|
const char alarm[] = "BEGIN:VALARM";
|
||||||
const struct string endalarm = STRING_BUILD ("END:VALARM");
|
const char endalarm[] = "END:VALARM";
|
||||||
const struct string desc = STRING_BUILD ("DESCRIPTION");
|
const char desc[] = "DESCRIPTION";
|
||||||
ical_vevent_e vevent_type;
|
ical_vevent_e vevent_type;
|
||||||
char *p, buf_upper[BUFSIZ];
|
char *p, buf_upper[BUFSIZ];
|
||||||
struct {
|
struct {
|
||||||
@ -955,11 +955,11 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
{
|
{
|
||||||
/* Need to skip VALARM properties because some keywords could
|
/* Need to skip VALARM properties because some keywords could
|
||||||
interfere, such as DURATION, SUMMARY,.. */
|
interfere, such as DURATION, SUMMARY,.. */
|
||||||
if (strcmp (buf_upper, endalarm.str) == 0)
|
if (strcmp (buf_upper, endalarm) == 0)
|
||||||
skip_alarm = 0;
|
skip_alarm = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp (buf_upper, endevent.str) == 0)
|
if (strcmp (buf_upper, endevent) == 0)
|
||||||
{
|
{
|
||||||
if (vevent.mesg)
|
if (vevent.mesg)
|
||||||
{
|
{
|
||||||
@ -1039,7 +1039,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (strcmp (buf_upper, dtstart.str) == 0)
|
if (strcmp (buf_upper, dtstart) == 0)
|
||||||
{
|
{
|
||||||
if ((p = strchr (buf, ':')) != NULL)
|
if ((p = strchr (buf, ':')) != NULL)
|
||||||
vevent.start = ical_datetime2long (++p, &vevent_type);
|
vevent.start = ical_datetime2long (++p, &vevent_type);
|
||||||
@ -1050,7 +1050,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, dtend.str) == 0)
|
else if (strcmp (buf_upper, dtend) == 0)
|
||||||
{
|
{
|
||||||
if ((p = strchr (buf, ':')) != NULL)
|
if ((p = strchr (buf, ':')) != NULL)
|
||||||
vevent.end = ical_datetime2long (++p, &vevent_type);
|
vevent.end = ical_datetime2long (++p, &vevent_type);
|
||||||
@ -1061,7 +1061,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, duration.str) == 0)
|
else if (strcmp (buf_upper, duration) == 0)
|
||||||
{
|
{
|
||||||
if ((vevent.dur = ical_dur2long (buf)) <= 0)
|
if ((vevent.dur = ical_dur2long (buf)) <= 0)
|
||||||
{
|
{
|
||||||
@ -1070,24 +1070,24 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, rrule.str) == 0)
|
else if (strcmp (buf_upper, rrule) == 0)
|
||||||
{
|
{
|
||||||
vevent.rpt = ical_read_rrule (log, buf, noskipped, ITEMLINE);
|
vevent.rpt = ical_read_rrule (log, buf, noskipped, ITEMLINE);
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, exdate.str) == 0)
|
else if (strcmp (buf_upper, exdate) == 0)
|
||||||
{
|
{
|
||||||
ical_read_exdate (&vevent.exc, log, buf, noskipped, ITEMLINE);
|
ical_read_exdate (&vevent.exc, log, buf, noskipped, ITEMLINE);
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, summary.str) == 0)
|
else if (strcmp (buf_upper, summary) == 0)
|
||||||
{
|
{
|
||||||
vevent.mesg = ical_read_summary (buf);
|
vevent.mesg = ical_read_summary (buf);
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, alarm.str) == 0)
|
else if (strcmp (buf_upper, alarm) == 0)
|
||||||
{
|
{
|
||||||
skip_alarm = 1;
|
skip_alarm = 1;
|
||||||
vevent.has_alarm = 1;
|
vevent.has_alarm = 1;
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, desc.str) == 0)
|
else if (strcmp (buf_upper, desc) == 0)
|
||||||
{
|
{
|
||||||
vevent.note = ical_read_note (buf, noskipped, ICAL_VEVENT,
|
vevent.note = ical_read_note (buf, noskipped, ICAL_VEVENT,
|
||||||
ITEMLINE, log);
|
ITEMLINE, log);
|
||||||
@ -1114,11 +1114,11 @@ static void
|
|||||||
ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped,
|
ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped,
|
||||||
char *buf, char *lstore, unsigned *lineno)
|
char *buf, char *lstore, unsigned *lineno)
|
||||||
{
|
{
|
||||||
const struct string endtodo = STRING_BUILD ("END:VTODO");
|
const char endtodo[] = "END:VTODO";
|
||||||
const struct string summary = STRING_BUILD ("SUMMARY");
|
const char summary[] = "SUMMARY";
|
||||||
const struct string alarm = STRING_BUILD ("BEGIN:VALARM");
|
const char alarm[] = "BEGIN:VALARM";
|
||||||
const struct string endalarm = STRING_BUILD ("END:VALARM");
|
const char endalarm[] = "END:VALARM";
|
||||||
const struct string desc = STRING_BUILD ("DESCRIPTION");
|
const char desc[] = "DESCRIPTION";
|
||||||
const int LOWEST = 9;
|
const int LOWEST = 9;
|
||||||
const int ITEMLINE = *lineno;
|
const int ITEMLINE = *lineno;
|
||||||
char buf_upper[BUFSIZ];
|
char buf_upper[BUFSIZ];
|
||||||
@ -1139,11 +1139,11 @@ ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped,
|
|||||||
{
|
{
|
||||||
/* Need to skip VALARM properties because some keywords could
|
/* Need to skip VALARM properties because some keywords could
|
||||||
interfere, such as DURATION, SUMMARY,.. */
|
interfere, such as DURATION, SUMMARY,.. */
|
||||||
if (strcmp (buf_upper, endalarm.str) == 0)
|
if (strcmp (buf_upper, endalarm) == 0)
|
||||||
skip_alarm = 0;
|
skip_alarm = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp (buf_upper, endtodo.str) == 0)
|
if (strcmp (buf_upper, endtodo) == 0)
|
||||||
{
|
{
|
||||||
if (!vtodo.has_priority)
|
if (!vtodo.has_priority)
|
||||||
vtodo.priority = LOWEST;
|
vtodo.priority = LOWEST;
|
||||||
@ -1179,15 +1179,15 @@ ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped,
|
|||||||
vtodo.priority = LOWEST;
|
vtodo.priority = LOWEST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, summary.str) == 0)
|
else if (strcmp (buf_upper, summary) == 0)
|
||||||
{
|
{
|
||||||
vtodo.mesg = ical_read_summary (buf);
|
vtodo.mesg = ical_read_summary (buf);
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, alarm.str) == 0)
|
else if (strcmp (buf_upper, alarm) == 0)
|
||||||
{
|
{
|
||||||
skip_alarm = 1;
|
skip_alarm = 1;
|
||||||
}
|
}
|
||||||
else if (strcmp (buf_upper, desc.str) == 0)
|
else if (strcmp (buf_upper, desc) == 0)
|
||||||
{
|
{
|
||||||
vtodo.note = ical_read_note (buf, noskipped, ICAL_VTODO,
|
vtodo.note = ical_read_note (buf, noskipped, ICAL_VTODO,
|
||||||
ITEMLINE, log);
|
ITEMLINE, log);
|
||||||
@ -1212,8 +1212,8 @@ void
|
|||||||
ical_import_data (FILE *stream, FILE *log, unsigned *events, unsigned *apoints,
|
ical_import_data (FILE *stream, FILE *log, unsigned *events, unsigned *apoints,
|
||||||
unsigned *todos, unsigned *lines, unsigned *skipped)
|
unsigned *todos, unsigned *lines, unsigned *skipped)
|
||||||
{
|
{
|
||||||
const struct string vevent = STRING_BUILD ("BEGIN:VEVENT");
|
const char vevent[] = "BEGIN:VEVENT";
|
||||||
const struct string vtodo = STRING_BUILD ("BEGIN:VTODO");
|
const char vtodo[] = "BEGIN:VTODO";
|
||||||
char buf[BUFSIZ], lstore[BUFSIZ];
|
char buf[BUFSIZ], lstore[BUFSIZ];
|
||||||
float ical_version;
|
float ical_version;
|
||||||
|
|
||||||
@ -1229,12 +1229,12 @@ ical_import_data (FILE *stream, FILE *log, unsigned *events, unsigned *apoints,
|
|||||||
{
|
{
|
||||||
(*lines)++;
|
(*lines)++;
|
||||||
str_toupper (buf);
|
str_toupper (buf);
|
||||||
if (strcmp (buf, vevent.str) == 0)
|
if (strcmp (buf, vevent) == 0)
|
||||||
{
|
{
|
||||||
ical_read_event (stream, log, events, apoints, skipped, buf, lstore,
|
ical_read_event (stream, log, events, apoints, skipped, buf, lstore,
|
||||||
lines);
|
lines);
|
||||||
}
|
}
|
||||||
else if (strcmp (buf, vtodo.str) == 0)
|
else if (strcmp (buf, vtodo) == 0)
|
||||||
{
|
{
|
||||||
ical_read_todo (stream, log, todos, skipped, buf, lstore, lines);
|
ical_read_todo (stream, log, todos, skipped, buf, lstore, lines);
|
||||||
}
|
}
|
||||||
|
42
src/keys.c
42
src/keys.c
@ -303,16 +303,16 @@ keys_remove_binding (int key, enum key action)
|
|||||||
int
|
int
|
||||||
keys_str2int (char *key)
|
keys_str2int (char *key)
|
||||||
{
|
{
|
||||||
const struct string CONTROL_KEY = STRING_BUILD ("C-");
|
const char CONTROL_KEY[] = "C-";
|
||||||
const struct string TAB_KEY = STRING_BUILD ("TAB");
|
const char TAB_KEY[] = "TAB";
|
||||||
const struct string SPACE_KEY = STRING_BUILD ("SPC");
|
const char SPACE_KEY[] = "SPC";
|
||||||
const struct string ESCAPE_KEY = STRING_BUILD ("ESC");
|
const char ESCAPE_KEY[] = "ESC";
|
||||||
const struct string CURSES_KEY_UP = STRING_BUILD ("UP");
|
const char CURSES_KEY_UP[] = "UP";
|
||||||
const struct string CURSES_KEY_DOWN = STRING_BUILD ("DWN");
|
const char CURSES_KEY_DOWN[] = "DWN";
|
||||||
const struct string CURSES_KEY_LEFT = STRING_BUILD ("LFT");
|
const char CURSES_KEY_LEFT[] = "LFT";
|
||||||
const struct string CURSES_KEY_RIGHT = STRING_BUILD ("RGT");
|
const char CURSES_KEY_RIGHT[] = "RGT";
|
||||||
const struct string CURSES_KEY_HOME = STRING_BUILD ("KEY_HOME");
|
const char CURSES_KEY_HOME[] = "KEY_HOME";
|
||||||
const struct string CURSES_KEY_END = STRING_BUILD ("KEY_END");
|
const char CURSES_KEY_END[] = "KEY_END";
|
||||||
|
|
||||||
if (!key)
|
if (!key)
|
||||||
return -1;
|
return -1;
|
||||||
@ -322,25 +322,25 @@ keys_str2int (char *key)
|
|||||||
{
|
{
|
||||||
if (key[0] == '^')
|
if (key[0] == '^')
|
||||||
return CTRL ((int)key[1]);
|
return CTRL ((int)key[1]);
|
||||||
else if (!strcmp (key, CONTROL_KEY.str))
|
else if (!strcmp (key, CONTROL_KEY))
|
||||||
return CTRL ((int)key[CONTROL_KEY.len]);
|
return CTRL ((int)key[sizeof (CONTROL_KEY) - 1]);
|
||||||
else if (!strcmp (key, TAB_KEY.str))
|
else if (!strcmp (key, TAB_KEY))
|
||||||
return TAB;
|
return TAB;
|
||||||
else if (!strcmp (key, ESCAPE_KEY.str))
|
else if (!strcmp (key, ESCAPE_KEY))
|
||||||
return ESCAPE;
|
return ESCAPE;
|
||||||
else if (!strcmp (key, SPACE_KEY.str))
|
else if (!strcmp (key, SPACE_KEY))
|
||||||
return SPACE;
|
return SPACE;
|
||||||
else if (!strcmp (key, CURSES_KEY_UP.str))
|
else if (!strcmp (key, CURSES_KEY_UP))
|
||||||
return KEY_UP;
|
return KEY_UP;
|
||||||
else if (!strcmp (key, CURSES_KEY_DOWN.str))
|
else if (!strcmp (key, CURSES_KEY_DOWN))
|
||||||
return KEY_DOWN;
|
return KEY_DOWN;
|
||||||
else if (!strcmp (key, CURSES_KEY_LEFT.str))
|
else if (!strcmp (key, CURSES_KEY_LEFT))
|
||||||
return KEY_LEFT;
|
return KEY_LEFT;
|
||||||
else if (!strcmp (key, CURSES_KEY_RIGHT.str))
|
else if (!strcmp (key, CURSES_KEY_RIGHT))
|
||||||
return KEY_RIGHT;
|
return KEY_RIGHT;
|
||||||
else if (!strcmp (key, CURSES_KEY_HOME.str))
|
else if (!strcmp (key, CURSES_KEY_HOME))
|
||||||
return KEY_HOME;
|
return KEY_HOME;
|
||||||
else if (!strcmp (key, CURSES_KEY_END.str))
|
else if (!strcmp (key, CURSES_KEY_END))
|
||||||
return KEY_END;
|
return KEY_END;
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user