Skip to content

Instantly share code, notes, and snippets.

@sm00th
Created January 4, 2022 09:03
Show Gist options
  • Save sm00th/df99f857ec429b7b2756ae98ed78aca8 to your computer and use it in GitHub Desktop.
Save sm00th/df99f857ec429b7b2756ae98ed78aca8 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <glib.h>
static char *imc_away_alias_list[8][5] =
{
{ "Away from computer", "Away", "Extended away", NULL },
{ "NA", "N/A", "Not available", NULL },
{ "Busy", "Do not disturb", "DND", "Occupied", NULL },
{ "Be right back", "BRB", NULL },
{ "On the phone", "Phone", "On phone", NULL },
{ "Out to lunch", "Lunch", "Food", NULL },
{ "Invisible", "Hidden" },
{ NULL }
};
static char *imc_away_state_find(GList *gcm, char *away, char **message)
{
GList *m;
int i, j;
for (m = gcm; m; m = m->next) {
if (g_strncasecmp(m->data, away, strlen(m->data)) == 0) {
/* At least the Yahoo! module works better if message
contains no data unless it adds something to what
we have in state already. */
if (message && strlen(m->data) == strlen(away)) {
*message = NULL;
}
return m->data;
}
}
for (i = 0; *imc_away_alias_list[i]; i++) {
int keep_message;
for (j = 0; imc_away_alias_list[i][j]; j++) {
if (g_strncasecmp(away, imc_away_alias_list[i][j], strlen(imc_away_alias_list[i][j])) == 0) {
keep_message = strlen(away) != strlen(imc_away_alias_list[i][j]);
break;
}
}
if (!imc_away_alias_list[i][j]) { /* If we reach the end, this row */
continue; /* is not what we want. Next! */
}
/* Now find an entry in this row which exists in gcm */
for (j = 0; imc_away_alias_list[i][j]; j++) {
for (m = gcm; m; m = m->next) {
if (g_strcasecmp(imc_away_alias_list[i][j], m->data) == 0) {
if (!keep_message && message) {
*message = NULL;
}
return imc_away_alias_list[i][j];
}
}
}
/* No need to look further, apparently this state doesn't
have any good alias for this protocol. */
break;
}
return NULL;
}
int main(int argc, char **argv)
{
static GList *m = NULL;
if (argc < 2) {
printf("No arguments supplied\n");
return 1;
}
m = g_list_prepend(m, "invisible");
m = g_list_prepend(m, "dnd");
m = g_list_prepend(m, "online");
m = g_list_prepend(m, "idle");
printf("away=%s\n", imc_away_state_find(m, argv[1], NULL));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment