1 /* Copyright (c) 1993 by Sanjay Ghemawat */
2 #include "basic.h"
3 #include "cal_tcl.h"
4 #include "ical.h"
5 #include "item_tcl.h"
6 
7 /*
8  * Notice Creator
9  *
10  *      notice <name>
11  */
12 
Cmd_CreateNotice(ClientData,Tcl_Interp * tcl,int argc,const char * argv[])13 int Cmd_CreateNotice(ClientData, Tcl_Interp* tcl, int argc, const char* argv[]) {
14     if (argc != 1) {
15         TCL_Error(tcl, "invalid arguments to notice");
16     }
17 
18     Item_Tcl* item = new Item_Tcl(tcl, new Notice, 0);
19     TCL_Return(tcl, (char*) item->handle());
20 }
21 
22 /*
23  * Appointment Creator
24  *
25  *      appointment <name>      -- Returns <name>
26  */
27 
Cmd_CreateAppt(ClientData,Tcl_Interp * tcl,int argc,const char * argv[])28 int Cmd_CreateAppt(ClientData, Tcl_Interp* tcl, int argc, const char* argv[]) {
29     if (argc != 1) {
30         TCL_Error(tcl, "invalid arguments to appointment");
31     }
32 
33     Item_Tcl* item = new Item_Tcl(tcl, new Appointment, 0);
34     TCL_Return(tcl, (char*) item->handle());
35 }
36 
37 /*
38  * Calendar Creator
39  *
40  *      calendar <name> <filename>      -- Returns <name>
41  */
42 
Cmd_CreateCalendar(ClientData,Tcl_Interp * tcl,int argc,const char * argv[])43 int Cmd_CreateCalendar(ClientData, Tcl_Interp* tcl, int argc, const char* argv[]) {
44     if (argc != 3) {
45         TCL_Error(tcl, "invalid arguments to calendar");
46     }
47 
48     Calendar_Tcl* c = new Calendar_Tcl(tcl, argv[1], argv[2]);
49     if (!c->error())
50         TCL_Return(tcl, "");
51 
52     Tcl_SetResult(tcl, (char*)c->error_msg(), TCL_VOLATILE);
53     delete c;
54     return TCL_ERROR;
55 }
56 
57 /*
58  * usage        ical_expand_file_name <filename>
59  * effects      Converts <filename> into a name suitable for passing
60  *              to the local operating system.  This transformation
61  *              may involve tilde substitution.  If any part of the
62  *              of the translation fails, this routine returns an
63  *              error.  Otherwise it returns the translated file name.
64  */
Cmd_ExpandFileName(ClientData,Tcl_Interp * tcl,int argc,const char * argv[])65 int Cmd_ExpandFileName(ClientData, Tcl_Interp* tcl, int argc, const char* argv[]) {
66     if (argc != 2) {
67         TCL_Error(tcl, "invalid arguments to expand_file_name");
68     }
69 
70     Tcl_DString buf;
71     char* result = Tcl_TranslateFileName(tcl, argv[1], &buf);
72     if (result != NULL) {
73         Tcl_SetResult(tcl, result, TCL_VOLATILE);
74         Tcl_DStringFree(&buf);
75         return TCL_OK;
76     } else {
77         return TCL_ERROR;
78     }
79 }
80