extern char* vr_findVerRegName() { FSSpec regSpec; OSErr err; short foundVRefNum; long foundDirID; int bCreate = 0; /* quick exit if we have the info */ if ( verRegName != NULL ) return verRegName; err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID); if (err == noErr) { err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_VERREG, ®Spec); if (err == -43) /* if file doesn't exist */ { err = FSpCreate(®Spec, 'MOSS', 'REGS', smSystemScript); bCreate = 1; } if (err == noErr) { Handle thePath; short pathLen; err = FSpGetFullPath(®Spec, &pathLen, &thePath); if (err == noErr && thePath) { /* we have no idea if this moves memory, so better lock the handle */ #if defined(STANDALONE_REGISTRY) || defined(USE_STDIO_MODES) HLock(thePath); verRegName = (char *)XP_ALLOC(pathLen + 1); XP_STRNCPY(verRegName, *thePath, pathLen); verRegName[pathLen] = '\0'; #else /* Since we're now using NSPR, this HAS to be a unix path! */ const char* src; char* dst; HLock(thePath); verRegName = (char*)XP_ALLOC(pathLen + 2); src = *(char**)thePath; dst = verRegName; *dst++ = '/'; while (pathLen--) { char c = *src++; *dst++ = (c == ':') ? '/' : c; } *dst = '\0'; #endif } DisposeHandle(thePath); } } return verRegName; }
VR_INTERFACE(REGERR) VR_UninstallDeleteSharedFilesKey(char *component_path) { REGERR err; char *regbuf; char *converted_component_path; uint32 convertedDataLength = 0; uint32 regbuflen = 0; uint32 curregbuflen = 0; uint32 len = 0; err = vr_Init(); if (err != REGERR_OK) return err; if ( component_path == NULL ) err = REGERR_PARAM; convertedDataLength = 2 * XP_STRLEN(component_path) + 1; converted_component_path = (char*)XP_ALLOC(convertedDataLength); if (converted_component_path == NULL ) { err = REGERR_MEMORY; return err; } err = vr_convertPackageName(component_path, converted_component_path, convertedDataLength); if (err != REGERR_OK) { XP_FREEIF(converted_component_path); return err; } regbuflen = 256 + XP_STRLEN(converted_component_path); regbuf = (char*)XP_ALLOC( regbuflen ); if (regbuf != NULL ) { err = vr_GetUninstallItemPath(converted_component_path, regbuf, regbuflen); if (err == REGERR_OK) { curregbuflen = XP_STRLEN(regbuf); len = XP_STRLEN(SHAREDFILESSTR); if (len < (regbuflen - curregbuflen)) { XP_STRCAT(regbuf, SHAREDFILESSTR); err = NR_RegDeleteKey( vreg, ROOTKEY_PRIVATE, regbuf ); } else err = REGERR_BUFTOOSMALL; } XP_FREE(regbuf); } else { err = REGERR_MEMORY; } XP_FREE(converted_component_path); return err; } /* UninstallDeleteSharedFilesKey */
PUBLIC void NET_LoadNetHelpTopic(MWContext *pContext, const char *topic) { char *pNetHelpURLString; URL_Struct *pHelpURL; if (topic == NULL) { return; } /* Convert the fully-specified topic into a nethelp URL: */ pNetHelpURLString = (char *) XP_ALLOC(strlen(topic) + strlen(NETHELP_URL_PREFIX)+1); if (!pNetHelpURLString) { return; } XP_STRCPY(pNetHelpURLString, NETHELP_URL_PREFIX); XP_STRCPY(&(pNetHelpURLString[strlen(NETHELP_URL_PREFIX)]), topic); pHelpURL = NET_CreateURLStruct(pNetHelpURLString, NET_NORMAL_RELOAD); if (!pHelpURL) { return; } NET_GetURL(pHelpURL, FO_PRESENT, pContext, simple_exit); XP_FREEIF(pNetHelpURLString); }
char *XP_Cat(char *a0, ...) { va_list ap; char *a, *result, *cp; int len; /* Count up string length's */ va_start(ap, a0); len = 1; a = a0; while (a != (char*) NULL) { len += XP_STRLEN(a); a = va_arg(ap, char*); } va_end(ap); /* Allocate memory and copy strings */ va_start(ap, a0); result = cp = (char*) XP_ALLOC(len); if (!cp) return 0; a = a0; while (a != (char*) NULL) { len = XP_STRLEN(a); XP_MEMCPY(cp, a, len); cp += len; a = va_arg(ap, char*); } *cp = 0; va_end(ap); return result; }
PUBLIC void XP_NetHelp(MWContext *pContext, const char *topic) { MWContext *pActiveContext = NULL; char *pHelpURLString = NULL; /* Prepend the vendor name "netscape/" to all of our own topics */ if (topic == NULL) { pHelpURLString = XP_STRDUP("netscape/home"); } else { pHelpURLString = (char *) XP_ALLOC(strlen(topic) + strlen("netscape/")+1); if (!pHelpURLString) { return; } XP_STRCPY(pHelpURLString, "netscape/"); XP_STRCPY(&(pHelpURLString[9]), topic); } /* Now get the right context to load it from */ if (pContext != NULL) { pActiveContext = pContext; } else { pActiveContext = FE_GetNetHelpContext(); } NET_LoadNetHelpTopic(pActiveContext, pHelpURLString); XP_FREEIF(pHelpURLString); }
/* Again like strdup but it concatinates and free's and uses Realloc */ PUBLIC char * NET_SACat (char **destination, const char *source) { if (source && *source) { if (*destination) { int length = XP_STRLEN (*destination); *destination = (char *) XP_REALLOC (*destination, length + XP_STRLEN(source) + 1); if (*destination == NULL) return(NULL); XP_STRCPY (*destination + length, source); } else { *destination = (char *) XP_ALLOC (XP_STRLEN(source) + 1); if (*destination == NULL) return(NULL); XP_STRCPY (*destination, source); } } return *destination; }
/* binary block Allocate and Concatenate * * destination_length is the length of the existing block * source_length is the length of the block being added to the * destination block */ PUBLIC char * NET_BACat (char **destination, size_t destination_length, const char *source, size_t source_length) { if (source) { if (*destination) { *destination = (char *) XP_REALLOC (*destination, destination_length + source_length); if (*destination == NULL) return(NULL); XP_MEMMOVE (*destination + destination_length, source, source_length); } else { *destination = (char *) XP_ALLOC (source_length); if (*destination == NULL) return(NULL); XP_MEMCPY(*destination, source, source_length); } } return *destination; }
char* vr_findVerRegName () { if ( verRegName != NULL ) return verRegName; #ifndef STANDALONE_REGISTRY { char *def = NULL; char *home = getenv("HOME"); if (home != NULL) { def = (char *) XP_ALLOC(XP_STRLEN(home) + XP_STRLEN(DEF_VERREG)+1); if (def != NULL) { XP_STRCPY(def, home); XP_STRCAT(def, DEF_VERREG); } } if (def != NULL) { verRegName = XP_STRDUP(def); } XP_FREEIF(def); } #else verRegName = XP_STRDUP(TheRegistry); #endif /*STANDALONE_REGISTRY*/ return verRegName; }
static void fe_movemail_perror(MWContext *context, const char *message) { int e = errno; char *es = 0; char *buf1 = 0; char buf2[512]; char *suffix; int L; XP_ASSERT(context); if (!context) return; if ((unsigned)e < (unsigned)sys_nerr) { es = sys_errlist [e]; } else { PR_snprintf (buf2, sizeof (buf2), XP_GetString( XFE_UNKNOWN_ERROR_CODE ), errno); es = buf2; } suffix = XP_GetString(XFE_MOVEMAIL_FAILURE_SUFFIX); if(!suffix) suffix = ""; if(!message) message = ""; L = XP_STRLEN(message) + XP_STRLEN(es) + XP_STRLEN(suffix) + 40; buf1 = (char *) XP_ALLOC(L); if(!buf1) return; PR_snprintf (buf1, L-1, "%s\n%s\n\n%s", message, es, suffix); FE_Alert (context, buf1); XP_FREE(buf1); }
char* vr_findVerRegName () { if ( verRegName != NULL ) return verRegName; #ifndef STANDALONE_REGISTRY { char *def = NULL; char settings[1024]; find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settings, sizeof(settings)); if (settings != NULL) { def = (char *) XP_ALLOC(XP_STRLEN(settings) + XP_STRLEN(BEOS_VERREG)+1); if (def != NULL) { XP_STRCPY(def, settings); XP_STRCAT(def, BEOS_VERREG); } } if (def != NULL) { verRegName = XP_STRDUP(def); } XP_FREEIF(def); } #else verRegName = XP_STRDUP(TheRegistry); #endif /*STANDALONE_REGISTRY*/ return verRegName; }
VR_INTERFACE(REGERR) VR_GetUninstallUserName(char *regPackageName, char *outbuf, uint32 buflen) { REGERR err; RKEY key = 0; char *regbuf = NULL; char *convertedName = NULL; uint32 convertedDataLength = 0; uint32 regbuflen = 0; err = vr_Init(); if (err != REGERR_OK) return err; if ( regPackageName == NULL || *regPackageName == '\0' || outbuf == NULL ) return REGERR_PARAM; convertedDataLength = 2 * XP_STRLEN(regPackageName) + 1; convertedName = (char*)XP_ALLOC(convertedDataLength); if (convertedName == NULL ) { err = REGERR_MEMORY; return err; } err = vr_convertPackageName(regPackageName, convertedName, convertedDataLength); if (err != REGERR_OK) { XP_FREE(convertedName); return err; } regbuflen = 256 + XP_STRLEN(convertedName); regbuf = (char*)XP_ALLOC( regbuflen ); if (regbuf == NULL ) { err = REGERR_MEMORY; } else { err = vr_GetUninstallItemPath(convertedName, regbuf, regbuflen); if (err == REGERR_OK) { err = NR_RegGetKey( vreg, ROOTKEY_PRIVATE, regbuf, &key ); } XP_FREE(regbuf); } if (err == REGERR_OK) err = NR_RegGetEntryString( vreg, key, PACKAGENAMESTR, outbuf, buflen ); XP_FREE(convertedName); return err; } /* GetUninstallName */
/* buf -> mz_mbNullConv -> frombuf -> INTL_TextToUnicode -> ucs2buf -> INTL_UnicodeToStr -> tobuf */ PRIVATE unsigned char* mz_AnyToAnyThroughUCS2(CCCDataObject obj, const unsigned char *buf, int32 bufsz) { /* buffers */ unsigned char* fromBuf = NULL; INTL_Unicode* ucs2Buf = NULL; unsigned char* toBuf = NULL; /* buffers' length */ uint32 ucs2BufLen = 0; uint32 fromBufLen = 0; uint32 toBufLen = 0; /* from & to csid */ uint16 fromCsid = INTL_GetCCCFromCSID(obj); uint16 toCsid = INTL_GetCCCToCSID(obj); /* get the fromBuf */ if( !( fromBuf = mz_mbNullConv( obj, buf, bufsz) ) ) return NULL; /* map fromBuf -> ucs2Buf */ fromBufLen = INTL_GetCCCLen(obj); ucs2BufLen = INTL_TextToUnicodeLen( fromCsid, fromBuf, fromBufLen ); if( !( ucs2Buf = XP_ALLOC( (ucs2BufLen + 1 ) * 2)) ){ return NULL; } /* be care, the return value is HOW MANY UNICODE IN THIS UCS2BUF, not how many bytes */ ucs2BufLen = INTL_TextToUnicode( fromCsid, fromBuf, fromBufLen, ucs2Buf, ucs2BufLen ); /* map ucs2Buf -> toBuf */ toBufLen = INTL_UnicodeToStrLen( toCsid, ucs2Buf, ucs2BufLen ); /* we get BYTES here :) */ if( !( toBuf = XP_ALLOC( toBufLen + 1 ) ) ) return NULL; INTL_UnicodeToStr( toCsid, ucs2Buf, ucs2BufLen, toBuf, toBufLen ); /* clean up after myself */ free( fromBuf ); free( ucs2Buf ); /* In order to let the caller know how long the buffer is, i have to set its tail NULL. */ toBuf[ toBufLen ] = 0; return toBuf; }
/* ** This function deletes a directory and everything under it. ** Deleting directories with "non-file" files, such as links, ** will produce behavior of XP_RemoveFile, since that's what is ** ultimately called. ** ** Return values: zero on failure, non-zero for success. */ int XP_RemoveDirectoryRecursive(const char *name, XP_FileType type) { XP_DirEntryStruct *entry; XP_StatStruct statbuf; int status; char* child; char* dot = "."; char* dotdot = ".."; int ret = 1; XP_Dir dir = XP_OpenDir(name, type); if (!dir) return 0; /* ** Go through the directory entries and delete appropriately */ while ((entry = XP_ReadDir(dir))) { /* ** Allocate space for current name + path separator + directory name + NULL */ child = XP_ALLOC( strlen(name) + 2 + strlen(entry->d_name) ); XP_STRCAT(child,"/"); XP_STRCAT(child,entry->d_name); if (!(status = XP_Stat(child, &statbuf, type))) { if (entry->d_name == dot || entry->d_name == dotdot) { /* Do nothing, rmdir will clean these up */ } else if (S_ISDIR(statbuf.st_mode)) { /* Recursive call to clean out subdirectory */ if (!XP_RemoveDirectoryRecursive(child, type)) ret = 0; } else { /* Everything that's not a directory is a file! */ if (XP_FileRemove(child, type) != 0) ret = 0; } } XP_FREE(child); } /* OK, remove the top-level directory if we can */ if (XP_RemoveDirectory(name, type) != 0) ret = 0; XP_CloseDir(dir); return ret; }
char* IStreamIn::ReadZString(){ char *pRet = 0; int32 iLen = ReadInt(); if( iLen ){ pRet = (char*)XP_ALLOC(iLen); Read( pRet, iLen ); } return pRet; }
/* * The beginning of a usemap MAP record. * Allocate the structure and initialize it. It will be filled * by later AREA tags. */ void lo_BeginMap(MWContext *context, lo_DocState *state, PA_Tag *tag) { PA_Block buff; char *str; lo_MapRec *map; map = XP_NEW(lo_MapRec); if (map == NULL) { state->top_state->out_of_memory = TRUE; return; } map->name = NULL; map->areas = NULL; map->areas_last = NULL; map->next = NULL; buff = lo_FetchParamValue(context, tag, PARAM_NAME); if (buff != NULL) { char *name; PA_LOCK(str, char *, buff); if (str != NULL) { int32 len; len = lo_StripTextWhitespace(str, XP_STRLEN(str)); } name = (char *)XP_ALLOC(XP_STRLEN(str) + 1); if (name == NULL) { map->name = NULL; } else { XP_STRCPY(name, str); map->name = name; } PA_UNLOCK(buff); PA_FREE(buff); } else { map->name = NULL; } if (map->name == NULL) { XP_DELETE(map); return; } state->top_state->current_map = map; }
void XFE_ReadAttachPanel::addAttachments(MSG_Pane *pane,MSG_AttachmentData* data) { // adopt storage of backend attachment list, free in removeAllAttachments _pane=pane; _attachments=data; MSG_AttachmentData* tmp; for (tmp = data ; tmp->url ; tmp++) { char *itemLabel=NULL; // Hack around back-end not naming the sent v-card. Use // description field: "Card for ...", to provide some // uniqueness among received vcards. if (tmp->real_name && XP_STRCASECMP(tmp->real_name,"vcard.vcf")==0 && tmp->description && strlen(tmp->description)>0) { itemLabel=(char*)XP_ALLOC(strlen(tmp->description)+4+1); sprintf(itemLabel,"%s.vcf",tmp->description); } // find a label for the attachment else if (tmp->real_name && strlen(tmp->real_name)>0) { itemLabel=XP_STRDUP(tmp->real_name); } else if (tmp->description && strlen(tmp->description)>0) { itemLabel=XP_STRDUP(tmp->description); } else if (tmp->real_type && strlen(tmp->real_type)>0) { itemLabel=XP_STRDUP(tmp->real_type); } else { itemLabel=XP_STRDUP("attachment"); } // translate problem characters in label to '_' char *s=itemLabel; while (*s) { if (*s==' ' || *s=='/' || *s=='\\') *s='_'; s++; } XFE_AttachPanelItem *item = new XFE_AttachPanelItem(this, tmp->url, itemLabel, tmp->real_type); addItem(item); // add to drag handler if (_attachDrag && item->image()) { _attachDrag->addDragWidget(item->image()); } if (itemLabel) XP_FREE(itemLabel); } // select first attachment by default if (_numItems>0) selectItem(_items[0]); }
/* This routine is designed to replace the following routine: mz_euc2euc mz_b52b5 mz_cns2cns mz_ksc2ksc mz_sjis2sjis mz_utf82utf8 It should also replace mz_gb2gb but currently mz_gb2gb also handle hz to gb. We need to move that functionality out of mz_gb2gb */ PRIVATE unsigned char * mz_mbNullConv(CCCDataObject obj, const unsigned char *buf, int32 bufsz) { int32 left_over; int32 len; unsigned char *p; unsigned char *ret; int32 total; intl_CharLenFunc CharLenFunc = intl_char_len_func[INTL_GetCCCCvtflag(obj)]; int charlen = 0; /* Get the unconverted buffer */ unsigned char *uncvtbuf = INTL_GetCCCUncvtbuf(obj); int32 uncvtsz = strlen((char *)uncvtbuf); /* return in the input is nonsense */ if ((!obj) || (! buf) || (bufsz < 0)) return NULL; /* Allocate Output Buffer */ total = uncvtsz + bufsz; ret = (unsigned char *) XP_ALLOC(total + 1); if (!ret) { INTL_SetCCCRetval(obj, MK_OUT_OF_MEMORY); return NULL; } /* Copy unconverted buffer into the output bufer */ memcpy(ret, uncvtbuf, uncvtsz); /* Copy the current input buffer into the output buffer */ memcpy(ret+uncvtsz, buf, bufsz); /* Walk through the buffer and figure out the left_over length */ for (p=ret, len=total, left_over=0; len > 0; p += charlen, len -= charlen) { if((charlen = CharLenFunc(*p)) > 1) { /* count left_over only if it is multibyte char */ if(charlen > len) /* count left_over only if the len is less than charlen */ left_over = len; }; } /* Copy the left over into the uncvtbuf */ if(left_over) memcpy(uncvtbuf, p - charlen, left_over); /* Null terminated the uncvtbuf */ uncvtbuf[left_over] = '\0'; /* Null terminate the return buffer and set the length */ INTL_SetCCCLen(obj, total - left_over); ret[total - left_over] = 0; return ret; }
char * XP_PlatformFileToURL (const char *name) { char *prefix = "file://"; char *retVal = XP_ALLOC (XP_STRLEN(name) + XP_STRLEN(prefix) + 1); if (retVal) { XP_STRCPY (retVal, "file://"); XP_STRCAT (retVal, name); } return retVal; }
void CContentView::AddChildSizeInfo(NAVCENTPOS *pPreference) { if(m_pChildSizeInfo == NULL) { m_pChildSizeInfo = XP_ListNew(); } NAVCENTPOS *pNew = (NAVCENTPOS *)XP_ALLOC(sizeof(NAVCENTPOS)); memcpy(pNew, pPreference, sizeof(NAVCENTPOS)); XP_ListAddObject(m_pChildSizeInfo, pNew); }
_esFEData * esMakeFEData(RDF_Resource parent, RDF_Resource child, int method) { _esFEData *feData; if ((feData = (_esFEData *)XP_ALLOC(3*sizeof(char *))) != NULL) { feData->parent = copyString(resourceID(parent)); feData->child = copyString(resourceID(child)); feData->method = method; } return(feData); }
/* * used for ARCHIVE= and SRC= * Create name of form "archive.jar/src.js" */ static char * lo_BuildJSArchiveURL( char *archive_name, char *filename ) { uint32 len = XP_STRLEN(archive_name) + XP_STRLEN(filename) + 2; char *path = XP_ALLOC(len); if (path) { XP_STRCPY(path, archive_name); XP_STRCAT(path, "/"); XP_STRCAT(path, filename); } return path; }
char *strdup(const char *source) { char *newAllocation; size_t stringLength; stringLength = strlen(source) + 1; newAllocation = (char *)XP_ALLOC(stringLength); if (newAllocation == NULL) return NULL; BlockMoveData(source, newAllocation, stringLength); return newAllocation; }
VR_INTERFACE(REGERR) VR_CreateRegistry( char *installation, char *programPath, char *versionStr ) { REGERR err; char * regname = vr_findVerRegName(); #if defined(XP_UNIX) && !defined(XP_MACOSX) char * regbuf = NULL; #endif if ( installation == NULL || *installation == '\0' ) return REGERR_PARAM; #if defined(XP_UNIX) && !defined(XP_MACOSX) #ifndef STANDALONE_REGISTRY if (bGlobalRegistry) #endif { regbuf = (char*)XP_ALLOC( 10 + XP_STRLEN(programPath) ); if (regbuf == NULL) return REGERR_MEMORY; XP_STRCPY( regbuf, programPath ); XP_STRCAT( regbuf, "registry" ); regname = regbuf; } #endif /* XP_UNIX */ PR_Lock(vr_lock); /* automatically creates it if not found */ err = NR_RegOpen( regname, &vreg ); if (err == REGERR_OK) { /* create default tree with 'installation' under Navigator */ /* set Current to the installation string */ err = vr_SetCurrentNav( installation, programPath, versionStr ); if ( REGERR_OK == err ) isInited = 1; else NR_RegClose( vreg ); } PR_Unlock(vr_lock); #if defined(XP_UNIX) && !defined(XP_MACOSX) XP_FREEIF( regbuf ); #endif return err; } /* CreateRegistry */
VR_INTERFACE(REGERR) VR_UninstallFileExistsInList(char *regPackageName, char *vrName) { REGERR err; RKEY key = 0; char *regbuf; char sharedfilesstr[MAXREGNAMELEN]; uint32 regbuflen = 0; uint32 curregbuflen = 0; uint32 len = 0; err = vr_Init(); if (err != REGERR_OK) return err; if ( regPackageName == NULL ) err = REGERR_PARAM; if ( vrName == NULL ) err = REGERR_PARAM; regbuflen = 256 + XP_STRLEN(regPackageName); regbuf = (char*)XP_ALLOC( regbuflen ); if (regbuf != NULL ) { err = vr_GetUninstallItemPath(regPackageName, regbuf, regbuflen); if (err == REGERR_OK) { curregbuflen = XP_STRLEN(regbuf); len = XP_STRLEN(SHAREDFILESSTR); if (len < (regbuflen - curregbuflen)) { XP_STRCAT(regbuf, SHAREDFILESSTR); err = NR_RegGetKey( vreg, ROOTKEY_PRIVATE, regbuf, &key ); } else err = REGERR_BUFTOOSMALL; } XP_FREEIF(regbuf); } else { err = REGERR_MEMORY; } if (err == REGERR_OK) err = NR_RegGetEntryString( vreg, key, vrName, sharedfilesstr, sizeof(sharedfilesstr) ); return err; } /* UninstallFileExistsInList */
intn PA_ParseStringToTags(MWContext *context, char *buf, int32 len, void *output_func) { intn ret; pa_DocData *fake_doc_data; NET_StreamClass s; fake_doc_data = XP_NEW_ZAP(pa_DocData); if (fake_doc_data == NULL) { return(-1); } fake_doc_data->doc_id = 100164; fake_doc_data->window_id = context; fake_doc_data->output_tag = (PA_OutputFunction *)output_func; fake_doc_data->hold_buf = XP_ALLOC(HOLD_BUF_UNIT * sizeof(char)); if (fake_doc_data->hold_buf == NULL) { XP_DELETE(fake_doc_data); return(-1); } fake_doc_data->hold_size = HOLD_BUF_UNIT; fake_doc_data->brute_tag = P_UNKNOWN; fake_doc_data->format_out = FO_PRESENT_INLINE; fake_doc_data->parser_stream = XP_NEW(NET_StreamClass); if (fake_doc_data->parser_stream == NULL) { XP_FREE(fake_doc_data->hold_buf); XP_DELETE(fake_doc_data); return(-1); } /* We don't need most of the fields in the fake stream */ fake_doc_data->parser_stream->complete = PA_MDLComplete; fake_doc_data->parser_stream->data_object = (void *)fake_doc_data; fake_doc_data->is_inline_stream = TRUE; s.data_object=fake_doc_data; ret = PA_ParseBlock(&s, (const char *)buf, (int)len); if (ret > 0) { PA_MDLComplete(&s); } return(ret); }
NET_StreamClass * OLE_ViewStream(int format_out, void *pDataObj, URL_Struct *urls, MWContext *pContext) { NET_StreamClass *stream = nil, *viewstream; char *org_content_type; if (!(stream = XP_NEW_ZAP(NET_StreamClass))) { XP_TRACE(("OLE_ViewStream memory lossage")); return 0; } stream->name = "ole viewer"; stream->complete = ole_view_complete; stream->abort = ole_view_abort; stream->is_write_ready = ole_view_write_ready; stream->data_object = NULL; stream->window_id = pContext; stream->put_block = (MKStreamWriteFunc)ole_view_write; org_content_type = urls->content_type; urls->content_type = 0; StrAllocCopy(urls->content_type, TEXT_HTML); urls->is_binary = 1; /* secret flag for mail-to save as */ if((viewstream=NET_StreamBuilder(format_out, urls, pContext)) != 0) { char *buffer = (char*) XP_ALLOC(XP_STRLEN(fakehtml) + XP_STRLEN(urls->address) + 1); if (buffer) { XP_SPRINTF(buffer, fakehtml, urls->address); (*viewstream->put_block)(viewstream, buffer, XP_STRLEN(buffer)); (*viewstream->complete)(viewstream); XP_FREE(buffer); } } /* XXX hack alert - this has to be set back for abort to work correctly */ XP_FREE(urls->content_type); urls->content_type = org_content_type; return stream; }
void main() { int ch; char *b; int32 src_count; char *dst; int32 dst_count; char * src; int src_size; int done; done = ch = 0; src_size = src_count = 0; src = (char *) XP_ALLOC(TEST_CSS_INITIAL_BUFSIZ); if (src) src_size = TEST_CSS_INITIAL_BUFSIZ; while (!done) { for (b = src + src_count; src_count < src_size; src_count++, b++) { *b = ch = getc(stdin); /* Either the null character or EOF will serve to terminate. */ if (ch == EOF || ch == '\0') { done = 1; /* We don't need to add this character to the src_count */ break; } } if (!done) { src_size += TEST_CSS_INCR_BUFSIZ; src = (char *) XP_REALLOC(src, src_size); if (!src) { src_size = src_count = 0; printf("css test: memory allocation failure\n"); done = 1; } } } /* The src_count need not include the terminating NULL or EOF */ CSS_ConvertToJS(src, src_count, &dst, &dst_count); printf("%s", dst); XP_FREE(dst); }
PRIVATE INTL_CompoundStr* INTL_CompoundStrNewSeg_p(INTL_Encoding_ID inencoding, unsigned char* intext) { INTL_CompoundStr *This; This = XP_ALLOC(sizeof(INTL_CompoundStr)); if(This != NULL) { char *p_text=0; StrAllocCopy(p_text, (char*)intext); This->text = (unsigned char*)p_text; This->next = NULL; This->encoding = inencoding; } return This; }
char *XP_AppendStr(char *in, const char *append) { int alen, inlen; alen = XP_STRLEN(append); if (in) { inlen = XP_STRLEN(in); in = (char*) XP_REALLOC(in,inlen+alen+1); if (in) { XP_MEMCPY(in+inlen, append, alen+1); } } else { in = (char*) XP_ALLOC(alen+1); if (in) { XP_MEMCPY(in, append, alen+1); } } return in; }
char * hk_TagIndexToFunctionString(int32 tag_indx) { char *total_name; total_name = NULL; if (tag_indx == P_TEXT) { total_name = XP_STRDUP("TEXT_hook"); } else if (tag_indx == P_UNKNOWN) { total_name = NULL; } else if (tag_indx >= P_MAX) { total_name = NULL; } else { const char *tag_name; tag_name = PA_TagString(tag_indx); if (tag_name == NULL) { total_name = NULL; } else { int32 len; len = XP_STRLEN(tag_name) + XP_STRLEN("_hook") + 1; total_name = XP_ALLOC(len); if (total_name != NULL) { XP_STRCPY(total_name, tag_name); XP_STRCAT(total_name, "_hook"); } } } return(total_name); }