summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-03-01 23:44:27 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2012-03-12 20:36:22 +0100
commit0f4b45e62487e32e789571912fd2190168f753bc (patch)
tree69ba14eb3255f91d59856283e9568395f92d92fc
parent2c9499bf272e06a62902711c6c20621ef3f80e64 (diff)
downloadcalcurse-0f4b45e62487e32e789571912fd2190168f753bc.tar.gz
calcurse-0f4b45e62487e32e789571912fd2190168f753bc.zip
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>
-rw-r--r--src/calcurse.h6
-rw-r--r--src/ical.c100
-rw-r--r--src/keys.c42
3 files changed, 71 insertions, 77 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index c260ef6..fa026f8 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -210,7 +210,6 @@
} \
} while (0)
-#define STRING_BUILD(str) {str, sizeof (str) - 1}
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define __FILE_POS__ __FILE__ ":" TOSTRING(__LINE__)
@@ -248,11 +247,6 @@ struct dmon_conf {
unsigned log; /* log daemon activity */
};
-struct string {
- const char *str;
- const int len;
-};
-
enum datefmt {
DATEFMT_MMDDYYYY = 1,
DATEFMT_DDMMYYYY,
diff --git a/src/ical.c b/src/ical.c
index e43331b..f176926 100644
--- a/src/ical.c
+++ b/src/ical.c
@@ -465,14 +465,14 @@ static float
ical_chk_header (FILE *fd, char *buf, char *lstore, unsigned *lineno)
{
const int HEADER_MALFORMED = -1;
- const struct string icalheader = STRING_BUILD ("BEGIN:VCALENDAR");
+ const char icalheader[] = "BEGIN:VCALENDAR";
float version;
if (!ical_readline (fd, buf, lstore, lineno))
return HEADER_MALFORMED;
str_toupper (buf);
- if (strcmp (buf, icalheader.str) != 0)
+ if (strcmp (buf, icalheader) != 0)
return HEADER_MALFORMED;
while (!sscanf (buf, "VERSION:%f", &version))
@@ -702,12 +702,12 @@ static ical_rpt_t *
ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
const int itemline)
{
- const struct string daily = STRING_BUILD ("DAILY");
- const struct string weekly = STRING_BUILD ("WEEKLY");
- const struct string monthly = STRING_BUILD ("MONTHLY");
- const struct string yearly = STRING_BUILD ("YEARLY");
- const struct string count = STRING_BUILD ("COUNT=");
- const struct string interv = STRING_BUILD ("INTERVAL=");
+ const char daily[] = "DAILY";
+ const char weekly[] = "WEEKLY";
+ const char monthly[] = "MONTHLY";
+ const char yearly[] = "YEARLY";
+ const char count[] = "COUNT=";
+ const char interv[] = "INTERVAL=";
unsigned interval;
ical_rpt_t *rpt;
char *p;
@@ -730,13 +730,13 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
}
else
{
- if (strcmp (freqstr, daily.str) == 0)
+ if (strcmp (freqstr, daily) == 0)
rpt->type = RECUR_DAILY;
- else if (strcmp (freqstr, weekly.str) == 0)
+ else if (strcmp (freqstr, weekly) == 0)
rpt->type = RECUR_WEEKLY;
- else if (strcmp (freqstr, monthly.str) == 0)
+ else if (strcmp (freqstr, monthly) == 0)
rpt->type = RECUR_MONTHLY;
- else if (strcmp (freqstr, yearly.str) == 0)
+ else if (strcmp (freqstr, yearly) == 0)
rpt->type = RECUR_YEARLY;
else
{
@@ -769,9 +769,9 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
unsigned cnt;
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)
{
rpt->until = 0;
@@ -786,9 +786,9 @@ ical_read_rrule (FILE *log, char *rrulestr, unsigned *noskipped,
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)
{
rpt->freq = 1;
@@ -921,16 +921,16 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
unsigned *lineno)
{
const int ITEMLINE = *lineno;
- const struct string endevent = STRING_BUILD ("END:VEVENT");
- const struct string summary = STRING_BUILD ("SUMMARY");
- const struct string dtstart = STRING_BUILD ("DTSTART");
- const struct string dtend = STRING_BUILD ("DTEND");
- const struct string duration = STRING_BUILD ("DURATION");
- const struct string rrule = STRING_BUILD ("RRULE");
- const struct string exdate = STRING_BUILD ("EXDATE");
- const struct string alarm = STRING_BUILD ("BEGIN:VALARM");
- const struct string endalarm = STRING_BUILD ("END:VALARM");
- const struct string desc = STRING_BUILD ("DESCRIPTION");
+ const char endevent[] = "END:VEVENT";
+ const char summary[] = "SUMMARY";
+ const char dtstart[] = "DTSTART";
+ const char dtend[] = "DTEND";
+ const char duration[] = "DURATION";
+ const char rrule[] = "RRULE";
+ const char exdate[] = "EXDATE";
+ const char alarm[] = "BEGIN:VALARM";
+ const char endalarm[] = "END:VALARM";
+ const char desc[] = "DESCRIPTION";
ical_vevent_e vevent_type;
char *p, buf_upper[BUFSIZ];
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
interfere, such as DURATION, SUMMARY,.. */
- if (strcmp (buf_upper, endalarm.str) == 0)
+ if (strcmp (buf_upper, endalarm) == 0)
skip_alarm = 0;
continue;
}
- if (strcmp (buf_upper, endevent.str) == 0)
+ if (strcmp (buf_upper, endevent) == 0)
{
if (vevent.mesg)
{
@@ -1039,7 +1039,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
}
else
{
- if (strcmp (buf_upper, dtstart.str) == 0)
+ if (strcmp (buf_upper, dtstart) == 0)
{
if ((p = strchr (buf, ':')) != NULL)
vevent.start = ical_datetime2long (++p, &vevent_type);
@@ -1050,7 +1050,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
goto cleanup;
}
}
- else if (strcmp (buf_upper, dtend.str) == 0)
+ else if (strcmp (buf_upper, dtend) == 0)
{
if ((p = strchr (buf, ':')) != NULL)
vevent.end = ical_datetime2long (++p, &vevent_type);
@@ -1061,7 +1061,7 @@ ical_read_event (FILE *fdi, FILE *log, unsigned *noevents, unsigned *noapoints,
goto cleanup;
}
}
- else if (strcmp (buf_upper, duration.str) == 0)
+ else if (strcmp (buf_upper, duration) == 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;
}
}
- else if (strcmp (buf_upper, rrule.str) == 0)
+ else if (strcmp (buf_upper, rrule) == 0)
{
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);
}
- else if (strcmp (buf_upper, summary.str) == 0)
+ else if (strcmp (buf_upper, summary) == 0)
{
vevent.mesg = ical_read_summary (buf);
}
- else if (strcmp (buf_upper, alarm.str) == 0)
+ else if (strcmp (buf_upper, alarm) == 0)
{
skip_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,
ITEMLINE, log);
@@ -1114,11 +1114,11 @@ static void
ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped,
char *buf, char *lstore, unsigned *lineno)
{
- const struct string endtodo = STRING_BUILD ("END:VTODO");
- const struct string summary = STRING_BUILD ("SUMMARY");
- const struct string alarm = STRING_BUILD ("BEGIN:VALARM");
- const struct string endalarm = STRING_BUILD ("END:VALARM");
- const struct string desc = STRING_BUILD ("DESCRIPTION");
+ const char endtodo[] = "END:VTODO";
+ const char summary[] = "SUMMARY";
+ const char alarm[] = "BEGIN:VALARM";
+ const char endalarm[] = "END:VALARM";
+ const char desc[] = "DESCRIPTION";
const int LOWEST = 9;
const int ITEMLINE = *lineno;
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
interfere, such as DURATION, SUMMARY,.. */
- if (strcmp (buf_upper, endalarm.str) == 0)
+ if (strcmp (buf_upper, endalarm) == 0)
skip_alarm = 0;
continue;
}
- if (strcmp (buf_upper, endtodo.str) == 0)
+ if (strcmp (buf_upper, endtodo) == 0)
{
if (!vtodo.has_priority)
vtodo.priority = LOWEST;
@@ -1179,15 +1179,15 @@ ical_read_todo (FILE *fdi, FILE *log, unsigned *notodos, unsigned *noskipped,
vtodo.priority = LOWEST;
}
}
- else if (strcmp (buf_upper, summary.str) == 0)
+ else if (strcmp (buf_upper, summary) == 0)
{
vtodo.mesg = ical_read_summary (buf);
}
- else if (strcmp (buf_upper, alarm.str) == 0)
+ else if (strcmp (buf_upper, alarm) == 0)
{
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,
ITEMLINE, log);
@@ -1212,8 +1212,8 @@ void
ical_import_data (FILE *stream, FILE *log, unsigned *events, unsigned *apoints,
unsigned *todos, unsigned *lines, unsigned *skipped)
{
- const struct string vevent = STRING_BUILD ("BEGIN:VEVENT");
- const struct string vtodo = STRING_BUILD ("BEGIN:VTODO");
+ const char vevent[] = "BEGIN:VEVENT";
+ const char vtodo[] = "BEGIN:VTODO";
char buf[BUFSIZ], lstore[BUFSIZ];
float ical_version;
@@ -1229,12 +1229,12 @@ ical_import_data (FILE *stream, FILE *log, unsigned *events, unsigned *apoints,
{
(*lines)++;
str_toupper (buf);
- if (strcmp (buf, vevent.str) == 0)
+ if (strcmp (buf, vevent) == 0)
{
ical_read_event (stream, log, events, apoints, skipped, buf, lstore,
lines);
}
- else if (strcmp (buf, vtodo.str) == 0)
+ else if (strcmp (buf, vtodo) == 0)
{
ical_read_todo (stream, log, todos, skipped, buf, lstore, lines);
}
diff --git a/src/keys.c b/src/keys.c
index 3495964..337edc1 100644
--- a/src/keys.c
+++ b/src/keys.c
@@ -303,16 +303,16 @@ keys_remove_binding (int key, enum key action)
int
keys_str2int (char *key)
{
- const struct string CONTROL_KEY = STRING_BUILD ("C-");
- const struct string TAB_KEY = STRING_BUILD ("TAB");
- const struct string SPACE_KEY = STRING_BUILD ("SPC");
- const struct string ESCAPE_KEY = STRING_BUILD ("ESC");
- const struct string CURSES_KEY_UP = STRING_BUILD ("UP");
- const struct string CURSES_KEY_DOWN = STRING_BUILD ("DWN");
- const struct string CURSES_KEY_LEFT = STRING_BUILD ("LFT");
- const struct string CURSES_KEY_RIGHT = STRING_BUILD ("RGT");
- const struct string CURSES_KEY_HOME = STRING_BUILD ("KEY_HOME");
- const struct string CURSES_KEY_END = STRING_BUILD ("KEY_END");
+ const char CONTROL_KEY[] = "C-";
+ const char TAB_KEY[] = "TAB";
+ const char SPACE_KEY[] = "SPC";
+ const char ESCAPE_KEY[] = "ESC";
+ const char CURSES_KEY_UP[] = "UP";
+ const char CURSES_KEY_DOWN[] = "DWN";
+ const char CURSES_KEY_LEFT[] = "LFT";
+ const char CURSES_KEY_RIGHT[] = "RGT";
+ const char CURSES_KEY_HOME[] = "KEY_HOME";
+ const char CURSES_KEY_END[] = "KEY_END";
if (!key)
return -1;
@@ -322,25 +322,25 @@ keys_str2int (char *key)
{
if (key[0] == '^')
return CTRL ((int)key[1]);
- else if (!strcmp (key, CONTROL_KEY.str))
- return CTRL ((int)key[CONTROL_KEY.len]);
- else if (!strcmp (key, TAB_KEY.str))
+ else if (!strcmp (key, CONTROL_KEY))
+ return CTRL ((int)key[sizeof (CONTROL_KEY) - 1]);
+ else if (!strcmp (key, TAB_KEY))
return TAB;
- else if (!strcmp (key, ESCAPE_KEY.str))
+ else if (!strcmp (key, ESCAPE_KEY))
return ESCAPE;
- else if (!strcmp (key, SPACE_KEY.str))
+ else if (!strcmp (key, SPACE_KEY))
return SPACE;
- else if (!strcmp (key, CURSES_KEY_UP.str))
+ else if (!strcmp (key, CURSES_KEY_UP))
return KEY_UP;
- else if (!strcmp (key, CURSES_KEY_DOWN.str))
+ else if (!strcmp (key, CURSES_KEY_DOWN))
return KEY_DOWN;
- else if (!strcmp (key, CURSES_KEY_LEFT.str))
+ else if (!strcmp (key, CURSES_KEY_LEFT))
return KEY_LEFT;
- else if (!strcmp (key, CURSES_KEY_RIGHT.str))
+ else if (!strcmp (key, CURSES_KEY_RIGHT))
return KEY_RIGHT;
- else if (!strcmp (key, CURSES_KEY_HOME.str))
+ else if (!strcmp (key, CURSES_KEY_HOME))
return KEY_HOME;
- else if (!strcmp (key, CURSES_KEY_END.str))
+ else if (!strcmp (key, CURSES_KEY_END))
return KEY_END;
else
return -1;