MCPcopy Create free account
hub / github.com/Singular/Singular / sdb_edit

Function sdb_edit

Singular/sdb.cc:109–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109void sdb_edit(procinfo *pi)
110{
111 char * filename = omStrDup("/tmp/sdXXXXXX");
112 int f=mkstemp(filename);
113 if (f==-1)
114 {
115 Print("cannot open %s\n",filename);
116 omFree(filename);
117 return;
118 }
119 if (pi->language!= LANG_SINGULAR)
120 {
121 Print("cannot edit type %d\n",pi->language);
122 si_close(f);
123 }
124 else
125 {
126 const char *editor=getenv("EDITOR");
127 if (editor==NULL)
128 editor=getenv("VISUAL");
129 if (editor==NULL)
130 editor="vi";
131 editor=omStrDup(editor);
132
133 if (pi->data.s.body==NULL)
134 {
135 iiGetLibProcBuffer(pi);
136 if (pi->data.s.body==NULL)
137 {
138 PrintS("cannot get the procedure body\n");
139 si_close(f);
140 si_unlink(filename);
141 omFree(filename);
142 return;
143 }
144 }
145
146 size_t res=write(f,pi->data.s.body,strlen(pi->data.s.body));
147 si_close(f);
148 if (res==-1)
149 {
150 PrintS("cannot write the procedure body\n");
151 si_unlink(filename);
152 omFree(filename);
153 return;
154 }
155
156 int pid=fork();
157 if (pid!=0)
158 {
159 si_wait(&pid);
160 }
161 else if(pid==0)
162 {
163 if (strchr(editor,' ')==NULL)
164 {
165 execlp(editor,editor,filename,NULL);
166 Print("cannot exec %s\n",editor);

Callers 2

jjEXTENDED_SYSTEMFunction · 0.85
sdbFunction · 0.85

Calls 4

iiGetLibProcBufferFunction · 0.85
PrintSFunction · 0.85
myfreadFunction · 0.85
PrintFunction · 0.50

Tested by

no test coverage detected