static void group_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *string) { InternetAddressGroup *group = (InternetAddressGroup *) ia; gboolean encode = flags & INTERNET_ADDRESS_ENCODE; gboolean fold = flags & INTERNET_ADDRESS_FOLD; char *name = NULL; size_t len = 0; if (ia->name != NULL) { name = encoded_name (ia->name, encode); len = strlen (name); if (fold && *linelen > 1 && (*linelen + len + 1) > GMIME_FOLD_LEN) { linewrap (string); *linelen = 1; } g_string_append_len (string, name, len); } g_string_append_len (string, ": ", 2); *linelen += len + 2; g_free (name); _internet_address_list_to_string (group->members, flags, linelen, string); g_string_append_c (string, ';'); *linelen += 1; }
void DeterministicSLAM::mergeOtherSegments(const SegmentScan &s) { //??QList<Geometry::LineSegment *> outdoorSegments; const AlignedVector<UncertainLineSegment> &scan = s.getSegments(); int i, j; /* Slow O(n^2) search for line segments to merge */ for(i = 0; i < scan.size(); i++) { for(j = 0; j < otherSegments.size(); j++) { LineSegment &lm = *(otherSegments[j]); const UncertainLineSegment &ls = scan[i]; double angle = linewrap(lm.angle() - ls.angle()); /* Check if the segments are almost collinear (and long enough) */ if(lm.length() > 0.1 && ls.length() > 0.1 && std::fabs(angle) < Config::SLAM::collinearityThreshold) { /* Get a new line segment by rotating around the centroid in order to align the two segments */ LineSegment rotated = Rototranslation(ls.centroid(), angle) * ls; const Point &rp1 = rotated.p1(); const Point &rp2 = rotated.p2(); /* Check if the point to line distance of one (either one is ok) of the rotated segment is small enough */ if(lm.distance2(rp1) < SQUARE(Config::SLAM::mergeThreshold)) { /* Check that the projection of at least one the endpoints falls in an acceptable range */ double proj1 = lm.project1D(rp1), proj2 = lm.project1D(rp2); double accept_l = - Config::SLAM::mergeThreshold; double accept_u = lm.length() + Config::SLAM::mergeThreshold; /* TODO: Serve che il controllo sulla distanza abbia isolinee circolari, non rettangolari come ora */ if((proj1 >= accept_l && proj1 <= accept_u) || (proj2 >= accept_l && proj2 <= accept_u)) { /* Merge the line segments */ lm.mergeInPlace(ls); //???outdoorSegments.append(new LineSegment(lm)); //lm.mergeInPlaceProjection(ls); break; } } } } /* No segments were merged, add the last one to the map */ if(j == otherSegments.size() ){//&& scan[i].length() > SM_MINIMUM_SEGMENT_LENGTH) { LineSegment *s = new LineSegment(scan[i]); otherSegments.append(s); //??outdoorSegments.append(new LineSegment(scan[i])); } } /*if(outdoor){ segments=outdoorSegments; }*/ }
static void append_folded_name (GString *string, size_t *linelen, const char *name) { const char *word, *lwsp; size_t len; word = name; while (*word) { lwsp = word; if (*word == '"') { /* quoted string, don't break these up */ lwsp++; while (*lwsp && *lwsp != '"') { if (*lwsp == '\\') lwsp++; if (*lwsp) lwsp++; } if (*lwsp == '"') lwsp++; } else { /* normal word */ while (*lwsp && !is_lwsp (*lwsp)) lwsp++; } len = lwsp - word; if (*linelen > 1 && (*linelen + len) > GMIME_FOLD_LEN) { linewrap (string); *linelen = 1; } g_string_append_len (string, word, len); *linelen += len; word = lwsp; while (*word && is_lwsp (*word)) word++; if (*word && is_lwsp (*lwsp)) { g_string_append_c (string, ' '); (*linelen)++; } } }
main() { int i; int len; /* current line length */ char line[MAXLINE+1]; /* current input line plus '\0' */ for (i=0; i<WRAP_COL; i++) printf("%1d", i%10); printf("\n\n"); while ((len = mygetline(line, MAXLINE)) != EOF) if (len>0) { linewrap(line, len, WRAP_COL); printf("%s\n", line); } return 0; }
static void mailbox_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *string) { InternetAddressMailbox *mailbox = (InternetAddressMailbox *) ia; gboolean encode = flags & INTERNET_ADDRESS_ENCODE; gboolean fold = flags & INTERNET_ADDRESS_FOLD; char *name; size_t len; if (ia->name && *ia->name) { name = encoded_name (ia->name, encode); len = strlen (name); if (fold && (*linelen + len) > GMIME_FOLD_LEN) { if (len > GMIME_FOLD_LEN) { /* we need to break up the name */ append_folded_name (string, linelen, name); } else { /* the name itself is short enough to fit on a single * line, but only if we write it on a line by itself */ if (*linelen > 1) { linewrap (string); *linelen = 1; } g_string_append_len (string, name, len); *linelen += len; } } else { /* we can safely fit the name on this line */ g_string_append_len (string, name, len); *linelen += len; } g_free (name); len = strlen (mailbox->addr); if (fold && (*linelen + len + 3) >= GMIME_FOLD_LEN) { g_string_append_len (string, "\n\t<", 3); *linelen = 2; } else { g_string_append_len (string, " <", 2); *linelen += 2; } g_string_append_len (string, mailbox->addr, len); g_string_append_c (string, '>'); *linelen += len + 1; } else { len = strlen (mailbox->addr); if (fold && (*linelen + len) > GMIME_FOLD_LEN) { linewrap (string); *linelen = 1; } g_string_append_len (string, mailbox->addr, len); *linelen += len; } }