Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:MargueriteSu:branches:M17N:fonts
fontpackages
fontpackages.prov.c
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File fontpackages.prov.c of Package fontpackages
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> char* read_output(char* str) { int size = 80; int i = 0; FILE* cmd = popen(str, "r"); char* tmp = (char*)malloc(8); char* result = (char*)calloc(size, sizeof(char)); while (fgets(tmp, sizeof(tmp), cmd) != NULL) { i += strlen(tmp); if (i > size - 1) { size += 80; result = (char*)realloc(result, size); } strncat(result, tmp, i); } pclose(cmd); free(tmp); return result; } char* read_stdin() { int size = 80; int i = 0; int j = 0; char* result = (char*)calloc(size, sizeof(char)); char* buf = (char*)malloc(8); while ((i = read(STDIN_FILENO, buf, sizeof(buf))) > 0) { j += i; if (j > size - 1) { size += 80; result = (char*)realloc(result, size); } strncat(result, buf, i); } free(buf); return result; } void replace(char* str) { int i; for (i = 0; i < strlen(str)+1; i++) { if (str[i] == ' ') { str[i] = '_'; } else if (str[i] == ',') { str[i] = '\0'; break; } } } typedef struct { char* name; char* lang; } Font; Font* parse(char* file) { Font* f = malloc(sizeof(Font)); char* out; char* out1; char* cmd1 = "/usr/bin/fc-scan -f '%{family}' "; char* cmd2 = (char*)malloc(strlen(cmd1)+strlen(file)+1); strncat(cmd2, cmd1, strlen(cmd1)); strncat(cmd2, file, strlen(file)); cmd2[strlen(cmd1)+strlen(file)] = '\0'; out = read_output(cmd2); if (out) { replace(out); f->name = out; } free(cmd2); char* cmd3 = "/usr/bin/fc-scan -f '%{lang}' "; char* cmd4 = (char*)malloc(strlen(cmd3)+strlen(file)+1); strncat(cmd4, cmd3, strlen(cmd3)); strncat(cmd4, file, strlen(file)); cmd4[strlen(cmd3)+strlen(file)] = '\0'; out1 = read_output(cmd4); if (out1) { f->lang = out1; } free(cmd4); return f; } int main(int argc, char *argv[]) { Font* f; char* file = read_stdin(); f = parse(file); printf("font(%s)\n", f->name); if (strlen(f->lang) > 0) { printf("font(%s)\n", f->lang); } free(file); free(f->name); free(f->lang); free(f); return 0; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor