/// /// BuildKeywordString static char *BuildKeywordString(void) { char *keywords = NULL; ULONG i; ENTER(); dstrcpy(&keywords, C->AttachmentKeywords); for(i=0; IntMimeTypeArray[i].ContentType != NULL; i++) { if(IsStrEmpty(IntMimeTypeArray[i].Extension) == FALSE) { char *copy; // split the space separated extensions and build a string of // comma separated extensions with leading '.' if((copy = strdup(IntMimeTypeArray[i].Extension)) != NULL) { char *ext = copy; do { char *e; if((e = strpbrk(ext, " ")) != NULL) *e++ = '\0'; if(dstrlen(keywords) != 0) dstrcat(&keywords, ","); dstrcat(&keywords, "."); dstrcat(&keywords, ext); ext = e; } while(ext != NULL); free(copy); } } } D(DBF_GUI, "build keyword string '%s'", keywords); RETURN(keywords); return keywords; }
void dxprintf(dbuf_t * d, char *fmt, ...) { va_list ap; int total; va_start(ap, fmt); total = vsnprintf(_dxprintf_temp_buf, sizeof(_dxprintf_temp_buf), fmt, ap); debug(DBG_GLOBAL, 250, "buffer for dxprintf: '%s' (%d bytes long)\n", _dxprintf_temp_buf, total); dstrcat(d, _dxprintf_temp_buf, total); va_end(ap); }
/// GetFolderInfo() // this function creates a folder string and returns it static void GetFolderInfo(struct Data *data, struct Folder *folder) { char *src; char *info = NULL; ENTER(); // Lets create the label of the AppIcon now for(src = C->InfoBarText; *src; src++) { char dst[10]; if(*src == '%') { switch(*++src) { case '%': dst[0] = '%'; dst[1] = '\0'; break; case 'n': snprintf(dst, sizeof(dst), "%d", folder->New); break; case 'u': snprintf(dst, sizeof(dst), "%d", folder->Unread); break; case 't': snprintf(dst, sizeof(dst), "%d", folder->Total); break; case 's': snprintf(dst, sizeof(dst), "%d", folder->Sent); break; } } else { dst[0] = *src; dst[1] = '\0'; } dstrcat(&info, dst); } if(info != NULL) { strlcpy(data->folderInfo, info, sizeof(data->folderInfo)); dstrfree(info); } else data->folderInfo[0] = '\0'; LEAVE(); }
size_t dstrfcatn(dstring_t dest, FILE *fp, size_t n) { size_t count; /* number of characters successfully read from fp */ dstring_t temp; /* will store the string which will be appended to dest */ int olddstrerrno; /* saves dstrerrno value from call to dstrfreadn() */ /* allocate space for our temporary string */ if (DSTR_SUCCESS != dstrnalloc(&temp, dstrlen(dest))) { /* 0 items are successfully read if we can't get the memory ;) dstrerrno should have been set by dstralloc() */ return 0; } /* read a line of input from the file, and make sure dstrerrno will be set properly */ count = dstrfreadn(temp, fp, n); if (DSTR_SUCCESS != dstrerrno) { if (0 == dstrlen(temp)) { dstrfree(&temp); return 0; } } /* save dstrerrno value at this point, so that any file read errors will be reported */ olddstrerrno = dstrerrno; /* cat temp to dest - dstrcat will see if dest is initialized for us :) */ dstrcat(dest, temp); if (DSTR_SUCCESS != dstrerrno) { dstrfree(&temp); return 0; } /* free our temp string and return successfully */ dstrfree(&temp); _setdstrerrno(olddstrerrno); return count; }
void G_RecordDemo(const char* name) { byte *demostart, *dm_p; int i; demofp = NULL; endDemo = false; dstrcpy(demoname, name); dstrcat(demoname, ".lmp"); if(access(demoname, F_OK)) { demofp = fopen(demoname, "wb"); } else { int demonum = 0; while(demonum < 10000) { sprintf(demoname, "%s%i.lmp", name, demonum); if(access(demoname, F_OK)) { demofp = fopen(demoname, "wb"); break; } demonum++; } // so yeah... dunno how to properly handle this... if(demonum >= 10000) { I_Error("G_RecordDemo: file %s already exists", demoname); return; } } CON_DPrintf("--------Recording %s--------\n", demoname); demostart = dm_p = malloc(1000); G_InitNew(startskill, startmap); *dm_p++ = 'D'; *dm_p++ = 'M'; *dm_p++ = '6'; *dm_p++ = '4'; *dm_p++ = '\0'; *dm_p++ = gameskill; *dm_p++ = gamemap; *dm_p++ = deathmatch; *dm_p++ = respawnparm; *dm_p++ = respawnitem; *dm_p++ = fastparm; *dm_p++ = nomonsters; *dm_p++ = consoleplayer; *dm_p++ = (byte)((rngseed >> 24) & 0xff); *dm_p++ = (byte)((rngseed >> 16) & 0xff); *dm_p++ = (byte)((rngseed >> 8) & 0xff); *dm_p++ = (byte)( rngseed & 0xff); *dm_p++ = (byte)((gameflags >> 24) & 0xff); *dm_p++ = (byte)((gameflags >> 16) & 0xff); *dm_p++ = (byte)((gameflags >> 8) & 0xff); *dm_p++ = (byte)( gameflags & 0xff); *dm_p++ = (byte)((compatflags >> 24) & 0xff); *dm_p++ = (byte)((compatflags >> 16) & 0xff); *dm_p++ = (byte)((compatflags >> 8) & 0xff); *dm_p++ = (byte)( compatflags & 0xff); for(i = 0; i < MAXPLAYERS; i++) { *dm_p++ = playeringame[i]; } if(fwrite(demostart, 1, dm_p-demostart, demofp) != (size_t)(dm_p-demostart)) { I_Error("G_RecordDemo: Error writing demo header"); } free(demostart); demorecording = true; usergame = false; G_RunGame(); G_CheckDemoStatus(); }
struct bfs_printf *parse_bfs_printf(const char *format, struct cmdline *cmdline) { struct bfs_printf *head = NULL; struct bfs_printf **tail = &head; struct bfs_printf *literal = new_directive(bfs_printf_literal); if (!literal) { goto error; } for (const char *i = format; *i; ++i) { char c = *i; if (c == '\\') { c = *++i; if (c >= '0' && c < '8') { c = 0; for (int j = 0; j < 3 && *i >= '0' && *i < '8'; ++i, ++j) { c *= 8; c += *i - '0'; } --i; goto one_char; } switch (c) { case 'a': c = '\a'; break; case 'b': c = '\b'; break; case 'f': c = '\f'; break; case 'n': c = '\n'; break; case 'r': c = '\r'; break; case 't': c = '\t'; break; case 'v': c = '\v'; break; case '\\': c = '\\'; break; case 'c': tail = append_literal(tail, &literal); struct bfs_printf *directive = new_directive(bfs_printf_flush); if (!directive) { goto error; } tail = append_directive(tail, directive); goto done; case '\0': bfs_error(cmdline, "'%s': Incomplete escape sequence '\\'.\n", format); goto error; default: bfs_error(cmdline, "'%s': Unrecognized escape sequence '\\%c'.\n", format, c); goto error; } } else if (c == '%') { if (i[1] == '%') { c = *++i; goto one_char; } struct bfs_printf *directive = new_directive(NULL); if (!directive) { goto directive_error; } if (dstrapp(&directive->str, c) != 0) { perror("dstrapp()"); goto directive_error; } const char *specifier = "s"; // Parse any flags bool must_be_numeric = false; while (true) { c = *++i; switch (c) { case '#': case '0': case '+': must_be_numeric = true; // Fallthrough case ' ': case '-': if (strchr(directive->str, c)) { bfs_error(cmdline, "'%s': Duplicate flag '%c'.\n", format, c); goto directive_error; } if (dstrapp(&directive->str, c) != 0) { perror("dstrapp()"); goto directive_error; } continue; } break; } // Parse the field width while (c >= '0' && c <= '9') { if (dstrapp(&directive->str, c) != 0) { perror("dstrapp()"); goto directive_error; } c = *++i; } // Parse the precision if (c == '.') { do { if (dstrapp(&directive->str, c) != 0) { perror("dstrapp()"); goto directive_error; } c = *++i; } while (c >= '0' && c <= '9'); } switch (c) { case 'a': directive->fn = bfs_printf_ctime; directive->stat_field = BFS_STAT_ATIME; break; case 'b': directive->fn = bfs_printf_b; break; case 'c': directive->fn = bfs_printf_ctime; directive->stat_field = BFS_STAT_CTIME; break; case 'd': directive->fn = bfs_printf_d; specifier = "jd"; break; case 'D': directive->fn = bfs_printf_D; break; case 'f': directive->fn = bfs_printf_f; break; case 'F': if (!cmdline->mtab) { bfs_error(cmdline, "Couldn't parse the mount table: %s.\n", strerror(cmdline->mtab_error)); goto directive_error; } directive->fn = bfs_printf_F; directive->mtab = cmdline->mtab; break; case 'g': directive->fn = bfs_printf_g; break; case 'G': directive->fn = bfs_printf_G; break; case 'h': directive->fn = bfs_printf_h; break; case 'H': directive->fn = bfs_printf_H; break; case 'i': directive->fn = bfs_printf_i; break; case 'k': directive->fn = bfs_printf_k; break; case 'l': directive->fn = bfs_printf_l; break; case 'm': directive->fn = bfs_printf_m; specifier = "o"; break; case 'M': directive->fn = bfs_printf_M; break; case 'n': directive->fn = bfs_printf_n; break; case 'p': directive->fn = bfs_printf_p; break; case 'P': directive->fn = bfs_printf_P; break; case 's': directive->fn = bfs_printf_s; break; case 'S': directive->fn = bfs_printf_S; specifier = "g"; break; case 't': directive->fn = bfs_printf_ctime; directive->stat_field = BFS_STAT_MTIME; break; case 'u': directive->fn = bfs_printf_u; break; case 'U': directive->fn = bfs_printf_U; break; case 'w': directive->fn = bfs_printf_ctime; directive->stat_field = BFS_STAT_BTIME; break; case 'y': directive->fn = bfs_printf_y; break; case 'Y': directive->fn = bfs_printf_Y; break; case 'A': directive->stat_field = BFS_STAT_ATIME; goto directive_strftime; case 'B': case 'W': directive->stat_field = BFS_STAT_BTIME; goto directive_strftime; case 'C': directive->stat_field = BFS_STAT_CTIME; goto directive_strftime; case 'T': directive->stat_field = BFS_STAT_MTIME; goto directive_strftime; directive_strftime: directive->fn = bfs_printf_strftime; c = *++i; if (!c) { bfs_error(cmdline, "'%s': Incomplete time specifier '%s%c'.\n", format, directive->str, i[-1]); goto directive_error; } else if (strchr("%+@aAbBcCdDeFgGhHIjklmMnprRsStTuUVwWxXyYzZ", c)) { directive->c = c; } else { bfs_error(cmdline, "'%s': Unrecognized time specifier '%%%c%c'.\n", format, i[-1], c); goto directive_error; } break; case '\0': bfs_error(cmdline, "'%s': Incomplete format specifier '%s'.\n", format, directive->str); goto directive_error; default: bfs_error(cmdline, "'%s': Unrecognized format specifier '%%%c'.\n", format, c); goto directive_error; } if (must_be_numeric && strcmp(specifier, "s") == 0) { bfs_error(cmdline, "'%s': Invalid flags '%s' for string format '%%%c'.\n", format, directive->str + 1, c); goto directive_error; } if (dstrcat(&directive->str, specifier) != 0) { perror("dstrcat()"); goto directive_error; } tail = append_literal(tail, &literal); tail = append_directive(tail, directive); if (!literal) { literal = new_directive(bfs_printf_literal); if (!literal) { goto error; } } continue; directive_error: free_directive(directive); goto error; } one_char: if (dstrapp(&literal->str, c) != 0) { perror("dstrapp()"); goto error; } } done: tail = append_literal(tail, &literal); if (head) { free_directive(literal); return head; } else { return literal; } error: free_directive(literal); free_bfs_printf(head); return NULL; }
void rx_addredit(UNUSED struct RexxHost *host, struct RexxParams *params, enum RexxAction action, UNUSED struct RexxMsg *rexxmsg) { struct args *args = params->args; ENTER(); switch(action) { case RXIF_INIT: { params->args = AllocVecPooled(G->SharedMemPool, sizeof(*args)); } break; case RXIF_ACTION: { struct ABookNode *abn; abn = G->abook.arexxABN; if(abn == NULL && G->ABookWinObject != NULL) abn = (struct ABookNode *)xget(G->ABookWinObject, MUIA_AddressBookWindow_ActiveEntry); SHOWVALUE(DBF_ABOOK, abn); if(abn != NULL) { if(args->alias != NULL) strlcpy(abn->Alias, args->alias, sizeof(abn->Alias)); if(args->name != NULL) strlcpy(abn->RealName, args->name, sizeof(abn->RealName)); if(args->email != NULL) strlcpy(abn->Address, args->email, sizeof(abn->Address)); if(args->pgp != NULL) strlcpy(abn->PGPId, args->pgp, sizeof(abn->PGPId)); if(args->homepage != NULL) strlcpy(abn->Homepage, args->homepage, sizeof(abn->Homepage)); if(args->street != NULL) strlcpy(abn->Street, args->street, sizeof(abn->Street)); if(args->city != NULL) strlcpy(abn->City, args->city, sizeof(abn->City)); if(args->country != NULL) strlcpy(abn->Country, args->country, sizeof(abn->Country)); if(args->phone != NULL) strlcpy(abn->Phone, args->phone, sizeof(abn->Phone)); if(args->comment != NULL) strlcpy(abn->Comment, args->comment, sizeof(abn->Comment)); if(args->birthdate != NULL) { char dateStr[SIZE_SMALL]; // if the user supplied 0 as the birthdate, he wants to "delete" the current // birthdate if(*args->birthdate == 0) abn->Birthday = 0; else if(BirthdayToString(*args->birthdate, dateStr, sizeof(dateStr)) == TRUE) abn->Birthday = *args->birthdate; else { params->rc = RETURN_ERROR; break; } } if(args->image != NULL) strlcpy(abn->Photo, args->image, sizeof(abn->Photo)); if(args->member != NULL && abn->type == ABNT_LIST) { char **p; // free the list members in case we are told to replace them if(args->add == FALSE) { dstrfree(abn->ListMembers); abn->ListMembers = NULL; } for(p = args->member; *p != NULL; p++) { dstrcat(&abn->ListMembers, *p); dstrcat(&abn->ListMembers, "\n"); } } G->abook.arexxABN = abn; G->abook.modified = TRUE; // update an existing address book window as well if(G->ABookWinObject != NULL) DoMethod(G->ABookWinObject, MUIM_AddressBookWindow_RedrawActiveEntry); } else params->rc = RETURN_ERROR; } break; case RXIF_FREE: { if(args != NULL) FreeVecPooled(G->SharedMemPool, args); } break; } LEAVE(); }