You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
814 B
C
43 lines
814 B
C
1 year ago
|
#include "emoji.h"
|
||
|
|
||
|
#include "json/layout.h"
|
||
|
|
||
|
#include <dirent.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
#define OBJ_TYPE struct emoji
|
||
|
struct json_object_field emoji_layout[] = {
|
||
|
JSON_FIELD_STRING( url, true ),
|
||
|
JSON_FIELD_STRING( shortcode, true ),
|
||
|
JSON_FIELD_END,
|
||
|
};
|
||
|
#undef OBJ_TYPE
|
||
|
JSON_FIELD_TYPE_OBJECT_LAYOUT_WITH_DEFAULTS( emoji );
|
||
|
|
||
|
char* filename_for_shortcode( const char* shortcode )
|
||
|
{
|
||
|
int len = strlen(shortcode);
|
||
|
|
||
|
DIR* d = opendir( "data/emoji" );
|
||
|
struct dirent* ent;
|
||
|
char* filename = NULL;
|
||
|
while( ent = readdir(d) ) {
|
||
|
if( 0 == strncmp( shortcode, ent->d_name, len ) && ent->d_name[len] == '.' ) {
|
||
|
closedir(d);
|
||
|
return strdup(ent->d_name);
|
||
|
}
|
||
|
}
|
||
|
closedir(d);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
void emoji_free( struct emoji* e )
|
||
|
{
|
||
|
if( !e ) { return; }
|
||
|
|
||
|
free(e->shortcode);
|
||
|
free(e->url);
|
||
|
free(e);
|
||
|
}
|