Free Hero Mesh

Check-in [eb79705225]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Implement the PIPE function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: eb7970522578fd3bac87edc4ffe6e3628049fb95
User & Date: user on 2021-09-26 02:11:17
Other Links: manifest | tags
Context
2021-09-26
22:10
Add edit.doc (documentation of level editor) check-in: 887efd70b0 user: user tags: trunk
02:11
Implement the PIPE function. check-in: eb79705225 user: user tags: trunk
2021-09-22
01:11
Add missing documentation for MAX_LEVEL SQL function, and default key bindings for go to first/last level. check-in: f6ec7187a2 user: user tags: trunk
Changes

Modified function.c from [2d1691d53b] to [e41cea6b80].

300
301
302
303
304
305
306







































307
308
309
310
311
312
313
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







static void fn_pfsize(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_result_int(cxt,*(Uint8*)sqlite3_user_data(cxt));
}

static void fn_picture_size(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_result_int(cxt,picture_size);
}

static void fn_pipe(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  const char*name=sqlite3_value_text(*argv);
  FILE*fp;
  int i;
  char buf[512];
  sqlite3_str*str;
  if(!name) return;
  fp=popen(name,"r");
  if(!fp) {
    sqlite3_result_error(cxt,"Cannot open pipe",-1);
    return;
  }
  str=sqlite3_str_new(userdb);
  for(;;) {
    i=fread(buf,1,512,fp);
    if(i<=0) break;
    sqlite3_str_append(str,buf,i);
  }
  pclose(fp);
  i=sqlite3_str_errcode(str);
  if(i==SQLITE_NOMEM) {
    sqlite3_result_error_nomem(cxt);
  } else if(i==SQLITE_TOOBIG) {
    sqlite3_result_error_toobig(cxt);
  } else if(i) {
    sqlite3_result_error(cxt,"Unknown error",-1);
  }
  if(i) {
    sqlite3_free(sqlite3_str_finish(str));
    return;
  }
  if(i=sqlite3_str_length(str)) {
    sqlite3_result_blob(cxt,sqlite3_str_finish(str),i,sqlite3_free);
  } else {
    sqlite3_free(sqlite3_str_finish(str));
    sqlite3_result_zeroblob(cxt,0);
  }
}

static void fn_read_lump_at(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_int64 of=sqlite3_value_int64(argv[0]);
  FILE*fp=sqlite3_value_pointer(argv[1],"http://zzo38computer.org/fossil/heromesh.ui#FILE_ptr");
  long sz;
  Uint8*buf;
  if(!fp) return;
1057
1058
1059
1060
1061
1062
1063

1064
1065
1066
1067
1068
1069
1070
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110







+







  sqlite3_create_function(userdb,"MOVENUMBER",0,SQLITE_UTF8,0,fn_movenumber,0,0);
  sqlite3_create_function(userdb,"MVALUE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_mvalue,0,0);
  sqlite3_create_function(userdb,"NVALUE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_zero_extend,0,0);
  sqlite3_create_function(userdb,"OVALUE",1,SQLITE_UTF8,0,fn_ovalue,0,0);
  sqlite3_create_function(userdb,"PFHEIGHT",0,SQLITE_UTF8,&pfheight,fn_pfsize,0,0);
  sqlite3_create_function(userdb,"PFWIDTH",0,SQLITE_UTF8,&pfwidth,fn_pfsize,0,0);
  sqlite3_create_function(userdb,"PICTURE_SIZE",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_picture_size,0,0);
  sqlite3_create_function(userdb,"PIPE",1,SQLITE_UTF8,0,fn_pipe,0,0);
  sqlite3_create_function(userdb,"READ_LUMP_AT",2,SQLITE_UTF8,0,fn_read_lump_at,0,0);
  sqlite3_create_function(userdb,"RESOURCE",-1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_resource,0,0);
  sqlite3_create_function(userdb,"SIGN_EXTEND",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_sign_extend,0,0);
  sqlite3_create_function(userdb,"SOLUTION_CACHEID",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,ptr1,fn_cacheid,0,0);
  sqlite3_create_function(userdb,"TRACE_OFF",0,SQLITE_UTF8,"",fn_trace_on,0,0);
  sqlite3_create_function(userdb,"TRACE_ON",0,SQLITE_UTF8,"\x01",fn_trace_on,0,0);
  sqlite3_create_function(userdb,"XY",2,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_xy,0,0);

Modified picture.c from [6e4f43abc3] to [b22c8897cb].

1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1176
1177
1178
1179
1180
1181
1182







1183
1184
1185
1186
1187
1188
1189







-
-
-
-
-
-
-







      break;
  }
  SDL_UnlockSurface(screen);
}

int modal_draw_popup(const unsigned char*txt) {
  SDL_Event ev;
#if 0
  SDL_Rect r;
  r.x=r.y=0;
  r.w=screen->w;
  r.h=4;
  SDL_FillRect(screen,&r,0xFE);
#endif
  set_cursor(XC_iron_cross);
  redraw:
  draw_popup(txt);
  SDL_Flip(screen);
  while(SDL_WaitEvent(&ev)) switch(ev.type) {
    case SDL_QUIT:
      SDL_PushEvent(&ev);

Modified sql.doc from [8a894d3d40] to [3bb83c39fa].

95
96
97
98
99
100
101




102
103
104
105
106
107
108
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112







+
+
+
+







OVALUE(number)
  Makes a game value of type 'object'. The argument is the ID number of
  the object in the OBJECTS table.

PICTURE_SIZE()
  Tell you the picture size.

PIPE(command)
  Execute a operating system shell command and return the output of that
  command as a blob.

READ_LUMP_AT(offset,ptr)
  Used internally; there is no way to use this in user SQL codes.

RESOURCE(...)
  Given the list of resource names, read a value from the X resource
  manager. Returns null if there is no such resource value.