vfprintf(stderr, fmt, ap);
va_end(ap);
} // end of htrc
/***********************************************************************/ /* Plug initialization routine. */ /* Language points on initial language name and eventual path. */ /* Return value is the pointer to the Global structure. */ /***********************************************************************/
PGLOBAL PlugInit(LPCSTR Language, size_t worksize)
{
PGLOBAL g;
if (trace(2))
htrc("PlugInit: Language='%-.256s'\n",
((!Language) ? "Null" : (char*)Language));
try {
g = new GLOBAL;
} catch (...) {
fprintf(stderr, MSG(GLOBAL_ERROR), (int)sizeof(GLOBAL)); return NULL;
} // end try/catch
/***********************************************************************/ /* Set the full path of a file relatively to a given path. */ /* Note: this routine is not really implemented for Unix. */ /***********************************************************************/
LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath)
{ char newname[_MAX_PATH]; char direc[_MAX_DIR], defdir[_MAX_DIR], tmpdir[_MAX_DIR]; char fname[_MAX_FNAME]; char ftype[_MAX_EXT]; #ifdefined(_WIN32) char drive[_MAX_DRIVE], defdrv[_MAX_DRIVE]; #else char *drive = NULL, *defdrv = NULL; #endif
if (trace(2))
htrc("prefix=%-.256s fn=%-.256s path=%-.256s\n", prefix, FileName, defpath);
if (strlen(FileName) >= _MAX_PATH)
{
*pBuff= 0; /* Hope this is treated as error of some kind*/ return FileName;
}
if (!(mfile = fopen(msgfile, "rt"))) {
snprintf(stmsg, sizeof(stmsg), "Fail to open message file %s", msgfile); goto err;
} // endif mfile
for (;;) if (!fgets(buff, 256, mfile)) {
snprintf(stmsg, sizeof(stmsg), "Cannot get message %d %s", mid, SVP(m)); goto fin;
} else if (atoi(buff) == mid) break;
if (sscanf(buff, " %*d %.31s \"%.255[^\"]", msgid, stmsg) < 2) { // Old message file if (!sscanf(buff, " %*d \"%.255[^\"]", stmsg)) {
snprintf(stmsg, sizeof(stmsg), "Bad message file for %d %s", mid, SVP(m)); goto fin;
} else
m = NULL;
} // endif sscanf
if (m && strcmp(m, msgid)) { // Message file is out of date
strcpy(stmsg, m); goto fin;
} // endif m
fin:
fclose(mfile);
err: if (g) { // Called by STEP
msg = PlugDup(g, stmsg);
} else// Called by MSG or PlgGetErrorMsg
msg = stmsg;
return msg;
} // end of PlugReadMessage
#elifdefined(NEWMSG) /***********************************************************************/ /* PlugGetMessage: get a message from the resource string table. */ /***********************************************************************/ char *PlugGetMessage(PGLOBAL g, int mid)
{ char *msg;
#if0// was !defined(UNIX) && !defined(UNIV_LINUX) int n = LoadString(s_hModule, (uint)mid, (LPTSTR)stmsg, 200);
#else// ALL if (!GetRcString(mid, stmsg, 200))
snprintf(stmsg, sizeof(stmsg) "Message %d not found", mid); #endif// ALL
if (g) { // Called by STEP
msg = PlugDup(g, stmsg);
} else// Called by MSG or PlgGetErrorMsg
msg = stmsg;
return msg;
} // end of PlugGetMessage #endif// NEWMSG
#ifdefined(_WIN32) /***********************************************************************/ /* Return the line length of the console screen buffer. */ /***********************************************************************/ short GetLineLength(PGLOBAL g)
{
CONSOLE_SCREEN_BUFFER_INFO coninfo;
HANDLE hcons = GetStdHandle(STD_OUTPUT_HANDLE); BOOL b = GetConsoleScreenBufferInfo(hcons, &coninfo);
return (b) ? coninfo.dwSize.X : 0;
} // end of GetLineLength #endif// _WIN32
/***********************************************************************/ /* Program for memory allocation of work and language areas. */ /***********************************************************************/ bool AllocSarea(PGLOBAL g, size_t size)
{ /*********************************************************************/ /* This is the allocation routine for the WIN32/UNIX/AIX version. */ /*********************************************************************/ #ifdefined(_WIN32) if (size >= 1048576) // 1M
g->Sarea = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); else #endif
g->Sarea = malloc(size);
#ifdefined(DEVELOPMENT) if (true) { #else if (trace(8)) { #endif if (g->Sarea) {
htrc("Work area of %zd allocated at %p\n", size, g->Sarea);
} else
htrc("SareaAlloc: %-.256s\n", g->Message);
} // endif trace
return (!g->Sarea);
} // end of AllocSarea
/***********************************************************************/ /* Program for memory freeing the work area. */ /***********************************************************************/ void FreeSarea(PGLOBAL g)
{ if (g->Sarea) { #ifdefined(_WIN32) if (g->Sarea_Size >= 1048576) // 1M
VirtualFree(g->Sarea, 0, MEM_RELEASE); else #endif
free(g->Sarea);
#ifdefined(DEVELOPMENT) if (true) #else if (trace(8)) #endif
htrc("Freeing Sarea at %p size = %zd\n", g->Sarea, g->Sarea_Size);
/***********************************************************************/ /* Program for SubSet initialization of memory pools. */ /* Here there should be some verification done such as validity of */ /* the address and size not larger than memory size. */ /***********************************************************************/ BOOL PlugSubSet(void *memp, size_t size)
{
PPOOLHEADER pph = (PPOOLHEADER)memp;
pph->To_Free = (size_t)sizeof(POOLHEADER);
pph->FreeBlk = size - pph->To_Free; returnFALSE;
} /* end of PlugSubSet */
/***********************************************************************/ /* Use it to export a function that do throwing. */ /***********************************************************************/ staticvoid *DoThrow(int n)
{ throw n;
} /* end of DoThrow */
/***********************************************************************/ /* Program for sub-allocating one item in a storage area. */ /* The simple way things are done here is based on the fact */ /* that no freeing of suballocated blocks is permitted in CONNECT. */ /***********************************************************************/ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size)
{
PPOOLHEADER pph; /* Points on area header. */
if (!memp) /*******************************************************************/ /* Allocation is to be done in the Sarea. */ /*******************************************************************/
memp = g->Sarea;
size = ROUNDUP_TO_8(size); /* Round up size to multiple of 8 */
pph = (PPOOLHEADER)memp;
if (trace(16))
htrc("SubAlloc in %p size=%zd used=%zd free=%zd\n",
memp, size, pph->To_Free, pph->FreeBlk);
if (size > pph->FreeBlk) { /* Not enough memory left in pool */
PCSZ pname = "Work";
snprintf(g->Message, sizeof(g->Message), "Not enough memory in %-.256s area for request of %zu (used=%zu free=%zu)",
pname, size, pph->To_Free, pph->FreeBlk);
if (trace(1))
htrc("PlugSubAlloc: %-.256s\n", g->Message);
DoThrow(1234);
} /* endif size OS32 code */
/*********************************************************************/ /* Do the suballocation the simplest way. */ /*********************************************************************/
memp = MakePtr(memp, pph->To_Free); /* Points to suballocated block */
pph->To_Free += size; /* New offset of pool free block */
pph->FreeBlk -= size; /* New size of pool free block */
if (trace(16))
htrc("Done memp=%p used=%zd free=%zd\n",
memp, pph->To_Free, pph->FreeBlk);
return (memp);
} /* end of PlugSubAlloc */
/***********************************************************************/ /* Program for sub-allocating and copying a string in a storage area. */ /***********************************************************************/ char *PlugDup(PGLOBAL g, constchar *str)
{ if (str) { char *sm = (char*)PlugSubAlloc(g, NULL, strlen(str) + 1);
/*************************************************************************/ /* This routine makes a pointer from an offset to a memory pointer. */ /*************************************************************************/ void* MakePtr(void* memp, size_t offset)
{ // return ((offset == 0) ? NULL : &((char*)memp)[offset]); return (!offset) ? NULL : (char *)memp + offset;
} /* end of MakePtr */
/*************************************************************************/ /* This routine makes an offset from a pointer new format. */ /*************************************************************************/
size_t MakeOff(void* memp, void* ptr)
{ if (ptr) { #ifdefined(_DEBUG) || defined(DEVELOPMENT) if (ptr <= memp) {
fprintf(stderr, "ptr %p <= memp %p", ptr, memp);
DoThrow(999);
} // endif ptr #endif// _DEBUG || DEVELOPMENT return (size_t)(((char*)ptr) - ((char*)memp));
} else return0;
} /* end of MakeOff */
/*---------------------- End of PLUGUTIL program ------------------------*/
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.25Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.