// Get and send a fortune. void send_fortune () { std::string fortune; try { fortune = get_fortune (); } catch (int e) { display_error_dialog ("Could not get output of 'fortune'.\n" "Please verify you have it installed in your system."); return; } send_notify (fortune, settings.getTimeout ()); }
/** * main function of cmml-fortune. */ int main(int argc, char *argv[]) { int i; CMML_Time * dur = NULL; CMML_Preamble * pre = NULL; CMML_Head * head = NULL; CMML_Clip * clip = NULL; CMML_Time * start = NULL, * end = NULL; double s; char * outfilename = NULL; FILE * outfile = stdout; char * encoding = DEFAULT_ENCODING; char * short_command = DEFAULT_SHORT_COMMAND; char * long_command = DEFAULT_LONG_COMMAND; char buf[BUFSIZE]; while (1) { char * optstring = "hvd:e:o:s:l:"; #ifdef HAVE_GETOPT_LONG static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"version",no_argument,0, 'v'}, {"duration", required_argument, 0, 'd'}, {"encoding", required_argument, 0, 'e'}, {"output", required_argument, 0, 'o'}, {"short-command", required_argument, 0, 's'}, {"long-command", required_argument, 0, 'l'}, {0,0,0,0} }; i = getopt_long(argc, argv, optstring, long_options, NULL); #else i = getopt(argc, argv, optstring); #endif if (i == -1) break; if (i == ':') PrintUsage (argv[0]); switch (i) { case 'h': /* help */ PrintUsage (argv[0]); break; case 'v': /* version */ fprintf(stdout, "cmml-fortune version " VERSION "\n"); fprintf(stdout, "# cmml-fortune, Copyright (C) 2003 CSIRO Australia www.csiro.au ; www.annodex.net\n"); exit (0); break; case 'd': /* duration */ dur = cmml_time_new (optarg); if (dur == NULL) { printf ("Unable to parse duration %s\n", optarg); } break; case 'e': /* encoding */ encoding = optarg; break; case 'o': /* output */ outfilename = optarg; break; case 's': /* short command */ short_command = optarg; break; case 'l': /* long command */ long_command = optarg; break; default: break; } } /* set duration of file */ if (dur == NULL) dur = cmml_time_new (DEFAULT_DURATION); /* open output file */ if (outfilename != NULL) { if ((outfile = fopen (outfilename, "wb")) == NULL) { fprintf (stderr, "Error opening %s for writing\n", outfilename); exit (1); } } /* write preamble */ pre = cmml_preamble_new(encoding, NULL, NULL, NULL, NULL); cmml_preamble_snprint (buf, BUFSIZE, pre); fputs (buf, outfile); cmml_preamble_destroy(pre); /* write head */ head = cmml_head_new(); head->title = get_fortune (short_command); cmml_head_pretty_snprint (buf, BUFSIZE, head); fputs (buf, outfile); cmml_head_destroy(head); /* write clips */ for (s = 0.0; s < dur->t.sec; s += 5.0) { cmml_npt_snprint (buf, BUFSIZE, s); start = cmml_time_new (buf); cmml_npt_snprint (buf, BUFSIZE, s+4); end = cmml_time_new (buf); clip = cmml_clip_new(start, end); clip->anchor_href = strdup("http://www.annodex.net/"); clip->anchor_text = get_fortune(short_command); clip->desc_text = get_fortune (long_command); cmml_clip_pretty_snprint (buf, BUFSIZE, clip); fputs (buf, outfile); cmml_clip_destroy(clip); } fprintf (outfile, "</cmml>\n"); return 0; }
int main(int argc, char **argv) { char *dev = "/dev/i2c-2"; int fd = open(dev, O_RDWR); int ret; uint8_t address = 0x27; char ip[32]; char fortune[128]; int scroll_delay = 200; signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); if(fd<0) { printf("open: %s\n", strerror(errno)); exit(1); } ret = ioctl(fd, I2C_SLAVE, address); if(ret<0) { printf("set i2c address: %s\n", strerror(errno)); exit(1); } lcd_init(fd); while(!g_quit) { char tmp_fortune[16+1]; int i; get_ip(ip, sizeof(ip)); get_fortune(fortune, sizeof(fortune)); //strncpy(tmp_fortune, fortune, 16); snprintf(tmp_fortune, sizeof(tmp_fortune), "%s", fortune); printf("display fortune: %s\n", fortune); lcd_display_string(fd, tmp_fortune, 1); printf("display ip: %s\n", ip); lcd_display_string(fd, ip, 2); msleep(900); // no scrolling if fit in one line if( strlen(fortune)<=16) { msleep(2000); continue; } // do scrolling text if unable to fit in one line printf("scroll start: %s\n", fortune); for(i=1; i<=strlen(fortune) && !g_quit ; ++i) { // shift the string to the left by 1 character snprintf(tmp_fortune, sizeof(tmp_fortune), "%s", fortune+i); lcd_display_string(fd, tmp_fortune, 1); msleep(scroll_delay); } printf("scroll end: %s\n", fortune); } lcd_clear(fd); close(fd); return 0; }