2017-04-25 14:41:48 +02:00
|
|
|
/* utils.h --
|
|
|
|
|
*
|
2020-05-23 23:13:14 +02:00
|
|
|
* *********************************************************************
|
|
|
|
|
* * Copyright (C) 1985, 1990 Regents of the University of California. *
|
|
|
|
|
* * Permission to use, copy, modify, and distribute this *
|
|
|
|
|
* * software and its documentation for any purpose and without *
|
|
|
|
|
* * fee is hereby granted, provided that the above copyright *
|
|
|
|
|
* * notice appear in all copies. The University of California *
|
|
|
|
|
* * makes no representations about the suitability of this *
|
|
|
|
|
* * software for any purpose. It is provided "as is" without *
|
|
|
|
|
* * express or implied warranty. Export of this software outside *
|
|
|
|
|
* * of the United States of America may require an export license. *
|
2017-04-25 14:41:48 +02:00
|
|
|
* *********************************************************************
|
|
|
|
|
*
|
|
|
|
|
* This file just defines all the features available from the
|
|
|
|
|
* Magic utility routines.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* rcsid "$Header: /usr/cvsroot/magic-8.0/utils/utils.h,v 1.2 2009/09/10 20:32:55 tim Exp $" */
|
|
|
|
|
|
2024-10-16 08:38:41 +02:00
|
|
|
#ifndef _MAGIC__UTILS__UTILS_H
|
|
|
|
|
#define _MAGIC__UTILS__UTILS_H
|
2017-04-25 14:41:48 +02:00
|
|
|
|
|
|
|
|
#include "utils/magic.h"
|
2024-10-04 21:07:03 +02:00
|
|
|
#include "utils/tech.h"
|
2017-04-25 14:41:48 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Cast second argument to LookupStruct() to (LookupTable *) to
|
|
|
|
|
* make lint very happy.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2024-10-10 21:11:37 +02:00
|
|
|
const char *d_str;
|
2017-04-25 14:41:48 +02:00
|
|
|
} LookupTable;
|
|
|
|
|
|
|
|
|
|
/* The following stuff just defines the global routines provided
|
|
|
|
|
* by files other than hash and stack and geometry.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-10-10 21:11:37 +02:00
|
|
|
extern int Lookup(const char *str, const char * const *table);
|
|
|
|
|
extern int LookupAny(char, const char * const *);
|
|
|
|
|
extern int LookupFull(const char *, const char * const *);
|
|
|
|
|
extern int LookupStruct(const char *str, const LookupTable *table_start, int size);
|
|
|
|
|
extern int LookupStructFull(const char *str, const char * const *table, int size);
|
2024-10-12 09:15:58 +02:00
|
|
|
extern int PaExpand(const char **, char **, int);
|
2024-10-12 09:17:21 +02:00
|
|
|
extern char *nextName(const char **ppath, const char *file, char *dest, int size);
|
2024-10-12 09:37:41 +02:00
|
|
|
extern FILE *PaOpen(const char *file, const char *mode, const char *ext, const char *path, const char *library,
|
|
|
|
|
char **pRealName);
|
2024-10-12 09:36:54 +02:00
|
|
|
extern FILE *PaLockOpen(const char *file, const char *mode, const char *ext, const char *path, const char *library,
|
|
|
|
|
char **pRealName, bool *is_locked, int *fdp);
|
2024-10-12 08:47:55 +02:00
|
|
|
extern char *StrDup(char **, const char *);
|
2024-10-10 21:11:37 +02:00
|
|
|
extern bool Match(const char *pattern, const char *string);
|
2024-10-12 08:54:04 +02:00
|
|
|
extern char *ArgStr(int *pargc, char ***pargv, const char *argType);
|
2024-10-12 08:47:55 +02:00
|
|
|
extern bool StrIsWhite(const char *, bool);
|
|
|
|
|
extern bool StrIsInt(const char *);
|
|
|
|
|
extern bool StrIsNumeric(const char *);
|
2017-04-25 14:41:48 +02:00
|
|
|
|
2022-10-10 11:50:15 +02:00
|
|
|
/* C99 compat */
|
2024-10-12 09:10:39 +02:00
|
|
|
extern void PaAppend(char **pathptr, const char *newstring);
|
2022-10-10 11:50:15 +02:00
|
|
|
extern void ReduceFraction(int *, int *);
|
|
|
|
|
extern bool TechLoad(char *, SectionID);
|
|
|
|
|
extern void UndoFlush();
|
|
|
|
|
extern int FindGCF();
|
|
|
|
|
extern int GetRect();
|
|
|
|
|
extern void niceabort();
|
|
|
|
|
extern void ShowRect();
|
|
|
|
|
extern void FindDisplay();
|
|
|
|
|
extern void ForkChildAdd();
|
2024-10-12 09:43:34 +02:00
|
|
|
extern int PaEnum(const char *path, const char *file, int (*proc)(), ClientData cdata);
|
2022-10-10 11:50:15 +02:00
|
|
|
extern int paVisitProcess();
|
2024-10-12 10:26:55 +02:00
|
|
|
extern void SetNoisyInt(int *parm, const char *valueS, FILE *file);
|
2024-10-12 10:27:30 +02:00
|
|
|
extern void SetNoisyDI(dlong *parm, const char *valueS, FILE *file);
|
2025-08-25 12:49:47 +02:00
|
|
|
extern bool ParsSplit(char *str, int maxArgc, int *argc, char **argv, const char **remainder);
|
2022-10-10 11:50:15 +02:00
|
|
|
|
2024-10-12 10:27:45 +02:00
|
|
|
extern int SetNoisyBool(bool *parm, const char *valueS, FILE *file);
|
2017-04-25 14:41:48 +02:00
|
|
|
|
Played around with the file locking and discovered to my chagrin that
whenever a process writes a cell to disk, it immediately releases the
file lock it had on that cell, which is clearly not the intent of file
locking. Fixed this issue. On a related topic, revised the "cellname
writeable" command so that it can make a cell editable even if the cell
has an advisory lock and cannot be made writeable. Perhaps there should
be a clearer distinction here between "writeable" and "editable". Also:
Reconsidered the previous commit, which removed the "--disable-locking"
from the configuration options. Because some operating systems may not
implement fnctl()-based file locking (Cygwin, for one, apparently doesn't),
it is still useful to be able to completely remove the function, in case
the operating system will fail to recognize the fnctl() values in the
code. Now, file locking behavior can be permanently removed through the
configuration option, or temporarily disabled from the command line.
2022-01-01 22:53:46 +01:00
|
|
|
#ifdef FILE_LOCKS
|
2017-04-25 14:41:48 +02:00
|
|
|
extern FILE *flock_open();
|
Played around with the file locking and discovered to my chagrin that
whenever a process writes a cell to disk, it immediately releases the
file lock it had on that cell, which is clearly not the intent of file
locking. Fixed this issue. On a related topic, revised the "cellname
writeable" command so that it can make a cell editable even if the cell
has an advisory lock and cannot be made writeable. Perhaps there should
be a clearer distinction here between "writeable" and "editable". Also:
Reconsidered the previous commit, which removed the "--disable-locking"
from the configuration options. Because some operating systems may not
implement fnctl()-based file locking (Cygwin, for one, apparently doesn't),
it is still useful to be able to completely remove the function, in case
the operating system will fail to recognize the fnctl() values in the
code. Now, file locking behavior can be permanently removed through the
configuration option, or temporarily disabled from the command line.
2022-01-01 22:53:46 +01:00
|
|
|
#endif
|
2017-04-25 14:41:48 +02:00
|
|
|
|
|
|
|
|
/* The following macro takes an integer and returns another integer that
|
|
|
|
|
* is the same as the first except that all the '1' bits are turned off,
|
|
|
|
|
* except for the rightmost '1' bit.
|
|
|
|
|
*
|
|
|
|
|
* Examples: 01010100 --> 00000100
|
|
|
|
|
* 1111 --> 0001
|
|
|
|
|
* 0111011100 --> 0000000100
|
|
|
|
|
*/
|
|
|
|
|
#define LAST_BIT_OF(x) ((x) & ~((x) - 1))
|
|
|
|
|
|
2024-10-12 10:22:11 +02:00
|
|
|
extern float MagAtof(const char *s);
|
2017-04-25 14:41:48 +02:00
|
|
|
|
2024-10-12 10:21:02 +02:00
|
|
|
extern int Wait(int *status);
|
|
|
|
|
extern int WaitPid(int pid, int *status);
|
2017-04-25 14:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#define FORK_f(pid) do { pid = fork(); if (pid > 0) ForkChildAdd (pid); } while (0)
|
|
|
|
|
#define FORK_vf(pid) do { pid = vfork(); if (pid > 0) ForkChildAdd (pid); } while (0)
|
|
|
|
|
|
|
|
|
|
#if defined(SYSV) || defined(CYGWIN) || defined(__APPLE__)
|
|
|
|
|
|
|
|
|
|
#define FORK(pid) FORK_f(pid)
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#define FORK(pid) FORK_vf(pid)
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-10-16 08:38:41 +02:00
|
|
|
#endif /* _MAGIC__UTILS__UTILS_H */
|