int Vec2_Look(var self, var input, int pos) { Vec2Data* v = cast(self, Vec2); var x = $(Real, 0); var y = $(Real, 0); pos = scan_from(input, pos, "(%f, %f)", x, y); v->x = as_double(x); v->y = as_double(y); return pos; }
int Real_Look(var self, var input, int pos) { return scan_from(input, pos, "%f", self); }
void cpy_sender(char *str, char *rcpt, char *to, char *fhost) { int gotaddr= 0; int gotname= 0; int gotmisc= 0; char *p; char *pa= "unknown"; /* see NOTE below */ char *pn= "unknown"; /* see NOTE below */ char addr[CDDBBUFSIZ]; char name[CDDBBUFSIZ]; char misc[CDDBBUFSIZ]; /* Scan the string for the name and address. */ if(scan_from(str, addr, SCAN_ADDR)) gotaddr = 1; if(scan_from(str, name, SCAN_NAME)) gotname = 1; if((!gotaddr || !gotname) && scan_from(str, misc, SCAN_MISC)) gotmisc = 1; /* NOTE: there might be cases where neither SCAN_ADDR nor SCAN_NAME * nor SCAN_MISC return plausible values. Therefore pa and pn need * to be initialized to avoid picking-up garbage. Maybe it would * make sense not to process such cases at all. */ if(gotaddr) { pa = addr; } else if(gotmisc) { pa = misc; gotaddr = 1; gotmisc = 0; } if(gotname) { pn = name; } else if(gotmisc) { pn = misc; gotname = 1; } /* We couldn't parse the string, use the raw "from". */ if(!gotaddr) { strcpy(rcpt, str); pn = &rcpt[strlen(rcpt) - 1]; if(*pn == '\n') *pn = '\0'; strcpy(to, rcpt); strcpy(fhost, "unknown"); return; } /* Copy the relevant parts. */ cddbd_snprintf(rcpt, CDDBBUFSIZ, "%s", pa); if(gotname) cddbd_snprintf(to, CDDBBUFSIZ, "%s (%s)", pa, pn); else cddbd_snprintf(to, CDDBBUFSIZ, "%s", pa); /* * Get the hostname from the address. If it's a complicated * address, this may goof up. If there's no discernible host we * must assume it's because there isn't one, so call it "localhost". */ if((p = strrchr(pa, '@')) != NULL) cddbd_snprintf(fhost, CDDBBUFSIZ, "%s", (p + 1)); else if((p = strchr(pa, '!')) != NULL) { *p = '\0'; cddbd_snprintf(fhost, CDDBBUFSIZ, "%s", pa); } else if((p = strrchr(pa, '%')) != NULL) cddbd_snprintf(fhost, CDDBBUFSIZ, "%s", (p + 1)); else strcpy(fhost, LHOST); }
int String_Look(var self, var input, int pos) { return scan_from(input, pos, "\"%[^\"]\"", self); }