⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textmisc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
   userTrans.Trim();   if ( userTrans.size() > 0 ) {      if ( userTrans.StartsWith("#override") )	 XtOverrideTranslations(text, XtParseTranslationTable(userTrans));      else if ( userTrans.StartsWith("#augment") )	 XtAugmentTranslations(text, XtParseTranslationTable(userTrans));      else	 XtVaSetValues(text, XmNtranslations,		       XtParseTranslationTable(userTrans), NULL);   }   return text;} // End CreateText/*-------------------------------------------------------------------------- *  Set Text widget from character array */voidTextSetString(Widget w, CharC c){   if ( c.Length() == 0 ) {      if ( XmIsTextField(w) ) XmTextFieldSetString(w, "");      else		      XmTextSetString(w, "");      return;   }//// Use the existing string if possible//   if ( c.FollowedByNull() ) {      if ( XmIsTextField(w) ) XmTextFieldSetString(w, (char*)c.Addr());      else		      XmTextSetString(w, (char*)c.Addr());      return;   }//// Use the internal buffer if possible//   if ( c.Length() <= BUFLEN ) {      strncpy(buffer, c.Addr(), c.Length());      buffer[c.Length()] = 0;      if ( XmIsTextField(w) ) XmTextFieldSetString(w, buffer);      else		      XmTextSetString(w, buffer);      return;   }//// If we reached this point, we will try to write the data to a//   temporary file so we can null-terminate it.//   Boolean	error = False;   char	*tmpFile = tempnam(NULL, NULL);   if ( !tmpFile ) error = True;//// Open the file//   int	fd;   if ( !error ) {      fd = open(tmpFile, O_RDWR|O_CREAT|O_TRUNC, 0600);      if ( fd < 0 ) {	 free(tmpFile);	 error = True;      }   }//// Write the file and the null//   if ( !error ) {      if ( !c.WriteFile(fd) || write(fd, &null, 1) != 1 ) {	 unlink(tmpFile);	 free(tmpFile);	 error = True;      }      close(fd);   }//// Map the file//   MappedFileC	*mf;   if ( !error ) {      mf = MapFile(tmpFile);      if ( !mf ) {	 unlink(tmpFile);	 free(tmpFile);	 error = True;      }   }//// Use the data from the mapped file//   if ( !error ) {      if ( XmIsTextField(w) ) XmTextFieldSetString(w, (char*)mf->Addr());      else		      XmTextSetString(w, (char*)mf->Addr());      UnmapFile(mf);      unlink(tmpFile);      free(tmpFile);      return;   }//// If we reached this point, we have to use the 1K at a time method//   if ( XmIsText(w) ) XmTextDisableRedisplay(w);   if ( XmIsTextField(w) ) XmTextFieldSetString(w, "");   else			   XmTextSetString(w, "");   const char	*str = c.Addr();   int		rem = c.Length();   while ( rem > 0 ) {      int	len = MIN(rem, BUFLEN);      strncpy(buffer, str, len);      buffer[len] = 0;      if ( XmIsTextField(w) )	 XmTextFieldInsert(w, XmTextGetLastPosition(w), buffer);      else	 XmTextInsert(w, XmTextGetLastPosition(w), buffer);      str += len;      rem -= len;   }   if ( XmIsTextField(w) ) XmTextFieldShowPosition(w, 0);   else			   XmTextShowPosition(w, 0);   if ( XmIsText(w) ) XmTextEnableRedisplay(w);} // End TextSetString/*-------------------------------------------------------------------------- *  Insert character array in text widget */voidTextInsert(Widget w, XmTextPosition pos, CharC c){   if ( c.Length() == 0 ) return;//// Use the existing string if possible//   if ( c.FollowedByNull() ) {      if ( XmIsTextField(w) ) XmTextFieldInsert(w, pos, (char*)c.Addr());      else		      XmTextInsert(w, pos, (char*)c.Addr());      return;   }//// Use the internal buffer if possible//   if ( c.Length() <= BUFLEN ) {      strncpy(buffer, c.Addr(), c.Length());      buffer[c.Length()] = 0;      if ( XmIsTextField(w) ) XmTextFieldInsert(w, pos, buffer);      else		      XmTextInsert(w, pos, buffer);      return;   }//// If we reached this point, we will try to write the data to a//   temporary file so we can null-terminate it.//   Boolean	error = False;   char	*tmpFile = tempnam(NULL, NULL);   if ( !tmpFile ) error = True;//// Open the file//   int	fd;   if ( !error ) {      fd = open(tmpFile, O_RDWR|O_CREAT|O_TRUNC, 0600);      if ( fd < 0 ) {	 free(tmpFile);	 error = True;      }   }//// Write the file and the null//   if ( !error ) {      if ( !c.WriteFile(fd) || write(fd, &null, 1) != 1 ) {	 unlink(tmpFile);	 free(tmpFile);	 error = True;      }      close(fd);   }//// Map the file//   MappedFileC	*mf;   if ( !error ) {      mf = MapFile(tmpFile);      if ( !mf ) {	 unlink(tmpFile);	 free(tmpFile);	 error = True;      }   }//// Use the data from the mapped file//   if ( !error ) {      if ( XmIsTextField(w) ) XmTextFieldInsert(w, pos, (char*)mf->Addr());      else		      XmTextInsert(w, pos, (char*)mf->Addr());      UnmapFile(mf);      unlink(tmpFile);      free(tmpFile);      return;   }//// If we reached this point, we have to use the 1K at a time method//   if ( XmIsText(w) ) XmTextDisableRedisplay(w);   const char	*str = c.Addr();   int		rem = c.Length();   while ( rem > 0 ) {      int	len = MIN(rem, BUFLEN);      strncpy(buffer, str, len);      buffer[len] = 0;      if ( XmIsTextField(w) ) XmTextFieldInsert(w, pos, buffer);      else		      XmTextInsert(w, pos, buffer);      pos += len;      str += len;      rem -= len;   }   if ( XmIsText(w) ) XmTextEnableRedisplay(w);} // End TextInsert/*-------------------------------------------------------------------------- *  Set Text widget from string list */voidTextSetList(Widget w, const StringListC& list){   StringC	tmp;   unsigned	count = list.size();   for (int i=0; i<count; i++) {      if ( i > 0 ) tmp += '\n';      tmp += *list[i];   }   XmTextSetString(w, tmp);} // End TextSetList/*-------------------------------------------------------------------------- *  Set string list from text widget */voidTextGetList(Widget w, StringListC& list){   char		*cs = XmTextGetString(w);   CharC	src(cs);   StringC	tmp;   u_int	offset = 0;   CharC	entry = src.NextWord(offset, "\n");   while ( entry.Length() > 0 ) {      tmp = entry;      list.add(tmp);      offset = entry.Addr() - src.Addr() + 1;      entry = src.NextWord(offset, "\n");   }   XtFree(cs);} // End TextSetList

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -