dthelp: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / dtmail / dtmail / RoamCmds.C
index 7fb83edb5f1c4ee0cb8867faafe071052ec6e8a9..7c55d298926511ad0e8dbbdec13cc7a91f73fd23 100644 (file)
@@ -16,7 +16,7 @@
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
+ * License along with these libraries and programs; if not, write
  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  * Floor, Boston, MA 02110-1301 USA
  */
@@ -76,6 +76,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <stdint.h>
 #include <pwd.h>
 #include <X11/Intrinsic.h>
 #include <Xm/Text.h>
@@ -143,7 +144,7 @@ extern XtPointer _XmStringUngenerate (
 #include <sys/file.h>
 
 
-extern forceUpdate( Widget );
+extern void forceUpdate( Widget );
 
 RoamCmd::RoamCmd
 (char *name, char *label, int active, RoamMenuWindow *window)
@@ -317,6 +318,8 @@ OpenContainerCmd::OpenContainerCmd (
                                ) : RoamInterruptibleCmd (name, label, active)
 {
     _menuWindow = window;
+    _open_create_flag = DTM_FALSE;
+    _open_lock_flag = DTM_FALSE;
 }
 
 // Parent's execute() ends up calling derived class's doit()
@@ -422,6 +425,10 @@ ConvertContainerCmd::ConvertContainerCmd(
     _num_converted = 0;
     _num_to_be_converted = 0;
     _dialog = NULL;
+    _criteria = NULL;
+    _conv_cb = NULL;
+    _src = NULL;
+    _dest = NULL;
 }
 
 void
@@ -533,7 +540,7 @@ ConvertContainerCmd::post_dialog()
     
     char * buf = new char[25];
     
-    sprintf(buf, "Converted: %3d%", 0);
+    sprintf(buf, "Converted: %3d%%", 0);
     
     _dialog->post ("Mailer",
                   buf,
@@ -614,6 +621,7 @@ ChooseCmd::ChooseCmd(
                      ) :  NoUndoCmd( name, label, active )
 {
     _menuwindow = window;
+    _msgno = NULL;
 }
 
 void
@@ -654,6 +662,7 @@ DeleteCmd::DeleteCmd(
                      ) :  Cmd ( name, label, active )
 {
     _menuwindow = window;
+    _msgno = NULL;
 }
 
 void
@@ -891,6 +900,8 @@ UnifiedSelectMailboxCmd::UnifiedSelectMailboxCmd (
                this,
                parent)
 {
+   _only_show_mailboxes = DTM_FALSE;
+
    if (! _is_initialized)
    {
        FORCE_SEGV_DECL(DtMail::Session, m_session);
@@ -1392,6 +1403,8 @@ UndeleteCmd::UndeleteCmd (
     _menuwindow = window;
     _undelFromList = NULL;
     _fromList = viaDeleteList;
+    _clientData = NULL;
+    _num_deleted = 0;
 }
 
 UndeleteCmd::~UndeleteCmd()
@@ -1495,6 +1508,9 @@ MoveCopyCmd::MoveCopyCmd( char *name,
     _menuwindow = menu_window;
     _copy_button = NULL;
     _move_button = NULL;
+    _file_list = NULL;
+    _file_text = NULL;
+    _default_button = NULL;
 }
 
 MoveCopyCmd::~MoveCopyCmd()
@@ -1548,7 +1564,7 @@ MoveCopyCmd::doit()
                _copy_button,
                XmNhelpCallback, 
                HelpCB,
-               "dtmailViewmainWindowWork-AreapanedWform2RowColumnMoveCopy");
+               (void *)"dtmailViewmainWindowWork-AreapanedWform2RowColumnMoveCopy");
        XtAddCallback(
                _copy_button,
                XmNactivateCallback,
@@ -1644,7 +1660,7 @@ MoveCopyCmd::fileSelectedCallback2 (
        // If a string was successfully extracted, call
        // unifiedMailboxSelected to handle the file.
        *selected = '\0';
-       if (NULL != dname) strcat(selected, dname);
+       if (NULL != dname) snprintf(selected, sizeof(selected), "%s", dname);
        strcat(selected, fname);
         obj->updateUnifiedData();
        obj->unifiedMailboxSelected(
@@ -1836,7 +1852,7 @@ PrintCmd::printit( int silent )
     DebugPrintf(1, "%s: printit\n", name());
     
     // Create tmp file.
-    sprintf(tmpdir, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
+    snprintf(tmpdir, MAXPATHLEN+1, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
     if ((p = tempnam(tmpdir, "dtmail")) == NULL) {
        delete [] tmpdir;
        return;
@@ -2239,6 +2255,7 @@ SaveAttachCmd::SaveAttachCmd ( char *name,
                       parent)
 {
    _parent = clientData;
+   _name = NULL;
 }
 
 SaveAttachCmd::SaveAttachCmd ( 
@@ -2260,6 +2277,7 @@ SaveAttachCmd::SaveAttachCmd (
                       parent )
 {
    _parent = clientData;
+   _name = NULL;
 }
 
 SaveAttachCmd::SaveAttachCmd ( 
@@ -2281,6 +2299,7 @@ SaveAttachCmd::SaveAttachCmd (
                       parent )
 {
     _parent = clientData;
+    _name = NULL;
 }
 
 void
@@ -2427,7 +2446,7 @@ Check file permissions and retry."),
     if (NULL == _roam_menu_window)
     {
        char    *text_buf = _text_editor->get_contents();
-       writeText((XtPointer) fd, text_buf);
+       writeText((XtPointer) (intptr_t) fd, text_buf);
         XtFree((char*) text_buf);
     }
     else
@@ -2452,9 +2471,9 @@ SaveAsTextCmd::writeTextFromScrolledList(int fd)
     // Create temp file.
     //
     char *tmpdir = new char[MAXPATHLEN+1];
-    sprintf(tmpdir, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
+    snprintf(tmpdir, MAXPATHLEN+1, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY);
     if ((tmppath = tempnam(tmpdir, "dtmail")) == NULL) {
-       sprintf(buf, GETMSG(DT_catd, 3, 51, "Unable to create %s."), tmpdir);
+       snprintf(buf, sizeof(buf), GETMSG(DT_catd, 3, 51, "Unable to create %s."), tmpdir);
        _genDialog->setToErrorDialog(GETMSG(DT_catd, 3, 52, "Mailer"), buf);
         helpId = DTMAILHELPNOCREATE;        
        _genDialog->post_and_return(helpId);
@@ -2492,8 +2511,8 @@ SaveAsTextCmd::writeTextFromScrolledList(int fd)
        next_msg->display(
                        visible_headers,
                        &SaveAsTextCmd::writeText,
-                       (XtPointer) fd);
-       writeText((XtPointer) fd, "\n\n");
+                       (XtPointer) (intptr_t) fd);
+       writeText((XtPointer) (intptr_t) fd, "\n\n");
     } while ((next_msg = mailbox->nextMessage()) != (DmxMsg *) NULL);
     delete mailbox;
 
@@ -2725,7 +2744,7 @@ void RenameAttachCmd::doit()
     
     renameDialog = aa->getRenameDialog();
     
-    sprintf(buf, GETMSG(DT_catd, 3, 57, "Rename attachment as"));
+    sprintf(buf, "%s", GETMSG(DT_catd, 3, 57, "Rename attachment as"));
     
     message = XmStringCreateLocalized(buf);
     
@@ -3239,6 +3258,7 @@ OtherAliasesCmd::OtherAliasesCmd(
     int active)
     : NoUndoCmd (name, label, active)
 {
+        _header = NULL;
 }
 
 void
@@ -3373,7 +3393,7 @@ VacationCmd::stopVacation()
 {
     char *forwardfile = new char[MAXPATHLEN+1];
     
-    sprintf(forwardfile, "%s/%s", getenv("HOME"), _forwardFile);
+    snprintf(forwardfile, MAXPATHLEN+1, "%s/%s", getenv("HOME"), _forwardFile);
 
     // Remove the current .forward file (it has vacation in it)
     // Recover and replace the original backup forward file, if 
@@ -3394,7 +3414,7 @@ VacationCmd::priorVacationRunning()
     Boolean    retval = FALSE;
     char *forwardfile = new char[MAXPATHLEN+1];
 
-    sprintf(forwardfile, "%s/%s", getenv("HOME"), _forwardFile);
+    snprintf(forwardfile, MAXPATHLEN+1, "%s/%s", getenv("HOME"), _forwardFile);
 
     if (SafeAccess(forwardfile, F_OK) != 0) {
        delete [] forwardfile;
@@ -3473,7 +3493,7 @@ VacationCmd::handleForwardFile()
        else
          dialog = theRoamApp.genDialog();
 
-       sprintf(error_buf, GETMSG(DT_catd, 1, 102, "You are already using the forwarding facility for\nsomething other than Vacation.  While Vacation is\nrunning, Vacation will be appended to this other\nforwarding activity. Is it still OK to start Vacation?\0"));
+       sprintf(error_buf, "%s", GETMSG(DT_catd, 1, 102, "You are already using the forwarding facility for\nsomething other than Vacation.  While Vacation is\nrunning, Vacation will be appended to this other\nforwarding activity. Is it still OK to start Vacation?\0"));
 
        dialog->setToQuestionDialog(GETMSG(DT_catd, 1, 103, "Mailer"), 
                                    error_buf);
@@ -3521,7 +3541,7 @@ VacationCmd::handleForwardFile()
        else
          dialog = theRoamApp.genDialog();
 
-       sprintf(error_buf, GETMSG(DT_catd, 1, 104, "You are already running the vacation program in your .forward file.\nConsult documentation on how to stop it and remove it from your .forward file.\nTry this command after fixing that problem.\0"));
+       sprintf(error_buf, "%s", GETMSG(DT_catd, 1, 104, "You are already running the vacation program in your .forward file.\nConsult documentation on how to stop it and remove it from your .forward file.\nTry this command after fixing that problem.\0"));
        
        dialog->setToErrorDialog("Error", error_buf);
        helpId = DTMAILHELPREMOVEVACATION;
@@ -3712,6 +3732,7 @@ VacationCmd::handleForwardFile()
            delete [] messagefile;
            delete [] error_buf;
            delete [] forwardfile;
+           SafeClose(bkup_fd);
            SafeClose(fwd_fd);
            return 1;
        }
@@ -3734,6 +3755,7 @@ VacationCmd::handleForwardFile()
            strlen(append_buf2)) {
            // error
            SafeClose(bkup_fd);
+           SafeClose(fwd_fd);
            delete [] buf;
            delete [] messagefile;
            delete [] error_buf;
@@ -3791,7 +3813,7 @@ VacationCmd::recoverForwardFile(
        char *buf = new char[BUFSIZ+1];
        int  fd;
 
-       sprintf(buf, file);
+       sprintf(buf, "%s", file);
        strcat(buf, _backupSuffix);
 
        if (rename(buf, file) < 0) {
@@ -3811,7 +3833,7 @@ VacationCmd::recoverForwardFile(
            return(-1);
        }       
 
-       if ((fd = SafeOpen(file, O_RDONLY)) == 0) {
+       if ((fd = SafeOpen(file, O_RDONLY)) == -1) {
            delete [] buf;
            return(-1);
        }
@@ -3898,7 +3920,7 @@ VacationCmd::parseVacationMessage()
     struct stat buf;
     if (SafeFStat(fd, &buf) < 0) {
 
-       sprintf(dialog_text, 
+       sprintf(dialog_text, "%s",
                GETMSG(DT_catd, 1, 105, "Cannot open .vacation.msg file -- No write permission."));
        dialog->setToQuestionDialog("Mailer", dialog_text);
        helpId = DTMAILHELPNOWRITEVACATION;
@@ -3915,16 +3937,14 @@ VacationCmd::parseVacationMessage()
     size_t map_size = (int) (buf.st_size + 
                            (page_size - (buf.st_size % page_size)));
 
-    if (buf.st_size == 0)
+    if (buf.st_size == 0) {
+      SafeClose(fd);
       return;
+   }
 
     int free_buf = 0;
     mbuf.size = buf.st_size;
-#ifdef __osf__
-    mbuf.buffer = (char *)mmap(0, map_size, PROT_READ, MAP_PRIVATE, fd, 0);
-#else
     mbuf.buffer = mmap(0, map_size, PROT_READ, MAP_PRIVATE, fd, 0);
-#endif
     if (mbuf.buffer == (char *)-1) {
        free_buf = 1;
        mbuf.buffer = new char[mbuf.size];
@@ -4086,7 +4106,7 @@ VacationCmd::handleMessageFile(
     }
 
     if (msg_file_exists >= 0 &&  text_changed) {
-       sprintf(dialog_text, 
+       sprintf(dialog_text, "%s",
                GETMSG(DT_catd, 1, 106, ".vacation.msg file exists.  Replace with new text?"));
        dialog->setToQuestionDialog("Mailer", dialog_text);
        helpId = DTMAILHELPEXISTSVACATION;
@@ -4104,7 +4124,7 @@ VacationCmd::handleMessageFile(
 
        fd = SafeOpen(messagefile, O_WRONLY | O_CREAT);
        if (fd < 0) {
-           sprintf(dialog_text, 
+           sprintf(dialog_text, "%s",
                GETMSG(DT_catd, 1, 107, "Cannot open .vacation.msg file -- No write permission."));
            dialog->setToQuestionDialog("Mailer", dialog_text);
            helpId = DTMAILHELPERROR;